Exemple #1
0
 public byte[] Serialize(CimClass cimClass, ClassSerializationOptions options)
 {
     unsafe
     {
         if (cimClass != null)
         {
             this.AssertNotDisposed();
             int num = 0;
             this.Serialize(cimClass, options, null, ref num);
             byte[] numArray = new byte[num];
             int    num1     = 0;
             this.Serialize(cimClass, options, numArray, ref num1);
             return(numArray);
         }
         else
         {
             throw new ArgumentNullException("cimClass");
         }
     }
 }
        private List <CimClass> GetInheritanceChain(CimInstance cimInstance)
        {
            List <CimClass> inheritanceChain = new List <CimClass>();
            CimClass        cimClass         = cimInstance.CimClass;

            Dbg.Assert(cimClass != null, "CimInstance should always have ClassDecl");
            while (cimClass != null)
            {
                inheritanceChain.Add(cimClass);
                try
                {
                    cimClass = cimClass.CimSuperClass;
                }
                catch (CimException)
                {
                    break;
                }
            }
            return(inheritanceChain);
        }
        private CimInstance ConvertToAtLogon(ScheduledJobTrigger trigger, CimSession cimSession)
        {
            string      user;
            CimClass    @class      = cimSession.GetClass(JobTriggerToCimInstanceConverter.CIM_TRIGGER_NAMESPACE, "MSFT_TaskLogonTrigger");
            CimInstance cimInstance = new CimInstance(@class);

            cimInstance.CimInstanceProperties["Delay"].Value = ScheduledJobWTS.ConvertTimeSpanToWTSString(trigger.RandomDelay);
            if (ScheduledJobTrigger.IsAllUsers(trigger.User))
            {
                user = null;
            }
            else
            {
                user = trigger.User;
            }
            string str = user;

            cimInstance.CimInstanceProperties["UserId"].Value = str;
            JobTriggerToCimInstanceConverter.AddCommonProperties(trigger, cimInstance);
            return(cimInstance);
        }
Exemple #4
0
        private List <CimClass> GetInheritanceChain(CimInstance cimInstance)
        {
            List <CimClass> list     = new List <CimClass>();
            CimClass        cimClass = cimInstance.CimClass;

            while (cimClass != null)
            {
                list.Add(cimClass);
                try
                {
                    cimClass = cimClass.CimSuperClass;
                    if (cimClass == null)
                    {
                        break;
                    }
                    continue;
                }
                catch (CimException)
                {
                    return(list);
                }
            }
            return(list);
        }
