internal static string GetFrequencyUnit(ManagementPackRule mpr) { try { XmlDocument xmlDoc = new XmlDocument(); xmlDoc.LoadXml(mpr.DataSourceCollection[0].Configuration); foreach (XmlNode node in xmlDoc.ChildNodes[0].ChildNodes[0]) { if (node.Name == "Interval") { if (node.Attributes["Unit"].Value.ToString() == "Hours") { return(ServiceManagerLocalization.GetStringFromManagementPack("strHours")); } else { return(ServiceManagerLocalization.GetStringFromManagementPack("strMinutes")); } } } return(string.Empty); } catch { return(string.Empty); } }
public bool DeleteProjectConnector(IDataItem item) { try { //get the connector class. Later we will get the type projection so we can delete related objects. //item = ConsoleContextHelper.Instance.GetInstance((Guid)item["$Id$"]); //get type projection of the connector (Cireson.ProjectAutomation.ConnectorRelatesToProjects.ProjectionType) (34e516cf-644f-11b7-be02-6c886ec0573b) item = ConsoleContextHelper.Instance.GetProjectionInstance((Guid)item["$Id$"], new Guid("34e516cf-644f-11b7-be02-6c886ec0573b")); //add in some sort of confirmation on delete... later. if (MessageBox.Show( String.Format(ServiceManagerLocalization.GetStringFromManagementPack("strConfirmDelete") + " {0}", item["DisplayName"]), ServiceManagerLocalization.GetStringFromManagementPack("strDeleteConnector"), MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.No) { return(false); } var emg = ConsoleContext.GetConsoleEMG(); var emoConnector = emg.EntityObjects.GetObject <EnterpriseManagementObject>((Guid)item["$Id$"], ObjectQueryOptions.Default); var iddRemove = new IncrementalDiscoveryData(); // (Cireson.ProjectAutomation.Library) (System.ProjectConfigItemRelatesToProjectConnector) (da061582-3f6c-d7b7-d17d-0a91b8a51ace) ManagementPackRelationship mprConnectorHasProject = emg.EntityTypes.GetRelationshipClass(new Guid("da061582-3f6c-d7b7-d17d-0a91b8a51ace")); //remove the related project CIs. foreach (EnterpriseManagementRelationshipObject <EnterpriseManagementObject> obj in emg.EntityObjects.GetRelationshipObjectsWhereSource <EnterpriseManagementObject>(emoConnector.Id, mprConnectorHasProject, DerivedClassTraversalDepth.None, TraversalDepth.OneLevel, ObjectQueryOptions.Default)) { iddRemove.Remove(obj.TargetObject); } //remove workflow rule for the connector try { //Cireson Project Server Automation Library Configuration (Cireson.ProjectAutomation.Library.Configuration) (19b2a173-bea9-9e50-0709-1470424916f2) ManagementPack mpConnectorWorkflow = emg.ManagementPacks.GetManagementPack(new Guid("19b2a173-bea9-9e50-0709-1470424916f2")); //Project Server Connector (Cireson.ProjectAutomation.Library) (Microsoft.SystemCenter.Connector.ProjectServer) (d581d2d6-b6cd-b558-7ac7-db233a7c82ec) ManagementPackClass mpcConnector = emg.EntityTypes.GetClass(new Guid("d581d2d6-b6cd-b558-7ac7-db233a7c82ec")); string sConnectorRuleId = string.Format("{0}.{1}", "Cireson.ProjectServer.Automation", new Guid(emoConnector[mpcConnector, "Id"].Value.ToString()).ToString("N")); ManagementPackRule mprConnector = mpConnectorWorkflow.GetRule(sConnectorRuleId); mprConnector.Status = ManagementPackElementStatus.PendingDelete; mpConnectorWorkflow.AcceptChanges(); } catch { } iddRemove.Remove(emoConnector); iddRemove.Commit(emg); return(true); } catch (Exception ex) { ConsoleContextHelper.Instance.ShowErrorDialog(ex, string.Empty, ConsoleJobExceptionSeverity.Error); return(false); } }
private void UpdateConnectorInstance() { //Get the server name to connect to and connect String strServerName = Registry.GetValue("HKEY_CURRENT_USER\\Software\\Microsoft\\System Center\\2010\\Service Manager\\Console\\User Settings", "SDKServiceMachine", "localhost").ToString(); EnterpriseManagementGroup emg = new EnterpriseManagementGroup(strServerName); //Get the Connectors MP and CSV Connector Class ManagementPack mpConnectors = emg.GetManagementPack("Microsoft.Demo.Connectors", null, new Version("1.0.0.0")); ManagementPackClass classCSVConnector = mpConnectors.GetClass("Microsoft.Demo.Connectors.CSVConnector"); //Get the Connector object using the object ID EnterpriseManagementObject emoCSVConnector = emg.EntityObjects.GetObject <EnterpriseManagementObject>(this.EnterpriseManagementObjectID, ObjectQueryOptions.Default); //Set the property values to the new values emoCSVConnector[classCSVConnector, "DisplayName"].Value = this.DisplayName; emoCSVConnector[classCSVConnector, "DataFilePath"].Value = this.DataFilePath; emoCSVConnector[classCSVConnector, "DataFilePath"].Value = this.DataFilePath; emoCSVConnector[classCSVConnector, "MappingFilePath"].Value = this.MappingFilePath; emoCSVConnector[classCSVConnector, "NumberMinutes"].Value = this.NumberMinutes; //Update Connector instance emoCSVConnector.Commit(); //Get the rule using the Connector ID and then update the data source and write action module configuration ManagementPackRule ruleConnector = mpConnectors.GetRule(this.ConnectorID); ruleConnector.DataSourceCollection[0].Configuration = "<Scheduler>" + "<SimpleReccuringSchedule>" + "<Interval Unit=\"Minutes\">" + this.NumberMinutes + "</Interval>" + "</SimpleReccuringSchedule>" + "<ExcludeDates />" + "</Scheduler>"; ruleConnector.WriteActionCollection[0].Configuration = "<Subscription>" + "<WindowsWorkflowConfiguration>" + "<AssemblyName>CSVConnectorWorkflow</AssemblyName>" + "<WorkflowTypeName>WorkflowAuthoring.CSVConnectorWorkflow</WorkflowTypeName>" + "<WorkflowParameters>" + "<WorkflowParameter Name=\"DataFilePath\" Type=\"string\">" + this.DataFilePath + "</WorkflowParameter>" + "<WorkflowParameter Name=\"FormatFilePath\" Type=\"string\">" + this.MappingFilePath + "</WorkflowParameter>" + "</WorkflowParameters>" + "<RetryExceptions />" + "<RetryDelaySeconds>60</RetryDelaySeconds>" + "<MaximumRunningTimeSeconds>300</MaximumRunningTimeSeconds>" + "</WindowsWorkflowConfiguration>" + "</Subscription>"; ruleConnector.Status = ManagementPackElementStatus.PendingUpdate; mpConnectors.AcceptChanges(); }
//--------------------------------------------------------------------- private void DisplayAdvisorQueryIfApplicable(ManagementPackElement element) { if (!(element is ManagementPackRule)) { return; } ManagementPackRule rule = (ManagementPackRule)element; DataTable t = m_dataset.Tables["Rules"]; m_QueryResourceTextBox.Text = String.Empty; }
internal static int GetFrequencyInterval(ManagementPackRule mpr) { try { XmlDocument xmlDoc = new XmlDocument(); xmlDoc.LoadXml(mpr.DataSourceCollection[0].Configuration); foreach (XmlNode node in xmlDoc.ChildNodes[0].ChildNodes[0]) { if (node.Name == "Interval") { return(Convert.ToInt32(node.InnerXml)); } } return(0); } catch { return(0); } }
internal static string GetDailyScheduleStartTime(ManagementPackRule mpr) { try { XmlDocument xmlDoc = new XmlDocument(); xmlDoc.LoadXml(mpr.DataSourceCollection[0].Configuration); foreach (XmlNode node in xmlDoc.ChildNodes[0].ChildNodes[0].ChildNodes[0].ChildNodes[0]) { if (node.Name == "Start") { return(node.InnerXml); } } return(string.Empty); } catch { return(string.Empty); } }
protected override void ProcessRecord() { if (Id != Guid.Empty) { ManagementPackRule rule = _mg.Monitoring.GetRule(Id); PSObject o = new PSObject(rule); o.Members.Add(new PSNoteProperty("ManagementPack", rule.GetManagementPack())); WriteObject(o); } else { foreach (ManagementPackRule rule in _mg.Monitoring.GetRules()) { if (r.Match(rule.Name).Success) { PSObject o = new PSObject(rule); o.Members.Add(new PSNoteProperty("ManagementPack", rule.GetManagementPack())); WriteObject(o); } } } }
public override void ExecuteCommand(IList <NavigationModelNodeBase> nodes, NavigationModelNodeTask task, ICollection <string> parameters) { if (parameters.Contains("Create")) { WizardStory wizard = new WizardStory(); //set the icon and title bar ResourceManager rm = new ResourceManager("SCSM.AzureAutomation.WPF.Connector.Resources", typeof(Resources).Assembly); Bitmap bitmap = (Bitmap)rm.GetObject("AzureAutomation2x24"); IntPtr ptr = bitmap.GetHbitmap(); BitmapSource bitmapsource = System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap(ptr, IntPtr.Zero, Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions()); wizard.StoryImage = bitmapsource; wizard.WizardWindowTitle = "Create Azure Automation Connector"; WizardData data = new AzureAutomationWizardData(); wizard.WizardData = data; //add th pages wizard.AddLast(new WizardStep("Welcome", typeof(AzureAutomationWelcomePage), wizard.WizardData)); wizard.AddLast(new WizardStep("Configuration", typeof(AzureAutomationConfigurationPage), wizard.WizardData)); wizard.AddLast(new WizardStep("Summary", typeof(AzureAutomationSummaryPage), wizard.WizardData)); wizard.AddLast(new WizardStep("Results", typeof(AzureAutomationResultPage), wizard.WizardData)); //Create a wizard window and show it WizardWindow wizardwindow = new WizardWindow(wizard); // this is needed so that WinForms will pass messages on to the hosted WPF control System.Windows.Forms.Integration.ElementHost.EnableModelessKeyboardInterop(wizardwindow); wizardwindow.ShowDialog(); //Update the view when done with the wizard so that the new connector shows if (data.WizardResult == WizardResult.Success) { RequestViewRefresh(); } } else if (parameters.Contains("Edit")) { //Get the server name to connect to and connect to the server String strServerName = Registry.GetValue("HKEY_CURRENT_USER\\Software\\Microsoft\\System Center\\2010\\Service Manager\\Console\\User Settings", "SDKServiceMachine", "localhost").ToString(); EnterpriseManagementGroup emg = new EnterpriseManagementGroup(strServerName); //Get the object using the selected node ID String strID = String.Empty; foreach (NavigationModelNodeBase node in nodes) { strID = node["$Id$"].ToString(); } EnterpriseManagementObject emoAAConnector = emg.EntityObjects.GetObject <EnterpriseManagementObject>(new Guid(strID), ObjectQueryOptions.Default); //Create a new "wizard" (also used for property dialogs as in this case), set the title bar, create the data, and add the pages WizardStory wizard = new WizardStory(); wizard.WizardWindowTitle = "Edit Azure Automation Connector"; WizardData data = new AzureAutomationWizardData(emoAAConnector); wizard.WizardData = data; wizard.AddLast(new WizardStep("Configuration", typeof(AzureAutomationConfigurationPage), wizard.WizardData)); //Show the property page PropertySheetDialog wizardWindow = new PropertySheetDialog(wizard); //Update the view when done so the new values are shown bool?dialogResult = wizardWindow.ShowDialog(); if (dialogResult.HasValue && dialogResult.Value) { RequestViewRefresh(); } } else if (parameters.Contains("Delete") || parameters.Contains("Disable") || parameters.Contains("Enable")) { //Get the server name to connect to and create a connection String strServerName = Registry.GetValue("HKEY_CURRENT_USER\\Software\\Microsoft\\System Center\\2010\\Service Manager\\Console\\User Settings", "SDKServiceMachine", "localhost").ToString(); EnterpriseManagementGroup emg = new EnterpriseManagementGroup(strServerName); //Get the object using the selected node ID String strID = String.Empty; foreach (NavigationModelNodeBase node in nodes) { strID = node["$Id$"].ToString(); } EnterpriseManagementObject emoAAConnector = emg.EntityObjects.GetObject <EnterpriseManagementObject>(new Guid(strID), ObjectQueryOptions.Default); if (parameters.Contains("Delete")) { //Remove the object from the database IncrementalDiscoveryData idd = new IncrementalDiscoveryData(); idd.Remove(emoAAConnector); idd.Commit(emg); } //Get the rule using the connector ID ManagementPack mpConnectors = emg.GetManagementPack("SCSM.AzureAutomation", "ac1fe0583b6c84af", new Version("1.0.0.0")); ManagementPack mpAAConnectorWorkflows = emg.GetManagementPack("SCSM.AzureAutomation.Workflows", null, new Version("1.0.0.0")); ManagementPackClass classAAConnector = mpConnectors.GetClass("SCSM.AzureAutomation.Connector"); String strConnectorID = emoAAConnector[classAAConnector, "Id"].ToString(); ManagementPackRule ruleConnector = mpAAConnectorWorkflows.GetRule(strConnectorID); //Update the Enabled property or delete as appropriate if (parameters.Contains("Delete")) { ruleConnector.Status = ManagementPackElementStatus.PendingDelete; } else if (parameters.Contains("Disable")) { emoAAConnector[classAAConnector, "Enabled"].Value = false; ruleConnector.Enabled = ManagementPackMonitoringLevel.@false; ruleConnector.Status = ManagementPackElementStatus.PendingUpdate; } else if (parameters.Contains("Enable")) { emoAAConnector[classAAConnector, "Enabled"].Value = true; ruleConnector.Enabled = ManagementPackMonitoringLevel.@true; ruleConnector.Status = ManagementPackElementStatus.PendingUpdate; } //Commit the changes to the connector object and rule emoAAConnector.Commit(); mpAAConnectorWorkflows.AcceptChanges(); //Update the view when done so the item is either removed or the updated Enabled value shows RequestViewRefresh(); } }
private void CreateConnectorInstance() { try { //Get the server name to connect to String strServerName = Registry.GetValue("HKEY_CURRENT_USER\\Software\\Microsoft\\System Center\\2010\\Service Manager\\Console\\User Settings", "SDKServiceMachine", "localhost").ToString(); //Conneect to the server EnterpriseManagementGroup emg = new EnterpriseManagementGroup(strServerName); //Get the System MP so we can get the system key token and version so we can get other MPs using that info ManagementPack mpSystem = emg.ManagementPacks.GetManagementPack(SystemManagementPack.System); string strSystemKeyToken = mpSystem.KeyToken; ManagementPack mpSubscriptions = emg.GetManagementPack("Microsoft.SystemCenter.Subscriptions", strSystemKeyToken, new Version("1.0.0.0")); //Also get the System Center and Connector MPs - we'll need things from those MPs later ManagementPack mpSystemCenter = emg.ManagementPacks.GetManagementPack(SystemManagementPack.SystemCenter); ManagementPack mpConnectors = emg.GetManagementPack("SCSM.AzureAutomation", "ac1fe0583b6c84af", new Version("1.0.0.0")); ManagementPack mpAAConnectorWorkflows = emg.GetManagementPack("SCSM.AzureAutomation.Workflows", null, new Version("1.0.0.0")); //Get the AzureAutomationConnector class in the Connectors MP ManagementPackClass classAAConnector = mpConnectors.GetClass("SCSM.AzureAutomation.Connector"); //Create a new CreatableEnterpriseManagementObject. We'll set the properties on this and then post it to the database. EnterpriseManagementObject cemoAAConnector = new CreatableEnterpriseManagementObject(emg, classAAConnector); //Sytem.Entity properties cemoAAConnector[classAAConnector, "DisplayName"].Value = this.DisplayName; //Required //Microsoft.SystemCenter.Connector properties //This is just a tricky way to create a unique ID which conforms to the syntax rules for MP element ID attribute values. String strConnectorID = String.Format(CultureInfo.InvariantCulture, "{0}.{1}", "AAConnector", Guid.NewGuid().ToString("N")); cemoAAConnector[classAAConnector, "Id"].Value = strConnectorID; //Required; Key //System.LinkingFramework.DataSource properties cemoAAConnector[classAAConnector, "DataProviderDisplayName"].Value = "Azure Automation Connector"; //Optional, shown in Connectors view cemoAAConnector[classAAConnector, "Enabled"].Value = true; //Optional, shown in Connectors view cemoAAConnector[classAAConnector, "Name"].Value = this.DisplayName; //SCSM.AzureAutomation.Connector properties cemoAAConnector[classAAConnector, "AutomationAccount"].Value = this.AutomationAccount; cemoAAConnector[classAAConnector, "SubscriptionID"].Value = this.SubscriptionID; cemoAAConnector[classAAConnector, "ResourceGroup"].Value = this.ResourceGroup; cemoAAConnector[classAAConnector, "RunAsAccountName"].Value = this.RunAsAccountName; cemoAAConnector[classAAConnector, "RunAsAccountPassword"].Value = this.RunAsAccountPassword; cemoAAConnector[classAAConnector, "RefreshIntervalHours"].Value = this.RefreshIntervalHours; //Create Connector instance cemoAAConnector.Commit(); //Now we need to create the CSV Connector rule... //Get the Scheduler data source module type from the System MP and the Windows Workflow Task Write Action Module Type from the Subscription MP ManagementPackDataSourceModuleType dsmtScheduler = (ManagementPackDataSourceModuleType)mpSystem.GetModuleType("System.Scheduler"); ManagementPackWriteActionModuleType wamtWindowsWorkflowTaskWriteAction = (ManagementPackWriteActionModuleType)mpSubscriptions.GetModuleType("Microsoft.EnterpriseManagement.SystemCenter.Subscription.WindowsWorkflowTaskWriteAction"); //Create a new rule for the CSV Connector in the Connectors MP. Set the name of this rule to be the same as the connector instance ID so there is a pairing between them ManagementPackRule ruleAAConnector = new ManagementPackRule(mpAAConnectorWorkflows, strConnectorID); //Set the target and other properties of the rule ruleAAConnector.Target = mpSystemCenter.GetClass("Microsoft.SystemCenter.SubscriptionWorkflowTarget"); //Create a new Data Source Module in the new CSV Connector rule ManagementPackDataSourceModule dsmSchedule = new ManagementPackDataSourceModule(ruleAAConnector, "DS1"); //Set the configuration of the data source rule. Pass in the frequency (number of minutes) dsmSchedule.Configuration = "<Scheduler>" + "<SimpleReccuringSchedule>" + "<Interval Unit=\"Hours\">" + strRefreshIntervalHours + "</Interval>" + "</SimpleReccuringSchedule>" + "<ExcludeDates />" + "</Scheduler>"; //Set the Schedule Data Source Module Type to the Simple Schedule Module Type from the System MP dsmSchedule.TypeID = dsmtScheduler; //Add the Scheduler Data Source to the Rule ruleAAConnector.DataSourceCollection.Add(dsmSchedule); //Now repeat essentially the same process for the Write Action module... //Create a new Write Action Module in the CSV Connector rule ManagementPackWriteActionModule wamAAConnector = new ManagementPackWriteActionModule(ruleAAConnector, "WA1"); //Set the Configuration XML wamAAConnector.Configuration = "<Subscription>" + "<WindowsWorkflowConfiguration>" + //Specify the Windows Workflow Foundation workflow Assembly name here "<AssemblyName>SCSM.AzureAutomation.Workflows.AT</AssemblyName>" + //Specify the type name of the workflow to call in the assembly here: "<WorkflowTypeName>WorkflowAuthoring.RefreshConnector</WorkflowTypeName>" + "<WorkflowParameters>" + //Pass in the parameters here. In this case the two parameters are the data file path and the mapping file path "<WorkflowParameter Name=\"RefreshConnectorScript_ConnectorId\" Type=\"string\">" + strConnectorID + "</WorkflowParameter>" + "</WorkflowParameters>" + "<RetryExceptions />" + "<RetryDelaySeconds>60</RetryDelaySeconds>" + "<MaximumRunningTimeSeconds>300</MaximumRunningTimeSeconds>" + "</WindowsWorkflowConfiguration>" + "</Subscription>"; //Set the module type of the module to be the Windows Workflow Task Write Action Module Type from the Subscriptions MP. wamAAConnector.TypeID = wamtWindowsWorkflowTaskWriteAction; //Add the Write Action Module to the rule ruleAAConnector.WriteActionCollection.Add(wamAAConnector); //Mark the rule as pending update ruleAAConnector.Status = ManagementPackElementStatus.PendingAdd;; //Accept the rule changes which updates the database mpAAConnectorWorkflows.AcceptChanges(); } catch (Exception e) { MessageBox.Show(e.Message + e.InnerException.Message); } }
private void CreateConnectorInstance() { try { //Get the server name to connect to String strServerName = Registry.GetValue("HKEY_CURRENT_USER\\Software\\Microsoft\\System Center\\2010\\Service Manager\\Console\\User Settings", "SDKServiceMachine", "localhost").ToString(); //Conneect to the server EnterpriseManagementGroup emg = new EnterpriseManagementGroup(strServerName); //Get the System MP so we can get the system key token and version so we can get other MPs using that info ManagementPack mpSystem = emg.ManagementPacks.GetManagementPack(SystemManagementPack.System); string strSystemKeyToken = mpSystem.KeyToken; ManagementPack mpSubscriptions = emg.GetManagementPack("Microsoft.SystemCenter.Subscriptions", strSystemKeyToken, new Version("1.0.0.0")); //Also get the System Center and Connector MPs - we'll need things from those MPs later ManagementPack mpSystemCenter = emg.ManagementPacks.GetManagementPack(SystemManagementPack.SystemCenter); ManagementPack mpConnectors = emg.GetManagementPack("SCSM.AzureAutomation", "ac1fe0583b6c84af", new Version("1.0.0.0")); ManagementPack mpAAConnectorWorkflows = emg.GetManagementPack("SCSM.AzureAutomation.Workflows", null, new Version("1.0.0.0")); //Get the AzureAutomationConnector class in the Connectors MP ManagementPackClass classAAConnector = mpConnectors.GetClass("SCSM.AzureAutomation.Connector"); //Create a new CreatableEnterpriseManagementObject. We'll set the properties on this and then post it to the database. EnterpriseManagementObject cemoAAConnector = new CreatableEnterpriseManagementObject(emg, classAAConnector); //Sytem.Entity properties cemoAAConnector[classAAConnector, "DisplayName"].Value = this.DisplayName; //Required //Microsoft.SystemCenter.Connector properties //This is just a tricky way to create a unique ID which conforms to the syntax rules for MP element ID attribute values. String strConnectorID = String.Format(CultureInfo.InvariantCulture, "{0}.{1}", "AAConnector", Guid.NewGuid().ToString("N")); cemoAAConnector[classAAConnector, "Id"].Value = strConnectorID; //Required; Key //System.LinkingFramework.DataSource properties cemoAAConnector[classAAConnector, "DataProviderDisplayName"].Value = "Azure Automation Connector"; //Optional, shown in Connectors view cemoAAConnector[classAAConnector, "Enabled"].Value = true; //Optional, shown in Connectors view cemoAAConnector[classAAConnector, "Name"].Value = this.DisplayName; //SCSM.AzureAutomation.Connector properties cemoAAConnector[classAAConnector, "AutomationAccount"].Value = this.AutomationAccount; cemoAAConnector[classAAConnector, "SubscriptionID"].Value = this.SubscriptionID; cemoAAConnector[classAAConnector, "ResourceGroup"].Value = this.ResourceGroup; cemoAAConnector[classAAConnector, "RunAsAccountName"].Value = this.RunAsAccountName; cemoAAConnector[classAAConnector, "RunAsAccountPassword"].Value = this.RunAsAccountPassword; cemoAAConnector[classAAConnector, "RefreshIntervalHours"].Value = this.RefreshIntervalHours; //Create Connector instance cemoAAConnector.Commit(); //Now we need to create the CSV Connector rule... //Get the Scheduler data source module type from the System MP and the Windows Workflow Task Write Action Module Type from the Subscription MP ManagementPackDataSourceModuleType dsmtScheduler = (ManagementPackDataSourceModuleType)mpSystem.GetModuleType("System.Scheduler"); ManagementPackWriteActionModuleType wamtWindowsWorkflowTaskWriteAction = (ManagementPackWriteActionModuleType)mpSubscriptions.GetModuleType("Microsoft.EnterpriseManagement.SystemCenter.Subscription.WindowsWorkflowTaskWriteAction"); //Create a new rule for the CSV Connector in the Connectors MP. Set the name of this rule to be the same as the connector instance ID so there is a pairing between them ManagementPackRule ruleAAConnector = new ManagementPackRule(mpAAConnectorWorkflows, strConnectorID); //Set the target and other properties of the rule ruleAAConnector.Target = mpSystemCenter.GetClass("Microsoft.SystemCenter.SubscriptionWorkflowTarget"); //Create a new Data Source Module in the new CSV Connector rule ManagementPackDataSourceModule dsmSchedule = new ManagementPackDataSourceModule(ruleAAConnector, "DS1"); //Set the configuration of the data source rule. Pass in the frequency (number of minutes) dsmSchedule.Configuration = "<Scheduler>" + "<SimpleReccuringSchedule>" + "<Interval Unit=\"Hours\">" + strRefreshIntervalHours + "</Interval>" + "</SimpleReccuringSchedule>" + "<ExcludeDates />" + "</Scheduler>"; //Set the Schedule Data Source Module Type to the Simple Schedule Module Type from the System MP dsmSchedule.TypeID = dsmtScheduler; //Add the Scheduler Data Source to the Rule ruleAAConnector.DataSourceCollection.Add(dsmSchedule); //Now repeat essentially the same process for the Write Action module... //Create a new Write Action Module in the CSV Connector rule ManagementPackWriteActionModule wamAAConnector = new ManagementPackWriteActionModule(ruleAAConnector, "WA1"); //Set the Configuration XML wamAAConnector.Configuration = "<Subscription>" + "<WindowsWorkflowConfiguration>" + //Specify the Windows Workflow Foundation workflow Assembly name here "<AssemblyName>SCSM.AzureAutomation.Workflows.AT</AssemblyName>" + //Specify the type name of the workflow to call in the assembly here: "<WorkflowTypeName>WorkflowAuthoring.RefreshConnector</WorkflowTypeName>" + "<WorkflowParameters>" + //Pass in the parameters here. In this case the two parameters are the data file path and the mapping file path "<WorkflowParameter Name=\"RefreshConnectorScript_ConnectorId\" Type=\"string\">" + strConnectorID + "</WorkflowParameter>" + "</WorkflowParameters>" + "<RetryExceptions />" + "<RetryDelaySeconds>60</RetryDelaySeconds>" + "<MaximumRunningTimeSeconds>300</MaximumRunningTimeSeconds>" + "</WindowsWorkflowConfiguration>" + "</Subscription>"; //Set the module type of the module to be the Windows Workflow Task Write Action Module Type from the Subscriptions MP. wamAAConnector.TypeID = wamtWindowsWorkflowTaskWriteAction; //Add the Write Action Module to the rule ruleAAConnector.WriteActionCollection.Add(wamAAConnector); //Mark the rule as pending update ruleAAConnector.Status = ManagementPackElementStatus.PendingAdd; ; //Accept the rule changes which updates the database mpAAConnectorWorkflows.AcceptChanges(); } catch (Exception e) { MessageBox.Show(e.Message + e.InnerException.Message); } }
public static void CreateNotificationRule(string strDisplayName, string strName, string strCriteria, EnterpriseManagementObject emoUser, ManagementPackClass mpc, ManagementPackObjectTemplate mpt, ref ManagementPack mp, EnterpriseManagementGroup emg) { ManagementPack mpSystemCenterLibrary = Helper.GetManagementPackByName("Microsoft.SystemCenter.Library", emg); ManagementPack mpSubscriptions = Helper.GetManagementPackByName("Microsoft.SystemCenter.Subscriptions", emg); string strSubscriptionsMPAlias = MakeMPElementSafeName(mpSubscriptions.Name); AddManagementPackReference(strSubscriptionsMPAlias, mpSubscriptions.Name, ref mp, emg); string strSystemCenterLibraryMPAlias = MakeMPElementSafeName(mpSystemCenterLibrary.Name); AddManagementPackReference(strSystemCenterLibraryMPAlias, mpSystemCenterLibrary.Name, ref mp, emg); ManagementPackClass mpcSubscriptionWorkflowTarget = GetClassByName("Microsoft.SystemCenter.SubscriptionWorkflowTarget", emg); ManagementPackDataSourceModuleType mpdsmtSubscription = (ManagementPackDataSourceModuleType)mpSubscriptions.GetModuleType("Microsoft.SystemCenter.CmdbInstanceSubscription.DataSourceModule"); ManagementPackRule mpr = new ManagementPackRule(mp, MakeMPElementSafeName(String.Format("NotificationSubscription.{0}", Guid.NewGuid()))); mpr.Enabled = ManagementPackMonitoringLevel.@true; mpr.ConfirmDelivery = true; mpr.Remotable = true; mpr.Priority = ManagementPackWorkflowPriority.Normal; mpr.Category = ManagementPackCategoryType.System; mpr.DiscardLevel = 100; mpr.Target = mp.ProcessElementReference <ManagementPackClass>(String.Format("$MPElement[Name=\"{0}!{1}\"]$", strSystemCenterLibraryMPAlias, mpcSubscriptionWorkflowTarget.Name)); ManagementPackDataSourceModule mpdsmSubscription = new ManagementPackDataSourceModule(mpr, "DS"); mpdsmSubscription.TypeID = mp.ProcessElementReference <ManagementPackDataSourceModuleType>(String.Format("$MPElement[Name=\"{0}!{1}\"]$", strSubscriptionsMPAlias, mpdsmtSubscription.Name)); StringBuilder sbDataSourceConfiguration = new StringBuilder(); sbDataSourceConfiguration.Append("<Subscription>"); sbDataSourceConfiguration.Append(String.Format("<InstanceSubscription Type=\"{0}\">", mpc.Id.ToString())); sbDataSourceConfiguration.Append(strCriteria); sbDataSourceConfiguration.Append("</InstanceSubscription>"); sbDataSourceConfiguration.Append("<PollingIntervalInSeconds>60</PollingIntervalInSeconds>"); sbDataSourceConfiguration.Append("<BatchSize>100</BatchSize>"); sbDataSourceConfiguration.Append("</Subscription>"); mpdsmSubscription.Configuration = sbDataSourceConfiguration.ToString(); ManagementPackWriteActionModuleType mpwamtSubscription = (ManagementPackWriteActionModuleType)mpSubscriptions.GetModuleType("Microsoft.EnterpriseManagement.SystemCenter.Subscription.WindowsWorkflowTaskWriteAction"); ManagementPackWriteActionModule mpwamSubscription = new ManagementPackWriteActionModule(mpr, "WA"); mpwamSubscription.TypeID = mp.ProcessElementReference <ManagementPackWriteActionModuleType>(String.Format("$MPElement[Name=\"{0}!{1}\"]$", strSubscriptionsMPAlias, mpwamtSubscription.Name)); StringBuilder sbWriteActionConfiguration = new StringBuilder(); sbWriteActionConfiguration.Append("<Subscription>"); sbWriteActionConfiguration.Append("<VisibleWorkflowStatusUi>true</VisibleWorkflowStatusUi>"); sbWriteActionConfiguration.Append("<EnableBatchProcessing>true</EnableBatchProcessing>"); sbWriteActionConfiguration.Append("<WindowsWorkflowConfiguration>"); sbWriteActionConfiguration.Append("<AssemblyName>Microsoft.EnterpriseManagement.Notifications.Workflows</AssemblyName>"); sbWriteActionConfiguration.Append("<WorkflowTypeName>Microsoft.EnterpriseManagement.Notifications.Workflows.SendNotificationsActivity</WorkflowTypeName>"); sbWriteActionConfiguration.Append("<WorkflowParameters>"); sbWriteActionConfiguration.Append("<WorkflowParameter Name=\"SubscriptionId\" Type=\"guid\">$MPElement$</WorkflowParameter>"); sbWriteActionConfiguration.Append("<WorkflowArrayParameter Name=\"DataItems\" Type=\"string\">"); sbWriteActionConfiguration.Append("<Item>$Data/.$</Item>"); sbWriteActionConfiguration.Append("</WorkflowArrayParameter>"); sbWriteActionConfiguration.Append("<WorkflowArrayParameter Name=\"InstanceIds\" Type=\"string\">"); sbWriteActionConfiguration.Append("<Item>$Data/BaseManagedEntityId$</Item>"); sbWriteActionConfiguration.Append("</WorkflowArrayParameter>"); sbWriteActionConfiguration.Append("<WorkflowArrayParameter Name=\"TemplateIds\" Type=\"string\">"); sbWriteActionConfiguration.Append(String.Format("<Item>{0}</Item>", mpt.Id.ToString())); sbWriteActionConfiguration.Append("</WorkflowArrayParameter>"); sbWriteActionConfiguration.Append("<WorkflowArrayParameter Name=\"PrimaryUserList\" Type=\"string\">"); sbWriteActionConfiguration.Append(String.Format("<Item>{0}</Item>", emoUser.Id.ToString())); sbWriteActionConfiguration.Append("</WorkflowArrayParameter>"); sbWriteActionConfiguration.Append("</WorkflowParameters>"); sbWriteActionConfiguration.Append("<RetryExceptions/>"); sbWriteActionConfiguration.Append("<RetryDelaySeconds>60</RetryDelaySeconds>"); sbWriteActionConfiguration.Append("<MaximumRunningTimeSeconds>7200</MaximumRunningTimeSeconds>"); sbWriteActionConfiguration.Append("</WindowsWorkflowConfiguration>"); sbWriteActionConfiguration.Append("</Subscription>"); mpwamSubscription.Configuration = sbWriteActionConfiguration.ToString(); mpr.DataSourceCollection.Add(mpdsmSubscription); mpr.WriteActionCollection.Add(mpwamSubscription); mpr.Status = ManagementPackElementStatus.PendingAdd; mp.AcceptChanges(); }
//This Saves the values that have been set throughout the Wizard Pages back into the management pack so the //Advanced Action Log Notifier can read them via ((Get-SCSMObject -Class (Get-SCSMClass -Name "AdhocAdam.Advanced.Action.Log.Notify.AdminSettings$"))) public override void AcceptChanges(WizardMode wizardMode) { //Get the server name to connect to and then connect String strServerName = Registry.GetValue("HKEY_CURRENT_USER\\Software\\Microsoft\\System Center\\2010\\Service Manager\\Console\\User Settings", "SDKServiceMachine", "localhost").ToString(); EnterpriseManagementGroup emg = new EnterpriseManagementGroup(strServerName); //Get the Advanced Action Notifier class by GUID ManagementPackClass adhocAdamAALNClass = emg.EntityTypes.GetClass(new Guid("49a053e7-6080-e211-fd79-ca3607eecce7")); //Get the SMLets Exchange Connector Settings object using the object GUID EnterpriseManagementObject emoAdminSetting = emg.EntityObjects.GetObject <EnterpriseManagementObject>(this.EnterpriseManagementObjectID, ObjectQueryOptions.Default); //Workflow Status //Retrieve the unsealed workflow management pack that contains the workflows, to control whether or not the workflows are enabled/disabled //https://marcelzehner.ch/2013/07/04/a-look-at-scsm-workflows-and-notifications-and-how-to-manage-them-by-using-scripts/ ManagementPack adhocAdamAALWFClass = emg.ManagementPacks.GetManagementPack(new Guid("4db18489-38fa-895a-7149-902b675dc752")); ManagementPackRule assignedNotificationWF = adhocAdamAALWFClass.GetRule("AdhocAdam.Advanced.Action.Log.Notify.TroubleTicketAnalystCommentNotification"); ManagementPackRule affectedNotificationWF = adhocAdamAALWFClass.GetRule("AdhocAdam.Advanced.Action.Log.Notify.TroubleTicketUserCommentNotification"); ManagementPackRule workItemCommentNotificationWF = adhocAdamAALWFClass.GetRule("AdhocAdam.Advanced.Action.Log.Notify.WorkItemUserCommentNotification"); assignedNotificationWF.Status = ManagementPackElementStatus.PendingUpdate; affectedNotificationWF.Status = ManagementPackElementStatus.PendingUpdate; workItemCommentNotificationWF.Status = ManagementPackElementStatus.PendingUpdate; //Notify Assigned To if (this.IsNotifyAssignedUserEnabled == true) { assignedNotificationWF.Enabled = ManagementPackMonitoringLevel.@true; } else { assignedNotificationWF.Enabled = ManagementPackMonitoringLevel.@false; } //Notify Affected User if (this.IsNotifyAffecteddUserEnabled == true) { affectedNotificationWF.Enabled = ManagementPackMonitoringLevel.@true; } else { affectedNotificationWF.Enabled = ManagementPackMonitoringLevel.@false; } //Service Request Comments if (this.IsNotifyWorkItemCommentsEnabled == true) { workItemCommentNotificationWF.Enabled = ManagementPackMonitoringLevel.@true; } else { workItemCommentNotificationWF.Enabled = ManagementPackMonitoringLevel.@false; } //save the changes back to the unsealed mp adhocAdamAALWFClass.AcceptChanges(); //Azure Settings emoAdminSetting[adhocAdamAALNClass, "EnableAzureTranslate"].Value = this.IsAzureTranslateEnabled; emoAdminSetting[adhocAdamAALNClass, "ACSAPIKey"].Value = this.AzureCognitiveServicesTranslateAPIKey; //Templates try { emoAdminSetting[adhocAdamAALNClass, "TroubleTicketAnalystCommentTemplate"].Value = this.TroubleTicketAnalystCommentTemplate.Id; } catch { } try { emoAdminSetting[adhocAdamAALNClass, "TroubleTicketUserCommentTemplate"].Value = this.TroubleTicketUserCommentTemplate.Id; } catch { } try { emoAdminSetting[adhocAdamAALNClass, "WorkItemCommentTemplate"].Value = this.WorkItemCommentLogTemplate.Id; } catch { } //Update the MP emoAdminSetting.Commit(); this.WizardResult = WizardResult.Success; }
//This Loads the settings that have been set in the management pack. In some cases for user protection, they load values from the function below //so on Save some kind of value is committed. This provides the means to suggest a value once, but ignore it afterwards. internal AdminSettingWizardData(EnterpriseManagementObject emoAdminSetting) { //Get the server name to connect to and then connect String strServerName = Registry.GetValue("HKEY_CURRENT_USER\\Software\\Microsoft\\System Center\\2010\\Service Manager\\Console\\User Settings", "SDKServiceMachine", "localhost").ToString(); EnterpriseManagementGroup emg = new EnterpriseManagementGroup(strServerName); /*Get the Advanced Action Notifier class by GUID ##PowerShell SMlets equivalent: * Get-SCSMClass -name "AdhocAdam.Advanced" * Get-SCSMClass -id "49a053e7-6080-e211-fd79-ca3607eecce7" */ ManagementPackClass adhocAdamAALNClass = emg.EntityTypes.GetClass(new Guid("49a053e7-6080-e211-fd79-ca3607eecce7")); //Azure Settings try { this.IsAzureTranslateEnabled = Boolean.Parse(emoAdminSetting[adhocAdamAALNClass, "EnableAzureTranslate"].ToString()); } catch { this.IsAzureTranslateEnabled = false; } this.AzureCognitiveServicesTranslateAPIKey = emoAdminSetting[adhocAdamAALNClass, "ACSAPIKey"].ToString(); //Retrieve the unsealed workflow management pack that contains the workflows, to control whether or not the workflows are enabled/disabled //https://marcelzehner.ch/2013/07/04/a-look-at-scsm-workflows-and-notifications-and-how-to-manage-them-by-using-scripts/ ManagementPack adhocAdamAALWFClass = emg.ManagementPacks.GetManagementPack(new Guid("4db18489-38fa-895a-7149-902b675dc752")); ManagementPackRule assignedNotificationWF = adhocAdamAALWFClass.GetRule("AdhocAdam.Advanced.Action.Log.Notify.TroubleTicketAnalystCommentNotification"); ManagementPackRule affectedNotificationWF = adhocAdamAALWFClass.GetRule("AdhocAdam.Advanced.Action.Log.Notify.TroubleTicketUserCommentNotification"); ManagementPackRule workItemCommentNotificationWF = adhocAdamAALWFClass.GetRule("AdhocAdam.Advanced.Action.Log.Notify.WorkItemUserCommentNotification"); //Assigned User notification if (assignedNotificationWF.Enabled == ManagementPackMonitoringLevel.@false) { this.IsNotifyAssignedUserEnabled = false; } else { this.IsNotifyAssignedUserEnabled = true; } //Affected User notification if (affectedNotificationWF.Enabled == ManagementPackMonitoringLevel.@false) { this.IsNotifyAffecteddUserEnabled = false; } else { this.IsNotifyAffecteddUserEnabled = true; } //Work Item (Service Request) notification if (workItemCommentNotificationWF.Enabled == ManagementPackMonitoringLevel.@false) { this.IsNotifyWorkItemCommentsEnabled = false; } else { this.IsNotifyWorkItemCommentsEnabled = true; } //Templates //First, we'll pull all of the Email Templates from the Admin Settings pane //Get-SCSMClass -id "0814d9a7-8332-a5df-2ec8-34d07f3d40db" //Get-SCSMClass -name "System.Notification.Template.SMTP" ManagementPackObjectTemplateCriteria mpotcTTATemplates = new ManagementPackObjectTemplateCriteria("TypeID = '0814d9a7-8332-a5df-2ec8-34d07f3d40db'"); this.TroubleTicketAnalystCommentTemplates = emg.Templates.GetObjectTemplates(mpotcTTATemplates); this.TroubleTicketAnalystCommentTemplates = this.TroubleTicketAnalystCommentTemplates.OrderBy(template => template.DisplayName).ToList(); try { Guid ttacTemplate = (Guid)emoAdminSetting[null, "TroubleTicketAnalystCommentTemplate"].Value; this.TroubleTicketAnalystCommentTemplate = emg.Templates.GetObjectTemplate(ttacTemplate); } catch { } ManagementPackObjectTemplateCriteria mpotcTTUTemplates = new ManagementPackObjectTemplateCriteria("TypeID = '0814d9a7-8332-a5df-2ec8-34d07f3d40db'"); this.TroubleTicketUserCommentTemplates = emg.Templates.GetObjectTemplates(mpotcTTUTemplates); this.TroubleTicketUserCommentTemplates = this.TroubleTicketUserCommentTemplates.OrderBy(template => template.DisplayName).ToList(); try { Guid ttucTemplate = (Guid)emoAdminSetting[null, "TroubleTicketUserCommentTemplate"].Value; this.TroubleTicketUserCommentTemplate = emg.Templates.GetObjectTemplate(ttucTemplate); } catch { } ManagementPackObjectTemplateCriteria mpotcWICLTemplates = new ManagementPackObjectTemplateCriteria("TypeID = '0814d9a7-8332-a5df-2ec8-34d07f3d40db'"); this.WorkItemCommentLogTemplates = emg.Templates.GetObjectTemplates(mpotcWICLTemplates); this.WorkItemCommentLogTemplates = this.WorkItemCommentLogTemplates.OrderBy(template => template.DisplayName).ToList(); try { Guid wiclTemplate = (Guid)emoAdminSetting[null, "WorkItemCommentTemplate"].Value; this.WorkItemCommentLogTemplate = emg.Templates.GetObjectTemplate(wiclTemplate); } catch { } //load the MP this.EnterpriseManagementObjectID = emoAdminSetting.Id; }