コード例 #1
0
ファイル: SettingsFileReader.cs プロジェクト: lkomanetz/Ecli
        public FileReaderResult Read(string settings)
        {
            try {
                JObject settingsJson = JObject.Parse(settings);
                IEnumerable <JProperty>       properties = settingsJson.Root.Select(p => (JProperty)p);
                IList <ISettingsReaderResult> contents   = new List <ISettingsReaderResult>();

                foreach (var kvp in _availableReaders)
                {
                    ISettingsReader       reader = kvp.Value;
                    ISettingsReaderResult readResult;
                    JProperty             prop = properties.Where(p => p.Name == kvp.Key).SingleOrDefault();

                    if (prop == null)
                    {
                        readResult = reader.Read(kvp.Key, String.Empty);
                    }
                    else
                    {
                        readResult = reader.Read(prop.Name, prop.Value.ToString());
                    }

                    contents.Add(readResult);
                }

                return(new SettingsFileReaderResult(contents, settingsJson));
            }
            catch (Exception err) {
                return(new SettingsFileReaderResult(err));
            }
        }
コード例 #2
0
 public NugetSettings(ISettingsReader reader)
 {
     model = reader.Read<SettingsModel>() ??
        new SettingsModel
        {
            WorkDirectory = AppDomain.CurrentDomain.BaseDirectory,
            Defaults = new SettingsDefaultsModel
            {
                IconUrl = "INPUT-DEFAULT-ICON-URL",
                LicenceUrl = "INPUT-DEFAULT-LICENCE-URL"
            }
        };
 }
コード例 #3
0
ファイル: SettingsPersistence.cs プロジェクト: palmettos/D2ID
        public ApplicationSettings Load(string filename)
        {
            ILegacySettingsResolver resolver = new DefaultLegacySettingsResolver();

            foreach (var factory in ReaderFactoryEnumeration(resolver, filename))
            {
                ISettingsReader reader = null;

                try
                {
                    // Create reader from factory.
                    reader = factory();

                    // Try to read settings.
                    ApplicationSettings settings = reader.Read();
                    if (settings != null)
                    {
                        Logger.Instance.WriteLine("Loaded settings from \"{0}\"", filename);

                        // Update current settings file.
                        if (CurrentSettingsFile != filename)
                        {
                            CurrentSettingsFile = filename;
                        }

                        return(settings);
                    }
                }
                // Stop iterating, file doesn't exist.
                catch (FileNotFoundException)
                {
                    break;
                }
                // Log other IO exceptions.
                catch (IOException e)
                {
                    Logger.Instance.WriteLine("Settings Error: [{0}] {1}", e.GetType().Name, e.Message);
                }
                finally
                {
                    if (reader != null)
                    {
                        reader.Dispose();
                    }
                }
            }

            // Failed to load.
            return(null);
        }
コード例 #4
0
        public static ApplicationSettings Load(string path)
        {
            ILegacySettingsResolver resolver = new DefaultLegacySettingsResolver();

            foreach (Func <ISettingsReader> factory in ReaderFactoryEnumeration(resolver, path))
            {
                ISettingsReader settingsReader = null;

                try
                {
                    settingsReader = factory();

                    // Try to read settings.
                    var settings = settingsReader.Read();
                    if (settings != null)
                    {
                        Logger.Info($"Loaded settings from \"{path}\"");

                        return(settings);
                    }
                }
                catch (DirectoryNotFoundException)
                {
                    Logger.Info($"Failed to read \"{path}\": Folder does not exist.");
                    return(null);
                }
                catch (FileNotFoundException)
                {
                    // Stop iterating, file doesn't exist.
                    break;
                }
                catch (IOException e)
                {
                    // Log other IO exceptions.
                    Logger.Warn("Failed to read settings", e);
                }
                finally
                {
                    settingsReader?.Dispose();
                }
            }

            // Failed to load.
            return(null);
        }
コード例 #5
0
ファイル: Settings.cs プロジェクト: yoger6/EasySettings
 private void LoadSettings(ISettingsReader reader)
 {
     _settings = reader.Read();
 }
コード例 #6
0
ファイル: EmailService.cs プロジェクト: devmankz/Depmon
 public EmailService(ISettingsReader settingsReader)
 {
     _config = settingsReader.Read();
 }
コード例 #7
0
 public NotificationService(IUnitOfWork unitOfWork, ISettingsReader settingsReader, IEmailService emailService)
 {
     _unitOfWork = unitOfWork;
     _emailService = emailService;
     _config = settingsReader.Read();
 }