Пример #1
0
        private bool TryOpenMappingFile(ITracer tracer, string localCacheRoot, out FileBasedDictionary <string, string> mappingFile, out string errorMessage)
        {
            mappingFile  = null;
            errorMessage = string.Empty;

            string error;
            string mappingFilePath = Path.Combine(localCacheRoot, MappingFile);

            if (!FileBasedDictionary <string, string> .TryCreate(
                    tracer,
                    mappingFilePath,
                    this.fileSystem,
                    out mappingFile,
                    out error))
            {
                errorMessage = "Could not open mapping file for local cache: " + error;

                EventMetadata metadata = CreateEventMetadata();
                metadata.Add("mappingFilePath", mappingFilePath);
                metadata.Add("error", error);
                tracer.RelatedError(metadata, "TryOpenMappingFile: Could not open mapping file for local cache");

                return(false);
            }

            return(true);
        }
Пример #2
0
        public static bool TryInitialize(ITracer tracer, PhysicalFileSystem fileSystem, string dotGSDPath, out string error)
        {
            string dictionaryPath = Path.Combine(dotGSDPath, GSDConstants.DotGSD.Databases.RepoMetadata);

            if (Instance != null)
            {
                if (!Instance.repoMetadata.DataFilePath.Equals(dictionaryPath, StringComparison.OrdinalIgnoreCase))
                {
                    throw new InvalidOperationException(
                              string.Format(
                                  "TryInitialize should never be called twice with different parameters. Expected: '{0}' Actual: '{1}'",
                                  Instance.repoMetadata.DataFilePath,
                                  dictionaryPath));
                }
            }
            else
            {
                Instance = new RepoMetadata(tracer);
                if (!FileBasedDictionary <string, string> .TryCreate(
                        tracer,
                        dictionaryPath,
                        fileSystem,
                        out Instance.repoMetadata,
                        out error))
                {
                    return(false);
                }
            }

            error = null;
            return(true);
        }
Пример #3
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);
        }