Exemplo n.º 1
0
        public bool TryGetMaintenanceDelayTime(out DateTime time)
        {
            string timeFileName = this.GetMaintenanceDelayFilePath();

            if (this.fileSystem.FileExists(timeFileName))
            {
                try
                {
                    string contents = this.fileSystem.ReadAllText(timeFileName);

                    if (long.TryParse(contents, out long seconds))
                    {
                        time = EpochConverter.FromUnixEpochSeconds(seconds);
                        return(true);
                    }
                }
                catch (IOException)
                {
                    // Eat any issue reading this file
                }
            }

            time = DateTime.MinValue;
            return(false);
        }
Exemplo n.º 2
0
        protected override void PerformMaintenance()
        {
            long   last;
            string error = null;

            if (!this.TryGetMaxGoodPrefetchTimestamp(out last, out error))
            {
                this.Context.Tracer.RelatedError(error);
                return;
            }

            DateTime lastDateTime = EpochConverter.FromUnixEpochSeconds(last);
            DateTime now          = DateTime.UtcNow;

            if (now <= lastDateTime + this.timeBetweenPrefetches)
            {
                this.Context.Tracer.RelatedInfo(this.Area + ": Skipping prefetch since most-recent prefetch ({0}) is too close to now ({1})", lastDateTime, now);
                return;
            }

            this.RunGitCommand(process =>
            {
                this.TryPrefetchCommitsAndTrees(out error, process);
                return(null);
            });

            if (!string.IsNullOrEmpty(error))
            {
                this.Context.Tracer.RelatedWarning(
                    metadata: this.CreateEventMetadata(),
                    message: $"{nameof(this.TryPrefetchCommitsAndTrees)} failed with error '{error}'",
                    keywords: Keywords.Telemetry);
            }
        }
Exemplo n.º 3
0
        public void EpochToDateToEpoch()
        {
            long time      = 15237623489;
            long converted = EpochConverter.ToUnixEpochSeconds(EpochConverter.FromUnixEpochSeconds(time));

            time.ShouldEqual(converted);
        }
Exemplo n.º 4
0
        public void DateToEpochToDate()
        {
            DateTime time      = new DateTime(2018, 12, 18, 8, 12, 13, DateTimeKind.Utc);
            DateTime converted = EpochConverter.FromUnixEpochSeconds(EpochConverter.ToUnixEpochSeconds(time));

            time.ShouldEqual(converted);
        }
        private EuGatewayService CreateGatewayService(
            TemporaryExposureKeyRepository keysRepository,
            ISignatureService signatureService,
            IMapper autoMapper,
            IGatewayHttpClient gateWayHttpClient,
            IKeyFilter keyFilter,
            IGatewayWebContextReader webContextReader,
            IEFGSKeyStoreService storeService,
            ILogger <EuGatewayService> logger,
            EuGatewayConfig config)
        {
            var encodingService = new EncodingService();
            var epochConverter  = new EpochConverter();

            var gatewaySyncStateSettingsDao = new GatewaySyncStateSettingsDao(new SettingRepository(_dbContext));
            var settingsService             = new SettingsService(gatewaySyncStateSettingsDao);

            return(new EuGatewayService(
                       keysRepository,
                       signatureService,
                       encodingService,
                       keyFilter,
                       webContextReader,
                       autoMapper,
                       logger,
                       config,
                       settingsService,
                       epochConverter,
                       gateWayHttpClient,
                       storeService));
        }
