public MSFTNetServiceStopControlSuccess(IInfrastructureObjectScope scope, CimInstance instance) : base(scope, instance)
 {
 }
예제 #2
0
        /// <summary>
        /// <para>
        /// Set <see cref="CimInstance"/> with properties specified in cmdlet
        /// </para>
        /// </summary>
        /// <param name="cimInstance"></param>
        public void SetCimInstance(CimInstance cimInstance, CimSetCimInstanceContext context, CmdletOperationBase cmdlet)
        {
            DebugHelper.WriteLog("CimSetCimInstance::SetCimInstance", 4);

            if (!cmdlet.ShouldProcess(cimInstance.ToString(), action))
            {
                return;
            }

            Exception exception = null;
            if (!SetProperty(context.Property, ref cimInstance, ref exception))
            {
                cmdlet.ThrowTerminatingError(exception, action);
                return;
            }
            CimSessionProxy proxy = CreateCimSessionProxy(context.Proxy, context.PassThru);
            proxy.ModifyInstanceAsync(cimInstance.CimSystemProperties.Namespace, cimInstance);
        }
예제 #3
0
        /// <summary>
        /// <para>
        /// Invoke cimmethod on given <see cref="CimInstance"/>
        /// </para>
        /// </summary>
        /// <param name="cimInstance"></param>
        public void InvokeCimMethodOnCimInstance(CimInstance cimInstance, XOperationContextBase context, CmdletOperationBase operation)
        {
            DebugHelper.WriteLogEx();
            CimInvokeCimMethodContext cimInvokeCimMethodContext = context as CimInvokeCimMethodContext;
            Debug.Assert(cimInvokeCimMethodContext != null, "CimInvokeCimMethod::InvokeCimMethodOnCimInstance should has CimInvokeCimMethodContext != NULL.");

            string action = string.Format(CultureInfo.CurrentUICulture, actionTemplate, cimInvokeCimMethodContext.MethodName);
            if (!operation.ShouldProcess(cimInstance.ToString(), action))
            {
                return;
            }

            CimSessionProxy proxy = CreateCimSessionProxy(cimInvokeCimMethodContext.Proxy);
            proxy.InvokeMethodAsync(
                cimInvokeCimMethodContext.Namespace,
                cimInstance,
                cimInvokeCimMethodContext.MethodName,
                cimInvokeCimMethodContext.ParametersCollection);
        }
예제 #4
0
        /// <summary>
        /// Create <see cref="CimSession"/> by given computer name
        /// and cimInstance. Then create wrapper object.
        /// </summary>
        /// <param name="computerName"></param>
        /// <param name="cimInstance"></param>
        public CimSessionProxy(string computerName, CimInstance cimInstance)
        {
            DebugHelper.WriteLogEx("ComputerName {0}; cimInstance.CimSessionInstanceID = {1}; cimInstance.CimSessionComputerName = {2}.",
                0,
                computerName,
                cimInstance.GetCimSessionInstanceId(),
                cimInstance.GetCimSessionComputerName());

            if (computerName != ConstValue.NullComputerName)
            {
                CreateSetSession(computerName, null, null, null, false);
                return;
            }

            Debug.Assert(cimInstance != null, "Caller should verify cimInstance != null");
            
            // computerName is null, fallback to create session from cimInstance
            CimSessionState state = CimSessionBase.GetCimSessionState();
            if (state != null)
            {
                CimSession session = state.QuerySession(cimInstance.GetCimSessionInstanceId());
                if (session != null)
                {
                    DebugHelper.WriteLogEx("Found the session from cache with InstanceID={0}.", 0, cimInstance.GetCimSessionInstanceId());
                    CreateSetSession(null, session, null, null, false);
                    return;
                }
            }
            String cimsessionComputerName = cimInstance.GetCimSessionComputerName();
            CreateSetSession(cimsessionComputerName, null, null, null, false);
            this.isDefaultSession = (cimsessionComputerName  == ConstValue.NullComputerName);

            DebugHelper.WriteLogEx("Create a temp session with computerName = {0}.", 0, cimsessionComputerName);
        }
예제 #5
0
        /// <summary>
        /// <para>
        /// Get full <see cref="CimInstance"/> from server based on the key
        /// </para>
        /// </summary>
        /// <param name="cimInstance"></param>
        internal void GetCimInstance(CimInstance cimInstance, XOperationContextBase context)
        {
            DebugHelper.WriteLogEx();

            CimNewCimInstanceContext newCimInstanceContext = context as CimNewCimInstanceContext;
            if (newCimInstanceContext == null)
            {
                DebugHelper.WriteLog("Invalid (null) CimNewCimInstanceContext", 1);
                return;
            }

            CimSessionProxy proxy = CreateCimSessionProxy(newCimInstanceContext.Proxy);
            string nameSpace = (cimInstance.CimSystemProperties.Namespace == null) ? newCimInstanceContext.Namespace : cimInstance.CimSystemProperties.Namespace;
            proxy.GetInstanceAsync(nameSpace, cimInstance);
        }
예제 #6
0
 /// <summary>
 /// Create <see cref="CimSessionProxy"/> object, and
 /// add the proxy into cache.
 /// </summary>
 /// <param name="computerName"></param>
 /// <param name="cimInstance"></param>
 /// <param name="passThru"></param>
 protected CimSessionProxy CreateCimSessionProxy(string computerName, CimInstance cimInstance, bool passThru)
 {
     CimSessionProxy proxy = new CimSessionProxySetCimInstance(computerName, cimInstance, passThru);
     this.SubscribeEventAndAddProxytoCache(proxy);
     return proxy;
 }
