Exemplo n.º 1
0
        public IHvService TargetHost_Hv2()
        {
            string address  = this.CurrentTargetHostName();
            string username = "";
            string password = "";
            string str      = "localhost";

            if (address != str)
            {
                HostUriBuilder helperHostUriBuilder = this._Context.CredentialHelper.TargetHelperHostUriBuilder;
                username = CUtils.CombinUsernameAndDomain(helperHostUriBuilder.Credentials.UserName, helperHostUriBuilder.Credentials.Domain);
                password = helperHostUriBuilder.Credentials.Password;
            }
            IHvServiceLogger      serviceLogger      = this._ServiceLogger;
            IHvServiceCallContext serviceCallContext = this._ServiceCallContext;
            IHvService            service2012ByWmi   = HvServiceFactory.CreateHvService2012ByWmi(address, serviceLogger, serviceCallContext);

            try
            {
                service2012ByWmi.Logon(username, password);
                return(service2012ByWmi);
            }
            catch (Exception ex)
            {
                this._Logger.Information(ex, "Exception thrown during login:  ");
                service2012ByWmi.Dispose();
                throw;
            }
        }
Exemplo n.º 2
0
 public HyperVService(string address, NetworkCredential cred, ILogger logger, IHvServiceCallContext callContext)
 {
     this._Address     = address;
     this._Cred        = cred;
     this._Logger      = logger;
     this._CallContext = callContext;
     this._Scope       = WMIUtils.ConnectToServer(this._Address, CUtils.CombinUsernameAndDomain(this._Cred.UserName, this._Cred.Domain), this._Cred.Password, "\\root\\virtualization\\v2");
     this._VirtSysMgmt = VirtualSystemManagementService.GetVirtualSystemManagmentService(this._Scope);
     this._SystemName  = this._VirtSysMgmt.SystemName;
 }
Exemplo n.º 3
0
        public IHvService LocalHost_Hv2()
        {
            string                address            = "localhost";
            string                username           = "";
            string                password           = "";
            IHvServiceLogger      serviceLogger      = this._ServiceLogger;
            IHvServiceCallContext serviceCallContext = this._ServiceCallContext;
            IHvService            service2012ByWmi   = HvServiceFactory.CreateHvService2012ByWmi(address, serviceLogger, serviceCallContext);

            try
            {
                service2012ByWmi.Logon(username, password);
                return(service2012ByWmi);
            }
            catch (Exception ex)
            {
                this._Logger.Information(ex, "Exception thrown during login:  ");
                service2012ByWmi.Dispose();
                throw;
            }
        }
Exemplo n.º 4
0
        protected static void InvokeAndWaitForJob(ManagementObject mo, IHvService hvService, string methodName, object[] args)
        {
            if (string.IsNullOrEmpty(methodName) || args == null || args.Length == 0)
            {
                throw new ArgumentException(nameof(InvokeAndWaitForJob));
            }
            uint num1 = (uint)mo.InvokeMethod(methodName, args);

            switch (num1)
            {
            case 0:
                break;

            case 4096:
                string           path             = (string)args[args.Length - 1];
                ManagementObject managementObject = new ManagementObject(mo.Scope, new ManagementPath(path), (ObjectGetOptions)null);
                ushort           num2             = 3;
                Thread.Sleep(200);
                Stopwatch stopwatch = new Stopwatch();
                try
                {
                    stopwatch.Start();
                    IHvServiceCallContext serviceCallContext = hvService.HvServiceCallContext;
                    while (true)
                    {
                        managementObject.Get();
                        num2 = (ushort)managementObject["JobState"];
                        switch (num2)
                        {
                        case 3:
                        case 4:
                            if (!serviceCallContext.Stop)
                            {
                                if (serviceCallContext.Timeout <= 0L || stopwatch.ElapsedMilliseconds <= serviceCallContext.Timeout * 1000L)
                                {
                                    Thread.Sleep(1000);
                                    continue;
                                }
                                goto label_11;
                            }
                            else
                            {
                                goto label_9;
                            }

                        default:
                            goto label_15;
                        }
                    }
label_9:
                    throw new HyperVException("operation " + managementObject["Name"] + " aborted");
label_11:
                    throw new HyperVException("operation " + managementObject["Name"] + " timed out");
                }
                finally
                {
                    stopwatch.Stop();
                }
label_15:
                if ((int)num2 == 7)
                {
                    break;
                }
                ushort num3 = (ushort)managementObject["ErrorCode"];
                string str  = (string)managementObject["ErrorDescription"];
                throw new HyperVException(string.Format((IFormatProvider)CultureInfo.InvariantCulture, "method: {0} failed with error code: {1} and error description: {2}", (object)methodName, (object)num3, (object)str));

            default:
                throw new HyperVException("method: " + methodName + " call failed with error code: " + (object)num1);
            }
        }