Exemplo n.º 1
0
        public void TestUpdateDataStream()
        {
            var       client       = new DefaultOneNETClient(url, appkey, "");
            const int testDeviceId = 768719;
            var       dsId         = "testupdate" + DateTime.Now.Ticks;
            //add new
            var data = new DataStreamCommon {
                ID = dsId, Unit = "ABC", Unit_Symbol = "abc", Tags = new [] { "testupdate", "yztest" }
            };
            var newReq = new NewDataStreamRequest {
                DeviceID = testDeviceId, DataStream = data
            };
            var resp = client.Execute(newReq);

            Assert.IsFalse(resp.IsError);
            Console.WriteLine(resp.Data.Ds_Uuid);

            //test update
            var uData = new DataStreamCommon {
                Unit = "XYZ", Unit_Symbol = "xyz", Tags = new [] { "updated", "testxyz" }
            };
            var uReq = new UpdateDataStreamRequest {
                DeviceID = testDeviceId, DataStreamId = dsId, DataStream = uData
            };
            var client1 = new DefaultOneNETClient(url, appkey, "");
            var delResp = client1.Execute(uReq);

            Assert.IsFalse(delResp.IsError);
        }
Exemplo n.º 2
0
        public void TestAddAndDeleteDataStream()
        {
            var          client       = new DefaultOneNETClient(url, appkey, "");
            const int    testDeviceId = 768719;
            const string dsId         = "testdelete";
            //test add new
            var data = new DataStreamCommon {
                ID = dsId, Unit = "sth", Unit_Symbol = "sth"
            };
            var newReq = new NewDataStreamRequest {
                DeviceID = testDeviceId, DataStream = data
            };
            var resp = client.Execute(newReq);

            Assert.IsFalse(resp.IsError);
            Console.WriteLine(resp.Data.Ds_Uuid);
            //test delete
            var client1 = new DefaultOneNETClient(url, appkey, "");
            var delReq  = new DeleteDataStreamRequest {
                DeviceID = testDeviceId, DataStreamId = dsId
            };
            var delResp = client1.Execute(delReq);

            Assert.IsFalse(delResp.IsError);
        }
Exemplo n.º 3
0
        public void DeleteAddDevice()
        {
            var client = new DefaultOneNETClient(url, appkey, "");
            var device = new DeviceBasicInfo
            {
                Title    = "测试C# SDK",
                Desc     = "一次通过一次通过一次通过",
                Private  = true,
                OnLine   = false,
                Tags     = new[] { "测试", "sdk" },
                Protocol = "HTTP",
                Location = new LocationInfo(370000, 17.609997, 177.03403)
            };
            var req = new NewDeviceRequest
            {
                Protocol  = Scheme.HTTP,
                NewDevice = device
            };
            var resp = client.Execute(req);

            Assert.IsFalse(resp.IsError);
            Assert.IsNotNull(resp.Data);
            Console.WriteLine(resp.Data.Device_Id);

            //delete
            var delReq = new DeleteDeviceRequest {
                DeviceID = resp.Data.Device_Id
            };
            var delResp = client.Execute(delReq);

            Assert.IsFalse(delResp.IsError);
        }
Exemplo n.º 4
0
        public void TestGetKeys()
        {
            var client = new DefaultOneNETClient(url, appkey, "");
            //test get all
            var req = new GetKeysRequest();
            var rsp = client.Execute(req);

            Console.WriteLine(rsp.Body);
            Assert.IsFalse(rsp.IsError);
            Assert.IsNotNull(rsp.Data);
            Assert.IsTrue(rsp.Data.Total_Count > 0);

            //test get by key
            var c1   = new DefaultOneNETClient(url, appkey, "");
            var req1 = new GetKeysRequest {
                Key = "jb3idOcNvc3Tv=WtoBLBLPYgVyg="
            };
            var rsp1 = c1.Execute(req1);

            Assert.IsFalse(rsp1.IsError);
            Assert.IsNotNull(rsp1.Data);
            Assert.IsTrue(rsp1.Data.Total_Count > 0);

            //test get by device id
            var c2   = new DefaultOneNETClient(url, appkey, "");
            var req2 = new GetKeysRequest {
                DeviceId = "776941"
            };
            var rsp2 = c2.Execute(req2);

            Assert.IsFalse(rsp2.IsError);
            Assert.IsNotNull(rsp2.Data);
            Assert.IsTrue(rsp1.Data.Total_Count > 0);
        }
