Beispiel #1
0
        public void Read(UserProfile profile, out BindableCollection <Addon> addons, out BindableCollection <LaunchParameter> parameters, out LaunchSettings launchSettings)
        {
            Logger.LogDebug("ProfileService", "Reading profile from disk");

            try
            {
                ProfileFile profileFile = new ProfileFile {
                    Profile = profile
                };

                var settings = new JsonSerializerSettings {
                    Converters = { new JsonLaunchParameterConverter() }
                };
                JsonConvert.PopulateObject(_fileAccessor.ReadAllText(Path.Combine(ApplicationConfig.ConfigPath, ApplicationConfig.ProfilesFolder,
                                                                                  string.Format(ApplicationConfig.ProfileNameFormat, profile.Id))), profileFile, settings);

                addons         = profileFile.Addons;
                parameters     = profileFile.Parameters;
                launchSettings = profileFile.LaunchSettings;
            }
            catch (Exception e)
            {
                Logger.LogException("ProfileService", "Error reading profile", e);
                addons         = new BindableCollection <Addon>();
                parameters     = new BindableCollection <LaunchParameter>();
                launchSettings = new LaunchSettings();
            }
        }
Beispiel #2
0
        public void TEMPLATE_IS_PUT_WHEN_IS_VALID()
        {
            //Arrange
            var template = new TemplateInfo(_fileAccessor, _eventWriter)
            {
                FileName = "file",
                Name     = "template"
            };
            var rawBody = "body";

            _fileAccessor.Exists("file").Returns(true);
            _fileAccessor.ReadAllText(template.FileName).Returns(rawBody);
            template.ActivateOptions();
            var appender = new ElasticSearchAppender(_elasticClientFactory, "index", "type", _timer,
                                                     _tolerateCallsFactory,
                                                     _bulk, _logEventConverterFactory, _elasticFilters, _fileAccessor, _eventWriter)
            {
                Template = template
            };

            //Act
            appender.ActivateOptions();

            //Assert
            _elasticClient.Received().PutTemplateRaw(template.Name, rawBody);
        }
Beispiel #3
0
        public override void ActivateOptions()
        {
            AddOptionalServer();
            _client = _elasticClientFactory.CreateClient(Servers, ElasticSearchTimeout, Ssl, AllowSelfSignedServerCert, AuthenticationMethod);

            _logEventConverter = _logEventConverterFactory.Create(FixedFields, SerializeObjects);

            if (Template != null && Template.IsValid)
            {
                if (IndexAsync)
                {
                    _client.PutTemplateRaw(Template.Name, _fileAccessor.ReadAllText(Template.FileName));
                }
                else
                {
                    _client.PutTemplateRaw(Template.Name, _fileAccessor.ReadAllText(Template.FileName));
                }
            }

            ElasticFilters.PrepareConfiguration(_client);

            _timer.Restart(BulkIdleTimeout);
        }
Beispiel #4
0
        public LoadSettingsResult Read()
        {
            Logger.LogDebug("SettingsService", "Reading settings from disk");

            var loadResult = LoadSettingsResult.NoExistingSettings;
            var configFile = new ConfigFile();

            //Try to ready legacy config if present
            if (LegacyConfigExists())
            {
                try
                {
                    configFile = ReadLegacy();
                    loadResult = LoadSettingsResult.LoadedLegacySettings;

                    ApplicationSettings = configFile.ApplicationSettings;
                    DefaultProfileId    = configFile.DefaultProfileId;
                    Write();
                }
                catch (Exception e)
                {
                    configFile = new ConfigFile();
                    loadResult = LoadSettingsResult.ErrorLoadingLegacySettings;
                    Logger.LogException("SettingsService", "Exception reading legacy settings", e);
                }
            }
            else
            {
                //Read existing config if present
                if (SettingsExist())
                {
                    try
                    {
                        JsonConvert.PopulateObject(_fileAccessor.ReadAllText(Path.Combine(ApplicationConfig.ConfigPath, ApplicationConfig.ConfigFileName)), configFile);
                        loadResult = LoadSettingsResult.LoadedExistingSettings;
                    }
                    catch (Exception e)
                    {
                        configFile = new ConfigFile();
                        loadResult = LoadSettingsResult.ErrorLoadingSettings;
                        Logger.LogException("SettingsService", "Exception reading settings", e);
                    }
                }
            }

            configFile.Servers = new BindableCollection <Server>(configFile.Servers.Union(ApplicationConfig.DefaultServers)); //Add default servers if they are not present

            DefaultProfileId = configFile.DefaultProfileId;

            foreach (var profile in configFile.Profiles)
            {
                UserProfiles.Add(new UserProfile(profile.Key, profile.Value, profile.Key == DefaultProfileId));
            }

            ApplicationSettings = configFile.ApplicationSettings;
            Servers             = configFile.Servers;

            //Set culture if no previous settings
            if (loadResult != LoadSettingsResult.LoadedExistingSettings)
            {
                var installedCulture = CultureInfo.InstalledUICulture.TwoLetterISOLanguageName;
                var cultureMatch     = ApplicationConfig.Languages.FirstOrDefault(l => l.StartsWith(installedCulture));
                if (cultureMatch != null)
                {
                    ApplicationSettings.Language = cultureMatch;
                }
            }
            Thread.CurrentThread.CurrentUICulture = CultureInfo.GetCultureInfo(ApplicationConfig.Languages.Contains(ApplicationSettings.Language)
                ? ApplicationSettings.Language
                : ApplicationConfig.Languages.First());

            Logger.LogDebug("SettingsService", $"Finished reading settings, result was: {loadResult}");

            return(loadResult);
        }