Example #1
0
        public void ShouldUseDefaultServices()
        {
            var rdapService = new Mock <IService>();

            rdapService
            .Setup(e => e.ServiceType())
            .Returns(ServiceTypes.RDAP);

            rdapService
            .Setup(e => e.SendQueryAsync("google.com"))
            .Returns(Task.FromResult(new ServiceResultDto
            {
                Result = "DATA FROM RDAP"
            }));


            var configSection = new Mock <IConfigurationSection>();

            configSection.Setup(c => c.Value)
            .Returns("RDAP,Ping");

            var config = new Mock <IConfiguration>();

            config.Setup(s => s.GetSection("DefaultServices"))
            .Returns(configSection.Object);


            var infoCollector = new InfoCollector(new[] { rdapService.Object }, config.Object);

            var results = infoCollector.Request("google.com").Result;

            Assert.Single(results);
            Assert.Equal("DATA FROM RDAP", results[0].Result);
        }
Example #2
0
        private SpinLock _lock; // can't be readonly

        public ScanCoordinator(string scanStartingPath, string scanResultsFilePath,
                               XmlDocument scanResultsDocument, Dispatcher uiDispatcher)
        {
            _lock = new SpinLock();

            _infoCollector               = new InfoCollector(scanStartingPath, new TaskInfoBuilder());
            _fileWriterTaskProcessor     = new FileWriterTaskProcessor(scanResultsFilePath);
            _treeWriterInfoTaskProcessor = new TreeWriterInfoTaskProcessor(uiDispatcher, scanResultsDocument);

            _infoCollector.InfoCollected += OnItemScanned;
            _infoCollector.InfoCollected += _fileWriterTaskProcessor.QueueTask;
            _infoCollector.InfoCollected += _treeWriterInfoTaskProcessor.QueueTask;

            _fileWriterTaskProcessor.Processed     += OnItemWroteToFile;
            _treeWriterInfoTaskProcessor.Processed += OnItemWroteToTree;

            _infoCollector.Completed               += OnCollectingCompleted;
            _infoCollector.Completed               += _fileWriterTaskProcessor.Finish;
            _infoCollector.Completed               += _treeWriterInfoTaskProcessor.Finish;
            _fileWriterTaskProcessor.Completed     += OnWritingToFileCompleted;
            _treeWriterInfoTaskProcessor.Completed += OnWritingToTreeCompleted;

            _infoCollector.Failed               += OnFailed;
            _fileWriterTaskProcessor.Failed     += OnFailed;
            _treeWriterInfoTaskProcessor.Failed += OnFailed;
        }
Example #3
0
        public void AggregateData_WithMultipleHandler_And_DuplicatedKeys()
        {
            // Arrange
            var simpleData1 = new Dictionary <string, string>()
            {
                { "Key1", "Value1" }
            };

            var infoHandler1 = new Mock <IInfoProvider>();

            infoHandler1.Setup(x => x.GetData())
            .Returns(simpleData1);

            var infoHandler2 = new Mock <IInfoProvider>();

            infoHandler2.Setup(x => x.GetData())
            .Returns(simpleData1);

            var collector = new InfoCollector(new List <IInfoProvider>()
            {
                infoHandler1.Object, infoHandler2.Object
            }, _mockLogger.Object);

            // Act
            var result = collector.AggregateData();

            // Assert
            //Assert.Throws<ArgumentException>(collector.AggregateData);
            _mockLogger.VerifyLogging(string.Format(Messages.DUPLICATED_KEY, simpleData1.First().Key), LogLevel.Warning, Times.Once());
            Assert.Equal(result, simpleData1);
        }
 public WebstatsController(
     ILogger <WebstatsController> logger,
     IConfiguration config,
     InfoCollector infoCollector) : base(logger, config)
 {
     _infoCollector = infoCollector;
 }
Example #5
0
        public TypeGenerationInfo(TypeName typeName, string baseName)
        {
            this.typeName = typeName;
            this.baseName = baseName;

            nestedElementsCollector = new InfoCollector<NestedElementGenerationInfo, GroupGenerationInfo>(flatNestedElements, groups);

            attributesCollector = new InfoCollector<AttributeGenerationInfo, AttributesGroupGenerationInfo>(attributes, attributeGroups);
        }
 public static void AddInfoCollector(InfoCollector ic)
 {
     allInfoCollectors.Add(ic);
     if (ic.isAgent == 1)
     {
         agentCount++;
         agentsInUse++;
     }
 }
