Exemple #1
0
        static void Main(string[] args)
        {
            // get and parse json configuration file
            string  jsonConfig        = File.ReadAllText(Directory.GetCurrentDirectory() + "/config.json");
            dynamic jsonValues        = JObject.Parse(jsonConfig);
            string  ingressServiceUrl = jsonValues.endpoint;
            string  producerToken     = jsonValues.producertoken;
            int     delayInterval     = jsonValues.interval;

            // create Http client to send requests to ingress service
            IngressClient client = new IngressClient(ingressServiceUrl, producerToken);

            // Use compression when sending data.
            client.UseCompression = jsonValues.compressionGzip;

            // Send Type messages (both Static and Dynamic)
            client.CreateTypes(new string[] { FirstStaticType.JsonSchema, SecondStaticType.JsonSchema });
            client.CreateTypes(new string[] { FirstDynamicType.JsonSchema, SecondDynamicType.JsonSchema, ThirdDynamicType.JsonSchema });

            // Send Container messages
            Container[] streams =
            {
                new Container()
                {
                    Id = "Container1", TypeId = "FirstDynamicType"
                },
                new Container()
                {
                    Id = "Container2", TypeId = "FirstDynamicType"
                },
                new Container()
                {
                    Id = "Container3", TypeId = "SecondDynamicType"
                },
                new Container()
                {
                    Id = "Container4", TypeId = "ThirdDynamicType"
                }
            };
            client.CreateContainers(streams);

            // Send Assets in Data messages
            AssetLinkValues <FirstStaticType> assetParent = new AssetLinkValues <FirstStaticType>()
            {
                typeid = "FirstStaticType",
                Values = new List <FirstStaticType> {
                    new FirstStaticType()
                    {
                        index = "Asset1", name = "Parent element", StringProperty = "Parent element attribute value"
                    }
                }
            };

            client.SendValuesAsync(new AssetLinkValues <FirstStaticType>[] { assetParent }).Wait();

            AssetLinkValues <SecondStaticType> assetChild = new AssetLinkValues <SecondStaticType>()
            {
                typeid = "SecondStaticType",
                Values = new List <SecondStaticType> {
                    new SecondStaticType()
                    {
                        index = "Asset2", name = "Child element", StringProperty = "Child element attribute value"
                    }
                }
            };

            client.SendValuesAsync(new AssetLinkValues <SecondStaticType>[] { assetChild }).Wait();

            // Send Asset-to-child-Asset Links
            AssetLinkValues <AFLink <StaticElement, StaticElement> > dataLink = new AssetLinkValues <AFLink <StaticElement, StaticElement> >()
            {
                typeid = "__Link",
                Values = new List <AFLink <StaticElement, StaticElement> >   {
                    new AFLink <StaticElement, StaticElement>()
                    {
                        source = new StaticElement()
                        {
                            typeid = "FirstStaticType", index = "_ROOT"
                        }, target = new StaticElement()
                        {
                            typeid = "FirstStaticType", index = "Asset1"
                        }
                    },
                    new AFLink <StaticElement, StaticElement>()
                    {
                        source = new StaticElement()
                        {
                            typeid = "FirstStaticType", index = "Asset1"
                        }, target = new StaticElement()
                        {
                            typeid = "SecondStaticType", index = "Asset2"
                        }
                    }
                }
            };

            client.SendValuesAsync(new AssetLinkValues <AFLink <StaticElement, StaticElement> >[] { dataLink, }).Wait();

            // Send Asset-to-Data (i.e. Dynamic Attribute) Links
            AssetLinkValues <AFLink <StaticElement, DynamicElement> > dynamic_dataLink = new AssetLinkValues <AFLink <StaticElement, DynamicElement> >()
            {
                typeid = "__Link",
                Values = new List <AFLink <StaticElement, DynamicElement> >   {
                    new AFLink <StaticElement, DynamicElement>()
                    {
                        source = new StaticElement()
                        {
                            typeid = "FirstStaticType", index = "Asset1"
                        }, target = new DynamicElement()
                        {
                            containerid = "Container1"
                        }
                    },
                    new AFLink <StaticElement, DynamicElement>()
                    {
                        source = new StaticElement()
                        {
                            typeid = "SecondStaticType", index = "Asset2"
                        }, target = new DynamicElement()
                        {
                            containerid = "Container2"
                        }
                    },
                    new AFLink <StaticElement, DynamicElement>()
                    {
                        source = new StaticElement()
                        {
                            typeid = "SecondStaticType", index = "Asset2"
                        }, target = new DynamicElement()
                        {
                            containerid = "Container3"
                        }
                    },
                    new AFLink <StaticElement, DynamicElement>()
                    {
                        source = new StaticElement()
                        {
                            typeid = "SecondStaticType", index = "Asset2"
                        }, target = new DynamicElement()
                        {
                            containerid = "Container4"
                        }
                    }
                }
            };

            client.SendValuesAsync(new AssetLinkValues <AFLink <StaticElement, DynamicElement> >[] { dynamic_dataLink }).Wait();

            // Setting handler for Ctrl+C to exit sending data loop
            bool continueRunning = true;

            Console.CancelKeyPress += (sender, eventArgs) =>
            {
                continueRunning = false;
                Console.Write("Stopping... ");
                eventArgs.Cancel = true;
            };

            // simulate realtime data
            Random rint    = new Random();
            Random rdouble = new Random();
            string string_boolean_value = "True";
            int    integer_enum_value   = 0;

            // Now send simulated relatime data continously
            while (continueRunning)
            {
                // Create set of integers to send to streams
                List <FirstDynamicType> values = new List <FirstDynamicType>();
                for (int i = 0; i < 3; i++)
                {
                    values.Add(new FirstDynamicType()
                    {
                        timestamp = DateTime.UtcNow, IntegerProperty = rint.Next()
                    });
                    Thread.Sleep(10);  // Offset the time-stamps by 10 ms
                }
                DataValues vals1 = new DataValues()
                {
                    ContainerId = streams[0].Id, Values = values
                };
                DataValues vals2 = new DataValues()
                {
                    ContainerId = streams[1].Id, Values = values
                };
                // Now send them
                client.SendValuesAsync(new DataValues[] { vals1, vals2 }).Wait();

                // Create set of SecondDynamicType values to send to streams
                List <SecondDynamicType> fnumbers = new List <SecondDynamicType>();
                for (int i = 0; i < 3; i++)
                {
                    string_boolean_value = (string_boolean_value == "True") ? "False" : "True";
                    fnumbers.Add(new SecondDynamicType()
                    {
                        timestamp = DateTime.UtcNow, NumberProperty1 = rdouble.NextDouble(), NumberProperty2 = rdouble.NextDouble(), StringEnum = string_boolean_value
                    });
                    Thread.Sleep(10);  // Offset the time-stamps by 10 ms
                }
                DataValues nums = new DataValues()
                {
                    ContainerId = streams[2].Id, Values = fnumbers
                };
                client.SendValuesAsync(new DataValues[] { nums }).Wait();


                // Create set of ThirdDynamicType values to send to streams
                List <ThirdDynamicType> enumvalues = new List <ThirdDynamicType>();
                for (int i = 0; i < 3; i++)
                {
                    integer_enum_value = (integer_enum_value == 0) ? 1 : 0;
                    enumvalues.Add(new ThirdDynamicType()
                    {
                        timestamp = DateTime.UtcNow, IntegerEnum = integer_enum_value
                    });
                    Thread.Sleep(10);  // Offset the time-stamps by 10 ms
                }
                DataValues bvals = new DataValues()
                {
                    ContainerId = streams[3].Id, Values = enumvalues
                };
                client.SendValuesAsync(new DataValues[] { bvals }).Wait();

                Thread.Sleep(delayInterval);
            }
        }
