internal static CimInstance GetAllValues(CimSession cimSession, string cimNamespace, string cimClassName)
        {
            CimInstance instance;
            try
            {
                CimClass cimClass = cimSession.GetClass(cimNamespace, cimClassName);
                instance = new CimInstance(cimClass);
                var cimProperties = from p in cimClass.CimClassProperties select p;
                foreach (CimPropertyDeclaration property in cimProperties)
                {
                    Console.Write("Please type value for Property '" + property.Name + "' of Type:({0}) ", property.CimType);
                    string propertyValue = Console.ReadLine();
                    if (propertyValue != null)
                    {
                        instance.CimInstanceProperties[property.Name].Value = propertyValue;
                    }
                }
            }
            catch (CimException exception)
            {
                Console.WriteLine("Unable to get schema for class " + cimClassName + " in namespace " + cimNamespace);
                PrintCimException(exception);
                return null;
            }

            return instance;
        }
Esempio n. 2
0
		internal static ErrorCategory ConvertCimErrorToErrorCategory(CimInstance cimError)
		{
			ErrorCategory errorCategory = ErrorCategory.NotSpecified;
			if (cimError != null)
			{
				CimProperty item = cimError.CimInstanceProperties["Error_Category"];
				if (item != null)
				{
					if (LanguagePrimitives.TryConvertTo<ErrorCategory>(item.Value, CultureInfo.InvariantCulture, out errorCategory))
					{
						return errorCategory;
					}
					else
					{
						return ErrorCategory.NotSpecified;
					}
				}
				else
				{
					return ErrorCategory.NotSpecified;
				}
			}
			else
			{
				return ErrorCategory.NotSpecified;
			}
		}
		internal EnumerateAssociatedInstancesJob(CimJobContext jobContext, CimQuery cimQuery, CimInstance associatedObject, string associationName, string resultRole, string sourceRole) : base(jobContext, cimQuery)
		{
			this.associatedObject = associatedObject;
			this.associationName = associationName;
			this.resultRole = resultRole;
			this.sourceRole = sourceRole;
		}
 private static PSAdaptedProperty GetPSComputerNameAdapter(CimInstance cimInstance)
 {
     PSAdaptedProperty psComputerNameProperty = new PSAdaptedProperty(RemotingConstants.ComputerNameNoteProperty, cimInstance);
     psComputerNameProperty.baseObject = cimInstance;
     //psComputerNameProperty.adapter = this;
     return psComputerNameProperty;
 }
        internal static void AssociateCimInstanceWithCustomOptions(CimInstance cimInstance, CimCustomOptionsDictionary newCustomOptions)
        {
            if (newCustomOptions == null)
            {
                return;
            }

            lock (newCustomOptions._dictModificationLock)
            {
                if (newCustomOptions._dict.Count == 0)
                {
                    return;
                }
            }

            bool foundAssociatedOptions = true;
            CimCustomOptionsDictionary oldCustomOptions = s_cimInstanceToCustomOptions.GetValue(
                cimInstance,
                delegate
                    {
                        foundAssociatedOptions = false;
                        return newCustomOptions;
                    });

            if (foundAssociatedOptions)
            {
                lock (oldCustomOptions._dictModificationLock)
                {
                    foreach (KeyValuePair<string, object> newCustomOption in newCustomOptions.GetSnapshot())
                    {
                        oldCustomOptions._dict[newCustomOption.Key] = newCustomOption.Value;
                    }
                }
            }
        }
		internal static void AssociateCimInstanceWithCustomOptions(CimInstance cimInstance, CimCustomOptionsDictionary newCustomOptions)
		{
            bool flag = false;
			if (newCustomOptions != null)
			{
				lock (newCustomOptions._dictModificationLock)
				{
					if (newCustomOptions._dict.Count == 0)
					{
						return;
					}
				}
				CimCustomOptionsDictionary value = CimCustomOptionsDictionary.CimInstanceToCustomOptions.GetValue(cimInstance, (CimInstance param0) => {
					flag = false;
					return newCustomOptions;
				}
				);
				if (flag)
				{
					lock (value._dictModificationLock)
					{
						foreach (KeyValuePair<string, object> snapshot in newCustomOptions.GetSnapshot())
						{
							value._dict[snapshot.Key] = snapshot.Value;
						}
					}
				}
				return;
			}
			else
			{
				return;
			}
		}
