Beispiel #1
0
        private static async Task omfAsync()
        {
            IConfigurationBuilder builder = new ConfigurationBuilder()
                                            .SetBasePath(Directory.GetCurrentDirectory())
                                            .AddJsonFile("appsettings.json");
            IConfiguration configuration = builder.Build();

            // ==== Client constants ====
            string tenantId          = configuration["TenantId"];
            string namespaceId       = configuration["NamespaceId"];
            string address           = configuration["Address"];
            string resource          = configuration["Resource"];
            string clientId          = configuration["ClientId"];
            string clientKey         = configuration["ClientKey"];
            string aadInstanceFormat = configuration["AADInstanceFormat"];

            QiSecurityHandler securityHandler =
                new QiSecurityHandler(resource, tenantId, aadInstanceFormat, clientId, clientKey);
            HttpClient httpClient = new HttpClient(securityHandler)
            {
                BaseAddress = new Uri(address)
            };

            _client = httpClient;
            //create type
            string JsonSchema =
                @"{""id"": ""SimpleType"",""type"": ""object"",
                ""classification"": ""dynamic"",
                ""properties"": {
                    ""Time"": { ""type"": ""string"", ""format"": ""date-time"", ""isindex"": true },
                    ""Value"": { ""type"": ""number"", ""format"": ""float64"" }
                }
            }";

            JsonSchema = string.Format("[{0}]", string.Join(",", new string[] { JsonSchema }));
            var     bytes = Encoding.UTF8.GetBytes(JsonSchema);
            Message type  = new Message();

            type.ProducerToken = SECURITY_TOKEN;
            type.MessageType   = MessageType.Type;
            type.Action        = MessageAction.Create;
            type.MessageFormat = MessageFormat.JSON;
            type.Body          = bytes;
            type.Version       = "1.0";
            HttpResponseMessage response = await httpClient.PostAsync($"api/omf", HttpContentFromMessage(type));

            response.EnsureSuccessStatusCode();

            //create container
            JsonSchema =
                @"{""Id"": ""TestStream1"",""TypeId"": ""SimpleType""}";
            JsonSchema = string.Format("[{0}]", string.Join(",", new string[] { JsonSchema }));
            bytes      = Encoding.UTF8.GetBytes(JsonSchema);
            Message contain = new Message();

            contain.ProducerToken = SECURITY_TOKEN;
            contain.MessageType   = MessageType.Container;
            contain.Action        = MessageAction.Create;
            contain.MessageFormat = MessageFormat.JSON;
            contain.Body          = bytes;
            contain.Version       = "1.0";
            response.EnsureSuccessStatusCode();
            //create data


            // send and read time series indefinitely
            while (true)
            {
                // Create our set of values to send to our streams
                List <SimpleType> values = new List <SimpleType>();
                for (int i = 0; i < 10; i++)
                {
                    values.Add(new SimpleType()
                    {
                        Time = DateTime.UtcNow, Value = i
                    });
                    Thread.Sleep(10);  // Offset the time-stamps by 10 ms
                }
                Console.Write("Sending Data\n");
                StreamValues vals1 = new StreamValues()
                {
                    ContainerId = "TestStream1", Values = values
                };

                // Now send them
                SendValuesAsync(new StreamValues[] { vals1 }).Wait();
                JsonSchema = JsonConvert.SerializeObject(values);

                // Now read from the Namespace
                Console.WriteLine("Getting data");
                response = await httpClient.GetAsync(
                    $"api/Tenants/{tenantId}/Namespaces/{namespaceId}/Streams/TestStream1/Data/GetLastValue");

                if (!response.IsSuccessStatusCode)
                {
                    throw new HttpRequestException(response.ToString());
                }

                Console.WriteLine(response.Content.ReadAsStringAsync().Result);
                Thread.Sleep(1000);
            }
        }