Exemple #2
0
        private static void DefineAssets(List <string> pIDs, Container[] containers)
        {
            //send asset for fleet
            AssetLinkValues <FleetStaticType> assetFleet = new AssetLinkValues <FleetStaticType>()
            {
                typeid = "Fleet",
                Values = new List <FleetStaticType> {
                    new FleetStaticType()
                    {
                        index = "SouthEastFleet", name = "SouthEastFleet"
                    }
                }
            };

            //client.SendValuesAsync(new AssetLinkValues<FleetStaticType>[] { assetFleet }).Wait();
            OMFIngressHelper.SendValuesToAllEndPointsAsync(new AssetLinkValues <FleetStaticType>[] { assetFleet }).Wait();

            //vehicle asset
            AssetLinkValues <VehicleStaticType> assetVehicle = new AssetLinkValues <VehicleStaticType>()
            {
                typeid = "Vehicle",
                Values = new List <VehicleStaticType> {
                    new VehicleStaticType()
                    {
                        index = configuration.VehicleName, name = configuration.VehicleName
                    }
                }
            };

            //client.SendValuesAsync(new AssetLinkValues<VehicleStaticType>[] { assetVehicle }).Wait();
            OMFIngressHelper.SendValuesToAllEndPointsAsync(new AssetLinkValues <VehicleStaticType>[] { assetVehicle }).Wait();

            //Measurement Assets
            List <ValueStaticType> values = new List <ValueStaticType>();

            foreach (string pid in pIDs)
            {
                ValueStaticType valueStatic = new ValueStaticType()
                {
                    index = GetMeasurement(pid).ToString(), name = GetMeasurement(pid).ToString(), PIDString = pid
                };
                values.Add(valueStatic);
            }
            AssetLinkValues <ValueStaticType> assetValue = new AssetLinkValues <ValueStaticType>()
            {
                typeid = "ValueStaticType",
                Values = values
            };

            //client.SendValuesAsync(new AssetLinkValues<ValueStaticType>[] { assetValue }).Wait();
            OMFIngressHelper.SendValuesToAllEndPointsAsync(new AssetLinkValues <ValueStaticType>[] { assetValue }).Wait();

            List <AFLink <StaticElement, StaticElement> > aflinks = new List <AFLink <StaticElement, StaticElement> >();
            AFLink <StaticElement, StaticElement>         aFLink  = new AFLink <StaticElement, StaticElement> {
                source = new StaticElement()
                {
                    typeid = nameof(FleetStaticType), index = "_ROOT"
                }, target = new StaticElement()
                {
                    typeid = nameof(FleetStaticType), index = "SouthEastFleet"
                }
            };

            aflinks.Add(aFLink);
            aFLink = new AFLink <StaticElement, StaticElement> {
                source = new StaticElement()
                {
                    typeid = nameof(FleetStaticType), index = "SouthEastFleet"
                }, target = new StaticElement()
                {
                    typeid = nameof(VehicleStaticType), index = configuration.VehicleName
                }
            };
            aflinks.Add(aFLink);
            foreach (var v in values)
            {
                aFLink = new AFLink <StaticElement, StaticElement> {
                    source = new StaticElement()
                    {
                        typeid = nameof(VehicleStaticType), index = configuration.VehicleName
                    }, target = new StaticElement()
                    {
                        typeid = nameof(ValueStaticType), index = v.index
                    }
                };
                aflinks.Add(aFLink);
            }
            //send asset parent-child links
            AssetLinkValues <AFLink <StaticElement, StaticElement> > assetLink = new AssetLinkValues <AFLink <StaticElement, StaticElement> >()
            {
                typeid = "__Link",
                Values = aflinks
            };

            //client.SendValuesAsync(new AssetLinkValues<AFLink<StaticElement, StaticElement>>[] { assetLink }).Wait();
            OMFIngressHelper.SendValuesToAllEndPointsAsync(new AssetLinkValues <AFLink <StaticElement, StaticElement> >[] { assetLink }).Wait();

            List <AFLink <StaticElement, DynamicElement> > dataLinks = new List <AFLink <StaticElement, DynamicElement> >();

            for (int i = 0; i < containers.Length; i++)
            {
                dataLinks.Add(new AFLink <StaticElement, DynamicElement>()
                {
                    source = new StaticElement()
                    {
                        typeid = nameof(ValueStaticType), index = values[i].index
                    }, target = new DynamicElement()
                    {
                        containerid = containers[i].Id
                    }
                });
            }
            AssetLinkValues <AFLink <StaticElement, DynamicElement> > dataLink = new AssetLinkValues <AFLink <StaticElement, DynamicElement> >()
            {
                typeid = "__Link",
                Values = dataLinks
            };

            //client.SendValuesAsync(new AssetLinkValues<AFLink<StaticElement, DynamicElement>>[] { dataLink }).Wait();
            OMFIngressHelper.SendValuesToAllEndPointsAsync(new AssetLinkValues <AFLink <StaticElement, DynamicElement> >[] { dataLink }).Wait();
        }