Esempio n. 7
0
		internal InvocationContext(CimSessionProxy proxy)
		{
			if (proxy != null)
			{
				this.ComputerName = proxy.CimSession.ComputerName;
				this.TargetCimInstance = proxy.TargetCimInstance;
			}
		}
		private static void AddCommonProperties(ScheduledJobTrigger trigger, CimInstance cimInstance)
		{
			cimInstance.CimInstanceProperties["Enabled"].Value = trigger.Enabled;
			DateTime? at = trigger.At;
			if (at.HasValue)
			{
				cimInstance.CimInstanceProperties["StartBoundary"].Value = ScheduledJobWTS.ConvertDateTimeToString(trigger.At);
			}
		}
Esempio n. 9
0
		public bool Serialize(CimInstance cimInstance, InstanceSerializationOptions options, byte[] buffer, ref int offset)
		{
			int num = 0;
			if (cimInstance != null)
			{
				if (buffer != null)
				{
					if ((long)offset <= (long)((int)buffer.Length))
					{
						if ((long)offset == (long)((int)buffer.Length))
						{
							buffer = null;
						}
					}
					else
					{
						throw new ArgumentOutOfRangeException("offset");
					}
				}
				else
				{
					if (offset != 0)
					{
						throw new ArgumentNullException("buffer");
					}
				}
				this.AssertNotDisposed();
				bool flag = true;
                MiResult miResult = MiResult.OK; //TODO: // SerializerMethods.SerializeInstance(this._myHandle, options, cimInstance.InstanceHandle, buffer, offset, out num);
				MiResult miResult1 = miResult;
				switch (miResult1)
				{
					case MiResult.OK:
					{
						offset = offset + num;
						flag = true;
						return flag;
					}
					case MiResult.FAILED:
					{
						if (buffer == null || (long)(offset + num) > (long)((int)buffer.Length))
						{
							miResult = MiResult.OK;
							offset = offset + num;
						}
						flag = false;
						return flag;
					}
				}
				CimException.ThrowIfMiResultFailure(miResult);
				return flag;
			}
			else
			{
				throw new ArgumentNullException("cimInstance");
			}
		}
 internal InstanceMethodInvocationJob(CimJobContext jobContext, bool passThru, CimInstance targetInstance, MethodInvocationInfo methodInvocationInfo)
         : base(
             jobContext,
             passThru,
             targetInstance.ToString(),
             methodInvocationInfo)
 {
     Dbg.Assert(targetInstance != null, "Caller should verify targetInstance != null");
     _targetInstance = targetInstance;
 }
