Ejemplo n.º 1
0
 private void TheThread()
 {
     try {
         SingleThreadedAsync.Run(() => Runner());
     }
     catch (Exception exp) {
         logger.Error("HistoryDBWorker terminated unexpectedly: " + exp.Message);
     }
     terminated = true;
 }
Ejemplo n.º 2
0
        public static void ConnectAndRunModule(string host, int port, ModuleBase module) {

            var connector = new TcpConnectorSlave();
            connector.Connect(host, port);

            try {
                SingleThreadedAsync.Run(() => Loop(connector, module));
            }
            catch (Exception exp) {
                Console.Error.WriteLine("EXCEPTION: " + exp.Message);
            }
        }
Ejemplo n.º 3
0
 private void TheThread()
 {
     try {
         SingleThreadedAsync.Run(() => Runner());
     }
     catch (Exception exp) {
         hasTerminated = true;
         logger.Warn($"Runner failed for module {moduleName}: " + exp.Message);
         if (runPromise != null)
         {
             runPromise.TrySetException(exp);
         }
         else if (initPromise != null)
         {
             initPromise.TrySetException(exp);
         }
     }
 }
Ejemplo n.º 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.");
        }