예제 #7
0
 /// <summary>
 /// Enumerate cim instance associated with the
 /// given instance asynchronously
 /// </summary>
 /// <param name="namespaceName"></param>
 /// <param name="sourceInstance"></param>
 /// <param name="associationClassName"></param>
 /// <param name="resultClassName"></param>
 /// <param name="sourceRole"></param>
 /// <param name="resultRole"></param>
 public void EnumerateAssociatedInstancesAsync(
     string namespaceName,
     CimInstance sourceInstance,
     string associationClassName,
     string resultClassName,
     string sourceRole,
     string resultRole)
 {
     Debug.Assert(sourceInstance != null, "Caller should verify that sourceInstance != NULL.");
     DebugHelper.WriteLogEx("Instance class {0}, association class {1}", 0, sourceInstance.CimSystemProperties.ClassName, associationClassName);
     this.CheckAvailability();
     this.targetCimInstance = sourceInstance;
     this.operationName = Strings.CimOperationNameEnumerateAssociatedInstances;
     this.operationParameters.Clear();
     this.operationParameters.Add(@"namespaceName", namespaceName);
     this.operationParameters.Add(@"sourceInstance", sourceInstance);
     this.operationParameters.Add(@"associationClassName", associationClassName);
     this.operationParameters.Add(@"resultClassName", resultClassName);
     this.operationParameters.Add(@"sourceRole", sourceRole);
     this.operationParameters.Add(@"resultRole", resultRole);
     this.WriteOperationStartMessage(this.operationName, this.operationParameters);
     CimAsyncMultipleResults<CimInstance> asyncResult = this.session.EnumerateAssociatedInstancesAsync(namespaceName, sourceInstance, associationClassName, resultClassName, sourceRole, resultRole, this.options);
     ConsumeCimInstanceAsync(asyncResult, new CimResultContext(sourceInstance));
 }
예제 #8
0
 protected CIMPCVideoController(IInfrastructureObjectScope scope, CimInstance instance) : base(scope, instance)
 {
 }
예제 #9
0
 protected CIMDiskDrive(IInfrastructureObjectScope scope, CimInstance instance) : base(scope, instance)
 {
 }
예제 #10
0
 public MSFTNetLbfoTeamTeamMember(IInfrastructureObjectScope scope, CimInstance instance) : base(scope, instance)
 {
 }
 public Win32VolumeChangeEvent(IInfrastructureObjectScope scope, CimInstance instance) : base(scope, instance)
 {
 }
예제 #12
0
        /// <summary>
        /// <para>
        /// Set the properties value to be modified to the given
        /// <see cref="CimInstance"/>
        /// </para>
        /// </summary>
        /// <param name="properties"></param>
        /// <param name="cimInstance"></param>
        /// <param name="terminationMessage"></param>
        /// <returns></returns>
        private bool SetProperty(IDictionary properties, ref CimInstance cimInstance, ref Exception exception)
        {
            DebugHelper.WriteLogEx();
            if (properties.Count == 0)
            {
                // simply ignore if empty properties was provided
                return(true);
            }

            IDictionaryEnumerator enumerator = properties.GetEnumerator();

            while (enumerator.MoveNext())
            {
                object value = GetBaseObject(enumerator.Value);
                string key   = enumerator.Key.ToString();
                DebugHelper.WriteLog("Input property name '{0}' with value '{1}'", 1, key, value);

                try
                {
                    CimProperty property = cimInstance.CimInstanceProperties[key];
                    // modify existing property value if found
                    if (property != null)
                    {
                        if ((property.Flags & CimFlags.ReadOnly) == CimFlags.ReadOnly)
                        {
                            // can not modify ReadOnly property
                            exception = new CimException(String.Format(CultureInfo.CurrentUICulture,
                                                                       Strings.CouldNotModifyReadonlyProperty, key, cimInstance));
                            return(false);
                        }
                        // allow modify the key property value as long as it is not readonly,
                        // then the modified ciminstance is stand for a different CimInstance
                        DebugHelper.WriteLog("Set property name '{0}' has old value '{1}'", 4, key, property.Value);
                        property.Value = value;
                    }
                    else // For dynamic instance, it is valid to add a new property
                    {
                        CimProperty newProperty;
                        if (value == null)
                        {
                            newProperty = CimProperty.Create(
                                key,
                                value,
                                CimType.String,
                                CimFlags.Property);
                        }
                        else
                        {
                            CimType referenceType   = CimType.Unknown;
                            object  referenceObject = GetReferenceOrReferenceArrayObject(value, ref referenceType);
                            if (referenceObject != null)
                            {
                                newProperty = CimProperty.Create(
                                    key,
                                    referenceObject,
                                    referenceType,
                                    CimFlags.Property);
                            }
                            else
                            {
                                newProperty = CimProperty.Create(
                                    key,
                                    value,
                                    CimFlags.Property);
                            }
                        }

                        try
                        {
                            cimInstance.CimInstanceProperties.Add(newProperty);
                        }
                        catch (CimException e)
                        {
                            if (e.NativeErrorCode == NativeErrorCode.Failed)
                            {
                                string errorMessage = String.Format(CultureInfo.CurrentUICulture,
                                                                    Strings.UnableToAddPropertyToInstance,
                                                                    newProperty.Name,
                                                                    cimInstance);
                                exception = new CimException(errorMessage, e);
                            }
                            else
                            {
                                exception = e;
                            }

                            return(false);
                        }

                        DebugHelper.WriteLog("Add non-key property name '{0}' with value '{1}'.", 3, key, value);
                    }
                }
                catch (Exception e)
                {
                    DebugHelper.WriteLog("Exception {0}", 4, e);
                    exception = e;
                    return(false);
                }
            }

            return(true);
        }
