Exemplo n.º 1
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)));
        }