Browsing articles in "Tech"

Using the Sim4BPM Client Libraries

Oct 6, 2010   //   by John   //   Sim4BPM, Tech  //  No Comments

We’ve started work on client libraries to help developers create applications that use the Sim4BPM schema. Currently, there is a .NET library. The library consists of an object model for the Sim4BPM schema. This allows developers to programmatically create business process scenario objects, or components of a business process scenario (for example, a set of activity parameters). It also allows developers to serialize their objects to xml that conforms to the Sim4BPM schema, as well as create objects from xml.

same day payday loans

Here’s a quick and dirty sample: we’ll create a (very simple!) business process scenario in .NET and serialize it to an xml file. We’ll then read the resulting xml file into a new business process scenario object and read one of the properties of the scenario – it’s name:

   1: using System;
   2: using System.Collections.Generic;
   3: using System.Text;
   4: using System.IO;
   5: using System.Xml.Serialization;
   6: using Sim4bpm.ScenarioDefinition.ObjectModel;
   7:
   8: namespace Sim4bpm.Test {
   9:     class Program {
  10:         static void Main(string[] args) {
  11:
  12:             // programmatically create a new scenario
  13:             Scenario testScenario = new Scenario();
  14:             testScenario.Name = "Test Sim4BPM Scenario";
  15:             testScenario.Author = "John Januszczak";
  16:
  17:             // serialize the scenario to an xml file
  18:             XmlSerializer serializer = new XmlSerializer(typeof(Scenario));
  19:             TextWriter writer = new StreamWriter("testscenario.xml");
  20:             serializer.Serialize(writer, testScenario);
  21:             writer.Close();
  22:
  23:             Console.WriteLine("Scenario serialized.");
  24:             Console.WriteLine("Press enter to continue.");
  25:             Console.ReadLine();
  26:
  27:             // deserialize a scenario object from the xml file
  28:             TextReader reader = new StreamReader("testscenario.xml");
  29:             Scenario myScenario = (Scenario)serializer.Deserialize(reader);
  30:             reader.Close();
  31:
  32:             Console.WriteLine(myScenario.Name);
  33:             Console.WriteLine("Press enter to quit.");
  34:             Console.ReadLine();
  35:         }
  36:     }
  37: }

Here’s the xml that was generated by the above code:

   1: <?xml version="1.0" encoding="utf-8"?>
   2: <Scenario xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
   3:   <Name>Test Sim4BPM Scenario</Name>
   4:   <Author>John Januszczak</Author>
   5:   <Created>2010-10-06T13:17:51.3125-04:00</Created>
   6:   <Modified>2010-10-06T13:17:51.3125-04:00</Modified>
   7:   <Editor />
   8:   <Context IsCalendarBased="true">
   9:     <Start />
  10:     <End />
  11:     <ClockUnits>Minute</ClockUnits>
  12:     <SchedulingMethod>Concurrent</SchedulingMethod>
  13:     <ResourceSelection>Performance</ResourceSelection>
  14:   </Context>
  15:   <Simulation>
  16:     <Seed Type="System" Value="0" />
  17:     <Animation>Off</Animation>
  18:     <Initialization />
  19:     <Termination />
  20:   </Simulation>
  21:   <Events />
  22:   <Resourcing>
  23:     <Roles />
  24:     <Resources />
  25:   </Resourcing>
  26:   <Activities />
  27: </Scenario>