Example #7
0
        public void ReturnEmptyData_WhenNoHandler()
        {
            // Arrange
            var collector = new InfoCollector(new List <IInfoProvider>(), _mockLogger.Object);

            // Act
            var result = collector.AggregateData();

            // Assert
            Assert.True(result.Count == 0);
        }
        public override object EditValue(System.ComponentModel.ITypeDescriptorContext context,
                                         System.IServiceProvider provider, object value)
        {
            IWindowsFormsEditorService edSvc =
                (IWindowsFormsEditorService)provider.GetService(typeof(IWindowsFormsEditorService));

            if (edSvc != null)
            {
                InfoCollector infoCollector = new InfoCollector((ControlDaSession)value);
                edSvc.ShowDialog(infoCollector);
                return(infoCollector.InfoCollected);
            }
            return(value);
        }
Example #9
0
            static void Main(string[] args)
            {
                InfoCollector collector = new InfoCollector();

                collector.ClientSetup();

                HttpResponseMessage response = collector.GetResponseFromRequest("stock/clf/chart/5y").Result;

                String JsonString = collector.GetStringFromResponse(response).Result;

                JArray jsonObjectArray = JArray.Parse(JsonString);

                //https://stackoverflow.com/questions/15726197/parsing-a-json-array-using-json-net
                foreach (JObject jsonObject in jsonObjectArray.Children <JObject>())
                {
                    foreach (JProperty jsonProperty in jsonObject.Properties())
                    {
                        String name  = jsonProperty.Name;
                        String value = (String)jsonProperty.Value;
                    }
                }

                ////https://stackoverflow.com/questions/12676746/parse-json-string-in-c-sharp
                //foreach (JObject jsonObject in jsonObjectArray)
                //{
                //    foreach (KeyValuePair<String, JToken> obj in jsonObject)
                //    {
                //        //var Key = obj.Key;
                //        var close = (String)obj.Value["close"];
                //    }
                //}

                //List<StockInfo> si = JsonConvert.DeserializeObject<List<StockInfo>>(JsonString);

                IEnumerable <StockInfo> si2 = JsonConvert.DeserializeObject <IEnumerable <StockInfo> >(JsonString).Reverse();
            }
Example #10
0
        public void AggregateData_WithMultipleHandler()
        {
            // Arrange
            var simpleData1 = new Dictionary <string, string>()
            {
                { "Key1", "Value1" }
            };

            var infoHandler1 = new Mock <IInfoProvider>();

            infoHandler1.Setup(x => x.GetData())
            .Returns(simpleData1);

            var simpleData2 = new Dictionary <string, string>()
            {
                { "Key2", "Value2" }
            };

            var infoHandler2 = new Mock <IInfoProvider>();

            infoHandler2.Setup(x => x.GetData())
            .Returns(simpleData2);

            var collector = new InfoCollector(new List <IInfoProvider>()
            {
                infoHandler1.Object, infoHandler2.Object
            }, _mockLogger.Object);

            // Act
            var result = collector.AggregateData();

            // Assert
            var dict = simpleData1.Union(simpleData2).ToDictionary(k => k.Key, v => v.Value);

            Assert.Equal(result, dict);
        }
Example #11
0
        public void InstantiateHandler_ReturnDataInHandler()
        {
            // Arrange
            var simpleData = new Dictionary <string, string>()
            {
                { "Key1", "Value1" }
            };

            var infoHandlerSimple = new Mock <IInfoProvider>();

            infoHandlerSimple.Setup(x => x.GetData())
            .Returns(simpleData);

            var collector = new InfoCollector(new List <IInfoProvider>()
            {
                infoHandlerSimple.Object
            }, _mockLogger.Object);

            // Act
            var result = collector.AggregateData();

            // Assert
            Assert.Equal(result, simpleData);
        }
Example #12
0
        public async void ShouldReturnEmptyResults()
        {
            string HostName = "google.com";

            var services = new List <IService>();

            var rdapService = new Mock <IService>();

            rdapService
            .Setup(e => e.ServiceType())
            .Returns(ServiceTypes.RDAP);

            rdapService
            .Setup(e => e.SendQueryAsync(HostName))
            .Returns(Task.FromResult(new ServiceResultDto()
            {
                Result = "",
                Status = "Error"
            }));

            services.Add(rdapService.Object);


            var pingService = new Mock <IService>();

            pingService
            .Setup(e => e.ServiceType())
            .Returns(ServiceTypes.Ping);

            pingService
            .Setup(e => e.SendQueryAsync(HostName))
            .Returns(Task.FromResult(new ServiceResultDto()
            {
                Result = "",
                Status = "Error"
            }));

            services.Add(pingService.Object);



            var configSection = new Mock <IConfigurationSection>();

            configSection.Setup(c => c.Value)
            .Returns("RDAP,Ping");

            var config = new Mock <IConfiguration>();

            config.Setup(s => s.GetSection("DefaultServices"))
            .Returns(configSection.Object);


            var infoCollector = new InfoCollector(services, config.Object);


            var results = infoCollector.Request("google.com").Result;


            foreach (var item in results)
            {
                Assert.Equal("Error", item.Status);
            }
        }