Exemplo n.º 5
0
        public void TestAddEDPDevice()
        {
            var client = new DefaultOneNETClient(url, appkey, "");
            var device = new DeviceBasicInfo
            {
                Title     = "C#添加EDP设备Auth_Info",
                Desc      = "C# SDK添加EDP设备",
                Private   = true,
                OnLine    = false,
                Tags      = new[] { "测试", "sdk" },
                Protocol  = "EDP",
                Auth_Info = new JRaw("{\"sim\":123456445}"),
                Location  = new LocationInfo(370000, 18.609997, 77.03403)
            };
            var req = new NewDeviceRequest
            {
                Protocol  = Scheme.HTTP,
                NewDevice = device
            };
            var resp = client.Execute(req);

            Assert.IsFalse(resp.IsError);
            Assert.IsNotNull(resp.Data);
            Assert.IsTrue(resp.Data.Device_Id > 0);
        }
Exemplo n.º 6
0
        public void TestSearchDevices()
        {
            var client = new DefaultOneNETClient(url, appkey, "");

            //test keywords
            var req = new SearchDeviceRequest
            {
                Protocol = Scheme.HTTP,
                Keywords = "768"
            };
            var resp = client.Execute(req);

            Assert.IsFalse(resp.IsError);
            Assert.AreEqual(0, resp.Errno);
            Assert.AreEqual("succ", resp.Error);
            Assert.IsNotNull(resp.Data);
            Assert.AreEqual(2, resp.Data.Total_Count);

            //test other para
            var req2 = new SearchDeviceRequest
            {
                Protocol = Scheme.HTTP,
                Private  = false
            };
            var client2 = new DefaultOneNETClient(url, appkey, "");
            var resp2   = client2.Execute(req2);

            Assert.IsFalse(resp2.IsError);
            Assert.IsNotNull(resp2.Data);
            Assert.AreEqual(1, resp2.Data.Total_Count);
        }
Exemplo n.º 7
0
        public void TestAddBinData()
        {
            var client = new DefaultOneNETClient(url, appkey, "");
            var fp     = @"../../files/dev_data.txt";
            var fi     = new FileInfo(fp);
            var len    = fi.Length;
            var fs     = new FileStream(fp, FileMode.Open);
            var buffer = new byte[len];

            fs.Read(buffer, 0, (int)len);
            fs.Close();

            var req = new NewBinDataRequest {
                DeviceID = 3011964, DatastreamId = "data", BinData = buffer
            };
            var rsp = client.Execute(req);

            Assert.IsFalse(rsp.IsError);
            Console.WriteLine(rsp.Body);
            Assert.IsNotNull(rsp.Data);
            Assert.IsNotNull(rsp.Data.Index);

            //Thread.Sleep(10000);

            var client1 = new DefaultOneNETClient(url, appkey, "");
            //get bin data added from above test method
            var gReq = new GetBinDataRequest {
                Index = rsp.Data.Index
            };
            var gRsp = client1.Execute(gReq);

            Assert.IsFalse(gRsp.IsError);
            Assert.IsNotNull(gRsp.Body);
            Console.WriteLine(gRsp.Body);
        }
Exemplo n.º 8
0
        public void TestGetBinData()
        {
            var client1 = new DefaultOneNETClient(url, appkey, "");
            //get bin data added from above test method
            var gReq = new GetBinDataRequest {
                Index = "768672_1459242295299_datastream_id1"
            };
            var gRsp = client1.Execute(gReq);

            Assert.IsFalse(gRsp.IsError);
            Assert.IsNotNull(gRsp.Body);
            Assert.IsNotNull(gRsp.BinDataBody);

            var stream = new MemoryStream(gRsp.BinDataBody);

            var bytes = new byte[stream.Length];

            stream.Read(bytes, 0, bytes.Length);
            stream.Seek(0, SeekOrigin.Begin);
            var fileName = "../../files/" + DateTime.Now.ToString("yyyyMMddHHmm") + ".jpg";

            var fs = new FileStream(fileName, FileMode.Create);
            var bw = new BinaryWriter(fs);

            bw.Write(bytes);
            bw.Close();
            fs.Close();
        }
