static void Main(string[] args) { StreamReader sr = null; string content = null; try { //load the order xml. sr = new StreamReader("..\\..\\OrderSample.xml"); content = sr.ReadToEnd(); } finally { sr.Close(); } GenericIdentity gi = new GenericIdentity("CustomerA"); GenericPrincipal gp = new GenericPrincipal(gi, null); //create a new document object Document doc = new Document(gp, content, null); SAF.Application.Configuration.ConfigurationManager cm = null; cm = (SAF.Application.Configuration.ConfigurationManager)ConfigurationSettings.GetConfig("MyApplication"); //get the initial document layer object IDocumentLayer layer = (IDocumentLayer)cm.DocumentLayerConfig.GetDocumentLayerByName("Special"); //start processing the document. IDocument response = layer.ProcessDocument(doc); Console.WriteLine(">>>>>>>>>>>>>Repsonse document from " + response.Sender.Identity.Name + " has arrived <<<<<<<<<<<<"); Console.WriteLine("Response Document is: \n " + response.Content + "\n"); }
/// <summary> /// Create an object for the next document layer and set it /// to the Next property /// </summary> /// <param name="configXml">configuration data contain the document layers participating the chain</param> public DocumentBlankLayer(XmlNode configXml) { XmlNode node = configXml.SelectSingleNode("Layer"); if (node != null) { Type type = Type.GetType(node.Attributes["type"].Value); object[] parameters = new Object[1] { node }; next = (IDocumentLayer)Activator.CreateInstance(type, parameters); } }
public DocumentDoSomeWorkLayer(XmlNode configXml) { XmlNode node = configXml.SelectSingleNode("Layer"); if (node != null) { //retrieve the type information of the document layer from the configuration xml Type type = Type.GetType(node.Attributes["type"].Value); object[] parameters = new Object[1] { node }; next = (IDocumentLayer)Activator.CreateInstance(type, parameters); } }
public DocumentLoggingLayer(XmlNode configXml) { XmlNode node = configXml.SelectSingleNode("Layer"); connString = configXml.SelectSingleNode("Config").Attributes["connection"].Value; if (node != null) { //retrieve the type information of the document layer. Type type = Type.GetType(node.Attributes["type"].Value); object[] parameters = new Object[1] { node }; next = (IDocumentLayer)Activator.CreateInstance(type, parameters); } }
public DocumentXmlValidationLayer(XmlNode configXml) { XmlNode node = configXml.SelectSingleNode("Layer"); //retrieve the schema information. incomingSchema = configXml.SelectSingleNode("Config").Attributes["incomingSchema"].Value; outgoingSchema = configXml.SelectSingleNode("Config").Attributes["outgoingSchema"].Value; if (node != null) { Type type = Type.GetType(node.Attributes["type"].Value); object[] parameters = new Object[1] { node }; next = (IDocumentLayer)Activator.CreateInstance(type, parameters); } }
static void Main(string[] args) { //read the customer order StreamReader sr = null; string content = null; try { sr = new StreamReader("..\\..\\OrderSample.xml"); content = sr.ReadToEnd(); } finally { sr.Close(); } GenericIdentity gi = new GenericIdentity("CustomerA"); GenericPrincipal gp = new GenericPrincipal(gi, null); //create the document object IDocument doc = new Document(gp, content, null); //load the configuration obect for the workflow SAF.Application.Configuration.ConfigurationManager cm = null; cm = (ConfigurationManager)ConfigurationSettings.GetConfig("MyApplication"); //get the inital documet layer IDocumentLayer layer = (IDocumentLayer)cm.DocumentLayerConfig.GetDocumentLayerByName("PurchaseOrderWorkFlow"); //start process the document by calling the ProcessDocument on the inital layer. //For this perticular example, the last document layer is DocumentWorkFlowLayer object //which will trigger the work flow defined in the GenericPurchaseOrderVisitor class IDocument response = layer.ProcessDocument(doc); //display potential response document if (response != null) { Console.WriteLine(">>>>>>>>>>>>>Repsonse document from " + response.Sender.Identity.Name + " has arrived <<<<<<<<<<<<"); Console.WriteLine("Response Document is: \n " + response.Content + "\n"); } //change the cost of some product to greater than $100 and run this demo again //to see how the workflow is changed. }
/// <summary> /// constructor that initialize the first processing unit and the visitor class /// which contain the process flow and coordination logic used to process the cusotmer orders. /// </summary> /// <param name="configXml"></param> public DocumentWorkFlowLayer(XmlNode configXml) { XmlNode node = configXml.SelectSingleNode("Layer"); string initialComponent = configXml.SelectSingleNode("Config/InitialComponent").Attributes["type"].Value; string visitor = configXml.SelectSingleNode("Config/Visitor").Attributes["type"].Value; //use reflect to create the processing unit and visitor object nextComponent = (IComponent)Activator.CreateInstance(Type.GetType(initialComponent), null); v = (IVisitor)Activator.CreateInstance(Type.GetType(visitor), null); //set the Next property to the next document layer if there is one. if (node != null) { Type type = Type.GetType(node.Attributes["type"].Value); object[] parameters = new Object[1] { node }; next = (IDocumentLayer)Activator.CreateInstance(type, parameters); } }
public DocumentWorkFlowLayer(IDocumentLayer nextLayer) { Next = nextLayer; }
/// <summary> /// set up the next document layer in the chain /// </summary> /// <param name="nextLayer">next document layer</param> public DocumentBlankLayer(IDocumentLayer nextLayer) { Next = nextLayer; }