Exemple #5
0
 /// <summary>
 /// Serializes the <paramref name="cimClass"/>
 /// </summary>
 /// <param name="cimClass">Class to serialize</param>
 /// <param name="options">Serialization options</param>
 /// <returns>Serialized representation of <paramref name="cimClass"/></returns>
 public byte[] Serialize(CimClass cimClass, ClassSerializationOptions options)
 {
     /*
      *  if (cimClass == null)
      *  {
      *      throw new ArgumentNullException("cimClass");
      *  }
      *  this.AssertNotDisposed();
      *
      *  bool dataFitsIntoBuffer;
      *  uint requiredBufferSize = 0;
      *  dataFitsIntoBuffer = Serialize(cimClass, options, null, ref requiredBufferSize);
      *  Debug.Assert(!dataFitsIntoBuffer, "Passing null buffer - data cannot possibly fit into this buffer");
      *
      *  byte[] buffer = new byte[requiredBufferSize];
      *  uint offset = 0;
      *  dataFitsIntoBuffer = Serialize(cimClass, options, buffer, ref offset);
      *  Debug.Assert(dataFitsIntoBuffer, "Newly allocated buffer should fit (1)");
      *  Debug.Assert(buffer.Length == offset, "Newly allocated buffer should fit exactly (2)");
      *
      *  return buffer;
      */
     return(new byte[1]);
 }
        internal static Dictionary <string, object> GetKeyValues(CimSession cimSession, string cimNamespace, string cimClassName)
        {
            Dictionary <string, object> propertyValues = new Dictionary <string, object>();

            try
            {
                CimClass cimClass      = cimSession.GetClass(cimNamespace, cimClassName);
                var      keyProperties = from p in cimClass.CimClassProperties where ((p.Flags & CimFlags.Key) == CimFlags.Key) select p;
                foreach (CimPropertyDeclaration keyProperty in keyProperties)
                {
                    Console.Write("Please type Key value for Property '" + keyProperty.Name + "' of Type:({0}) ", keyProperty.CimType);
                    string propertyValue = Console.ReadLine();
                    propertyValues.Add(keyProperty.Name, propertyValue);
                }
            }
            catch (CimException exception)
            {
                Console.WriteLine("Unable to get schema for class " + cimClassName + " in namespace " + cimNamespace);
                PrintCimException(exception);
                return(null);
            }

            return(propertyValues);
        }
        internal static CimMethodParametersCollection InvokeMethodCore(
            CimSession cimSession,
            string cimNamespace,
            string cimClassName,
            out string cimMethodName,
            out CimInstance inputInstance)
        {
            CimMethodParametersCollection methodParameters = new CimMethodParametersCollection();

            inputInstance = null;
            cimMethodName = null;
            bool isStaticMethod = false;

            try
            {
                CimClass cimClass = cimSession.GetClass(cimNamespace, cimClassName);

                // Print Methods
                foreach (CimMethodDeclaration methodDecl in cimClass.CimClassMethods)
                {
                    Console.WriteLine("Method Name = " + methodDecl.Name);
                }

                cimMethodName = DotNetSample.GetName("Method Name");
                if (cimClass.CimClassMethods[cimMethodName].Qualifiers["static"] != null)
                {
                    isStaticMethod = true;
                }

                foreach (CimMethodParameterDeclaration methodParameter in cimClass.CimClassMethods[cimMethodName].Parameters)
                {
                    bool bInQualifier = (methodParameter.Qualifiers["In"] != null);
                    if (bInQualifier)
                    {
                        Console.Write("Please type value for Parameter '" + methodParameter.Name + "' of Type:({0}) ", methodParameter.CimType);
                        string parameterValue = Console.ReadLine();
                        if (!String.IsNullOrEmpty(parameterValue))
                        {
                            methodParameters.Add(CimMethodParameter.Create(methodParameter.Name, parameterValue, methodParameter.CimType, 0));
                        }
                    }
                }

                // Get the instance if method is not static
                if (!isStaticMethod)
                {
                    // Get the instances for this class.
                    List <CimInstance> list = GetAndPrintInstances(cimSession, cimNamespace, cimClassName);
                    if (list == null || list.Count == 0)
                    {
                        Console.WriteLine("InvokeMethodCore operation not performed");
                        return(null);
                    }

                    while (true)
                    {
                        Console.WriteLine("On which instance do you want to invoke the method");
                        string instanceId = Console.ReadLine();
                        int    result;
                        if (String.IsNullOrEmpty(instanceId) || int.TryParse(instanceId, out result) == false || result >= list.Count)
                        {
                            Console.WriteLine("Please type the instance Id in the range {0} to {1}", 0, list.Count - 1);
                        }
                        else
                        {
                            inputInstance = (CimInstance)list[result];
                            break;
                        }
                    }
                }
            }
            catch (CimException exception)
            {
                Console.WriteLine("Unable to get schema for class '" + cimClassName + "' in namespace " + cimNamespace);
                PrintCimException(exception);
                return(null);
            }

            return(methodParameters);
        }
Exemple #8
0
        public CimClass DeserializeClass(byte[] serializedData, ref int offset, CimClass parentClass, string computerName, string namespaceName)
        {
            ClassHandle classHandle = this.DeserializeClassHandle(serializedData, ref offset, parentClass, computerName, namespaceName);

            return(new CimClass(classHandle));
        }
