コード例 #1
0
ファイル: Shipping.cs プロジェクト: lulzzz/BrandStore
 static public int GetFirstFreeShippingMethodID()
 {
     foreach (String s in AppLogic.AppConfig("ShippingMethodIDIfFreeShippingIsOn").Trim().Split(','))
     {
         String s2 = s.Trim();
         if (s2.Length != 0)
         {
             if (CommonLogic.IsInteger(s2))
             {
                 return(System.Int32.Parse(s2));
             }
         }
     }
     return(0);
 }
コード例 #2
0
ファイル: Shipping.cs プロジェクト: lulzzz/BrandStore
        public static int ZoneLookup(String zip)
        {
            int ZipCodePrefixLength = AppLogic.AppConfigNativeInt("ZipCodePrefixLength");

            if (ZipCodePrefixLength < 0)
            {
                ZipCodePrefixLength = 3;
            }

            if (ZipCodePrefixLength > 5)
            {
                ZipCodePrefixLength = 5;
            }

            zip = zip.Trim().PadRight(5, '0');
            String ZipSubStr    = zip.Substring(0, ZipCodePrefixLength);
            int    ZipSubStrInt = 0;

            try
            {
                ZipSubStrInt = Localization.ParseUSInt(ZipSubStr);
            }
            catch
            {
                return(AppLogic.AppConfigUSInt("ZoneIDForNoMatch")); // something bad as input zip
            }
            int ZoneID = 0;

            using (SqlConnection dbconn = DB.dbConn())
            {
                dbconn.Open();
                using (IDataReader rs = DB.GetRS("select * from ShippingZone with (NOLOCK)", dbconn))
                {
                    while (rs.Read())
                    {
                        String[] thisZipList = Regex.Replace(DB.RSField(rs, "ZipCodes"), "\\s+", "", RegexOptions.Compiled).Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
                        foreach (String s in thisZipList)
                        {
                            // is it a single 3 digit prefix, or a range:
                            if (s.IndexOf("-") ==
                                -1)
                            {
                                String s2 = s.Substring(0, ZipCodePrefixLength);
                                // single item:
                                int LowPrefix = 0;
                                try
                                {
                                    if (CommonLogic.IsInteger(s2))
                                    {
                                        LowPrefix = Localization.ParseUSInt(s2);
                                    }
                                }
                                catch
                                {
                                }
                                if (LowPrefix == ZipSubStrInt)
                                {
                                    ZoneID = DB.RSFieldInt(rs, "ShippingZoneID");
                                    break;
                                }
                            }
                            else
                            {
                                // range:
                                String[] s2         = s.Split('-');
                                int      LowPrefix  = 0;
                                int      HighPrefix = 0;
                                try
                                {
                                    String s2a;
                                    s2a = s2[0].Substring(0, ZipCodePrefixLength);
                                    String s2b;
                                    s2b = s2[1].Substring(0, ZipCodePrefixLength);
                                    if (CommonLogic.IsInteger(s2a))
                                    {
                                        LowPrefix = Localization.ParseUSInt(s2a);
                                    }
                                    if (CommonLogic.IsInteger(s2b))
                                    {
                                        HighPrefix = Localization.ParseUSInt(s2b);
                                    }
                                }
                                catch
                                {
                                }
                                if (LowPrefix <= ZipSubStrInt &&
                                    ZipSubStrInt <= HighPrefix)
                                {
                                    ZoneID = DB.RSFieldInt(rs, "ShippingZoneID");
                                    break;
                                }
                            }
                        }
                    }
                }
            }
            if (ZoneID == 0)
            {
                ZoneID = AppLogic.AppConfigUSInt("ZoneIDForNoMatch");
            }
            return(ZoneID);
        }