Exemplo n.º 6
0
        private void BackgroundPrefetch()
        {
            try
            {
                using (ITracer activity = this.tracer.StartActivity(nameof(this.BackgroundPrefetch), EventLevel.Informational))
                {
                    long   last;
                    string error;

                    if (!CommitPrefetcher.TryGetMaxGoodPrefetchTimestamp(activity, this.enlistment, this.fileSystem, this.gitObjects, out last, out error))
                    {
                        activity.RelatedError(error);
                        return;
                    }

                    DateTime lastDateTime = EpochConverter.FromUnixEpochSeconds(last);
                    DateTime now          = DateTime.UtcNow;

                    if (now <= lastDateTime + this.timeBetweenPrefetches)
                    {
                        activity.RelatedInfo(TelemetryKey + ": Skipping prefetch since most-recent prefetch ({0}) is too close to now ({1})", lastDateTime, now);
                        return;
                    }

                    if (!CommitPrefetcher.TryPrefetchCommitsAndTrees(activity, this.enlistment, this.fileSystem, this.gitObjects, out error))
                    {
                        activity.RelatedError($"{TelemetryKey}: {nameof(CommitPrefetcher.TryPrefetchCommitsAndTrees)} failed with error '{error}'");
                    }
                }
            }
            catch (ThreadAbortException)
            {
                this.tracer.RelatedInfo(TelemetryKey + ": Aborting prefetch background thread due to ThreadAbortException");
                return;
            }
            catch (IOException e)
            {
                EventMetadata metadata = new EventMetadata();
                metadata.Add("Method", nameof(this.BackgroundPrefetch));
                metadata.Add("ExceptionMessage", e.Message);
                metadata.Add("StackTrace", e.StackTrace);
                this.tracer.RelatedWarning(
                    metadata: metadata,
                    message: TelemetryKey + ": IOException while running prefetch background thread (non-fatal): " + e.Message,
                    keywords: Keywords.Telemetry);
            }
            catch (Exception e)
            {
                EventMetadata metadata = new EventMetadata();
                metadata.Add("Method", nameof(this.BackgroundPrefetch));
                metadata.Add("ExceptionMessage", e.Message);
                metadata.Add("StackTrace", e.StackTrace);
                this.tracer.RelatedError(
                    metadata: metadata,
                    message: TelemetryKey + ": Unexpected Exception while running prefetch background thread (fatal): " + e.Message,
                    keywords: Keywords.Telemetry);
                Environment.Exit((int)ReturnCode.GenericError);
            }
        }
Exemplo n.º 7
0
        public void CanConvert_false()
        {
            // Act
            var converter = new EpochConverter();
            var type      = typeof(string);

            // Assert
            converter.CanConvert(type).ShouldBeFalse();
        }
Exemplo n.º 8
0
        public void CanConvert_true()
        {
            // Act
            var converter = new EpochConverter();
            var type      = typeof(DateTime);

            // Assert
            converter.CanConvert(type).ShouldBeTrue();
        }
Exemplo n.º 9
0
        public void Properties()
        {
            // Act
            var converter = new EpochConverter();

            // Assert
            converter.CanRead.ShouldBeTrue();
            converter.CanWrite.ShouldBeTrue();
        }
Exemplo n.º 10
0
 public Candle(long timeEpoch, decimal low, decimal high, decimal open, decimal close, decimal volume)
 {
     Time   = EpochConverter.DateTimeFromUnixTimestampSeconds(timeEpoch);
     Low    = low;
     High   = high;
     Open   = open;
     Close  = close;
     Volume = volume;
 }
Exemplo n.º 11
0
 protected void SaveLastRunTimeToFile()
 {
     if (!this.Context.FileSystem.TryWriteTempFileAndRename(
             this.LastRunTimeFilePath,
             EpochConverter.ToUnixEpochSeconds(DateTime.UtcNow).ToString(),
             out Exception handledException))
     {
         this.Context.Tracer.RelatedError(this.CreateEventMetadata(handledException), "Failed to record run time");
     }
 }
Exemplo n.º 12
0
        private bool TryFetchUsingGvfsProtocol(GitProcess gitProcess, out string error)
        {
            if (!this.TryGetMaxGoodPrefetchPackTimestamp(out long last, out error))
            {
                this.Context.Tracer.RelatedError(error);
                return(false);
            }

            TimeSpan timeBetween = this.GitObjects.IsUsingCacheServer()
                                    ? this.timeBetweenFetches
                                    : this.timeBetweenFetchesNoCacheServer;

            DateTime lastDateTime = EpochConverter.FromUnixEpochSeconds(last);
            DateTime now          = DateTime.UtcNow;

            if (!this.forceRun && now <= lastDateTime + timeBetween)
            {
                this.Context.Tracer.RelatedInfo(this.Area + ": Skipping fetch since most-recent fetch ({0}) is too close to now ({1})", lastDateTime, now);
                error = null;
                return(true);
            }

            // We take our own lock here to keep background and foreground fetches
            // (i.e. a user running 'scalar run fetch')
            // from running at the same time.
            using (FileBasedLock fetchLock = ScalarPlatform.Instance.CreateFileBasedLock(
                       this.Context.FileSystem,
                       this.Context.Tracer,
                       Path.Combine(this.Context.Enlistment.GitPackRoot, FetchCommitsAndTreesLock)))
            {
                WaitUntilLockIsAcquired(this.Context.Tracer, fetchLock);

                this.GitObjects.DeleteStaleTempPrefetchPackAndIdxs();
                this.GitObjects.DeleteTemporaryFiles();

                GitProcess.Result result = gitProcess.GvfsHelperPrefetch();

                if (result.ExitCodeIsFailure)
                {
                    error = result.Errors;
                    return(false);
                }

                this.UpdateKeepPacks();
            }

            error = null;
            return(true);
        }