예제 #13
0
        /// <summary>
        /// <para>
        /// Create <see cref="CimMethodParametersCollection"/> with given key properties.
        /// And/or <see cref="CimClass"/> object.
        /// </para>
        /// </summary>
        /// <param name="parameters"></param>
        /// <param name="cimClass"></param>
        /// <param name="cimInstance"></param>
        /// <param name="methodName"></param>
        /// <returns></returns>
        /// <exception cref="ArgumentNullException">See CimProperty.Create</exception>
        /// <exception cref="ArgumentException">CimProperty.Create</exception>
        private CimMethodParametersCollection CreateParametersCollection(
            IDictionary parameters,
            CimClass cimClass,
            CimInstance cimInstance,
            string methodName)
        {
            DebugHelper.WriteLogEx();

            CimMethodParametersCollection collection = null;
            if (parameters == null)
            {
                return collection;
            }
            else if (parameters.Count == 0)
            {
                return collection;
            }

            collection = new CimMethodParametersCollection();
            IDictionaryEnumerator enumerator = parameters.GetEnumerator();
            while (enumerator.MoveNext())
            {
                string parameterName = enumerator.Key.ToString();

                CimFlags parameterFlags = CimFlags.In;
                object parameterValue = GetBaseObject(enumerator.Value);

                DebugHelper.WriteLog(@"Create parameter name= {0}, value= {1}, flags= {2}.", 4,
                    parameterName,
                    parameterValue,
                    parameterFlags);

                CimMethodParameter parameter = null;
                CimMethodDeclaration declaration = null;
                string className = null;
                if (cimClass != null)
                {
                    className = cimClass.CimSystemProperties.ClassName;
                    declaration = cimClass.CimClassMethods[methodName];
                    if (declaration == null)
                    {
                        throw new ArgumentException(String.Format(
                                CultureInfo.CurrentUICulture, Strings.InvalidMethod, methodName, className));
                    }
                }
                else if (cimInstance != null)
                {
                    className = cimInstance.CimClass.CimSystemProperties.ClassName;
                    declaration = cimInstance.CimClass.CimClassMethods[methodName];
                }

                if (declaration != null)
                {
                    CimMethodParameterDeclaration paramDeclaration = declaration.Parameters[parameterName];
                    if (paramDeclaration == null)
                    {
                        throw new ArgumentException(String.Format(
                            CultureInfo.CurrentUICulture, Strings.InvalidMethodParameter, parameterName, methodName, className));
                    }
                    parameter = CimMethodParameter.Create(
                        parameterName,
                        parameterValue,
                        paramDeclaration.CimType,
                        parameterFlags);
                    // FIXME: check in/out qualifier
                    // parameterFlags = paramDeclaration.Qualifiers;
                }
                else
                {
                    if (parameterValue == null)
                    {
                        // try the best to get the type while value is null                    
                        parameter = CimMethodParameter.Create(
                            parameterName,
                            parameterValue,
                            CimType.String,
                            parameterFlags);
                    }
                    else
                    {
                        CimType referenceType = CimType.Unknown;
                        object referenceObject = GetReferenceOrReferenceArrayObject(parameterValue, ref referenceType);
                        if (referenceObject != null)
                        {
                            parameter = CimMethodParameter.Create(
                                parameterName,
                                referenceObject,
                                referenceType,
                                parameterFlags);
                        }
                        else
                        {
                            parameter = CimMethodParameter.Create(
                                parameterName,
                                parameterValue,
                                parameterFlags);
                        }
                    }
                }
                if (parameter != null)
                    collection.Add(parameter);
            }
            return collection;
        }
예제 #14
0
 /// <summary>
 /// <para>
 /// Create <see cref="CimSessionProxy"/> and set properties
 /// </para>
 /// </summary>
 /// <param name="computerName"></param>
 /// <param name="cimInstance"></param>
 /// <param name="cmdlet"></param>
 /// <returns></returns>
 private CimSessionProxy CreateSessionProxy(
     string computerName,
     CimInstance cimInstance,
     InvokeCimMethodCommand cmdlet)
 {
     CimSessionProxy proxy = CreateCimSessionProxy(computerName, cimInstance);
     SetSessionProxyProperties(ref proxy, cmdlet);
     return proxy;
 }
예제 #15
0
 public Win32PerfRawDataCountersIPsecIKEv2IPv6(IInfrastructureObjectScope scope, CimInstance instance) : base(scope, instance)
 {
 }
예제 #16
0
 public MsvmStorageAllocationSettingData(IInfrastructureObjectScope scope, CimInstance instance) : base(scope, instance)
 {
 }
예제 #17
0
        public void WriteUnnamedCimInstance(CimInstance instance)
        {
            #region Actual XML Request
            /*
            [...]
            <INSTANCE CLASSNAME="CIM_NFS">
                <QUALIFIER NAME="Deprecated" TYPE="string" TOSUBCLASS="false" >
                    <VALUE.ARRAY>
                        <VALUE>CIM_FileShare</VALUE>
                    </VALUE.ARRAY>
                </QUALIFIER>
                <QUALIFIER NAME="Version" TYPE="string" TOSUBCLASS="false" TRANSLATABLE="true" >
                    <VALUE>2.6.0</VALUE>
                </QUALIFIER>
                [...]
                <PROPERTY NAME="CSCreationClassName" TYPE="string" CLASSORIGIN="CIM_FileSystem" PROPAGATED="true" >
                    <QUALIFIER NAME="Key" TYPE="boolean" OVERRIDABLE="false" >
                        <VALUE>true</VALUE>
                    </QUALIFIER>
                    [...]
                    <VALUE>tCSCreationClassName</VALUE>
                </PROPERTY>
                [...]
                <PROPERTY NAME="Root" TYPE="string" CLASSORIGIN="CIM_FileSystem" PROPAGATED="true" >
                    <QUALIFIER NAME="Description" TYPE="string" TRANSLATABLE="true" >
                        <VALUE>Path name or other information defining the root of the FileSystem.</VALUE>
                    </QUALIFIER>
                    [...]
                </PROPERTY>
                [...]
                <PROPERTY.ARRAY NAME="OperationalStatus" TYPE="uint16" CLASSORIGIN="CIM_ManagedSystemElement" PROPAGATED="true" >
                    <QUALIFIER NAME="Description" TYPE="string" TRANSLATABLE="true" >
                        <VALUE>Indicates the current statuses of the element. Various operational statuses are defined. Many of the enumeration&apos;s values are self-explanatory. However, a few are not and are described here in more detail. &quot;Stressed&quot; indicates that the element is functioning, but needs attention. Examples of &quot;Stressed&quot; states are overload, overheated, and so on. &quot;Predictive Failure&quot; indicates that an element is functioning nominally but predicting a failure in the near future. &quot;In Service&quot; describes an element being configured, maintained, cleaned, or otherwise administered. &quot;No Contact&quot; indicates that the monitoring system has knowledge of this element, but has never been able to establish communications with it. &quot;Lost Communication&quot; indicates that the ManagedSystem Element is known to exist and has been contacted successfully in the past, but is currently unreachable. &quot;Stopped&quot; and &quot;Aborted&quot; are similar, although the former implies a clean and orderly stop, while the latter implies an abrupt stop where the state and configuration of the element might need to be updated. &quot;Dormant&quot; indicates that the element is inactive or quiesced. &quot;Supporting Entity in Error&quot; indicates that this element might be &quot;OK&quot; but that another element, on which it is dependent, is in error. An example is a network service or endpoint that cannot function due to lower-layer networking problems. &quot;Completed&quot; indicates that the element has completed its operation. This value should be combined with either OK, Error, or Degraded so that a client can tell if the complete operation Completed with OK (passed), Completed with Error (failed), or Completed with Degraded (the operation finished, but it did not complete OK or did not report an error). &quot;Power Mode&quot; indicates that the element has additional power model information contained in the Associated PowerManagementService association. OperationalStatus replaces the Status property on ManagedSystemElement to provide a consistent approach to enumerations, to address implementation needs for an array property, and to provide a migration path from today&apos;s environment to the future. This change was not made earlier because it required the deprecated qualifier. Due to the widespread use of the existing Status property in management applications, it is strongly recommended that providers or instrumentation provide both the Status and OperationalStatus properties. Further, the first value of OperationalStatus should contain the primary status for the element. When instrumented, Status (because it is single-valued) should also provide the primary status of the element.</VALUE>
                    </QUALIFIER>
                    [...]
                    <VALUE.ARRAY>
                        <VALUE></VALUE>
                    </VALUE.ARRAY>
                </PROPERTY.ARRAY>
                [...]
            </INSTANCE>
            */
            #endregion

            this.WriteInstanceElement();
            this.WriteClassNameAttributeString(instance.ClassName);
            this.WriteCimPropertyReferenceList(instance.PropertyReferences);

            this.WriteCimQualifierList(instance.Qualifiers);
            this.WriteCimPropertyList(instance.Properties);

            this.WriteEndElement();
        }
