Beispiel #1
0
        private static CacheDependency CreateOracleDepenedency(string connectionString, DbCommand dbCommand)
        {
            OracleCacheDependency depenedency = new OracleCacheDependency(connectionString, dbCommand.CommandText);

            if (dbCommand.Parameters.Count > 0)
            {
                foreach (DbParameter parameter in dbCommand.Parameters)
                {
                    OracleCmdParams dependencyParameter = new OracleCmdParams();
                    dependencyParameter.Direction = (OracleParameterDirection)((int)parameter.Direction - 1);
                    switch (parameter.Direction)
                    {
                        case ParameterDirection.Input:
                            dependencyParameter.Direction = OracleParameterDirection.Input;
                            break;
                        case ParameterDirection.Output:
                            dependencyParameter.Direction = OracleParameterDirection.Output;
                            break;
                    }

                    dependencyParameter.Value = parameter.Value;

                    depenedency.CommandParams.Add(parameter.ParameterName, dependencyParameter);
                }
            }

            return depenedency;
        }
Beispiel #2
0
        private CacheDependency GetNonAggregateDependencies(ExpirationHint hint)
        {
            if (hint is KeyDependency)
            {
                KeyDependency keyDep = (KeyDependency)hint;

                return(new Runtime.Dependencies.KeyDependency(keyDep.CacheKeys, new DateTime(keyDep.StartAfterTicks)));
            }
            else if (hint is FileDependency)
            {
                FileDependency fileDep = (FileDependency)hint;
                return(new Runtime.Dependencies.FileDependency(fileDep.fileNames, new DateTime(fileDep.StartAfterTicks)));
            }

            else if (hint is OleDbCacheDependency)
            {
                OleDbCacheDependency oleDbDep = (OleDbCacheDependency)hint;
                return(DBDependencyFactory.CreateOleDbCacheDependency(oleDbDep.ConnectionString, oleDbDep.DbCacheKey));
            }
            else if (hint is Sql7CacheDependency)
            {
                Sql7CacheDependency sql7Dep = (Sql7CacheDependency)hint;
                return(DBDependencyFactory.CreateSqlCacheDependency(sql7Dep.ConnectionString, sql7Dep.DbCacheKey));
            }

            else if (hint is OracleCacheDependency)
            {
                OracleCacheDependency oracleDep = (OracleCacheDependency)hint;

                Dictionary <string, OracleCmdParams> parameters = new Dictionary <string, OracleCmdParams>();
                IDictionaryEnumerator enu = oracleDep.CommandParams.GetEnumerator();
                while (enu.MoveNext())
                {
                    string key = enu.Key.ToString();
                    OracleCommandParams cmdParam = (OracleCommandParams)enu.Value;

                    OracleCmdParams commandParam = new OracleCmdParams();

                    commandParam.Direction = (OracleParameterDirection)cmdParam.Direction;
                    commandParam.Type      = (OracleCmdParamsType)cmdParam.Type;
                    commandParam.Value     = cmdParam.Value;

                    parameters.Add(key, commandParam);
                }

                Runtime.Dependencies.OracleCacheDependency oraDep = new Runtime.Dependencies.OracleCacheDependency(oracleDep.ConnectionString,
                                                                                                                   oracleDep.QueryString,
                                                                                                                   (OracleCommandType)oracleDep.CommandType,
                                                                                                                   parameters);
                return(oraDep);
            }

            else if (hint is SqlYukonCacheDependency)
            {
                SqlYukonCacheDependency yukonDep = (SqlYukonCacheDependency)hint;

                Dictionary <string, Runtime.Dependencies.SqlCmdParams> parameters = new Dictionary <string, Runtime.Dependencies.SqlCmdParams>();
                IDictionaryEnumerator enu = yukonDep.CommandParams.GetEnumerator();

                while (enu.MoveNext())
                {
                    string       key   = enu.Key.ToString();
                    SqlCmdParams param = (SqlCmdParams)enu.Value;
                    Runtime.Dependencies.SqlCmdParams yukonCmdParam = new Runtime.Dependencies.SqlCmdParams();

                    yukonCmdParam.SqlParamDir             = param.Direction;
                    yukonCmdParam.Type                    = (CmdParamsType)param.DbType;
                    yukonCmdParam.IsNullable              = param.IsNullable;
                    yukonCmdParam.LocaleID                = param.LocaleID;
                    yukonCmdParam.Offset                  = param.Offset;
                    yukonCmdParam.Precision               = param.Precision;
                    yukonCmdParam.Scale                   = param.Scale;
                    yukonCmdParam.Size                    = param.ParamSize;
                    yukonCmdParam.SourceColumn            = param.SourceColumn;
                    yukonCmdParam.SourceColumnNullMapping = param.SourceColumnNullMapping;
                    yukonCmdParam.SqlValue                = param.SqlValue;
                    yukonCmdParam.SourceVersion           = (SqlDataRowVersion)(int)param.SrcVersion;
                    yukonCmdParam.TypeName                = param.TypeName;
                    yukonCmdParam.UdtTypeName             = param.UdtName;
                    yukonCmdParam.Value                   = param.Value;

                    parameters.Add(key, yukonCmdParam);
                }

                Runtime.Dependencies.SqlCacheDependency sqlDep = new Runtime.Dependencies.SqlCacheDependency(yukonDep.ConnectionString,
                                                                                                             yukonDep.QueryString,
                                                                                                             (SqlCommandType)yukonDep.CommandType,
                                                                                                             parameters);
                return(sqlDep);
            }
            if (hint is NosDBCacheDependency)
            {
                NosDBCacheDependency nosDbDep = (NosDBCacheDependency)hint;

                Dictionary <string, object> parameters = new Dictionary <string, object>();
                IDictionaryEnumerator       enu        = nosDbDep.CommandParams.GetEnumerator();
                while (enu.MoveNext())
                {
                    string key = enu.Key.ToString();
                    parameters.Add(key, enu.Value);
                }
                NosDBDependency oraDep = new NosDBDependency(nosDbDep.ConnectionString, nosDbDep.QueryString, parameters, nosDbDep.Timeout);
                return(oraDep);
            }
            return(null);
        }
