示例#1
0
        public static void Main(string[] args)
        {
            string apiKey            = "";
            string authToken         = "";
            string managedDeviceType = "demotest";
            string managedDeviceId   = "1234";

            if (string.IsNullOrEmpty(apiKey) || string.IsNullOrEmpty(authToken))
            {
                Console.Write("please Enter API Key : ");
                apiKey = Console.ReadLine();
                Console.WriteLine();
                Console.Write("Please Enter Auth Token : ");
                authToken = Console.ReadLine();
            }
            IBMWIoTP.ApiClient client = new IBMWIoTP.ApiClient(apiKey, authToken);
            client.Timeout = 5000;
            try {
                //Organization

                Console.WriteLine("get org info");
                Console.WriteLine(new System.Web.Script.Serialization.JavaScriptSerializer().Serialize(client.GetOrganizationDetail()));

                //Bulk Operations

                Console.WriteLine("get all device list");
                Console.WriteLine(new System.Web.Script.Serialization.JavaScriptSerializer().Serialize(client.GetAllDevices()));

                IBMWIoTP.RegisterDevicesInfo [] bulk = new IBMWIoTP.RegisterDevicesInfo[1];
                var info = new IBMWIoTP.RegisterDevicesInfo();
                info.deviceId   = "123qwe";
                info.typeId     = managedDeviceType;
                info.authToken  = "1qaz2wsx3edc4rfv";
                info.deviceInfo = new IBMWIoTP.DeviceInfo();
                info.location   = new IBMWIoTP.LocationInfo();
                info.metadata   = new {};
                bulk[0]         = info;

                Console.WriteLine("get Bulk reg ");
                Console.WriteLine(new System.Web.Script.Serialization.JavaScriptSerializer().Serialize(client.RegisterMultipleDevices(bulk)));

                IBMWIoTP.DeviceListElement [] removeBulk = new IBMWIoTP.DeviceListElement[1];
                var del = new IBMWIoTP.DeviceListElement();
                del.deviceId = "123qwe";
                del.typeId   = managedDeviceType;

                removeBulk[0] = del;
                Console.WriteLine("get Bulk remove ");
                Console.WriteLine(new System.Web.Script.Serialization.JavaScriptSerializer().Serialize(client.DeleteMultipleDevices(removeBulk)));

                //Device Types

                Console.WriteLine("GetAllDeviceTypes ");
                Console.WriteLine(new System.Web.Script.Serialization.JavaScriptSerializer().Serialize(client.GetAllDeviceTypes()));

                DeviceTypeInfo devty = new DeviceTypeInfo();
                devty.classId    = "Gateway";
                devty.deviceInfo = new DeviceInfo();
                devty.id         = "gatewaypi";
                devty.metadata   = new {};
                Console.WriteLine("RegisterDeviceType");
                Console.WriteLine(new System.Web.Script.Serialization.JavaScriptSerializer().Serialize(client.RegisterDeviceType(devty)));

                Console.WriteLine("UpdateDeviceType ");
                var u = new IBMWIoTP.DeviceTypeInfoUpdate();
                u.description = "test";
                Console.WriteLine(new System.Web.Script.Serialization.JavaScriptSerializer().Serialize(client.UpdateDeviceType("gatewaypi", u)));

                Console.WriteLine("GetDeviceType ");
                Console.WriteLine(new System.Web.Script.Serialization.JavaScriptSerializer().Serialize(client.GetDeviceType("gatewaypi")));

                //Devices

                Console.WriteLine("ListDevices");
                Console.WriteLine(new System.Web.Script.Serialization.JavaScriptSerializer().Serialize(client.ListDevices(managedDeviceType)));

                string newDeviceId = DateTime.Now.ToString("yyyyMMddHHmmssffff");
                var    newdevice   = new RegisterSingleDevicesInfo();
                newdevice.deviceId   = newDeviceId;
                newdevice.authToken  = "testtest";
                newdevice.deviceInfo = new IBMWIoTP.DeviceInfo();
                newdevice.location   = new IBMWIoTP.LocationInfo();
                newdevice.metadata   = new {};
                Console.WriteLine("RegisterDevice");
                Console.WriteLine(new System.Web.Script.Serialization.JavaScriptSerializer().Serialize(client.RegisterDevice("gatewaypi", newdevice)));

                var update = new IBMWIoTP.UpdateDevicesInfo();
                update.deviceInfo = new IBMWIoTP.DeviceInfo();
                Console.WriteLine("UpdateDeviceInfo");
                Console.WriteLine(new System.Web.Script.Serialization.JavaScriptSerializer().Serialize(client.UpdateDeviceInfo("gatewaypi", newDeviceId, update)));

                Console.WriteLine("GetDeviceInfo");
                Console.WriteLine(new System.Web.Script.Serialization.JavaScriptSerializer().Serialize(client.GetDeviceInfo("gatewaypi", newDeviceId)));

                Console.WriteLine("GetGatewayConnectedDevice");
                Console.WriteLine(new System.Web.Script.Serialization.JavaScriptSerializer().Serialize(client.GetGatewayConnectedDevice("gatewaypi", newDeviceId)));

                Console.WriteLine("GetDeviceLocationInfo");
                Console.WriteLine(new System.Web.Script.Serialization.JavaScriptSerializer().Serialize(client.GetDeviceLocationInfo("gatewaypi", newDeviceId)));

                Console.WriteLine("UpdateDeviceLocationInfo");
                var loc = new IBMWIoTP.LocationInfo();
                loc.accuracy         = 1;
                loc.measuredDateTime = DateTime.Now.ToString("o");
                Console.WriteLine(new System.Web.Script.Serialization.JavaScriptSerializer().Serialize(client.UpdateDeviceLocationInfo("gatewaypi", newDeviceId, loc)));

                Console.WriteLine("GetDeviceManagementInfo");
                Console.WriteLine(new System.Web.Script.Serialization.JavaScriptSerializer().Serialize(client.GetDeviceManagementInfo(managedDeviceType, managedDeviceId)));

                Console.WriteLine("UnregisterDevice");
                client.UnregisterDevice("gatewaypi", newDeviceId);


                Console.WriteLine("DeleteDeviceType ");
                client.DeleteDeviceType("gatewaypi");


                Console.WriteLine("AddDeviceDiagLogs");
                var log = new IBMWIoTP.LogInfo();
                log.message  = "test";
                log.severity = 1;

                client.AddDeviceDiagLogs(managedDeviceType, managedDeviceId, log);

                Console.WriteLine("GetAllDiagnosticLogs");
                var logResult = client.GetAllDiagnosticLogs(managedDeviceType, managedDeviceId);
                Console.WriteLine(new System.Web.Script.Serialization.JavaScriptSerializer().Serialize(logResult));



                Console.WriteLine("GetDiagnosticLog");
                Console.WriteLine(new System.Web.Script.Serialization.JavaScriptSerializer().Serialize(client.GetDiagnosticLog(managedDeviceType, managedDeviceId, logResult[0]["id"])));

                Console.WriteLine("DeleteDiagnosticLog");
                Console.WriteLine(new System.Web.Script.Serialization.JavaScriptSerializer().Serialize(client.DeleteDiagnosticLog(managedDeviceType, managedDeviceId, logResult[0]["id"])));

                Console.WriteLine("ClearAllDiagnosticLogs");
                Console.WriteLine(new System.Web.Script.Serialization.JavaScriptSerializer().Serialize(client.ClearAllDiagnosticLogs(managedDeviceType, managedDeviceId)));



                Console.WriteLine("AddErrorCode");
                var err = new IBMWIoTP.ErrorCodeInfo();
                err.errorCode = 0;
                err.timestamp = "";
                Console.WriteLine(new System.Web.Script.Serialization.JavaScriptSerializer().Serialize(client.AddErrorCode(managedDeviceType, managedDeviceId, err)));

                Console.WriteLine("GetDeviceErrorCodes");
                Console.WriteLine(new System.Web.Script.Serialization.JavaScriptSerializer().Serialize(client.GetDeviceErrorCodes(managedDeviceType, managedDeviceId)));

                Console.WriteLine("ClearDeviceErrorCodes");
                Console.WriteLine(new System.Web.Script.Serialization.JavaScriptSerializer().Serialize(client.ClearDeviceErrorCodes(managedDeviceType, managedDeviceId)));

                Console.WriteLine("Problem ");
                Console.WriteLine(new System.Web.Script.Serialization.JavaScriptSerializer().Serialize(client.GetDeviceConnectionLogs(managedDeviceType, managedDeviceId)));

                Console.WriteLine("data usage ");
                Console.WriteLine(new System.Web.Script.Serialization.JavaScriptSerializer().Serialize(client.GetDataUsage("2016", "2016", false)));


                Console.WriteLine("Service Status");
                Console.WriteLine(new System.Web.Script.Serialization.JavaScriptSerializer().Serialize(client.GetServiceStatus()));

                Console.WriteLine("lastEvents");
                Console.WriteLine(new System.Web.Script.Serialization.JavaScriptSerializer().Serialize(client.GetLastEvents(managedDeviceType, managedDeviceId)));

                Console.WriteLine("lastEvents of type");
                Console.WriteLine(new System.Web.Script.Serialization.JavaScriptSerializer().Serialize(client.GetLastEventsByEventType(managedDeviceType, managedDeviceId, "test")));


                Console.WriteLine("GetAllDeviceManagementRequests");
                Console.WriteLine(new System.Web.Script.Serialization.JavaScriptSerializer().Serialize(client.GetAllDeviceManagementRequests()));

                Console.WriteLine("InitiateDeviceManagementRequest");
                IBMWIoTP.DeviceMgmtparameter [] param = new IBMWIoTP.DeviceMgmtparameter[1];
                IBMWIoTP.DeviceMgmtparameter    p     = new IBMWIoTP.DeviceMgmtparameter();
                p.name   = "rebootAfter";
                p.value  = "100";
                param[0] = p;
                IBMWIoTP.DeviceListElement [] deviceList = new IBMWIoTP.DeviceListElement[1];
                IBMWIoTP.DeviceListElement    ele        = new IBMWIoTP.DeviceListElement();
                ele.typeId    = managedDeviceType;
                ele.deviceId  = managedDeviceId;
                deviceList[0] = ele;
                var response = client.InitiateDeviceManagementRequest("device/reboot", param, deviceList);             //new System.Web.Script.Serialization.JavaScriptSerializer().Deserialize<dynamic>(jsonResponse);
                Console.WriteLine(new System.Web.Script.Serialization.JavaScriptSerializer().Serialize(response));
                string id = response["reqId"];

                Console.WriteLine("GetDeviceManagementRequest");
                Console.WriteLine(new System.Web.Script.Serialization.JavaScriptSerializer().Serialize(client.GetDeviceManagementRequest(id)));

                Console.WriteLine("GetDeviceManagementRequestStatus");
                Console.WriteLine(new System.Web.Script.Serialization.JavaScriptSerializer().Serialize(client.GetDeviceManagementRequestStatus(id)));

                Console.WriteLine("GetDeviceManagementRequestStatus");
                Console.WriteLine(new System.Web.Script.Serialization.JavaScriptSerializer().Serialize(client.GetDeviceManagementRequestStatus(id, ele.typeId, ele.deviceId)));

                Console.WriteLine("DeleteDeviceManagementRequest");
                Console.WriteLine(new System.Web.Script.Serialization.JavaScriptSerializer().Serialize(client.DeleteDeviceManagementRequest(id)));

                Console.WriteLine("weather");
                Console.WriteLine(new System.Web.Script.Serialization.JavaScriptSerializer().Serialize(client.GetDeviceLocationWeather(managedDeviceType, managedDeviceId)));
            } catch (Exception ex) {
                Console.WriteLine(ex.Message);
            }
            Console.Write("Press any key to exit . . . ");
            Console.ReadKey();
        }
