本文整理汇总了C#中Microsoft.Management.Infrastructure.CimInstance类的典型用法代码示例。如果您正苦于以下问题:C# CimInstance类的具体用法?C# CimInstance怎么用?C# CimInstance使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
CimInstance类属于Microsoft.Management.Infrastructure命名空间,在下文中一共展示了CimInstance类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: GetAllValues
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;
}
开发者ID:dhanzhang,项目名称:Windows-classic-samples,代码行数:27,代码来源:SampleCimOperation.cs
示例2: EnumerateAssociatedInstancesJob
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;
}
开发者ID:nickchal,项目名称:pash,代码行数:7,代码来源:EnumerateAssociatedInstancesJob.cs
示例3: ConvertCimErrorToErrorCategory
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;
}
}
开发者ID:nickchal,项目名称:pash,代码行数:27,代码来源:ErrorToErrorRecord.cs
示例4: GetPSComputerNameAdapter
private static PSAdaptedProperty GetPSComputerNameAdapter(CimInstance cimInstance)
{
PSAdaptedProperty psComputerNameProperty = new PSAdaptedProperty(RemotingConstants.ComputerNameNoteProperty, cimInstance);
psComputerNameProperty.baseObject = cimInstance;
//psComputerNameProperty.adapter = this;
return psComputerNameProperty;
}
开发者ID:dfinke,项目名称:powershell,代码行数:7,代码来源:ciminstancetypeadapter.cs
示例5: AssociateCimInstanceWithCustomOptions
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;
}
}
开发者ID:nickchal,项目名称:pash,代码行数:34,代码来源:CimCustomOptionsDictionary.cs
示例6: AssociateCimInstanceWithCustomOptions
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;
}
}
}
}
开发者ID:40a,项目名称:PowerShell,代码行数:35,代码来源:cimOperationOptionsHelper.cs
示例7: InvocationContext
internal InvocationContext(CimSessionProxy proxy)
{
if (proxy != null)
{
this.ComputerName = proxy.CimSession.ComputerName;
this.TargetCimInstance = proxy.TargetCimInstance;
}
}
开发者ID:nickchal,项目名称:pash,代码行数:8,代码来源:InvocationContext.cs
示例8: Serialize
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");
}
}
开发者ID:nickchal,项目名称:pash,代码行数:57,代码来源:CimSerializer.cs
示例9: AddCommonProperties
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);
}
}
开发者ID:nickchal,项目名称:pash,代码行数:9,代码来源:JobTriggerToCimInstanceConverter.cs
示例10: InstanceMethodInvocationJob
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;
}
开发者ID:40a,项目名称:PowerShell,代码行数:10,代码来源:InstanceMethodInvocationJob.cs
示例11: AddComputerToCollection
/// <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();
}
}
开发者ID:RRedFalcon,项目名称:GSD,代码行数:58,代码来源:gsd.library.SCCM.cs
示例12: EnumerateAssociatedInstancesJob
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");
}
开发者ID:40a,项目名称:PowerShell,代码行数:15,代码来源:EnumerateAssociatedInstancesJob.cs
示例13: MergeOptions
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;
}
}
开发者ID:40a,项目名称:PowerShell,代码行数:15,代码来源:cimOperationOptionsHelper.cs
示例14: RemoveCimInstance
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;
}
}
开发者ID:nickchal,项目名称:pash,代码行数:16,代码来源:CimRemoveCimInstance.cs
示例15: CreateCimInstance
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;
}
}
开发者ID:nickchal,项目名称:pash,代码行数:47,代码来源:CimNewCimInstance.cs
示例16: GetInheritanceChain
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;
}
开发者ID:nickchal,项目名称:pash,代码行数:20,代码来源:CimInstanceAdapter.cs
示例17: CimSubscriptionResult
internal CimSubscriptionResult(InstanceHandle handle, string bookmark, string machineId)
{
this._resultInstance = new CimInstance(handle, null);
this._bookmark = bookmark;
this._machineId = machineId;
}
开发者ID:nickchal,项目名称:pash,代码行数:6,代码来源:CimSubscriptionResult.cs
示例18: RehydrateCimInstanceProperty
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;
}
开发者ID:nickchal,项目名称:pash,代码行数:75,代码来源:InternalDeserializer.cs
示例19: RehydrateCimInstance
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;
}
开发者ID:nickchal,项目名称:pash,代码行数:57,代码来源:InternalDeserializer.cs
示例20: GetReferenceOrReferenceArrayObject
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;
}
}
}
开发者ID:nickchal,项目名称:pash,代码行数:61,代码来源:CimAsyncOperation.cs
注:本文中的Microsoft.Management.Infrastructure.CimInstance类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论