Ejemplo n.º 1
0
        private async Task SaveEntryData(IEnumerable <EntryData> flst)
        {
            var exceptions = new ConcurrentQueue <Exception>();

            flst.AsParallel(new ParallelLinqOptions()
            {
                MaxDegreeOfParallelism = Environment.ProcessorCount
            }).ForAll(itm =>
            {
                try
                {
                    using (var ctx = new EntryDataDSContext())
                    {
                        ctx.ApplyChanges(itm);
                        ctx.SaveChanges();
                    }
                }
                catch (Exception ex)
                {
                    exceptions.Enqueue(ex);
                }
            });
            if (exceptions.Count > 0)
            {
                throw new AggregateException(exceptions);
            }
        }
Ejemplo n.º 2
0
        private IEnumerable <EntryData> FixExistingEntryData(List <EntryData> elst)
        {
            var exceptions = new ConcurrentQueue <Exception>();

            Parallel.ForEach(elst, itm =>
            {
                try
                {
                    using (var ctx = new EntryDataDSContext())
                    {
                        var pi = ctx.EntryData.Find(itm.EntryDataId);
                        if (pi != null)
                        {
                            ctx.EntryData.Remove(pi);
                            ctx.SaveChanges();
                            ctx.Database.ExecuteSqlCommand(
                                string.Format("Delete from EntryData_PurchaseOrders where EntryDataId = '{0}'",
                                              itm.EntryDataId));
                        }
                    }
                }
                catch (Exception ex)
                {
                    exceptions.Enqueue(ex);
                }
            });
            if (exceptions.Count > 0)
            {
                throw new AggregateException(exceptions);
            }
            return(elst);//.Where(x => x != null)
        }
Ejemplo n.º 3
0
        public async Task ProcessDroppedFile(string fileName, string fileType, AsycudaDocumentSet docSet, bool overWriteExisting)
        {
            //get the text
            var wStr = Core.Common.PDF2TXT.Pdf2Txt.Instance.ExtractTextFromPdf(fileName);

            var elst = await GetEntryData(wStr).ConfigureAwait(false);

            await ImportInventory(elst).ConfigureAwait(false);

            var flst       = FixExistingEntryData(elst);
            var exceptions = new ConcurrentQueue <Exception>();

            flst.AsParallel(new ParallelLinqOptions()
            {
                MaxDegreeOfParallelism = Environment.ProcessorCount
            }).ForAll(itm =>
            {
                try
                {
                    using (var ctx = new EntryDataDSContext())
                    {
                        ctx.ApplyChanges(itm);
                        ctx.SaveChanges();
                    }
                }
                catch (Exception ex)
                {
                    exceptions.Enqueue(ex);
                }
            });
            if (exceptions.Count > 0)
            {
                throw new AggregateException(exceptions);
            }
        }