Exemplo n.º 1
0
        public async Task BasicCollection()
        {
            FluentOlapConfiguration.ServiceDefinitions = new ServiceDefinitions
            {
                ["PostsService"] = new HttpService("https://jsonplaceholder.typicode.com/posts/{PostId}")
            };

            PostAnalyzer analyzer = new PostAnalyzer();

            analyzer.ServiceName = "PostsService";

            PopulationResultCollection rs = await DataCollector.CollectData(analyzer, new HttpServiceOptions
            {
                PrefixKey  = "post",
                Parameters = new
                {
                    PostId = 1
                }
            });

            PopulationResult data = rs.Dequeue();

            foreach (string key in data.Keys)
            {
                Assert.IsTrue(analyzer.TypeMap.Keys.Contains(key));
            }
        }
Exemplo n.º 2
0
        static void Main(string[] args)
        {
            var collector = new DataCollector();

            var consolePresenter         = new ConsolePresenter();
            var filePresenter            = new FilePresenter(@"d:\temp\persons.txt");
            var shoutingConsolePresenter = new ShoutingConsolePresenter();

            var multiplePresenter = new MultiplePresenter(new List <IPresenter> {
                shoutingConsolePresenter, consolePresenter, filePresenter
            });

            while (true)
            {
                Console.Write("Enter your name: ");
                var name = Console.ReadLine();

                Console.Write("Enter your age: ");
                var age = int.Parse(Console.ReadLine());

                collector.CollectData(name, age);

                Console.Write("Add more? (y/n) ");
                var answer = Console.ReadKey();
                Console.WriteLine();

                if (answer.Key == ConsoleKey.N)
                {
                    break;
                }
            }
            collector.PresentData(multiplePresenter);

            Console.ReadLine();
        }
Exemplo n.º 3
0
        public void ValidateCollectDataNullDataSetName()
        {
            //Arrange
            DataCollector dataCollector = new DataCollector(new UaPubSubDataStore());

            //Assert
            Assert.Throws <ArgumentException>(() => dataCollector.CollectData(null), "The data collect does not throw exception when null parameter.");
        }
Exemplo n.º 4
0
        public void ValidateCollectDataUnknownDataSetName()
        {
            //Arrange
            DataCollector dataCollector = new DataCollector(new UaPubSubDataStore());
            //Act
            DataSet collectedDataSet = dataCollector.CollectData("");

            //Assert
            Assert.IsNull(collectedDataSet, "The data collect returns data for unknown DataSetName.");
        }
        public void ValidateAddPublishedDataSet()
        {
            //Arrange
            DataCollector dataCollector       = new DataCollector(new UaPubSubDataStore());
            var           pubSubConfiguration = UaPubSubConfigurationHelper.LoadConfiguration(ConfigurationFileName);

            //Act
            dataCollector.AddPublishedDataSet(pubSubConfiguration.PublishedDataSets[0]);
            DataSet collectedDataSet = dataCollector.CollectData(pubSubConfiguration.PublishedDataSets[0].Name);

            //Assert
            Assert.IsNotNull(collectedDataSet,
                             "Cannot collect data therefore the '{0}' publishedDataSet was not registered correctly.", pubSubConfiguration.PublishedDataSets[0].Name);
        }
Exemplo n.º 6
0
        public async Task <PopulationResult> PopulateAsync <TInput>(TInput input)
            where TInput : IServiceInput
        {
            if (MessageMap == null)
            {
                MessageMap = new MessageProperties("NONE", "Id");
            }

            PopulationResultCollection rs = await DataCollector.CollectData(this, input);

            PopulationResult merged = MergeIntoAggregate(rs);

            return(merged);
        }
Exemplo n.º 7
0
        public void ValidateRemovePublishedDataSet()
        {
            //Arrange
            DataCollector            dataCollector    = new DataCollector(new UaPubSubDataStore());
            PublishedDataSetDataType publishedDataSet = new PublishedDataSetDataType();

            publishedDataSet.Name = "Name";
            //Act
            dataCollector.AddPublishedDataSet(publishedDataSet);
            dataCollector.RemovePublishedDataSet(publishedDataSet);
            DataSet collectedDataSet = dataCollector.CollectData(publishedDataSet.Name);

            //Assert
            Assert.IsNull(collectedDataSet, "The '{0}' publishedDataSet was not removed correctly.", publishedDataSet.Name);
        }