Beispiel #3
0
        public static CacheDependency GetCacheDependency(ExpirationHint hint, ref DateTime absoluteExpiration, ref TimeSpan slidingExpiration)
        {
            CacheDependency cacheDependency = null;

            if (hint != null)
            {
                if (hint is AggregateExpirationHint)
                {
                    AggregateExpirationHint aggregate = (AggregateExpirationHint)hint;
                    IList <ExpirationHint>  hints     = aggregate.Hints;
                    if (hints != null && hints.Count > 0)
                    {
                        foreach (ExpirationHint h in hints)
                        {
                            AddToDependency(ref cacheDependency, GetCacheDependency(h, ref absoluteExpiration, ref slidingExpiration));
                        }
                    }
                }

                else if (hint is FixedExpiration)
                {
                    absoluteExpiration = ((FixedExpiration)hint).AbsoluteTime;
                }
                else if (hint is IdleExpiration)
                {
                    slidingExpiration = ((IdleExpiration)hint).SlidingTime;
                }

                else if (hint is KeyDependency)
                {
                    KeyDependency keyDep = (KeyDependency)hint;

                    AddToDependency(ref cacheDependency,
                                    new Runtime.Dependencies.KeyDependency(keyDep.CacheKeys, new DateTime(keyDep.StartAfterTicks)));
                }

                else if (hint is FileDependency)
                {
                    FileDependency fileDep = (FileDependency)hint;

                    AddToDependency(ref cacheDependency, new Runtime.Dependencies.FileDependency(fileDep.fileNames, new DateTime(fileDep.StartAfterTicks)));
                }


                else if (hint is OleDbCacheDependency)
                {
                    OleDbCacheDependency oleDbDep = (OleDbCacheDependency)hint;

                    AddToDependency(ref cacheDependency,
                                    new CacheDependency(null, null, DBDependencyFactory.CreateOleDbCacheDependency(
                                                            oleDbDep.ConnectionString, oleDbDep.DbCacheKey)));
                }



                else if (hint is Sql7CacheDependency)
                {
                    Sql7CacheDependency sql7Dep = (Sql7CacheDependency)hint;
                    AddToDependency(ref cacheDependency,
                                    new CacheDependency(null, null, DBDependencyFactory.CreateSqlCacheDependency(
                                                            sql7Dep.ConnectionString, sql7Dep.DbCacheKey)));
                }



                else if (hint is OracleCacheDependency)
                {
                    OracleCacheDependency oracleDep = (OracleCacheDependency)hint;

                    Dictionary <string, OracleCmdParams> parameters = new Dictionary <string, OracleCmdParams>();
                    IDictionaryEnumerator enu = oracleDep.CommandParams.GetEnumerator();
                    while (enu.MoveNext())
                    {
                        string key = enu.Key.ToString();
                        OracleCommandParams cmdParam = (OracleCommandParams)enu.Value;

                        OracleCmdParams commandParam = new OracleCmdParams();

                        commandParam.Direction = (OracleParameterDirection)cmdParam.Direction;
                        commandParam.Type      = (OracleCmdParamsType)cmdParam.Type;
                        commandParam.Value     = cmdParam.Value;

                        parameters.Add(key, commandParam);
                    }

                    Runtime.Dependencies.OracleCacheDependency oraDep = new Runtime.Dependencies.OracleCacheDependency(oracleDep.ConnectionString,
                                                                                                                       oracleDep.QueryString,
                                                                                                                       (OracleCommandType)oracleDep.CommandType,
                                                                                                                       parameters);

                    AddToDependency(ref cacheDependency, oraDep);
                }


                else if (hint is SqlYukonCacheDependency)
                {
                    SqlYukonCacheDependency yukonDep = (SqlYukonCacheDependency)hint;

                    Dictionary <string, Runtime.Dependencies.SqlCmdParams> parameters = new Dictionary <string, Runtime.Dependencies.SqlCmdParams>();
                    IDictionaryEnumerator enu = yukonDep.CommandParams.GetEnumerator();

                    while (enu.MoveNext())
                    {
                        string       key   = enu.Key.ToString();
                        SqlCmdParams param = (SqlCmdParams)enu.Value;
                        Runtime.Dependencies.SqlCmdParams yukonCmdParam = new Runtime.Dependencies.SqlCmdParams();

                        yukonCmdParam.SqlParamDir             = param.Direction;
                        yukonCmdParam.Type                    = (CmdParamsType)param.DbType;
                        yukonCmdParam.IsNullable              = param.IsNullable;
                        yukonCmdParam.LocaleID                = param.LocaleID;
                        yukonCmdParam.Offset                  = param.Offset;
                        yukonCmdParam.Precision               = param.Precision;
                        yukonCmdParam.Scale                   = param.Scale;
                        yukonCmdParam.Size                    = param.ParamSize;
                        yukonCmdParam.SourceColumn            = param.SourceColumn;
                        yukonCmdParam.SourceColumnNullMapping = param.SourceColumnNullMapping;
                        yukonCmdParam.SqlValue                = param.SqlValue;
                        yukonCmdParam.SourceVersion           = (SqlDataRowVersion)(int)param.SrcVersion;
                        yukonCmdParam.TypeName                = param.TypeName;
                        yukonCmdParam.UdtTypeName             = param.UdtName;
                        yukonCmdParam.Value                   = param.Value;

                        parameters.Add(key, yukonCmdParam);
                    }

                    Runtime.Dependencies.SqlCacheDependency sqlDep = new Runtime.Dependencies.SqlCacheDependency(yukonDep.ConnectionString,
                                                                                                                 yukonDep.QueryString,
                                                                                                                 (SqlCommandType)yukonDep.CommandType,
                                                                                                                 parameters);

                    AddToDependency(ref cacheDependency, sqlDep);
                }
                else if (hint is NosDBCacheDependency)
                {
                    NosDBCacheDependency nosDbDep = (NosDBCacheDependency)hint;

                    Dictionary <string, object> parameters = new Dictionary <string, object>();
                    IDictionaryEnumerator       enu        = nosDbDep.CommandParams.GetEnumerator();
                    while (enu.MoveNext())
                    {
                        string key = enu.Key.ToString();
                        parameters.Add(key, enu.Value);
                    }
                    NosDBDependency nosDb = new NosDBDependency(nosDbDep.ConnectionString, nosDbDep.QueryString, parameters, nosDbDep.Timeout);
                    AddToDependency(ref cacheDependency, nosDb);
                }
            }

            return(cacheDependency);
        }
