Exemple #1
0
        public static IEnumerable <Sample> ReadAllSources(IEnumerable <string> paths, LocalFileReaderPool readersPool, ILogger logger, IChanelFactory chanelFactory)
        {
            var result  = new List <Sample>();
            var report  = new ReportPrototype(DateTime.Now);
            var reports = new List <string>(paths.Count());
            var timer   = new Stopwatch();

            foreach (var file in paths)
            {
                var stats     = new StatsBuilder(file);
                var extension = new FileInfo(file).Extension.Trim('.');
                var protocol  = ExtractProtocol(file);
                var chanel    = chanelFactory.Create(protocol);
                using (var stream = chanel.Connect(file))
                {
                    var reader = readersPool.Borrow(extension);
                    timer.Start();
                    var samples = reader.Read(stream);
                    timer.Stop();
                    readersPool.Release(reader);
                    result.AddRange(samples);

                    stats.AddDuration(timer.Elapsed);
                    stats.AddCount((uint)samples.Count());

                    timer.Reset();
                }

                reports.Add(report.Clone(stats.Build()));
                logger.Log(report.Clone(stats.Build()));
            }

            return(result);
        }
Exemple #2
0
        public async Task CreateReport_WrongData_PreviousIsNullPresentIsFalse(string reportName, int CurrentRoomId, string CurrentRoomName, int CurrentBuildingId, string CurrentBuildingName, int[] assetId, int[] assetTypeId, string[] assetTypeName, char[] assetLetter, bool[] present)
        {
            RoomEntity room = new RoomEntity {
                id = CurrentRoomId, name = CurrentRoomName, building = new BuildingEntity {
                    id = CurrentBuildingId, name = CurrentBuildingName
                }
            };
            ReportPositionPrototype positionPrototyp1 = new ReportPositionPrototype(new AssetEntity {
                id = assetId[0], type = new AssetTypeEntity {
                    id = assetTypeId[0], name = assetTypeName[0], letter = assetLetter[0]
                }
            }, null, present[0]);
            ReportPositionPrototype positionPrototyp2 = new ReportPositionPrototype(new AssetEntity {
                id = assetId[1], type = new AssetTypeEntity {
                    id = assetTypeId[1], name = assetTypeName[1], letter = assetLetter[1]
                }
            }, null, present[1]);
            ReportPrototype reportPrototype = new ReportPrototype(reportName, room, new ReportPositionPrototype[] { positionPrototyp1, positionPrototyp2 });
            int             resultInt       = await apiController.createReport(reportPrototype);

            bool resultBool = false;

            if (resultInt > 0)
            {
                resultBool = true;
            }
            Assert.AreEqual(false, resultBool);
        }
Exemple #3
0
        public async Task createReport_CorrectData_OneAsset(string reportName, int CurrentRoomId, string CurrentRoomName, int CurrentBuildingId, string CurrentBuildingName, int assetId, int assetTypeId, string assetTypeName, char assetLetter, int PreviousRoomId, string PreviousRoomName, int PreviousBuildingId, string PreviousBuildingName, bool present)
        {
            RoomEntity room = new RoomEntity {
                id = CurrentRoomId, name = CurrentRoomName, building = new BuildingEntity {
                    id = CurrentBuildingId, name = CurrentBuildingName
                }
            };
            ReportPositionPrototype positionPrototyp = new ReportPositionPrototype(new AssetEntity {
                id = assetId, type = new AssetTypeEntity {
                    id = assetTypeId, name = assetTypeName, letter = assetLetter
                }
            }, new RoomEntity {
                id = PreviousRoomId, name = PreviousRoomName, building = new BuildingEntity {
                    id = PreviousBuildingId, name = PreviousBuildingName
                }
            }, present);
            ReportPrototype reportPrototype = new ReportPrototype(reportName, room, new ReportPositionPrototype[] { positionPrototyp });
            int             resultInt       = await apiController.createReport(reportPrototype);

            bool resultBool = false;

            if (resultInt > 0)
            {
                resultBool = true;
            }
            Assert.AreEqual(true, resultBool);
        }
        /// <summary>
        /// Asynchronicznie tworzy i dodaje do bazy nowy raport z podanego opisu
        /// </summary>
        /// <param name="report">Opis raportu</param>
        /// <returns>Identyfikator liczbowy nowo dodanego raportu lub -1 jeśli nie udało się dodać raportu do bazy danych</returns>
        public async Task <int> createReport(ReportPrototype report)
        {
            var    uri  = "/addNewReport";
            string data = ConvertDataToJSON(report);

            if (data == null)
            {
                return(-1);
            }

            var content = PreperDataToSend(data);

            return(await SendRequest(uri, content));
        }
Exemple #5
0
        public async Task CreateReport_WrongData_ZeroAsset(string reportName, int roomId, string roomName, int buildingId, string buildingName)
        {
            RoomEntity room = new RoomEntity {
                id = roomId, name = roomName, building = new BuildingEntity {
                    id = buildingId, name = buildingName
                }
            };
            ReportPrototype reportPrototype = new ReportPrototype(reportName, room, new ReportPositionPrototype[] {});
            int             resultInt       = await apiController.createReport(reportPrototype);

            bool resultBool = false;

            if (resultInt > 0)
            {
                resultBool = true;
            }
            Assert.AreEqual(false, resultBool);
        }