コード例 #3
0
        public static String GetEncryptParam(String ParamName)
        {
            var param = string.Empty;

            if (ParamName == "EncryptKey")
            {
                // Pull the encryption key from appsettings.
                param = CommonLogic.Application(ParamName);

                // The EncryptKey AppSetting will either be plain text from a merchant manually setting the value
                //  or it will be encrypted from setting it via the Change Encrypt Key in admin. If it was set through
                //  the admin, a KEK and a TEK will have been generated. Bypass decryption if neither are set.
                var keyEncryptionKeyConfig = GlobalConfig.GetGlobalConfig(KeyEncryptionKeyName);
                var tertiaryEncryptionKey  = ConfigurationManager.AppSettings[TertiaryEncryptionKeyName];

                if (keyEncryptionKeyConfig != null &&
                    !string.IsNullOrWhiteSpace(keyEncryptionKeyConfig.ConfigValue) &&
                    !string.IsNullOrWhiteSpace(tertiaryEncryptionKey))
                {
                    var encryptIterations    = AppLogic.AppConfigNativeInt("EncryptIterations");
                    var hashAlgorithm        = AppLogic.AppConfig("HashAlgorithm");
                    var initializationVector = AppLogic.AppConfig("InitializationVector");
                    var keySize = AppLogic.AppConfigNativeInt("KeySize");

                    // We found the KEK and the TEK, decrypt the KEK using the TEK.
                    var decryptedKEK = Security.UnmungeString(keyEncryptionKeyConfig.ConfigValue, string.Empty, new Security.SecurityParams
                    {
                        EncryptIterations    = encryptIterations,
                        EncryptKey           = tertiaryEncryptionKey,
                        HashAlgorithm        = hashAlgorithm,
                        InitializationVector = initializationVector,
                        KeySize = keySize
                    });

                    // Decrypt the Encrypt Key using the decrypted KEK.
                    param = Security.UnmungeString(param, string.Empty, new Security.SecurityParams
                    {
                        EncryptIterations    = encryptIterations,
                        EncryptKey           = decryptedKEK,
                        HashAlgorithm        = hashAlgorithm,
                        InitializationVector = initializationVector,
                        KeySize = keySize
                    });
                }
            }
            else
            {
                param = AppLogic.AppConfig(ParamName);
            }

            // now do validation!
            if (ParamName == "EncryptKey")
            {
                if (param.Length == 0 || param == "WIZARD" ||
                    param == AppLogic.ro_TBD)
                {
                    throw new ArgumentException("You must enter your EncryptKey in the /AppSettings.config file!!! Review documentation for instructions.");
                }
            }

            if (ParamName == "EncryptIterations")
            {
                if (param.Length == 0 && !CommonLogic.IsInteger(param) && Convert.ToInt32(param) >= 1 &&
                    Convert.ToInt32(param) <= 4)
                {
                    throw new ArgumentException("The EncryptIterations parameter must be an integer value between 1 and 4.");
                }
            }

            if (ParamName == "InitializationVector")
            {
                if (param.Length == 0 || param == AppLogic.ro_TBD ||
                    param.Length != 16)
                {
                    throw new ArgumentException("You MUST set your InitializationVector in the AppConfig manager in the admin site! it MUST be exactly 16 characters/digits long. This is required for security reasons.");
                }
            }

            if (ParamName == "KeySize")
            {
                if (param.Length == 0 || param == "0" ||
                    (param != "128" && param != "192" && param != "256"))
                {
                    throw new ArgumentException("You MUST set your KeySize value in the AppConfig manager in the admin site to an allowed valid value! This is required for security reasons.");
                }
            }

            if (ParamName == "HashAlgorithm")
            {
                if (param.Length == 0 ||
                    (param != "MD5" && param != "SHA1"))
                {
                    throw new ArgumentException("You MUST set your HashAlgorithm in the AppConfig manager in the admin site to an allowed valid value! This is required for security reasons.");
                }
            }

            return(param);
        }