Beispiel #4
0
        public override CacheDependency GetCacheDependency(
            string connectionString,
            object key)
        {
            var cmdType = IsStoredProcedure ?
                          OracleCommandType.StoredProcedure :
                          OracleCommandType.Text;

            string cmdText = GetCommand();

            var cmdParams = new Dictionary <string, OracleCmdParams>();

            if (!string.IsNullOrWhiteSpace(PrimaryKeyInputParameter))
            {
                if (!ValidateKey(key))
                {
                    if (key == null)
                    {
                        throw new ArgumentException(
                                  $"Key cannot be null");
                    }
                    throw new ArgumentOutOfRangeException(
                              $"Key type {key.GetType().FullName} not supported");
                }

                var cmdParam = new OracleCmdParams();
                cmdParam.Value     = key;
                cmdParam.Type      = GetCommandParamType(PrimaryKeyDbType);
                cmdParam.Direction = OracleParameterDirection.Input;

                cmdParams.Add(PrimaryKeyInputParameter, cmdParam);
            }

            if (IsStoredProcedure)
            {
                foreach (var pair in OutputParametersAndDbTypes)
                {
                    var pairKey  = pair.Key;
                    var pairType = pair.Value;

                    if (string.IsNullOrWhiteSpace(pairKey) ||
                        string.IsNullOrWhiteSpace(pairType))
                    {
                        throw new ArgumentNullException(
                                  "Key/value pair invalid with empty or null values. " +
                                  "Please check your dependency configuration");
                    }
                    var cmdParam = new OracleCmdParams();
                    cmdParam.Type      = GetCommandParamType(pairType);
                    cmdParam.Direction = OracleParameterDirection.Output;

                    var cmdParamKey = $"{pairKey}";

                    cmdParams.Add(cmdParamKey, cmdParam);
                }
            }

            return(new OracleCacheDependency(
                       connectionString,
                       cmdText,
                       cmdType,
                       cmdParams));
        }
