public void PerformCleanup()
        {
            var reader = new EventInfoPropertyReader();

            var propFiles = Directory.GetFiles(StautConfiguration.Current.CollectorDirectory, "eventinfo.properties",
                                               SearchOption.AllDirectories);

            foreach (var propFile in propFiles)
            {
                var propDir = Path.GetDirectoryName(propFile);
                if (String.IsNullOrWhiteSpace(propDir))
                {
                    continue;
                }
                var info = reader.ReadProperties(propFile);
                if (info.Start.Date >= DateTime.Today) // Vi rører ikke events før de er over.
                {
                    continue;
                }
                var fileCount = Directory.GetFiles(propDir).Count();
                if (fileCount > 1) // Ligger det flere filer der holder vi avstand.
                {
                    continue;
                }
                var leafDir             = PathUtils.GetLeafDirectoryName(propFile);
                var storagePropFilename = Path.Combine(PathUtils.GetStoragePath(info.Start, leafDir), "eventinfo.properties");
                if (!File.Exists(storagePropFilename)) // Hvis ikke eventinfo-fila er kopiert over holder vi oss unna.
                {
                    continue;
                }
                // Kommer vi hit må vi vel endelig innse at dette directoriet kan slettes
                Directory.Delete(propDir, true);
            }
        }
        public void ReadProperties_WhenGivenEmptyString_ThrowsArgumentException()
        {
            // Arrange
            var sut = new EventInfoPropertyReader();

            // Act
            Assert.Throws <ArgumentException>(() => sut.ReadProperties(String.Empty));

            // Assert
        }
        public void ReadProperties_WhenGivenNull_ThrowsArgumentException()
        {
            // Arrange
            var sut = new EventInfoPropertyReader();

            // Act
            Assert.Throws <ArgumentException>(() => sut.ReadProperties(null));

            // Assert
        }
        public void ReadProperties_GivenGoodInputFile_ReturnsValidObject()
        {
            // Arrange
            var sut = new EventInfoPropertyReader();

            // Act
            var res = sut.ReadProperties(@"..\..\TestData\eventinfo.properties");

            // Assert
            res.Should().NotBeNull("valid filename should result in valid object");
        }
        public void ReadProperties_WhenGivenNonExistingFile_ThrowsArgumentException()
        {
            // Arrange
            var          sut         = new EventInfoPropertyReader();
            const string badFilename = @"buh:\nah\d'oh\eventinfo.properties";

            // Act
            Assert.Throws <ArgumentException>(() => sut.ReadProperties(badFilename));

            // Assert
        }
        public void ReadProperties_GivenGoodInputFile_GetsCorrectGeometryUrl()
        {
            // Arrange
            var sut = new EventInfoPropertyReader();

            // Act
            var res = sut.ReadProperties(@"..\..\TestData\eventinfo.properties");

            // Assert
            res.GeometryUrl.Should().Be("http://www.billettservice.no/seatmap/proxy/geometry/syst-25/geometry/TLD12_V07_geometry.xml", "that is the correct url");
        }
        public void ReadProperties_GivenGoodInputFile_GetsCorrectAvailabilityUrl()
        {
            // Arrange
            var sut = new EventInfoPropertyReader();

            // Act
            var res = sut.ReadProperties(@"..\..\TestData\eventinfo.properties");

            // Assert
            res.AvailibilityUrl.Should().Be("http://www.billettservice.no/seatmap/proxy/availability/NO/TLD0915-2015,NO-438525.xml", "that is the correct url");
        }
        public void ReadProperties_GivenGoodInputFile_GetsCorrectEventNumber()
        {
            // Arrange
            var sut = new EventInfoPropertyReader();

            // Act
            var res = sut.ReadProperties(@"..\..\TestData\eventinfo.properties");

            // Assert
            res.EventNumber.Should()
            .Be(438525, "that is what the eventid field of the file contains");
        }
        public void ReadProperties_GivenGoodInputFile_GetsCorrectDisplayName()
        {
            // Arrange
            var sut = new EventInfoPropertyReader();

            // Act
            var res = sut.ReadProperties(@"..\..\TestData\eventinfo.properties");

            // Assert
            res.DisplayName.Should()
            .Be("Rosenborg - Sarpsborg 08", "that is what the eventname field of the file contains");
        }
        public void ReadProperties_GivenGoodInputFile_GetsCorrectOpponent()
        {
            // Arrange
            var sut = new EventInfoPropertyReader();

            // Act
            var res = sut.ReadProperties(@"..\..\TestData\eventinfo.properties");

            // Assert
            res.Opponent.Should()
            .Be("Sarpsborg", "that is what the opponent field of the file contains");
        }
        public void ReadProperties_GivenGoodInputFile_GetsCorrectTournament()
        {
            // Arrange
            var sut = new EventInfoPropertyReader();

            // Act
            var res = sut.ReadProperties(@"..\..\TestData\eventinfo.properties");

            // Assert
            res.Tournament.Should()
            .Be("LEAGUE", "that is what the competition field of the file contains");
        }
        public void ReadProperties_GivenGoodInputFile_GetsCorrectLocation()
        {
            // Arrange
            var sut = new EventInfoPropertyReader();

            // Act
            var res = sut.ReadProperties(@"..\..\TestData\eventinfo.properties");

            // Assert
            res.Location.Should()
            .Be("TLD", "that is what the location field of the file contains");
        }
        public void ReadProperties_GivenGoodInputFile_GetsCorrectStartTime()
        {
            // Arrange
            var sut = new EventInfoPropertyReader();

            // Act
            var res = sut.ReadProperties(@"..\..\TestData\eventinfo.properties");

            // Assert
            res.Start.Year.Should().Be(2015, "that is the correct year");
            res.Start.Month.Should().Be(8, "that is the correct month");
            res.Start.Day.Should().Be(2, "that is the correct day");
            res.Start.Hour.Should().Be(20, "that is the correct hour");
            res.Start.Minute.Should().Be(00, "that is the correct minute");
        }
        public IEnumerable <BillettServiceEvent> FetchEvents(string archivePath)
        {
            if (String.IsNullOrWhiteSpace(archivePath) || !Directory.Exists(archivePath))
            {
                throw new ArgumentException("Dårlig filområde");
            }

            // Loop gjennom archivePath sine subdirectories etter eventinfo.properties-filer
            var reader = new EventInfoPropertyReader();

            _events = Directory.GetFiles(archivePath, "eventinfo.properties", SearchOption.AllDirectories)
                      .ToDictionary(file => Path.GetDirectoryName(file), file => reader.ReadProperties(file));

            return(_events.Values);
        }
