示例#1
0
        public static PhysicalInterfacesInfo PhysicalInterfaces(IBMWIoTP.ApiClient cli, EventTypeInfo evnt)
        {
            Console.WriteLine("Physical Interfaces sample request");
            Console.WriteLine("Add Draft PhysicalInterfaces");
            PhysicalInterfaceDraft draft = new PhysicalInterfaceDraft();

            draft.name        = "TempPI";
            draft.description = "new PhysicalInterfaces for temp";
            PhysicalInterfacesInfo newPI = cli.AddDraftPhysicalInterfaces(draft);

            Console.WriteLine(new System.Web.Script.Serialization.JavaScriptSerializer().Serialize(newPI));
            Console.WriteLine("===============================================================================");
            Console.WriteLine("Get all Draft PhysicalInterfaces");
            Console.WriteLine(new System.Web.Script.Serialization.JavaScriptSerializer().Serialize(cli.GetAllDraftPhysicalInterfaces()));
            Console.WriteLine("===============================================================================");
            Console.WriteLine("Update Draft PhysicalInterfaces");
            newPI.description = "changed to new discription";
            Console.WriteLine(new System.Web.Script.Serialization.JavaScriptSerializer().Serialize(cli.UpdateDraftPhysicalInterfaces(newPI)));
            Console.WriteLine("===============================================================================");
            Console.WriteLine("Get Draft PhysicalInterfaces");
            Console.WriteLine(new System.Web.Script.Serialization.JavaScriptSerializer().Serialize(cli.GetDraftPhysicalInterfaces(newPI.id)));
            Console.WriteLine("===============================================================================");
            Console.WriteLine("Map PhysicalInterfaces EventType");
            EventTypeBind bind = new EventTypeBind();

            bind.eventTypeId = evnt.id;
            bind.eventId     = "temperature";
            Console.WriteLine(new System.Web.Script.Serialization.JavaScriptSerializer().Serialize(cli.MapDraftPhysicalInterfacesEvent(newPI.id, bind)));
            Console.WriteLine("===============================================================================");
            Console.WriteLine("Get all Mapping PhysicalInterfaces EventType");
            Console.WriteLine(new System.Web.Script.Serialization.JavaScriptSerializer().Serialize(cli.GetAllDraftPhysicalInterfacesMappedEvents(newPI.id)));
            Console.WriteLine("===============================================================================");
            Console.WriteLine("Delete Mapping PhysicalInterfaces EventType");
            cli.DeleteDraftPhysicalInterfacesMappedEvents(newPI.id, bind.eventId);
            Console.WriteLine("===============================================================================");
            Console.WriteLine("Get All active PhysicalInterfaces");
            PhysicalInterfacesCollection coll = cli.GetAllActivePhysicalInterfaces();

            Console.WriteLine(new System.Web.Script.Serialization.JavaScriptSerializer().Serialize(coll));
            Console.WriteLine("===============================================================================");
            if (coll.results.Count > 0)
            {
                Console.WriteLine("Get active PhysicalInterfaces");
                Console.WriteLine(new System.Web.Script.Serialization.JavaScriptSerializer().Serialize(cli.GetActivePhysicalInterfaces(coll.results[0].id)));
                Console.WriteLine("===============================================================================");
                Console.WriteLine("Get active PhysicalInterfaces Events ");
                Console.WriteLine(new System.Web.Script.Serialization.JavaScriptSerializer().Serialize(cli.GetActivePhysicalInterfacesEvents(coll.results[0].id)));
                Console.WriteLine("===============================================================================");
            }
            return(newPI);
        }
