Esempio n. 1
0
        public static bool IsFileExtenstionAllowed(string sAllowedExt, string sExt)
        {
            if (sExt != null && sExt.StartsWith("."))
            {
                sExt = sExt.Substring(1, sExt.Length - 1);
            }
            sAllowedExt = sAllowedExt.Replace("|", ",");
            var aExt = sAllowedExt.Split(',');

            return(aExt.Any(t => StringUtils.EqualsIgnoreCase(sExt, t)));
        }
Esempio n. 2
0
 public static bool IsSystemDirectory(string directoryName)
 {
     if (StringUtils.EqualsIgnoreCase(directoryName, AspnetClient.DirectoryName) ||
         StringUtils.EqualsIgnoreCase(directoryName, Bin.DirectoryName) ||
         StringUtils.EqualsIgnoreCase(directoryName, SiteFiles.DirectoryName) ||
         StringUtils.EqualsIgnoreCase(directoryName, WebConfigUtils.AdminDirectory))
     {
         return(true);
     }
     return(false);
 }
Esempio n. 3
0
        public static string GetConnectionStringByName(string name)
        {
            var connectionString = string.Empty;

            try
            {
                var doc = new XmlDocument();

                var configFile = PathUtils.Combine(PhysicalApplicationPath, WebConfigFileName);

                doc.Load(configFile);

                var appSettings = doc.SelectSingleNode("configuration/appSettings");
                if (appSettings != null)
                {
                    foreach (XmlNode setting in appSettings)
                    {
                        if (setting.Name != "add")
                        {
                            continue;
                        }

                        var attrKey = setting.Attributes?["key"];
                        if (attrKey == null)
                        {
                            continue;
                        }

                        if (!StringUtils.EqualsIgnoreCase(attrKey.Value, name))
                        {
                            continue;
                        }

                        var attrValue = setting.Attributes["value"];
                        if (attrValue != null)
                        {
                            connectionString = attrValue.Value;
                        }
                        break;
                    }
                }
            }
            catch
            {
                // ignored
            }

            return(connectionString);
        }
Esempio n. 4
0
        public static void SelectSingleItemIgnoreCase(ListControl listControl, string value)
        {
            if (listControl == null)
            {
                return;
            }

            listControl.ClearSelection();
            foreach (ListItem item in listControl.Items)
            {
                if (StringUtils.EqualsIgnoreCase(item.Value, value))
                {
                    item.Selected = true;
                    break;
                }
            }
        }
Esempio n. 5
0
        public static void SelectMultiItemsIgnoreCase(ListControl listControl, List <string> values)
        {
            if (listControl == null)
            {
                return;
            }

            listControl.ClearSelection();
            foreach (ListItem item in listControl.Items)
            {
                foreach (var value in values)
                {
                    if (StringUtils.EqualsIgnoreCase(item.Value, value))
                    {
                        item.Selected = true;
                        break;
                    }
                }
            }
        }
Esempio n. 6
0
        public static void Load(string physicalApplicationPath)
        {
            PhysicalApplicationPath = physicalApplicationPath;

            var isProtectData    = false;
            var databaseType     = string.Empty;
            var connectionString = string.Empty;

            try
            {
                var doc = new XmlDocument();

                var configFile = PathUtils.Combine(PhysicalApplicationPath, WebConfigFileName);

                doc.Load(configFile);

                var appSettings = doc.SelectSingleNode("configuration/appSettings");
                if (appSettings != null)
                {
                    foreach (XmlNode setting in appSettings)
                    {
                        if (setting.Name == "add")
                        {
                            var attrKey = setting.Attributes?["key"];
                            if (attrKey != null)
                            {
                                if (StringUtils.EqualsIgnoreCase(attrKey.Value, nameof(IsProtectData)))
                                {
                                    var attrValue = setting.Attributes["value"];
                                    if (attrValue != null)
                                    {
                                        isProtectData = TranslateUtils.ToBool(attrValue.Value);
                                    }
                                }
                                else if (StringUtils.EqualsIgnoreCase(attrKey.Value, nameof(DatabaseType)))
                                {
                                    var attrValue = setting.Attributes["value"];
                                    if (attrValue != null)
                                    {
                                        databaseType = attrValue.Value;
                                    }
                                }
                                else if (StringUtils.EqualsIgnoreCase(attrKey.Value, nameof(ConnectionString)))
                                {
                                    var attrValue = setting.Attributes["value"];
                                    if (attrValue != null)
                                    {
                                        connectionString = attrValue.Value;
                                    }
                                }
                                else if (StringUtils.EqualsIgnoreCase(attrKey.Value, nameof(AdminDirectory)))
                                {
                                    var attrValue = setting.Attributes["value"];
                                    if (attrValue != null)
                                    {
                                        AdminDirectory = attrValue.Value;
                                    }
                                }
                                else if (StringUtils.EqualsIgnoreCase(attrKey.Value, nameof(SecretKey)))
                                {
                                    var attrValue = setting.Attributes["value"];
                                    if (attrValue != null)
                                    {
                                        SecretKey = attrValue.Value;
                                    }
                                }

                                else if (StringUtils.EqualsIgnoreCase(attrKey.Value, nameof(IsNightlyUpdate)))
                                {
                                    var attrValue = setting.Attributes["value"];
                                    if (attrValue != null)
                                    {
                                        IsNightlyUpdate = TranslateUtils.ToBool(attrValue.Value);
                                    }
                                }
                            }
                        }
                    }

                    if (isProtectData)
                    {
                        databaseType     = TranslateUtils.DecryptStringBySecretKey(databaseType);
                        connectionString = TranslateUtils.DecryptStringBySecretKey(connectionString);
                    }
                }
            }
            catch
            {
                // ignored
            }

            IsProtectData    = isProtectData;
            DatabaseType     = DatabaseTypeUtils.GetEnumType(databaseType);
            ConnectionString = connectionString;
            if (string.IsNullOrEmpty(AdminDirectory))
            {
                AdminDirectory = "siteserver";
            }
            if (string.IsNullOrEmpty(SecretKey))
            {
                SecretKey = StringUtils.GetShortGuid();
                //SecretKey = "vEnfkn16t8aeaZKG3a4Gl9UUlzf4vgqU9xwh8ZV5";
            }
        }