Exemplo n.º 8
0
        public void ValidateAddPublishedDataSet()
        {
            //Arrange
            string configurationFile   = Utils.GetAbsoluteFilePath(m_configurationFileName, true, true, false);
            var    pubSubConfiguration = UaPubSubConfigurationHelper.LoadConfiguration(configurationFile);

            DataCollector dataCollector = new DataCollector(new UaPubSubDataStore());

            //Act
            dataCollector.AddPublishedDataSet(pubSubConfiguration.PublishedDataSets.First());
            DataSet collectedDataSet = dataCollector.CollectData(pubSubConfiguration.PublishedDataSets.First().Name);

            //Assert
            Assert.IsNotNull(collectedDataSet,
                             "Cannot collect data therefore the '{0}' publishedDataSet was not registered correctly.", pubSubConfiguration.PublishedDataSets[0].Name);
        }
Exemplo n.º 9
0
    public static void Main()
    {
        List <IDataRecievable> sensors = new List <IDataRecievable>
        {
            new PiSensor(),
            new StringSensor()
        };
        DataCollector dc = new DataCollector(sensors);

        dc.CollectData();
        decimal pi       = dc.GetResultFromSensor <decimal>(typeof(PiSensor));
        string  greeting = dc.GetResultFromSensor <string>(typeof(StringSensor));

        Console.WriteLine(2 * pi);
        Console.WriteLine(greeting);
    }
Exemplo n.º 10
0
Arquivo: Program.cs Projeto: NiekM/OMG
    static void Main()
    {
        Application.EnableVisualStyles();
        Application.SetCompatibleTextRenderingDefault(false);


        //Application.Run(new Visualizer(Scene.MixScene
        //    (new ParticleData(300, 1, 5, 3, energy: 10))
        //));
        //Application.Run(new Visualizer(Scene.MixScene
        //    (new ParticleData(900, 1000, 5, 2, energy: 10)
        //    , new ParticleData(200, 1, 8, 4)
        //    )
        //));
        //Application.Run(new Visualizer(Scene.MixScene
        //    (new ParticleData(50, 1, 12, 5))
        //));
        //Application.Run(new Visualizer(Scene.MixScene
        //    ( new ParticleData(900, 1000, 5, 2, energy: 10)
        //    , new ParticleData(200, 1, 8, 4, energy: 5)
        //    )
        //));
        //Application.Run(new Visualizer(Scene.MixScene
        //    (new ParticleData(900, 1000, 5, 2, energy: 10)
        //    , new ParticleData(200, 1, 8, 4, energy: 5)
        //    )
        //));

        //List<Simulation> simulations = new List<Simulation>();

        //for (int i = 1; i <= 5; i++)
        //{
        //    int size = 200 * i - 100;
        //    simulations.Add(new Simulation($"Equalmass_{size}_{size}", new ParticleData(size, 1, 5, 2)));
        //}

        //DataCollector.CollectData(iterations: 100, timeStep: 10, threads: 10, tests: 50, simulations: simulations.ToArray());

        DataCollector.CollectData(iterations: 100, timeStep: 10f, threads: 10, tests: 50, simulations: new []
                                  { new Simulation("MassEXTREME", new ParticleData(300, 1, 6, 3), new ParticleData(300, 1E4, 6, 3)) }
                                  );
    }
