public static void ScafoldAppConfig(bool isSetToDefault = false)
        {
            if (string.IsNullOrEmpty(GetAppSettings <string>("ServiceDisplayName")) || isSetToDefault)
            {
                var defaultConfiguration = new ApplicationConfigurationModel().GetDefalultApplicationConfiguration();

                if (!string.IsNullOrEmpty(defaultConfiguration.ServiceDisplayName))
                {
                    SetAppSettings <string>("ServiceDisplayName", defaultConfiguration.ServiceDisplayName);
                }

                if (!string.IsNullOrEmpty(defaultConfiguration.ServiceName))
                {
                    SetAppSettings <string>("ServiceName", defaultConfiguration.ServiceName);
                }

                if (!string.IsNullOrEmpty(defaultConfiguration.InstallationLocation))
                {
                    SetAppSettings <string>("InstallationLocation", defaultConfiguration.InstallationLocation);
                }

                if (!string.IsNullOrEmpty(defaultConfiguration.InstallerLocation))
                {
                    SetAppSettings <string>("InstallerLocation", defaultConfiguration.InstallerLocation);
                }

                if (!string.IsNullOrEmpty(defaultConfiguration.PrinterSettingDirectory))
                {
                    SetAppSettings <string>("PrinterSettingDirectory", defaultConfiguration.PrinterSettingDirectory);
                }
            }
        }
        public void ResetForm()
        {
            var setting = ApplicationConfig.Instance;

            _appConfig = new ApplicationConfigurationModel
            {
                InstallationLocation    = setting.Settings.InstallationLocation,
                InstallerLocation       = setting.Settings.InstallerLocation,
                PrinterSettingDirectory = setting.Settings.PrinterSettingDirectory,
                ServiceDisplayName      = setting.Settings.ServiceDisplayName,
                ServiceName             = setting.Settings.ServiceName
            };
        }
        public static void UpdateAppSetting(ApplicationConfigurationModel model)
        {
            SetAppSettings <string>("ServiceDisplayName", model.ServiceDisplayName);
            SetAppSettings <string>("ServiceName", model.ServiceName);
            SetAppSettings <string>("InstallationLocation", model.InstallationLocation);
            SetAppSettings <string>("InstallerLocation", model.InstallerLocation);
            SetAppSettings <string>("PrinterSettingDirectory", model.PrinterSettingDirectory);

            //update applicaton Setting
            var setting = ApplicationConfig.Instance;

            setting.UpdateSetting();
        }
Exemple #4
0
        public HttpResponseMessage AddApplicationConfiguration(ApplicationConfigurationModel applicationConfigurationModel)
        {
            if (applicationConfigurationModel == null)
            {
                return(this.Request.CreateErrorResponse(HttpStatusCode.BadRequest, "Invalid application configuration model."));
            }

            if (this.ModelState.IsValid && applicationConfigurationModel.ApplicationConfigurationEntries.Count > 0)
            {
                var data = this.applicationConfigurationService.AddApplicationConfiguration(applicationConfigurationModel);
                return(this.Request.CreateResponse(HttpStatusCode.OK, data));
            }

            if (applicationConfigurationModel.ApplicationConfigurationEntries.Count == 0)
            {
                return(this.Request.CreateErrorResponse(HttpStatusCode.BadRequest, "Application configuration entries must required."));
            }

            // Create an error message for returning
            string messages = string.Join("; ", this.ModelState.Values.SelectMany(x => x.Errors).Select(x => x.ErrorMessage));

            return(this.Request.CreateErrorResponse(HttpStatusCode.BadRequest, messages));
        }
        private IReadOnlyDictionary <string, IConfigurationElement> LoadParameters()
        {
            string loadedContent;

            if (configurationFileLoader != null)
            {
                using Stream stream       = configurationFileLoader(configurationFile);
                using StreamReader reader = new StreamReader(stream);

                // Appel synchrone, car l'appel asynchrone peut ne pas aboutir.
                loadedContent = reader.ReadToEnd();
            }
            else
            {
                using StreamReader reader = File.OpenText(configurationFile);
                loadedContent             = reader.ReadToEnd();
            }

            JsonSerializerOptions options = new JsonSerializerOptions()
            {
                AllowTrailingCommas = true,
            };

            ApplicationConfigurationModel baseConfiguration = JsonSerializer.Deserialize <ApplicationConfigurationModel>(loadedContent, options);

            loadedContent = null;

            foreach (ConfigurationElement parameter in baseConfiguration.Parameters)
            {
                if (parameter?.Value is JsonElement parameterValue)
                {
                    parameter.Value = JsonSerializer.Deserialize(parameterValue.GetRawText(), Type.GetType(parameter.ElementType));
                }
            }

            return(new ReadOnlyDictionary <string, IConfigurationElement>(baseConfiguration.Parameters.ToDictionary(k => k.Name, v => v as IConfigurationElement)));
        }
