• Skip to primary navigation
  • Skip to main content
Carbon60

Carbon60

The Managed Cloud Difference

  • Show Search
  • Contact Us
  • Get Started
Hide Search
  • Cloud Adoption
    Cloud Adoption

    Starting or continuing on your cloud journey — whether public, private or hybrid — is a complex undertaking. But no matter your company size or industry, our cloud consulting experts can help with end-to-end solutions to plan, migrate and operate your business in the cloud.

    • Cloud Readiness Assessment

      Chart a new course for your IT environment with a Cloud Readiness Assessment. With a proven process, we take into consideration your technology, people and business strategy and tailor a public, private or hybrid cloud environment that will set your organization up for success.

      Learn more
    • Cloud Migration Services

      Cloud migration can transform your business and give you a competitive edge – when done properly. Our cloud experts will help you move complex workloads to the right cloud environment, the right way – tailored for your specific needs.

      Learn more
    • Cloud Launchpad
    • Modernization
    • Cloud Security & Compliance
  • Managed Cloud
    Managed Cloud

    Get the most out of the cloud and keep your IT team out of the weeds. Gain predictability and control around security, compliance, agility, reliability, performance – and cost – by tapping into our standard-setting managed cloud services.

    • Managed Private Cloud

      Safe, stable, fast, compliant, secure and fully managed – get a reliable and data sovereign cloud infrastructure platform for your applications.

      Learn more
    • Managed Public Cloud

      Experience matters. Whether you choose Managed AWS, Azure or Google Cloud, we can take care of the heavy lifting while you focus on your business.

      Learn more
    • Cloud Backup
    • Cloud Disaster Recovery
    • Security
    • Managed Public Cloud
    • Cloud Disaster Recovery
    • Applications
  • Industries
    Industries

    When it comes to financial services, healthcare, public sector and technology – there is simply no room for error or uncertainty when it comes to data security and compliance. There are specific and important considerations that we are well-versed in navigating. We’re trusted by governments and organizations to safely house mission-critical functions every day.

    • Financial Services

      Increase go-to-market speed, while meeting SOC2, PCI-DSS and OSFI B10 regulatory and organizational obligations.

      Learn more
    • Healthcare

      Get secure, scalable high-performance data, while improving the patient experience and addressing every compliance and privacy requirement.

      Learn more
    • Public Sector
    • Technology
  • Partners
    Partners

    Simply put – the right technology and the right platform is the one that’s right for your business. We’re highly certified and experienced in the major public clouds – so regardless of complexity, customization or preference – we’re well-equipped to have your back every step of the way.

    • AWS

      AWS Premier Partner with 100+ AWS certifications and counting.

      Learn more
    • Microsoft Azure

      Gold Microsoft Azure Partner with core competencies and certifications.

      Learn more
    • Google Cloud
    • VMware
  • Insights
    Insights

    Sharing knowledge and expertise is a big part of how we’ve evolved - and how we help our customers.

    • Blog

      Stay up to date with the latest trends and developments in the fast-moving world of digital transformation.

      Read
    • Events

      Make sure to join us for our next event and connect with cloud experts who have a lot to share.

      Attend
    • Resources

      Your toolkit to do a deeper dive with case studies, info sheets, checklists and more.

      Explore
  • About
    About

    We’re on a mission to bring digital transformation to more businesses, by making forward-thinking cloud strategy – and high-performance cloud services – more accessible.

    • Leadership

      Meet the leadership team who are driving our vision forward.

      Learn more
    • About Carbon60

      Learn more about who we are, and how we help our customers evolve with confidence.

      Learn more
    • Careers
    • News
  • Contact Us
  • Get Started

Executing System Center Orchestrator 2012 Runbooks from C#

August 15, 2012

The Problem:

System Center Orchestrator 2012 exposes a data service that enables to query and execute runbooks. But working directly with the data service is like executing a WCF service by manually composing the SOAP messages. There are no type-safe parameters, no intellisense and you need to type the exact path of the runbook or even worse, specify GUIDs . Developing and testing a code that is involved with Orchestrator runbooks execution quickly becomes a cumbersome and tedious task.

The Solution:

