public void Work(object state) { IGraphable data = (IGraphable)state; MessageQueueTransaction tx = null; IFormatterGraphResult gResult = null; try { // Create a message and prepare for sending Message msg = new Message(); Result = new MsmqSendResult(); // Format and prepare result gResult = Formatter.Graph(msg.BodyStream, data); Result.Code = gResult.Code; Result.Details = gResult.Details; // Accepted messages get sent if (Result.Code == ResultCode.Accepted || Result.Code == ResultCode.AcceptedNonConformant) { // Create a transaction if the queue is transactional if (Queue.Transactional) { tx = new MessageQueueTransaction(); tx.Begin(); } // Publish if (tx != null) { Queue.Send(msg, tx); } else { Queue.Send(msg); } // Commit the transaction if (tx != null) { tx.Commit(); } } } catch (MessageValidationException e) { Result.Code = ResultCode.Rejected; List <IResultDetail> dtl = new List <IResultDetail>(new IResultDetail[] { new ResultDetail(ResultDetailType.Error, e.Message, e) }); dtl.AddRange(gResult.Details ?? new IResultDetail[0]); Result.Details = dtl.ToArray(); if (tx != null && tx.Status == MessageQueueTransactionStatus.Pending) { tx.Abort(); } } catch (FormatException e) { Result.Code = ResultCode.Rejected; Result.Details = new IResultDetail[] { new ResultDetail(ResultDetailType.Error, e.Message, e) }; if (tx != null && tx.Status == MessageQueueTransactionStatus.Pending) { tx.Abort(); } } catch (Exception e) { Result.Code = ResultCode.Error; Result.Details = new IResultDetail[] { new ResultDetail(ResultDetailType.Error, e.Message, e) }; if (tx != null && tx.Status == MessageQueueTransactionStatus.Pending) { tx.Abort(); } } finally { } // Fire completed event if (Completed != null) { Completed(this); } }
public void EV_1110_DefaultUniprocessorCustomTypeTest() { // Load a sample because I don't want to write a full construction method ClinicalDocument clinicalDocument = null; using (Stream inStream = typeof(EV_1110).Assembly.GetManifestResourceStream("MARC.Everest.Test.Resources.phrDocTesting_140219112155-0500.xml")) { XmlIts1Formatter fmtr = new XmlIts1Formatter(); fmtr.ValidateConformance = false; fmtr.GraphAides.Add(new ClinicalDocumentDatatypeFormatter()); var result = fmtr.Parse(XmlReader.Create(inStream), typeof(ClinicalDocument)); clinicalDocument = result.Structure as ClinicalDocument; } var observation = new ObservationMyProfile() { MoodCode = x_ActMoodDocumentObservation.Eventoccurrence, Code = "3202-20", EntryRelationship = new List <EntryRelationship>() { new EntryRelationship(x_ActRelationshipEntryRelationship.HasComponent, true) { ClinicalStatement = new ObservationMyProfile() } } } ; CascadeNullFlavor(observation.EntryRelationship[0], NullFlavor.Unknown); // Cascade a null flavor on one of the entries clinicalDocument.Component.GetBodyChoiceIfStructuredBody().Component[1].Section.Entry.Add(new Entry( x_ActRelationshipEntry.HasComponent, false, observation )); // Cascade a null flavor on one of the entries clinicalDocument.Component.GetBodyChoiceIfStructuredBody().Component[2].Section.Entry.Add(new Entry( x_ActRelationshipEntry.HasComponent, false, observation )); // Cascade a null flavor on one of the entries clinicalDocument.Component.GetBodyChoiceIfStructuredBody().Component[3].Section.Entry.Add(new Entry( x_ActRelationshipEntry.HasComponent, false, observation )); StringWriter sw = new StringWriter(); using (XmlWriter xw = XmlWriter.Create(sw, new XmlWriterSettings() { Indent = true })) { XmlIts1Formatter fmtr = new XmlIts1Formatter(); fmtr.ValidateConformance = false; fmtr.GraphAides.Add(new ClinicalDocumentDatatypeFormatter()); fmtr.Settings = SettingsType.DefaultUniprocessor; fmtr.Settings |= SettingsType.SuppressXsiNil; fmtr.Settings |= SettingsType.SuppressNullEnforcement; fmtr.Settings |= SettingsType.AlwaysCheckForOverrides; fmtr.RegisterXSITypeName("POCD_MT000040.Observation", typeof(MARC.Everest.Test.Regressions.EV_1102.ObservationWithConfidentialityCode)); using (XmlStateWriter xsw = new XmlStateWriter(xw)) { xsw.WriteStartElement("hl7", "ClinicalDocument", "urn:hl7-org:v3"); xsw.WriteAttributeString("xmlns", "xsi", null, XmlIts1Formatter.NS_XSI); xsw.WriteAttributeString("schemaLocation", XmlIts1Formatter.NS_XSI, @"urn:hl7-org:v3 Schemas/CDA-PITO-E2E.xsd"); xsw.WriteAttributeString("xmlns", null, null, @"urn:hl7-org:v3"); xsw.WriteAttributeString("xmlns", "hl7", null, @"urn:hl7-org:v3"); xsw.WriteAttributeString("xmlns", "e2e", null, @"http://standards.pito.bc.ca/E2E-DTC/cda"); xsw.WriteAttributeString("xmlns", "xs", null, @"http://www.w3.org/2001/XMLSchema"); IFormatterGraphResult result = fmtr.Graph(xsw, clinicalDocument); foreach (ResultDetail itm in result.Details) { Trace.WriteLine(String.Format("{0}:{1} @ {2}", itm.Type, itm.Message, itm.Location)); } xsw.WriteEndElement(); // clinical document xsw.Flush(); } } Trace.WriteLine(sw.ToString()); Regex re = new Regex(@"\<entryRelationship.*/\>"); if (re.IsMatch(sw.ToString())) { Assert.Fail("Output of entry relationship is not as expected"); } }
public void Work(object state) { // Prepare stream Stream s = null; FileSendResult result = new FileSendResult(); IGraphable data = (IGraphable)state; IFormatterGraphResult fResult = null; try { // Graph the object. //We graph to a memory stream and transfer to a file stream on success because //the state of the stream is unknown if the result code is not accepted. This //could cause a process which is listening to new files to read an invalid or //non-conformant message from the publish service. In this model, we graph, //verify and finally commit. MemoryStream ms = new MemoryStream(); fResult = Formatter.Graph(ms, data); result.Code = fResult.Code; result.Details = fResult.Details; // Did the operation succeed? if (result.Code == ResultCode.Accepted || result.Code == ResultCode.AcceptedNonConformant) { //TODO: Should transfer in chunks instead of all at once. s = System.IO.File.Create(TargetFile); ms.WriteTo(s); ms.Close(); } } catch (MessageValidationException e) { result.Code = ResultCode.Rejected; List <IResultDetail> dtl = new List <IResultDetail>(new IResultDetail[] { new FileResultDetail(ResultDetailType.Error, e.Message, TargetFile, e) }); dtl.AddRange(fResult.Details ?? new IResultDetail[0]); result.Details = dtl.ToArray(); } catch (FormatException e) { result.Code = ResultCode.Rejected; result.Details = new IResultDetail[] { new FileResultDetail(ResultDetailType.Error, e.Message, TargetFile, e) }; } catch (DirectoryNotFoundException e) { result.Code = ResultCode.NotAvailable; result.Details = new IResultDetail[] { new FileResultDetail(ResultDetailType.Error, e.Message, TargetFile, e) }; } catch (IOException e) { result.Code = ResultCode.Error; result.Details = new IResultDetail[] { new FileResultDetail(ResultDetailType.Error, e.Message, TargetFile, e) }; } catch (Exception e) { result.Code = ResultCode.Error; result.Details = new IResultDetail[] { new FileResultDetail(ResultDetailType.Error, e.Message, TargetFile, e) }; } finally { if (s != null) { s.Close(); } if (result.Code != ResultCode.Accepted) { System.IO.File.Delete(TargetFile); } } this.Result = result; // Fire completed event if (Completed != null) { Completed(this); } }