예제 #1
0
 public MediatorCore()
 {
     reqHandler = new HandleClientRequests(this);
     if (theCore == null)
     {
         theCore = this;
     }
 }
예제 #2
0
 public ModuleState(Module config, MediatorCore core)
 {
     this.logger    = LogManager.GetLogger(config.Name);
     this.Config    = config;
     this.core      = core;
     this.State     = State.Created;
     this.Password  = Guid.NewGuid().ToString();
     this.variables = new ModuleVariables(config.ID, config.Name, config.VariablesFileName);
 }
예제 #3
0
 private static void DoReader(Logger logger, MediatorCore core, string title)
 {
     while (true)
     {
         string line = Console.In.ReadLine();
         if (line == "Stop")
         {
             core.RequestShutdown();
             logger.Info($"{title} terminate requested...");
             return;
         }
     }
 }
예제 #4
0
        static void Main(string[] args)
        {
            if (args.Length > 1 && args[0] == "encrypt")
            {
                string text      = args[1];
                string encrypted = SimpleEncryption.Encrypt(text);
                Console.WriteLine("Encrypted = " + encrypted);
                return;
            }

            if (args.Length > 4 && args[0] == "copydb")
            {
                string srcType       = args[1];
                string srcConnection = args[2];
                string dstType       = args[3];
                string dstConnection = args[4];
                Console.WriteLine($"Copy data from \"{srcConnection}\" to \"{dstConnection}\"...");

                Timeseries.Migrate.CopyData(
                    srcType: srcType,
                    srcConnectionString: srcConnection,
                    dstType: dstType,
                    dstConnectionString: dstConnection);

                return;
            }

            string configFileName    = "";
            string title             = "";
            string logDir            = "";
            string logName           = "";
            string fileStartComplete = "";
            bool   clearDBs          = false;

            Parser.Default.ParseArguments <Options>(args).WithParsed(o => {
                configFileName    = o.ConfigFileName;
                title             = o.Title;
                logDir            = o.LogDir;
                logName           = o.LogName;
                fileStartComplete = o.FileStartComplete;
                clearDBs          = o.ClearDBs;
            });

            string fullLogDir = Path.GetFullPath(logDir);

            LayoutRenderer.Register("log-output-dir", (logEvent) => fullLogDir);
            LayoutRenderer.Register("log-file-name", (logEvent) => logName);

            string workingDir = Directory.GetCurrentDirectory();

            Console.Title = $"{title} - {workingDir}";

            Logger logger = LogManager.GetLogger("Mediator.Prog");

            if (!File.Exists(configFileName))
            {
                const string oldConfigFileName = "config.xml";
                if (configFileName == Options.DefaultConfigName && File.Exists(oldConfigFileName))
                {
                    configFileName = oldConfigFileName;
                    logger.Info($"Using old configuration file name \"{oldConfigFileName}\". Consider renaming file to \"{Options.DefaultConfigName}\".");
                }
                else
                {
                    logger.Error($"Main configuration file \"{configFileName}\" not found in {workingDir}");
                    return;
                }
            }

            string version = Util.VersionInfo.ifakFAST_Str();

            logger.Info($"Starting {title} {version}...");

            var core = new MediatorCore();

            Console.CancelKeyPress += delegate(object sender, ConsoleCancelEventArgs e) {
                e.Cancel = true;
                core.RequestShutdown();
                logger.Info($"{title} terminate requested...");
            };

            Thread t = new Thread(() => { DoReader(logger, core, title); });

            t.IsBackground = true;
            t.Start();

            try {
                SingleThreadedAsync.Run(() => core.Run(configFileName, clearDBs, fileStartComplete));
            }
            catch (Exception exp) {
                logger.Error(exp.GetBaseException(), exp.Message);
            }

            logger.Info($"{title} terminated.");
        }