Exemplo n.º 11
0
        public void ValidateCollectDataFromExtensionFields()
        {
            //Arrange
            UaPubSubDataStore dataStore     = new UaPubSubDataStore();
            DataCollector     dataCollector = new DataCollector(dataStore);

            #region set up published data set that collects data from extension fields
            PublishedDataSetDataType publishedDataSetSimple = new PublishedDataSetDataType();
            publishedDataSetSimple.Name = "Simple";
            // Define  publishedDataSetSimple.DataSetMetaData
            publishedDataSetSimple.DataSetMetaData = new DataSetMetaDataType();
            publishedDataSetSimple.DataSetMetaData.DataSetClassId = new Uuid(Guid.Empty);
            publishedDataSetSimple.DataSetMetaData.Name           = publishedDataSetSimple.Name;
            publishedDataSetSimple.DataSetMetaData.Fields         = new FieldMetaDataCollection()
            {
                new FieldMetaData()
                {
                    Name           = "BoolToggle",
                    DataSetFieldId = new Uuid(Guid.NewGuid()),
                    DataType       = DataTypeIds.Boolean,
                    ValueRank      = ValueRanks.Scalar
                },
                new FieldMetaData()
                {
                    Name           = "Int32",
                    DataSetFieldId = new Uuid(Guid.NewGuid()),
                    DataType       = DataTypeIds.Int32,
                    ValueRank      = ValueRanks.Scalar
                },
                new FieldMetaData()
                {
                    Name           = "Int32Fast",
                    DataSetFieldId = new Uuid(Guid.NewGuid()),
                    DataType       = DataTypeIds.Int32,
                    ValueRank      = ValueRanks.Scalar
                },
                new FieldMetaData()
                {
                    Name           = "DateTime",
                    DataSetFieldId = new Uuid(Guid.NewGuid()),
                    DataType       = DataTypeIds.DateTime,
                    ValueRank      = ValueRanks.Scalar
                }
            };

            //initialize Extension fields collection
            publishedDataSetSimple.ExtensionFields = new KeyValuePairCollection()
            {
                new Opc.Ua.KeyValuePair()
                {
                    Key   = new QualifiedName("BoolToggle"),
                    Value = true
                },
                new Opc.Ua.KeyValuePair()
                {
                    Key   = new QualifiedName("Int32"),
                    Value = (int)100
                },
                new Opc.Ua.KeyValuePair()
                {
                    Key   = new QualifiedName("Int32Fast"),
                    Value = (int)50
                },
                new Opc.Ua.KeyValuePair()
                {
                    Key   = new QualifiedName("DateTime"),
                    Value = DateTime.Today
                }
            };

            PublishedDataItemsDataType publishedDataItems = new PublishedDataItemsDataType();
            publishedDataItems.PublishedData = new PublishedVariableDataTypeCollection();
            //create PublishedData based on metadata names
            foreach (var field in publishedDataSetSimple.DataSetMetaData.Fields)
            {
                publishedDataItems.PublishedData.Add(
                    new PublishedVariableDataType()
                {
                    SubstituteValue = new QualifiedName(field.Name)
                });
            }
            publishedDataSetSimple.DataSetSource = new ExtensionObject(publishedDataItems);
            #endregion

            //Act
            dataCollector.AddPublishedDataSet(publishedDataSetSimple);
            DataSet collectedDataSet = dataCollector.CollectData(publishedDataSetSimple.Name);
            //Assert
            Assert.IsNotNull(publishedDataItems, "The m_firstPublishedDataSet.DataSetSource is not PublishedDataItemsDataType.");
            Assert.IsNotNull(collectedDataSet, "collectedDataSet is null.");
            Assert.IsNotNull(collectedDataSet.Fields, "collectedDataSet.Fields is null.");

            Assert.AreEqual(collectedDataSet.Fields.Length, publishedDataItems.PublishedData.Count, "collectedDataSet and published data fields count do not match.");
            // validate collected values
            Assert.AreEqual(collectedDataSet.Fields[0].Value.Value, true, "collectedDataSet.Fields[0].Value.Value does not match.");
            Assert.AreEqual(collectedDataSet.Fields[1].Value.Value, (int)100, "collectedDataSet.Fields[1].Value.Value does not match.");
            Assert.AreEqual(collectedDataSet.Fields[2].Value.Value, (int)50, "collectedDataSet.Fields[2].Value.Value does not match.");
            Assert.AreEqual(collectedDataSet.Fields[3].Value.Value, DateTime.Today, "collectedDataSet.Fields[3].Value.Value does not match.");
        }
