Ejemplo n.º 1
0
        private static void UpdateAesKey(IDictionary <string, object> dictionary)
        {
            string aesKeyString = AppSettingsHelper.Get(GlobalSettingKey.CRYPTOGRAPHY_AES_KEY);

            if (string.IsNullOrEmpty(aesKeyString))
            {
                return;
                //throw new MissingAppSettingException("Cryptography AES Key", GlobalSettingKey.CRYPTOGRAPHY_AES_KEY.Key);
            }

            byte[] aesKey;

            try
            {
                aesKey = StringHelper.StringToByteArray(aesKeyString, ',');
            }
            catch (Exception exception)
            {
                throw new Exception(
                          $"Cannot convert the following comma separated string to byte array. Tip: numbers should be between 0 and 255. \n{aesKeyString}",
                          exception);
            }

            if (aesKey.Length != 32)
            {
                throw new Exception(
                          $"{GlobalSettingKey.CRYPTOGRAPHY_AES_KEY.Key} has an invalid lenght (= {aesKey.Length}) (32 bytes are expected). \nOriginal value: \n{aesKeyString}");
            }

            dictionary.AddOrUpdate(GlobalSettingKey.CRYPTOGRAPHY_AES_KEY.Key, aesKey);
        }
Ejemplo n.º 2
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }

            app.UseHttpsRedirection();
            app.UseRouting();

            app.UseCors(x => x.AllowAnyOrigin().AllowAnyMethod().AllowAnyHeader());

            app.UseEndpoints(endpoints =>
            {
                endpoints.MapControllers();
            });

            app.UseSwagger();

            app.UseSwaggerUI(c =>
            {
                c.RoutePrefix = AppSettingsHelper.Get("Swagger", "RoutePrefix");
                c.SwaggerEndpoint($"{AppSettingsHelper.Get("Swagger", "Version")}/swagger.json", AppSettingsHelper.Get("Swagger", "Title"));
            });
        }
        public static bool SendEmail(string subject, string body)
        {
            string emailFrom  = AppSettingsHelper.Get("EmailFrom");
            string emailTo    = AppSettingsHelper.Get("EmailTo");
            string smtpServer = AppSettingsHelper.Get("SMTPServer");

            return(SendEmail(subject, body, emailFrom, emailTo, smtpServer));
        }
        /// <summary>
        /// Get the current application name.
        /// </summary>
        public static string GetAppName()
        {
            string appName = AppSettingsHelper.Get("AppName");

            if (appName != null)
            {
                appName = appName.Trim();
            }
            return(appName);
        }
Ejemplo n.º 5
0
        private static void UpdateVersion(IDictionary <string, object> dictionary)
        {
            string ver = AppSettingsHelper.Get(GlobalSettingKey.APPLICATION_VERSION);

            if (string.IsNullOrWhiteSpace(ver))
            {
                return;
            }

            dictionary.AddOrUpdate(GlobalSettingKey.APPLICATION_VERSION.Key, new Version(ver));
        }
Ejemplo n.º 6
0
        private void UpdateIdObfuscation(IDictionary <string, object> dictionary)
        {
            bool?idObfuscation = AppSettingsHelper.Get(GlobalSettingKey.ID_OBFUSCATION);

            if (!idObfuscation.HasValue)
            {
                return;
            }

            dictionary.AddOrUpdate(GlobalSettingKey.ID_OBFUSCATION.Key, idObfuscation.Value);
        }