Exemplo n.º 9
0
        public void TestSendBinDataCmd()
        {
            var client = new DefaultOneNETClient(url, appkey, "");
            //todo:待测
            var fp     = @"../../files/test.txt";
            var fi     = new FileInfo(fp);
            var len    = fi.Length;
            var fs     = new FileStream(fp, FileMode.Open);
            var buffer = new byte[len];

            fs.Read(buffer, 0, (int)len);
            fs.Close();

            var req = new SendCmdRequest {
                DeviceID = 3081523, Protocol = Scheme.HTTP, CmdContent = buffer, IsByte = true
            };
            var rsp = client.Execute(req);

            Assert.IsFalse(rsp.IsError);
            Console.WriteLine(rsp.Body);
            var body = JsonConvert.DeserializeObject <CmdSendResp>(rsp.Body);

            Assert.IsNotNull(rsp.Data);
            Assert.IsNotNull(body.Data.Cmd_uuid);
        }
Exemplo n.º 10
0
        public void TestDeleteTrigger()
        {
            //add
            var client = new DefaultOneNETClient(url, appkey, "");
            var req    = new NewTriggerRequest
            {
                Trigger = new NewTriggerInfo
                {
                    Title     = "test delete trigger for some device",
                    Url       = "http://www.baidu.com",
                    Type      = TriggerType.InOut.GetTriggerTypeString(),
                    Threshold = new { lolmt = 40, uplmt = 300 },
                    Dev_Ids   = new[] { "768672" },
                    Ds_Id     = "每日进货量"
                }
            };

            var rsp = client.Execute(req);

            Assert.IsFalse(rsp.IsError);
            Assert.IsNotNull(rsp.Data);
            Assert.IsNotNull(rsp.Data.Trigger_Id);

            var c1   = new DefaultOneNETClient(url, appkey, "");
            var req1 = new DeleteTriggerRequest {
                TriggerID = rsp.Data.Trigger_Id
            };
            var rsp1 = c1.Execute(req1);

            Assert.IsFalse(rsp1.IsError);
        }
Exemplo n.º 11
0
        public void TestRegisterAttr()
        {
            var client = new DefaultOneNETClient(url, appkey, "");
            var req    = new RegisterAttrRequest {
                DeviceRegisterAttr = { Allow_Dup = false }
            };
            var resp = client.Execute(req);

            Assert.IsFalse(resp.IsError);
        }
Exemplo n.º 12
0
        public void TestSearchHistoryData()
        {
            var client = new DefaultOneNETClient(url, appkey, "");
            var req    = new SearchHistoryDataRequest {
                Start = DateTime.Parse("2012-03-02")
            };
            var rsp = client.Execute(req);

            Assert.IsFalse(rsp.IsError);
            Assert.IsNotNull(rsp.Data);
            Assert.IsTrue(rsp.Data.DataPoints.Count > 0);
        }
Exemplo n.º 13
0
        public void TestGetATrigger()
        {
            var client = new DefaultOneNETClient(url, appkey, "");
            var req    = new GetTriggerRequest {
                TriggerID = "20631"
            };
            var rsp = client.Execute(req);

            Assert.IsFalse(rsp.IsError);
            Assert.IsNotNull(rsp.Data);
            Assert.IsNotNull(rsp.Data.Id);
            Console.WriteLine(rsp.Body);
        }
Exemplo n.º 14
0
        public void TestSearchTrigger()
        {
            var client = new DefaultOneNETClient(url, appkey, "");
            var req    = new SearchTriggerRequest {
                Title = "test add"
            };
            var rsp = client.Execute(req);

            Assert.IsFalse(rsp.IsError);
            Assert.IsNotNull(rsp.Data);
            Assert.IsTrue(rsp.Data.Total_Count > 0);
            Assert.IsNotNull(rsp.Data.Triggers);
        }