コード例 #4
0
        static void ResizePhoto(Hashtable configValues, Image originalPhoto, string filename, string tempFilename, string size, string content)
        {
            var resizeMe = AppLogic.AppConfigBool("UseImageResize");

            if (configValues.ContainsKey("resize") && configValues["resize"].ToString() == "false")
            {
                resizeMe = false;
            }
            else if (configValues.ContainsKey("resize") && configValues["resize"].ToString() == "true")
            {
                resizeMe = true;
            }

            if (!resizeMe)
            {
                originalPhoto.Save(filename);
                return;
            }

            var resizedWidth   = AppLogic.AppConfigNativeInt("DefaultWidth_" + size);
            var resizedHeight  = AppLogic.AppConfigNativeInt("DefaultHeight_" + size);
            var resizedQuality = AppLogic.AppConfigNativeInt("DefaultQuality");

            var stretchMe = AppLogic.AppConfig("DefaultStretch");
            var cropMe    = AppLogic.AppConfig("DefaultCrop");
            var cropV     = AppLogic.AppConfig("DefaultCropVertical");
            var cropH     = AppLogic.AppConfig("DefaultCropHorizontal");
            var fillColor = AppLogic.AppConfig("DefaultFillColor");

            var sourceWidth  = originalPhoto.Width;
            var sourceHeight = originalPhoto.Height;
            var sourceX      = 0;
            var sourceY      = 0;
            // we will extend 2 pixels on all sides to avoid the border bug
            // we could use InterpolationMode.NearestNeighbor instead of
            // InterpolationMode.HighQualityBicubic but not without sacrificing quality
            var destX = -2;
            var destY = -2;

            var nPercent  = 0f;
            var nPercentW = 0f;
            var nPercentH = 0f;

            var destWidth  = 0;
            var destHeight = 0;

            if (configValues.ContainsKey("width") &&
                CommonLogic.IsInteger(configValues["width"].ToString()))
            {
                resizedWidth = Int32.Parse(configValues["width"].ToString());
            }

            if (configValues.ContainsKey("height") &&
                CommonLogic.IsInteger(configValues["height"].ToString()))
            {
                resizedHeight = Int32.Parse(configValues["height"].ToString());
            }

            if (configValues.ContainsKey("quality") &&
                CommonLogic.IsInteger(configValues["quality"].ToString()))
            {
                resizedQuality = Int32.Parse(configValues["quality"].ToString());
            }

            if (configValues.ContainsKey("stretch"))
            {
                stretchMe = configValues["stretch"].ToString();
            }

            if (configValues.ContainsKey("fill"))
            {
                fillColor = configValues["fill"].ToString();
            }

            if (configValues.ContainsKey("crop"))
            {
                cropMe = configValues["crop"].ToString();

                if (cropMe == "true")
                {
                    if (configValues.ContainsKey("cropv"))
                    {
                        cropV = configValues["cropv"].ToString();
                    }

                    if (configValues.ContainsKey("croph"))
                    {
                        cropH = configValues["croph"].ToString();
                    }
                }
            }

            if (resizedWidth < 1 || resizedHeight < 1)
            {
                resizedWidth  = originalPhoto.Width;
                resizedHeight = originalPhoto.Height;
            }

            if (cropMe == "true")
            {
                var AnchorUpDown    = cropV;
                var AnchorLeftRight = cropH;
                nPercentW = ((float)resizedWidth / (float)sourceWidth);
                nPercentH = ((float)resizedHeight / (float)sourceHeight);

                if (nPercentH < nPercentW)
                {
                    nPercent = nPercentW;
                    switch (AnchorUpDown)
                    {
                    case "top":
                        destY = -2;
                        break;

                    case "bottom":
                        destY = (int)(resizedHeight - (sourceHeight * nPercent));
                        break;

                    case "center":
                    default:
                        destY = (int)((resizedHeight - (sourceHeight * nPercent)) / 2) - 2;
                        break;
                    }
                }
                else
                {
                    nPercent = nPercentH;
                    switch (AnchorLeftRight.ToUpper())
                    {
                    case "left":
                        destX = 0;
                        break;

                    case "right":
                        destX = (int)(resizedWidth - (sourceWidth * nPercent));
                        break;

                    case "middle":
                    default:
                        destX = (int)((resizedWidth - (sourceWidth * nPercent)) / 2) - 2;
                        break;
                    }
                }
            }
            else
            {
                nPercentW = ((float)resizedWidth / (float)sourceWidth);
                nPercentH = ((float)resizedHeight / (float)sourceHeight);

                if (nPercentH < nPercentW)
                {
                    nPercent = nPercentH;
                    destX    = (int)((resizedWidth - (sourceWidth * nPercent)) / 2);
                }
                else
                {
                    nPercent = nPercentW;
                    destY    = (int)((resizedHeight - (sourceHeight * nPercent)) / 2) - 2;
                }
            }
            // let's account for the extra pixels we left to avoid the borderbug here
            // some distortion will occur...but it should be unnoticeable
            if (stretchMe == "false" && (originalPhoto.Width < resizedWidth && originalPhoto.Height < resizedHeight))
            {
                destWidth  = originalPhoto.Width;
                destHeight = originalPhoto.Height;
                destX      = (int)((resizedWidth / 2) - (originalPhoto.Width / 2));
                destY      = (int)((resizedHeight / 2) - (originalPhoto.Height / 2));
            }
            else
            {
                destWidth  = (int)Math.Ceiling(sourceWidth * nPercent) + 4;
                destHeight = (int)Math.Ceiling(sourceHeight * nPercent) + 4;
            }

            SavePhoto(resizedWidth, resizedHeight, destHeight, destWidth, destX, destY, sourceHeight, sourceWidth, sourceX, sourceY, originalPhoto, filename, fillColor, resizedQuality, content);
        }