Esempio n. 11
0
        /// <summary>
        /// Adds the given a computer to a collection.
        /// </summary>
        /// <param name="computerName">The name of the computer to add.</param>
        /// <param name="collectionId">The CollectionID of the collection to which the computer will be added.</param>           
        public static bool AddComputerToCollection(string computerName, string collectionId)
        {
            /*
             * Dear Forgetful me. I will explain what happens here so that you NEVER have to figure this out ever again. took you long enough the first time.
             *
             * Step one: cimSession. cimSession is the overall session connection to the remote server. This is SCCM01 in this case. cimSession is also used to call methods
             * of any of the classes in any of the namespaces of the current connection to the current server. whew.
             *
             * Step two: The method that we're going to call takes in a parameter. that parameter in this case is SMS_CollectionRuleDirect. That class takes two properties.
             * since the direct rule that we are creating is a computer, then the two parameters are: SMS_R_System as the class, and the ResourceID of the computer. So the
             * first thing we do is create an instance of the cimCollectionRuleDirect class, and add the two properties that we need (ResourceClassName, ResourceID)
             *
             * Step three: Now that we have the parameter that we want to send to the method, we need to package it as a parameter fit to be sent. so we create a new
             * CimMethodParametersCollection and add cimCollectionRuleDirect to it as the only parameter.
             *
             * Step four: Ok, so now we have the parameter that we need all ready, and all we need to do is call the method and pass it the parameter. We want to call the method
             * on the actual collection that we want the computer added, so we must do a query to find it.
             *
             * Step five: Last step, call the method on the collection.  we use the cimSession connection to invoke the method, and pass in the parameters: 1)the collection
             * whose method we are invoking 2) the name of the method that we are invoking, and 3) the parameter that we are passing. voila.
             */

            CimSession cimSession = null;
            try
            {
                var resourceId = uint.Parse(GetComputerByName(computerName).ResourceID);
                cimSession = CimSession.Create(Properties.Resources.SCCMServerName);

                var cimCollectionRuleDirect = new CimInstance("SMS_CollectionRuleDirect");
                //CimClass cimClass = cimSession.GetClass(@"ROOT\sms\site_EDU","SMS_CollectionRuleDirect");

                cimCollectionRuleDirect.CimInstanceProperties.Add(CimProperty.Create("ResourceClassName", "SMS_R_System", CimFlags.Key));
                cimCollectionRuleDirect.CimInstanceProperties.Add(CimProperty.Create("ResourceID", resourceId, CimFlags.Key));

                var addMembershipRuleParameters = new CimMethodParametersCollection
                {
                    CimMethodParameter.Create("collectionRule", cimCollectionRuleDirect, CimFlags.Parameter)
                };

                var cimCollection = CIM.RunQuery("Select * FROM SMS_Collection WHERE CollectionID='" + collectionId + "'").FirstOrDefault();

                cimSession.InvokeMethod(cimCollection, "AddMembershipRule", addMembershipRuleParameters);
                return true;
            }
            catch (Exception)
            {
                return false;
            }
            finally
            {
                cimSession?.Dispose();
            }
        }
        internal EnumerateAssociatedInstancesJob(CimJobContext jobContext, CimQuery cimQuery, CimInstance associatedObject, string associationName, string resultRole, string sourceRole)
                : base(jobContext, cimQuery)
        {
            _associatedObject = associatedObject;
            Dbg.Assert(_associatedObject != null, "Caller should verify that associatedObject is not null");

            _associationName = associationName;
            Dbg.Assert(_associationName != null, "Caller should verify that associationName is not null");

            _resultRole = resultRole;
            Dbg.Assert(_resultRole != null, "Caller should verify that resultRole is not null");

            _sourceRole = sourceRole;
            Dbg.Assert(_sourceRole != null, "Caller should verify that sourceRole is not null");
        }
Esempio n. 13
0
 internal static CimCustomOptionsDictionary MergeOptions(CimCustomOptionsDictionary optionsFromCommandLine, CimInstance instanceRelatedToThisOperation)
 {
     CimCustomOptionsDictionary instanceRelatedOptions;
     if (s_cimInstanceToCustomOptions.TryGetValue(instanceRelatedToThisOperation, out instanceRelatedOptions) && instanceRelatedOptions != null)
     {
         IEnumerable<KeyValuePair<string, object>> instanceRelatedOptionsSnapshot = instanceRelatedOptions.GetSnapshot();
         IEnumerable<KeyValuePair<string, object>> optionsFromCommandLineSnapshot = optionsFromCommandLine.GetSnapshot();
         var mergedOptions = instanceRelatedOptionsSnapshot.Concat(optionsFromCommandLineSnapshot); // note - order matters here
         return new CimCustomOptionsDictionary(mergedOptions);
     }
     else
     {
         return optionsFromCommandLine;
     }
 }
Esempio n. 14
0
		internal void RemoveCimInstance(CimInstance cimInstance, XOperationContextBase context, CmdletOperationBase cmdlet)
		{
			DebugHelper.WriteLogEx();
			string str = cimInstance.ToString();
			if (cmdlet.ShouldProcess(str, "Remove-CimInstance"))
			{
				CimRemoveCimInstanceContext cimRemoveCimInstanceContext = context as CimRemoveCimInstanceContext;
				CimSessionProxy cimSessionProxy = base.CreateCimSessionProxy(cimRemoveCimInstanceContext.Proxy);
				cimSessionProxy.DeleteInstanceAsync(cimRemoveCimInstanceContext.Namespace, cimInstance);
				return;
			}
			else
			{
				return;
			}
		}
