Exemplo n.º 1
0
        /// <summary>
        /// Main function that initializes the two sample applications
        /// </summary>
        /// <param name="args"></param>
        static void Main(string[] args)
        {
            /** Make sure these values are set. Program can't run without them! */
            if (string.IsNullOrWhiteSpace(API_SERVER))
            {
                Console.WriteLine("API_SERVER variable not set!");

                Console.WriteLine("Press any key to continue...");
                Console.ReadKey();
                return;
            }
            else if (string.IsNullOrWhiteSpace(API_KEY))
            {
                Console.WriteLine("API_KEY variable not set!");

                Console.WriteLine("Press any key to continue...");
                Console.ReadKey();
                return;
            }
            http = new HttpAsync(API_SERVER, API_KEY);

            /** Program 1 */
            FirstApp.Run();

            /** Program 2 */
            SecondApp.Run();
        }
Exemplo n.º 2
0
        /// <summary>
        /// Program entry point.
        /// </summary>
        public static async Task Main(string[] args)
        {
            CheckVariables();

            IHttpAsync http = new HttpAsync($"{API_SERVER}/api/{Version}", API_KEY);

            /* -- App 1 -- */
            Console.WriteLine("This first sample application will test the get, create, update," +
                              " and delete functions of \"parkinglots\", \"driveways\" and \"sensors\".");

            Console.WriteLine("Run first sample application (y/n)? ");
            string input = Console.ReadLine();

            if (input == "y" || input == "Y")
            {
                await new SampleAppOne(http).Run();
            }


            /* -- App 2 -- */
            Console.WriteLine("This second sample application will test the \"sensorlogs\" methods " +
                              "as well as the \"sensor downlink\" methods.");

            Console.WriteLine("Run second sample application (y/n)? ");
            input = Console.ReadLine();
            if (input == "y" || input == "Y")
            {
                await new SampleAppTwo(http).Run();
            }
        }
Exemplo n.º 3
0
 /// <summary>
 /// Send a deactivate downlink request.
 /// </summary>
 /// <param name="id">Id of the sensor.</param>
 public Task <string> Deactivate(string id)
 {
     try {
         return(HttpAsync.Post($"/{Path}/{id}/deactivate"));
     } catch {
         Console.WriteLine("Couldn't send deactivate request.");
         throw;
     }
 }
Exemplo n.º 4
0
 /// <summary>
 /// Send a reboot downlink request.
 /// </summary>
 /// <param name="id">Id of the sensor.</param>
 public Task <string> Reboot(string id)
 {
     try {
         return(HttpAsync.Post($"/{Path}/{id}/reboot"));
     } catch {
         Console.WriteLine("Couldn't send reboot request.");
         throw;
     }
 }
Exemplo n.º 5
0
        public async Task <JsonResult> OnPostAsync(string UserInput)
        {
            try
            {
                HttpAsync httpAsync = new HttpAsync();
                string    response  = await httpAsync.Get(CrtShUrl.Replace("#URL#", UserInput));

                return(new JsonResult(response));
            }
            catch (Exception ex)
            {
                return(new JsonResult(ex.Message));
            }
        }
Exemplo n.º 6
0
        /// <summary>
        /// Get logs for the given sensor withing the time interval.
        /// </summary>
        /// <param name="start">Starting date-time.</param>
        /// <param name="end">Ending date-time.</param>
        /// <param name="id">Id of the sensor.</param>
        public async Task <ICollection <SensorLog> > GetSensorLogs(string start, string end, string id)
        {
            try {
                string response = await HttpAsync.Get($"/{Path}/{id}/{SensorLogApi.Path}/{start}/{end}");

                try {
                    return(JsonConvert.DeserializeObject <ICollection <SensorLog> >(response));
                } catch (Exception ex) {
                    Console.WriteLine($"Couldn't create sensor log objects: " + ex);
                    return(new List <SensorLog>());
                }
            } catch {
                Console.WriteLine($"Couldn't get sensor logs.");
                throw;
            }
        }
        /// <summary>
        /// Get all driveways that belong to the parking lot.
        /// </summary>
        /// <param name="id">Id of the parking lot.</param>
        public async Task <ICollection <Driveway> > GetDriveways(string id)
        {
            try {
                string response = await HttpAsync.Get($"/{Path}/{id}/{DrivewayApi.Path}");

                try {
                    return(JsonConvert.DeserializeObject <ICollection <Driveway> >(response));
                } catch (Exception ex) {
                    Console.WriteLine($"Couldn't create driveway objects: " + ex);
                    return(new List <Driveway>());
                }
            } catch {
                Console.WriteLine($"Couldn't get driveways.");
                throw;
            }
        }
