Autor Beitrag
erdmulch
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 21



BeitragVerfasst: Di 08.03.11 20:38 
Hallo,

kann mir jemand sagen warum der code nicht bis :
"public bool Connect(string hostName, string userName, string password)"
kommt?
hab natürlich eine Main Methode geschrieben!!!!

ausblenden volle Höhe C#-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
110:
111:
112:
113:
114:
115:
116:
117:
118:
119:
120:
121:
122:
123:
124:
125:
126:
127:
128:
129:
130:
131:
132:
133:
134:
135:
136:
137:
138:
139:
140:
141:
142:
143:
144:
145:
146:
147:
148:
149:
150:
151:
152:
153:
154:
155:
156:
157:
158:
159:
160:
161:
162:
163:
164:
165:
166:
167:
168:
169:
170:
171:
172:
173:
174:
175:
176:
177:
178:
179:
180:
181:
182:
183:
184:
185:
186:
187:
188:
189:
190:
191:
192:
193:
194:
195:
196:
197:
198:
199:
200:
201:
202:
203:
204:
205:
206:
207:
208:
209:
210:
211:
212:
213:
214:
215:
216:
217:
218:
219:
220:
221:
222:
223:
224:
225:
226:
227:
228:
229:
230:
231:
232:
233:
234:
235:
236:
237:
using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices; 

using VixCOM; 

namespace Tranxition.BuildTasks
{
    public class VixWrapper
    {
        VixCOM.IVixLib vixLib = null

        ulong m_vixError;
        VixCOM.IHost m_hostHandle = null;
        VixCOM.IVM m_vmHandle = null

        public ulong GetError()
        {
            return m_vixError;
        } 

        public VixWrapper()
        {
            try
            {
                vixLib = new VixCOM.VixLibClass();
            }
            catch (COMException comExc)
            {
                System.Diagnostics.Trace.WriteLine(comExc.Message + "\n");
                throw;
            }
        } 

        /// <summary>
        /// Creates a host handle
        /// </summary>
        /// <returns>true if succeeded, otherwise false</returns>
        public bool Connect(string hostName, string userName, string password)
        {
            
            int hostType = string.IsNullOrEmpty(hostName) ?
                VixCOM.Constants.VIX_SERVICEPROVIDER_VMWARE_WORKSTATION :
                VixCOM.Constants.VIX_SERVICEPROVIDER_VMWARE_SERVER; 

            int vixVersion = VixCOM.Constants.VIX_API_VERSION; 

            vixVersion = 1// Bugfix: http://communities.vmware.com/message/649925#649925 

            VixCOM.IJob jobHandle = vixLib.Connect(vixVersion,
                hostType, hostName, 0, userName, password, 0null,  null); 

            int[] propertyIds = new int[1] { VixCOM.Constants.VIX_PROPERTY_JOB_RESULT_HANDLE };
            object results = new object(); 

            m_vixError = jobHandle.Wait(propertyIds, ref results); 

            if (m_vixError == VixCOM.Constants.VIX_OK)
            {
                object[] objectArray = (object[])results;
                m_hostHandle = (VixCOM.IHost)objectArray[0];
                return true;
            } 

            return false;
        } 

        /// <summary>
        /// Opens the virtual machine specified in vmxFilePath
        /// </summary>
        /// <param name=”vmxFilePath”>The virtual machine vmx file to open</param>
        /// <returns>true if succeeded, otherwise false</returns>
        public bool Open(string vmxFilePath)
        {
            IJob jobHandle = m_hostHandle.OpenVM(vmxFilePath, null); 

            int[] propertyIds = new int[1] { VixCOM.Constants.VIX_PROPERTY_JOB_RESULT_HANDLE };
            object results = new object(); 

            m_vixError = jobHandle.Wait(propertyIds, ref results); 

            if (m_vixError == VixCOM.Constants.VIX_OK)
            {
                object[] objectArray = (object[])results;
                m_vmHandle = (VixCOM.IVM)objectArray[0];
                return true;
            } 

            return false;
        } 

        /// <summary>
        /// Power on the virtual machine
        /// </summary>
        /// <returns>true if succeeded, otherwise false</returns>
        public bool PowerOn()
        {
            IJob jobHandle = m_vmHandle.PowerOn(VixCOM.Constants.VIX_VMPOWEROP_LAUNCH_GUI,
                nullnull);
            m_vixError = jobHandle.WaitWithoutResults(); 

            if (m_vixError == VixCOM.Constants.VIX_OK)
            {
                //
                // Wait until guest is completely booted.
                //
                jobHandle = m_vmHandle.WaitForToolsInGuest(300null); 

                m_vixError = jobHandle.WaitWithoutResults();
            } 

            return (m_vixError == VixCOM.Constants.VIX_OK);
        } 

        ///// <summary>
        ///// Starts a snapshot of a virtual machine
        ///// </summary>
        ///// <param name=”snapshot_name”>The name of the snapshot to start</param>
        ///// <returns>true if succeeded, otherwise false</returns>
        //public bool RevertToLastSnapshot()
        //{
        //    ISnapshot snapshot = null;
        //    m_vixError = m_vmHandle.GetRootSnapshot(0, out snapshot); 