Exemplo n.º 15
0
        public void TestGetDataStream()
        {
            var client = new DefaultOneNETClient(url, appkey, "");
            var req    = new GetDataStreamRequest {
                DeviceID = "768719", DataStreamId = "x", Protocol = Scheme.HTTP
            };
            var resp = client.Execute(req);

            Assert.IsFalse(resp.IsError);
            Assert.AreEqual(0, resp.Errno);
            Assert.AreEqual("succ", resp.Error);
            Assert.IsNotNull(resp.Data);
            Console.WriteLine(resp.Body);
        }
Exemplo n.º 16
0
        public void TestGetCmdResponse()
        {
            var client = new DefaultOneNETClient(url, appkey, "");
            //todo
            var id  = "pendingtobetested";
            var req = new GetCmdRespRequest {
                CmdUuid = id
            };
            var rsp = client.Execute(req);

            Assert.IsFalse(rsp.IsError);
            Console.WriteLine("查询命令" + id + "的响应结果:");
            Console.WriteLine(rsp.Body);
        }
Exemplo n.º 17
0
        public void TestSendCmd()
        {
            var client = new DefaultOneNETClient(url, appkey, "");
            //todo:待测
            var req = new SendCmdRequest {
                DeviceID = 768719, Protocol = Scheme.HTTP, CmdContent = new { testpara = "test" }
            };
            var rsp = client.Execute(req);

            Assert.IsFalse(rsp.IsError);
            Console.WriteLine(rsp.Body);
            Assert.IsNotNull(rsp.Data);
            Assert.IsNotNull(rsp.Data.Cmd_uuid);
        }
Exemplo n.º 18
0
        public void TestRegister()
        {
            var client = new DefaultOneNETClient(url, "", "");
            var req    = new DeviceRegisterRequest {
                RegisterCode = register_code,
                NewDevice    = { SN = "yz123test", Title = "C#注册设备" },
                Protocol     = Scheme.HTTP
            };
            var resp = client.Execute(req);

            Assert.IsFalse(resp.IsError);
            Assert.IsNotNull(resp.Data);
            Assert.IsTrue(resp.Data.Device_Id > 0);
            Assert.IsNotNull(resp.Data.Key);
        }
Exemplo n.º 19
0
        public void TestUpdateTrigger()
        {
            var client = new DefaultOneNETClient(url, appkey, "");
            var data   = new Trigger
            {
                Title     = "test update trigger",
                Type      = TriggerType.LargerOrEqual.GetTriggerTypeString(),
                Threshold = 60
            };
            var rep = new UpdateTriggerRequest {
                TriggerID = "20631", Trigger = data
            };

            var rsp = client.Execute(rep);

            Assert.IsFalse(rsp.IsError);
        }
Exemplo n.º 20
0
        public void TestSearchDataPointWithCondition()
        {
            var client = new DefaultOneNETClient(url, appkey, "");
            //测试带参查询
            var req1 = new SearchDataPointRequest {
                DeviceID = "768719", Protocol = Scheme.HTTP
            };

            req1.DataStreamId = "loc,shake";
            var rsp1 = client.Execute(req1);

            Assert.IsFalse(rsp1.IsError);
            Assert.AreEqual(0, rsp1.Errno);
            Assert.AreEqual("succ", rsp1.Error);
            Assert.IsNotNull(rsp1.Data);
            Assert.AreEqual(2, rsp1.Data.Count);
            Console.WriteLine("带参查询结果:" + rsp1.Body);
        }
