Beispiel #1
0
        static void Main(string[] args)
        {
            string API_URL      = ConfigurationManager.AppSettings["API_URL"];
            string AppID        = ConfigurationManager.AppSettings["AppID"];
            string DeveloperKey = ConfigurationManager.AppSettings["DeveloperKey"];

            // validate if a parameter was provided
            if (args != null && args.Length > 0)
            {
                // Build url with parameters
                string url = $"{API_URL}/Road/{args[0]}?app_id={AppID}&app_key={DeveloperKey}";

                IRoadStatusManager roadStatusManager = new RoadStatusManager();
                ConsoleResponse    response          = roadStatusManager.RoadStatus(url);

                // write responses
                foreach (string line in response.Lines)
                {
                    Console.WriteLine(line);
                }

                Environment.Exit(response.ExitCode);
            }
            else // No parameter was provided
            {
                Console.WriteLine("Provide road id as parameter");
                Environment.Exit((int)EnumExitCode.ParamError);
            }
        }
Beispiel #2
0
        public void Load()
        {
            StormLib.Console.SetValue("Debugging_Level", new ConsoleVarable()
            {
                ValidCheck = CheckConsoleInput,
                Value      = "0",
                HelpInfo   = StormLib.Localization.DefaultLanguage.Strings.GetString("DEBUGGING_LEVEL_HELP")
            });

            StormLib.Console.SetFunc("debug_db_grabusr", new ConsoleFunction()
            {
                Function = new Func <string[], ConsoleResponse>((string[] debug_args) =>
                {
                    if (debug_args.Length == 0 || debug_args.Length > 1)
                    {
                        return(ConsoleResponse.Failed(StormLib.Localization.DefaultLanguage.Strings.GetString("DEBUG_DB_GRABUSR_HELP")));
                    }
                    if (debug_args.Length == 1)
                    {
                        // var v = Data.Tables.Account.GetAccountByUsername(debug_args[0]);
                        // if (v.Sucess == false)
                        //    return ConsoleResponse.Failed(StormLib.Localization.DefaultLanguage.Strings.GetFormatedString("DEBUG_DB_GRABUSR_NOFIND", debug_args[0]));

                        // return ConsoleResponse.Failed(StormLib.Localization.DefaultLanguage.Strings.GetFormatedString("DEBUG_DB_GRABUSR_FIND", v.Result.ID, v.Result.Username, v.Result.Password));
                    }
                    else
                    {
                    }

                    return(ConsoleResponse.Succeeded(""));
                }),
                HelpInfo = StormLib.Localization.DefaultLanguage.Strings.GetString("DEBUG_DB_GRABUSR_HELP")
            });
        }
Beispiel #3
0
        /// <summary>Method which is invoked when new <see cref="SubscriptionDataEvent"/> arrives.</summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="SubscriptionDataEvent"/> instance containing the event data.</param>
        private static void Connection_DataReceived(object sender, SubscriptionDataEvent e)
        {
            // Ignore any data that isn't a Console style response message.
            if (e.rootObject.GetType() != typeof(ConsoleResponse))
            {
                return;
            }

            ConsoleResponse consoleRoot = (ConsoleResponse)e.rootObject;

            Console.WriteLine(consoleRoot.Message);
        }
Beispiel #4
0
        private ConsoleResponse Disk(string[] arguments)
        {
            if (Program.DiskManager == null)
            {
                return(ConsoleResponse.Failed("Program.DiskManager is not setup yet!"));
            }

            if (arguments.Length == 0)
            {
                return(ConsoleResponse.Succeeded(DefaultLanguage.Strings.GetString("disk_Help")));
            }

            switch (arguments[0])
            {
            case "Free":
                return(ConsoleResponse.Succeeded("Disk Free: " + Program.DiskManager.SynchronousGetDiskAvaliable().ToString()));

            case "Limit":
                return(ConsoleResponse.Succeeded("Disk Limit: " + Program.DiskManager.UsageLimit.ToString()));
            }

            return(ConsoleResponse.Succeeded(DefaultLanguage.Strings.GetString("disk_Help")));
        }
Beispiel #5
0
        private static void SomeEyeCandy()
        {
            EnablePaging = true;
            VerticalLine();
            Indent = 2;

            Spinner("Working!! ", new List <ConsoleText>()
            {
                new ConsoleText("0", ConsoleColor.DarkGray),
                new ConsoleText("0", ConsoleColor.Gray),
                new ConsoleText("0", ConsoleColor.Green),
                new ConsoleText("0", ConsoleColor.Yellow),
                new ConsoleText("0", ConsoleColor.White)
            }, "All Done \n",
                    () => { Thread.Sleep(3000); });

            for (var i = 0; i < 100; i++)
            {
                WriteLine($"Test {i}");
            }

            WriteVertical("This is a test");
            WriteLineCentered(new ConsoleText("This is another test", ConsoleColor.Red));
            SpinnerDashes("Spin!!! ", () => { Thread.Sleep(1800); });
            Spinner("This line will be erased ", new[] { "5", "4", "3", "2", "1" }, "Now!", () => { Thread.Sleep(1100); });
            EraseLine();
            Indent = 0;
            HorizontalLine();

            ConsoleResponse Name = new ConsoleResponse("What is your name?");

            Name.GetInput();

            Write($"Hello {Name.Response.String}");

            EnablePaging = false;
        }