Ejemplo n.º 7
0
        protected bool IsValidPassword()
        {
            string userPassword  = GetQueryString("password");
            string adminPassword = AppSettingsHelper.Get("AdminPassword", "UnloadAppDomain1000tj");

            // make sure password was set
            if (userPassword == null || adminPassword == null)
            {
                return(false);
            }

            // check if password is correct
            return(Utility.IsMatch(userPassword, adminPassword));
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Gets the value showing if <see cref="GlobalSetting"/>.FriendlyCompanyName is expected as the prefix for appSetting's key.
        /// </summary>
        // TODO: It's better to remove this and automatically search for "Key", "CompanyName.Key", "ApplicationName.Key" in the web.config file.
        //public bool ApplicationNameAsKeyPrefix { get; private set; }

        public IDictionary <string, object> Get()
        {
            var appSettings = System.Configuration.ConfigurationManager.AppSettings;
            var dictionary  = appSettings.Cast <string>().ToDictionary(s => s, s => (object)appSettings[s]);

            UpdateAesKey(dictionary);
            UpdateIdObfuscation(dictionary);
            dictionary.AddOrUpdate(GlobalSettingKey.LOGMANAGER_LOGLEVEL.Key, AppSettingsHelper.Get(GlobalSettingKey.LOGMANAGER_LOGLEVEL));
            dictionary.AddOrUpdate(GlobalSettingKey.MEMORYCACHE_ABSOLUTE_EXPIRATION.Key, AppSettingsHelper.Get(GlobalSettingKey.MEMORYCACHE_ABSOLUTE_EXPIRATION));
            dictionary.AddOrUpdate(GlobalSettingKey.RECAPTCHA2_ENABLE.Key, AppSettingsHelper.Get(GlobalSettingKey.RECAPTCHA2_ENABLE));
            UpdateRecaptcha2Url(dictionary);
            UpdateVersion(dictionary);

            return(dictionary);
        }
Ejemplo n.º 9
0
        private static void UpdateRecaptcha2Url(IDictionary <string, object> dictionary)
        {
            string url = AppSettingsHelper.Get(GlobalSettingKey.RECAPTCHA2_URL);

            if (string.IsNullOrWhiteSpace(url))
            {
                return;
            }

            if (!Uri.IsWellFormedUriString(url, UriKind.Absolute))
            {
                throw new BadAppSettingException(GlobalSettingKey.RECAPTCHA2_URL.Key, url, typeof(Uri));
            }

            dictionary.AddOrUpdate(GlobalSettingKey.RECAPTCHA2_URL.Key, new Uri(url));
        }
Ejemplo n.º 10
0
        private void btnReadConnStrs_Click(object sender, EventArgs e)
        {
            txtConnStrs.Clear();
            if (CustomConfigHelper.Connections != null)
            {
                foreach (ConnectionElement element in CustomConfigHelper.Connections)
                {
                    txtConnStrs.AppendText(string.Format("Name = {0}, Conn = {1}, Read = {2}, Write = {3}{4}", element.ConnName, element.ConnString, element.ReadString, element.WriteString, Environment.NewLine));
                    txtConnStrs.AppendText(ConnectionStringConfigReader.GetDefaultConnectionString(element.ConnName) + Environment.NewLine);
                }
            }
            var configroot = AppSettingsHelper.Get();

            if (configroot != null)
            {
                txtConnStrs.AppendText(configroot.GetSection("TestConfig:SubTestConfig:Item1").Value);
                txtConnStrs.AppendText(configroot.GetSection("TestConfig:SubTestConfig").GetValue <string>("Item2"));
                txtConnStrs.AppendText(configroot.GetSection("TestConfig:SubTestConfig").GetValue <string>("Item3", "Item3Value"));
            }
        }
 /// <summary>
 /// Get the client name from the web.config.
 /// </summary>
 public static string GetClientNameFromConfig()
 {
     return(AppSettingsHelper.Get("ClientName"));
 }
 public void AppSettingsHelper_Get_SettingsPropertyNotFoundException(string appKey)
 {
     Assert.Throws <SettingsPropertyNotFoundException>(delegate { AppSettingsHelper.Get <string>(appKey); });
 }
 public void AppSettingsHelper_Get_InvalidCastException()
 {
     Assert.Throws <InvalidCastException>(delegate { AppSettingsHelper.Get <int>("IntKeyException"); });
 }
        public void AppSettingsHelper_Get_ReturnsExpectedType()
        {
            var result = AppSettingsHelper.Get <int>("IntKey");

            Assert.That(result, Is.TypeOf(typeof(int)));
        }
Ejemplo n.º 15
0
        static void Main(string[] args)
        {
#if DEBUG
            System.Diagnostics.Debugger.Launch();
#endif
            var p4Model       = new PerforceCommand();
            var parsingStatus = Parser.Default.ParseArguments(args, p4Model);

            try
            {
                if (!parsingStatus)
                {
                    Log.Info(p4Model.GetUsage());
                    return;
                }
                else
                {
                    if (p4Model.LoadFromConfig)
                    {
                        if (p4Model.Verbose)
                        {
                            Log.Info(LoggingStrings.LoadingConfigFile);
                        }
                        try
                        {
                            if (string.IsNullOrWhiteSpace(p4Model.Server))
                            {
                                p4Model.Server = AppSettingsHelper.Get <string>(ResourceStrings.PerforceServerKey);
                            }
                            if (string.IsNullOrWhiteSpace(p4Model.Username))
                            {
                                p4Model.Username = AppSettingsHelper.Get <string>(ResourceStrings.PerforceUsernameKey);
                            }
                            if (string.IsNullOrWhiteSpace(p4Model.Password))
                            {
                                p4Model.Password = AppSettingsHelper.Get <string>(ResourceStrings.PerforcePasswordKey);
                            }
                            if (string.IsNullOrWhiteSpace(p4Model.Timeout.ToString()))
                            {
                                p4Model.Timeout = AppSettingsHelper.Get <int>(ResourceStrings.PerforceTimeoutKey);
                            }
                        }
                        catch (Exception ex)
                        {
                            throw new Exception(ex.Message);
                        }
                    }
                    if (p4Model.Verbose)
                    {
                        Log.Info(string.Format(LoggingStrings.ConnectingLogging, p4Model.Server, p4Model.Username, p4Model.Location, string.Join(ResourceStrings.SourceListJoiner, p4Model.SourcesList)));
                    }
                    var p4Repo          = PerforceHelpers.GetPerforceRepo(p4Model.Server, p4Model.Username, p4Model.Password, p4Model.Timeout);
                    var dictionaryToUse = PerforceHelpers.CreateSourceDictionary(p4Repo, p4Model.Location, p4Model.SourcesList.ToList());
                    foreach (var entry in dictionaryToUse)
                    {
                        if (p4Model.Verbose)
                        {
                            Log.Info(string.Format(LoggingStrings.CopyFileLogging, entry.Value, entry.Key));
                        }
                        PerforceHelpers.CopyFile(p4Repo, entry.Key, entry.Value);
                    }
                    if (p4Model.Verbose)
                    {
                        Log.Info(LoggingStrings.LoggingOut);
                    }
                    PerforceHelpers.PerforceLogout(p4Repo);
                }
            }
            catch (Exception ex)
            {
                Log.Error(ex.Message);
            }
        }