protected override void ProcessRecord() { try { ManagementPackClass clsAnnouncement = SMHelpers.GetManagementPackClass(ClassTypes.System_Announcement_Item, SMHelpers.GetManagementPack(ManagementPacks.System_AdminItem_Library, _mg), _mg); ManagementPackEnumeration enumPriority = null; switch (_Priority) { case "Low": enumPriority = SMHelpers.GetEnum(Enumerations.System_Announcement_PriorityEnum_Low, _mg); break; case "Critical": enumPriority = SMHelpers.GetEnum(Enumerations.System_Announcement_PriorityEnum_Critical, _mg); break; case "Medium": enumPriority = SMHelpers.GetEnum(Enumerations.System_Announcement_PriorityEnum_Medium, _mg); break; default: enumPriority = SMHelpers.GetEnum(Enumerations.System_Announcement_PriorityEnum_Medium, _mg); break; } CreatableEnterpriseManagementObject emo = new CreatableEnterpriseManagementObject(_mg, clsAnnouncement); emo[clsAnnouncement, "Id"].Value = System.Guid.NewGuid().ToString(); if (_DisplayName != null) { emo[clsAnnouncement, "DisplayName"].Value = _DisplayName; } emo[clsAnnouncement, "Title"].Value = _DisplayName; if (_Body != null) { emo[clsAnnouncement, "Body"].Value = _Body; } emo[clsAnnouncement, "Priority"].Value = enumPriority.Id; emo[clsAnnouncement, "ExpirationDate"].Value = _ExpirationDate; emo.Commit(); if (_passThru) { WriteObject(ServiceManagerObjectHelper.AdaptManagementObject(this, _mg.EntityObjects.GetObject <EnterpriseManagementObject>(emo.Id, ObjectQueryOptions.Default))); } } catch (Exception) { } }
private void OnSubmitted(object sender, FormCommandExecutedEventArgs e) { try { CurrentDataItem = this.DataContext as IDataItem; if (!((bool)CurrentDataItem["$IsNew$"])) { CurrentEMO = emg.EntityObjects.GetObject <EnterpriseManagementObject>((Guid)CurrentDataItem["$Id$"], ObjectQueryOptions.Default); if (DrawingImage != null) { MemoryStream ms = new MemoryStream(); DrawingImage.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg); CurrentEMO[classNetworkMap, "Image"].Value = ms; CurrentEMO.Commit(); ms.Close(); } else { CurrentEMO[classNetworkMap, "Image"].Value = null; CurrentEMO.Commit(); } } else { if (DrawingImage != null) { MemoryStream ms = new MemoryStream(); DrawingImage.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg); CreatableEnterpriseManagementObject CreateNetworkMap = new CreatableEnterpriseManagementObject(emg, classNetworkMap); CreateNetworkMap[classNetworkMap, "Image"].Value = ms; CreateNetworkMap.Commit(); ms.Close(); } } } catch (Exception exc) { System.Windows.MessageBox.Show(DateTime.Now + " : " + "Error in OnSubmitted() " + exc.Message); } }
private void brd_Loc_Create_MouseDown(object sender, MouseButtonEventArgs e) { if (LocationTreeView.SelectedItem != null) { CreatableEnterpriseManagementObject newLocation = new CreatableEnterpriseManagementObject(emg, locationClass); //Add some property values newLocation[locationClass, "DisplayName"].Value = "Add some info"; newLocation.Commit(); //Treeview Item - Parent Item TreeViewItem TR = (TreeViewItem)LocationTreeView.SelectedItem; // Get an object by GUID Guid G = new Guid(TR.Tag.ToString()); EnterpriseManagementObject treeviewEMO = emg.EntityObjects.GetObject <EnterpriseManagementObject>(G, ObjectQueryOptions.Default); CreatableEnterpriseManagementRelationshipObject relationship = new CreatableEnterpriseManagementRelationshipObject(emg, relationClass); relationship.SetSource(treeviewEMO); relationship.SetTarget(newLocation); relationship.Commit(); //FillTreeView.Now(emg, locationClass, relationClass, LocationTreeView); Fill(); //Convert EnterpriseManagementObject to IDataItem EnterpriseManagementObjectDataType dataType = new EnterpriseManagementObjectDataType(locationClass); IDataItem newlocationDataItem = dataType.CreateProxyInstance(newLocation); //Open Console form for created object //ConsoleContextHelper.Instance.PopoutForm(itemIdentity); Microsoft.EnterpriseManagement.GenericForm.FormUtilities.Instance.PopoutForm(newlocationDataItem); } else { MessageBox.Show("Please select parent location!", "No location selected", MessageBoxButton.OK, MessageBoxImage.Warning); Trace.WriteLine(DateTime.Now + " : " + "Not have Values for create Rel"); } }
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); Version verSystemVersion = mpSystem.Version; string strSystemKeyToken = mpSystem.KeyToken; //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", 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.Connecto 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; //Create Connector instance cemoAAConnector.Commit(); //Accept the rule changes which updates the database mpConnectors.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); } }
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); } }