コード例 #1
0
ファイル: Vhdx.cs プロジェクト: phspies/terodoview_ce
 internal Vhdx(IHvService service, ManagementObject imageService, string filePath)
     : base(service, imageService)
 {
     this._filePath = filePath;
     object[] args1 = new object[3]
     {
         (object)filePath,
         null,
         null
     };
     this.InvokeAndWaitForJob("GetVirtualHardDiskSettingData", args1);
     this._VirtualHardDiskSettingData = (string)args1[1];
     if (this._VirtualHardDiskSettingData == null)
     {
         throw new HyperVException("Invalid path: " + filePath);
     }
     object[] args2 = new object[3]
     {
         (object)filePath,
         null,
         null
     };
     this.InvokeAndWaitForJob("GetVirtualHardDiskState", args2);
     this._VirtualHardDiskState = (string)args2[1];
 }
コード例 #2
0
ファイル: HyperVHelper.cs プロジェクト: phspies/OculiService
        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;
            }
        }
コード例 #3
0
ファイル: HyperVHelper.cs プロジェクト: phspies/OculiService
        public IHvService SourceHost()
        {
            HostUriBuilder helperHostUriBuilder = this._Context.CredentialHelper.ReverseHelperHostUriBuilder;
            string         username             = CUtils.CombinUsernameAndDomain(helperHostUriBuilder.Credentials.UserName, helperHostUriBuilder.Credentials.Domain);
            string         password             = helperHostUriBuilder.Credentials.Password;
            IHvService     hvServiceByWmi       = HvServiceFactory.CreateHvServiceByWmi(this.CurrentSourceHostName(), this._ServiceLogger, this._ServiceCallContext);

            try
            {
                hvServiceByWmi.Logon(username, password);
                return(hvServiceByWmi);
            }
            catch (Exception ex)
            {
                this._Logger.Information(ex, "Exception thrown during login:  ");
                hvServiceByWmi.Dispose();
                throw;
            }
        }
コード例 #4
0
ファイル: HyperVHelper.cs プロジェクト: phspies/OculiService
        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;
            }
        }
コード例 #5
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);
            }
        }
コード例 #6
0
 internal HyperVManagedElement(IHvService service, ManagementObject mo)
 {
     this._hvService = service;
     this._mo        = mo;
 }
コード例 #7
0
ファイル: Vhd_Hv.cs プロジェクト: phspies/terodoview_ce
 internal Vhd_Hv(IHvService service, ManagementObject mo, string filePath, string text)
     : base(service, mo)
 {
     this._filePath = filePath;
     this._text     = text;
 }