Exemplo n.º 8
0
        public async Task <ContentResult> OnPostRawDataAsync(string binid)
        {
            if (!string.IsNullOrEmpty(binid))
            {
                try
                {
                    HttpAsync httpAsync = new HttpAsync();
                    string    response  = await httpAsync.Get(PastBinUrl.Replace("#bin#", binid));

                    return(Content(response));
                }
                catch (Exception ex)
                {
                    return(Content(ex.Message));
                }
            }
            else
            {
                return(Content("No data not found"));
            }
        }
Exemplo n.º 9
0
        public async Task <JsonResult> OnPostAsync(string UserInput)
        {
            if (!string.IsNullOrEmpty(UserInput))
            {
                List <BinResult> binResults = new List <BinResult>();
                string[]         keywords   = UserInput.Split(" ").Take(5).ToArray();
                List <string>    jReturns   = new List <string>();
                foreach (string keyword in keywords)
                {
                    //    data.Labels.Add(keyword);
                    //todo add link to pastbin raw data based on binID
                    try
                    {
                        HttpAsync httpAsync = new HttpAsync();
                        string    response  = await httpAsync.Get(PsDumpUrl.Replace("#keyword#", keyword));

                        if (!string.IsNullOrEmpty(response))
                        {
                            try
                            {
                                binResults.Add(JsonConvert.DeserializeObject <BinResult>(response));
                                jReturns.Add(response);
                            }
                            catch (Exception)
                            {
                            }
                        }
                    }
                    catch (Exception)
                    {
                    }
                }
                //Create chart
                Chart chart = new Chart();
                chart.Type = Enums.ChartType.Line;
                LineDataset lineDataset = new LineDataset();
                Data        data        = new Data();
                data.Labels   = new List <string>();
                data.Datasets = new List <Dataset>();
                foreach (BinResult binResult in binResults)
                {
                    LineDataset    dataset = new LineDataset();
                    List <double?> c       = new List <double?>();
                    foreach (var line in binResult.data.GroupBy(f => DateTime.Parse(f.Time).ToUniversalTime()
                                                                .ToString("Y", System.Globalization.CultureInfo.CreateSpecificCulture("en-US")))
                             .Select(group => new
                    {
                        xAxis = group.Key,
                        yAxis = group.Count()
                    })
                             .OrderBy(x => x.xAxis))
                    {
                        Debug.WriteLine(line.xAxis);
                        if (!data.Labels.Contains(line.xAxis))
                        {
                            data.Labels.Add(line.xAxis);
                        }

                        if (c.Count() < data.Labels.IndexOf(line.xAxis))
                        {
                            for (int i = c.Count(); i < data.Labels.IndexOf(line.xAxis); i++)
                            {
                                c.Add(0);
                            }
                        }
                        c.Insert(data.Labels.IndexOf(line.xAxis), (line.yAxis));
                        Debug.WriteLine("{0} {1} {2}", binResult.Search, line.xAxis, line.yAxis);
                    }
                    lineDataset = CreateChartDataSet(binResult.Search, c);
                    data.Datasets.Add(lineDataset);
                }
                Options options = new Options()
                {
                    Scales              = new Scales(),
                    Responsive          = true,
                    MaintainAspectRatio = true
                };

                Scales scales = new Scales()
                {
                    YAxes = new List <Scale>()
                    {
                        new CartesianScale()
                    },
                    XAxes = new List <Scale>()
                    {
                        new CartesianScale()
                        {
                            Type     = "category",
                            Position = "bottom",
                            Ticks    = new CartesianLinearTick()
                            {
                                BeginAtZero = false
                            }
                        }
                    }
                };

                CartesianScale yAxes = new CartesianScale()
                {
                    Ticks = new Tick()
                };

                Tick tick = new Tick()
                {
                    Callback = "function(value, index, values) {return '#of bins' + value;}"
                };

                yAxes.Ticks  = tick;
                scales.YAxes = new List <Scale>()
                {
                    yAxes
                };
                options.Scales = scales;
                chart.Options  = options;
                chart.Data     = data;
                return(new JsonResult(new { table = jReturns, chart = chart.CreateChartCode("lineChart") }));
            }
            return(null);
        }