Ejemplo n.º 1
0
            public static string Create(InvoiceFull invoice)
            {
                var registeredDate = invoice.TaskAssignments.Min(ta => ta.Task.Task.CreatedTimestamp.FromMediusDate());
                //TODO: key should be the registered date?
                var fmt = new FilenameFormat
                {
                    InvoiceDate    = invoice.Invoice.InvoiceDate.FromMediusDate() ?? DateTime.MinValue,
                    Supplier       = invoice.Invoice.Supplier.Name,
                    Id             = invoice.Invoice.Id,
                    RegisteredDate = registeredDate ?? DateTime.MinValue,
                    State          = invoice.FirstTask?.Task?.State
                };

                return(fmt.ToString());
            }
Ejemplo n.º 2
0
        private async Task <Dictionary <InvoiceFull, List <string> > > DownloadImages(IEnumerable <InvoiceFull> invoices)
        {
            var api    = CreateApi();
            var result = new Dictionary <InvoiceFull, List <string> >();

            foreach (var invoice in invoices)
            {
                var filenameFormat = InvoiceFull.GetFilenamePrefix(invoice.Invoice.InvoiceDate.FromMediusDate().Value,
                                                                   invoice.Invoice.Supplier.Name, invoice.Invoice.Id) + "_{0}";
                var images = await api.GetTaskImages(api.GetTaskImagesInfo(invoice.FirstTask?.Task), true, filenameFormat);

                result.Add(invoice, images.Keys.Select(k => k.ToString()).ToList());
            }
            return(result);
        }
Ejemplo n.º 3
0
        public async Task MyTestMethod()
        {
            var underlyingStore = new InMemoryKVStore();
            var store           = new InvoiceStore(underlyingStore);

            var invoice = new InvoiceFull
            {
                Invoice = new MediusFlowAPI.Models.SupplierInvoiceGadgetData.Invoice {
                    InvoiceDate = DateTime.Today.ToMediusDate(),
                    Supplier    = new MediusFlowAPI.Models.SupplierInvoiceGadgetData.Supplier {
                        Name = "Supplier"
                    },
                    Id = 1
                },
                TaskAssignments = new List <InvoiceFull.TaskAssignmentAndTasks> {
                    new InvoiceFull.TaskAssignmentAndTasks {
                        Task = new InvoiceFull.TaskFull {
                            Task = new MediusFlowAPI.Models.Task.Response {
                                CreatedTimestamp = DateTime.Today.ToMediusDate(), State = 1
                            }
                        }
                    }
                }
            };

            await store.Post(invoice);

            var filenameFormat = InvoiceFull.FilenameFormat.Parse(InvoiceFull.FilenameFormat.Create(invoice));
            var retrieved      = await underlyingStore.Get(filenameFormat.ToString());

            if (retrieved is string serialized)
            {
                Newtonsoft.Json.JsonConvert.DeserializeObject(serialized);
            }
            else
            {
                throw new FormatException("Not a string");
            }

            //var xx = await store.Get(filenameFormat);
        }
Ejemplo n.º 4
0
        public async IAsyncEnumerable <T> LoadAndTransformInvoices <T>(Func <InvoiceFull, T> selector, Func <InvoiceFull.FilenameFormat, bool> quickFilter = null)
        {
            var files = await store.GetKeysParsed();

            foreach (var file in files)
            {
                if (quickFilter != null && quickFilter(file) == false)
                {
                    continue;
                }
                InvoiceFull invoice = null;
                try
                {
                    invoice = await store.Get(file);                     // JsonConvert.DeserializeObject<InvoiceFull>((await store.Get(file)).ToString());
                }
                catch (Exception ex)
                {
                    throw new Exception($"Deserialization of {file} failed", ex);
                }
                yield return(selector(invoice));
            }
        }
Ejemplo n.º 5
0
 public async Task Post(InvoiceFull item) => await store.Post(InvoiceFull.FilenameFormat.Create(item), item);