Exemple #9
0
 internal ClassHandle DeserializeClassHandle(byte[] serializedData, ref int offset, CimClass parentClass, string computerName, string namespaceName)
 {
     return(null);
 }
        protected override bool PreNewActionEvent(CmdletActionEventArgs args)
        {
            WildcardPattern wildcardPattern;

            DebugHelper.WriteLogEx();
            if (args.Action as CimWriteResultObject != null)
            {
                CimWriteResultObject action = args.Action as CimWriteResultObject;
                CimClass             result = action.Result as CimClass;
                if (result != null)
                {
                    object[] className = new object[1];
                    className[0] = result.CimSystemProperties.ClassName;
                    DebugHelper.WriteLog("class name = {0}", 1, className);
                    CimGetCimClassContext contextObject = base.ContextObject as CimGetCimClassContext;
                    if (WildcardPattern.ContainsWildcardCharacters(contextObject.ClassName))
                    {
                        wildcardPattern = new WildcardPattern(contextObject.ClassName, WildcardOptions.IgnoreCase);
                        if (!wildcardPattern.IsMatch(result.CimSystemProperties.ClassName))
                        {
                            return(false);
                        }
                    }
                    if (contextObject.PropertyName != null)
                    {
                        wildcardPattern = new WildcardPattern(contextObject.PropertyName, WildcardOptions.IgnoreCase);
                        bool flag = false;
                        if (result.CimClassProperties != null)
                        {
                            foreach (CimPropertyDeclaration cimClassProperty in result.CimClassProperties)
                            {
                                object[] name = new object[1];
                                name[0] = cimClassProperty.Name;
                                DebugHelper.WriteLog("--- property name : {0}", 1, name);
                                if (!wildcardPattern.IsMatch(cimClassProperty.Name))
                                {
                                    continue;
                                }
                                flag = true;
                                break;
                            }
                        }
                        if (!flag)
                        {
                            object[] propertyName = new object[1];
                            propertyName[0] = contextObject.PropertyName;
                            DebugHelper.WriteLog("Property name does not match: {0}", 1, propertyName);
                            return(flag);
                        }
                    }
                    if (contextObject.MethodName != null)
                    {
                        wildcardPattern = new WildcardPattern(contextObject.MethodName, WildcardOptions.IgnoreCase);
                        bool flag1 = false;
                        if (result.CimClassMethods != null)
                        {
                            foreach (CimMethodDeclaration cimClassMethod in result.CimClassMethods)
                            {
                                object[] objArray = new object[1];
                                objArray[0] = cimClassMethod.Name;
                                DebugHelper.WriteLog("--- method name : {0}", 1, objArray);
                                if (!wildcardPattern.IsMatch(cimClassMethod.Name))
                                {
                                    continue;
                                }
                                flag1 = true;
                                break;
                            }
                        }
                        if (!flag1)
                        {
                            object[] methodName = new object[1];
                            methodName[0] = contextObject.MethodName;
                            DebugHelper.WriteLog("Method name does not match: {0}", 1, methodName);
                            return(flag1);
                        }
                    }
                    if (contextObject.QualifierName != null)
                    {
                        wildcardPattern = new WildcardPattern(contextObject.QualifierName, WildcardOptions.IgnoreCase);
                        bool flag2 = false;
                        if (result.CimClassQualifiers != null)
                        {
                            foreach (CimQualifier cimClassQualifier in result.CimClassQualifiers)
                            {
                                object[] name1 = new object[1];
                                name1[0] = cimClassQualifier.Name;
                                DebugHelper.WriteLog("--- qualifier name : {0}", 1, name1);
                                if (!wildcardPattern.IsMatch(cimClassQualifier.Name))
                                {
                                    continue;
                                }
                                flag2 = true;
                                break;
                            }
                        }
                        if (!flag2)
                        {
                            object[] qualifierName = new object[1];
                            qualifierName[0] = contextObject.QualifierName;
                            DebugHelper.WriteLog("Qualifer name does not match: {0}", 1, qualifierName);
                            return(flag2);
                        }
                    }
                    object[] className1 = new object[1];
                    className1[0] = result.CimSystemProperties.ClassName;
                    DebugHelper.WriteLog("CimClass '{0}' is qulified.", 1, className1);
                    return(true);
                }
                else
                {
                    return(true);
                }
            }
            else
            {
                return(true);
            }
        }
Exemple #11
0
 public CimClass DeserializeClass(byte[] serializedData, ref int offset, CimClass parentClass)
 {
     return(this.DeserializeClass(serializedData, ref offset, parentClass, null, null));
 }
