예제 #1
0
        private bool TryLoadSettings(out string error)
        {
            if (this.allSettings == null)
            {
                FileBasedDictionary <string, string> config = null;
                if (FileBasedDictionary <string, string> .TryCreate(
                        tracer: null,
                        dictionaryPath: this.configFile,
                        fileSystem: this.fileSystem,
                        output: out config,
                        error: out error,
                        keyComparer: StringComparer.OrdinalIgnoreCase))
                {
                    this.allSettings = config;
                    return(true);
                }

                return(false);
            }

            error = null;
            return(true);
        }
예제 #2
0
        private bool TryGetLocalCacheKeyFromRemoteCacheServers(
            ITracer tracer,
            ServerGSDConfig serverGSDConfig,
            CacheServerInfo currentCacheServer,
            FileBasedDictionary <string, string> mappingFile,
            out string localCacheKey,
            out string error)
        {
            error         = null;
            localCacheKey = null;

            try
            {
                if (this.TryFindExistingLocalCacheKey(mappingFile, serverGSDConfig.CacheServers, out localCacheKey))
                {
                    EventMetadata metadata = CreateEventMetadata();
                    metadata.Add("currentCacheServer", currentCacheServer.ToString());
                    metadata.Add("localCacheKey", localCacheKey);
                    metadata.Add("this.enlistment.RepoUrl", this.enlistment.RepoUrl);
                    metadata.Add(TracingConstants.MessageKey.InfoMessage, nameof(this.TryGetLocalCacheKeyFromRemoteCacheServers) + ": Found an existing a local key by cross referencing");
                    tracer.RelatedEvent(EventLevel.Informational, "LocalCacheResolver_ExistingKeyFromCrossReferencing", metadata);
                }
                else
                {
                    localCacheKey = Guid.NewGuid().ToString("N");

                    EventMetadata metadata = CreateEventMetadata();
                    metadata.Add("currentCacheServer", currentCacheServer.ToString());
                    metadata.Add("localCacheKey", localCacheKey);
                    metadata.Add("this.enlistment.RepoUrl", this.enlistment.RepoUrl);
                    metadata.Add(TracingConstants.MessageKey.InfoMessage, nameof(this.TryGetLocalCacheKeyFromRemoteCacheServers) + ": Generated a new local key after cross referencing");
                    tracer.RelatedEvent(EventLevel.Informational, "LocalCacheResolver_NewKeyAfterCrossReferencing", metadata);
                }

                List <KeyValuePair <string, string> > mappingFileUpdates = new List <KeyValuePair <string, string> >();

                mappingFileUpdates.Add(new KeyValuePair <string, string>(this.ToMappingKey(this.enlistment.RepoUrl), localCacheKey));

                if (currentCacheServer.HasValidUrl())
                {
                    mappingFileUpdates.Add(new KeyValuePair <string, string>(this.ToMappingKey(currentCacheServer.Url), localCacheKey));
                }

                foreach (CacheServerInfo cacheServer in serverGSDConfig.CacheServers)
                {
                    string persistedLocalCacheKey;
                    if (mappingFile.TryGetValue(this.ToMappingKey(cacheServer.Url), out persistedLocalCacheKey))
                    {
                        if (!string.Equals(persistedLocalCacheKey, localCacheKey, StringComparison.OrdinalIgnoreCase))
                        {
                            EventMetadata metadata = CreateEventMetadata();
                            metadata.Add("cacheServer", cacheServer.ToString());
                            metadata.Add("persistedLocalCacheKey", persistedLocalCacheKey);
                            metadata.Add("localCacheKey", localCacheKey);
                            metadata.Add("currentCacheServer", currentCacheServer.ToString());
                            metadata.Add("this.enlistment.RepoUrl", this.enlistment.RepoUrl);
                            tracer.RelatedWarning(metadata, nameof(this.TryGetLocalCacheKeyFromRemoteCacheServers) + ": Overwriting persisted cache key with new value");

                            mappingFileUpdates.Add(new KeyValuePair <string, string>(this.ToMappingKey(cacheServer.Url), localCacheKey));
                        }
                    }
                    else
                    {
                        mappingFileUpdates.Add(new KeyValuePair <string, string>(this.ToMappingKey(cacheServer.Url), localCacheKey));
                    }
                }

                mappingFile.SetValuesAndFlush(mappingFileUpdates);
            }
            catch (Exception e)
            {
                EventMetadata metadata = CreateEventMetadata(e);
                tracer.RelatedError(metadata, nameof(this.TryGetLocalCacheKeyFromRemoteCacheServers) + ": Caught exception while getting local key");
                error = string.Format("Exception while getting local cache key: {0}", e.Message);
                return(false);
            }

            return(true);
        }