The solutions is a Visual Studio item template. When you add it to an existing project, it will ask for the Orchestrator servers details and generate hierarchy of proxy classes that match-up with the Orchestrator server folders hierarchy, and within every class there will be methods that will match-up with the runbooks on said folder that accept the runbooks parameters. In addition, the runbooks description will be appended to the methods remark summary, which makes the Visual Studio intellisense more helpful. Every class that contains runbooks also implements an interface named I{ClassName} that include these methods for easier testing. After adding this item to your project you will be able to execute a runbook as seen in the following code:

OrchestratorReference orchestratorReference = new OrchestratorReference();
Guid jobId = orchestratorReference.Development.Utils.WriteErrorLog(message, activity, runbook);

The OrchestratorReference object can be initialized with the credentials for accessing the Orchestrator web services.Ex:

OrchestratorReference orchestratorReference = new OrchestratorReference();
NetworkCredential cred = new NetworkCredential(userName, password, domain);
orchestratorReference.OrchestratorServiceCredentials = cred;

In case the runbook paths prefix depends on development environments you can use the AddReplaceFolderPrefix method to dynamically replace the path prefix. Ex:

OrchestratorReference orchestratorReference = new OrchestratorReference();
orchestratorReference.AddReplaceFolderPrefix(@"Development", @"Production");

All the runbooks functions return the job Id that was created on the Orchestrator server. The execution of the runbooks is asynchronized, to wait for the runbook completion and optionally collect the runbooks return values, you can use the created job Id with the following methods:

Guid jobId = orchestratorReference.Development.VMManager.VM.GetNextVMName("Test##");
Dictionary result = orchestratorReference.GetJobResult(jobId);
string nextVMName = result["nextVMName"];
public async Task GetNextVMName(string template)
{
   OrchestratorReference orchestratorReference = new OrchestratorReference();
   Guid jobId = orchestratorReference.Development.VMManager.VM.GetNextVMName(template);
   Dictionary result = await orchestratorReference.GetJobResultAsync(jobId);
   return result["nextVMName"];
}

The T4 template, responsible for generating the code, removes any classes/methods duplication and will name classes/methods with Pascal-case and methods parameters with camel-case. It also removes from the class/methods name any un-letter prefix characters, so if the folder name includes an index number prefix, this index will be truncate and will be visible only from the class/methods remarks summary.

Deployment:

  1. Extract the zip file available for download at the bottom of this post.
  2. Execute the “DeployItemTemplate.cmd” file.

Using:

  1. Open Visual Studio 2010
  2. Click on add -> new item, in a project from which you need to execute a runbook
  3. Choose the Orchestrator Reference template from the template list, type in a file name and click OK
  4. Type the Orchestrator servers name, port number where the Orchestrator service is listening (default 81) and if SSL is required
  5. Click on the Load button. The wizard will load the folders structure from the Orchestrator service and will enable to specify which folders to include in the new generated class
  6. Click the Add button.
  7. Optional – Expand the template file to check the generated cs file.
  8. Happy developing!

Source & Binary (107 KB)

IT Advice Async Framework, DataService, IWizard, Orchestrator, System Center, T4 template, Visual Studio Item Template

Related posts

Validating User Resources for Deploying a Service Template

October 1, 2012

Integrating SharePoint and System Center Orchestrator

January 22, 2013

PowerShell SSH Module for Nonstandard Devices Like Cisco ASA

October 28, 2014

Subscribe to receive Carbon60 news

Stay up to date on insights, blog articles, events and services from Carbon60 delivered to your inbox.

Subscribe
Carbon60
  • Cloud Adoption
    • Cloud Readiness Assessment
    • Cloud Migration Services
    • Cloud Launchpad
    • Modernization
    • Cloud Security & Compliance
  • Managed Cloud
    • Managed Private Cloud
    • Managed Public Cloud
    • Cloud Backup
    • Cloud Disaster Recovery
    • Security
    • Applications
  • Industries
    • Financial Services
    • Healthcare
    • Public Sector
    • Technology
Follow us on LinkedIn Follow us on Twitter Follow us on YouTube

© Copyright Carbon60 2023

  • Privacy Policy
  • Terms & Conditions
  • Contact Us