Exemple #12
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;
 }
        /// <summary>
        /// Returns a configured instance of System.Management.Automation.PowerShell, pre-populated with the command to run.
        /// </summary>
        /// <param name="context">The NativeActivityContext for the currently running activity.</param>
        /// <returns>A populated instance of System.Management.Automation.PowerShell</returns>
        /// <remarks>The infrastructure takes responsibility for closing and disposing the PowerShell instance returned.</remarks>
        protected override ActivityImplementationContext GetPowerShell(NativeActivityContext context)
        {
            System.Management.Automation.PowerShell invoker       = global::System.Management.Automation.PowerShell.Create();
            System.Management.Automation.PowerShell targetCommand = invoker.AddCommand(PSCommandName);

            // Initialize the arguments

            if (ClassName.Expression != null)
            {
                targetCommand.AddParameter("ClassName", ClassName.Get(context));
            }

            if (Key.Expression != null)
            {
                targetCommand.AddParameter("Key", Key.Get(context));
            }

            if (CimClass.Expression != null)
            {
                targetCommand.AddParameter("CimClass", CimClass.Get(context));
            }

            if (Property.Expression != null)
            {
                targetCommand.AddParameter("Property", Property.Get(context));
            }

            if (Namespace.Expression != null)
            {
                targetCommand.AddParameter("Namespace", Namespace.Get(context));
            }

            if (OperationTimeoutSec.Expression != null)
            {
                targetCommand.AddParameter("OperationTimeoutSec", OperationTimeoutSec.Get(context));
            }

            if (ResourceUri != null)
            {
                targetCommand.AddParameter("ResourceUri", ResourceUri.Get(context));
            }

            if (ClientOnly.Expression != null)
            {
                // Retrieve our host overrides
                var      hostValues   = context.GetExtension <HostParameterDefaults>();
                string[] computerName = null;

                if (hostValues != null)
                {
                    Dictionary <string, object> incomingArguments = hostValues.Parameters;
                    if (incomingArguments.ContainsKey("PSComputerName"))
                    {
                        computerName = incomingArguments["PSComputerName"] as string[];
                    }
                }

                if (computerName == null)
                {
                    targetCommand.AddParameter("ClientOnly", ClientOnly.Get(context));
                }
            }


            return(new ActivityImplementationContext()
            {
                PowerShellInstance = invoker
            });
        }
Exemple #14
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;
        }
Exemple #15
0
 public bool Serialize(CimClass cimClass, ClassSerializationOptions options, byte[] buffer, ref uint offset)
 {
     /*
      *  if (cimClass == null)
      *  {
      *      throw new ArgumentNullException("cimClass");
      *  }
      *  if (buffer == null)
      *  {
      *      if (offset != 0)
      *      {
      *          throw new ArgumentNullException("buffer");
      *      }
      *  }
      *  else
      *  {
      *      if (offset > buffer.Length) // offset == buffer.Length points outside of buffer, but is ok
      *      {
      *          throw new ArgumentOutOfRangeException("offset");
      *      }
      *      else if (offset == buffer.Length)
      *      {
      *          buffer = null;
      *      }
      *  }
      *  this.AssertNotDisposed();
      *
      *  bool doesDataFitIntoTheBuffer = true;
      *
      *  uint numberOfBytesUsed;
      *  MI_Result result = Native.SerializerMethods.SerializeClass(
      *      this._myHandle,
      *      (UInt32)options,
      *      cimClass.ClassHandle,
      *      buffer,
      *      offset,
      *      out numberOfBytesUsed);
      *  switch (result)
      *  {
      *      case MI_Result.MI_RESULT_FAILED:
      *          if ((buffer == null) || ((offset + numberOfBytesUsed) > buffer.Length))
      *          {
      *              result = MI_Result.MI_RESULT_OK;
      *              offset += numberOfBytesUsed;
      *          }
      *          doesDataFitIntoTheBuffer = false;
      *          return doesDataFitIntoTheBuffer;
      *
      *      case MI_Result.MI_RESULT_OK:
      *          offset += numberOfBytesUsed;
      *          doesDataFitIntoTheBuffer = true;
      *          return doesDataFitIntoTheBuffer;
      *
      *      default:
      *          CimException.ThrowIfMiResultFailure(result);
      *          Debug.Assert(false, "Should throw in the previous statement");
      *          return doesDataFitIntoTheBuffer;
      *  }
      */
     return(false);
 }
