示例#1
0
        public void run()
        {
            ApiEngine ae      = new ApiEngine(conf);
            Boolean   verbose = conf.getCfg("verbose").Equals("yes");

            while (true)
            {
                Console.Clear();
                string json_to_submit = ae.getJson();
                using (var client = new System.Net.WebClient())
                {
                    try
                    {
                        client.Headers[HttpRequestHeader.ContentType] = "application/json";
                        client.Headers.Add("HUBBLE-DEVICE-KEY", conf.getCfg("device_key"));
                        client.UploadData(conf.getCfg("apiEntry") + "api/v1/devices/" + conf.getCfg("device_id") + "/latest", System.Text.Encoding.UTF8.GetBytes(json_to_submit));
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine(e.StackTrace);
                    }
                }

                if (verbose)
                {
                    Console.WriteLine("Following JSON was sent for " + conf.getCfg("device_id") + "\n");
                    Console.WriteLine(json_to_submit);
                }

                System.Threading.Thread.Sleep(int.Parse(conf.getCfg("refreshTime")));
            }
        }
示例#2
0
        public void getJSON()
        {
            ApiEngine ae   = new ApiEngine(new Config());
            string    json = ae.getJson();

            Assert.IsFalse(String.IsNullOrEmpty(json));

            JavaScriptSerializer jss = new JavaScriptSerializer();

            HubbleJSON hubble_json = jss.Deserialize <HubbleJSON>(json);

            Assert.IsFalse(String.IsNullOrEmpty(hubble_json.name));
            Assert.IsFalse(String.IsNullOrEmpty(hubble_json.os_version));
            Assert.IsFalse(String.IsNullOrEmpty(hubble_json.client_version));
            Assert.IsFalse(String.IsNullOrEmpty(hubble_json.ram_total));
            Assert.IsFalse(String.IsNullOrEmpty(hubble_json.ram_free));
            Assert.IsFalse(String.IsNullOrEmpty(hubble_json.cpu_usage));
        }