pfizer viagra

Look Ma No Guids!

This API is for system Center Service Manager. It’s foundation is in a project I created CodePlex 18 months ago called System Center Service Manager Façade. While I found it to be a great help to me in writing custom management packs and custom SCSM functionality, it was too large and very bloated and did not follow C# generally accepted syntax.
This API is much cleaner and efficient. It covers the main objects used in most customizations. Currently it is used in production servers without incident. I hope you find it as useful as I have. The code is based on an out-of-the-box System Center Service Manager 2012 server.
It covers the following high-level objects, classes and type projections and provides strongly typed classes

  • Incident
  • Change Request
  • Activity
  • Problem
  • Service Request
  • Release Management

The API also has a comprehensive criteria builder that allows you to build criteria in code rather than XML. Here are some examples

         1:   
         2:  // Initialize the server conection context
         3:  Context.Init();
         4:   
         5:  //Build criteria for all change request
         6:   var statusExpression =
         7:                  new SimpleExpression(ChangeRequestPropertyCriteria.Status,
         8:                                       ChangeStatusEnum.InProgress.Id.ToString("B"),
         9:                                       ExpressionOperator.Equal);
        10:   
        11:  // Get a bulder for the System.WorkItem.ChangeRequest and where stautus is "InProgess"
        12:   var builder = new ObjectCriteriaBuilder(ChangeRequestHelper.ManagementPackClass, statusExpression 
        13:   
        14:  // Add the to the SCSM MP for change request
        15:   builder.AddReference(ChangeRequestPropertyCriteria.ManagementPackReference);
        16:   
        17:  // get the xml criteria 
        18:  var criteria = builder.GetCriteria();
        19:   
        20:  //Get a stronly typed list of ChangeRequests
        21:  var changes = Context.GetObjectReader(criteria, ObjectQueryOptions.Default).Select(t => new ChangeRequest(t));
        22:   
        23:  // Some linq magic
        24:  changes.ToList().ForEach(DoStuff);
        25:   

      You can download the source code on codeplex http://scsmapi.codeplex.com

      The API is generated using complex templates. The templates are available for purchase at www.savviety.com or email gary at that domain.

    New SCSM API – Totally Rewritten – Even Easier – 9 out of 10 dentists recommend

    I will be posting a new System Center Service Manager (SCSM) API to CodePlex later today or tomorrow. It is a total rewrite of the old SCSMFade API

    Here is some cool bits I knocked put for a client.

    var statusExpression =
                    new SimpleExpression(ChangeRequestCriteria.Status,
                        ChangeStatusEnum.InProgress.Id.ToString("B"), 
                        ExpressionOperator.Equal);
    var targetDate = DateTime.UtcNow.AddHours(8).ToString("G");
    
    var startDateExpression = new SimpleExpression(ChangeRequestCriteria.ScheduledStartDate,
                                                        targetDate, 
                                                        ExpressionOperator.Less);
    
    var andExpression = new AndExpression(new List<SimpleExpression>{statusExpression,startDateExpression});
    var builder = new ObjectCriteriaBuilder(ChangeRequestHelper.ManagementPackClass, andExpression);
    
    builder.AddReference(ChangeRequestCriteria.ManagementPackReference);
    
    var criteria = builder.GetCriteria();
    
    Context.Init();
               
    var changes = Context.GetObjectReader(criteria, ObjectQueryOptions.Default)
                  .Select(t => new ChangeRequest(t));
    
    changes.ToList().ForEach(DoStuff);
    
    

    Validate Management Packs in Visual Studio with XSD

    I do not know why Microsoft makes this so hard. I was hoping the would help me, but it does not work for me.

    Anyways, I do not have permission to distribute the ManagementPackSchema.v2.0.xsd, but I can tell you how to get it.

    Create a c# console program

    
     class Program
        {
            static void Main(string[] args)
            {
                var assembly = Assembly.LoadFile(@"<Drive:>\Program Files\Microsoft System Center 2012\Service Manager\SDK Binaries\Microsoft.EnterpriseManagement.Core.dll");
    
                Directory.CreateDirectory("schemas\\maml");
                Directory.CreateDirectory("schemas\\reporting");
                Directory.CreateDirectory("schemas");
    
                var resourceManager = new ResourceManager("ManagementPackSchema", assembly);
    
                var resourceSet = resourceManager.GetResourceSet(CultureInfo.CurrentUICulture, true, true);
                foreach (DictionaryEntry entry in resourceSet)
                {
                    var resourceKey = entry.Key.ToString();
                    var resource = entry.Value.ToString();
    
                    var bytes = Encoding.UTF8.GetBytes(resource);
                    var path = Path.Combine("schemas", resourceKey);
    
                    File.WriteAllBytes(path, bytes);
                }
    
                // move schemas to fix relative paths in maml.xsd
                var files = Directory.GetFiles("schemas").Where(t => t.Contains("ManagementPackSchema") == false);
                foreach (var file in files)
                {
                    File.Move(file,Path.Combine("schemas\\maml", Path.GetFileName(file)));
                }
         }
        }
    

    Now copy the schema directory (if you don’t change it – bin\debug) to where you want

    Open an MP in Visual Studio and click anywhere in the XML and then right click -> properties

    Click the … button on schemas and add add the appropriate ManagementPackSchema.*.xsd to the Visual Studio Schema collection

    NOTE you must click “Do not use” on the default xml.xsd.

    Happy System Center Service Manager (SCSM)!

    Enjoy

    Increase the version number of your management packs in PowerShell

    Here it is and it has saved me. I added this PowerShell script to my VS 2012 build events and automated build to importing of the management packs.

    I will post the other script later today.

    Casting an EnterpriseManagementObject to an IDataItem

    Trying to casting an EnterpriseManagementObject to an IDataItem was killing me. Things like this are very frustrating as I am creating copies of the System Center Service Manager 2012 forms.

    Here is what I did

    // get User Class
    var @class = emg.EntityTypes.GetClass(new Guid("e2386b9b-5364-e438-a317-93836b979c56"));
    var reader = emg.EntityObjects.GetObjectReader<EnterpriseManagementObject>(@class, ObjectQueryOptions.Default);
    var userEmo = reader.FirstOrDefault(t => t[null, "UserName"].Value.ToString() == "Gary Davidson");
    var dataType = new EnterpriseManagementObjectDataType(@class);
    IDataItem iUser = dataType.CreateProxyInstance(userEmo);     
    

    Note the last two lines! they convert an EnterpriseManagementObject to an IDataItem

    Don’t pay the ransom I escaped

    I have been a little under the radar lately lets see

    Now with no other responsibilities I  can get back to this blog and my new company Savviety Consulting.

    Currently I am at MMS 2012 and Vegas. Stay tuned for a new release of SCSMFacade and the new Team Foundation Server (TFS) connector.

      Calculating priority in the System Center Service Manager portal

      There seems to be an issue when you create an incident in the System Center Service Manager (SCSM) portal that the priority is calculated after the incident is saved. This results in the update incident notification workflow been triggered. So I had to figure out how to calculate priority when an incident is saved in the portal.

      I’ll show you two ways to do it the first way is with the SDK and the second with the SCSM façade api.

      var emg = new EnterpriseManagementGroup("Your SCSM Server");
      
      // ManagementPackReferences is a class in Microsoft.Mom.BuildConstants.dll
      var settingsId = new Guid(ManagementPackReferences.SYSTEM_WORKITEM_INCIDENT_GENERALSETTING_REFERENCE);
      var mp = emg.ManagementPacks.GetManagementPack(settingsId);
      var @class = mp.GetClass("System.WorkItem.Incident.GeneralSetting");
      
      // Why "DisplayName IS NOT NULL"? I borrowed it from somewhere
      
      var criteria = new EnterpriseManagementObjectCriteria("DisplayName IS NOT NULL", @class);
      var settings = emg.EntityObjects.GetObjectReader<EnterpriseManagementObject>(criteria, ObjectQueryOptions.Default).FirstOrDefault();
      if (settings == null)
      {
          throw new InvalidOperationException("Could not retrieve Default Incident Settings");
      }
      var priorityMatrix = settings[null, "PriorityMatrix"].Value.ToString();
      
      Guid urgency, inpact; // set these to the input valuew
      
      var el = XElement.Parse(priorityMatrix);
      
      // linq abuse , but I wanted to see if I can do it in one line
      var priority = el.Elements().Where(x => x.Attribute("Id").Value == urgency.ToString()).First().Elements().Where(x => x.Attribute("Id").Value == impact.ToString()).First();
      
      var priorityValue = int.Parse(priority.Value);
      

      I know I am showing off but her is how I do it

      var priorityValue = SCSMServer.IncidentSettings.GetPriority(new Guid(urgencyId), new Guid(impactId));
      

      you can set the priority in the portal code web part CreatRequest.cs in the SetValues method

       dataItem[Microsoft.EnterpriseManagement.ServiceManager.Portal.Common.Constants.Priority] =
                      PortalHelper.GetPriority(urgency["Id"].ToString(), impact["Id"].ToString());
      

      PortalHelper is a helper class I use, but I am sure you can figure it out.

      The workflow always runs twice…

      This particular problem drove me absolutely crazy. At seemingly random times, the create incident e-mail notification workflow would run twice. This was a deal-breaker to releasing System Center Service Manager (SCSM). After a couple days of trial and error I discovered that when I entered a value in an extended property the workflow ran twice. If I just entered values in the default incident class the workflow ran once. After consulting with Microsoft support we arrived at the following solution.

      Export your management pack that contains the create incident e-mail workflow. Locate the ID of your incident extension class with the following SQL query and copy it to the clipboard.

       
      SELECT  [ManagedTypeId], [TypeName] FROM [ManagedType] WHERE IsExtensionType = 1 Order by [TimeAdded] DESC
      

      Open it up in an editor and look for the following section.

      Your guid should be “a604b942-4c7b-2fb2-28dc-61dc6f465c68″ which is the incident ID. Replace the incident id with the extension class id.

      Now your create incident notification workflow will run once.

      SCSM MonitoringHost.exe was killing me – Fixed

      I was up all night working on this and I can’t sleep so what better way to make me sleepy them write blog posts. I’ll let you know if it works.

      Like many of you on the forums and blogs you may have experienced the System Center Service Manager (SCSM) monitoringhost.exe consuming all available CPU resources for a long period of time. I opened the case with Microsoft and we proceeded to work a decision tree into well in the night with no solution. We did determined the issue was related to the sending of e-mails whether they be notification e-mails or subscription e-mails.

      This morning while waiting for the Microsoft SCSM engineer to call back and continue our diagnosis I decided to create an SMTP server locally on the SCSM server and pointed the e-mail channel to the local SMTP server instead of Exchange. After having done this the problem went away. I created about 30 change requests and incidents all with notifications and subscriptions and monitoringhost.exe did not consume the CPU as it had done before.

      Soon after the engineer called back, I was able to walk him through this solution we changed the SMTP channel back to exchange and reproduced the problem. We changed it back to the SMTP server and did not have a problem. The engineer is going to work this solution in the lab at Microsoft. While this is a work around there still is an issue for those of you who must use Exchange for the SMTP channel.

      The case is still open and I will post any resolution on this blog.

      Change Request and Incident Data passed to Activities

      I don’t know about you guys but my people were giving me hell over the fact that you could not get parent data into activity email notifications. This was a huge problem for our implementation. Below is how I solved it.

      In a nutshell I created a custom workflow activity and then bound it to whenever a change request or incident is created. The workflow activity then copies fields into an extension class for review and manual activities. Let’s start with the management pack that extends review and manual activities

      <ClassTypes>
              <ClassType ID="Interclick.ManualActivity.ExtensionClass" Accessibility="Public" Abstract="false" Base="CoreActivity!System.WorkItem.Activity.ManualActivity" Hosted="false" Singleton="false" Extension="true">
                <Property ID="ParentTitle" Type="string" AutoIncrement="false" Key="false" CaseSensitive="false" MaxLength="256" MinLength="0" Required="false"  />
                <Property ID="ParentDescription" Type="string" AutoIncrement="false" Key="false" CaseSensitive="false" MaxLength="256" MinLength="0" Required="false"  />
                <Property ID="ParentArea" Type="string" AutoIncrement="false" Key="false" CaseSensitive="false" MaxLength="256" MinLength="0" Required="false"  />
                <Property ID="ParentImpact" Type="string" AutoIncrement="false" Key="false" CaseSensitive="false" MaxLength="256" MinLength="0" Required="false"  />
                <Property ID="ParentPriority" Type="string" AutoIncrement="false" Key="false" CaseSensitive="false" MaxLength="256" MinLength="0" Required="false"  />
                <Property ID="ParentRisk" Type="string" AutoIncrement="false" Key="false" CaseSensitive="false" MaxLength="256" MinLength="0" Required="false"  />
                <Property ID="ParentScheduledStart" Type="string" AutoIncrement="false" Key="false" CaseSensitive="false" MaxLength="256" MinLength="0" Required="false"  />
                <Property ID="ParentScheduledEnd" Type="string" AutoIncrement="false" Key="false" CaseSensitive="false" MaxLength="256" MinLength="0" Required="false"  />
              </ClassType>
      
              <ClassType ID="Interclick.ReviewActivity.ExtensionClass" Accessibility="Public" Abstract="false" Base="CoreActivity!System.WorkItem.Activity.ReviewActivity" Hosted="false" Singleton="false" Extension="true">
                <Property ID="ParentTitle" Type="string" AutoIncrement="false" Key="false" CaseSensitive="false" MaxLength="256" MinLength="0" Required="false"  />
                <Property ID="ParentDescription" Type="string" AutoIncrement="false" Key="false" CaseSensitive="false" MaxLength="256" MinLength="0" Required="false"  />
                <Property ID="ParentArea" Type="string" AutoIncrement="false" Key="false" CaseSensitive="false" MaxLength="256" MinLength="0" Required="false"  />
                <Property ID="ParentImpact" Type="string" AutoIncrement="false" Key="false" CaseSensitive="false" MaxLength="256" MinLength="0" Required="false"  />
                <Property ID="ParentPriority" Type="string" AutoIncrement="false" Key="false" CaseSensitive="false" MaxLength="256" MinLength="0" Required="false"  />
                <Property ID="ParentRisk" Type="string" AutoIncrement="false" Key="false" CaseSensitive="false" MaxLength="256" MinLength="0" Required="false"  />
                <Property ID="ParentScheduledStart" Type="string" AutoIncrement="false" Key="false" CaseSensitive="false" MaxLength="256" MinLength="0" Required="false"  />
                <Property ID="ParentScheduledEnd" Type="string" AutoIncrement="false" Key="false" CaseSensitive="false" MaxLength="256" MinLength="0" Required="false"  />
              </ClassType>
            </ClassTypes>
      

      You can modify this to support the fields you need for your use cases. I created as many as I could so wouldn’t have to keep changing it.

      Now create a Windows workflow activity library application in Visual Studio. Reference the following assemblies

      • System.Drawing – if you don’t know where that is you need another job.
      • Microsoft.EnterpriseManagement.Core – this can be found in the “SDK Binaries” directory on the SCSM server
      • Microsoft.ServiceManager.WorkflowAuthoring.ActivityLibrary – this can be found in the SCSM authoring “PackagesToLoad” directory
      • System.ServiceManager.Facade – you can get this on CodePlex by downloading the current source code and compiling

      Below is the code that I used in my workflow activity, I was under a very tight deadline so no comments from the peanut gallery. I will clean it up later.

       protected override ActivityExecutionStatus Execute(ActivityExecutionContext executionContext)
              {
                  SCSMServer.SetCurrentManagementGroup("localhost");
                  var changeRequestProjection = SCSMChangeRequest.GetChangeRequest(WorkItemId);
                  
                  foreach (var activityProjection in changeRequestProjection)
                  {
                      var activity = activityProjection.Value.Object;
                      if (activity[null, "Id"] == null) break;
      
                      activity[null, "ParentId"].Value = (changeRequestProjection.Object[null, "Id"].Value != null)
                                                               ? changeRequestProjection.Object[null, "Id"].Value.ToString
                                                                     ()
                                                               : null;
      
                      activity[null, "ParentTitle"].Value = (changeRequestProjection.Object[null, "Title"].Value != null)
                                                                 ? changeRequestProjection.Object[null, "Title"].Value.ToString
                                                                       ()
                                                                 : null;
      
                      activity[null, "ParentDescription"].Value =
                          (changeRequestProjection.Object[null, "Description"].Value != null)
                              ? changeRequestProjection.Object[null, "Description"].Value.ToString()
                              : null;
      
                      activity[null, "ParentArea"].Value = (changeRequestProjection.Object[null, "Area"].Value != null) ? ((ManagementPackEnumeration)changeRequestProjection.Object[null, "Area"].Value).DisplayName : null;
      
                      activity[null, "ParentImpact"].Value = (changeRequestProjection.Object[null, "Impact"].Value != null) ? ((ManagementPackEnumeration)changeRequestProjection.Object[null, "Impact"].Value).DisplayName : null;
      
                      activity[null, "ParentPriority"].Value = (changeRequestProjection.Object[null, "Priority"].Value != null) ? ((ManagementPackEnumeration)changeRequestProjection.Object[null, "Priority"].Value).DisplayName : null;
      
                      activity[null, "ParentRisk"].Value = (changeRequestProjection.Object[null, "Risk"].Value != null) ? ((ManagementPackEnumeration)changeRequestProjection.Object[null, "Risk"].Value).DisplayName : null;
      
                      if ((changeRequestProjection.Object[null, "ScheduledStartDate"].Value != null))
                      {
                          var value = changeRequestProjection.Object[null, "ScheduledStartDate"].Value.ToString();
                          var date = DateTime.Parse(value);
                          activity[null, "ParentScheduledStart"].Value = date.ToString("g");
                      }
      
                      if ((changeRequestProjection.Object[null, "ScheduledEndDate"].Value != null))
                      {
                          var value = changeRequestProjection.Object[null, "ScheduledEndDate"].Value.ToString();
                          var date = DateTime.Parse(value);
                          activity[null, "ParentScheduledEnd"].Value = date.ToString("g");
                      }
                      changeRequestProjection.Overwrite();               
                     
                  }
      
                return ActivityExecutionStatus.Closed;
      
              }
      

      Please note “if (activity[null, "Id"] == null) break;” for some reason at least on my box the foreach loop does not stop on the last activity and so without this statement it throws null reference exceptions.

      To get all that in a workflow see this link. On a side note I would use the management pack that you used to extend the activity types.

      In the System Center Service Manager (SCSM) authoring tool you will need to create two workflows using your custom activity. One workflow is for when incident is created and the other for when a change request is created assuming you want to do this on both objects.

      So import your management pack and create a change request or incident save it and when you go back to the activities, open one of them and you should see the following at least this is what I see

      You can then use these fields in manual and review activity notifications. I am working on a solution to the problem of adding activities once a change request or incident has been created. Since the parent ID is stored in a sibling activity I should be able to figure it out. Same Bat Time Same Bat Channel.

      As Travis said “Sweet Hotness”.