Exemplo n.º 1
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);
        }
Exemplo n.º 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);
        }
Exemplo n.º 3
0
        public static ExpirationHint GetExpirationHintObj(Alachisoft.NCache.Common.Protobuf.Dependency dependency, bool resyncOnExpiration, string serializationContext)
        {
            AggregateExpirationHint hints = new AggregateExpirationHint();

            if (dependency != null && dependency.keyDep != null && dependency.keyDep.Count > 0)
            {
                for (int i = 0; i < dependency.keyDep.Count; i++)
                {
                    Alachisoft.NCache.Caching.AutoExpiration.KeyDependency keyDep =
                        new Alachisoft.NCache.Caching.AutoExpiration.KeyDependency(dependency.keyDep[i].keys.ToArray(),
                                                                                   new DateTime(dependency.keyDep[i].startAfter));

                    hints.Add(keyDep);
                }
            }

            if (dependency != null && dependency.fileDep != null && dependency.fileDep.Count > 0)
            {
                for (int i = 0; i < dependency.fileDep.Count; i++)
                {
                    Alachisoft.NCache.Caching.AutoExpiration.FileDependency fileDep =
                        new Alachisoft.NCache.Caching.AutoExpiration.FileDependency(dependency.fileDep[i].filePaths.ToArray(),
                                                                                    new DateTime(dependency.fileDep[i].startAfter));

                    hints.Add(fileDep);
                }
            }

            if (dependency != null && dependency.oleDbDep != null && dependency.oleDbDep.Count > 0)
            {
                for (int i = 0; i < dependency.oleDbDep.Count; i++)
                {
                    OleDbCacheDependency oleDb = new OleDbCacheDependency(dependency.oleDbDep[i].connectionString,
                                                                          dependency.oleDbDep[i].dbCacheKey);

                    hints.Add(oleDb);
                }
            }



            if (dependency != null && dependency.sql7Dep != null && dependency.sql7Dep.Count > 0)
            {
                for (int i = 0; i < dependency.sql7Dep.Count; i++)
                {
                    Sql7CacheDependency sql7Dep = new Sql7CacheDependency(dependency.sql7Dep[i].connectionString,
                                                                          dependency.sql7Dep[i].dbCacheKey);

                    hints.Add(sql7Dep);
                }
            }


            if (dependency != null && dependency.xtDep != null && dependency.xtDep.Count > 0)
            {
                try
                {
                    for (int i = 0; i < dependency.xtDep.Count; i++)
                    {
                        IFormatter formater = new BinaryFormatter();
                        byte[]     buffer   = dependency.xtDep[i].data;
                        object     obj      = null;

                        using (MemoryStream stream = new MemoryStream(buffer))
                        {
                            obj = formater.Deserialize(stream);
                        }


                        Alachisoft.NCache.Caching.AutoExpiration.ExtensibleDependency xtDep =
                            new Alachisoft.NCache.Caching.AutoExpiration.ExtensibleDependency(
                                (Runtime.Dependencies.ExtensibleDependency)obj);


                        hints.Add(xtDep);
                    }
                }
                catch (SerializationException ex)
                {
                    throw new OperationFailedException(ex.Message);
                }
            }

            if (dependency != null && dependency.oracleDep != null && dependency.oracleDep.Count > 0)
            {
                for (int i = 0; i < dependency.oracleDep.Count; i++)
                {
                    Hashtable parameters = new Hashtable();
                    for (int pc = 0; pc < dependency.oracleDep[i].param.Count; pc++)
                    {
                        OracleCommandParams commandParam = new OracleCommandParams((Runtime.Dependencies.OracleCmdParamsType)dependency.oracleDep[i].param[pc].cmdParam.dbType,
                                                                                   dependency.oracleDep[i].param[pc].cmdParam.value,
                                                                                   (Runtime.Dependencies.OracleParameterDirection)dependency.oracleDep[i].param[pc].cmdParam.direction);
                        parameters.Add(dependency.oracleDep[i].param[pc].key, commandParam);
                    }

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

                    hints.Add(oraDep);
                }
            }



            if (dependency != null && dependency.yukonDep != null && dependency.yukonDep.Count > 0)
            {
                for (int i = 0; i < dependency.yukonDep.Count; i++)
                {
                    Hashtable parameters = new Hashtable();
                    for (int pc = 0; pc < dependency.yukonDep[i].param.Count; pc++)
                    {
                        YukonCommandParam yukonParam   = dependency.yukonDep[i].param[pc].cmdParam;
                        SqlCmdParams      commandParam = new SqlCmdParams((SqlDbType)yukonParam.dbType, yukonParam.value);

                        commandParam.CmpInfo                 = (System.Data.SqlTypes.SqlCompareOptions)yukonParam.cmpOptions;
                        commandParam.Direction               = (ParameterDirection)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.ParamSize               = yukonParam.size;
                        commandParam.SourceColumn            = yukonParam.sourceColumn;
                        commandParam.SourceColumnNullMapping = yukonParam.sourceColumnNull;
                        commandParam.SqlValue                = yukonParam.sqlValue;
                        commandParam.SrcVersion              = (DataRowVersion)yukonParam.version;
                        commandParam.DbType                  = (SqlDbType)yukonParam.typeId;
                        commandParam.TypeName                = yukonParam.typeName;
                        commandParam.UdtName                 = yukonParam.udtTypeName;

                        if (!yukonParam.nullValueProvided)
                        {
                            string val = yukonParam.value as string;
                            if (val != null)
                            {
                                if (commandParam.DbType == SqlDbType.Binary || commandParam.DbType == SqlDbType.VarBinary || commandParam.DbType == SqlDbType.Image || commandParam.DbType == SqlDbType.Timestamp)
                                {
                                    System.Text.UTF8Encoding encoding = new System.Text.UTF8Encoding();
                                    commandParam.Value = encoding.GetBytes(val);
                                }
                                else if (commandParam.DbType == SqlDbType.DateTime || commandParam.DbType == SqlDbType.DateTime2 || commandParam.DbType == SqlDbType.Date || commandParam.DbType == SqlDbType.SmallDateTime)
                                {
                                    commandParam.Value = new DateTime(Convert.ToInt64(val));
                                }
                                else if (commandParam.DbType == SqlDbType.Time)
                                {
                                    commandParam.Value = new TimeSpan(Convert.ToInt64(val));
                                }
                                else if (commandParam.DbType == SqlDbType.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.DbType == SqlDbType.Money || commandParam.DbType == SqlDbType.SmallMoney || commandParam.DbType == SqlDbType.Decimal)
                                {
                                    commandParam.Value = Convert.ToDecimal(val);
                                }
                                else if (commandParam.DbType == SqlDbType.Int)
                                {
                                    commandParam.Value = Convert.ToInt32(val);
                                }
                                else if (commandParam.DbType == SqlDbType.BigInt)
                                {
                                    commandParam.Value = Convert.ToInt64(val);
                                }
                                else if (commandParam.DbType == SqlDbType.SmallInt)
                                {
                                    commandParam.Value = Convert.ToInt16(val);
                                }
                                else if (commandParam.DbType == SqlDbType.Real)
                                {
                                    commandParam.Value = Convert.ToSingle(val);
                                }
                                else if (commandParam.DbType == SqlDbType.UniqueIdentifier)
                                {
                                    commandParam.Value = System.Data.SqlTypes.SqlGuid.Parse(val);
                                }
                                else if (commandParam.DbType == SqlDbType.TinyInt)
                                {
                                    commandParam.Value = Convert.ToByte(val);
                                }
                                else if (commandParam.DbType == SqlDbType.Float)
                                {
                                    commandParam.Value = Convert.ToDouble(val);
                                }
                                else if (commandParam.DbType == SqlDbType.Bit)
                                {
                                    commandParam.Value = Convert.ToBoolean(val);
                                }
                                else
                                {
                                    commandParam.Value = val;
                                }
                            }
                            else
                            {
                                commandParam.Value = DBNull.Value;
                            }
                        }
                        else
                        {
                            commandParam.Value = DBNull.Value;
                        }

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

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

                    hints.Add(yukonDep);
                }
            }
            if (dependency != null && dependency.NosDep != null && dependency.NosDep.Count > 0)
            {
                for (int i = 0; i < dependency.NosDep.Count; i++)
                {
                    Hashtable parameters = new Hashtable();
                    for (int pc = 0; pc < dependency.NosDep[i].param.Count; pc++)
                    {
                        parameters.Add(dependency.NosDep[i].param[pc].key, dependency.NosDep[i].param[pc].value);
                    }
                    NosDBCacheDependency oraDep = new NosDBCacheDependency(dependency.NosDep[i].connectionString,
                                                                           dependency.NosDep[i].query,
                                                                           dependency.NosDep[i].timeout,
                                                                           parameters);

                    hints.Add(oraDep);
                }
            }


            if (resyncOnExpiration)
            {
                hints.SetBit(ExpirationHint.NEEDS_RESYNC);
            }

            IList <ExpirationHint> expHints = hints.Hints;

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

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

            return(hints);
        }