Example #13
0
 /// <summary>
 /// The method to  be overriden and to be provided for the IHashValue interface.
 /// In its body you have to collect all your class's information that is
 /// to be exposed to the L20n Language Environment within the translations where you
 /// pass this class to.
 /// </summary>
 public abstract void Collect(InfoCollector info);
 public static void StopInfoCollector(InfoCollector ic)
 {
     agentStats.Add(ComputeAgentStatistics(ic));
 }
    private static Dictionary <AgentStat, float> ComputeAgentStatistics(InfoCollector info)
    {
        var stats          = new Dictionary <AgentStat, float>();
        var fixedDeltaTime = Time.fixedDeltaTime;

        foreach (var stat in Enum.GetValues(typeof(AgentStat)).Cast <AgentStat>())
        {
            float val = 0;

            switch (stat)
            {
            // Human or Agent
            case AgentStat.IS_AGENT:
                val = info.isAgent;
                break;

            //Primary Metrics
            case AgentStat.AGENT_COLLISION_COUNT:
                val = info.agentCollisionCount;
                break;

            case AgentStat.OBSTACLE_COLLISION_COUNT:
                val = info.obstacleCollisionCount;
                break;

            case AgentStat.AGENT_COMPLETION_TIME:
                //val = info.totalFrames * Parameters.Simulation.FIXED_DELTA_TIME;
                val = info.totalFrames * fixedDeltaTime;
                break;

            case AgentStat.TOTAL_METABOLIC_ENERGY:
                val = info.speedToMetabolicEnergy.GetTotal();
                break;

            // Turning Metrics
            case AgentStat.TOTAL_DEGREES_TURNED:
                val = info.angleToAbs.GetTotal();
                break;

            case AgentStat.AVG_ANGULAR_SPEED:
                //val = info.angleToAbs.GetTotal() / info.angleToAbs.GetTotalCount() / Parameters.Simulation.FIXED_DELTA_TIME;
                val = info.angleToAbs.GetTotal() / info.angleToAbs.GetTotalCount() / fixedDeltaTime;
                break;

            case AgentStat.MAX_INSTANT_ANG_SPEED:
                //val = info.maxAbsAngle / Parameters.Simulation.FIXED_DELTA_TIME;
                val = info.maxAbsAngle / fixedDeltaTime;
                break;

            //case Stat.MAX_TURNING_IN_WINDOW:
            //    val = Util.GetMaxAngularDevInWindow(motion, 5);
            //    break;
            case AgentStat.ANGULAR_INFLECTION_COUNT:
                val = Mathf.Abs(info.angleInflections);
                break;

            // Distance/Speed Metrics
            case AgentStat.TOTAL_DISTANCE:
                val = info.velToSpeed.GetTotal();
                break;

            case AgentStat.AVG_SPEED:
                val = info.velToSpeed.GetTotal() / info.velToSpeed.GetTotalCount() / fixedDeltaTime;
                break;

            case AgentStat.MAX_INSTANT_SPEED:
                val = info.maxSpeed / fixedDeltaTime;
                break;
            //case Stat.MAX_DIST_IN_WINDOW:
            //    val = Util.GetMaxDistInWindow(motion, 5);
            //    break;
            //case Stat.MIN_DIST_IN_WINDOW:
            //    val = Util.GetMinDistInWindow(motion, 5);
            //    break;

            // Speed-Change Metrics
            case AgentStat.TOTAL_SPEED_CHANGE:
                val = info.speedToSpeedChange.GetTotal();
                break;

            case AgentStat.AVG_SPEED_CHANGE:
                val = info.speedToSpeedChange.GetTotal() / info.speedToSpeedChange.GetTotalCount() / fixedDeltaTime;
                break;

            case AgentStat.MAX_INSTANT_SPEED_CHANGE:
                val = info.maxSpeedChange / fixedDeltaTime;
                break;

            //case Stat.MAX_SPEED_CHANGE_IN_WINDOW:
            //    val = Util.GetMaxSpeedChangeInWindow(motion, 5);
            //    break;
            case AgentStat.SPEED_CHANGE_INFLECT_COUNT:
                val = Mathf.Abs(info.speedChangeInflections);
                break;

            // Acceleration MEtrics
            case AgentStat.TOTAL_ACCELERATION:
                val = info.velToAccel.GetTotal();
                break;

            case AgentStat.AVG_ACCELERATION:
                val = info.velToAccel.GetTotal() / info.velToAccel.GetTotalCount() / fixedDeltaTime;
                break;

            case AgentStat.MAX_INSTANT_ACCEL:
                val = info.maxAccel / fixedDeltaTime;
                break;
                //case Stat.MAX_ACCEL_IN_WINDOW:
                //    val = Util.GetMaxAccelInWindow(motion);
                //    break;
            }

            stats.Add(stat, val);
        }

        return(stats);
    }