public int Run(string[] argv)
        {
            int exitCode = 0;
            int error1   = VMCommand.CommandPing(this.vmHandle, this.unitId);

            if (error1 != 0)
            {
                throw new ApplicationException("Cannot ping VM", (Exception) new Win32Exception(error1));
            }
            int error2 = VMCommand.CommandRun(this.vmHandle, this.unitId, argv.Length, argv, new VMCommand.ChunkHandler(this.OutputHandler), new VMCommand.ChunkHandler(this.ErrorHandler), ref exitCode);

            if (error2 != 0)
            {
                throw new ApplicationException("Cannot run VM command", (Exception) new Win32Exception(error2));
            }
            if (this.outputBuffer.Length > 0 && this.userOutputHandler != null)
            {
                this.userOutputHandler(this.outputBuffer.ToString());
            }
            if (this.errorBuffer.Length > 0 && this.userErrorHandler != null)
            {
                this.userErrorHandler(this.errorBuffer.ToString());
            }
            return(exitCode);
        }
Exemple #2
0
        private static void SetId(string vmName)
        {
            Logger.Info("Starting id manager");
            string id = Id.GenerateID();
            bool   flag;

            do
            {
                Thread.Sleep(50);
                flag = false;
                try
                {
                    VMCommand vmCommand = new VMCommand();
                    vmCommand.Attach(vmName);
                    int num = vmCommand.Run(new string[2]
                    {
                        "iSetId",
                        id
                    });
                    if (num != 0)
                    {
                        Logger.Info("Failed to set Id:" + num.ToString());
                        flag = true;
                    }
                }
                catch
                {
                    Logger.Info("Retrying to set Id");
                    flag = true;
                }
            }while (flag);
            Logger.Info("Set Id success!");
        }
        public void Attach(string vmName)
        {
            uint vmId = MonitorLocator.Lookup(vmName);

            this.unitId   = (uint)this.random.Next();
            this.vmHandle = VMCommand.CommandAttach(vmId, this.unitId);
            if (this.vmHandle.IsInvalid)
            {
                throw new ApplicationException("Cannot attach to monitor: " + Marshal.GetLastWin32Error().ToString());
            }
        }
 private void ErrorHandler(string chunk)
 {
     VMCommand.CommonHandler(chunk, this.errorBuffer, this.userErrorHandler);
 }
 private void OutputHandler(string chunk)
 {
     VMCommand.CommonHandler(chunk, this.outputBuffer, this.userOutputHandler);
 }
 public void Kill()
 {
     VMCommand.CommandKill(this.vmHandle, this.unitId);
 }