public override void Given() { Event = new EpcisEvent { Type = EventType.Quantity, BusinessLocation = "test:location", BusinessStep = "test:step", CaptureTime = new System.DateTime(2020, 05, 15, 12, 32, 32), EventTime = new System.DateTime(2020, 05, 15, 13, 00, 00), EventTimeZoneOffset = new TimeZoneOffset { Value = 60 } }; Event.Epcs.Add(new Epc { Type = EpcType.Quantity, Id = "test:epc", Quantity = 5 }); Event.SourceDestinationList.Add(new SourceDestination { Id = "test:source", Type = "source:type", Direction = SourceDestinationType.Source }); }
private XElement Format(EpcisEvent @event) { switch (@event.EventType) { case EventType.ObjectEvent: return(FormatObjectEvent(@event)); case EventType.QuantityEvent: return(FormatQuantityEvent(@event)); case EventType.AggregationEvent: return(FormatAggregationEvent(@event)); case EventType.TransactionEvent: return(FormatTransactionEvent(@event)); case EventType.TransformationEvent: return(FormatTransformationEvent(@event)); } throw new Exception($"Unknown event type: {@event.EventType}"); }
private void AddSourceDestinationList(EpcisEvent evt, Dictionary <string, object> dictionary) { var sources = evt.SourceDestinationList.Where(x => x.Direction == SourceDestinationType.Source).Select(s => new Dictionary <string, object> { { "type", s.Type }, { "source", s.Id } }); var dests = evt.SourceDestinationList.Where(x => x.Direction == SourceDestinationType.Destination).Select(s => new Dictionary <string, object> { { "type", s.Type }, { "destination", s.Id } }); if (sources.Any()) { dictionary.Add("sourceList", sources); } if (dests.Any()) { dictionary.Add("destinationList", dests); } }
internal static CustomField ParseCustomField(XElement element, EpcisEvent epcisEvent, FieldType type) { var field = new CustomField { Type = type, Name = element.Name.LocalName, Namespace = element.Name.NamespaceName, TextValue = element.HasElements ? null : element.Value, NumericValue = element.HasElements ? null : double.TryParse(element.Value, out double doubleValue) ? doubleValue : default(double?), DateValue = element.HasElements ? null : DateTime.TryParse(element.Value, out DateTime dateValue) ? dateValue : default(DateTime?), }; if (element.HasElements) { foreach (var children in element.Elements()) { var childrenField = ParseCustomField(children, epcisEvent, type); field.Children.Add(childrenField); } } foreach (var attribute in element.Attributes().Where(a => a.Name.LocalName != "xmlns")) { var attributeField = new CustomField { Type = FieldType.Attribute, Name = attribute.Name.LocalName, Namespace = attribute.Name.Namespace.NamespaceName, TextValue = attribute.Value, NumericValue = element.HasElements ? null : double.TryParse(element.Value, out double doubleVal) ? doubleVal : default(double?), DateValue = element.HasElements ? null : DateTime.TryParse(element.Value, out DateTime dateVal) ? dateVal : default(DateTime?), }; field.Children.Add(attributeField); } return(field); }
public override void Given() { Event = new EpcisEvent { Type = EventType.Transformation, BusinessLocation = "test:location", BusinessStep = "test:step", CaptureTime = new System.DateTime(2020, 05, 15, 12, 32, 32), EventTime = new System.DateTime(2020, 05, 15, 13, 00, 00), EventTimeZoneOffset = new TimeZoneOffset { Value = 60 }, SourceDestinationList = new List <SourceDestination> { new SourceDestination { Direction = SourceDestinationType.Source, Id = "source_id", Type = "source" } }, Epcs = new List <Epc> { new Epc { Type = EpcType.OutputQuantity, Id = "epc:1", IsQuantity = true, Quantity = 25, UnitOfMeasure = "KGM" } }, CustomFields = new List <CustomField> { new CustomField { Type = FieldType.CustomField, Name = "test", Namespace = "ns_test", Children = new List <CustomField> { new CustomField { Type = FieldType.CustomField, Name = "inner", Namespace = "ns_test", TextValue = "value" } } } } }; Event.SourceDestinationList.Add(new SourceDestination { Id = "test:source", Type = "source:type", Direction = SourceDestinationType.Source }); }
public override void Given() { Event = new EpcisEvent { Type = EventType.Transaction, Action = EventAction.Observe, BusinessLocation = "test:trans_location", BusinessStep = "test:step", BusinessTransactions = new List <BusinessTransaction> { new BusinessTransaction { Id = "test_trans", Type = "trans_type" } }, CaptureTime = new System.DateTime(2020, 05, 15, 12, 32, 32), EventTime = new System.DateTime(2020, 07, 15, 13, 00, 00), EventTimeZoneOffset = new TimeZoneOffset { Value = -60 } }; Event.SourceDestinationList.Add(new SourceDestination { Id = "test:source", Type = "source:type", Direction = SourceDestinationType.Source }); }
private void AddEpcList(EpcisEvent evt) { var inputEpcList = new XElement("inputEPCList", evt.Epcs.Where(x => x.Type == EpcType.InputEpc).Select(e => new XElement("epc", e.Id))); var inputQuantity = new XElement("inputQuantityList", evt.Epcs.Where(x => x.Type == EpcType.InputQuantity).Select(XmlEventFormatter.FormatQuantity)); var outputQuantity = new XElement("outputQuantityList", evt.Epcs.Where(x => x.Type == EpcType.OutputQuantity).Select(XmlEventFormatter.FormatQuantity)); var outputEpcList = new XElement("outputEPCList", evt.Epcs.Where(x => x.Type == EpcType.OutputEpc).Select(e => new XElement("epc", e.Id))); if (inputEpcList.HasElements) { _root.Add(inputEpcList); } if (inputQuantity.HasElements) { _root.Add(inputQuantity); } if (outputEpcList.HasElements) { _root.Add(outputEpcList); } if (outputQuantity.HasElements) { _root.Add(outputQuantity); } }
private void AddInputOutputEpcList(EpcisEvent evt) { var inputEpcList = new XElement("inputEPCList", XmlEventFormatter.FormatEpcList(evt, EpcType.InputEpc)); var inputQuantity = new XElement("inputQuantityList", XmlEventFormatter.FormatEpcQuantity(evt, EpcType.InputQuantity)); var outputQuantity = new XElement("outputQuantityList", XmlEventFormatter.FormatEpcQuantity(evt, EpcType.OutputQuantity)); var outputEpcList = new XElement("outputEPCList", XmlEventFormatter.FormatEpcList(evt, EpcType.OutputEpc)); if (inputEpcList.HasElements) { Root.Add(inputEpcList); } if (inputQuantity.HasElements) { Root.Add(inputQuantity); } if (outputEpcList.HasElements) { Root.Add(outputEpcList); } if (outputQuantity.HasElements) { Root.Add(outputQuantity); } }
public void AddEventExtension(EpcisEvent evt) { _extension.AddIfAny(XmlEventFormatter.GenerateCustomFields(evt, FieldType.EventExtension)); }
public bool CanFormat(EpcisEvent epcisEvent) { return(epcisEvent.EventType == EventType.Aggregation); }
private void AddAction(EpcisEvent objectEvent) { _root.Add(new XElement("action", objectEvent.Action.DisplayName)); }
public void AddEventExtension(EpcisEvent evt) { var extension = new XElement("extension", XmlEventFormatter.GenerateCustomFields(evt, FieldType.EventExtension)); _extension.AddIfNotNull(extension); }
protected override void AddEventExtension(EpcisEvent evt) { Extension.AddIfAny(XmlEventFormatter.GenerateCustomFields(evt, FieldType.EventExtension)); }
public bool CanFormat(EpcisEvent epcisEvent) { return(epcisEvent.EventType == EventType.Transaction); }
protected virtual void AddIlmdFields(EpcisEvent evt, XElement element) { var ilmdElement = new XElement("ilmd", XmlEventFormatter.GenerateCustomFields(evt, FieldType.Ilmd)); element.AddIfNotNull(ilmdElement); }
private void AddIlmdFields(EpcisEvent evt) { _extension.AddIfAny(XmlEventFormatter.GenerateCustomFields(evt, FieldType.Ilmd)); }
private void AddBusinessLocation(EpcisEvent evt) { _root.AddIfNotNull(XmlEventFormatter.GenerateBusinessLocation(evt)); }
public void AddDisposition(EpcisEvent evt) { _root.AddIfNotNull(XmlEventFormatter.GenerateDisposition(evt)); }
private static EpcisEvent ParseAttributes(XElement root, EpcisEvent epcisEvent) { foreach (var node in root.Elements()) { switch (node.Name.LocalName) { case "eventTime": epcisEvent.EventTime = DateTime.Parse(node.Value, CultureInfo.InvariantCulture); break; case "eventTimeZoneOffset": epcisEvent.EventTimeZoneOffset = new TimeZoneOffset { Representation = node.Value }; break; case "action": epcisEvent.Action = Enumeration.GetByDisplayName <EventAction>(node.Value); break; case "epcList": node.ParseEpcListInto(epcisEvent); break; case "childEPCs": node.ParseChildEpcListInto(epcisEvent); break; case "inputQuantityList": node.ParseQuantityListInto(epcisEvent, true); break; case "inputEPCList": node.ParseEpcListInto(epcisEvent, true); break; case "outputQuantityList": node.ParseQuantityListInto(epcisEvent, false); break; case "outputEPCList": node.ParseEpcListInto(epcisEvent, false); break; case "epcClass": epcisEvent.Epcs.Add(new Epc { Type = EpcType.Quantity, Id = node.Value, IsQuantity = true }); break; case "quantity": epcisEvent.Epcs.Single(x => x.Type == EpcType.Quantity).Quantity = float.Parse(node.Value, CultureInfo.InvariantCulture); break; case "bizStep": epcisEvent.BusinessStep = node.Value; break; case "disposition": epcisEvent.Disposition = node.Value; break; case "eventID": epcisEvent.EventId = node.Value; break; case "errorDeclaration": epcisEvent.ErrorDeclaration = node.ToErrorDeclaration(epcisEvent); break; case "transformationId": epcisEvent.TransformationId = node.Value; break; case "bizLocation": node.ParseBusinessLocation(epcisEvent); break; case "bizTransactionList": epcisEvent.BusinessTransactions = node.ToBusinessTransactions(); break; case "readPoint": node.ParseReadPoint(epcisEvent); break; case "sourceList": node.ParseSourceInto(epcisEvent.SourceDestinationList); break; case "destinationList": node.ParseDestinationInto(epcisEvent.SourceDestinationList); break; case "ilmd": ParseIlmd(node, epcisEvent); break; case "parentID": epcisEvent.Epcs.Add(new Epc { Id = node.Value, Type = EpcType.ParentId }); break; case "recordTime": // We don't process record time as it will be overrided in any case.. break; case "extension": ParseExtensionElement(node, epcisEvent); break; default: epcisEvent.CustomFields.Add(ParseCustomField(node, epcisEvent, FieldType.EventExtension)); break; } } return(epcisEvent); }
public bool CanFormat(EpcisEvent epcisEvent) { return(epcisEvent.EventType == EventType.Object); }
private void AddCustomFields(EpcisEvent evt) { _root.AddIfAny(XmlEventFormatter.GenerateCustomFields(evt, FieldType.CustomField)); }
protected virtual void AddBusinessTransactions(EpcisEvent evt) { Root.AddIfNotNull(XmlEventFormatter.GenerateBusinessTransactions(evt)); }
private static XElement CreateDestinationList(EpcisEvent evt) { return(new XElement("destinationList", evt.SourceDestinationList .Where(x => x.Direction == SourceDestinationType.Destination) .Select(x => new XElement("destination", new XAttribute("type", x.Type), x.Id)))); }
protected virtual void AddSourceDestinations(EpcisEvent evt, XElement element) { element.AddIfAny(XmlEventFormatter.GenerateSourceDest(evt)); }
private void AddReadPoint(EpcisEvent evt) { _root.AddIfNotNull(XmlEventFormatter.GenerateReadPoint(evt)); }
private static XElement FormatEvent(EpcisEvent evt) { return(Formatters.TryGetValue(evt.Type, out Func <EpcisEvent, XElement> formatter) ? formatter(evt) : throw new Exception($"Unknown event type to format {evt?.Type?.DisplayName}")); }
private void AddBusinessTransactions(EpcisEvent evt) { _root.AddIfNotNull(XmlEventFormatter.GenerateBusinessTransactions(evt)); }
private static IEnumerable <XElement> CreateCustomFields(EpcisEvent evt, FieldType type) { return(evt.CustomFields.Where(x => x.Type == type).Select(FormatField)); }
private void AddSourceDestinations(EpcisEvent evt) { _root.AddIfAny(XmlEventFormatter.GenerateSourceDest(evt)); }
public XElement Format(EpcisEvent epcisEvent) { throw new System.NotImplementedException(); }