示例#1
0
        private async Task Shutdown(MessageContainer data)
        {
            bool.TryParse(data.ResolveParameter("Restart", 0), out bool restart);
            if (!int.TryParse(data.ResolveParameter("Timeout", 1), out int timeout))
            {
                timeout = 10;
            }
            if (restart)
            {
                data.AddValue("Restart", $"Restarting the system in {timeout}sec. We will be back online in a moment.");
            }
            else
            {
                data.AddValue("Shutdown", $"Shutting down the system in {timeout}sec. Hope to be back soon again.");
            }

            await Shutdown(restart, timeout);

            await ComponentHandler.HandleOutput(data).ConfigureAwait(false);

            if (data.Origin is CommunicationComponentBase)
            {
                await CloseChannel(data.Origin as CommunicationComponentBase, data.SessionId).ConfigureAwait(false);
            }
        }
示例#2
0
 private async Task GetActiveTimers(MessageContainer data)
 {
     TimerItem <Tuple <ComponentActionDelegate, MessageContainer> >[] activeTimers = timerWheel.GetActiveTimerItems();
     foreach (TimerItem <Tuple <ComponentActionDelegate, MessageContainer> > item in activeTimers)
     {
         data.AddMultiPartValue("TimerItem", $"TimerItemId :: {item.TimerItemId.ToString()} Interval :: {item.Interval.ToString()} RemainingRepetitions :: {item.Repetition} ActionCommand :: {item.Data.Item2.GetJson().Stringify()}");
     }
     await ComponentHandler.HandleOutput(data).ConfigureAwait(false);
 }
示例#3
0
        private async Task CloseChannel(MessageContainer data)
        {
            data.AddValue("Close", "BYE. Hope to see you soon again.");
            await ComponentHandler.HandleOutput(data).ConfigureAwait(false);

            if (data.Origin is CommunicationComponentBase)
            {
                await CloseChannel(data.Origin as CommunicationComponentBase, data.SessionId).ConfigureAwait(false);
            }
        }
示例#4
0
        private async Task RemoveTimerItem(MessageContainer data)
        {
            if (!Guid.TryParse(data.ResolveParameter("TimerId", 0), out Guid param))
            {
                data.AddValue("Remove", "No valid timer id given");
                await ComponentHandler.HandleOutput(data).ConfigureAwait(false);

                return;
            }
            await timerWheel.RemoveTimerItem(param).ConfigureAwait(false);

            data.AddValue("Remove", $"Task {param} succcessfully removed.");
            await ComponentHandler.HandleOutput(data).ConfigureAwait(false);
        }
示例#5
0
 private async Task SendEcho(MessageContainer data)
 {
     if (data.Parameters.Count == 0)
     {
         data.AddMultiPartValue("Echo", "Nothing to echo");
     }
     else
     {
         foreach (string value in data.Parameters)
         {
             data.AddMultiPartValue("Echo", value);
         }
     }
     await ComponentHandler.HandleOutput(data).ConfigureAwait(false);
 }
示例#6
0
        protected async Task ComponentHelp(MessageContainer data)
        {
            if (null == componentHelp)
            {
                componentHelp = new List <Tuple <string, string, string> >();
                data.AddValue(constHelp, "Preparing help text.");
                Task sendWaitMessage = ComponentHandler.HandleOutput(data);
                BuildHelpCache();
                await sendWaitMessage.ConfigureAwait(false);

                data.ClearValue(constHelp);
            }
            foreach (Tuple <string, string, string> helpText in this.componentHelp)
            {
                data.AddMultiPartValue(constHelp, $"{componentName} {helpText.Item1} {helpText.Item2}: {helpText.Item3}");
            }
            await ComponentHandler.HandleOutput(data).ConfigureAwait(false);
        }
示例#7
0
        private async Task RegisterTimerTask(MessageContainer data)
        {
            int param;
            TimerItem <Tuple <ComponentActionDelegate, MessageContainer> > timerItem = new TimerItem <Tuple <ComponentActionDelegate, MessageContainer> >();

            if (!int.TryParse(data.ResolveParameter("Interval", 0), out param))
            {
                param = 1000;
            }
            timerItem.Interval = TimeSpan.FromMilliseconds(param);
            if (!int.TryParse(data.ResolveParameter("Repetitions", 1), out param))
            {
                param = 0;
            }
            timerItem.Repetition = param;
            string timerAction = data.ResolveParameter("TimerAction", 2);

            string[]         actionParams    = timerAction.GetTokens().ToArray();
            MessageContainer timerActionData = new MessageContainer(data.SessionId, this, actionParams);

            ComponentActionDelegate actionDelegate = ComponentHandler.ResolveCommandHandler(timerActionData);

            if (null == actionDelegate || actionParams == null || actionParams.Length == 0)
            {
                data.AddValue("Register", "Could not parse task action. Please check the command provided.");
                await ComponentHandler.HandleOutput(data).ConfigureAwait(false);

                return;
            }
            timerItem.Data         = new Tuple <ComponentActionDelegate, MessageContainer>(actionDelegate, timerActionData);
            timerItem.TimerAction += TimerAction;
            await timerWheel.Add(timerItem).ConfigureAwait(false);

            data.AddValue("Register", $"Task succcessfully registered with ID {timerItem.TimerItemId}");
            await ComponentHandler.HandleOutput(data).ConfigureAwait(false);
        }
示例#8
0
 private async Task SendDateTime(MessageContainer data)
 {
     data.AddValue("DateTime", DateTime.Now.ToString());
     await ComponentHandler.HandleOutput(data).ConfigureAwait(false);
 }
示例#9
0
 private async Task SendHello(MessageContainer data)
 {
     data.AddMultiPartValue("Hello", "Hello. Great to see you here.");
     data.AddMultiPartValue("Hello", "Use 'Help + CRLF or Enter' command to get help.");
     await ComponentHandler.HandleOutput(data).ConfigureAwait(false);
 }
示例#10
0
 private async Task ListComponents(MessageContainer data)
 {
     data.AddValue("List", await ListComponents().ConfigureAwait(false));
     await ComponentHandler.HandleOutput(data).ConfigureAwait(false);
 }