Esempio n. 1
0
        public RunAdministrations LoadAdministration(PipelineContext ctx)
        {
            JObject cmdObj = JObject.Parse("{ 'sort': [{'adm_date': 'desc'}]}");
            var     ret    = new RunAdministrations(ctx.ImportEngine.RunAdminSettings);

            try
            {
                if (!DocType.IndexExists)
                {
                    return(ret);                   //Nothing to load here...
                }
                String url = ((ctx.ImportFlags & _ImportFlags.FullImport) == 0) ? DocType.UrlPart : DocType.UrlPartForPreviousIndex;
                if (!Connection.Exists(url))
                {
                    ctx.ErrorLog.Log("Cannot load previous administration: '{0}' not exists", url);
                    return(ret);
                }

                var e = new ESRecordEnum(Connection, url, cmdObj, ret.Settings.Capacity, "5m", false);
                foreach (var doc in e)
                {
                    RunAdministration ra;
                    try
                    {
                        ra = new RunAdministration(doc._Source);
                    }
                    catch (Exception err)
                    {
                        String msg = String.Format("Invalid record in run administration. Skipped.\nRecord={0}.", doc);
                        ctx.ImportLog.Log(_LogType.ltWarning, msg);
                        ctx.ErrorLog.Log(_LogType.ltWarning, msg);
                        ctx.ErrorLog.Log(err);
                        continue;
                    }
                    ret.Add(ra);
                    if (ret.Count >= 500)
                    {
                        break;
                    }
                }
                return(ret.Dump("loaded"));
            }
            catch (Exception err)
            {
                if ((ctx.ImportFlags & _ImportFlags.FullImport) == 0)
                {
                    throw;
                }
                ctx.ErrorLog.Log("Cannot load previous administration:");
                ctx.ErrorLog.Log(err);
                return(ret);
            }
        }
        public void Merge(RunAdministrations other)
        {
            Dump("before dst");
            other.Dump("before src");
            if (other == null || other.list.Count == 0)
            {
                return;
            }

            if (list.Count == 0)
            {
                list.AddRange(other.list);
                return;
            }

            foreach (var a in other.list)
            {
                Add(a);
            }
            Dump("after merge");
        }