예제 #18
0
 public Win32POTSModem(IInfrastructureObjectScope scope, CimInstance instance) : base(scope, instance)
 {
 }
예제 #19
0
 /// <summary>
 /// <para>
 /// create a cim instance asynchronously
 /// </para>
 /// </summary>
 /// <param name="namespaceName"></param>
 /// <param name="instance"></param>
 public void CreateInstanceAsync(string namespaceName, CimInstance instance)
 {
     Debug.Assert(instance != null, "Caller should verify that instance != NULL.");
     DebugHelper.WriteLogEx("EnableMethodResultStreaming = {0}", 0, this.options.EnableMethodResultStreaming);
     this.CheckAvailability();
     this.targetCimInstance = instance;
     this.operationName = Strings.CimOperationNameCreateInstance;
     this.operationParameters.Clear();
     this.operationParameters.Add(@"namespaceName", namespaceName);
     this.operationParameters.Add(@"instance", instance);
     this.WriteOperationStartMessage(this.operationName, this.operationParameters);
     CimAsyncResult<CimInstance> asyncResult = this.session.CreateInstanceAsync(namespaceName, instance, this.options);
     ConsumeCimInstanceAsync(asyncResult, new CimResultContext(instance));
 }
예제 #20
0
 public MSFTNetAdapterChecksumOffloadElementSetting(IInfrastructureObjectScope scope, CimInstance instance) : base(scope, instance)
 {
 }
예제 #21
0
 /// <summary>
 /// Invoke method of a given cim instance asynchronously
 /// </summary>
 /// <param name="namespaceName"></param>
 /// <param name="instance"></param>
 /// <param name="methodName"></param>
 /// <param name="methodParameters"></param>
 public void InvokeMethodAsync(
     string namespaceName,
     CimInstance instance,
     string methodName,
     CimMethodParametersCollection methodParameters)
 {
     Debug.Assert(instance != null, "Caller should verify that instance != NULL.");
     DebugHelper.WriteLogEx("EnableMethodResultStreaming = {0}", 0, this.options.EnableMethodResultStreaming);
     this.CheckAvailability();
     this.targetCimInstance = instance;
     this.operationName = Strings.CimOperationNameInvokeMethod;
     this.operationParameters.Clear();
     this.operationParameters.Add(@"namespaceName", namespaceName);
     this.operationParameters.Add(@"instance", instance);
     this.operationParameters.Add(@"methodName", methodName);
     this.WriteOperationStartMessage(this.operationName, this.operationParameters);
     CimAsyncMultipleResults<CimMethodResultBase> asyncResult = this.session.InvokeMethodAsync(namespaceName, instance, methodName, methodParameters, this.options);
     ConsumeCimInvokeMethodResultAsync(asyncResult, instance.CimSystemProperties.ClassName, methodName, new CimResultContext(instance));
 }
예제 #22
0
 protected CIMForwardsAmong(IInfrastructureObjectScope scope, CimInstance instance) : base(scope, instance)
 {
 }
예제 #23
0
 /// <summary>
 /// <para>
 /// WriteError callback
 /// </para>
 /// </summary>
 /// <param name="instance"></param>
 /// <returns></returns>
 public CimResponseType WriteError(CimInstance instance)
 {
     DebugHelper.WriteLogEx("Error:{0}", 0, instance);
     try
     {
         CimWriteError action = new CimWriteError(instance, this.invocationContextObject);
         this.FireNewActionEvent(action);
         return action.GetResponse();
     }
     catch (Exception ex)
     {
         DebugHelper.WriteLogEx("{0}", 0, ex);
         return CimResponseType.NoToAll;
     }
 }
예제 #24
0
 public MSFTNetQosPolicySettingData(IInfrastructureObjectScope scope, CimInstance instance) : base(scope, instance)
 {
 }