Esempio n. 15
0
		private CimInstance CreateCimInstance(string className, string cimNamespace, IEnumerable<string> key, IDictionary properties, NewCimInstanceCommand cmdlet)
		{
			CimInstance cimInstance = new CimInstance(className, cimNamespace);
			if (properties != null)
			{
				List<string> strs = new List<string>();
				if (key != null)
				{
					foreach (string str in key)
					{
						strs.Add(str);
					}
				}
				IDictionaryEnumerator enumerator = properties.GetEnumerator();
				while (enumerator.MoveNext())
				{
					CimFlags cimFlag = CimFlags.None;
					string str1 = enumerator.Key.ToString().Trim();
					if (strs.Contains<string>(str1, StringComparer.OrdinalIgnoreCase))
					{
						cimFlag = CimFlags.Key;
					}
					object baseObject = base.GetBaseObject(enumerator.Value);
					object[] objArray = new object[3];
					objArray[0] = str1;
					objArray[1] = baseObject;
					objArray[2] = cimFlag;
					DebugHelper.WriteLog("Create and add new property to ciminstance: name = {0}; value = {1}; flags = {2}", 5, objArray);
					PSReference pSReference = baseObject as PSReference;
					if (pSReference == null)
					{
						CimProperty cimProperty = CimProperty.Create(str1, baseObject, cimFlag);
						cimInstance.CimInstanceProperties.Add(cimProperty);
					}
					else
					{
						CimProperty cimProperty1 = CimProperty.Create(str1, base.GetBaseObject(pSReference.Value), CimType.Reference, cimFlag);
						cimInstance.CimInstanceProperties.Add(cimProperty1);
					}
				}
				return cimInstance;
			}
			else
			{
				return cimInstance;
			}
		}
Esempio n. 16
0
		protected virtual void Dispose(bool disposing)
		{
			if (!this._disposed)
			{
				if (disposing)
				{
					this._resultInstance.Dispose();
					this._resultInstance = null;
				}
				this._disposed = true;
				return;
			}
			else
			{
				return;
			}
		}
Esempio n. 17
0
		private CimInstance CreateCimInstance(CimClass cimClass, IDictionary properties, NewCimInstanceCommand cmdlet)
		{
			CimInstance cimInstance;
			CimInstance cimInstance1 = new CimInstance(cimClass);
			if (properties != null)
			{
				List<string> strs = new List<string>();
				IEnumerator enumerator = properties.Keys.GetEnumerator();
				try
				{
					while (enumerator.MoveNext())
					{
						string current = (string)enumerator.Current;
						if (cimInstance1.CimInstanceProperties[current] != null)
						{
							object baseObject = base.GetBaseObject(properties[current]);
							cimInstance1.CimInstanceProperties[current].Value = baseObject;
						}
						else
						{
							strs.Add(current);
							cmdlet.ThrowInvalidProperty(strs, cmdlet.CimClass.CimSystemProperties.ClassName, "Property", "New-CimInstance", properties);
							cimInstance = null;
							return cimInstance;
						}
					}
					return cimInstance1;
				}
				finally
				{
					IDisposable disposable = enumerator as IDisposable;
					if (disposable != null)
					{
						disposable.Dispose();
					}
				}
				return cimInstance;
			}
			else
			{
				return cimInstance1;
			}
		}
Esempio n. 18
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;
        }
Esempio n. 19
0
 private static PSAdaptedProperty GetPSComputerNameAdapter(CimInstance cimInstance)
 {
     return new PSAdaptedProperty(RemotingConstants.ComputerNameNoteProperty, cimInstance) { baseObject = cimInstance };
 }
Esempio n. 20
0
		internal CimSubscriptionResult(InstanceHandle handle, string bookmark, string machineId)
		{
			this._resultInstance = new CimInstance(handle, null);
			this._bookmark = bookmark;
			this._machineId = machineId;
		}
Esempio n. 21
0
 private bool RehydrateCimInstanceProperty(CimInstance cimInstance, PSPropertyInfo deserializedProperty, HashSet<string> namesOfModifiedProperties)
 {
     if (deserializedProperty.Name.Equals(RemotingConstants.ComputerNameNoteProperty, StringComparison.OrdinalIgnoreCase))
     {
         string computerName = deserializedProperty.Value as string;
         if (computerName != null)
         {
             cimInstance.SetCimSessionComputerName(computerName);
         }
         return true;
     }
     CimProperty property = cimInstance.CimInstanceProperties[deserializedProperty.Name];
     if (property == null)
     {
         return false;
     }
     object baseObject = deserializedProperty.Value;
     if (baseObject != null)
     {
         PSObject obj3 = PSObject.AsPSObject(baseObject);
         if (obj3.BaseObject is ArrayList)
         {
             Type type;
             object obj4;
             if ((obj3.InternalTypeNames == null) || (obj3.InternalTypeNames.Count == 0))
             {
                 return false;
             }
             string valueToConvert = Deserializer.MaskDeserializationPrefix(obj3.InternalTypeNames[0]);
             if (valueToConvert == null)
             {
                 return false;
             }
             if (!LanguagePrimitives.TryConvertTo<Type>(valueToConvert, CultureInfo.InvariantCulture, out type))
             {
                 return false;
             }
             if (!type.IsArray)
             {
                 return false;
             }
             if (!LanguagePrimitives.TryConvertTo(baseObject, type, CultureInfo.InvariantCulture, out obj4))
             {
                 return false;
             }
             obj3 = PSObject.AsPSObject(obj4);
         }
         baseObject = obj3.BaseObject;
     }
     try
     {
         property.Value = baseObject;
         if (!namesOfModifiedProperties.Contains(deserializedProperty.Name))
         {
             property.IsValueModified = false;
         }
     }
     catch (FormatException)
     {
         return false;
     }
     catch (InvalidCastException)
     {
         return false;
     }
     catch (ArgumentException)
     {
         return false;
     }
     catch (CimException)
     {
         return false;
     }
     return true;
 }
