Exemple #1
0
        public void resolves_single_logger_as_just_that_instance()
        {
            var inner = new ConsoleBusLogger();

            BusLogger.Combine(new IBusLogger[] { inner })
            .ShouldBeSameAs(inner);
        }
        public static void LoadConfiguration()
        {
            string config;
            string configFile = string.Format("{0}", Assembly.GetEntryAssembly().Location.Replace("Bus.exe", "config.json"));

            if (!File.Exists(configFile))
            {
                File.Create(configFile);
            }

            using (StreamReader configReader = new StreamReader(configFile))
            {
                config = configReader.ReadToEnd();
                try
                {
                    Bus.Model   = JsonConvert.DeserializeObject <BusConfig>(config);
                    validConfig = true;
                }
                catch (Exception e)
                {
                    Console.WriteLine(ConsoleFunctions.WriteWithColour(ConsoleColor.Red, "INVALID CONFIGURATION FILE"));
                    BusLogger.LogException(e);
                    validConfig = false;
                }
                finally
                {
                    configReader.Close();
                }
            }

            BusCCTV.CheckHDDUsage();
            BusCCTV.CheckDriveHealth();
        }
Exemple #3
0
        public HandlerPipeline(IEnvelopeSender sender, IEnvelopeSerializer serializer, HandlerGraph graph, IReplyWatcher replies, IBusLogger[] loggers)
        {
            _sender     = sender;
            _serializer = serializer;
            _graph      = graph;
            _replies    = replies;

            Logger = BusLogger.Combine(loggers);
        }
Exemple #4
0
        public void resolves_multiple_loggers_to_composite()
        {
            var inner1 = Substitute.For <IBusLogger>();
            var inner2 = Substitute.For <IBusLogger>();
            var inner3 = Substitute.For <IBusLogger>();

            BusLogger.Combine(new IBusLogger[] { inner1, inner2, inner3 })
            .ShouldBeOfType <CompositeLogger>()
            .Loggers.ShouldHaveTheSameElementsAs(inner1, inner2, inner3);
        }
        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));
        }
        private static void ProcessCommand(WebSocketSession session, string value)
        {
            Command command = JsonConvert.DeserializeObject <Command>(value);

            if (command.Token != Bus.AuthToken)
            {
                BusLogger.LogException(new InvalidAuthTokenException("INVALID AUTHENTICATION TOKEN ERROR"));
                session.Send(JsonConvert.SerializeObject(CommandProcessor.CommandCallback("error_message", "An incorrect authentication key was provided")));
                return;
            }

            session.Send(CommandProcessor.RunCommand(command));
            session.Close();
        }
        public static void StartBackend()
        {
            LoadConfiguration();
            Console.Title = string.Format("{0}, CheckDelay: {1}s", Bus.Model.ToString(), Bus.checkDelay);

            BusCCTV.Start();
            BusLogger.Start();
            BusTracker.Start();
            BusWebInterfaceListener.Start();

            while (validConfig)
            {
                ConsoleOutput();
                Thread.Sleep(Bus.checkDelay * 1000);
            }
        }
Exemple #8
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);
        }
Exemple #9
0
 public void resolves_no_loggers_as_nullo()
 {
     BusLogger.Combine(new IBusLogger[0])
     .ShouldBeOfType <BusLogger>();
 }
Exemple #10
0
 public EnvelopeSender(ChannelGraph channels, IEnvelopeSerializer serializer, IBusLogger[] loggers)
 {
     _channels   = channels;
     _serializer = serializer;
     Logger      = BusLogger.Combine(loggers);
 }