예제 #25
0
 /// <summary>
 /// <para>
 /// Create <see cref="CimInstance"/> with given properties.
 /// </para>
 /// </summary>
 /// <param name="cimClass"></param>
 /// <param name="properties"></param>
 /// <param name="cmdlet"></param>
 /// <returns></returns>
 /// <exception cref="ArgumentNullException">See CimProperty.Create</exception>
 /// <exception cref="ArgumentException">CimProperty.Create</exception>
 private CimInstance CreateCimInstance(
     CimClass cimClass,
     IDictionary properties,
     NewCimInstanceCommand cmdlet)
 {
     CimInstance cimInstance = new CimInstance(cimClass);
     if (properties == null)
     {
         return cimInstance;
     }
     List<string> notfoundProperties = new List<string>();
     foreach (string property in properties.Keys)
     {
         if (cimInstance.CimInstanceProperties[property] == null)
         {
             notfoundProperties.Add(property);
             cmdlet.ThrowInvalidProperty(notfoundProperties, cmdlet.CimClass.CimSystemProperties.ClassName, @"Property", action, properties);
             return null;
         }
         object propertyValue = GetBaseObject(properties[property]);
         cimInstance.CimInstanceProperties[property].Value = propertyValue;
     }
     return cimInstance;
 }
예제 #26
0
 public AggregateEvent(IInfrastructureObjectScope scope, CimInstance instance) : base(scope, instance)
 {
 }
예제 #27
0
        /// <summary>
        /// Convert <see cref="cimError"/> to <see cref="ErrorCategory"/>.
        /// </summary>
        /// <param name="cimError"></param>
        /// <returns></returns>
        internal static ErrorCategory ConvertCimErrorToErrorCategory(CimInstance cimError)
        {
            if (cimError == null)
            {
                return ErrorCategory.NotSpecified;
            }

            CimProperty errorCategoryProperty = cimError.CimInstanceProperties[@"Error_Category"];
            if (errorCategoryProperty == null)
            {
                return ErrorCategory.NotSpecified;
            }

            ErrorCategory errorCategoryValue;
            if (!LanguagePrimitives.TryConvertTo<ErrorCategory>(errorCategoryProperty.Value, CultureInfo.InvariantCulture, out errorCategoryValue))
            {
                return ErrorCategory.NotSpecified;
            }

            return errorCategoryValue;
        }
예제 #28
0
        /// <summary>
        /// <para>
        /// Create <see cref="CimMethodParametersCollection"/> with given key properties.
        /// And/or <see cref="CimClass"/> object.
        /// </para>
        /// </summary>
        /// <param name="parameters"></param>
        /// <param name="cimClass"></param>
        /// <param name="cimInstance"></param>
        /// <param name="methodName"></param>
        /// <returns></returns>
        /// <exception cref="ArgumentNullException">See CimProperty.Create.</exception>
        /// <exception cref="ArgumentException">CimProperty.Create.</exception>
        private CimMethodParametersCollection CreateParametersCollection(
            IDictionary parameters,
            CimClass cimClass,
            CimInstance cimInstance,
            string methodName)
        {
            DebugHelper.WriteLogEx();

            CimMethodParametersCollection collection = null;

            if (parameters == null)
            {
                return(collection);
            }
            else if (parameters.Count == 0)
            {
                return(collection);
            }

            collection = new CimMethodParametersCollection();
            IDictionaryEnumerator enumerator = parameters.GetEnumerator();

            while (enumerator.MoveNext())
            {
                string parameterName = enumerator.Key.ToString();

                const CimFlags parameterFlags = CimFlags.In;
                object         parameterValue = GetBaseObject(enumerator.Value);

                DebugHelper.WriteLog(@"Create parameter name= {0}, value= {1}, flags= {2}.", 4,
                                     parameterName,
                                     parameterValue,
                                     parameterFlags);

                CimMethodParameter   parameter   = null;
                CimMethodDeclaration declaration = null;
                string className = null;
                if (cimClass != null)
                {
                    className   = cimClass.CimSystemProperties.ClassName;
                    declaration = cimClass.CimClassMethods[methodName];
                    if (declaration == null)
                    {
                        throw new ArgumentException(string.Format(
                                                        CultureInfo.CurrentUICulture, CimCmdletStrings.InvalidMethod, methodName, className));
                    }
                }
                else if (cimInstance != null)
                {
                    className   = cimInstance.CimClass.CimSystemProperties.ClassName;
                    declaration = cimInstance.CimClass.CimClassMethods[methodName];
                }

                if (declaration != null)
                {
                    CimMethodParameterDeclaration paramDeclaration = declaration.Parameters[parameterName];
                    if (paramDeclaration == null)
                    {
                        throw new ArgumentException(string.Format(
                                                        CultureInfo.CurrentUICulture, CimCmdletStrings.InvalidMethodParameter, parameterName, methodName, className));
                    }

                    parameter = CimMethodParameter.Create(
                        parameterName,
                        parameterValue,
                        paramDeclaration.CimType,
                        parameterFlags);
                    // FIXME: check in/out qualifier
                    // parameterFlags = paramDeclaration.Qualifiers;
                }
                else
                {
                    if (parameterValue == null)
                    {
                        // try the best to get the type while value is null
                        parameter = CimMethodParameter.Create(
                            parameterName,
                            parameterValue,
                            CimType.String,
                            parameterFlags);
                    }
                    else
                    {
                        CimType referenceType   = CimType.Unknown;
                        object  referenceObject = GetReferenceOrReferenceArrayObject(parameterValue, ref referenceType);
                        if (referenceObject != null)
                        {
                            parameter = CimMethodParameter.Create(
                                parameterName,
                                referenceObject,
                                referenceType,
                                parameterFlags);
                        }
                        else
                        {
                            parameter = CimMethodParameter.Create(
                                parameterName,
                                parameterValue,
                                parameterFlags);
                        }
                    }
                }

                if (parameter != null)
                {
                    collection.Add(parameter);
                }
            }

            return(collection);
        }
예제 #29
0
 public Win32PerfRawDataHyperVReplicaStatsHyperVReplicaVM(IInfrastructureObjectScope scope, CimInstance instance) : base(scope, instance)
 {
 }
예제 #30
0
 public MSFTNetFirewallRuleInProfile(IInfrastructureObjectScope scope, CimInstance instance) : base(scope, instance)
 {
 }
 public Win32PerfFormattedDataCountersVFPQoSQueueTotalInboundNetworkTraffic(IInfrastructureObjectScope scope, CimInstance instance) : base(scope, instance)
 {
 }
 public Win32PerfFormattedDataNvspNicDropReasonsStatsHyperVVirtualNetworkAdapterDropReasons(IInfrastructureObjectScope scope, CimInstance instance) : base(scope, instance)
 {
 }
