示例#1
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);
        }
示例#2
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);
        }
示例#3
0
        public static ExpirationHint ReadExpHint(CompactReader reader)
        {
            ExpirationHintType expHint = ExpirationHintType.Parent;

            expHint = (ExpirationHintType)reader.ReadInt16();
            ExpirationHint tmpObj = null;

            switch (expHint)
            {
            case ExpirationHintType.NULL:
                return(null);

            case ExpirationHintType.Parent:
                tmpObj = (ExpirationHint)reader.ReadObject();
                return((ExpirationHint)tmpObj);

            case ExpirationHintType.FixedExpiration:
                FixedExpiration fe = new FixedExpiration();
                ((ICompactSerializable)fe).Deserialize(reader);
                return((ExpirationHint)fe);

            case ExpirationHintType.TTLExpiration:
                TTLExpiration ttle = new TTLExpiration();
                ((ICompactSerializable)ttle).Deserialize(reader);
                return((ExpirationHint)ttle);

            case ExpirationHintType.TTLIdleExpiration:
                TTLIdleExpiration ttlie = new TTLIdleExpiration();
                ((ICompactSerializable)ttlie).Deserialize(reader);
                return((ExpirationHint)ttlie);

            case ExpirationHintType.FixedIdleExpiration:
                FixedIdleExpiration fie = new FixedIdleExpiration();
                ((ICompactSerializable)fie).Deserialize(reader);
                return((ExpirationHint)fie);

            case ExpirationHintType.FileDependency:
                FileDependency fd = new FileDependency();
                ((ICompactSerializable)fd).Deserialize(reader);
                return((ExpirationHint)fd);

            case ExpirationHintType.KeyDependency:
                KeyDependency kd = new KeyDependency();
                ((ICompactSerializable)kd).Deserialize(reader);
                return((ExpirationHint)kd);

#if !(DEVELOPMENT || CLIENT)
            case ExpirationHintType.NodeExpiration:
                NodeExpiration ne = new NodeExpiration();
                ((ICompactSerializable)ne).Deserialize(reader);
                return((ExpirationHint)ne);
#endif
            case ExpirationHintType.Sql7CacheDependency:
                Sql7CacheDependency s7cd = new Sql7CacheDependency();
                ((ICompactSerializable)s7cd).Deserialize(reader);
                return((ExpirationHint)s7cd);

            case ExpirationHintType.OleDbCacheDependency:
                OleDbCacheDependency oledbDependency = new OleDbCacheDependency();
                ((ICompactSerializable)oledbDependency).Deserialize(reader);
                return((ExpirationHint)oledbDependency);

            case ExpirationHintType.SqlYukonCacheDependency:
                SqlYukonCacheDependency sycd = new SqlYukonCacheDependency();
                ((ICompactSerializable)sycd).Deserialize(reader);
                return((ExpirationHint)sycd);

            case ExpirationHintType.OracleCacheDependency:
                OracleCacheDependency orclcd = new OracleCacheDependency();
                ((ICompactSerializable)orclcd).Deserialize(reader);
                return((ExpirationHint)orclcd);


            case ExpirationHintType.IdleExpiration:
                IdleExpiration ie = new IdleExpiration();
                ((ICompactSerializable)ie).Deserialize(reader);
                return((ExpirationHint)ie);

            case ExpirationHintType.AggregateExpirationHint:
                AggregateExpirationHint aeh = new AggregateExpirationHint();
                ((ICompactSerializable)aeh).Deserialize(reader);
                return((ExpirationHint)aeh);

            case ExpirationHintType.DBCacheDependency:
                DBCacheDependency dbcd = new DBCacheDependency();
                ((ICompactSerializable)dbcd).Deserialize(reader);
                return((ExpirationHint)dbcd);

            case ExpirationHintType.ExtensibleDependency:
                ExtensibleDependency ed = new ExtensibleDependency();
                ed = (ExtensibleDependency)reader.ReadObject();
                return((ExpirationHint)ed);

            case ExpirationHintType.NosDBCacheDependency:
                NosDBCacheDependency nosDbd = new NosDBCacheDependency();
                ((ICompactSerializable)nosDbd).Deserialize(reader);
                return(nosDbd);

            case ExpirationHintType.DependencyHint:
                break;

            default:
                break;
            }
            return(null);
        }
示例#4
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);
        }
示例#5
0
        private static Alachisoft.NCache.Common.Protobuf.OracleDependency GetOracleDependency(Alachisoft.NCache.Caching.AutoExpiration.OracleCacheDependency oracleDep)
        {
            Alachisoft.NCache.Common.Protobuf.OracleDependency protoOraDep = new Alachisoft.NCache.Common.Protobuf.OracleDependency();
            protoOraDep.commandType      = (int)oracleDep.CommandType;
            protoOraDep.connectionString = oracleDep.ConnectionString;
            protoOraDep.query            = oracleDep.QueryString;

            foreach (DictionaryEntry entry in oracleDep.CommandParams)
            {
                OracleCommandParams oracleCommandParams = (OracleCommandParams)entry.Value;

                OracleParam param = new OracleParam();
                param.key = (string)entry.Key;

                param.cmdParam           = new OracleCommandParam();
                param.cmdParam.dbType    = (int)oracleCommandParams.Type;
                param.cmdParam.direction = (int)oracleCommandParams.Direction;
                param.cmdParam.value     = oracleCommandParams.Value.ToString();

                protoOraDep.param.Add(param);
            }

            return(protoOraDep);
        }