Exemplo n.º 13
0
 public ExposureKeyMock()
 {
     _countryFactory = new CountryMockFactory();
     _rndGenerator   = new MockRandomGenerator();
     _epochConverter = new EpochConverter();
     _countries      = new List <string>()
     {
         "AT", "BE", "BG", "HR", "CY", "CZ", "DK", "EE", "FI", "FR",
         "GR", "HU", "IE", "IT", "LV", "LT", "LU", "MT", "NL", "PL",
         "PT", "RO", "SK", "SI", "ES", "SE"
     };
     _potentialDuplicate01 = MockValidKey();
     _potentialDuplicate02 = MockValidKey();
     MockListLength        = 5;
 }
Exemplo n.º 14
0
        private string CreateAuthenticationMessage(List <string> productTypes)
        {
            var timestamp     = EpochConverter.GetCurrentUnixTimestampSeconds().ToString(CultureInfo.InvariantCulture);
            var authenticator = new ApiAuthenticator(ApiKey, ApiSecret, ApiPassphrase, UseTimeApi, true, JsonSettings);

            return(JsonConvert.SerializeObject(new WsAuth
            {
                ProductTypes = productTypes,
                Key = ApiKey,
                Passphrase = ApiPassphrase,
                Signature = authenticator.GenerateSignature(timestamp, "GET", "/users/self", string.Empty, ApiSecret),
                Timestamp = timestamp,
                Type = "subscribe"
            }));
        }
Exemplo n.º 15
0
        public void Read()
        {
            // Arrange
            var json       = "1490711400";
            var jsonUtf8   = (ReadOnlySpan <byte>)Encoding.UTF8.GetBytes(json);
            var jsonReader = new Utf8JsonReader(jsonUtf8);
            var objectType = (Type)null;
            var options    = new JsonSerializerOptions();

            var converter = new EpochConverter();

            // Act
            jsonReader.Read();
            var result = converter.Read(ref jsonReader, objectType, options);

            // Assert
            result.ShouldBe(new DateTime(2017, 3, 28, 14, 30, 0, DateTimeKind.Utc));
        }
Exemplo n.º 16
0
        public void Init()
        {
            _riskCalulator     = new RiskCalculator();
            _exposureKeyMock   = new ExposureKeyMock();
            _webContextMock    = new WebContextMock();
            _mockSetup         = new SetupMockedServices();
            _webContextReader  = new Mock <IGatewayWebContextReader>(MockBehavior.Strict);
            _keyFilter         = new Mock <IKeyFilter>(MockBehavior.Strict);
            _tempKeyRepository = new Mock <ITemporaryExposureKeyRepository>(MockBehavior.Strict);
            _logger            = new Mock <ILogger <EFGSKeyStoreService> >();
            _epochConverter    = new EpochConverter();
            _onsetDaysDecoder  = new DaysSinceOnsetOfSymptomsDecoder();

            _mockSetup.SetupWebContextReaderMock(_webContextReader);
            _mockSetup.SetupKeyFilterMock(_keyFilter);
            _mockSetup.SetupTemopraryExposureKeyRepositoryMock(_tempKeyRepository);

            _keyStoreService = new EFGSKeyStoreService(_webContextReader.Object, _keyFilter.Object, _tempKeyRepository.Object, _logger.Object, _riskCalulator, _epochConverter, _onsetDaysDecoder);
        }