예제 #33
0
 public MsvmMemorySettingData(IInfrastructureObjectScope scope, CimInstance instance) : base(scope, instance)
 {
 }
예제 #34
0
 protected CIMFileSystem(IInfrastructureObjectScope scope, CimInstance instance) : base(scope, instance)
 {
 }
예제 #35
0
        public void WriteCimInstance(CimInstance namedInstance)
        {
            //<VALUE.NAMEDINSTANCE>
            this.WriteNamedInstanceElement();
            this.WriteCimInstanceName(namedInstance.InstanceName);
            this.WriteUnnamedCimInstance(namedInstance);

            //</VALUE.NAMEDINSTANCE>
            this.WriteEndElement();
        }
예제 #36
0
 protected abstract bool IsMatchCore(CimInstance cimInstance);
예제 #37
0
 /// <summary>
 /// Retrieve the reference object or reference array object.
 /// The returned object has to be either CimInstance or CImInstance[] type,
 /// if not thrown exception.
 /// </summary>
 /// <param name="value"></param>
 /// <param name="referenceType">output the cimtype of the value, either Reference or ReferenceArray</param>
 /// <returns></returns>
 protected object GetReferenceOrReferenceArrayObject(object value, ref CimType referenceType)
 {
     PSReference cimReference = value as PSReference;
     if (cimReference != null)
     {
         object baseObject = GetBaseObject(cimReference.Value);
         CimInstance cimInstance = baseObject as CimInstance;
         if (cimInstance == null)
         {
             return null;
         }
         referenceType = CimType.Reference;
         return cimInstance;
     }
     else
     {
         object[] cimReferenceArray = value as object[];
         if (cimReferenceArray == null)
         {
             return null;
         }
         else if (!(cimReferenceArray[0] is PSReference))
         {
             return null;
         }
         CimInstance[] cimInstanceArray = new CimInstance[cimReferenceArray.Length];
         for (int i = 0; i < cimReferenceArray.Length; i++)
         {
             PSReference tempCimReference = cimReferenceArray[i] as PSReference;
             if (tempCimReference == null)
             {
                 return null;
             }
             object baseObject = GetBaseObject(tempCimReference.Value);
             cimInstanceArray[i] = baseObject as CimInstance;
             if (cimInstanceArray[i] == null)
             {
                 return null;
             }
         }
         referenceType = CimType.ReferenceArray;
         return cimInstanceArray;
     }
 }
예제 #38
0
 protected override bool IsMatchCore(CimInstance cimInstance)
 {
     return(true); // the fact that this method is getting called means that CIM found associated instances (i.e. by definition the argument *is* matching)
 }
예제 #39
0
 /// <summary>
 /// Modify cim instance asynchronously
 /// </summary>
 /// <param name="namespaceName"></param>
 /// <param name="instance"></param>
 public void ModifyInstanceAsync(string namespaceName, CimInstance instance)
 {
     Debug.Assert(instance != null, "Caller should verify that instance != NULL.");
     DebugHelper.WriteLogEx("namespace = {0}; classname = {1}", 0, namespaceName, instance.CimSystemProperties.ClassName);
     this.CheckAvailability();
     this.targetCimInstance = instance;
     this.operationName = Strings.CimOperationNameModifyInstance;
     this.operationParameters.Clear();
     this.operationParameters.Add(@"namespaceName", namespaceName);
     this.operationParameters.Add(@"instance", instance);
     this.WriteOperationStartMessage(this.operationName, this.operationParameters);
     CimAsyncResult<CimInstance> asyncResult = this.session.ModifyInstanceAsync(namespaceName, instance, this.options);
     ConsumeObjectAsync(asyncResult, new CimResultContext(instance));
 }
예제 #40
0
 public Win32LogicalFileAuditing(IInfrastructureObjectScope scope, CimInstance instance) : base(scope, instance)
 {
 }
예제 #41
0
 /// <summary>
 /// <para>
 /// Enumerate referencing instance associated with
 /// the given instance asynchronously
 /// </para>
 /// </summary>
 /// <param name="namespaceName"></param>
 /// <param name="sourceInstance"></param>
 /// <param name="associationClassName"></param>
 /// <param name="sourceRole"></param>
 public void EnumerateReferencingInstancesAsync(
     string namespaceName,
     CimInstance sourceInstance,
     string associationClassName,
     string sourceRole)
 {
     this.CheckAvailability();
 }
예제 #42
0
 protected CIMService(IInfrastructureObjectScope scope, CimInstance instance) : base(scope, instance)
 {
 }
예제 #43
0
 /// <summary>
 /// Create <see cref="CimSession"/> by given computer name.
 /// Then create wrapper object.
 /// </summary>
 /// <param name="computerName"></param>
 /// <param name="cimInstance"></param>
 /// <param name="passThru"></param>
 public CimSessionProxySetCimInstance(string computerName,
     CimInstance cimInstance,
     bool passThru)
     : base(computerName, cimInstance)
 {
     this.passThru = passThru;
 }
예제 #44
0
 public MsvmServicingSettings(IInfrastructureObjectScope scope, CimInstance instance) : base(scope, instance)
 {
 }
예제 #45
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="proxy"></param>
 internal InvocationContext(string computerName, CimInstance targetCimInstance)
 {
     this.ComputerName = computerName;
     this.TargetCimInstance = targetCimInstance;
 }
예제 #46
0
 protected CIMPotsModem(IInfrastructureObjectScope scope, CimInstance instance) : base(scope, instance)
 {
 }
예제 #47
0
        /// <summary>
        /// <para>
        /// Remove <see cref="CimInstance"/> from namespace specified in cmdlet
        /// </para>
        /// </summary>
        /// <param name="cimInstance"></param>
        internal void RemoveCimInstance(CimInstance cimInstance, XOperationContextBase context, CmdletOperationBase cmdlet)
        {
            DebugHelper.WriteLogEx();

            string target = cimInstance.ToString();
            if (!cmdlet.ShouldProcess(target, action))
            {
                return;
            }

            CimRemoveCimInstanceContext removeContext = context as CimRemoveCimInstanceContext;
            Debug.Assert(removeContext != null, "CimRemoveCimInstance::RemoveCimInstance should has CimRemoveCimInstanceContext != NULL.");

            CimSessionProxy proxy = CreateCimSessionProxy(removeContext.Proxy);
            proxy.DeleteInstanceAsync(removeContext.Namespace, cimInstance);
        }