示例#15
0
        public void MoveToArchive(MeasurementFile measurementFile)
        {
            var sourceDirectory = Path.GetDirectoryName(measurementFile.FullPath);

            if (String.IsNullOrWhiteSpace(sourceDirectory))
            {
                return; // Kutt resharper-mas
            }
            var eventDate =
                new EventInfoPropertyReader().ReadProperties(
                    Path.Combine(sourceDirectory, "eventinfo.properties")).Start;
            var destinationPath = PathUtils.GetStoragePath(eventDate, PathUtils.GetLeafDirectoryName(measurementFile.FullPath));

            if (!Directory.Exists(destinationPath))
            {
                Directory.CreateDirectory(destinationPath);
            }

            var destinationPropertyFile = Path.Combine(destinationPath, "eventinfo.properties");

            if (!File.Exists(destinationPropertyFile))
            {
                File.Copy(Path.Combine(sourceDirectory, "eventinfo.properties"),
                          destinationPropertyFile);
            }

            var destinationFileName = Path.Combine(destinationPath, Path.GetFileName(measurementFile.FullPath));

            if (File.Exists(destinationFileName))
            {
                var    i = 1;
                string uniqueFilename;

                do
                {
                    uniqueFilename = Path.Combine(destinationPath,
                                                  Path.GetFileNameWithoutExtension(measurementFile.FullPath + "_" + i++.ToString() +
                                                                                   Path.GetExtension(measurementFile.FullPath)));
                } while (File.Exists(uniqueFilename));

                destinationFileName = uniqueFilename;
            }

            File.Move(measurementFile.FullPath, destinationFileName);
        }