示例#2
0
        public static void sampleSequence(IBMWIoTP.ApiClient cli)
        {
            SchemaDraft sd = new SchemaDraft();

            sd.name       = "tempEventSchema";
            sd.schemaFile = "tempSchemaPi.json";
            Console.WriteLine("Create a draft event schema resource for your event type");
            SchemaInfo sc = cli.AddDraftSchema(sd);

            Console.WriteLine(new System.Web.Script.Serialization.JavaScriptSerializer().Serialize(sc));
            Console.WriteLine("===============================================================================");
            Console.WriteLine("Create a draft event type that references the event schema");
            EventTypeDraft draft = new EventTypeDraft();

            draft.name        = "test";
            draft.description = "eventType for temperature";
            draft.schemaId    = sc.id;
            EventTypeInfo info = cli.AddDraftEventType(draft);

            Console.WriteLine(new System.Web.Script.Serialization.JavaScriptSerializer().Serialize(info));
            Console.WriteLine("===============================================================================");
            Console.WriteLine("Create a draft physical interface");
            PhysicalInterfaceDraft draftPI = new PhysicalInterfaceDraft();

            draftPI.name        = "TempPI";
            draftPI.description = "new PhysicalInterfaces for temp";
            PhysicalInterfacesInfo newPI = cli.AddDraftPhysicalInterfaces(draftPI);

            Console.WriteLine(new System.Web.Script.Serialization.JavaScriptSerializer().Serialize(newPI));
            Console.WriteLine("===============================================================================");
            Console.WriteLine("Add the event type to the draft physical interface");
            EventTypeBind bind = new EventTypeBind();

            bind.eventId     = deviceEvent;
            bind.eventTypeId = info.id;
            EventTypeBind bindResponse = cli.MapDraftPhysicalInterfacesEvent(newPI.id, bind);

            Console.WriteLine(new System.Web.Script.Serialization.JavaScriptSerializer().Serialize(bindResponse));
            Console.WriteLine("===============================================================================");
            Console.WriteLine("Update the draft device type to connect the draft physical interface");
            PhysicalInterfacesInfo updatedPI = cli.AddDraftDeviceTypePI(deviceType, newPI);

            Console.WriteLine("===============================================================================");
            Console.WriteLine("Create a draft logical interface schema resource");
            SchemaDraft sdLI = new SchemaDraft();

            sdLI.name       = "temperatureEventSchema";
            sdLI.schemaFile = "tempSchemaLi.json";
            SchemaInfo schemaForLI = cli.AddDraftSchema(sdLI);

            Console.WriteLine(new System.Web.Script.Serialization.JavaScriptSerializer().Serialize(schemaForLI));
            Console.WriteLine("===============================================================================");
            Console.WriteLine("Create a draft logical interface that references a draft logical interface schema");
            LogicalInterfaceDraft draftLI = new LogicalInterfaceDraft();

            draftLI.name     = "environment sensor interface";
            draftLI.schemaId = schemaForLI.id;
            LogicalInterfaceInfo newLI = cli.AddDraftLogicalInterfaces(draftLI);

            Console.WriteLine(new System.Web.Script.Serialization.JavaScriptSerializer().Serialize(newLI));
            Console.WriteLine("===============================================================================");
            Console.WriteLine("Add the draft logical interface to a device type");
            LogicalInterfaceInfo mappedLI = cli.AddDraftDeviceTypeLI(deviceType, newLI);

            Console.WriteLine(new System.Web.Script.Serialization.JavaScriptSerializer().Serialize(mappedLI));
            Console.WriteLine("===============================================================================");
            Console.WriteLine("Define mappings to map properties in the inbound event to properties in the logical interface");
            MappingDraft liMappingDraft = new MappingDraft();

            liMappingDraft.notificationStrategy = "on-every-event";
            liMappingDraft.propertyMappings     = new {
                test = new {
                    temperature = "$event.temp"
                }
            };
            liMappingDraft.logicalInterfaceId = mappedLI.id;
            MappingInfo mappedLiInfo = cli.AddDraftDeviceTypeMapping(deviceType, liMappingDraft);

            Console.WriteLine(new System.Web.Script.Serialization.JavaScriptSerializer().Serialize(mappedLiInfo));
            Console.WriteLine("===============================================================================");
            Console.WriteLine("Validate and activate the configuration");
            OperationInfo activate = new OperationInfo(OperationInfo.Activate);
            var           responce = cli.OperateDraftDeviceType(deviceType, activate);

            Console.WriteLine(new System.Web.Script.Serialization.JavaScriptSerializer().Serialize(responce));
            Console.WriteLine("===============================================================================");
            Console.WriteLine(new System.Web.Script.Serialization.JavaScriptSerializer().Serialize(cli.GetCurrentDeviceState(deviceType, "1qaz2wsx", mappedLI.id)));
        }
示例#3
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)));
        }