예제 #48
0
 protected CIMRedundancyGroup(IInfrastructureObjectScope scope, CimInstance instance) : base(scope, instance)
 {
 }
예제 #49
0
        /// <summary>
        /// <para>
        /// Create <see cref="CimInstance"/> with given properties.
        /// </para>
        /// </summary>
        /// <param name="className"></param>
        /// <param name="key"></param>
        /// <param name="properties"></param>
        /// <param name="cmdlet"></param>
        /// <returns></returns>
        /// <exception cref="ArgumentNullException">See CimProperty.Create</exception>
        /// <exception cref="ArgumentException">CimProperty.Create</exception>
        private CimInstance CreateCimInstance(
            string className,
            string cimNamespace,
            IEnumerable<string> key,
            IDictionary properties,
            NewCimInstanceCommand cmdlet)
        {
            CimInstance cimInstance = new CimInstance(className,cimNamespace);
            if (properties == null)
            {
                return cimInstance;
            }
            
            List<string> keys = new List<string>();
            if (key != null)
            {
                foreach (string keyName in key)
                {
                    keys.Add(keyName);
                }
            }

            IDictionaryEnumerator enumerator = properties.GetEnumerator();
            while (enumerator.MoveNext())
            {
                CimFlags flag = CimFlags.None;
                string propertyName = enumerator.Key.ToString().Trim();
                if (keys.Contains(propertyName, StringComparer.OrdinalIgnoreCase))
                {
                    flag = CimFlags.Key;
                }
                object propertyValue = GetBaseObject(enumerator.Value);

                DebugHelper.WriteLog("Create and add new property to ciminstance: name = {0}; value = {1}; flags = {2}", 5, propertyName, propertyValue, flag);

                PSReference cimReference =  propertyValue as PSReference;
                if( cimReference != null )
                {
                    CimProperty newProperty = CimProperty.Create(propertyName, GetBaseObject(cimReference.Value), CimType.Reference, flag);
                    cimInstance.CimInstanceProperties.Add(newProperty);
                }
                else
                {
                    CimProperty newProperty = CimProperty.Create(
                        propertyName,
                        propertyValue,
                        flag);
                    cimInstance.CimInstanceProperties.Add(newProperty);
                }
                
            }
            return cimInstance;
        }
 public Win32PerfRawDataCountersVFPQoSQueueAverageOutboundNetworkTraffic(IInfrastructureObjectScope scope, CimInstance instance) : base(scope, instance)
 {
 }
예제 #51
0
 /// <summary>
 /// <para>
 /// Create <see cref="CimSessionProxy"/> and set properties
 /// </para>
 /// </summary>
 /// <param name="computerName"></param>
 /// <param name="cimInstance"></param>
 /// <param name="cmdlet"></param>
 /// <returns></returns>
 protected CimSessionProxy CreateSessionProxy(
     string computerName,
     CimInstance cimInstance,
     CimBaseCommand cmdlet)
 {
     CimSessionProxy proxy = CreateCimSessionProxy(computerName, cimInstance);
     SetSessionProxyProperties(ref proxy, cmdlet);
     return proxy;
 }
예제 #52
0
        /// <summary>
        /// <para>
        /// Refactor to be reused by Get-CimInstance;Remove-CimInstance;Set-CimInstance
        /// </para>
        /// </summary>
        /// <param name="cmdlet"></param>
        protected void GetCimInstanceInternal(CimBaseCommand cmdlet)
        {
            IEnumerable <string> computerNames = ConstValue.GetComputerNames(
                GetComputerName(cmdlet));
            string nameSpace;
            List <CimSessionProxy> proxys       = new List <CimSessionProxy>();
            bool        isGetCimInstanceCommand = (cmdlet is GetCimInstanceCommand);
            CimInstance targetCimInstance       = null;

            switch (cmdlet.ParameterSetName)
            {
            case CimBaseCommand.CimInstanceComputerSet:
                foreach (string computerName in computerNames)
                {
                    targetCimInstance = GetCimInstanceParameter(cmdlet);
                    CimSessionProxy proxy = CreateSessionProxy(computerName, targetCimInstance, cmdlet);
                    if (isGetCimInstanceCommand)
                    {
                        this.SetPreProcess(proxy, cmdlet as GetCimInstanceCommand);
                    }

                    proxys.Add(proxy);
                }

                break;

            case CimBaseCommand.ClassNameComputerSet:
            case CimBaseCommand.QueryComputerSet:
            case CimBaseCommand.ResourceUriComputerSet:
                foreach (string computerName in computerNames)
                {
                    CimSessionProxy proxy = CreateSessionProxy(computerName, cmdlet);
                    if (isGetCimInstanceCommand)
                    {
                        this.SetPreProcess(proxy, cmdlet as GetCimInstanceCommand);
                    }

                    proxys.Add(proxy);
                }

                break;

            case CimBaseCommand.ClassNameSessionSet:
            case CimBaseCommand.CimInstanceSessionSet:
            case CimBaseCommand.QuerySessionSet:
            case CimBaseCommand.ResourceUriSessionSet:
                foreach (CimSession session in GetCimSession(cmdlet))
                {
                    CimSessionProxy proxy = CreateSessionProxy(session, cmdlet);
                    if (isGetCimInstanceCommand)
                    {
                        this.SetPreProcess(proxy, cmdlet as GetCimInstanceCommand);
                    }

                    proxys.Add(proxy);
                }

                break;

            default:
                break;
            }

            switch (cmdlet.ParameterSetName)
            {
            case CimBaseCommand.ClassNameComputerSet:
            case CimBaseCommand.ClassNameSessionSet:
                nameSpace = ConstValue.GetNamespace(GetNamespace(cmdlet));
                if (IsClassNameQuerySet(cmdlet))
                {
                    string query = CreateQuery(cmdlet);
                    DebugHelper.WriteLogEx(@"Query = {0}", 1, query);
                    foreach (CimSessionProxy proxy in proxys)
                    {
                        proxy.QueryInstancesAsync(nameSpace,
                                                  ConstValue.GetQueryDialectWithDefault(GetQueryDialect(cmdlet)),
                                                  query);
                    }
                }
                else
                {
                    foreach (CimSessionProxy proxy in proxys)
                    {
                        proxy.EnumerateInstancesAsync(nameSpace, GetClassName(cmdlet));
                    }
                }

                break;

            case CimBaseCommand.CimInstanceComputerSet:
            case CimBaseCommand.CimInstanceSessionSet:
            {
                CimInstance instance = GetCimInstanceParameter(cmdlet);
                nameSpace = ConstValue.GetNamespace(instance.CimSystemProperties.Namespace);
                foreach (CimSessionProxy proxy in proxys)
                {
                    proxy.GetInstanceAsync(nameSpace, instance);
                }
            }

            break;

            case CimBaseCommand.QueryComputerSet:
            case CimBaseCommand.QuerySessionSet:
                nameSpace = ConstValue.GetNamespace(GetNamespace(cmdlet));
                foreach (CimSessionProxy proxy in proxys)
                {
                    proxy.QueryInstancesAsync(nameSpace,
                                              ConstValue.GetQueryDialectWithDefault(GetQueryDialect(cmdlet)),
                                              GetQuery(cmdlet));
                }

                break;

            case CimBaseCommand.ResourceUriSessionSet:
            case CimBaseCommand.ResourceUriComputerSet:
                foreach (CimSessionProxy proxy in proxys)
                {
                    proxy.EnumerateInstancesAsync(GetNamespace(cmdlet), GetClassName(cmdlet));
                }

                break;

            default:
                break;
            }
        }