Exemplo n.º 12
0
        public void ValidateCollectDataFromDataStore()
        {
            //Arrange
            UaPubSubDataStore dataStore = new UaPubSubDataStore();

            dataStore.WritePublishedDataItem(new NodeId("BoolToggle", NamespaceIndex), 0, new DataValue(new Variant(false)));
            dataStore.WritePublishedDataItem(new NodeId("Int32", NamespaceIndex), 0, new DataValue(new Variant(1)));
            dataStore.WritePublishedDataItem(new NodeId("Int32Fast", NamespaceIndex), 0, new DataValue(new Variant(2)));
            dataStore.WritePublishedDataItem(new NodeId("DateTime", NamespaceIndex), 0, new DataValue(new Variant(DateTime.MaxValue)));

            DataCollector dataCollector = new DataCollector(dataStore);

            #region set up published data set that collects data from extension fields
            PublishedDataSetDataType publishedDataSetSimple = new PublishedDataSetDataType();
            publishedDataSetSimple.Name = "Simple";
            // Define  publishedDataSetSimple.DataSetMetaData
            publishedDataSetSimple.DataSetMetaData = new DataSetMetaDataType();
            publishedDataSetSimple.DataSetMetaData.DataSetClassId = new Uuid(Guid.Empty);
            publishedDataSetSimple.DataSetMetaData.Name           = publishedDataSetSimple.Name;
            publishedDataSetSimple.DataSetMetaData.Fields         = new FieldMetaDataCollection()
            {
                new FieldMetaData()
                {
                    Name           = "BoolToggle",
                    DataSetFieldId = new Uuid(Guid.NewGuid()),
                    DataType       = DataTypeIds.Boolean,
                    ValueRank      = ValueRanks.Scalar
                },
                new FieldMetaData()
                {
                    Name           = "Int32",
                    DataSetFieldId = new Uuid(Guid.NewGuid()),
                    DataType       = DataTypeIds.Int32,
                    ValueRank      = ValueRanks.Scalar
                },
                new FieldMetaData()
                {
                    Name           = "Int32Fast",
                    DataSetFieldId = new Uuid(Guid.NewGuid()),
                    DataType       = DataTypeIds.Int32,
                    ValueRank      = ValueRanks.Scalar
                },
                new FieldMetaData()
                {
                    Name           = "DateTime",
                    DataSetFieldId = new Uuid(Guid.NewGuid()),
                    DataType       = DataTypeIds.DateTime,
                    ValueRank      = ValueRanks.Scalar
                }
            };

            PublishedDataItemsDataType publishedDataItems = new PublishedDataItemsDataType();
            publishedDataItems.PublishedData = new PublishedVariableDataTypeCollection();
            //create PublishedData based on metadata names
            foreach (var field in publishedDataSetSimple.DataSetMetaData.Fields)
            {
                publishedDataItems.PublishedData.Add(
                    new PublishedVariableDataType()
                {
                    PublishedVariable = new NodeId(field.Name, NamespaceIndex),
                    AttributeId       = Attributes.Value,
                });
            }
            publishedDataSetSimple.DataSetSource = new ExtensionObject(publishedDataItems);
            #endregion

            //Act
            dataCollector.AddPublishedDataSet(publishedDataSetSimple);
            DataSet collectedDataSet = dataCollector.CollectData(publishedDataSetSimple.Name);

            //Assert
            Assert.IsNotNull(publishedDataItems, "The m_firstPublishedDataSet.DataSetSource is not PublishedDataItemsDataType.");
            Assert.IsNotNull(collectedDataSet, "collectedDataSet is null.");
            Assert.IsNotNull(collectedDataSet.Fields, "collectedDataSet.Fields is null.");

            Assert.AreEqual(collectedDataSet.Fields.Length, publishedDataItems.PublishedData.Count, "collectedDataSet and published data fields count do not match.");

            // validate collected values
            Assert.AreEqual(collectedDataSet.Fields[0].Value.Value, false, "collectedDataSet.Fields[0].Value.Value does not match.");
            Assert.AreEqual(collectedDataSet.Fields[1].Value.Value, (int)1, "collectedDataSet.Fields[1].Value.Value does not match.");
            Assert.AreEqual(collectedDataSet.Fields[2].Value.Value, (int)2, "collectedDataSet.Fields[2].Value.Value does not match.");
            Assert.AreEqual(collectedDataSet.Fields[3].Value.Value, DateTime.MaxValue, "collectedDataSet.Fields[3].Value.Value does not match.");
        }
Exemplo n.º 13
0
        private void Kinect_OnTrackedBody(object sender, BodyEventArgs e)
        {
            Body body = e.BodyData;

            if (Mode == ControlMode.Disabled)
            {
                return;
            }

            for (int i = 1; i >= 0; i--) // Starts looking from right hand.
            {
                bool isLeft = i == 0;
                if (body.IsHandLiftForward(isLeft))
                {
                    if (usedHandIndex == -1)
                    {
                        usedHandIndex = i;
                    }
                    else if (usedHandIndex != i)
                    {
                        // In two-hand control mode, non-used hand would be used for pressing/releasing mouse button.
                        if (Mode == ControlMode.MoveGripPressing)
                        {
                            DoMouseControlByHandState(i, body.GetHandState(isLeft));
                        }

                        continue;
                    }

                    MVector2 handPos   = body.GetHandRelativePosition(isLeft);
                    MVector2 targetPos = cursorMapper.GetSmoothedOutputPosition(handPos);

                    MouseControl.MoveTo(targetPos.X, targetPos.Y);

                    if (Mode == ControlMode.GripToPress)
                    {
                        MouseControlState state = DoMouseControlByHandState(i, body.GetHandState(isLeft));
                        Data d = new Data(targetPos.X, targetPos.Y, state, body);
                        if (task_num != 0)
                        {
                            DataCollector.CollectData(d);
                        }
                        PositionDataUpdated?.Invoke(this, d);
                    }
                    else if (Mode == ControlMode.HoverToClick)
                    {
                        if ((targetPos - lastCursorPos).Length() > HoverRange)
                        {
                            ToggleHoverTimer(false);
                            hoverClicked = false;
                        }

                        lastCursorPos = targetPos;
                    }
                }
                else
                {
                    if (usedHandIndex == i)
                    {
                        // Reset to none.
                        usedHandIndex = NONE_USED;
                        ReleaseGrip(i);
                    }
                    else if (Mode == ControlMode.MoveLiftClicking)
                    {
                        DoMouseClickByHandLifting(i, body.GetHandRelativePosition(isLeft));
                        //System.Diagnostics.Trace.WriteLine(body.GetHandRelativePosition(isLeft).Y);
                    }
                    else // Release mouse button when it's not regularly released, such as hand tracking lost.
                    {
                        ReleaseGrip(i);
                    }
                }
            }

            ToggleHoverTimer(Mode == ControlMode.HoverToClick && usedHandIndex != -1);
        }