本文整理汇总了C#中Microsoft.Management.Infrastructure.CimInstance类的典型用法代码示例。如果您正苦于以下问题:C# CimInstance类的具体用法?C# CimInstance怎么用?C# CimInstance使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
CimInstance类属于Microsoft.Management.Infrastructure命名空间,在下文中一共展示了CimInstance类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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;
}
示例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;
}
示例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;
}
}
示例4: GetPSComputerNameAdapter
private static PSAdaptedProperty GetPSComputerNameAdapter(CimInstance cimInstance)
{
PSAdaptedProperty psComputerNameProperty = new PSAdaptedProperty(RemotingConstants.ComputerNameNoteProperty, cimInstance);
psComputerNameProperty.baseObject = cimInstance;
//psComputerNameProperty.adapter = this;
return psComputerNameProperty;
}
示例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;
}
}
示例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;
}
}
}
}
示例7: InvocationContext
internal InvocationContext(CimSessionProxy proxy)
{
if (proxy != null)
{
this.ComputerName = proxy.CimSession.ComputerName;
this.TargetCimInstance = proxy.TargetCimInstance;
}
}
示例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");
}
}
示例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);
}
}
示例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;
}
示例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();
}
}
示例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");
}
示例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;
}
}
示例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;
}
}
示例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;
}
}