예제 #53
0
        /// <summary>
        /// <para>
        /// Set the properties value to be modified to the given
        /// <see cref="CimInstance"/>
        /// </para>
        /// </summary>
        /// <param name="properties"></param>
        /// <param name="cimInstance"></param>
        /// <param name="terminationMessage"></param>
        /// <returns></returns>
        private bool SetProperty(IDictionary properties, ref CimInstance cimInstance, ref Exception exception)
        {
            DebugHelper.WriteLogEx();
            if (properties.Count == 0)
            {
                // simply ignore if empty properties was provided
                return true;
            }
            IDictionaryEnumerator enumerator = properties.GetEnumerator();
            while (enumerator.MoveNext())
            {
                object value = GetBaseObject(enumerator.Value);
                string key = enumerator.Key.ToString();
                DebugHelper.WriteLog("Input property name '{0}' with value '{1}'", 1, key, value);

                try
                {
                    CimProperty property = cimInstance.CimInstanceProperties[key];
                    // modify existing property value if found
                    if (property != null)
                    {
                        if ((property.Flags & CimFlags.ReadOnly) == CimFlags.ReadOnly)
                        {
                            // can not modify ReadOnly property
                            exception = new CimException(String.Format(CultureInfo.CurrentUICulture,
                                Strings.CouldNotModifyReadonlyProperty, key, cimInstance));
                            return false;
                        }
                        // allow modify the key property value as long as it is not readonly,
                        // then the modified ciminstance is stand for a different CimInstance
                        DebugHelper.WriteLog("Set property name '{0}' has old value '{1}'", 4, key, property.Value);
                        property.Value = value;
                    }
                    else // For dynamic instance, it is valid to add a new property
                    {
                        CimProperty newProperty;
                        if( value == null )
                        {
                            newProperty = CimProperty.Create(
                                key,
                                value,
                                CimType.String,
                                CimFlags.Property);
                        }
                        else
                        {
                            CimType referenceType = CimType.Unknown;
                            object referenceObject = GetReferenceOrReferenceArrayObject(value, ref referenceType);
                            if (referenceObject != null)
                            {
                                newProperty = CimProperty.Create(
                                    key,
                                    referenceObject,
                                    referenceType,
                                    CimFlags.Property);
                            }
                            else
                            {
                                newProperty = CimProperty.Create(
                                    key,
                                    value,
                                    CimFlags.Property);
                            }
                        }
                        try
                        {
                            cimInstance.CimInstanceProperties.Add(newProperty);
                        }
                        catch (CimException e)
                        {
                            if (e.NativeErrorCode == NativeErrorCode.Failed)
                            {
                                string errorMessage = String.Format(CultureInfo.CurrentUICulture,
                                    Strings.UnableToAddPropertyToInstance,
                                    newProperty.Name,
                                    cimInstance);
                                exception = new CimException(errorMessage, e);
                            }
                            else
                            {
                                exception = e;
                            }
                            return false;
                        }
                        DebugHelper.WriteLog("Add non-key property name '{0}' with value '{1}'.", 3, key, value);
                    }
                }
                catch (Exception e)
                {
                    DebugHelper.WriteLog("Exception {0}", 4, e);
                    exception = e;
                    return false;
                }
            }
            return true;
        }
예제 #54
0
 public MSFTNetAdapter(IInfrastructureObjectScope scope, CimInstance instance) : base(scope, instance)
 {
 }
예제 #55
0
 /// <summary>
 /// Constructor with an <see cref="CimInstance"/> error
 /// </summary>
 /// <param name="error"></param>
 public CimWriteError(CimInstance error, InvocationContext context)
 {
     this.error = error;
     this.invocationContext = context;
 }
예제 #56
0
 /// <summary>
 /// <para>
 /// Create <see cref="CimSessionProxy"/> and set properties
 /// </para>
 /// </summary>
 /// <param name="computerName"></param>
 /// <param name="cimInstance"></param>
 /// <param name="cmdlet"></param>
 /// <returns></returns>
 private CimSessionProxy CreateSessionProxy(
     string computerName,
     CimInstance cimInstance,
     GetCimAssociatedInstanceCommand cmdlet)
 {
     CimSessionProxy proxy = CreateCimSessionProxy(computerName, cimInstance);
     SetSessionProxyProperties(ref proxy, cmdlet);
     return proxy;
 }