示例#2
0
        public static void DeviceType(IBMWIoTP.ApiClient cli, LogicalInterfaceInfo li, PhysicalInterfacesInfo pi)
        {
            Console.WriteLine("===============================================================================");
            Console.WriteLine("Get all device type");
            var deviceTypes = cli.GetAllDeviceTypes();

            Console.WriteLine(new System.Web.Script.Serialization.JavaScriptSerializer().Serialize(deviceTypes));
            Console.WriteLine("===============================================================================");
            Console.WriteLine("operate on draft device type");
            OperationInfo work = new OperationInfo(OperationInfo.Validate);

            Console.WriteLine(new System.Web.Script.Serialization.JavaScriptSerializer().Serialize(cli.OperateDraftDeviceType(deviceType, work)));
            Console.WriteLine("===============================================================================");
            Console.WriteLine("Get all draft Logical Interface associated device type");
            Console.WriteLine(new System.Web.Script.Serialization.JavaScriptSerializer().Serialize(cli.GetAllDraftDeviceTypeLI(deviceType)));
            Console.WriteLine("===============================================================================");
            Console.WriteLine("Assocate Logical Interface with draft device type");
            Console.WriteLine(new System.Web.Script.Serialization.JavaScriptSerializer().Serialize(cli.AddDraftDeviceTypeLI(deviceType, li)));
            Console.WriteLine("===============================================================================");
            Console.WriteLine("Get all draft Device type mapping");
            MappingInfo[] info = cli.GetAllDraftDeviceTypeMapping(deviceType);
            Console.WriteLine(new System.Web.Script.Serialization.JavaScriptSerializer().Serialize(info));
            Console.WriteLine("===============================================================================");
            Console.WriteLine("Add draft Device type mapping");
            MappingDraft liMappingDraft = new MappingDraft();

            liMappingDraft.notificationStrategy = "on-every-event";
            liMappingDraft.propertyMappings     = new {
                test = new {
                    temperature = "$event.temp"
                }
            };
            liMappingDraft.logicalInterfaceId = li.id;
            Console.WriteLine(new System.Web.Script.Serialization.JavaScriptSerializer().Serialize(cli.AddDraftDeviceTypeMapping(deviceType, liMappingDraft)));
            Console.WriteLine("===============================================================================");
            Console.WriteLine("Get  draft Device type mapping with LI id");
            Console.WriteLine(new System.Web.Script.Serialization.JavaScriptSerializer().Serialize(cli.GetDraftDeviceTypeMapping(deviceType, li.id)));
            Console.WriteLine("===============================================================================");
            Console.WriteLine("Update  draft Device type mapping with LI id");
            Console.WriteLine(new System.Web.Script.Serialization.JavaScriptSerializer().Serialize(cli.UpdatedDraftDeviceTypeMapping(deviceType, liMappingDraft)));

            Console.WriteLine("===============================================================================");
            Console.WriteLine("Add draft Device type To PI ");
            Console.WriteLine(new System.Web.Script.Serialization.JavaScriptSerializer().Serialize(cli.AddDraftDeviceTypePI(deviceType, pi)));
            Console.WriteLine("===============================================================================");
            Console.WriteLine("Get draft Device type To PI ");
            Console.WriteLine(new System.Web.Script.Serialization.JavaScriptSerializer().Serialize(cli.GetDraftDeviceTypePI(deviceType)));


            Console.WriteLine("===============================================================================");
            Console.WriteLine("Delete draft Device type mapping");
            cli.DeleteDraftDeviceTypeMapping(deviceType, li.id);
            Console.WriteLine("===============================================================================");
            Console.WriteLine("Delete draft Device type To PI ");
            cli.DeleteDraftDeviceTypePI(deviceType);
            Console.WriteLine("===============================================================================");
            Console.WriteLine("Operate on Device type");
            Console.WriteLine("===============================================================================");
            Console.WriteLine("Get all active Device type Logical interface");
            LogicalInterfaceInfo[] coll = cli.GetAllActiveDeviceTypeLI(deviceType);
            Console.WriteLine(new System.Web.Script.Serialization.JavaScriptSerializer().Serialize(coll));
            Console.WriteLine("===============================================================================");
            Console.WriteLine("Get all active Device type mapping");
            Console.WriteLine(new System.Web.Script.Serialization.JavaScriptSerializer().Serialize(cli.GetAllActiveDeviceTypeMappings(deviceType)));
            Console.WriteLine("===============================================================================");
            Console.WriteLine("Get active Device type Physical interface");
            Console.WriteLine(new System.Web.Script.Serialization.JavaScriptSerializer().Serialize(cli.GetActiveDeviceTypePI(deviceType)));
            Console.WriteLine("===============================================================================");
            if (coll.Length > 0)
            {
                Console.WriteLine("Get all on Device type mapping");
                Console.WriteLine(new System.Web.Script.Serialization.JavaScriptSerializer().Serialize(cli.GetActiveDeviceTypeMappingLI(deviceType, coll[0].id)));
                Console.WriteLine("===============================================================================");
                Console.WriteLine("Get Device Type associated with logical interface id");
                Console.WriteLine(new System.Web.Script.Serialization.JavaScriptSerializer().Serialize(cli.GetAllDraftDeviceType("", coll[0].id)));
                Console.WriteLine("===============================================================================");
            }
            OperationInfo action = new OperationInfo(OperationInfo.Deactivate);

            Console.WriteLine(new System.Web.Script.Serialization.JavaScriptSerializer().Serialize(cli.OperateDeviceType(deviceType, action)));
        }