Exemplo n.º 17
0
        public void Write_null()
        {
            // Arrange
            var sb     = new StringBuilder();
            var sw     = new StringWriter(sb);
            var writer = new JsonTextWriter(sw);

            var value      = (DateTime?)null;
            var serializer = new JsonSerializer();

            var converter = new EpochConverter();

            // Act
            converter.WriteJson(writer, value, serializer);
            var result = sb.ToString();

            // Assert
            result.ShouldBeEmpty();
        }
Exemplo n.º 18
0
        public void Write()
        {
            // Arrange
            var sb     = new StringBuilder();
            var sw     = new StringWriter(sb);
            var writer = new JsonTextWriter(sw);

            var value      = new DateTime(2017, 3, 28, 14, 30, 0, DateTimeKind.Utc);
            var serializer = new JsonSerializer();

            var converter = new EpochConverter();

            // Act
            converter.WriteJson(writer, value, serializer);
            var result = sb.ToString();

            // Assert
            result.ShouldBe("1490711400");
        }
Exemplo n.º 19
0
        private EuGatewayService CreateGatewayServiceAndDependencies(IGatewayHttpClient httpClient)
        {
            _keysRepository = new TemporaryExposureKeyRepository(_dbContext, _countryRepository, _temporaryExposureKeyRepositoryLogger.Object);

            var signatureServiceMock = new Mock <ISignatureService>(MockBehavior.Strict);

            var webContextReader = new GatewayWebContextReader(_autoMapper, _loggerGatewayWebContextReader.Object);

            var epochConverter = new EpochConverter();

            var keyValidator        = new KeyValidator(epochConverter);
            var exposureKeyMapper   = new ExposureKeyMapper(_epochConverter);
            var keyFilterLoggerMock = new Mock <ILogger <KeyFilter> >(MockBehavior.Loose);
            var keyFilter           = new KeyFilter(_autoMapper, keyValidator, exposureKeyMapper, keyFilterLoggerMock.Object, _keysRepository);

            var storeServiceLoggerMock = new Mock <ILogger <EFGSKeyStoreService> >();

            var riskCalculator = new RiskCalculator();
            var dsosDecoder    = new DaysSinceOnsetOfSymptomsDecoder();
            var addTemporaryExposureKeyService = new Mock <IAddTemporaryExposureKeyService>(MockBehavior.Strict);

            addTemporaryExposureKeyService
            .Setup(x => x.FilterDuplicateKeysAsync(It.IsAny <List <TemporaryExposureKey> >()))
            .ReturnsAsync((List <TemporaryExposureKey> argument) =>
            {
                return(argument);
            });
            var storeService             = new EFGSKeyStoreService(keyFilter, _keysRepository, storeServiceLoggerMock.Object, riskCalculator, epochConverter, dsosDecoder, addTemporaryExposureKeyService.Object);
            var gatewayServiceLoggerMock = new Mock <ILogger <EuGatewayService> >(MockBehavior.Loose);

            return(CreateGatewayService(
                       _keysRepository,
                       signatureServiceMock.Object,
                       _autoMapper,
                       httpClient,
                       keyFilter,
                       webContextReader,
                       storeService,
                       gatewayServiceLoggerMock.Object,
                       epochConverter,
                       _config
                       ));
        }
Exemplo n.º 20
0
        public bool TryPauseMaintenanceUntil(DateTime time, out string errorMessage)
        {
            if (!this.TryCreateRepoRegistryDirectory(out errorMessage))
            {
                return(false);
            }

            string timeFileName = this.GetMaintenanceDelayFilePath();
            long   seconds      = EpochConverter.ToUnixEpochSeconds(time);

            if (!this.fileSystem.TryWriteAllText(timeFileName, seconds.ToString()))
            {
                errorMessage = $"Failed to write epoch {seconds} to '{timeFileName}'";
                return(false);
            }

            errorMessage = null;
            return(true);
        }
Exemplo n.º 21
0
        public void Read_date()
        {
            // Arrange
            var json = "1490711400";

            var textReader    = new StringReader(json);
            var jsonReader    = new JsonTextReader(textReader);
            var objectType    = (Type)null;
            var existingValue = (object)null;
            var serializer    = new JsonSerializer();

            var converter = new EpochConverter();

            // Act
            jsonReader.Read();
            var result = converter.ReadJson(jsonReader, objectType, existingValue, serializer);

            // Assert
            result.ShouldBe(new DateTime(2017, 3, 28, 14, 30, 0, DateTimeKind.Utc));
        }