Exemplo n.º 21
0
        public void TestDeleteKey()
        {
            var client      = new DefaultOneNETClient(url, appkey, "");
            var permissions = new List <Permission>
            {
                new Permission
                {
                    Access_Methods = new[]
                    {
                        HttpRequestMethod.Get.GetMethodString(),
                HttpRequestMethod.Delete.GetMethodString()
                    },
                    Resources = new List <KeyResource>
                    {
                        new KeyResource {
                            Dev_Id = "768672"
                        }
                    }
                }
            };
            var data = new ApiKeyInfo
            {
                Title       = "test delete key",
                Permissions = permissions
            };
            var req = new NewKeyRequest {
                KeyInfo = data
            };

            var rsp = client.Execute(req);

            Console.WriteLine("key to delete has added:   " + rsp.Body);
            Assert.IsFalse(rsp.IsError);
            Assert.IsNotNull(rsp.Data);
            Assert.IsNotNull(rsp.Data.Key);

            var c1   = new DefaultOneNETClient(url, appkey, "");
            var req1 = new DeleteKeyRequest {
                KeyString = rsp.Data.Key
            };
            var rsp1 = c1.Execute(req1);

            Assert.IsFalse(rsp1.IsError);
        }
Exemplo n.º 22
0
        public void TestGetDevice()
        {
            var client = new DefaultOneNETClient(url, appkey, "");
            var req    = new GetDeviceRequest {
                DeviceID = "768672", Protocol = Scheme.HTTP
            };
            var resp = client.Execute(req);

            Assert.IsFalse(resp.IsError);
            Assert.AreEqual(0, resp.Errno);
            Assert.AreEqual("succ", resp.Error);
            Assert.IsNotNull(resp.Data);
            Assert.IsNotNull(resp.Data.Datastreams);
            var first = resp.Data.Datastreams.FirstOrDefault();

            Assert.IsNotNull(first);
            Assert.IsNotNull(first.Create_Time);
            Console.WriteLine(resp.Body);
        }
Exemplo n.º 23
0
        public void TestUpdateDevice()
        {
            var client = new DefaultOneNETClient(url, appkey, "");
            var device = new DeviceBasicInfo
            {
                Title = "测试修改C# SDK的返回结果",
                Desc  = "一次通过一次通过一次通过了吗?(update)",
                //Private = true,
                OnLine = true,
                //Tags = new[] { "测试", "sdk" },
                //Location = new LocationInfo(370000, 27.609997, 178.03403)
            };
            var req = new UpdateDeviceRequest {
                DeviceID = 776941, DeviceInfo = device
            };
            var resp = client.Execute(req);

            Assert.IsFalse(resp.IsError);
        }
Exemplo n.º 24
0
        public void TestAddKey()
        {
            var client      = new DefaultOneNETClient(url, appkey, "");
            var permissions = new List <Permission>
            {
                new Permission
                {
                    Access_Methods = new[]
                    {
                        HttpRequestMethod.Get.GetMethodString(),
                HttpRequestMethod.Post.GetMethodString()
                    },
                    Resources = new List <KeyResource>
                    {
                        new KeyResource {
                            Dev_Id = "776938"
                        },
                        new KeyResource {
                            Dev_Id = "776941"
                        }
                    }
                }
            };
            var data = new ApiKeyInfo
            {
                Title       = "test key from C#",
                Permissions = permissions
            };
            var req = new NewKeyRequest {
                KeyInfo = data
            };

            var rsp = client.Execute(req);

            Assert.IsFalse(rsp.IsError);
            Console.WriteLine(rsp.Body);
            Assert.IsNotNull(rsp.Data);
            Assert.IsNotNull(rsp.Data.Key);
        }
Exemplo n.º 25
0
        public void TestSearchDataPoint()
        {
            var client = new DefaultOneNETClient(url, appkey, "");
            //测试无参查询
            var req = new SearchDataPointRequest {
                DeviceID = "768719", Protocol = Scheme.HTTP
            };
            var rsp = client.Execute(req);

            Assert.IsFalse(rsp.IsError);
            Assert.AreEqual(0, rsp.Errno);
            Assert.AreEqual("succ", rsp.Error);
            Assert.IsNotNull(rsp.Data);
            Assert.IsTrue(rsp.Data.Count > 0);
            Assert.IsTrue(rsp.Data.Datastreams[0].Datapoints.Count > 0);
            var val = rsp.Data.Datastreams[0].Datapoints[0].GetValue();

            Assert.IsNotNull(val);
            Console.WriteLine("无参查询结果:" + rsp.Body);
            Console.WriteLine("------------------------------------------------");
            Console.WriteLine("无参查询转换得到的第一个datapoint参数:" + val);
        }
