public static string RunCommand(Command command)
        {
            Stopwatch timeTaken = new Stopwatch();

            timeTaken.Start();

            BusLogger.LogWebInterfaceCommand(command);
            Task <CommandCallback> response = Task <CommandCallback> .Factory.StartNew(() =>
            {
                switch (command.CommandName)
                {
                case "get_command_log":
                    return(CommandCallback(command.CommandName, BusLogger.CommandLog));

                case "get_exception_log":
                    return(CommandCallback(command.CommandName, BusLogger.ExceptionLog));

                case "get_notifications":
                    return(CommandCallback(command.CommandName, NotificationManager.NotificationList));

                case "get_status":
                    return(CommandCallback(command.CommandName, BusMonitor.GetHappiness()));

                case "initial_load":
                    return(CommandCallback(command.CommandName, Bus.Model));

                case "mark_read":
                    NotificationManager.MarkNotificationAsRead(command.CommandParamaters[0]);
                    return(CommandCallback(command.CommandName, NotificationManager.NotificationList));

                case "reload_config":
                    BusFunctions.LoadConfiguration();
                    return(CommandCallback(command.CommandName, Bus.Model));

                case "toggle_door":
                    BusConfig.UpdateDoorStatus(Bus.Model, command.CommandParamaters[0]);
                    return(CommandCallback(command.CommandName, Bus.Model.Doors));

                default:
                    return(CommandCallback(null, null));
                }
            });

            timeTaken.Stop();

            response.Result.TimeTaken = new TimeTaken
            {
                Elapsed             = timeTaken.Elapsed,
                ElapsedMilliseconds = timeTaken.ElapsedMilliseconds,
                ElapsedTicks        = timeTaken.ElapsedTicks,
                IsRunning           = timeTaken.IsRunning
            };

            return(JsonConvert.SerializeObject(response.Result));
        }
Beispiel #2
0
        public static string Run(Command command)
        {
            CommandCallback commandCallback = new CommandCallback();

            BusLogger.LogWebInterfaceCommand(command);

            switch (command.CommandName)
            {
            case "get_command_log":
                commandCallback.Callback = command.CommandName;
                commandCallback.Data     = BusLogger.CommandLog;
                return(JsonConvert.SerializeObject(commandCallback));

            case "get_exception_log":
                commandCallback.Callback = command.CommandName;
                commandCallback.Data     = BusLogger.ExceptionLog;
                return(JsonConvert.SerializeObject(commandCallback));

            case "get_notifications":
                commandCallback.Callback = command.CommandName;
                commandCallback.Data     = NotificationManager.NotificationList;
                return(JsonConvert.SerializeObject(commandCallback));

            case "initial_load":
                commandCallback.Callback = command.CommandName;
                commandCallback.Data     = Bus.Model;
                return(JsonConvert.SerializeObject(commandCallback));

            case "reload_config":
                Console.Clear();
                BusFunctions.LoadConfiguration();
                commandCallback.Callback = command.CommandName;
                commandCallback.Data     = Bus.Model;
                return(JsonConvert.SerializeObject(commandCallback));

            case "toggle_door":
                BusConfig.UpdateDoorStatus(Bus.Model, command.CommandParamaters[0]);
                commandCallback.Callback = command.CommandName;
                commandCallback.Data     = Bus.Model.Doors;
                return(JsonConvert.SerializeObject(commandCallback));
            }

            return(string.Empty);
        }