Beispiel #1
0
        public void Write(EpcisQuery entity, Stream output)
        {
            XDocument document = Write((dynamic)entity);
            var       bytes    = Encoding.UTF8.GetBytes(document.ToString(SaveOptions.DisableFormatting | SaveOptions.OmitDuplicateNamespaces));

            output.Write(bytes, 0, bytes.Length);
        }
Beispiel #2
0
        public async Task Write(EpcisQuery entity, Stream output, CancellationToken cancellationToken)
        {
            XDocument document = Write((dynamic)entity);
            var       bytes    = Encoding.UTF8.GetBytes(document.ToString(SaveOptions.DisableFormatting | SaveOptions.OmitDuplicateNamespaces));

            await output.WriteAsync(bytes, 0, bytes.Length, cancellationToken);
        }
Beispiel #3
0
        public virtual IEnumerable <EpcisEvent> Perform(EpcisQuery query)
        {
            var sqlParams = new Dictionary <string, object>();
            var sqlQuery  = CreateSqlQuery(query, sqlParams);

            return(_eventsRetriever.Query(sqlQuery, sqlParams));
        }
Beispiel #4
0
        public async Task <IEpcisResponse> Dispatch(EpcisQuery query)
        {
            var handlerType = _handlers.SingleOrDefault(x => x.GetInterfaces().SingleOrDefault(i => i.IsGenericType && i.GetGenericTypeDefinition() == typeof(IQueryHandler <>))?.GetGenericArguments()[0] == query.GetType());
            var handler     = _serviceProvider.GetService(handlerType);

            return(await DispatchInternal(handler, query));
        }
Beispiel #5
0
        private static string CreateSqlQuery(EpcisQuery epcisQuery, IDictionary <string, object> sqlParams)
        {
            var sqlFilter = new List <string>();

            foreach (var key in epcisQuery.Parameters)
            {
                switch (key.Name)
                {
                case "EQ_Something":
                    sqlFilter.Add("Id IN @Id");
                    sqlParams.Add("@Id", key.Values);
                    break;

                default:
                    throw new QueryParameterException(string.Format("Query parameter {0} is unknown and can't be processed", key));
                }
            }

            return(sqlFilter.Any() ? string.Format("{0} WHERE {1}", SqlQuery, string.Join(" AND ", sqlFilter)) : SqlQuery);
        }
Beispiel #6
0
        public virtual XDocument Execute(string queryName, EpcisQuery parameters)
        {
            var performer = _queryPerformers.SingleOrDefault(x => x.Name == queryName);

            if (performer == null)
            {
                throw new NoSuchNameException(string.Format("There is no query matching the name '{0}'", queryName));
            }

            var events    = performer.Perform(parameters);
            var formatted = from evt in events let f = _formatters.Single(x => x.CanFormat(evt)) select f.Format(evt);

            return(new XDocument(
                       new XDeclaration("1.0", "UTF-8", "yes"),
                       new XElement("EPCISDocument",
                                    new XAttribute("creationDate", DateTime.UtcNow),
                                    new XAttribute("schemaVersion", "1.2"),
                                    new XElement("EPCISBody",
                                                 new XElement("EventList", formatted.ToArray <object>())
                                                 )
                                    )
                       ));
        }
        public virtual IEnumerable <EpcisEvent> Perform(EpcisQuery query)
        {
            var eventIds = _eventsRetriever.RetrieveIds(SqlQuery, new { Epc = query.Parameters.Single(x => x.Name == "epc").Values.Single() });

            return(_eventsRetriever.GetByIds(eventIds.ToArray()));
        }
Beispiel #8
0
 public IHttpActionResult Query([XmlSoapBody] EpcisQuery <XElement> body)
 {
     return(Ok(_eventQuery.Query(body)));
 }
Beispiel #9
0
        public virtual IEnumerable <EpcisEvent> Perform(EpcisQuery query)
        {
            var ids = query.Parameters.Where(x => x.Name == "id").SelectMany(x => x.Values).Select(long.Parse).ToArray();

            return(_eventsRetriever.GetByIds(ids));
        }
 public Task WriteQuery(EpcisQuery entity, Stream output, CancellationToken cancellationToken) => throw new NotImplementedException();
Beispiel #11
0
 public Task WriteQuery(EpcisQuery entity, Stream output, CancellationToken cancellationToken) => new XmlQueryFormatter().Write(entity, output, cancellationToken);