示例#1
0
        public static KeyValuePair <string, IDataParameter> GetInStrWithParameter(string columnName, string inStr)
        {
            var parameterName = $"P{StringUtils.GetShortGuid()}";
            var sqlString     = string.Empty;
            var parameter     = GetIDbDataParameter(parameterName, DataType.VarChar, 0, inStr);

            if (WebConfigUtils.DatabaseType == DatabaseType.MySql)
            {
                sqlString = $"INSTR({columnName}, @{parameterName}) > 0";
            }
            else if (WebConfigUtils.DatabaseType == DatabaseType.SqlServer)
            {
                sqlString = $"CHARINDEX(@{parameterName}, {columnName}) > 0";
            }
            else if (WebConfigUtils.DatabaseType == DatabaseType.PostgreSql)
            {
                sqlString = $"POSITION(@{parameterName} IN {columnName}) > 0";
            }
            else if (WebConfigUtils.DatabaseType == DatabaseType.Oracle)
            {
                sqlString = $"INSTR({columnName}, @{parameterName}) > 0";
            }

            return(new KeyValuePair <string, IDataParameter>(sqlString, parameter));
        }
示例#2
0
        public static string GetSafeFilename(string filename)
        {
            if (string.IsNullOrEmpty(filename))
            {
                return(StringUtils.GetShortGuid().ToLower());
            }

            return(string.Join("_", filename.Split(GetInvalidChars())));
        }
示例#3
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";
            }
        }
示例#4
0
 public static string GetLibraryFileName(string filePath)
 {
     return($"{StringUtils.GetShortGuid(false)}{GetExtension(filePath)}");
 }