Exemplo n.º 22
0
        public void Read_null()
        {
            // Arrange
            var json = "";

            var textReader    = new StringReader(json);
            var jsonReader    = new JsonTextReader(textReader);
            var objectType    = (Type)null;
            var existingValue = (object)null;
            var serializer    = new JsonSerializer();

            var converter = new EpochConverter();

            // Act
            jsonReader.Read();
            var result = converter.ReadJson(jsonReader, objectType, existingValue, serializer);

            // Assert
            result.ShouldBeNull();
        }
Exemplo n.º 23
0
        public void Write()
        {
            // Arrange
            var value      = new DateTime(2017, 3, 28, 14, 30, 0, DateTimeKind.Utc);
            var ms         = new MemoryStream();
            var jsonWriter = new Utf8JsonWriter(ms);
            var options    = new JsonSerializerOptions();

            var converter = new EpochConverter();

            // Act
            converter.Write(jsonWriter, value, options);
            jsonWriter.Flush();

            ms.Position = 0;
            var sr     = new StreamReader(ms);
            var result = sr.ReadToEnd();

            // Assert
            result.ShouldBe("1490711400");
        }
Exemplo n.º 24
0
        protected bool EnoughTimeBetweenRuns()
        {
            if (!this.Context.FileSystem.FileExists(this.LastRunTimeFilePath))
            {
                return(true);
            }

            string lastRunTime = this.Context.FileSystem.ReadAllText(this.LastRunTimeFilePath);

            if (!long.TryParse(lastRunTime, out long result))
            {
                this.Context.Tracer.RelatedError("Failed to parse long: {0}", lastRunTime);
                return(true);
            }

            if (DateTime.UtcNow.Subtract(EpochConverter.FromUnixEpochSeconds(result)) >= this.TimeBetweenRuns)
            {
                return(true);
            }

            return(false);
        }
Exemplo n.º 25
0
        public void FixedDates()
        {
            DateTime[] times = new DateTime[]
            {
                new DateTime(2018, 12, 13, 20, 53, 30, DateTimeKind.Utc),
                new DateTime(2035, 1, 3, 5, 0, 59, DateTimeKind.Utc),
                new DateTime(1989, 12, 31, 23, 59, 59, DateTimeKind.Utc)
            };
            long[] epochs = new long[]
            {
                1544734410,
                2051413259,
                631151999
            };

            for (int i = 0; i < times.Length; i++)
            {
                long epoch = EpochConverter.ToUnixEpochSeconds(times[i]);
                epoch.ShouldEqual(epochs[i]);

                DateTime time = EpochConverter.FromUnixEpochSeconds(epochs[i]);
                time.ShouldEqual(times[i]);
            }
        }
Exemplo n.º 26
0
        private void TestSetup(DateTime lastRun)
        {
            string lastRunTime = EpochConverter.ToUnixEpochSeconds(lastRun).ToString();

            this.gitProcess = new MockGitProcess();

            // Create enlistment using git process
            GVFSEnlistment enlistment = new MockGVFSEnlistment(this.gitProcess);

            // Create a last run time file
            MockFile timeFile = new MockFile(Path.Combine(enlistment.GitObjectsRoot, "info", PackfileMaintenanceStep.PackfileLastRunFileName), lastRunTime);

            // Create info directory to hold last run time file
            MockDirectory info = new MockDirectory(
                Path.Combine(enlistment.GitObjectsRoot, "info"),
                null,
                new List <MockFile>()
            {
                timeFile
            });

            // Create pack info
            MockDirectory pack = new MockDirectory(
                enlistment.GitPackRoot,
                null,
                new List <MockFile>()
            {
                new MockFile(Path.Combine(enlistment.GitPackRoot, "pack-1.pack"), "one"),
                new MockFile(Path.Combine(enlistment.GitPackRoot, "pack-1.idx"), "1"),
                new MockFile(Path.Combine(enlistment.GitPackRoot, "pack-2.pack"), "two"),
                new MockFile(Path.Combine(enlistment.GitPackRoot, "pack-2.idx"), "2"),
                new MockFile(Path.Combine(enlistment.GitPackRoot, "pack-3.pack"), "three"),
                new MockFile(Path.Combine(enlistment.GitPackRoot, "pack-3.idx"), "3"),
                new MockFile(Path.Combine(enlistment.GitPackRoot, KeepName), string.Empty),
                new MockFile(Path.Combine(enlistment.GitPackRoot, StaleIdxName), "4"),
            });

            // Create git objects directory
            MockDirectory gitObjectsRoot = new MockDirectory(enlistment.GitObjectsRoot, new List <MockDirectory>()
            {
                info, pack
            }, null);

            // Add object directory to file System
            List <MockDirectory> directories = new List <MockDirectory>()
            {
                gitObjectsRoot
            };
            PhysicalFileSystem fileSystem = new MockFileSystem(new MockDirectory(enlistment.EnlistmentRoot, directories, null));

            // Create and return Context
            this.tracer  = new MockTracer();
            this.context = new GVFSContext(this.tracer, fileSystem, repository: null, enlistment: enlistment);

            this.gitProcess.SetExpectedCommandResult(
                this.ExpireCommand,
                () => new GitProcess.Result(string.Empty, string.Empty, GitProcess.Result.SuccessCode));
            this.gitProcess.SetExpectedCommandResult(
                this.RepackCommand,
                () => new GitProcess.Result(string.Empty, string.Empty, GitProcess.Result.SuccessCode));
        }
