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
            });
        }
Exemplo n.º 2
0
        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}");
        }
Exemplo n.º 3
0
        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);
            }
        }
Exemplo n.º 4
0
        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);
        }
Exemplo n.º 5
0
        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
            });
        }
Exemplo n.º 7
0
        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);
            }
        }
Exemplo n.º 8
0
        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);
            }
        }
Exemplo n.º 9
0
 public void AddEventExtension(EpcisEvent evt)
 {
     _extension.AddIfAny(XmlEventFormatter.GenerateCustomFields(evt, FieldType.EventExtension));
 }
Exemplo n.º 10
0
 public bool CanFormat(EpcisEvent epcisEvent)
 {
     return(epcisEvent.EventType == EventType.Aggregation);
 }
Exemplo n.º 11
0
 private void AddAction(EpcisEvent objectEvent)
 {
     _root.Add(new XElement("action", objectEvent.Action.DisplayName));
 }
Exemplo n.º 12
0
        public void AddEventExtension(EpcisEvent evt)
        {
            var extension = new XElement("extension", XmlEventFormatter.GenerateCustomFields(evt, FieldType.EventExtension));

            _extension.AddIfNotNull(extension);
        }
Exemplo n.º 13
0
 protected override void AddEventExtension(EpcisEvent evt)
 {
     Extension.AddIfAny(XmlEventFormatter.GenerateCustomFields(evt, FieldType.EventExtension));
 }
Exemplo n.º 14
0
 public bool CanFormat(EpcisEvent epcisEvent)
 {
     return(epcisEvent.EventType == EventType.Transaction);
 }
Exemplo n.º 15
0
        protected virtual void AddIlmdFields(EpcisEvent evt, XElement element)
        {
            var ilmdElement = new XElement("ilmd", XmlEventFormatter.GenerateCustomFields(evt, FieldType.Ilmd));

            element.AddIfNotNull(ilmdElement);
        }
Exemplo n.º 16
0
 private void AddIlmdFields(EpcisEvent evt)
 {
     _extension.AddIfAny(XmlEventFormatter.GenerateCustomFields(evt, FieldType.Ilmd));
 }
Exemplo n.º 17
0
 private void AddBusinessLocation(EpcisEvent evt)
 {
     _root.AddIfNotNull(XmlEventFormatter.GenerateBusinessLocation(evt));
 }
Exemplo n.º 18
0
 public void AddDisposition(EpcisEvent evt)
 {
     _root.AddIfNotNull(XmlEventFormatter.GenerateDisposition(evt));
 }
Exemplo n.º 19
0
        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);
        }
Exemplo n.º 20
0
 public bool CanFormat(EpcisEvent epcisEvent)
 {
     return(epcisEvent.EventType == EventType.Object);
 }
Exemplo n.º 21
0
 private void AddCustomFields(EpcisEvent evt)
 {
     _root.AddIfAny(XmlEventFormatter.GenerateCustomFields(evt, FieldType.CustomField));
 }
Exemplo n.º 22
0
 protected virtual void AddBusinessTransactions(EpcisEvent evt)
 {
     Root.AddIfNotNull(XmlEventFormatter.GenerateBusinessTransactions(evt));
 }
Exemplo n.º 23
0
 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))));
 }
Exemplo n.º 24
0
 protected virtual void AddSourceDestinations(EpcisEvent evt, XElement element)
 {
     element.AddIfAny(XmlEventFormatter.GenerateSourceDest(evt));
 }
Exemplo n.º 25
0
 private void AddReadPoint(EpcisEvent evt)
 {
     _root.AddIfNotNull(XmlEventFormatter.GenerateReadPoint(evt));
 }
Exemplo n.º 26
0
 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}"));
 }
Exemplo n.º 27
0
 private void AddBusinessTransactions(EpcisEvent evt)
 {
     _root.AddIfNotNull(XmlEventFormatter.GenerateBusinessTransactions(evt));
 }
Exemplo n.º 28
0
 private static IEnumerable <XElement> CreateCustomFields(EpcisEvent evt, FieldType type)
 {
     return(evt.CustomFields.Where(x => x.Type == type).Select(FormatField));
 }
Exemplo n.º 29
0
 private void AddSourceDestinations(EpcisEvent evt)
 {
     _root.AddIfAny(XmlEventFormatter.GenerateSourceDest(evt));
 }
Exemplo n.º 30
0
 public XElement Format(EpcisEvent epcisEvent)
 {
     throw new System.NotImplementedException();
 }