Esempio n. 22
0
 private PSObject RehydrateCimInstance(PSObject deserializedObject)
 {
     CimInstance instance;
     if (!(deserializedObject.BaseObject is PSCustomObject))
     {
         return deserializedObject;
     }
     PSPropertyInfo classMetadataProperty = deserializedObject.InstanceMembers["__ClassMetadata"] as PSPropertyInfo;
     CimClass cimClass = this.RehydrateCimClass(classMetadataProperty);
     if (cimClass == null)
     {
         return deserializedObject;
     }
     try
     {
         instance = new CimInstance(cimClass);
     }
     catch (CimException)
     {
         return deserializedObject;
     }
     PSObject obj2 = PSObject.AsPSObject(instance);
     HashSet<string> namesOfModifiedProperties = new HashSet<string>(StringComparer.OrdinalIgnoreCase);
     PSPropertyInfo info2 = deserializedObject.InstanceMembers["__InstanceMetadata"] as PSPropertyInfo;
     if ((info2 != null) && (info2.Value != null))
     {
         PSPropertyInfo info3 = PSObject.AsPSObject(info2.Value).InstanceMembers["Modified"] as PSPropertyInfo;
         if ((info3 != null) && (info3.Value != null))
         {
             foreach (string str2 in info3.Value.ToString().Split(new char[] { ' ' }))
             {
                 namesOfModifiedProperties.Add(str2);
             }
         }
     }
     if (deserializedObject.adaptedMembers != null)
     {
         foreach (PSMemberInfo info4 in deserializedObject.adaptedMembers)
         {
             PSPropertyInfo deserializedProperty = info4 as PSPropertyInfo;
             if ((deserializedProperty != null) && !this.RehydrateCimInstanceProperty(instance, deserializedProperty, namesOfModifiedProperties))
             {
                 return deserializedObject;
             }
         }
     }
     foreach (PSMemberInfo info6 in deserializedObject.InstanceMembers)
     {
         PSPropertyInfo info7 = info6 as PSPropertyInfo;
         if (((info7 != null) && ((deserializedObject.adaptedMembers == null) || (deserializedObject.adaptedMembers[info7.Name] == null))) && (!info7.Name.Equals("__ClassMetadata", StringComparison.OrdinalIgnoreCase) && (obj2.Properties[info7.Name] == null)))
         {
             PSNoteProperty member = new PSNoteProperty(info7.Name, info7.Value);
             obj2.Properties.Add(member);
         }
     }
     return obj2;
 }
Esempio n. 23
0
		protected object GetReferenceOrReferenceArrayObject(object value, ref CimType referenceType)
		{
			PSReference pSReference = value as PSReference;
			if (pSReference == null)
			{
				object[] objArray = value as object[];
				if (objArray != null)
				{
					if (objArray[0] as PSReference != null)
					{
						CimInstance[] cimInstanceArray = new CimInstance[(int)objArray.Length];
						int num = 0;
						while (num < (int)objArray.Length)
						{
							PSReference pSReference1 = objArray[num] as PSReference;
							if (pSReference1 != null)
							{
								object baseObject = this.GetBaseObject(pSReference1.Value);
								cimInstanceArray[num] = baseObject as CimInstance;
								if (cimInstanceArray[num] != null)
								{
									num++;
								}
								else
								{
									return null;
								}
							}
							else
							{
								return null;
							}
						}
						referenceType = CimType.ReferenceArray;
						return cimInstanceArray;
					}
					else
					{
						return null;
					}
				}
				else
				{
					return null;
				}
			}
			else
			{
				object obj = this.GetBaseObject(pSReference.Value);
				CimInstance cimInstance = obj as CimInstance;
				if (cimInstance != null)
				{
					referenceType = CimType.Reference;
					return cimInstance;
				}
				else
				{
					return null;
				}
			}
		}