Beispiel #6
0
        public static string GetPage(HttpListenerContext context)
        {
            string ACTION = "";
            int    id;

            if (context.Request.QueryString.Count != 0)
            {
                foreach (string key in context.Request.QueryString.AllKeys)
                {
                    switch (key)
                    {
                    case "stops":
                        if (int.TryParse(context.Request.QueryString[key], out id))
                        {
                            if (Console.GetOnOff(string.Format(Variables.V_camera_stream_enabled, id)).Value)
                            {
                                ConsoleResponse cr = Console.SetValue(string.Format(Variables.V_camera_stream_enabled, id), "false");
                                if (cr.State == ConsoleCommandState.Sucess)
                                {
                                    ACTION += "Sucess! Camera " + id + " disabled.<br/>";
                                }
                                else
                                {
                                    ACTION += "Failure while disabling camera " + id + ": " + cr.Value + "<br/>";
                                }
                            }
                        }

                        break;

                    case "starts":
                        if (int.TryParse(context.Request.QueryString[key], out id))
                        {
                            if (!Console.GetOnOff(string.Format(Variables.V_camera_stream_enabled, id)).Value)
                            {
                                ConsoleResponse cr = Console.SetValue(string.Format(Variables.V_camera_stream_enabled, id), "true");
                                if (cr.State == ConsoleCommandState.Sucess)
                                {
                                    ACTION += "Sucess! Camera " + id + " enabled.<br/>";
                                }
                                else
                                {
                                    ACTION += "Failure while enabling camera " + id + ": " + cr.Value + "<br/>";
                                }
                            }
                        }
                        break;
                    }
                }
            }

            string camerafor = "";

            // Count is protected from having non numurical values so if this fails look elsewhere
            int count = int.Parse(Console.GetValue(Variables.V_camera_count).Value);

            for (int i = 0; i < count; i++)
            {
                camerafor += TemplateProcessor.Process(Environment.CurrentDirectory + "\\HTTP\\templates\\control.camerafor.template", new Dictionary <string, Func <string> >()
                {
                    { "URI", () => { return(context.Request.Url.LocalPath); } },
                    { "STATUS", () => { return(Console.GetValue(string.Format(Variables.V_camera_stream_enabled, i)).Value); } },
                    { "ID", () => { return(i.ToString()); } },
                });
            }


            return(TemplateProcessor.Process(Environment.CurrentDirectory + "\\HTTP\\templates\\control.template", new Dictionary <string, Func <string> >()
            {
                { "URI", () => { return context.Request.Url.LocalPath; } },
                { "ACTION", () => { return ACTION; } },
                { "control.camerafor.template", () => { return camerafor; } },
            }));
        }
Beispiel #7
0
        public ConsoleResponse RoadStatus(string url)
        {
            // Initialise return object
            ConsoleResponse Result = new ConsoleResponse
            {
                Lines = new List <string>()
            };

            try
            {
                HttpWebRequest req = (HttpWebRequest)HttpWebRequest.Create(url);
                req.Method = "GET";

                HttpWebResponse resp = (HttpWebResponse)req.GetResponse();

                ICollection <RoadCorridor> RoadCorridors;

                // convert json response to RoadCorridor object
                using (Stream respStream = resp.GetResponseStream())
                {
                    using (StreamReader streamReader = new StreamReader(respStream, Encoding.UTF8))
                    {
                        RoadCorridors = JsonConvert.DeserializeObject <ICollection <RoadCorridor> >(streamReader.ReadToEnd());
                    }
                }

                // Response is an array, we need to retrieve the first item
                RoadCorridor roadCorridor = RoadCorridors.FirstOrDefault();

                // Fill return object
                Result.Lines.Add($"status of the { roadCorridor.displayName} is as follows");
                Result.Lines.Add($"Road Status is {roadCorridor.statusSeverity}");
                Result.Lines.Add($"Road Status Description is {roadCorridor.statusSeverityDescription}");
                Result.ExitCode = (int)EnumExitCode.OK;
            }
            catch (WebException ex)
            {
                ApiError resultError;

                // validate exception before getting json
                if (ex.Status == WebExceptionStatus.ProtocolError && ex.Response != null && ((HttpWebResponse)ex.Response).StatusCode != HttpStatusCode.InternalServerError)
                {
                    var resp = (HttpWebResponse)ex.Response;

                    // convert json response to ApiError object
                    using (Stream respStream = resp.GetResponseStream())
                    {
                        using (StreamReader streamReader = new StreamReader(respStream, Encoding.UTF8))
                        {
                            resultError = JsonConvert.DeserializeObject <ApiError>(streamReader.ReadToEnd());
                        }
                    }

                    // Fill return object
                    Result.Lines.Add(resultError.message);
                    Result.ExitCode = (int)EnumExitCode.AppError;
                }
                else
                {
                    // write error log ex.Message
                    Result.ExitCode = (int)EnumExitCode.AppUnkownError;
                }
            }
            catch (Exception ex)
            {
                // write error log ex.Message
                Result.ExitCode = (int)EnumExitCode.AppUnkownError;
            }
            return(Result);
        }
Beispiel #8
0
 private static ConsoleResponse QuitConsoleFunction(string[] arguments)
 {
     ThreadsRunning = false;
     return(ConsoleResponse.Succeeded("Terminating."));
 }