Exemplo n.º 26
0
        public void TestSearchLogs()
        {
            //添加数据点
            var client0 = new DefaultOneNETClient(url, appkey, "");
            var streams = new List <DataStreamSimple>
            {
                new DataStreamSimple
                {
                    ID         = "test log",
                    Datapoints = new List <DataPointSimple>
                    {
                        new DataPointSimple {
                            Value = 88.8, At = "2016-03-23T00:35:43"
                        }
                    }
                }
            };

            var data = new NewDataPointData {
                DataStreams = streams
            };
            var req0 = new NewDataPointRequest {
                DeviceID = 768719, Data = data
            };
            var rsp0 = client0.Execute(req0);

            Assert.IsFalse(rsp0.IsError);

            //查询日志
            var client = new DefaultOneNETClient(url, appkey, "");
            var req    = new SearchLogsRequest {
                DeviceID = "768719", Start = DateTime.Now.AddHours(-3)
            };
            var rsp = client.Execute(req);

            Assert.IsFalse(rsp.IsError);
            Assert.IsNotNull(rsp.Data);
            Console.WriteLine(rsp.Body);
        }
Exemplo n.º 27
0
        public void TestAddTrigger()
        {
            var c1   = new DefaultOneNETClient(url, appkey, "");
            var req1 = new NewTriggerRequest
            {
                Trigger = new NewTriggerInfo
                {
                    Title     = "test add trigger for some device in C#",
                    Url       = "http://www.baidu.com",
                    Type      = TriggerType.Frozen.GetTriggerTypeString(),
                    Threshold = 120,
                    Dev_Ids   = new[] { "768672", "776941" },
                    Ds_Id     = "AutoAddedFromPointsAdd"
                }
            };

            var rsp1 = c1.Execute(req1);

            Assert.IsFalse(rsp1.IsError);
            Assert.IsNotNull(rsp1.Data);
            Assert.IsNotNull(rsp1.Data.Trigger_Id);
            Console.WriteLine("The second new trigger id: " + rsp1.Data.Trigger_Id);
        }
Exemplo n.º 28
0
        public void TestAddNewDataPoint()
        {
            var client  = new DefaultOneNETClient(url, appkey, "");
            var streams = new List <DataStreamSimple>
            {
                new DataStreamSimple
                {
                    ID         = "每日出货量",
                    Datapoints = new List <DataPointSimple>
                    {
                        new DataPointSimple {
                            Value = 88.8, At = "2016-03-23T00:35:43"
                        }
                    }
                },
                new DataStreamSimple
                {
                    ID         = "每日出货地点",
                    Datapoints = new List <DataPointSimple> {
                        new DataPointSimple
                        {
                            Value = new { yyy = 86, zzz = 65, aaa = "blablablabla" }
                        }
                    }
                }
            };

            var data = new NewDataPointData {
                DataStreams = streams
            };
            var req = new NewDataPointRequest {
                DeviceID = 768719, Data = data
            };
            var rsp = client.Execute(req);

            Assert.IsFalse(rsp.IsError);
        }
Exemplo n.º 29
0
        public void TestUpdateKey()
        {
            var client      = new DefaultOneNETClient(url, appkey, "");
            var permissions = new List <Permission>
            {
                new Permission
                {
                    Access_Methods = new[]
                    {
                        HttpRequestMethod.Get.GetMethodString(),
                HttpRequestMethod.Post.GetMethodString(),
                HttpRequestMethod.Put.GetMethodString()
                    },
                    Resources = new List <KeyResource>
                    {
                        new KeyResource {
                            Dev_Id = "776938"
                        },
                        new KeyResource {
                            Dev_Id = "776941"
                        }
                    }
                }
            };
            var data = new ApiKeyInfo
            {
                Title       = "test update key from C#",
                Permissions = permissions
            };
            var req = new UpdateKeyRequest {
                KeyString = "jb3idOcNvc3Tv=WtoBLBLPYgVyg=", KeyInfo = data
            };
            var rsp = client.Execute(req);

            Assert.IsFalse(rsp.IsError);
        }