public void CreateReqElemOutputTest02() { XmlWriter xw = null; Stream s = null; try { /* STREAMWRITER CODE * s = File.Create("C:/Test Files/example85Data2.xml"); * StreamWriter sw1 = new StreamWriter(s); * * /* END STREAMWRITER CODE */ // Setup the formatter var its1Formatter = new XmlIts1Formatter() { ValidateConformance = true, CreateRequiredElements = true }; its1Formatter.GraphAides.Add(new DatatypeFormatter() { ValidateConformance = false } ); // Initialize the XmlWriter & State writer StringWriter sw = new StringWriter(); xw = XmlWriter.Create(sw, new XmlWriterSettings() { Indent = true }); // State writer should always be used XmlStateWriter xsw = new XmlStateWriter(xw); // Create an instance REPC_IN000076CA instance = new REPC_IN000076CA( Guid.NewGuid(), DateTime.Now, ResponseMode.Immediate, REPC_IN000076CA.GetInteractionId(), REPC_IN000076CA.GetProfileId(), ProcessingID.Production, AcknowledgementCondition.Always, new MARC.Everest.RMIM.CA.R020402.MCCI_MT002200CA.Receiver(), new MARC.Everest.RMIM.CA.R020402.MCCI_MT002200CA.Sender() ); instance.controlActEvent = new MARC.Everest.RMIM.CA.R020402.MCAI_MT700210CA.ControlActEvent <MARC.Everest.RMIM.CA.R020402.REPC_MT220001CA.Document>(); // Format var result = its1Formatter.Graph(xsw, instance); /* STREAMWRITER CODE * var result2 = its1Formatter.Graph(s, instance); * // Close streamwriter * sw1.Close(); * /* END STREAMWRITER CODE */ // Flush the xml state writer xsw.Flush(); if (result.Code != ResultCode.Accepted) { Console.WriteLine("RESULT CODE: {0}", result.Code); foreach (var detail in result.Details) { Console.WriteLine("{0}: {1}", detail.Type, detail.Message); } } // Assert: Instance is not conformant. Assert.AreEqual(ResultCode.Rejected, result.Code); /* STREAMWRITER CODE * // Validate that the written file contains the two injected strings. * StreamReader sr = new StreamReader("C:/Test Files/example85Data2.xml"); * * String xmlFromFile = ""; * // write everything in the stream to the console * while (!sr.EndOfStream) * { * // store lines into a string * xmlFromFile += sr.ReadLine(); * } * * // Write xml from the file onto the console * Console.WriteLine(xmlFromFile); * /* END STREAMWRITER CODE */ } finally { if (xw != null) { xw.Close(); } } }// end test method
public void CreateReqElemOutputTest02() { XmlWriter xw = null; Stream s = null; try { /* STREAMWRITER CODE s = File.Create("C:/Test Files/example85Data2.xml"); StreamWriter sw1 = new StreamWriter(s); /* END STREAMWRITER CODE */ // Setup the formatter var its1Formatter = new XmlIts1Formatter() { ValidateConformance = true, CreateRequiredElements = true }; its1Formatter.GraphAides.Add(new DatatypeFormatter() { ValidateConformance = false } ); // Initialize the XmlWriter & State writer StringWriter sw = new StringWriter(); xw = XmlWriter.Create(sw, new XmlWriterSettings() { Indent = true }); // State writer should always be used XmlStateWriter xsw = new XmlStateWriter(xw); // Create an instance REPC_IN000076CA instance = new REPC_IN000076CA( Guid.NewGuid(), DateTime.Now, ResponseMode.Immediate, REPC_IN000076CA.GetInteractionId(), REPC_IN000076CA.GetProfileId(), ProcessingID.Production, AcknowledgementCondition.Always, new MARC.Everest.RMIM.CA.R020402.MCCI_MT002200CA.Receiver(), new MARC.Everest.RMIM.CA.R020402.MCCI_MT002200CA.Sender() ); instance.controlActEvent = new MARC.Everest.RMIM.CA.R020402.MCAI_MT700210CA.ControlActEvent <MARC.Everest.RMIM.CA.R020402.REPC_MT220001CA.Document>(); // Format var result = its1Formatter.Graph(xsw, instance); /* STREAMWRITER CODE var result2 = its1Formatter.Graph(s, instance); // Close streamwriter sw1.Close(); /* END STREAMWRITER CODE */ // Flush the xml state writer xsw.Flush(); if (result.Code != ResultCode.Accepted) { Console.WriteLine("RESULT CODE: {0}", result.Code); foreach (var detail in result.Details) { Console.WriteLine("{0}: {1}", detail.Type, detail.Message); } } // Assert: Instance is not conformant. Assert.AreEqual(ResultCode.Rejected, result.Code); /* STREAMWRITER CODE // Validate that the written file contains the two injected strings. StreamReader sr = new StreamReader("C:/Test Files/example85Data2.xml"); String xmlFromFile = ""; // write everything in the stream to the console while (!sr.EndOfStream) { // store lines into a string xmlFromFile += sr.ReadLine(); } // Write xml from the file onto the console Console.WriteLine(xmlFromFile); /* END STREAMWRITER CODE */ } finally { if (xw != null) xw.Close(); } }// end test method
/// <summary> /// Create an empty instance to send to the remote service /// </summary> /// <returns>An emtpy instance</returns> /// <remarks>IGraphable is similar to ISerializable. It identifies that a class can be represented /// using a formatter.</remarks> static IGraphable CreateInstance() { // We can use the shortcut constructors to make creating instances easier. If you are confused about what // any of these parameters are, please consult the Hello World tutorial as it explains each parameter in // more detail REPC_IN000076CA instance = new REPC_IN000076CA( new II(Guid.NewGuid()), // The message ID uniquely identifies the message. //It is an II.TOKEN so only a ROOT is required DateTime.Now, // The creation time of the message identifies when the message was // created. Since this is an exact TS, we can use DateTime.Now with no precision ResponseMode.Immediate, // The response mode tells the receiver how to process the // message. In our case, we want the message processed Immediately REPC_IN000076CA.GetInteractionId(), // We need to explicitly set the ID of the interaction // that is to be processed, this is done for consistency // (esp when batching is performed) REPC_IN000076CA.GetProfileId(), // We also need to tell the receiver // which profile we are conforming to. ProcessingID.Training, // Identifies how the message should be processed on the receiver. // Training means the message shouldn't actually update data on the receiver AcknowledgementCondition.Always, // Identifies when the message should be acknowledged. // We always want an acknowledgement in this case new MARC.Everest.RMIM.CA.R020401.MCCI_MT002300CA.Receiver(), // The sender/receiver are used // by the receiver to validate // that the sender is permitted // to communicate with the host new MARC.Everest.RMIM.CA.R020401.MCCI_MT002300CA.Sender() // and that the message is being // processed by the intended // recipient (just like email) ); // Set the receiver and sender structures in detail instance.Receiver.Device = new MARC.Everest.RMIM.CA.R020401.MCCI_MT002300CA.Device2( new II("1.2.3.4", "RecipientDeviceExtension") ); instance.Sender.Device = new MARC.Everest.RMIM.CA.R020401.MCCI_MT002300CA.Device1( new II("1.2.3.4", "SenderExtension") ); instance.Sender.Device.Name = "WcfClient Sample Application"; // Additional data can be set about the sender // Create the payload, again we'll use the shortcut method instance.controlActEvent = REPC_IN000076CA.CreateControlActEvent( new II("1.2.3.4.5", Guid.NewGuid().ToString()), // The control act identifier uniquely // identifies the event (or transaction) // that occured. This is different from // the message identifier that identifies // the message REPC_IN000076CA.GetTriggerEvent(), // The trigger event or controlActEvent.Code property is // used to identify the type of event that occured. In // many cases, the trigger event for an interaction is // fixed, and can be accessed using the .TRIGGER_EVENT // constant new MARC.Everest.RMIM.CA.R020401.MCAI_MT700211CA.RecordTarget(), // The record target identifies // the target of the event. In this case, it is the patient // that we are recording the discharge for new MARC.Everest.RMIM.CA.R020401.MCAI_MT700212CA.Author(), // The author identifies the person // that is responsible for the act new MARC.Everest.RMIM.CA.R020401.MCAI_MT700210CA.Subject2 <MARC.Everest.RMIM.CA.R020401.REPC_MT220001CA.Document>() // The subject is the actual data that is being created, // updated or retrieved from the remote system ); // Create the record target instance.controlActEvent.RecordTarget.SetPatient1(new SET <II>(new II("1.1.1.1.1", "1234"), II.Comparator), new MARC.Everest.RMIM.CA.R020401.COCT_MT050207CA.Person( new PN( EntityNameUse.Legal, new ENXP[] { new ENXP("John", EntityNamePartType.Given), new ENXP("Smith", EntityNamePartType.Family) } ), AdministrativeGender.Male, DateTime.Parse("1984-07-07") ) ); // Create the author instance.controlActEvent.Author.Time = DateTime.Now; instance.controlActEvent.Author.SetAuthorPerson( new MARC.Everest.RMIM.CA.R020401.COCT_MT090102CA.AssignedEntity(new SET <II>(new II("1.1.1.1.1", "1234"), II.Comparator) )); // This sample doesn't illustrate the creation of a complete discharge, however in order // to pass preliminary validation we'll need to set some null flavors on things we don't // want populated. RMIM classes can't infer nullflavors from the data types class, so they // use an auto-generated nullflavor from the MARC.Everest.RMIM.CA.R020401.Vocabulary.NullFlavor // enumeration instance.controlActEvent.Subject.NullFlavor = NullFlavor.NoInformation; return(instance); }
/// <summary> /// Create an empty instance to send to the remote service /// </summary> /// <returns>An emtpy instance</returns> /// <remarks>IGraphable is similar to ISerializable. It identifies that a class can be represented /// using a formatter.</remarks> static IGraphable CreateInstance() { // We can use the shortcut constructors to make creating instances easier. If you are confused about what // any of these parameters are, please consult the Hello World tutorial as it explains each parameter in // more detail REPC_IN000076CA instance = new REPC_IN000076CA( new II(Guid.NewGuid()), // The message ID uniquely identifies the message. //It is an II.TOKEN so only a ROOT is required DateTime.Now, // The creation time of the message identifies when the message was // created. Since this is an exact TS, we can use DateTime.Now with no precision ResponseMode.Immediate, // The response mode tells the receiver how to process the // message. In our case, we want the message processed Immediately REPC_IN000076CA.GetInteractionId(), // We need to explicitly set the ID of the interaction // that is to be processed, this is done for consistency // (esp when batching is performed) REPC_IN000076CA.GetProfileId(), // We also need to tell the receiver // which profile we are conforming to. ProcessingID.Training, // Identifies how the message should be processed on the receiver. // Training means the message shouldn't actually update data on the receiver AcknowledgementCondition.Always, // Identifies when the message should be acknowledged. // We always want an acknowledgement in this case new MARC.Everest.RMIM.CA.R020401.MCCI_MT002300CA.Receiver(), // The sender/receiver are used // by the receiver to validate // that the sender is permitted // to communicate with the host new MARC.Everest.RMIM.CA.R020401.MCCI_MT002300CA.Sender() // and that the message is being // processed by the intended // recipient (just like email) ); // Set the receiver and sender structures in detail instance.Receiver.Device = new MARC.Everest.RMIM.CA.R020401.MCCI_MT002300CA.Device2( new II("1.2.3.4", "RecipientDeviceExtension") ); instance.Sender.Device = new MARC.Everest.RMIM.CA.R020401.MCCI_MT002300CA.Device1( new II("1.2.3.4", "SenderExtension") ); instance.Sender.Device.Name = "WcfClient Sample Application"; // Additional data can be set about the sender // Create the payload, again we'll use the shortcut method instance.controlActEvent = REPC_IN000076CA.CreateControlActEvent( new II("1.2.3.4.5", Guid.NewGuid().ToString()), // The control act identifier uniquely // identifies the event (or transaction) // that occured. This is different from // the message identifier that identifies // the message REPC_IN000076CA.GetTriggerEvent(), // The trigger event or controlActEvent.Code property is // used to identify the type of event that occured. In // many cases, the trigger event for an interaction is // fixed, and can be accessed using the .TRIGGER_EVENT // constant new MARC.Everest.RMIM.CA.R020401.MCAI_MT700211CA.RecordTarget(), // The record target identifies // the target of the event. In this case, it is the patient // that we are recording the discharge for new MARC.Everest.RMIM.CA.R020401.MCAI_MT700212CA.Author(), // The author identifies the person // that is responsible for the act new MARC.Everest.RMIM.CA.R020401.MCAI_MT700210CA.Subject2<MARC.Everest.RMIM.CA.R020401.REPC_MT220001CA.Document>() // The subject is the actual data that is being created, // updated or retrieved from the remote system ); // Create the record target instance.controlActEvent.RecordTarget.SetPatient1(new SET<II>(new II("1.1.1.1.1", "1234"), II.Comparator), new MARC.Everest.RMIM.CA.R020401.COCT_MT050207CA.Person( new PN( EntityNameUse.Legal, new ENXP[] { new ENXP("John", EntityNamePartType.Given), new ENXP("Smith", EntityNamePartType.Family) } ), AdministrativeGender.Male, DateTime.Parse("1984-07-07") ) ); // Create the author instance.controlActEvent.Author.Time = DateTime.Now; instance.controlActEvent.Author.SetAuthorPerson( new MARC.Everest.RMIM.CA.R020401.COCT_MT090102CA.AssignedEntity(new SET<II>(new II("1.1.1.1.1", "1234"), II.Comparator) )); // This sample doesn't illustrate the creation of a complete discharge, however in order // to pass preliminary validation we'll need to set some null flavors on things we don't // want populated. RMIM classes can't infer nullflavors from the data types class, so they // use an auto-generated nullflavor from the MARC.Everest.RMIM.CA.R020401.Vocabulary.NullFlavor // enumeration instance.controlActEvent.Subject.NullFlavor = NullFlavor.NoInformation; return instance; }