Exemplo n.º 27
0
        private void TestSetup(DateTime lastRun)
        {
            string lastRunTime = EpochConverter.ToUnixEpochSeconds(lastRun).ToString();

            // Create GitProcess
            this.gitProcess = new MockGitProcess();
            this.gitProcess.SetExpectedCommandResult(
                PrunePackedCommand,
                () => new GitProcess.Result(string.Empty, string.Empty, GitProcess.Result.SuccessCode));

            // Create enlistment using git process
            ScalarEnlistment enlistment = new MockScalarEnlistment(this.gitProcess);

            string packPrefix = Path.Combine(enlistment.GitPackRoot, "from-loose");

            this.packCommand = $"pack-objects {packPrefix} --non-empty --window=0 --depth=0 -q";

            this.gitProcess.SetExpectedCommandResult(
                this.packCommand,
                () => new GitProcess.Result(string.Empty, string.Empty, GitProcess.Result.SuccessCode));

            // Create a last run time file
            MockFile timeFile = new MockFile(Path.Combine(enlistment.GitObjectsRoot, "info", LooseObjectsStep.LooseObjectsLastRunFileName), lastRunTime);

            // Create info directory to hold last run time file
            MockDirectory infoRoot = new MockDirectory(Path.Combine(enlistment.GitObjectsRoot, "info"), null, new List <MockFile>()
            {
                timeFile
            });

            // Create Hex Folder 1 with 1 File
            MockDirectory hex1 = new MockDirectory(
                Path.Combine(enlistment.GitObjectsRoot, "AA"),
                null,
                new List <MockFile>()
            {
                new MockFile(Path.Combine(enlistment.GitObjectsRoot, "AA", "1156f4f2b850673090c285289ea8475d629fe1"), "one")
            });

            // Create Hex Folder 2 with 2 Files
            MockDirectory hex2 = new MockDirectory(
                Path.Combine(enlistment.GitObjectsRoot, "F1"),
                null,
                new List <MockFile>()
            {
                new MockFile(Path.Combine(enlistment.GitObjectsRoot, "F1", "1156f4f2b850673090c285289ea8475d629fe2"), "two"),
                new MockFile(Path.Combine(enlistment.GitObjectsRoot, "F1", "1156f4f2b850673090c285289ea8475d629fe3"), "three")
            });

            // Create NonHex Folder with 4 Files
            MockDirectory nonhex = new MockDirectory(
                Path.Combine(enlistment.GitObjectsRoot, "ZZ"),
                null,
                new List <MockFile>()
            {
                new MockFile(Path.Combine(enlistment.GitObjectsRoot, "ZZ", "1156f4f2b850673090c285289ea8475d629fe4"), "4"),
                new MockFile(Path.Combine(enlistment.GitObjectsRoot, "ZZ", "1156f4f2b850673090c285289ea8475d629fe5"), "5"),
                new MockFile(Path.Combine(enlistment.GitObjectsRoot, "ZZ", "1156f4f2b850673090c285289ea8475d629fe6"), "6"),
                new MockFile(Path.Combine(enlistment.GitObjectsRoot, "ZZ", "1156f4f2b850673090c285289ea8475d629fe7"), "7")
            });

            MockDirectory pack = new MockDirectory(
                enlistment.GitPackRoot,
                null,
                new List <MockFile>());

            // Create git objects directory
            MockDirectory gitObjectsRoot = new MockDirectory(enlistment.GitObjectsRoot, new List <MockDirectory>()
            {
                infoRoot, hex1, hex2, nonhex, pack
            }, null);

            // Add object directory to file System
            List <MockDirectory> directories = new List <MockDirectory>()
            {
                gitObjectsRoot
            };
            PhysicalFileSystem fileSystem = new MockFileSystem(new MockDirectory(enlistment.EnlistmentRoot, directories, null));

            // Create and return Context
            this.tracer  = new MockTracer();
            this.context = new ScalarContext(this.tracer, fileSystem, enlistment: enlistment);
        }