Esempio n. 24
0
		protected CimSessionProxy CreateCimSessionProxy(string computerName, CimInstance cimInstance, bool passThru)
		{
			CimSessionProxy cimSessionProxySetCimInstance = new CimSessionProxySetCimInstance(computerName, cimInstance, passThru);
			this.SubscribeEventAndAddProxytoCache(cimSessionProxySetCimInstance);
			return cimSessionProxySetCimInstance;
		}
Esempio n. 25
0
		protected CimSessionProxy CreateCimSessionProxy(string computerName, CimInstance cimInstance)
		{
			CimSessionProxy cimSessionProxy = new CimSessionProxy(computerName, cimInstance);
			this.SubscribeEventAndAddProxytoCache(cimSessionProxy);
			return cimSessionProxy;
		}
Esempio n. 26
0
		internal CimPropertyOfInstance (SharedInstanceHandle instanceHandle, CimInstance instance, int index)
		{
			this._instanceHandle = instanceHandle;
			this._instance = instance;
			this._index = index;
		}
Esempio n. 27
0
		public CimInstance(CimInstance cimInstanceToClone)
		{
			this._CimSessionInstanceID = Guid.Empty;
			if (cimInstanceToClone != null)
			{
				InstanceHandle instanceHandle = cimInstanceToClone.InstanceHandle.Clone();
				this._myHandle = new SharedInstanceHandle(instanceHandle);
				return;
			}
			else
			{
				throw new ArgumentNullException("cimInstanceToClone");
			}
		}
Esempio n. 28
0
        /// <summary>
        /// Removes a computer from a collection.
        /// </summary>
        /// <param name="computerName">The name of the computer.</param>
        /// <param name="collectionId">The ID of the collection.</param>
        /// <returns>returns true if the move succeeded, false otherwise.</returns>
        public static bool RemoveComputerFromCollection(string computerName, string collectionId)
        {
            CimSession cimSession = null;
            try
            {
                var resourceId = uint.Parse(GetComputerByName(computerName).ResourceID);
                cimSession = CimSession.Create(Properties.Resources.SCCMServerName);

                var cimCollectionRuleDirect = new CimInstance("SMS_CollectionRuleDirect");

                cimCollectionRuleDirect.CimInstanceProperties.Add(CimProperty.Create("ResourceClassName", "SMS_R_System", CimFlags.Key));
                cimCollectionRuleDirect.CimInstanceProperties.Add(CimProperty.Create("ResourceID", resourceId, CimFlags.Key));

                var addMembershipRuleParameters = new CimMethodParametersCollection
                {
                    CimMethodParameter.Create("collectionRule", cimCollectionRuleDirect, CimFlags.Parameter)
                };

                var cimCollection = CIM.RunQuery("Select * FROM SMS_Collection WHERE CollectionID='" + collectionId + "'").FirstOrDefault();

                cimSession.InvokeMethod(cimCollection, "DeleteMemberShipRule", addMembershipRuleParameters);
                return true;
            }
            catch (Exception ex)
            {
                throw new Exception("An error occurred in RemoveComputerFromCollection.\n" + ex.Message);
            }
            finally
            {
                cimSession?.Dispose();
            }
        }
Esempio n. 29
0
 internal static object ConvertToNativeLayer(object value)
 {
     return(CimInstance.ConvertToNativeLayer(value, CimType.Unknown));
 }