Exemple #16
0
 public ClassHandler(CimSession cimSession, string className)
 {
     this.cimSession = cimSession;
     this.cimClass   = cimSession.GetClass(CimNamespace, className);
     this.className  = className;
 }
Exemple #17
0
        /// <summary>
        /// Returns a configured instance of System.Management.Automation.PowerShell, pre-populated with the command to run.
        /// </summary>
        /// <param name="context">The NativeActivityContext for the currently running activity.</param>
        /// <returns>A populated instance of System.Management.Automation.PowerShell</returns>
        /// <remarks>The infrastructure takes responsibility for closing and disposing the PowerShell instance returned.</remarks>
        protected override ActivityImplementationContext GetPowerShell(NativeActivityContext context)
        {
            System.Management.Automation.PowerShell invoker       = global::System.Management.Automation.PowerShell.Create();
            System.Management.Automation.PowerShell targetCommand = invoker.AddCommand(PSCommandName);

            // Initialize the arguments

            if (ClassName.Expression != null)
            {
                targetCommand.AddParameter("ClassName", ClassName.Get(context));
            }

            if (CimClass.Expression != null)
            {
                targetCommand.AddParameter("CimClass", CimClass.Get(context));
            }

            if (Query.Expression != null)
            {
                targetCommand.AddParameter("Query", Query.Get(context));
            }

            if (QueryDialect.Expression != null)
            {
                targetCommand.AddParameter("QueryDialect", QueryDialect.Get(context));
            }

            if (InputObject.Expression != null)
            {
                targetCommand.AddParameter("InputObject", InputObject.Get(context));
            }

            if (Arguments.Expression != null)
            {
                targetCommand.AddParameter("Arguments", Arguments.Get(context));
            }

            if (MethodName.Expression != null)
            {
                targetCommand.AddParameter("MethodName", MethodName.Get(context));
            }

            if (Namespace.Expression != null)
            {
                targetCommand.AddParameter("Namespace", Namespace.Get(context));
            }

            if (OperationTimeoutSec.Expression != null)
            {
                targetCommand.AddParameter("OperationTimeoutSec", OperationTimeoutSec.Get(context));
            }

            if (ResourceUri != null)
            {
                targetCommand.AddParameter("ResourceUri", ResourceUri.Get(context));
            }

            return(new ActivityImplementationContext()
            {
                PowerShellInstance = invoker
            });
        }
