private static void Translate2_0(CaseObject caseObj, ref Stream caseXML, String caseDirectory) { XmlSerializer serializer = new XmlSerializer(typeof(L3.Cargo.Common.Xml.XCase_2_0.XCase)); L3.Cargo.Common.Xml.XCase_2_0.XCase xcase = new L3.Cargo.Common.Xml.XCase_2_0.XCase(); if (caseObj != null) { xcase.version = "2.0"; if (caseObj.EventRecords != null && caseObj.attachments.CountofType(AttachmentType.EVENT_HISTORY) <= 0) { DataAttachment dataAttachmentEventHistory = null; List <L3.Cargo.Common.Xml.XCase_2_0.EventRecord> recordList = new List <L3.Cargo.Common.Xml.XCase_2_0.EventRecord>(); foreach (CaseObject.CaseEventRecord eventrecord in caseObj.EventRecords) { L3.Cargo.Common.Xml.XCase_2_0.EventRecord rc = new L3.Cargo.Common.Xml.XCase_2_0.EventRecord(); rc.createTime = eventrecord.createTime; rc.description = eventrecord.description; recordList.Add(rc); } dataAttachmentEventHistory = new DataAttachment(); dataAttachmentEventHistory.attachmentId = "events.xml"; dataAttachmentEventHistory.attachmentType = AttachmentType.EVENT_HISTORY; caseObj.attachments.Add(dataAttachmentEventHistory); XmlSerializer eventSerializer = new XmlSerializer(typeof(L3.Cargo.Common.Xml.XCase_2_0.EventHistory)); L3.Cargo.Common.Xml.XCase_2_0.EventHistory eventHistory = new L3.Cargo.Common.Xml.XCase_2_0.EventHistory(); eventHistory.EventRecord = recordList.ToArray(); FileStream fs = new FileStream(caseDirectory + "\\events.xml", FileMode.OpenOrCreate, FileAccess.ReadWrite); eventSerializer.Serialize(fs, eventHistory); fs.Close(); } xcase.abortedby = caseObj.AbortedBy; if (caseObj.attachments != null) { List <L3.Cargo.Common.Xml.XCase_2_0.Attachment> attachList = new List <L3.Cargo.Common.Xml.XCase_2_0.Attachment>(); foreach (DataAttachment attach in caseObj.attachments) { L3.Cargo.Common.Xml.XCase_2_0.Attachment at = new L3.Cargo.Common.Xml.XCase_2_0.Attachment(); at.createTime = attach.CreateTime; at.filename = attach.attachmentId; at.type = attach.attachmentType.ToString(); at.user = attach.User; attachList.Add(at); } xcase.attachments = attachList.ToArray(); } xcase.createTime = caseObj.createTime; xcase.currentArea = caseObj.CurrentArea; xcase.id = caseObj.CaseId; xcase.linkedCase = caseObj.LinkedCaseId; if (caseObj.ResultsList != null) { List <L3.Cargo.Common.Xml.XCase_2_0.Result> resultList = new List <L3.Cargo.Common.Xml.XCase_2_0.Result>(); try { foreach (result res in caseObj.ResultsList) { L3.Cargo.Common.Xml.XCase_2_0.Result rest = new L3.Cargo.Common.Xml.XCase_2_0.Result(); rest.analysisTime = res.AnalysisTime; rest.comment = res.Comment; rest.createTime = res.CreateTime; if (res.Decision == WorkstationDecision.Caution.ToString()) { rest.decision = (int)WorkstationDecision.Caution; } else if (res.Decision == WorkstationDecision.Clear.ToString()) { rest.decision = (int)WorkstationDecision.Clear; } else if (res.Decision == WorkstationDecision.Reject.ToString()) { rest.decision = (int)WorkstationDecision.Reject; } else { rest.decision = (int)WorkstationDecision.Unknown; } rest.reason = res.Reason; rest.stationType = res.StationType; rest.user = res.User; resultList.Add(rest); } } catch (Exception exp) { throw; } xcase.results = resultList.ToArray(); } if (caseObj.scanInfo != null) { xcase.scanInfo = new L3.Cargo.Common.Xml.XCase_2_0.ScanInfo(); if (caseObj.scanInfo.container != null) { xcase.scanInfo.container = new L3.Cargo.Common.Xml.XCase_2_0.Container(); xcase.scanInfo.container.code = caseObj.scanInfo.container.Code; xcase.scanInfo.container.id = caseObj.scanInfo.container.Id; xcase.scanInfo.container.sequenceNum = caseObj.scanInfo.container.SequenceNum; xcase.scanInfo.container.weight = caseObj.scanInfo.container.Weight; } if (caseObj.scanInfo.conveyance != null) { xcase.scanInfo.conveyance = new L3.Cargo.Common.Xml.XCase_2_0.Conveyance(); xcase.scanInfo.conveyance.batchNum = caseObj.scanInfo.conveyance.BatchNum; xcase.scanInfo.conveyance.id = caseObj.scanInfo.conveyance.Id; xcase.scanInfo.conveyance.totalWeight = caseObj.scanInfo.conveyance.TotalWeight; } if (caseObj.scanInfo.location != null) { xcase.scanInfo.location = new L3.Cargo.Common.Xml.XCase_2_0.Location(); xcase.scanInfo.location.latitude = caseObj.scanInfo.location.Latitude; xcase.scanInfo.location.longitude = caseObj.scanInfo.location.Longitude; } if (caseObj.scanInfo.ScanType != null) { xcase.scanInfo.type = caseObj.scanInfo.ScanType; } } if (caseObj.systemInfo != null) { xcase.systemInfo = new L3.Cargo.Common.Xml.XCase_2_0.SystemInfo(); xcase.systemInfo.baseLocation = caseObj.systemInfo.BaseLocation; xcase.systemInfo.systemType = caseObj.systemInfo.SystemType; } MemoryStream ms = new MemoryStream(); serializer.Serialize(ms, xcase); ms.Seek(0, SeekOrigin.Begin); caseXML.Flush(); ms.CopyTo(caseXML); caseXML.Seek(0, SeekOrigin.Begin); } }
private static void Translate2_0(CaseObject caseObj, ref Stream caseXML, String caseDirectory) { XmlSerializer serializer = new XmlSerializer(typeof(L3.Cargo.Common.Xml.XCase_2_0.XCase)); L3.Cargo.Common.Xml.XCase_2_0.XCase xcase = new L3.Cargo.Common.Xml.XCase_2_0.XCase(); if (caseObj != null) { xcase.version = "2.0"; if (caseObj.EventRecords != null && caseObj.attachments.CountofType(AttachmentType.EVENT_HISTORY) <= 0) { DataAttachment dataAttachmentEventHistory = null; List<L3.Cargo.Common.Xml.XCase_2_0.EventRecord> recordList = new List<L3.Cargo.Common.Xml.XCase_2_0.EventRecord>(); foreach (CaseObject.CaseEventRecord eventrecord in caseObj.EventRecords) { L3.Cargo.Common.Xml.XCase_2_0.EventRecord rc = new L3.Cargo.Common.Xml.XCase_2_0.EventRecord(); rc.createTime = eventrecord.createTime; rc.description = eventrecord.description; recordList.Add(rc); } dataAttachmentEventHistory = new DataAttachment(); dataAttachmentEventHistory.attachmentId = "events.xml"; dataAttachmentEventHistory.attachmentType = AttachmentType.EVENT_HISTORY; caseObj.attachments.Add(dataAttachmentEventHistory); XmlSerializer eventSerializer = new XmlSerializer(typeof(L3.Cargo.Common.Xml.XCase_2_0.EventHistory)); L3.Cargo.Common.Xml.XCase_2_0.EventHistory eventHistory = new L3.Cargo.Common.Xml.XCase_2_0.EventHistory(); eventHistory.EventRecord = recordList.ToArray(); FileStream fs = new FileStream(caseDirectory + "\\events.xml", FileMode.OpenOrCreate, FileAccess.ReadWrite); eventSerializer.Serialize(fs, eventHistory); fs.Close(); } xcase.abortedby = caseObj.AbortedBy; if (caseObj.attachments != null) { List<L3.Cargo.Common.Xml.XCase_2_0.Attachment> attachList = new List<L3.Cargo.Common.Xml.XCase_2_0.Attachment>(); foreach (DataAttachment attach in caseObj.attachments) { L3.Cargo.Common.Xml.XCase_2_0.Attachment at = new L3.Cargo.Common.Xml.XCase_2_0.Attachment(); at.createTime = attach.CreateTime; at.filename = attach.attachmentId; at.type = attach.attachmentType.ToString(); at.user = attach.User; attachList.Add(at); } xcase.attachments = attachList.ToArray(); } xcase.createTime = caseObj.createTime; xcase.currentArea = caseObj.CurrentArea; xcase.id = caseObj.CaseId; xcase.linkedCase = caseObj.LinkedCaseId; if (caseObj.ResultsList != null) { List<L3.Cargo.Common.Xml.XCase_2_0.Result> resultList = new List<L3.Cargo.Common.Xml.XCase_2_0.Result>(); try { foreach (result res in caseObj.ResultsList) { L3.Cargo.Common.Xml.XCase_2_0.Result rest = new L3.Cargo.Common.Xml.XCase_2_0.Result(); rest.analysisTime = res.AnalysisTime; rest.comment = res.Comment; rest.createTime = res.CreateTime; if (res.Decision == WorkstationDecision.Caution.ToString()) rest.decision = (int)WorkstationDecision.Caution; else if (res.Decision == WorkstationDecision.Clear.ToString()) rest.decision = (int)WorkstationDecision.Clear; else if (res.Decision == WorkstationDecision.Reject.ToString()) rest.decision = (int)WorkstationDecision.Reject; else rest.decision = (int)WorkstationDecision.Unknown; rest.reason = res.Reason; rest.stationType = res.StationType; rest.user = res.User; resultList.Add(rest); } } catch (Exception exp) { throw; } xcase.results = resultList.ToArray(); } if (caseObj.scanInfo != null) { xcase.scanInfo = new L3.Cargo.Common.Xml.XCase_2_0.ScanInfo(); if (caseObj.scanInfo.container != null) { xcase.scanInfo.container = new L3.Cargo.Common.Xml.XCase_2_0.Container(); xcase.scanInfo.container.code = caseObj.scanInfo.container.Code; xcase.scanInfo.container.id = caseObj.scanInfo.container.Id; xcase.scanInfo.container.sequenceNum = caseObj.scanInfo.container.SequenceNum; xcase.scanInfo.container.weight = caseObj.scanInfo.container.Weight; } if (caseObj.scanInfo.conveyance != null) { xcase.scanInfo.conveyance = new L3.Cargo.Common.Xml.XCase_2_0.Conveyance(); xcase.scanInfo.conveyance.batchNum = caseObj.scanInfo.conveyance.BatchNum; xcase.scanInfo.conveyance.id = caseObj.scanInfo.conveyance.Id; xcase.scanInfo.conveyance.totalWeight = caseObj.scanInfo.conveyance.TotalWeight; } if (caseObj.scanInfo.location != null) { xcase.scanInfo.location = new L3.Cargo.Common.Xml.XCase_2_0.Location(); xcase.scanInfo.location.latitude = caseObj.scanInfo.location.Latitude; xcase.scanInfo.location.longitude = caseObj.scanInfo.location.Longitude; } if (caseObj.scanInfo.ScanType != null) xcase.scanInfo.type = caseObj.scanInfo.ScanType; } if (caseObj.systemInfo != null) { xcase.systemInfo = new L3.Cargo.Common.Xml.XCase_2_0.SystemInfo(); xcase.systemInfo.baseLocation = caseObj.systemInfo.BaseLocation; xcase.systemInfo.systemType = caseObj.systemInfo.SystemType; } MemoryStream ms = new MemoryStream(); serializer.Serialize(ms, xcase); ms.Seek(0, SeekOrigin.Begin); caseXML.Flush(); ms.CopyTo(caseXML); caseXML.Seek(0, SeekOrigin.Begin); } }