Exemple #1
0
        internal static List <JsonComparer> AlignByIDs <T>(this ConverterRowBase <T> row,
                                                           List <T> byfRecs, List <T> rntRecs)
            where T : class, IDocumentDTO
        {
            if (byfRecs == null)
            {
                return(null);
            }
            var bag   = new ConcurrentBag <JsonComparer>();
            var jobs  = new List <Action>();
            var maxId = GetMaxId(byfRecs, rntRecs);
            var minId = GetMinId(byfRecs, rntRecs, maxId);

            foreach (var byf in byfRecs)
            {
                jobs.Add(() =>
                {
                    var rnt = rntRecs.SingleOrDefault(_ => _.Id == byf.Id);
                    bag.Add(new JsonComparer(byf.Id, byf, rnt));
                });
            }
            jobs.Add(()
                     => row.Unexpecteds = CountUnexpecteds(byfRecs, rntRecs));

            Parallel.Invoke(jobs.ToArray());
            var diffs = bag.ToList();

            diffs.RemoveAll(_ => _.BothNull);
            return(diffs.OrderBy(_ => _.CommonKey).ToList());
        }
Exemple #2
0
        private static async Task <IEnumerable <JsonComparer> > QueryThenCompare <T>(this ConverterRowBase <T> row) where T : class, IDocumentDTO
        {
            var byfRecs = await row.GetByfRecords();

            var rntRecs = row.SafeGetRntRecords();

            return(row.AlignRecords(byfRecs, rntRecs));
        }
Exemple #3
0
        private static void ShowFirstDiff <T>(this ConverterRowBase <T> row) where T : class, IDocumentDTO
        {
            var diff1 = row.DiffRows.FirstOrDefault(_ => _.IsTheSame == false);

            if (diff1 == null)
            {
                row.OnAllRecordsMatch();
                return;
            }
            row.LogError(diff1.Difference);
        }
Exemple #4
0
 private static List <JsonComparer> AlignRecords <T>(this ConverterRowBase <T> row, List <T> byfRecs, List <T> rntRecs) where T : class, IDocumentDTO
 {
     try
     {
         return(row.AlignByIDs(byfRecs, rntRecs));
     }
     catch (Exception ex)
     {
         row.LogError(ex.Info(true, true));
         return(null);
     }
 }
Exemple #5
0
 private static List <T> SafeGetRntRecords <T>(this ConverterRowBase <T> row) where T : class, IDocumentDTO
 {
     try
     {
         return(row.GetRntRecords(row.Main.AppArgs));
     }
     catch (Exception ex)
     {
         row.LogError(ex.Info(true, true));
         return(null);
     }
 }
 public static bool CanUpdateRnt <T>(this ConverterRowBase <T> row) where T : class, IDocumentDTO
 {
     if (row.Unexpecteds != 0)
     {
         return(false);
     }
     if (row.DiffsCount == 0)
     {
         return(false);
     }
     return(true);
 }
Exemple #7
0
        public static async Task GetDifferences <T>(this ConverterRowBase <T> row) where T : class, IDocumentDTO
        {
            row.StartBeingBusy("Getting row differences ...");
            row.ErrorText = null;
            await Task.Delay(1);

            var diffs = await row.QueryThenCompare();

            UIThread.Run(() => row.DiffRows.SetItems(diffs));
            row.UpdateCounts();
            row.ShowFirstDiff();
            row.StopBeingBusy();
        }
Exemple #8
0
        private static async Task <List <dynamic> > QueryByfServer <T>(this ConverterRowBase <T> row) where T : class, IDocumentDTO
        {
            try
            {
                await row.BeforeByfQuery();

                return(await row.GetViewsList(row.ViewsDisplayID));
            }
            catch (Exception ex)
            {
                row.LogError(ex.Info(true, true));
                return(null);
            }
        }
Exemple #9
0
 private static bool TryCastToRNT <T>(ConverterRowBase <T> row, dynamic dynamic, out T casted) where T : class, IDocumentDTO
 {
     try
     {
         casted = row.CastToRNT(dynamic);
         return(true);
     }
     catch (Exception ex)
     {
         var obj = dynamic as object;
         row.LogError(obj.ToJson(true));
         row.LogError(ex.Info(true, true));
         casted = default(T);
         return(false);
     }
 }
Exemple #10
0
        public static async Task <List <T> > GetByfRecords <T>(this ConverterRowBase <T> row) where T : class, IDocumentDTO
        {
            var casteds  = new List <T>();
            var dynamics = await row.QueryByfServer();

            if (dynamics == null)
            {
                return(null);
            }

            foreach (var dyn in dynamics)
            {
                if (TryCastToRNT(row, dyn, out T casted))
                {
                    casteds.Add(casted);
                }
                else
                {
                    return(null);
                }
            }
            return(casteds);
        }
        public static async Task UpdateRnt <T>(this ConverterRowBase <T> row) where T : class, IDocumentDTO
        {
            row.StartBeingBusy($"Importing all {row.Label} ...");
            await Task.Delay(1);

            await Task.Run(() =>
            {
                try
                {
                    var recs = row.DiffRows.Select(_ => _.Document1 as T);
                    row.ReplaceAll(recs, row.Main.AppArgs.MarketState);
                }
                catch (Exception ex)
                {
                    row.LogError(ex.Info(true, true));
                }
            });

            await Task.Delay(500);

            row.StopBeingBusy();
            row.RefreshCmd.ExecuteIfItCan();
        }