コード例 #5
0
        public static String GetEncryptParam(String ParamName)
        {
            String param = string.Empty;

            if (ParamName == "EncryptKey")
            {
                param = CommonLogic.Application(ParamName);
            }
            else
            {
                param = AppLogic.AppConfig(ParamName);
            }

            // now do validation!
            if (ParamName == "EncryptKey")
            {
                if (param.Length == 0 || param == "WIZARD" ||
                    param == AppLogic.ro_TBD)
                {
                    throw new ArgumentException("You must enter your EncryptKey in the /web.config file!!! Open that file in Notepad, and see the instructions.");
                }
            }

            if (ParamName == "EncryptIterations")
            {
                if (param.Length == 0 && !CommonLogic.IsInteger(param) && Convert.ToInt32(param) >= 1 &&
                    Convert.ToInt32(param) <= 4)
                {
                    throw new ArgumentException("The EncryptIterations parameter must be an integer value between 1 and 4.");
                }
            }

            if (ParamName == "InitializationVector")
            {
                if (param.Length == 0 || param == AppLogic.ro_TBD ||
                    param.Length != 16)
                {
                    throw new ArgumentException("You MUST set your InitializationVector in the AppConfig manager in the admin site! it MUST be exactly 16 characters/digits long. This is required for security reasons.");
                }
            }

            if (ParamName == "KeySize")
            {
                if (param.Length == 0 || param == "0" ||
                    (param != "128" && param != "192" && param != "256"))
                {
                    throw new ArgumentException("You MUST set your KeySize value in the AppConfig manager in the admin site to an allowed valid value! This is required for security reasons.");
                }
            }

            if (ParamName == "HashAlgorithm")
            {
                if (param.Length == 0 ||
                    (param != "MD5" && param != "SHA1"))
                {
                    throw new ArgumentException("You MUST set your HashAlgorithm in the AppConfig manager in the admin site to an allowed valid value! This is required for security reasons.");
                }
            }

            return(param);
        }