Exemple #1
0
        private async Task RestartConnectionOrFail()
        {
            if (isRestartingConnection)
            {
                while (isRestartingConnection)
                {
                    await Task.Delay(50);
                }
                return;
            }

            Console.Out.WriteLine($"{Timestamp.Now} WARN: Connection closed unexpectedly. Restarting connection...");
            Console.Out.Flush();

            try {
                isRestartingConnection = true;
                this.connection        = await HttpConnection.ConnectWithModuleLogin(initInfo);

                isRestartingConnection = false;
                Console.Out.WriteLine($"{Timestamp.Now}: Connection restarted successfully.");
                Console.Out.Flush();
            }
            catch (Exception exp) {
                Exception e = exp.GetBaseException() ?? exp;
                Console.Error.WriteLine($"{Timestamp.Now}: Restarting connection failed: {e.Message}");
                Console.Error.WriteLine($"{Timestamp.Now}: Terminating in 5 seconds...");
                Console.Error.Flush();
                await Task.Delay(5000);

                Environment.Exit(1);
            }
        }
        public override async Task Init(ModuleInitInfo info, VariableValue[] restoreVariableValues, Notifier notifier, ModuleThread moduleThread)
        {
            this.notifier = notifier;
            con           = await HttpConnection.ConnectWithModuleLogin(info, listener : null, timeoutSeconds : 10 * 60);

            moduleID = info.ModuleID;
            log      = LogManager.GetLogger(info.ModuleID);
        }
Exemple #3
0
        public override async Task Init(ModuleInitInfo info,
                                        VariableValue[] restoreVariableValues,
                                        Notifier notifier,
                                        ModuleThread moduleThread)
        {
            await base.Init(info, restoreVariableValues, notifier, moduleThread);

            connection = await HttpConnection.ConnectWithModuleLogin(info, this);

            await connection.EnableAlarmsAndEvents(Severity.Info);
        }
Exemple #4
0
        public override async Task Run(Func <bool> shutdown)
        {
            this.connection = await HttpConnection.ConnectWithModuleLogin(initInfo);

            running = true;

            _ = KeepSessionAlive();

            foreach (CalcInstance a in adapters)
            {
                StartRunLoopTask(a);
            }

            while (!shutdown())
            {
                await Task.Delay(100);
            }

            running = false;

            await Shutdown();
        }
        private static async Task <Connection> EnsureConnectOrThrow(ModuleInitInfo info, Connection?client, Action?onConfigChanged = null, string?moduleID = null)
        {
            if (client != null && !client.IsClosed)
            {
                try {
                    await client.Ping();

                    return(client);
                }
                catch (Exception) {
                    Task _ = client.Close();
                    return(await EnsureConnectOrThrow(info, null));
                }
            }

            try {
                EventListener?listener = onConfigChanged == null ? null : new MyEventListener(onConfigChanged);
                Connection    con      = await HttpConnection.ConnectWithModuleLogin(info, listener);

                if (onConfigChanged != null && moduleID != null)
                {
                    var objRoot = await con.GetRootObject(moduleID);

                    await con.EnableConfigChangedEvents(objRoot.ID);
                }
                return(con);
            }
            catch (Exception exp) {
                Exception e   = exp.GetBaseException() ?? exp;
                string    msg = $"Failed ifakFAST connection: {e.GetType().FullName} {e.Message}";
                if (!e.Message.Contains("request because system is shutting down"))
                {
                    Console.Error.WriteLine(msg);
                }
                throw new Exception(msg);
            }
        }
Exemple #6
0
        private async Task ConnectAndEnableEvents()
        {
            connection = await HttpConnection.ConnectWithModuleLogin(info, this);

            await connection.EnableAlarmsAndEvents(Severity.Info);
        }