Esempio n. 30
0
        internal static object ConvertFromNativeLayer(object value, SharedInstanceHandle sharedParentHandle = null, CimInstance parent = null, bool clone = false)
        {
            InstanceHandle instanceHandle;
            InstanceHandle instanceHandle1;
            InstanceHandle instanceHandle2 = value as InstanceHandle;

            if (instanceHandle2 == null)
            {
                InstanceHandle[] instanceHandleArray = value as InstanceHandle[];
                if (instanceHandleArray == null)
                {
                    return(value);
                }
                else
                {
                    CimInstance[] cimInstanceArray = new CimInstance[(int)instanceHandleArray.Length];
                    for (int i = 0; i < (int)instanceHandleArray.Length; i++)
                    {
                        InstanceHandle instanceHandle3 = instanceHandleArray[i];
                        if (instanceHandle3 != null)
                        {
                            CimInstance[] cimInstance = cimInstanceArray;
                            int           num         = i;
                            if (clone)
                            {
                                instanceHandle = instanceHandle3.Clone();
                            }
                            else
                            {
                                instanceHandle = instanceHandle3;
                            }
                            cimInstance[num] = new CimInstance(instanceHandle, sharedParentHandle);
                            if (parent != null)
                            {
                                cimInstanceArray[i].SetCimSessionComputerName(parent.GetCimSessionComputerName());
                                cimInstanceArray[i].SetCimSessionInstanceId(parent.GetCimSessionInstanceId());
                            }
                        }
                        else
                        {
                            cimInstanceArray[i] = null;
                        }
                    }
                    return(cimInstanceArray);
                }
            }
            else
            {
                if (clone)
                {
                    instanceHandle1 = instanceHandle2.Clone();
                }
                else
                {
                    instanceHandle1 = instanceHandle2;
                }
                CimInstance cimInstance1 = new CimInstance(instanceHandle1, sharedParentHandle);
                if (parent != null)
                {
                    cimInstance1.SetCimSessionComputerName(parent.GetCimSessionComputerName());
                    cimInstance1.SetCimSessionInstanceId(parent.GetCimSessionInstanceId());
                }
                return(cimInstance1);
            }
        }
Esempio n. 31
0
 private CimInstance ConvertToDefault(ScheduledJobTrigger trigger, CimSession cimSession)
 {
     CimClass cimClass = cimSession.GetClass(CIM_TRIGGER_NAMESPACE, "MSFT_TaskTrigger");
     CimInstance result = new CimInstance(cimClass);
     AddCommonProperties(trigger, result);
     return result;
 }
Esempio n. 32
0
		internal static object ConvertFromNativeLayer(object value, SharedInstanceHandle sharedParentHandle = null, CimInstance parent = null, bool clone = false)
		{
			InstanceHandle instanceHandle;
			InstanceHandle instanceHandle1;
			InstanceHandle instanceHandle2 = value as InstanceHandle;
			if (instanceHandle2 == null)
			{
				InstanceHandle[] instanceHandleArray = value as InstanceHandle[];
				if (instanceHandleArray == null)
				{
					return value;
				}
				else
				{
					CimInstance[] cimInstanceArray = new CimInstance[(int)instanceHandleArray.Length];
					for (int i = 0; i < (int)instanceHandleArray.Length; i++)
					{
						InstanceHandle instanceHandle3 = instanceHandleArray[i];
						if (instanceHandle3 != null)
						{
							CimInstance[] cimInstance = cimInstanceArray;
							int num = i;
							if (clone)
							{
								instanceHandle = instanceHandle3.Clone();
							}
							else
							{
								instanceHandle = instanceHandle3;
							}
							cimInstance[num] = new CimInstance(instanceHandle, sharedParentHandle);
							if (parent != null)
							{
								cimInstanceArray[i].SetCimSessionComputerName(parent.GetCimSessionComputerName());
								cimInstanceArray[i].SetCimSessionInstanceId(parent.GetCimSessionInstanceId());
							}
						}
						else
						{
							cimInstanceArray[i] = null;
						}
					}
					return cimInstanceArray;
				}
			}
			else
			{
				if (clone)
				{
					instanceHandle1 = instanceHandle2.Clone();
				}
				else
				{
					instanceHandle1 = instanceHandle2;
				}
				CimInstance cimInstance1 = new CimInstance(instanceHandle1, sharedParentHandle);
				if (parent != null)
				{
					cimInstance1.SetCimSessionComputerName(parent.GetCimSessionComputerName());
					cimInstance1.SetCimSessionInstanceId(parent.GetCimSessionInstanceId());
				}
				return cimInstance1;
			}
		}
Esempio n. 33
0
 internal CimSubscriptionResult(InstanceHandle handle, string bookmark, string machineId)
 {
     this._resultInstance = new CimInstance(handle, null);
     this._bookmark       = bookmark;
     this._machineId      = machineId;
 }