Exemplo n.º 1
0
        public Watcher(string rootFolder, RuleStatsTracker deps, LocalFolderRuleProcessor ruleProcessor, MergeConfig mCfg)
        {
            RootFolder = Path.GetFullPath( rootFolder );

            Deps = deps;
            MergeCfg = mCfg;
            RuleProcessor = ruleProcessor;
            TransformQueue = new Queue<string>();
            MergeQueue = new Queue<string>();
            TransformThread = new Thread(ProcessTransform);
            MergeThread = new Thread(ProcessMerge);

            // subscribe to writing event for dependencies chain checking
            RuleProcessor.FileManager.Writing += new FileManagerEventHandler(FileManagerWriting);
        }
Exemplo n.º 2
0
        public Watcher(string rootFolder, RuleStatsTracker deps, LocalFolderRuleProcessor ruleProcessor, MergeConfig mCfg)
        {
            RootFolder = Path.GetFullPath(rootFolder);

            Deps            = deps;
            MergeCfg        = mCfg;
            RuleProcessor   = ruleProcessor;
            TransformQueue  = new Queue <string>();
            MergeQueue      = new Queue <string>();
            TransformThread = new Thread(ProcessTransform);
            MergeThread     = new Thread(ProcessMerge);

            // subscribe to writing event for dependencies chain checking
            RuleProcessor.FileManager.Writing += new FileManagerEventHandler(FileManagerWriting);
        }
Exemplo n.º 3
0
        static int Main(string[] args)
        {
            Thread.CurrentThread.CurrentUICulture = CultureInfo.GetCultureInfo("en-US");

            LogManager.Configure(new TraceLogger(true, false)
            {
                TimestampFormat = "{0:hh:mm:ss}"
            });
            IDictionary <string, object> cmdParams;

            try {
                cmdParams = ExtractCmdParams(args, paramDescriptors);
            } catch (Exception ex) {
                log.Write(LogEvent.Fatal, ex.Message, ex);
                Console.Error.WriteLine(ex.Message);
                return(1);
            }
            if (!cmdParams.ContainsKey(BasePathParam))
            {
                cmdParams[BasePathParam] = Environment.CurrentDirectory;
                log.Write(LogEvent.Info, "Base path is not defined, using current directory: {0}", cmdParams[BasePathParam]);
            }
            if (!cmdParams.ContainsKey(IsIncrementalParam))
            {
                cmdParams[IsIncrementalParam] = false;
                log.Write(LogEvent.Info, "Incremental processing is not defined, by default: {0}.", cmdParams[IsIncrementalParam]);
            }
            if (!cmdParams.ContainsKey(IsWatchParam))
            {
                cmdParams[IsWatchParam] = false;
                log.Write(LogEvent.Info, "Watch mode is not defined, by default: {0}.", cmdParams[IsWatchParam]);
            }

            string                   rootFolder       = (string)cmdParams[BasePathParam];
            RuleStatsTracker         ruleStatsTracker = new RuleStatsTracker();
            LocalFolderRuleProcessor folderRuleProcessor;
            MergeConfig              mergeConfig = null;

            try {
                IComponentsConfig     config = ConfigurationSettings.GetConfig("components") as IComponentsConfig;
                INamedServiceProvider srvPrv = new NReco.Winter.ServiceProvider(config);

                folderRuleProcessor = srvPrv.GetService("folderRuleProcessor") as LocalFolderRuleProcessor;
                if (folderRuleProcessor == null)
                {
                    log.Write(LogEvent.Fatal, "Configuration error: missed or incorrect 'folderRuleProcessor' component");
                    return(2);
                }

                // read merge config
                if (cmdParams.ContainsKey(MergeParam))
                {
                    mergeConfig = new MergeConfig((string)cmdParams[MergeParam], rootFolder);
                }
                log.Write(LogEvent.Info, "Reading Folder: {0}", rootFolder);
                DateTime         dt           = DateTime.Now;
                LocalFileManager localFileMgr = new LocalFileManager(rootFolder);
                localFileMgr.Incremental = (bool)cmdParams[IsIncrementalParam];

                localFileMgr.Reading += new FileManagerEventHandler(ruleStatsTracker.OnFileReading);
                localFileMgr.Writing += new FileManagerEventHandler(ruleStatsTracker.OnFileWriting);
                folderRuleProcessor.RuleExecuting     += new FileRuleEventHandler(ruleStatsTracker.OnRuleExecuting);
                folderRuleProcessor.RuleExecuted      += new FileRuleEventHandler(ruleStatsTracker.OnRuleExecuted);
                folderRuleProcessor.RuleFileReadStart += new FileRuleEventHandler(ruleStatsTracker.OnRuleExecuting);
                folderRuleProcessor.RuleFileReadEnd   += new FileRuleEventHandler(ruleStatsTracker.OnRuleExecuted);

                folderRuleProcessor.FileManager = localFileMgr;
                localFileMgr.StartSession();
                folderRuleProcessor.Execute();
                localFileMgr.EndSession();

                log.Write(LogEvent.Info, "Apply time: {0}", DateTime.Now.Subtract(dt).TotalSeconds.ToString());
            } catch (Exception ex) {
                log.Write(LogEvent.Fatal, "Transformation failed: {0}", ex.ToString());
                return(3);
            }


            if (Convert.ToBoolean(cmdParams[IsWatchParam]))
            {
                // some delay for avoid watching for just changed files
                Thread.Sleep(100);

                Watcher w = new Watcher(rootFolder, ruleStatsTracker, folderRuleProcessor, mergeConfig);
                log.Write(LogEvent.Info, "Watching for filesystem changes... (press 'q' for exit)");
                w.Start();
                while (true)
                {
                    ConsoleKeyInfo keyInfo = System.Console.ReadKey();
                    if (keyInfo.KeyChar == 'q')
                    {
                        break;
                    }
                }
                w.Stop();
            }

            return(0);
        }