Exemplo n.º 28
0
        private void TestSetup(DateTime lastRun)
        {
            string lastRunTime = EpochConverter.ToUnixEpochSeconds(lastRun).ToString();

            // Create GitProcess
            this.gitProcess = new MockGitProcess();
            this.gitProcess.SetExpectedCommandResult(
                PrunePackedCommand,
                () => new GitProcess.Result(string.Empty, string.Empty, GitProcess.Result.SuccessCode));

            // Create enlistment using git process
            GVFSEnlistment enlistment = new MockGVFSEnlistment(this.gitProcess);

            // Create a last run time file
            MockFile timeFile = new MockFile(Path.Combine(enlistment.GitObjectsRoot, "info", LooseObjectsStep.LooseObjectsLastRunFileName), lastRunTime);

            // Create info directory to hold last run time file
            MockDirectory infoRoot = new MockDirectory(Path.Combine(enlistment.GitObjectsRoot, "info"), null, new List <MockFile>()
            {
                timeFile
            });

            // Create Hex Folder 1 with 1 File
            MockDirectory hex1 = new MockDirectory(
                Path.Combine(enlistment.GitObjectsRoot, "AA"),
                null,
                new List <MockFile>()
            {
                new MockFile(Path.Combine(enlistment.GitObjectsRoot, "AA", "test"), string.Empty)
            });

            // Create Hex Folder 2 with 2 Files
            MockDirectory hex2 = new MockDirectory(
                Path.Combine(enlistment.GitObjectsRoot, "F1"),
                null,
                new List <MockFile>()
            {
                new MockFile(Path.Combine(enlistment.GitObjectsRoot, "F1", "test1"), string.Empty),
                new MockFile(Path.Combine(enlistment.GitObjectsRoot, "F1", "test2"), string.Empty)
            });

            // Create NonHex Folder with 4 Files
            MockDirectory nonhex = new MockDirectory(
                Path.Combine(enlistment.GitObjectsRoot, "ZZ"),
                null,
                new List <MockFile>()
            {
                new MockFile(Path.Combine(enlistment.GitObjectsRoot, "ZZ", "test1"), string.Empty),
                new MockFile(Path.Combine(enlistment.GitObjectsRoot, "ZZ", "test2"), string.Empty),
                new MockFile(Path.Combine(enlistment.GitObjectsRoot, "ZZ", "test3"), string.Empty),
                new MockFile(Path.Combine(enlistment.GitObjectsRoot, "ZZ", "test4"), string.Empty)
            });

            // Create git objects directory
            MockDirectory gitObjectsRoot = new MockDirectory(enlistment.GitObjectsRoot, new List <MockDirectory>()
            {
                infoRoot, hex1, hex2, nonhex
            }, null);

            // Add object directory to file System
            List <MockDirectory> directories = new List <MockDirectory>()
            {
                gitObjectsRoot
            };
            PhysicalFileSystem fileSystem = new MockFileSystem(new MockDirectory(enlistment.EnlistmentRoot, directories, null));

            // Create and return Context
            this.tracer  = new MockTracer();
            this.context = new GVFSContext(this.tracer, fileSystem, repository: null, enlistment: enlistment);
        }