Пример #1
0
 public RunAdministrations(RunAdministrationSettings settings)
 {
     this.Settings = settings;
     list          = new List <RunAdministration>();
     Load();
 }
Пример #2
0
        public void Load(XmlHelper xml)
        {
            Xml = xml;
            String dir = xml.FileName;

            if (!String.IsNullOrEmpty(dir))
            {
                dir = Path.GetDirectoryName(xml.FileName);
            }
            Environment.SetEnvironmentVariable("IMPORT_ROOT", dir);
            fillTikaVars();

            _ImportFlags flags = ImportFlags;

            ImportFlags = xml.ReadEnum("@importflags", (_ImportFlags)0);
            if ((flags & _ImportFlags.UseFlagsFromXml) == 0)
            {
                ImportFlags = flags;
            }

            LogAdds         = xml.ReadInt("@logadds", LogAdds);
            MaxAdds         = xml.ReadInt("@maxadds", MaxAdds);
            SwitchesFromXml = xml.ReadStr("@switches", null);
            ImportLog.Log("Loading import xml: flags={0}, logadds={1}, maxadds={2}, file={3}.", ImportFlags, LogAdds, MaxAdds, xml.FileName);

            binDir = Xml.CombinePath(Xml.ReadStr("@bindir", "bin"));
            if (Directory.Exists(binDir))
            {
                ImportLog.Log(_LogType.ltInfo, "Using extra bin dir: {0}", binDir);
            }
            else
            {
                binDir = null;
                ImportLog.Log(_LogType.ltInfo, "No bin dir found... All executables are loaded from {0}.\r\nCheck bin dir={1}.", Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), binDir);
            }

            TempDir = IOUtils.AddSlash(Xml.CombinePath("temp"));
            IOUtils.ForceDirectories(TempDir, true);

            XmlNode x = Xml.SelectSingleNode("report");

            if (x == null)
            {
                Reporter = null;
            }
            else
            {
                Reporter = new MailReporter(x);
            }
            ImportLog.Log("loaded reporter: {0}", Reporter);


            RunAdminSettings = new RunAdministrationSettings(this, Xml.SelectSingleNode("runadmin"));
            ImportLog.Log("loaded runadmin settings: {0}", RunAdminSettings);

            //Load the supplied script
            ImportLog.Log(_LogType.ltTimerStart, "loading: scripts");
            XmlNode scriptNode = xml.SelectSingleNode("script");

            //Create the holder for the expressions
            ScriptExpressions = new ScriptExpressionHolder();

            ImportLog.Log(_LogType.ltTimer, "loading: helper process definitions ");
            ProcessHostCollection = new ProcessHostCollection(this, xml.SelectSingleNode("processes"));

            ImportLog.Log(_LogType.ltTimer, "loading: endpoints");
            Endpoints = new Endpoints(this, xml.SelectMandatoryNode("endpoints"));

            ImportLog.Log(_LogType.ltTimer, "loading: post-processors");
            PostProcessors = new PostProcessors(this, xml.SelectSingleNode("postprocessors"));

            ImportLog.Log(_LogType.ltTimer, "loading: converters");
            Converters = new Converters(
                xml.SelectSingleNode("converters"),
                "converter",
                (node) => Converter.Create(node),
                false);

            ImportLog.Log(_LogType.ltTimer, "loading: categories");
            Categories = new NamedAdminCollection <CategoryCollection>(
                xml.SelectSingleNode("categories"),
                "collection",
                (node) => new CategoryCollection(node),
                true);

            ImportLog.Log(_LogType.ltTimer, "loading: pipelines");
            Pipelines = new NamedAdminCollection <Pipeline>(
                xml.SelectMandatoryNode("pipelines"),
                "pipeline",
                (node) => new Pipeline(this, node),
                true);

            ImportLog.Log(_LogType.ltTimer, "loading: datasources");
            PipelineContext ctx = new PipelineContext(this);

            Datasources = new NamedAdminCollection <DatasourceAdmin>(
                xml.SelectMandatoryNode("datasources"),
                "datasource",
                (node) => new DatasourceAdmin(ctx, node),
                true);

            //Compile script if needed
            if (ScriptExpressions.Count > 0 || scriptNode != null)
            {
                ScriptHost = new ScriptHost(ScriptHostFlags.Default, TemplateFactory);
                if (scriptNode != null)
                {
                    String fn = scriptNode.ReadStr("@file", null);
                    if (fn != null)
                    {
                        ScriptHost.AddFile(xml.CombinePath(fn));
                    }
                }
                ScriptHost.ExtraSearchPath = binDir;
                if (ScriptExpressions.Count > 0)
                {
                    String fn = TempDir + "_ScriptExpressions.cs";
                    ScriptExpressions.SaveAndClose(fn);
                    ScriptHost.AddFile(fn);
                }
                ScriptHost.AddReference(Assembly.GetExecutingAssembly());
                ScriptHost.AddReference(typeof(Bitmanager.Json.JsonExt));
                ScriptHost.AddReference(typeof(Bitmanager.Elastic.ESConnection));
                ScriptHost.Compile();
            }

            ImportLog.Log(_LogType.ltTimerStop, "loading: finished. Loaded {0} datasources, {1} pipelines, {2} endpoints, {3} converters, {4} category collections.",
                          Datasources.Count,
                          Pipelines.Count,
                          Endpoints.Count,
                          Converters.Count,
                          Categories.Count);
        }