Exemple #18
0
        private CimMethodParametersCollection CreateParametersCollection(IDictionary parameters, CimClass cimClass, CimInstance cimInstance, string methodName)
        {
            DebugHelper.WriteLogEx();
            CimMethodParametersCollection cimMethodParametersCollection = null;

            if (parameters != null)
            {
                if (parameters.Count != 0)
                {
                    cimMethodParametersCollection = new CimMethodParametersCollection();
                    IDictionaryEnumerator enumerator = parameters.GetEnumerator();
                    while (enumerator.MoveNext())
                    {
                        string   str        = enumerator.Key.ToString();
                        CimFlags cimFlag    = CimFlags.In;
                        object   baseObject = base.GetBaseObject(enumerator.Value);
                        object[] objArray   = new object[3];
                        objArray[0] = str;
                        objArray[1] = baseObject;
                        objArray[2] = cimFlag;
                        DebugHelper.WriteLog("Create parameter name= {0}, value= {1}, flags= {2}.", 4, objArray);
                        CimMethodParameter   cimMethodParameter = null;
                        CimMethodDeclaration item = null;
                        string className          = null;
                        if (cimClass == null)
                        {
                            if (cimInstance != null)
                            {
                                className = cimInstance.CimClass.CimSystemProperties.ClassName;
                                item      = cimInstance.CimClass.CimClassMethods[methodName];
                            }
                        }
                        else
                        {
                            className = cimClass.CimSystemProperties.ClassName;
                            item      = cimClass.CimClassMethods[methodName];
                            if (item == null)
                            {
                                object[] objArray1 = new object[2];
                                objArray1[0] = methodName;
                                objArray1[1] = className;
                                throw new ArgumentException(string.Format(CultureInfo.CurrentUICulture, Strings.InvalidMethod, objArray1));
                            }
                        }
                        if (item == null)
                        {
                            if (baseObject != null)
                            {
                                CimType cimType = CimType.Unknown;
                                object  referenceOrReferenceArrayObject = base.GetReferenceOrReferenceArrayObject(baseObject, ref cimType);
                                if (referenceOrReferenceArrayObject == null)
                                {
                                    cimMethodParameter = CimMethodParameter.Create(str, baseObject, cimFlag);
                                }
                                else
                                {
                                    cimMethodParameter = CimMethodParameter.Create(str, referenceOrReferenceArrayObject, cimType, cimFlag);
                                }
                            }
                            else
                            {
                                cimMethodParameter = CimMethodParameter.Create(str, baseObject, CimType.String, cimFlag);
                            }
                        }
                        else
                        {
                            CimMethodParameterDeclaration cimMethodParameterDeclaration = item.Parameters[str];
                            if (cimMethodParameterDeclaration != null)
                            {
                                cimMethodParameter = CimMethodParameter.Create(str, baseObject, cimMethodParameterDeclaration.CimType, cimFlag);
                            }
                            else
                            {
                                object[] objArray2 = new object[3];
                                objArray2[0] = str;
                                objArray2[1] = methodName;
                                objArray2[2] = className;
                                throw new ArgumentException(string.Format(CultureInfo.CurrentUICulture, Strings.InvalidMethodParameter, objArray2));
                            }
                        }
                        if (cimMethodParameter == null)
                        {
                            continue;
                        }
                        cimMethodParametersCollection.Add(cimMethodParameter);
                    }
                    return(cimMethodParametersCollection);
                }
                else
                {
                    return(cimMethodParametersCollection);
                }
            }
            else
            {
                return(cimMethodParametersCollection);
            }
        }
Exemple #19
0
        internal MI_Class DeserializeClassHandle(byte[] serializedData, ref uint offset, CimClass parentClass, string computerName, string namespaceName)
        {
            if (serializedData == null)
            {
                throw new ArgumentNullException("serializedData");
            }
            if (offset >= serializedData.Length)
            {
                throw new ArgumentOutOfRangeException("offset");
            }
            this.AssertNotDisposed();

            // TODO: Implement the following function

            /*
             *  MI_Class nativeClassHandle = parentClass != null ? parentClass.ClassHandle : null;
             *
             *  UInt32 inputBufferUsed;
             *  MI_Class deserializedClass;
             *  MI_Instance cimError;
             *  MI_Result result = this._myHandle.DeserializeClass(
             *      0,
             *      serializedData,
             *      offset,
             *      nativeClassHandle,
             *      computerName,
             *      namespaceName,
             *      out deserializedClass,
             *      out inputBufferUsed,
             *      out cimError);
             *  CimException.ThrowIfMiResultFailure(result, cimError);
             *  offset += inputBufferUsed;
             *
             *  return deserializedClass;
             */

            // TODO: remove next line once above is fixed
            return(MI_Class.NewIndirectPtr());
        }
Exemple #20
0
        public void WriteCimClass(CimClass _class)
        {
            //<CLASS NAME="CIM_NFS"SUPERCLASS="CIM_RemoteFileSystem">

            this.WriteClassElement();
            this.WriteCimNameAttributeString(_class.ClassName);
            this.WriteSuperClassAttributeString(_class.SuperClass);

            this.WriteCimQualifierList(_class.Qualifiers);
            this.WriteCimPropertyList(_class.Properties);
            this.WriteCimMethodList(_class.Methods);

            WriteEndElement();
        }
        /// <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);
        }
 public CimTypeDeclaration(CimClass cimClass)
 {
     _cimClass = cimClass;
 }