Beispiel #5
0
        public static CacheDependency GetCacheDependency(Dependency dependency)
        {
            CacheDependency cacheDependency = null;

            if (dependency == null)
            {
                return(null);
            }

            if (dependency.keyDep.Count > 0)
            {
                for (int i = 0; i < dependency.keyDep.Count; i++)
                {
                    AddToDependency(ref cacheDependency,
                                    new Runtime.Dependencies.KeyDependency(
                                        dependency.keyDep[i].keys.ToArray(),
                                        new DateTime(dependency.keyDep[i].startAfter)));
                }
            }

            if (dependency.fileDep.Count > 0)
            {
                for (int i = 0; i < dependency.fileDep.Count; i++)
                {
                    AddToDependency(ref cacheDependency,
                                    new Runtime.Dependencies.FileDependency(
                                        dependency.fileDep[i].filePaths.ToArray(),
                                        new DateTime(dependency.fileDep[i].startAfter)));
                }
            }

            if (dependency.oleDbDep.Count > 0)
            {
                for (int i = 0; i < dependency.oleDbDep.Count; i++)
                {
                    AddToDependency(ref cacheDependency,
                                    new CacheDependency(null, null, DBDependencyFactory.CreateOleDbCacheDependency(
                                                            dependency.oleDbDep[i].connectionString,
                                                            dependency.oleDbDep[i].dbCacheKey)));
                }
            }

            if (dependency.sql7Dep.Count > 0)
            {
                for (int i = 0; i < dependency.sql7Dep.Count; i++)
                {
                    AddToDependency(ref cacheDependency,
                                    new CacheDependency(null, null, DBDependencyFactory.CreateSqlCacheDependency(
                                                            dependency.sql7Dep[i].connectionString,
                                                            dependency.sql7Dep[i].dbCacheKey)));
                }
            }

            if (dependency.oracleDep.Count > 0)
            {
                for (int i = 0; i < dependency.oracleDep.Count; i++)
                {
                    Dictionary <string, OracleCmdParams> parameters = new Dictionary <string, OracleCmdParams>();
                    for (int pc = 0; pc < dependency.oracleDep[i].param.Count; pc++)
                    {
                        OracleCmdParams commandParam = new OracleCmdParams();

                        commandParam.Direction = (OracleParameterDirection)dependency.oracleDep[i].param[pc].cmdParam.direction;
                        commandParam.Type      = (OracleCmdParamsType)dependency.oracleDep[i].param[pc].cmdParam.dbType;
                        commandParam.Value     = dependency.oracleDep[i].param[pc].cmdParam.value;

                        parameters.Add(dependency.oracleDep[i].param[pc].key, commandParam);
                    }

                    OracleCacheDependency oraDep = new OracleCacheDependency(dependency.oracleDep[i].connectionString,
                                                                             dependency.oracleDep[i].query,
                                                                             (OracleCommandType)dependency.oracleDep[i].commandType,
                                                                             parameters);

                    AddToDependency(ref cacheDependency, oraDep);
                }
            }


            if (dependency.yukonDep.Count > 0)
            {
                for (int i = 0; i < dependency.yukonDep.Count; i++)
                {
                    Dictionary <string, SqlCmdParams> parameters = new Dictionary <string, SqlCmdParams>();
                    for (int pc = 0; pc < dependency.yukonDep[i].param.Count; pc++)
                    {
                        YukonCommandParam yukonParam   = dependency.yukonDep[i].param[pc].cmdParam;
                        SqlCmdParams      commandParam = new SqlCmdParams();

                        commandParam.CompareInfo             = (SqlCmpOptions)yukonParam.cmpOptions;
                        commandParam.Direction               = (SqlParamDirection)yukonParam.direction;
                        commandParam.IsNullable              = yukonParam.isNullable;
                        commandParam.LocaleID                = yukonParam.localeId;
                        commandParam.Offset                  = yukonParam.offset;
                        commandParam.Precision               = (byte)yukonParam.precision;
                        commandParam.Scale                   = (byte)yukonParam.scale;
                        commandParam.Size                    = yukonParam.size;
                        commandParam.SourceColumn            = yukonParam.sourceColumn;
                        commandParam.SourceColumnNullMapping = yukonParam.sourceColumnNull;
                        commandParam.SqlValue                = yukonParam.sqlValue;
                        commandParam.Type                    = (CmdParamsType)yukonParam.typeId;
                        commandParam.TypeName                = yukonParam.typeName;
                        commandParam.UdtTypeName             = yukonParam.udtTypeName;

                        if (!yukonParam.nullValueProvided)
                        {
                            string val = yukonParam.value as string;
                            if (val != null)
                            {
                                if (commandParam.Type == CmdParamsType.Binary || commandParam.Type == CmdParamsType.VarBinary || /*commandParam.Type == CmdParamsType.Image ||*/ commandParam.Type == CmdParamsType.Timestamp)
                                {
                                    System.Text.UTF8Encoding encoding = new System.Text.UTF8Encoding();
                                    commandParam.Value = encoding.GetBytes(val);
                                }
                                else if (commandParam.Type == CmdParamsType.DateTime || commandParam.Type == CmdParamsType.DateTime2 || commandParam.Type == CmdParamsType.Date || commandParam.Type == CmdParamsType.SmallDateTime)
                                {
                                    commandParam.Value = new DateTime(Convert.ToInt64(val));
                                }
                                else if (commandParam.Type == CmdParamsType.Time)
                                {
                                    commandParam.Value = new TimeSpan(Convert.ToInt64(val));
                                }
                                else if (commandParam.Type == CmdParamsType.DateTimeOffset)
                                {
                                    string[] dateOffset = val.Split(new char[] { ',' });
                                    commandParam.Value = new DateTimeOffset(new DateTime(Convert.ToInt64(dateOffset[0])), TimeSpan.FromMinutes(Convert.ToInt32(dateOffset[1])));
                                }
                                else if (commandParam.Type == CmdParamsType.Money || commandParam.Type == CmdParamsType.SmallMoney || commandParam.Type == CmdParamsType.Decimal)
                                {
                                    commandParam.Value = Convert.ToDecimal(val);
                                }
                                else if (commandParam.Type == CmdParamsType.Int)
                                {
                                    commandParam.Value = Convert.ToInt32(val);
                                }
                                else if (commandParam.Type == CmdParamsType.BigInt)
                                {
                                    commandParam.Value = Convert.ToInt64(val);
                                }
                                else if (commandParam.Type == CmdParamsType.SmallInt)
                                {
                                    commandParam.Value = Convert.ToInt16(val);
                                }
                                else if (commandParam.Type == CmdParamsType.Real)
                                {
                                    commandParam.Value = Convert.ToSingle(val);
                                }
                                else if (commandParam.Type == CmdParamsType.UniqueIdentifier)
                                {
                                    commandParam.Value = new Guid(val);
                                }
                                else if (commandParam.Type == CmdParamsType.TinyInt)
                                {
                                    commandParam.Value = Convert.ToByte(val);
                                }
                                else if (commandParam.Type == CmdParamsType.Float)
                                {
                                    commandParam.Value = Convert.ToDouble(val);
                                }
                                else if (commandParam.Type == CmdParamsType.Bit)
                                {
                                    commandParam.Value = Convert.ToBoolean(val);
                                }
                                else
                                {
                                    commandParam.Value = val;
                                }
                            }
                        }

                        parameters.Add(dependency.yukonDep[i].param[pc].key, commandParam);
                    }

                    SqlCacheDependency yukonDep = new SqlCacheDependency(dependency.yukonDep[i].connectionString,
                                                                         dependency.yukonDep[i].query,
                                                                         (SqlCommandType)dependency.yukonDep[i].commandType,
                                                                         parameters);

                    AddToDependency(ref cacheDependency, yukonDep);
                }
            }

            if (dependency.NosDep.Count > 0)
            {
                for (int i = 0; i < dependency.NosDep.Count; i++)
                {
                    Dictionary <string, object> parameters    = new Dictionary <string, object>();
                    NosDbDependency             nosDependency = dependency.NosDep[i];
                    for (int pc = 0; pc < nosDependency.param.Count; pc++)
                    {
                        parameters.Add(nosDependency.param[pc].key, nosDependency.param[pc].value);
                    }

                    NosDBDependency NosDep = new NosDBDependency(nosDependency.connectionString, nosDependency.query,
                                                                 parameters, nosDependency.timeout);
                    AddToDependency(ref cacheDependency, NosDep);
                }
            }


            return(cacheDependency);
        }