Exemple #3
0
        private static void Setup()
        {
            // Send Type messages (both Static and Dynamic)
            _client.CreateTypes(new string[] { ProviderType.JsonSchema, TrackType.JsonSchema });
            _client.CreateTypes(new string[] { StatType.JsonSchema });

            // Send Container messages
            List <Container> streams = new List <Container>();
            string           containerId;

            foreach (TrackStat stat in _stats)
            {
                containerId = String.Format("Container{0}", stat.Id);
                streams.Add(new Container {
                    Id = containerId, TypeId = "StatType"
                });
            }

            _client.CreateContainers(streams);

            // Send Assets in Data messages
            AssetLinkValues <ProviderType> assetParent = new AssetLinkValues <ProviderType>()
            {
                typeid = "ProviderType",
                Values = new List <ProviderType> {
                    new ProviderType()
                    {
                        Index = "Provider0", Name = "Twitter"
                    }
                }
            };

            _client.SendValuesAsync(new AssetLinkValues <ProviderType>[] { assetParent }).Wait();

            List <TrackType> tracks = new List <TrackType>();

            foreach (TrackStat stat in _stats)
            {
                tracks.Add(new TrackType {
                    Index = String.Format("Track{0}", stat.Id), Name = stat.TrackValue
                });
            }

            AssetLinkValues <TrackType> assetChild = new AssetLinkValues <TrackType>()
            {
                typeid = "TrackType",
                Values = tracks
            };

            _client.SendValuesAsync(new AssetLinkValues <TrackType>[] { assetChild }).Wait();

            // Send Asset-to-child-Asset Links
            List <AFLink <StaticElement, StaticElement> > list1 = new List <AFLink <StaticElement, StaticElement> >();

            list1.Add(new AFLink <StaticElement, StaticElement>()
            {
                source = new StaticElement()
                {
                    typeid = "ProviderType", index = "_ROOT"
                },
                target = new StaticElement()
                {
                    typeid = "ProviderType", index = "Provider0"
                }
            });

            foreach (TrackStat stat in _stats)
            {
                list1.Add(new AFLink <StaticElement, StaticElement>()
                {
                    source = new StaticElement()
                    {
                        typeid = "ProviderType", index = "Provider0"
                    },
                    target = new StaticElement()
                    {
                        typeid = "TrackType", index = String.Format("Track{0}", stat.Id)
                    }
                });
            }

            AssetLinkValues <AFLink <StaticElement, StaticElement> > dataLink = new AssetLinkValues <AFLink <StaticElement, StaticElement> >()
            {
                typeid = "__Link",
                Values = list1
            };

            _client.SendValuesAsync(new AssetLinkValues <AFLink <StaticElement, StaticElement> >[] { dataLink, }).Wait();

            // Send Asset-to-Data (i.e. Dynamic Attribute) Links
            List <AFLink <StaticElement, DynamicElement> > list2 = new List <AFLink <StaticElement, DynamicElement> >();

            foreach (TrackStat stat in _stats)
            {
                list2.Add(new AFLink <StaticElement, DynamicElement>()
                {
                    source = new StaticElement()
                    {
                        typeid = "TrackType", index = String.Format("Track{0}", stat.Id)
                    },
                    target = new DynamicElement()
                    {
                        containerid = String.Format("Container{0}", stat.Id)
                    }
                });
            }
            AssetLinkValues <AFLink <StaticElement, DynamicElement> > dynamic_dataLink = new AssetLinkValues <AFLink <StaticElement, DynamicElement> >()
            {
                typeid = "__Link",
                Values = list2
            };

            _client.SendValuesAsync(new AssetLinkValues <AFLink <StaticElement, DynamicElement> >[] { dynamic_dataLink }).Wait();
        }