コード例 #1
0
        private void SetValuesUsingDictObj(IReadOnlyDictionary <string, string> merchantConfigDictionary)
        {
            var key = string.Empty;

            try
            {
                if (merchantConfigDictionary != null)
                {
                    _propertiesSetUsing = "Dictionary Object";

                    // MANDATORY KEYS
                    key                = "runEnvironment";
                    RunEnvironment     = merchantConfigDictionary[key];
                    key                = "authenticationType";
                    AuthenticationType = merchantConfigDictionary[key];

                    key        = "useMetaKey";
                    UseMetaKey = "false";
                    if (merchantConfigDictionary.ContainsKey(key))
                    {
                        UseMetaKey = merchantConfigDictionary[key];
                        if (string.IsNullOrEmpty(UseMetaKey))
                        {
                            UseMetaKey = "false";
                        }
                    }


                    Enumerations.AuthenticationType authTypeInput;
                    Enum.TryParse(AuthenticationType.ToUpper(), out authTypeInput);

                    if (Equals(authTypeInput, Enumerations.AuthenticationType.HTTP_SIGNATURE))
                    {
                        key               = "merchantID";
                        MerchantId        = merchantConfigDictionary[key];
                        key               = "merchantsecretKey";
                        MerchantSecretKey = merchantConfigDictionary[key];
                        key               = "merchantKeyId";
                        MerchantKeyId     = merchantConfigDictionary[key];
                    }

                    if (Equals(bool.Parse(UseMetaKey.ToString()), true))
                    {
                        key         = "portfolioID";
                        PortfolioId = merchantConfigDictionary[key];
                        if (Equals(PortfolioId, string.Empty))
                        {
                            throw new KeyNotFoundException();
                        }
                    }

                    // OPTIONAL KEYS
                    // only if the key is passed read the value, otherwise use default / null values
                    if (Equals(authTypeInput, Enumerations.AuthenticationType.JWT))
                    {
                        key        = "merchantID";
                        MerchantId = merchantConfigDictionary[key];
                        if (merchantConfigDictionary.ContainsKey("keyAlias"))
                        {
                            KeyAlias = merchantConfigDictionary["keyAlias"];
                        }

                        if (merchantConfigDictionary.ContainsKey("keyFilename"))
                        {
                            KeyfileName = merchantConfigDictionary["keyFilename"];
                        }

                        if (merchantConfigDictionary.ContainsKey("keyPass"))
                        {
                            KeyPass = merchantConfigDictionary["keyPass"];
                        }

                        if (merchantConfigDictionary.ContainsKey("keysDirectory"))
                        {
                            KeyDirectory = merchantConfigDictionary["keysDirectory"];
                        }
                    }

                    if (Equals(authTypeInput, Enumerations.AuthenticationType.OAUTH))
                    {
                        IsOAuthTokenAuthType = true;
                        key = "accessToken";
                        if (merchantConfigDictionary.ContainsKey(key) && !string.IsNullOrEmpty(merchantConfigDictionary[key]))
                        {
                            AccessToken = merchantConfigDictionary[key];
                        }
                        else
                        {
                            throw new KeyNotFoundException();
                        }

                        key = "refreshToken";
                        if (merchantConfigDictionary.ContainsKey(key) && !string.IsNullOrEmpty(merchantConfigDictionary[key]))
                        {
                            RefreshToken = merchantConfigDictionary[key];
                        }
                        else
                        {
                            throw new KeyNotFoundException();
                        }
                    }

                    if (Equals(authTypeInput, Enumerations.AuthenticationType.MUTUAL_AUTH))
                    {
                        key = "clientId";
                        if (merchantConfigDictionary.ContainsKey(key) && !string.IsNullOrEmpty(merchantConfigDictionary[key]))
                        {
                            ClientId = merchantConfigDictionary[key];
                        }
                        else
                        {
                            throw new KeyNotFoundException();
                        }

                        key = "clientSecret";
                        if (merchantConfigDictionary.ContainsKey(key) && !string.IsNullOrEmpty(merchantConfigDictionary[key]))
                        {
                            ClientSecret = merchantConfigDictionary[key];
                        }
                        else
                        {
                            throw new KeyNotFoundException();
                        }
                    }

                    key = "enableClientCert";
                    if (merchantConfigDictionary.ContainsKey(key) && !string.IsNullOrEmpty(merchantConfigDictionary[key]))
                    {
                        EnableClientCert = merchantConfigDictionary[key];
                    }
                    else
                    {
                        EnableClientCert = "false";
                    }

                    if (Equals(bool.Parse(EnableClientCert.ToString()), true))
                    {
                        key = "clientCertFile";
                        if (merchantConfigDictionary.ContainsKey(key) && !string.IsNullOrEmpty(merchantConfigDictionary[key]))
                        {
                            ClientCertFile = merchantConfigDictionary[key];
                        }
                        else
                        {
                            throw new KeyNotFoundException();
                        }

                        key = "clientCertPassword";
                        if (merchantConfigDictionary.ContainsKey(key) && !string.IsNullOrEmpty(merchantConfigDictionary[key]))
                        {
                            ClientCertPassword = merchantConfigDictionary[key];
                        }
                        else
                        {
                            throw new KeyNotFoundException();
                        }

                        key = "clientCertDirectory";
                        if (merchantConfigDictionary.ContainsKey(key) && !string.IsNullOrEmpty(merchantConfigDictionary[key]))
                        {
                            ClientCertDirectory = merchantConfigDictionary[key];
                        }
                        else
                        {
                            throw new KeyNotFoundException();
                        }
                    }

                    if (merchantConfigDictionary.ContainsKey("enableLog"))
                    {
                        EnableLog = merchantConfigDictionary["enableLog"];
                    }

                    if (merchantConfigDictionary.ContainsKey("logDirectory"))
                    {
                        LogDirectory = merchantConfigDictionary["logDirectory"];
                    }

                    if (merchantConfigDictionary.ContainsKey("logFileMaxSize"))
                    {
                        LogfileMaxSize = merchantConfigDictionary["logFileMaxSize"];
                    }

                    if (merchantConfigDictionary.ContainsKey("logFileName"))
                    {
                        LogFileName = merchantConfigDictionary["logFileName"];
                    }

                    if (merchantConfigDictionary.ContainsKey("timeout"))
                    {
                        TimeOut = merchantConfigDictionary["timeout"];
                    }

                    if (merchantConfigDictionary.ContainsKey("useProxy"))
                    {
                        UseProxy = merchantConfigDictionary["useProxy"];
                    }

                    if (merchantConfigDictionary.ContainsKey("proxyAddress"))
                    {
                        ProxyAddress = merchantConfigDictionary["proxyAddress"];
                    }

                    if (merchantConfigDictionary.ContainsKey("proxyPort"))
                    {
                        ProxyPort = merchantConfigDictionary["proxyPort"];
                    }

                    if (merchantConfigDictionary.ContainsKey("proxyUsername"))
                    {
                        ProxyUsername = merchantConfigDictionary["proxyUsername"];
                    }

                    if (merchantConfigDictionary.ContainsKey("proxyPassword"))
                    {
                        ProxyPassword = merchantConfigDictionary["proxyPassword"];
                    }
                }
            }
            catch (KeyNotFoundException)
            {
                throw new Exception(
                          $"{Constants.ErrorPrefix} Mandatory Key ({key}) Missing in the Configuration Dictionary Object Passed to the instance of MerchantConfig");
            }
        }