Esempio n. 7
0
        public static void UpdateWebConfig(string configPath, bool isProtectData, DatabaseType databaseType, string connectionString, string adminDirectory, string secretKey, bool isNightlyUpdate)
        {
            var doc = new XmlDocument();

            doc.Load(configPath);
            var dirty       = false;
            var appSettings = doc.SelectSingleNode("configuration/appSettings");

            if (appSettings != null)
            {
                foreach (XmlNode setting in appSettings)
                {
                    if (setting.Name == "add")
                    {
                        var attrKey = setting.Attributes?["key"];
                        if (attrKey != null)
                        {
                            if (StringUtils.EqualsIgnoreCase(attrKey.Value, nameof(IsProtectData)))
                            {
                                var attrValue = setting.Attributes["value"];
                                if (attrValue != null)
                                {
                                    attrValue.Value = isProtectData.ToString();
                                    dirty           = true;
                                }
                            }
                            else if (StringUtils.EqualsIgnoreCase(attrKey.Value, nameof(DatabaseType)))
                            {
                                var attrValue = setting.Attributes["value"];
                                if (attrValue != null)
                                {
                                    attrValue.Value = databaseType.Value;
                                    if (isProtectData)
                                    {
                                        attrValue.Value = TranslateUtils.EncryptStringBySecretKey(attrValue.Value, secretKey);
                                    }
                                    dirty = true;
                                }
                            }
                            else if (StringUtils.EqualsIgnoreCase(attrKey.Value, nameof(ConnectionString)))
                            {
                                var attrValue = setting.Attributes["value"];
                                if (attrValue != null)
                                {
                                    attrValue.Value = connectionString;
                                    if (isProtectData)
                                    {
                                        attrValue.Value = TranslateUtils.EncryptStringBySecretKey(attrValue.Value, secretKey);
                                    }
                                    dirty = true;
                                }
                            }
                            else if (StringUtils.EqualsIgnoreCase(attrKey.Value, nameof(AdminDirectory)))
                            {
                                var attrValue = setting.Attributes["value"];
                                if (attrValue != null)
                                {
                                    attrValue.Value = adminDirectory;
                                    dirty           = true;
                                }
                            }
                            else if (StringUtils.EqualsIgnoreCase(attrKey.Value, nameof(SecretKey)))
                            {
                                var attrValue = setting.Attributes["value"];
                                if (attrValue != null)
                                {
                                    attrValue.Value = secretKey;
                                    dirty           = true;
                                }
                            }
                            else if (StringUtils.EqualsIgnoreCase(attrKey.Value, nameof(IsNightlyUpdate)))
                            {
                                var attrValue = setting.Attributes["value"];
                                if (attrValue != null)
                                {
                                    attrValue.Value = isNightlyUpdate.ToString();
                                    dirty           = true;
                                }
                            }
                        }
                    }
                }
            }

            if (dirty)
            {
                var writer = new XmlTextWriter(configPath, Encoding.UTF8)
                {
                    Formatting = Formatting.Indented
                };
                doc.Save(writer);
                writer.Flush();
                writer.Close();
            }

            IsProtectData    = isProtectData;
            DatabaseType     = databaseType;
            ConnectionString = connectionString;
        }
Esempio n. 8
0
 public static bool IsExtension(string ext, params string[] extensions)
 {
     return(extensions.Any(extension => StringUtils.EqualsIgnoreCase(ext, extension)));
 }