Esempio n. 1
0
        private void SetupConfig(IServiceCollection services)
        {
            var config = GetConfigFromDB();

            _logger.LogInformation("Setting up configuration...");

            // Get encryption key
            _configuration["AppSettings:Secret"] = config.Configuration.GetValueOrDefault("encryption_key", string.Empty);
            // Get header key
            _configuration["AppSettings:HeaderKey"] = config.Configuration.GetValueOrDefault("header_key", string.Empty);

            var appSettingsSection = _configuration.GetSection("AppSettings");

            appSettingsSection["AppSettings:Secret"]    = _configuration["AppSettings:Secret"];
            appSettingsSection["AppSettings:HeaderKey"] = _configuration["AppSettings:HeaderKey"];

            var appSettings = appSettingsSection.Get <AppSettings>();

            appSettings.Secret = appSettingsSection["AppSettings:Secret"];
            HeaderKey.Set(appSettingsSection["AppSettings:HeaderKey"]);

            // Propagate the AppSettings throughout the API
            services.Configure <AppSettings>(_configuration.GetSection("AppSettings"));

            _logger.LogInformation("Configuration setup complete");
        }
Esempio n. 2
0
        public void OnAuthorization(AuthorizationFilterContext context)
        {
            var headerKey = HeaderKey.Get();

            if (!context.HttpContext.Request.Headers.ContainsKey("GameServerAuth") ||
                context.HttpContext.Request.Headers["GameServerAuth"] != headerKey)
            {
                context.Result = new ForbidResult();
            }
        }
Esempio n. 3
0
 internal void SetHeader()
 {
     if (!HeaderKey.IsNullOrEmpty() && !HeaderValue.IsNullOrEmpty())
     {
         OptionBuilder.Header.Add(HeaderKey, HeaderValue);
     }
     if (Headers != null && Headers.Count > 0)
     {
         Headers.ForDicEach((key, par) =>
         {
             OptionBuilder.Header.Add(key, par);
         });
     }
 }
Esempio n. 4
0
        public override int GetHashCode()
        {
            int hash = 1;

            if (Id.Length != 0)
            {
                hash ^= Id.GetHashCode();
            }
            hash ^= imageUrl_.GetHashCode();
            if (HeaderKey.Length != 0)
            {
                hash ^= HeaderKey.GetHashCode();
            }
            if (SubheaderKey.Length != 0)
            {
                hash ^= SubheaderKey.GetHashCode();
            }
            if (MainTextKey.Length != 0)
            {
                hash ^= MainTextKey.GetHashCode();
            }
            if (Timestamp != 0L)
            {
                hash ^= Timestamp.GetHashCode();
            }
            if (Template != 0)
            {
                hash ^= Template.GetHashCode();
            }
            if (Enabled != false)
            {
                hash ^= Enabled.GetHashCode();
            }
            if (ArticleRead != false)
            {
                hash ^= ArticleRead.GetHashCode();
            }
            if (_unknownFields != null)
            {
                hash ^= _unknownFields.GetHashCode();
            }
            return(hash);
        }
Esempio n. 5
0
 internal void SetHeader()
 {
     SyncStatic.TryCatch(() =>
     {
         if (Headers != null && Headers.Count > 0)
         {
             MultiConfig.HeaderOpt.Add(Headers);
         }
         else if (!HeaderKey.IsNullOrEmpty())
         {
             MultiConfig.HeaderOpt.Add(new Dictionary <string, string> {
                 { HeaderKey, HeaderValue }
             });
         }
         else
         {
             throw new Exception("Header配置不满足!");
         }
     }, ex => throw ex);
 }
Esempio n. 6
0
        public override int GetHashCode()
        {
            int hash = 1;

            if (secretData_ != null)
            {
                hash ^= SecretData.GetHashCode();
            }
            if (HeaderKey.Length != 0)
            {
                hash ^= HeaderKey.GetHashCode();
            }
            if (HeaderPrefix.Length != 0)
            {
                hash ^= HeaderPrefix.GetHashCode();
            }
            if (_unknownFields != null)
            {
                hash ^= _unknownFields.GetHashCode();
            }
            return(hash);
        }
        private void GetFileNameFromURL(object sender, DoWorkEventArgs e)
        {
            // First, see if there's a content-disposition header.

            /*
             * Content-Disposition: attachment; filename=genome.jpeg;
             *      modification-date="Wed, 12 Feb 1997 16:29:51 -0500";
             */

            Uri url = (Uri)e.Argument;

            try {
                WebRequest  WebRequestObject = HttpWebRequest.Create(url);
                WebResponse ResponseObject   = WebRequestObject.GetResponse();
                ResponseObject.Close();

                foreach (string HeaderKey in ResponseObject.Headers)
                {
                    if (HeaderKey.Equals("content-disposition", StringComparison.OrdinalIgnoreCase))
                    {
                        string[] sections = ResponseObject.Headers[HeaderKey].Split(';');
                        foreach (string section in sections)
                        {
                            string[] parts = section.Split('=');
                            if (parts.Count() == 2)
                            {
                                e.Result = Uri.UnescapeDataString(parts[1].Trim(new char[] { ' ', '"', '\'' }));
                                return;
                            }
                        }
                    }
                }
            } catch { }

            // If not, strip out any query and return the filename

            e.Result = Path.GetFileName(url.AbsolutePath);
        }