Exemplo n.º 1
0
        private static ExpirationHint GetExpirationHint(CacheDependency cacheDependency, AggregateExpirationHint aggregateHint)
        {
            if (cacheDependency == null)
            {
                return(null);
            }

            ExpirationHint hint = null;

            if (cacheDependency is Runtime.Dependencies.KeyDependency)
            {
                Runtime.Dependencies.KeyDependency keyDependency = cacheDependency as Runtime.Dependencies.KeyDependency;
                hint = new KeyDependency(keyDependency.CacheKeys, new DateTime(keyDependency.StartAfterTicks));

                aggregateHint.Add(hint);
            }


            else if (cacheDependency is Runtime.Dependencies.FileDependency)
            {
                Runtime.Dependencies.FileDependency fileDependency = cacheDependency as Runtime.Dependencies.FileDependency;

                hint = new FileDependency(fileDependency.fileNames, new DateTime(fileDependency.StartAfterTicks));

                aggregateHint.Add(hint);
            }

            else if (cacheDependency is Runtime.Dependencies.DBCacheDependency)
            {
                Runtime.Dependencies.DBCacheDependency dbDependency = cacheDependency as Runtime.Dependencies.DBCacheDependency;

                switch (dbDependency.Type)
                {
                case Runtime.Dependencies.DBDependencyType.OleDbCacheDependency:
                    hint = new OleDbCacheDependency(dbDependency.ConnectionString, dbDependency.PrimaryKey);
                    break;

                case Runtime.Dependencies.DBDependencyType.SqlCacheDependency:
                    hint = new Sql7CacheDependency(dbDependency.ConnectionString, dbDependency.PrimaryKey);
                    break;
                }

                aggregateHint.Add(hint);
            }


            else if (cacheDependency is Runtime.Dependencies.OracleCacheDependency)
            {
                Runtime.Dependencies.OracleCacheDependency oracleDependency = cacheDependency as Runtime.Dependencies.OracleCacheDependency;

                Hashtable parameters = new Hashtable();
                if (oracleDependency.CommandParams != null)
                {
                    foreach (KeyValuePair <string, Runtime.Dependencies.OracleCmdParams> pair in oracleDependency.CommandParams)
                    {
                        Runtime.Dependencies.OracleCmdParams oracleCommandParams = pair.Value;
                        OracleCommandParams commandParam = new OracleCommandParams((OracleCmdParamsType)oracleCommandParams.Type, oracleCommandParams.Value, oracleCommandParams.Direction);
                        parameters.Add(pair.Key, commandParam);
                    }
                }

                hint = new OracleCacheDependency(oracleDependency.ConnectionString, oracleDependency.CommandText, oracleDependency.CommandType, parameters);
                aggregateHint.Add(hint);
            }



            else if (cacheDependency is Runtime.Dependencies.SqlCacheDependency)
            {
                Runtime.Dependencies.SqlCacheDependency sqlDependency = cacheDependency as Runtime.Dependencies.SqlCacheDependency;

                Hashtable parameters = new Hashtable();

                if (sqlDependency.CommandParams != null)
                {
                    foreach (KeyValuePair <string, Runtime.Dependencies.SqlCmdParams> pair in sqlDependency.CommandParams)
                    {
                        Runtime.Dependencies.SqlCmdParams param = pair.Value;

                        Alachisoft.NCache.Caching.AutoExpiration.SqlCmdParams commandParam = new SqlCmdParams();
                        commandParam.CmpInfo                 = param.SqlCmpInfo;
                        commandParam.Direction               = param.SqlParamDir;
                        commandParam.IsNullable              = param.IsNullable;
                        commandParam.LocaleID                = param.LocaleID;
                        commandParam.Offset                  = param.Offset;
                        commandParam.Precision               = param.Precision;
                        commandParam.Scale                   = param.Scale;
                        commandParam.ParamSize               = param.Size;
                        commandParam.SourceColumn            = param.SourceColumn;
                        commandParam.SourceColumnNullMapping = param.SourceColumnNullMapping;
                        commandParam.SqlValue                = param.SqlValue;
                        commandParam.SrcVersion              = param.SrcVersion;
                        commandParam.DbType                  = (SqlDbType)param.Type;
                        commandParam.TypeName                = param.TypeName;
                        commandParam.UdtName                 = param.UdtTypeName;
                        commandParam.Value                   = param.Value;
                        parameters.Add(pair.Key, commandParam);
                    }
                }

                hint = new SqlYukonCacheDependency(sqlDependency.ConnectionString, sqlDependency.CommandText, sqlDependency.CommandType, parameters);
                aggregateHint.Add(hint);
            }


            else if (cacheDependency is Runtime.Dependencies.ExtensibleDependency)
            {
                hint = new ExtensibleDependency(cacheDependency as Runtime.Dependencies.ExtensibleDependency);

                aggregateHint.Add(hint);
            }
            else if (cacheDependency is NosDBDependency)
            {
                NosDBDependency nosDbDependency = cacheDependency as NosDBDependency;
                hint = new NosDBCacheDependency(nosDbDependency.ConnectionString, nosDbDependency.CommandText, nosDbDependency.Timeout, nosDbDependency.Parameters);
                aggregateHint.Add(hint);
            }
            else
            {
                foreach (CacheDependency dep in cacheDependency.Dependencies)
                {
                    hint = GetExpirationHint(dep, aggregateHint);
                }
            }
            IList <ExpirationHint> hints = aggregateHint.Hints;

            if (hints.Count == 0)
            {
                return(null);
            }

            if (hints.Count == 1)
            {
                return(hints[0]);
            }

            return(aggregateHint);
        }
Exemplo n.º 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);
        }
Exemplo n.º 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);
        }