Beispiel #2
0
        static void Main(string[] args)
        {
            // Set this up in your app.config
            string ingressServiceUrl = ConfigurationManager.AppSettings["IngressServiceUrl"];
            string producerToken     = ConfigurationManager.AppSettings["ProducerToken"];

            IngressClient client = new IngressClient(ingressServiceUrl, producerToken);

            // Use compression when sending data.  For such small sample messages, compression doesn't
            // save us much space, but we're doing it here for demonstration sake.
            client.UseCompression = true;


            // 1) Send the Types message
            client.CreateTypes(new string[] { SimpleType.JsonSchema });
            client.CreateTypes(new string[] { ComplexType.JsonSchema });


            // 2) Send the Streams message
            StreamInfo stream1 = new StreamInfo()
            {
                StreamId = "TestStream1", TypeId = "SimpleType"
            };
            StreamInfo stream2 = new StreamInfo()
            {
                StreamId = "TestStream2", TypeId = "SimpleType"
            };
            StreamInfo stream3 = new StreamInfo()
            {
                StreamId = "TestStream3", TypeId = "ComplexType"
            };

            client.CreateStreams(new StreamInfo[] { stream1, stream2, stream3 });


            // 3) Send the Values messages
            StreamValues complexValue = new StreamValues()
            {
                StreamId = stream3.StreamId,
                Values   = new List <ComplexType> {
                    ComplexType.CreateSampleValue()
                }
            };

            client.SendValuesAsync(new StreamValues[] { complexValue }).Wait();

            // Here we loop indefinitely, sending 10 time series events to two streams every second.
            while (true)
            {
                // Create our set of values to send to our streams
                List <SimpleType> values = new List <SimpleType>();
                for (int i = 0; i < 10; i++)
                {
                    values.Add(new SimpleType()
                    {
                        Time = DateTime.UtcNow, Value = i
                    });
                    Thread.Sleep(10);  // Offset the time-stamps by 10 ms
                }

                StreamValues vals1 = new StreamValues()
                {
                    StreamId = stream1.StreamId, Values = values
                };
                StreamValues vals2 = new StreamValues()
                {
                    StreamId = stream2.StreamId, Values = values
                };

                // Now send them
                client.SendValuesAsync(new StreamValues[] { vals1, vals2 }).Wait();

                Thread.Sleep(1000);
            }
        }
Beispiel #3
0
        static void Main(string[] args)
        {
            IConfigurationBuilder builder = new ConfigurationBuilder()
                                            .SetBasePath(Directory.GetCurrentDirectory())
                                            .AddJsonFile("appsettings.json");
            IConfiguration configuration = builder.Build();

            // ==== Client constants ====
            string tenantId     = configuration["TenantId"];
            string namespaceId  = configuration["NamespaceId"];
            string address      = configuration["Address"];
            string clientId     = configuration["ClientId"];
            string clientSecret = configuration["ClientSecret"];

            IngressClient client = new IngressClient(address, tenantId, namespaceId, clientId, clientSecret);

            // Use compression when sending data.  For such small sample messages, compression doesn't
            // save us much space, but we're doing it here for demonstration sake.
            client.UseCompression = true;


            // 1) Send the Types message
            client.CreateTypes(new string[] { SimpleType.JsonSchema });
            client.CreateTypes(new string[] { ComplexType.JsonSchema });


            // 2) Send the Containers message
            ContainerInfo stream1 = new ContainerInfo()
            {
                Id = "TestStream1", TypeId = "SimpleType"
            };
            ContainerInfo stream2 = new ContainerInfo()
            {
                Id = "TestStream2", TypeId = "SimpleType"
            };
            ContainerInfo stream3 = new ContainerInfo()
            {
                Id = "TestStream3", TypeId = "ComplexType"
            };

            client.CreateContainers(new ContainerInfo[] { stream1, stream2, stream3 });


            // 3) Send the Values messages
            StreamValues complexValue = new StreamValues()
            {
                ContainerId = stream3.Id,
                Values      = new List <ComplexType> {
                    ComplexType.CreateSampleValue()
                }
            };

            client.SendValuesAsync(new StreamValues[] { complexValue }).Wait();

            // Here we loop indefinitely, sending 10 time series events to two streams every second.
            while (true)
            {
                // Create our set of values to send to our streams
                List <SimpleType> values = new List <SimpleType>();
                for (int i = 0; i < 10; i++)
                {
                    values.Add(new SimpleType()
                    {
                        Time = DateTime.UtcNow, Value = i
                    });
                    Thread.Sleep(10);  // Offset the time-stamps by 10 ms
                }

                StreamValues vals1 = new StreamValues()
                {
                    ContainerId = stream1.Id, Values = values
                };
                StreamValues vals2 = new StreamValues()
                {
                    ContainerId = stream2.Id, Values = values
                };

                // Now send them
                client.SendValuesAsync(new StreamValues[] { vals1, vals2 }).Wait();

                Thread.Sleep(1000);
            }
        }