Example #1
0
        public ImportReport Import(String[] enabledDSses = null)
        {
            var ret = new ImportReport();

            RunAdministrations = RunAdminSettings.Load();
            StartTimeUtc       = DateTime.UtcNow;

            ImportLog.Log();
            ImportLog.Log(new String('_', 80));
            ImportLog.Log(_LogType.ltProgress, "Starting import. VirtMem={3:F1}GB, Flags={0}, MaxAdds={1}, ActiveDS's='{2}'.", ImportFlags, MaxAdds, enabledDSses == null ? null : String.Join(", ", enabledDSses), OS.GetTotalVirtualMemory() / (1024 * 1024 * 1024.0));

            PipelineContext mainCtx = new PipelineContext(this);

            try
            {
                _ErrorState stateFilter = _ErrorState.All;
                if ((ImportFlags & _ImportFlags.IgnoreLimited) != 0)
                {
                    stateFilter &= ~_ErrorState.Limited;
                }
                if ((ImportFlags & _ImportFlags.IgnoreErrors) != 0)
                {
                    stateFilter &= ~_ErrorState.Error;
                }

                Endpoints.Open(mainCtx);

                for (int i = 0; i < Datasources.Count; i++)
                {
                    DatasourceAdmin admin = Datasources[i];
                    if (!String.IsNullOrEmpty(OverrideEndpoint))
                    {
                        ImportLog.Log(_LogType.ltWarning, "Datsource {0} will run with the override endpoint={1}", admin.Name, OverrideEndpoint);
                        admin.EndpointName = OverrideEndpoint;
                    }
                    if (!String.IsNullOrEmpty(OverrideEndpoint))
                    {
                        ImportLog.Log(_LogType.ltWarning, "Datsource {0} will run with the override pipeline={1}", admin.Name, OverridePipeline);
                        //admin.p = OverrideEndpoint;
                    }

                    if (!isActive(enabledDSses, admin))
                    {
                        ImportLog.Log(_LogType.ltProgress, "[{0}]: not active", admin.Name);
                        continue;
                    }

                    var report = new DatasourceReport(admin);
                    ret.Add(report);
                    PipelineContext ctx      = new PipelineContext(mainCtx, admin, report);
                    var             pipeline = admin.Pipeline;

                    try
                    {
                        admin.Import(ctx);
                        mainCtx.ErrorState |= (ctx.ErrorState & stateFilter);
                        if (ctx.LastError != null)
                        {
                            mainCtx.LastError = ctx.LastError;
                        }
                        report.MarkEnded(ctx);
                    }
                    catch (Exception err)
                    {
                        mainCtx.LastError   = err;
                        mainCtx.ErrorState |= (ctx.ErrorState & stateFilter) | _ErrorState.Error;
                        report.MarkEnded(ctx);
                        throw;
                    }
                    Endpoints.OptClosePerDatasource(ctx);

                    foreach (var c in Converters)
                    {
                        c.DumpMissed(ctx);
                    }
                }
                ImportLog.Log(_LogType.ltProgress, "Import ended");
                ProcessHostCollection.StopAll();
                Endpoints.Close(mainCtx);
                RunAdminSettings.Save(RunAdministrations);
            }
            catch (Exception err2)
            {
                mainCtx.LastError = err2;
                throw;
            }
            finally
            {
                try
                {
                    Endpoints.CloseFinally(mainCtx);
                }
                catch (Exception e2)
                {
                    ErrorLog.Log(e2);
                    ImportLog.Log(e2);
                }
                try
                {
                    ProcessHostCollection.StopAll();
                }
                catch (Exception e2)
                {
                    ErrorLog.Log(e2);
                    ImportLog.Log(e2);
                }
                try
                {
                    ret.SetGlobalStatus(mainCtx);
                    if (Reporter != null)
                    {
                        Reporter.SendReport(mainCtx, ret);
                    }
                }
                catch (Exception e2)
                {
                    ErrorLog.Log(e2);
                    ImportLog.Log(e2);
                }
            }
            //ret.SetGlobalStatus(mainCtx);
            ImportLog.Log("Unknown switches: [{0}]", ret.UnknownSwitches);
            ImportLog.Log("Mentioned switches: [{0}]", ret.MentionedSwitches);
            return(ret);
        }