Exemplo n.º 4
0
        static int Main(string[] args)
        {
            Thread.CurrentThread.CurrentUICulture = CultureInfo.GetCultureInfo("en-US");

            LogManager.Configure(new TraceLogger(true, false) { TimestampFormat = "{0:hh:mm:ss}" });
            IDictionary<string, object> cmdParams;
            try {
                cmdParams = ExtractCmdParams(args, paramDescriptors);
            } catch (Exception ex) {
                log.Write(LogEvent.Fatal, ex.Message, ex);
                Console.Error.WriteLine(ex.Message);
                return 1;
            }
            if (!cmdParams.ContainsKey(BasePathParam)) {
                cmdParams[BasePathParam] = Environment.CurrentDirectory;
                log.Write(LogEvent.Info, "Base path is not defined, using current directory: {0}", cmdParams[BasePathParam]);
            }
            if (!cmdParams.ContainsKey(IsIncrementalParam)) {
                cmdParams[IsIncrementalParam] = false;
                log.Write(LogEvent.Info, "Incremental processing is not defined, by default: {0}.", cmdParams[IsIncrementalParam]);
            }
            if (!cmdParams.ContainsKey(IsWatchParam)) {
                cmdParams[IsWatchParam] = false;
                log.Write(LogEvent.Info, "Watch mode is not defined, by default: {0}.", cmdParams[IsWatchParam]);
            }

            string rootFolder = (string)cmdParams[BasePathParam];
            RuleStatsTracker ruleStatsTracker = new RuleStatsTracker();
            LocalFolderRuleProcessor folderRuleProcessor;
            MergeConfig mergeConfig = null;
            try {
                IComponentsConfig config = ConfigurationSettings.GetConfig("components") as IComponentsConfig;
                INamedServiceProvider srvPrv = new NReco.Winter.ServiceProvider(config);

                folderRuleProcessor = srvPrv.GetService("folderRuleProcessor") as LocalFolderRuleProcessor;
                if (folderRuleProcessor == null) {
                    log.Write(LogEvent.Fatal, "Configuration error: missed or incorrect 'folderRuleProcessor' component");
                    return 2;
                }

                // read merge config
                if (cmdParams.ContainsKey(MergeParam)) {
                    mergeConfig = new MergeConfig( (string) cmdParams[MergeParam], rootFolder );
                }
                log.Write(LogEvent.Info, "Reading Folder: {0}", rootFolder);
                DateTime dt = DateTime.Now;
                LocalFileManager localFileMgr = new LocalFileManager(rootFolder);
                localFileMgr.Incremental = (bool)cmdParams[IsIncrementalParam];

                localFileMgr.Reading += new FileManagerEventHandler(ruleStatsTracker.OnFileReading);
                localFileMgr.Writing += new FileManagerEventHandler(ruleStatsTracker.OnFileWriting);
                folderRuleProcessor.RuleExecuting += new FileRuleEventHandler(ruleStatsTracker.OnRuleExecuting);
                folderRuleProcessor.RuleExecuted += new FileRuleEventHandler(ruleStatsTracker.OnRuleExecuted);
                folderRuleProcessor.RuleFileReadStart += new FileRuleEventHandler(ruleStatsTracker.OnRuleExecuting);
                folderRuleProcessor.RuleFileReadEnd += new FileRuleEventHandler(ruleStatsTracker.OnRuleExecuted);

                folderRuleProcessor.FileManager = localFileMgr;
                localFileMgr.StartSession();
                folderRuleProcessor.Execute();
                localFileMgr.EndSession();

                log.Write(LogEvent.Info, "Apply time: {0}", DateTime.Now.Subtract(dt).TotalSeconds.ToString());
            } catch (Exception ex) {
                log.Write(LogEvent.Fatal, "Transformation failed: {0}", ex.ToString());
                return 3;
            }

            if (Convert.ToBoolean(cmdParams[IsWatchParam])) {
                // some delay for avoid watching for just changed files
                Thread.Sleep(100);

                Watcher w = new Watcher(rootFolder, ruleStatsTracker, folderRuleProcessor, mergeConfig);
                log.Write(LogEvent.Info, "Watching for filesystem changes... (press 'q' for exit)");
                w.Start();
                while (true) {
                    ConsoleKeyInfo keyInfo = System.Console.ReadKey();
                    if (keyInfo.KeyChar == 'q')
                        break;
                }
                w.Stop();

            }

            return 0;
        }