Exemple #6
0
        ResponseModel IApplicationConfigurationService.AddApplicationConfiguration(ApplicationConfigurationModel applicationConfigurationModel)
        {
            var applicationConfiguration = this.dbContext.ApplicationConfiguration.FirstOrDefault(a => a.ConfigurationType.Equals(applicationConfigurationModel.ApplicationConfigurationType.Trim(), StringComparison.InvariantCultureIgnoreCase));

            if (applicationConfiguration == null)
            {
                return(new ResponseModel(StatusCode.Error, "Invalid application configuration type."));
            }

            // adding notificationClickActionEntry in database required for data services component.
            if (applicationConfigurationModel.ApplicationConfigurationType.Trim().Equals(ApiConstant.FirebaseApplicationConfiguration, StringComparison.InvariantCultureIgnoreCase))
            {
                var notificationClickActionEntry = applicationConfiguration.ApplicationConfigurationEntry.FirstOrDefault(e => e.ConfigurationKey.Equals(ApiConstant.NotificationClickActionKey, StringComparison.InvariantCultureIgnoreCase));

                if (notificationClickActionEntry == null)
                {
                    var configEntry = new ApplicationConfigurationEntry()
                    {
                        ConfigurationKey           = ApiConstant.NotificationClickActionKey,
                        ConfigurationValue         = ApiConfiguration.NotificationClickAction,
                        ApplicationConfigurationId = applicationConfiguration.Id,
                        CreatedBy = this.context.Current.UserId,
                        CreatedOn = DateTime.UtcNow
                    };

                    this.dbContext.ApplicationConfigurationEntry.Add(configEntry);
                }
                else if (!notificationClickActionEntry.ConfigurationValue.Equals(ApiConfiguration.NotificationClickAction, StringComparison.InvariantCultureIgnoreCase))
                {
                    notificationClickActionEntry.ConfigurationValue = ApiConfiguration.NotificationClickAction;
                    notificationClickActionEntry.ModifiedBy         = this.context.Current.UserId;
                    notificationClickActionEntry.ModifiedOn         = DateTime.UtcNow;
                }
            }

            foreach (var applicationConfigurationEntry in applicationConfigurationModel.ApplicationConfigurationEntries)
            {
                var updateConfig = applicationConfiguration.ApplicationConfigurationEntry.FirstOrDefault(e => e.ConfigurationKey.Equals(applicationConfigurationEntry.ConfigurationKey, StringComparison.InvariantCultureIgnoreCase));

                if (updateConfig != null)
                {
                    updateConfig.ConfigurationValue = applicationConfigurationEntry.ConfigurationValue;
                    updateConfig.ModifiedBy         = this.context.Current.UserId;
                    updateConfig.ModifiedOn         = DateTime.UtcNow;
                }
                else
                {
                    var configEntry = new ApplicationConfigurationEntry()
                    {
                        ConfigurationKey           = applicationConfigurationEntry.ConfigurationKey,
                        ConfigurationValue         = applicationConfigurationEntry.ConfigurationValue,
                        ApplicationConfigurationId = applicationConfiguration.Id,
                        CreatedBy = this.context.Current.UserId,
                        CreatedOn = DateTime.UtcNow
                    };

                    this.dbContext.ApplicationConfigurationEntry.Add(configEntry);
                }
            }

            this.dbContext.SaveChanges();
            return(new ResponseModel(StatusCode.Ok, "Application configuration added successfully."));
        }