Ejemplo n.º 1
0
        public static SchemaInfo Schema(IBMWIoTP.ApiClient cli)
        {
            Console.WriteLine("Get all draft schima");
            Console.WriteLine(new System.Web.Script.Serialization.JavaScriptSerializer().Serialize(cli.GetAllDraftSchemas()));
            Console.WriteLine("===============================================================================");
            SchemaDraft sd = new SchemaDraft();

            sd.name       = "test";
            sd.schemaFile = "tempSchemaPi.json";
            Console.WriteLine("Add schima draft");
            SchemaInfo si = cli.AddDraftSchema(sd);

            Console.WriteLine(new System.Web.Script.Serialization.JavaScriptSerializer().Serialize(si));
            Console.WriteLine("===============================================================================");
            Console.WriteLine("Updated draft schema content");
            Console.WriteLine(new System.Web.Script.Serialization.JavaScriptSerializer().Serialize(cli.UpdateDraftSchemaContent(si.id, "tempSchema.json")));
            Console.WriteLine("===============================================================================");
            Console.WriteLine("Delete draft schema");
            cli.DeleteDraftSchema(cli.AddDraftSchema(sd).id);
            Console.WriteLine("===============================================================================");
            Console.WriteLine("Updated draft schema metadata");
            si.description = "new temp change";
            Console.WriteLine(new System.Web.Script.Serialization.JavaScriptSerializer().Serialize(cli.UpdateDraftSchemaMetadata(si)));
            Console.WriteLine("===============================================================================");
            Console.WriteLine("Get draft schima metadata");
            Console.WriteLine(new System.Web.Script.Serialization.JavaScriptSerializer().Serialize(cli.GetDraftSchemaMetadata(si.id)));
            Console.WriteLine("===============================================================================");
            Console.WriteLine("Get draft schima Content");
            Console.WriteLine(new System.Web.Script.Serialization.JavaScriptSerializer().Serialize(cli.GetDraftSchemaContent(si.id)));
            Console.WriteLine("===============================================================================");

            Console.WriteLine("Get All active schimas");
            SchemaCollection coll = cli.GetAllActiveSchemas();

            Console.WriteLine(new System.Web.Script.Serialization.JavaScriptSerializer().Serialize(coll));
            Console.WriteLine("===============================================================================");
            if (coll.results.Length > 0)
            {
                Console.WriteLine("Get active schimas");
                Console.WriteLine(new System.Web.Script.Serialization.JavaScriptSerializer().Serialize(cli.GetActiveSchemaMetadata(coll.results[0].id)));
                Console.WriteLine("===============================================================================");
                Console.WriteLine("Get active schima content ");
                Console.WriteLine(new System.Web.Script.Serialization.JavaScriptSerializer().Serialize(cli.GetActiveSchemaContent(coll.results[0].id)));
                Console.WriteLine("===============================================================================");
            }

            return(si);
        }
Ejemplo n.º 2
0
        public static void Main(string[] args)
        {
            try{
                Console.WriteLine("============================ IBM WatsonIoTP Sample ============================");
                Console.WriteLine("===============================================================================");

                Console.WriteLine("Check Out Following Samples For Information Management");
                Console.WriteLine("1.Basic scenario");
                Console.WriteLine("2.All API sample");
                Console.WriteLine("3.Any key to exit");
                Console.Write("Please enter your choice :");
                int val = int.Parse(Console.ReadLine());

                Console.WriteLine("===============================================================================");
                switch (val)
                {
                case 1: Init();
                    Console.WriteLine("Starting Basic scenario");
                    sampleSequence(cli);
                    break;

                case 2: Init();
                    Console.WriteLine("Starting All API sample");
                    SchemaInfo    sc   = Schema(cli);
                    EventTypeInfo info = EventType(cli, sc);
                    var           pi   = PhysicalInterfaces(cli, info);
                    SchemaDraft   sd   = new SchemaDraft();
                    sd.name       = "test";
                    sd.schemaFile = "tempSchemaLi.json";
                    SchemaInfo si = cli.AddDraftSchema(sd);
                    var        li = LogicalInterface(cli, si);
                    DeviceType(cli, li, pi);
                    Devices(cli, li);
                    break;

                default: break;
                }
                Console.Write("Press any key to continue . . . ");
                Console.ReadKey();
            }
            catch (Exception e) {
                Console.WriteLine("Err :" + e.Message);
            }
        }
Ejemplo n.º 3
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)));
        }