        //    if (m_vixError == VixCOM.Constants.VIX_OK)
        //    {
        //        IJob jobHandle = m_vmHandle.RevertToSnapshot(snapshot, 0, null, null); 

        //        m_vixError = jobHandle.WaitWithoutResults();
        //    } 

        //    return (m_vixError == VixCOM.Constants.VIX_OK);
        //} 

        /// <summary>
        /// Login to the virtual machine
        /// </summary>
        /// <returns>true if succeeded, otherwise false</returns>
        public bool LogIn(string username, string password)
        {
            IJob jobHandle = m_vmHandle.LoginInGuest(username, password, 0null);
            m_vixError = jobHandle.WaitWithoutResults(); 

            return (m_vixError == VixCOM.Constants.VIX_OK);
        } 

        /// <summary>
        /// Creates the directory in the Virtual Machine
        /// </summary>
        /// <param name=”pathName”></param>
        /// <returns></returns>
        public bool CreateDirectoryInVm(string pathName)
        {
            IJob jobHandle = m_vmHandle.CreateDirectoryInGuest(pathName, nullnull);
            m_vixError = jobHandle.WaitWithoutResults(); 

            return (m_vixError == VixCOM.Constants.VIX_OK);
        } 

        /// <summary>
        /// Copies a file from the host machine to the virtual machine
        /// </summary>
        /// <param name=”sourceFile”>The source file on the host machine</param>
        /// <param name=”destinationFile”>The destination on the VM</param>
        /// <returns>true if succeeded, otherwise false</returns>
        public bool CopyFileToVm(string sourceFile, string destinationFile)
        {
            //
            // Copy files from host to guest
            //
            IJob jobHandle = m_vmHandle.CopyFileFromHostToGuest(sourceFile, destinationFile,
                0nullnull);
            m_vixError = jobHandle.WaitWithoutResults(); 

            return (m_vixError == VixCOM.Constants.VIX_OK);
        } 

        ///// <summary>
        ///// Copies a file from the virtual machine to the host machine
        ///// </summary>
        ///// <param name=”sourceFile”>The source file on the virtual machine</param>
        ///// <param name=”destinationFile”>The destination on the host machine</param>
        ///// <returns>true if succeeded, otherwise false</returns>
        //public bool CopyFileFromVm(string sourceFile, string destinationFile)
        //{
        //    //
        //    // Copy files from host to guest
        //    //
        //    IJob jobHandle = m_vmHandle.CopyFileFromGuestToHost(sourceFile, destinationFile,
        //        0, null, null);
        //    m_vixError = jobHandle.WaitWithoutResults(); 

        //    return (m_vixError == VixCOM.Constants.VIX_OK);
        //} 

        ///// <summary>
        ///// Runs a program on the virtual machine
        ///// </summary>
        ///// <param name=”exePath”>The path of the program on the virtual machine</param>
        ///// <param name=”parameters”>The parameters to pass to the executable</param>
        ///// <param name=”resultCode”>The result code returned from the program that ran on the VM</param>
        ///// <returns>true if succeeded, otherwise false</returns>
        //public bool RunProgram(string exePath, string parameters, out int resultCode)
        //{
        //    resultCode = -1; 

        //    IJob jobHandle = m_vmHandle.RunProgramInGuest(exePath,
        //        parameters, VixCOM.Constants.VIX_RUNPROGRAM_ACTIVATE_WINDOW, null, null); // clientData 

        //    int[] propertyIds = new int[1] { VixCOM.Constants.VIX_PROPERTY_JOB_RESULT_GUEST_PROGRAM_EXIT_CODE };
        //    object results = new object();
        //    m_vixError = jobHandle.Wait(propertyIds, ref results); 

        //    if (m_vixError == VixCOM.Constants.VIX_OK)
        //    {
        //        object[] objectArray = (object[])results;
        //        resultCode = (int)objectArray[0];
        //        return true;
        //    } 

        //    return false;
        //} 

        /// <summary>
        /// Power off the virtual machine
        /// </summary>
        /// <returns>true if succeeded, otherwise false</returns>
        public bool PowerOff()
        {
            IJob jobHandle = m_vmHandle.PowerOff(VixCOM.Constants.VIX_VMPOWEROP_NORMAL, null);
            m_vixError = jobHandle.WaitWithoutResults(); 

            return (m_vixError == VixCOM.Constants.VIX_OK);
        }
    }
}


Moderiert von user profile iconKha: C#-Tags hinzugefügt
Kha
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 3803
Erhaltene Danke: 176

Arch Linux
Python, C, C++ (vim)
BeitragVerfasst: Di 08.03.11 20:47 
Du bist du lustig :roll: - ist dir schon aufgefallen, dass in dem Codebatzen kein einziger Aufruf von Connect vorkommt? Von hier aus können wir dir also nur antworten: Debugger starten und durchsteppen.

_________________
>λ=