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; }
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; }
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; }
private CimInstance ConvertToAtStartup(ScheduledJobTrigger trigger, CimSession cimSession) { CimClass cimClass = cimSession.GetClass(CIM_TRIGGER_NAMESPACE, "MSFT_TaskBootTrigger"); CimInstance cimInstance = new CimInstance(cimClass); cimInstance.CimInstanceProperties["Delay"].Value = ScheduledJobWTS.ConvertTimeSpanToWTSString(trigger.RandomDelay); AddCommonProperties(trigger, cimInstance); return cimInstance; }
private CimInstance ConvertToAtLogon(ScheduledJobTrigger trigger, CimSession cimSession) { CimClass cimClass = cimSession.GetClass(CIM_TRIGGER_NAMESPACE, "MSFT_TaskLogonTrigger"); CimInstance cimInstance = new CimInstance(cimClass); cimInstance.CimInstanceProperties["Delay"].Value = ScheduledJobWTS.ConvertTimeSpanToWTSString(trigger.RandomDelay); // Convert the "AllUsers" name ("*" character) to null for Task Scheduler. string userId = (ScheduledJobTrigger.IsAllUsers(trigger.User)) ? null : trigger.User; cimInstance.CimInstanceProperties["UserId"].Value = userId; AddCommonProperties(trigger, cimInstance); return cimInstance; }
private CimInstance ConvertToOnce(ScheduledJobTrigger trigger, CimSession cimSession) { CimClass cimClass = cimSession.GetClass(CIM_TRIGGER_NAMESPACE, "MSFT_TaskTimeTrigger"); CimInstance cimInstance = new CimInstance(cimClass); cimInstance.CimInstanceProperties["RandomDelay"].Value = ScheduledJobWTS.ConvertTimeSpanToWTSString(trigger.RandomDelay); if (trigger.RepetitionInterval != null && trigger.RepetitionDuration != null) { CimClass cimRepClass = cimSession.GetClass(CIM_TRIGGER_NAMESPACE, "MSFT_TaskRepetitionPattern"); CimInstance cimRepInstance = new CimInstance(cimRepClass); cimRepInstance.CimInstanceProperties["Interval"].Value = ScheduledJobWTS.ConvertTimeSpanToWTSString(trigger.RepetitionInterval.Value); if (trigger.RepetitionDuration == TimeSpan.MaxValue) { cimRepInstance.CimInstanceProperties["StopAtDurationEnd"].Value = false; } else { cimRepInstance.CimInstanceProperties["StopAtDurationEnd"].Value = true; cimRepInstance.CimInstanceProperties["Duration"].Value = ScheduledJobWTS.ConvertTimeSpanToWTSString(trigger.RepetitionDuration.Value); } cimInstance.CimInstanceProperties["Repetition"].Value = cimRepInstance; } AddCommonProperties(trigger, cimInstance); return cimInstance; }
private CimInstance ConvertToWeekly(ScheduledJobTrigger trigger, CimSession cimSession) { CimClass cimClass = cimSession.GetClass(CIM_TRIGGER_NAMESPACE, "MSFT_TaskWeeklyTrigger"); CimInstance cimInstance = new CimInstance(cimClass); cimInstance.CimInstanceProperties["DaysOfWeek"].Value = ScheduledJobWTS.ConvertDaysOfWeekToMask(trigger.DaysOfWeek); cimInstance.CimInstanceProperties["RandomDelay"].Value = ScheduledJobWTS.ConvertTimeSpanToWTSString(trigger.RandomDelay); cimInstance.CimInstanceProperties["WeeksInterval"].Value = trigger.Interval; AddCommonProperties(trigger, cimInstance); return cimInstance; }
private CimInstance ConvertToOnce(ScheduledJobTrigger trigger, CimSession cimSession) { bool valueOrDefault; CimClass @class = cimSession.GetClass(JobTriggerToCimInstanceConverter.CIM_TRIGGER_NAMESPACE, "MSFT_TaskTimeTrigger"); CimInstance cimInstance = new CimInstance(@class); cimInstance.CimInstanceProperties["RandomDelay"].Value = ScheduledJobWTS.ConvertTimeSpanToWTSString(trigger.RandomDelay); TimeSpan? repetitionInterval = trigger.RepetitionInterval; if (repetitionInterval.HasValue) { TimeSpan? repetitionDuration = trigger.RepetitionDuration; if (repetitionDuration.HasValue) { CimClass cimClass = cimSession.GetClass(JobTriggerToCimInstanceConverter.CIM_TRIGGER_NAMESPACE, "MSFT_TaskRepetitionPattern"); CimInstance wTSString = new CimInstance(cimClass); TimeSpan? nullable = trigger.RepetitionInterval; wTSString.CimInstanceProperties["Interval"].Value = ScheduledJobWTS.ConvertTimeSpanToWTSString(nullable.Value); TimeSpan? repetitionDuration1 = trigger.RepetitionDuration; TimeSpan maxValue = TimeSpan.MaxValue; if (!repetitionDuration1.HasValue) { valueOrDefault = false; } else { valueOrDefault = repetitionDuration1.GetValueOrDefault() == maxValue; } if (!valueOrDefault) { wTSString.CimInstanceProperties["StopAtDurationEnd"].Value = true; TimeSpan? nullable1 = trigger.RepetitionDuration; wTSString.CimInstanceProperties["Duration"].Value = ScheduledJobWTS.ConvertTimeSpanToWTSString(nullable1.Value); } else { wTSString.CimInstanceProperties["StopAtDurationEnd"].Value = false; } cimInstance.CimInstanceProperties["Repetition"].Value = wTSString; } } JobTriggerToCimInstanceConverter.AddCommonProperties(trigger, cimInstance); return cimInstance; }
private CimInstance ConvertToDefault(ScheduledJobTrigger trigger, CimSession cimSession) { CimClass @class = cimSession.GetClass(JobTriggerToCimInstanceConverter.CIM_TRIGGER_NAMESPACE, "MSFT_TaskTrigger"); CimInstance cimInstance = new CimInstance(@class); JobTriggerToCimInstanceConverter.AddCommonProperties(trigger, cimInstance); return cimInstance; }
private CimInstance ConvertToDaily(ScheduledJobTrigger trigger, CimSession cimSession) { CimClass @class = cimSession.GetClass(JobTriggerToCimInstanceConverter.CIM_TRIGGER_NAMESPACE, "MSFT_TaskDailyTrigger"); CimInstance cimInstance = new CimInstance(@class); cimInstance.CimInstanceProperties["RandomDelay"].Value = ScheduledJobWTS.ConvertTimeSpanToWTSString(trigger.RandomDelay); cimInstance.CimInstanceProperties["DaysInterval"].Value = trigger.Interval; JobTriggerToCimInstanceConverter.AddCommonProperties(trigger, cimInstance); return cimInstance; }
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; }
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; }