private SqlCacheDependency GetCustomerIDsByCountrySqlDependency(
            string country)
        {
            var sqlQuery = $"SELECT CustomerID " +
                           $"FROM dbo.Customers " +
                           $"WHERE Country = @country";

            var cmdParam = new SqlCmdParams
            {
                Value = country,
                Size  = 255,
                Type  = CmdParamsType.NVarChar
            };

            var sqlCmdParams = new Dictionary <string, SqlCmdParams>
            {
                { "@country", cmdParam }
            };

            return(new SqlCacheDependency(
                       ConnectionString,
                       sqlQuery,
                       SqlCommandType.Text,
                       sqlCmdParams));
        }
Example #2
0
        private static SqlCacheDependency GetCustomerSqlDependency(
            string customerId)
        {
            var sqlQuery = $"SELECT CustomerID, " +
                           $"       CompanyName, " +
                           $"       ContactName, " +
                           $"       ContactTitle, " +
                           $"       City, " +
                           $"       Country, " +
                           $"       Region, " +
                           $"       PostalCode, " +
                           $"       Phone, " +
                           $"       Fax, " +
                           $"       Address " +
                           $"FROM dbo.Customers " +
                           $"WHERE CustomerID = @cid";

            var cmdParam = new SqlCmdParams
            {
                Value = customerId,
                Size  = 255,
                Type  = CmdParamsType.NVarChar
            };

            var sqlCmdParams = new Dictionary <string, SqlCmdParams>
            {
                { "@cid", cmdParam }
            };

            return(new SqlCacheDependency(
                       connectionString,
                       sqlQuery,
                       SqlCommandType.Text,
                       sqlCmdParams));
        }
Example #3
0
        private SqlCacheDependency CreateSqlDepenedency(string conString, DbCommand dbCommand)
        {
            SqlCommand         sqlCmd      = dbCommand as SqlCommand;
            SqlCacheDependency depenedency = null;

            if (sqlCmd != null)
            {
                depenedency = new SqlCacheDependency(conString, sqlCmd.CommandText.StripTabsAndNewlines());
                if (sqlCmd.Parameters != null && sqlCmd.Parameters.Count > 0)
                {
                    foreach (SqlParameter parameter in sqlCmd.Parameters)
                    {
                        SqlCmdParams dependencyParameter = new SqlCmdParams();
                        //dependencyParameter.Direction = (SqlParamDirection)((int)parameter.Direction - 1);
                        switch (parameter.Direction)
                        {
                        case ParameterDirection.Input:
                            dependencyParameter.Direction = SqlParamDirection.Input;
                            break;

                        case ParameterDirection.InputOutput:
                            dependencyParameter.Direction = SqlParamDirection.InputOutput;
                            break;

                        case ParameterDirection.Output:
                            dependencyParameter.Direction = SqlParamDirection.Output;
                            break;

                        case ParameterDirection.ReturnValue:
                            dependencyParameter.Direction = SqlParamDirection.ReturnValue;
                            break;
                        }
                        dependencyParameter.IsNullable              = parameter.IsNullable;
                        dependencyParameter.LocaleID                = parameter.LocaleId;
                        dependencyParameter.Offset                  = parameter.Offset;
                        dependencyParameter.Precision               = parameter.Precision;
                        dependencyParameter.Scale                   = parameter.Scale;
                        dependencyParameter.Size                    = parameter.Size;
                        dependencyParameter.SourceColumn            = parameter.SourceColumn;
                        dependencyParameter.SourceColumnNullMapping = parameter.SourceColumnNullMapping;
                        dependencyParameter.SourceVersion           = (SqlDataRowVersion)parameter.SourceVersion;
                        dependencyParameter.SqlValue                = parameter.SqlValue;
                        dependencyParameter.UdtTypeName             = parameter.UdtTypeName;
                        dependencyParameter.SourceColumn            = parameter.SourceColumn;
                        dependencyParameter.Type                    = (CmdParamsType)parameter.SqlDbType;
                        dependencyParameter.TypeName                = parameter.TypeName;
                        dependencyParameter.SourceColumn            = parameter.SourceColumn;
                        dependencyParameter.Value                   = parameter.Value;


                        depenedency.CommandParams.Add(parameter.ParameterName, dependencyParameter);
                    }
                }
            }
            return(depenedency);
        }
Example #4
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="command"></param>
        /// <param name="expHint"></param>
        /// <param name="beginQuoteIndex"></param>
        /// <param name="endQuoteIndex"></param>
        public ExpirationHint CreateDependencyFromString(ref string command, ref byte[] data, string cacheId, ref int beginQuoteIndex, ref int endQuoteIndex, bool isBulkOps, object items, ref int currentXtDep)
        {
            bool   isInner = false;
            string interimCommand = null;
            int    interimBeginIndex = 0, interimEndIndex = 0;

            ExpirationHint          expirationHint = null;
            AggregateExpirationHint aggregateExpiration = null;

            do
            {
                beginQuoteIndex += interimEndIndex;

                UpdateDelimIndexes(command, '\r', ref beginQuoteIndex, ref endQuoteIndex);
                if (endQuoteIndex < 0)
                {
                    break;
                }

                interimCommand = command.Substring(beginQuoteIndex + 1, endQuoteIndex - beginQuoteIndex - 1).Remove(0, 1);

                if (interimCommand == string.Empty)
                {
                    break;
                }
                if (interimCommand.StartsWith("\""))
                {
                    endQuoteIndex = beginQuoteIndex;
                    break;
                }

                interimBeginIndex = interimEndIndex = 0;

                if (interimCommand.StartsWith("INNER") && !isInner)
                {
                    isInner             = true;
                    aggregateExpiration = new AggregateExpirationHint();
                }
                else if (interimCommand.StartsWith("FILEDEPENDENCY")

                         || interimCommand.StartsWith("KEYDEPENDENCY")

                         )
                {
                    string    value = null;
                    DateTime  startAfter;
                    ArrayList list = new ArrayList();

                    UpdateDelimIndexes(interimCommand, '"', ref interimBeginIndex, ref interimEndIndex);
                    while (true)
                    {
                        UpdateDelimIndexes(interimCommand, '"', ref interimBeginIndex, ref interimEndIndex);

                        value = interimCommand.Substring(interimBeginIndex + 1, interimEndIndex - interimBeginIndex - 1);
                        int valueBeginIndex = 0, valueEndIndex = 0;

                        if (value.Equals("STARTAFTER"))
                        {
                            UpdateDelimIndexes(interimCommand, '"', ref interimBeginIndex, ref interimEndIndex);
                            startAfter = new DateTime(Convert.ToInt64(interimCommand.Substring(interimBeginIndex + 1, interimEndIndex - interimBeginIndex - 1)));

                            interimBeginIndex += valueBeginIndex; interimEndIndex += valueEndIndex;

                            break;
                        }
                        else
                        {
                            list.Add(value);
                        }
                    }

                    if (interimCommand.StartsWith("KEYDEPENDENCY"))
                    {
                        expirationHint = new KeyDependency((string[])list.ToArray(typeof(string)), startAfter);
                    }
                    else
                    {
                        expirationHint = new FileDependency((string[])list.ToArray(typeof(string)), startAfter);
                    }
                }
                else if (interimCommand.StartsWith("EXTDEPENDENCY"))
                {
                    if (!isBulkOps)
                    {
                        UpdateDelimIndexes(interimCommand, '"', ref interimBeginIndex, ref interimEndIndex);
                        UpdateDelimIndexes(interimCommand, '"', ref interimBeginIndex, ref interimEndIndex);
                        int extensibleDepStartIndex = Convert.ToInt32(interimCommand.Substring(interimBeginIndex + 1, interimEndIndex - interimBeginIndex - 1));

                        UpdateDelimIndexes(interimCommand, '"', ref interimBeginIndex, ref interimEndIndex);
                        int extensibleDepEndIndex = Convert.ToInt32(interimCommand.Substring(interimBeginIndex + 1, interimEndIndex - interimBeginIndex - 1));

                        byte[] value = null;
                        byte[] extensibleDependency = new byte[extensibleDepEndIndex - extensibleDepStartIndex];
                        value = new byte[extensibleDepStartIndex];

                        MemoryStream mStream = new MemoryStream(data);
                        mStream.Read(value, 0, extensibleDepStartIndex);
                        mStream.Read(extensibleDependency, 0, extensibleDepEndIndex - extensibleDepStartIndex);
                        mStream.Close();

                        data = value;

                        expirationHint = (ExtensibleDependency)Serialization.Formatters.CompactBinaryFormatter.FromByteBuffer(extensibleDependency, cacheId);
                    }
                    else
                    {
                        ArrayList        userItems  = items as ArrayList;
                        UserBinaryObject userBinObj = userItems[currentXtDep++] as UserBinaryObject;
                        if (userBinObj != null)
                        {
                            expirationHint = (ExtensibleDependency)Serialization.Formatters.CompactBinaryFormatter.FromByteBuffer(userBinObj.GetFullObject(), cacheId);
                        }
                    }
                }
                else if (interimCommand.StartsWith("SQL7DEPENDENCY")

                         || interimCommand.StartsWith("OLEDBDEPENDENCY")

                         )
                {
                    UpdateDelimIndexes(interimCommand, '"', ref interimBeginIndex, ref interimEndIndex);
                    UpdateDelimIndexes(interimCommand, '"', ref interimBeginIndex, ref interimEndIndex);
                    string connectionString = interimCommand.Substring(interimBeginIndex + 1, interimEndIndex - interimBeginIndex - 1);

                    UpdateDelimIndexes(interimCommand, '"', ref interimBeginIndex, ref interimEndIndex);
                    string cacheKey = interimCommand.Substring(interimBeginIndex + 1, interimEndIndex - interimBeginIndex - 1);


                    if (interimCommand.StartsWith("OLEDBDEPENDENCY"))
                    {
                        expirationHint = new OleDbCacheDependency(connectionString, cacheKey);
                    }
                    else
                    {
                        expirationHint = new Sql7CacheDependency(connectionString, cacheKey);
                    }
                }
                else if (interimCommand.StartsWith("YUKONDEPENDENCY"))
                {
                    UpdateDelimIndexes(interimCommand, '"', ref interimBeginIndex, ref interimEndIndex);
                    UpdateDelimIndexes(interimCommand, '"', ref interimBeginIndex, ref interimEndIndex);
                    string connectionString = interimCommand.Substring(interimBeginIndex + 1, interimEndIndex - interimBeginIndex - 1);

                    UpdateDelimIndexes(interimCommand, '"', ref interimBeginIndex, ref interimEndIndex);
                    string queryString = interimCommand.Substring(interimBeginIndex + 1, interimEndIndex - interimBeginIndex - 1);

                    UpdateDelimIndexes(interimCommand, '"', ref interimBeginIndex, ref interimEndIndex);
                    string      commandType = interimCommand.Substring(interimBeginIndex + 1, interimEndIndex - interimBeginIndex - 1);
                    CommandType cmdType     = (CommandType)Convert.ToInt32(commandType);

                    UpdateDelimIndexes(interimCommand, '"', ref interimBeginIndex, ref interimEndIndex);
                    string cmdParamId = interimCommand.Substring(interimBeginIndex + 1, interimEndIndex - interimBeginIndex - 1);


                    if (interimCommand.StartsWith("ORACLEDEPENDENCY"))
                    {
                        Hashtable cmdParams = new Hashtable();
                        if (cmdParamId != string.Empty)
                        {
                            while (true)
                            {
                                UpdateDelimIndexes(interimCommand, '"', ref interimBeginIndex, ref interimEndIndex);
                                if (interimEndIndex == -1)
                                {
                                    break;
                                }
                                string key = interimCommand.Substring(interimBeginIndex + 1, interimEndIndex - interimBeginIndex - 1);

                                UpdateDelimIndexes(interimCommand, '"', ref interimBeginIndex, ref interimEndIndex);
                                string type = interimCommand.Substring(interimBeginIndex + 1, interimEndIndex - interimBeginIndex - 1);
                                Runtime.Dependencies.OracleCmdParamsType oracleType = (Runtime.Dependencies.OracleCmdParamsType)Convert.ToInt32(type);

                                UpdateDelimIndexes(interimCommand, '"', ref interimBeginIndex, ref interimEndIndex);
                                object value = interimCommand.Substring(interimBeginIndex + 1, interimEndIndex - interimBeginIndex - 1);

                                UpdateDelimIndexes(interimCommand, '"', ref interimBeginIndex, ref interimEndIndex);
                                string direction = interimCommand.Substring(interimBeginIndex + 1, interimEndIndex - interimBeginIndex - 1);
                                Runtime.Dependencies.OracleParameterDirection oracleParamDirection = (Runtime.Dependencies.OracleParameterDirection)Convert.ToInt32(direction);


                                OracleCommandParams oracleParams = new OracleCommandParams(oracleType, value, oracleParamDirection);
                                cmdParams.Add(key, oracleParams);
                            }
                        }
                        if (cmdParams.Count > 0)
                        {
                            expirationHint = new OracleCacheDependency(connectionString, queryString, cmdType, cmdParams);
                        }
                        else
                        {
                            expirationHint = new OracleCacheDependency(connectionString, queryString, cmdType, new Hashtable());
                        }
                    }
                    else
                    {
                        Hashtable cmdParams = new Hashtable();
                        if (cmdParamId != string.Empty)
                        {
                            while (true)
                            {
                                UpdateDelimIndexes(interimCommand, '"', ref interimBeginIndex, ref interimEndIndex);
                                if (interimEndIndex == -1)
                                {
                                    break;
                                }
                                string key = interimCommand.Substring(interimBeginIndex + 1, interimEndIndex - interimBeginIndex - 1);

                                UpdateDelimIndexes(interimCommand, '"', ref interimBeginIndex, ref interimEndIndex);
                                string    type    = interimCommand.Substring(interimBeginIndex + 1, interimEndIndex - interimBeginIndex - 1);
                                SqlDbType sqlType = (SqlDbType)Convert.ToInt32(type);

                                UpdateDelimIndexes(interimCommand, '"', ref interimBeginIndex, ref interimEndIndex);
                                string             direction      = interimCommand.Substring(interimBeginIndex + 1, interimEndIndex - interimBeginIndex - 1);
                                ParameterDirection paramDirection = (ParameterDirection)Convert.ToInt32(direction);

                                UpdateDelimIndexes(interimCommand, '"', ref interimBeginIndex, ref interimEndIndex);
                                string dbtype = interimCommand.Substring(interimBeginIndex + 1, interimEndIndex - interimBeginIndex - 1);
                                DbType dbType = (DbType)Convert.ToInt32(dbtype);

                                UpdateDelimIndexes(interimCommand, '"', ref interimBeginIndex, ref interimEndIndex);
                                string            cmpOptions     = interimCommand.Substring(interimBeginIndex + 1, interimEndIndex - interimBeginIndex - 1);
                                SqlCompareOptions compareOptions = (SqlCompareOptions)Convert.ToInt32(cmpOptions);

                                UpdateDelimIndexes(interimCommand, '"', ref interimBeginIndex, ref interimEndIndex);
                                string         srcVer     = interimCommand.Substring(interimBeginIndex + 1, interimEndIndex - interimBeginIndex - 1);
                                DataRowVersion srcVersion = (DataRowVersion)Convert.ToInt32(srcVer);

                                UpdateDelimIndexes(interimCommand, '"', ref interimBeginIndex, ref interimEndIndex);
                                object value = interimCommand.Substring(interimBeginIndex + 1, interimEndIndex - interimBeginIndex - 1);
                                if (value.ToString() == "#")
                                {
                                    value = null;
                                }

                                UpdateDelimIndexes(interimCommand, '"', ref interimBeginIndex, ref interimEndIndex);
                                bool isNullable = Convert.ToBoolean(interimCommand.Substring(interimBeginIndex + 1, interimEndIndex - interimBeginIndex - 1));

                                UpdateDelimIndexes(interimCommand, '"', ref interimBeginIndex, ref interimEndIndex);
                                int localeId = Convert.ToInt32(interimCommand.Substring(interimBeginIndex + 1, interimEndIndex - interimBeginIndex - 1));

                                UpdateDelimIndexes(interimCommand, '"', ref interimBeginIndex, ref interimEndIndex);
                                int offset = Convert.ToInt32(interimCommand.Substring(interimBeginIndex + 1, interimEndIndex - interimBeginIndex - 1));

                                UpdateDelimIndexes(interimCommand, '"', ref interimBeginIndex, ref interimEndIndex);
                                byte precision = Convert.ToByte(interimCommand.Substring(interimBeginIndex + 1, interimEndIndex - interimBeginIndex - 1));

                                UpdateDelimIndexes(interimCommand, '"', ref interimBeginIndex, ref interimEndIndex);
                                byte scale = Convert.ToByte(interimCommand.Substring(interimBeginIndex + 1, interimEndIndex - interimBeginIndex - 1));

                                UpdateDelimIndexes(interimCommand, '"', ref interimBeginIndex, ref interimEndIndex);
                                int size = Convert.ToInt32(interimCommand.Substring(interimBeginIndex + 1, interimEndIndex - interimBeginIndex - 1));

                                UpdateDelimIndexes(interimCommand, '"', ref interimBeginIndex, ref interimEndIndex);
                                string sourceColumn = (interimCommand.Substring(interimBeginIndex + 1, interimEndIndex - interimBeginIndex - 1));
                                if (sourceColumn == "#")
                                {
                                    sourceColumn = "";
                                }

                                UpdateDelimIndexes(interimCommand, '"', ref interimBeginIndex, ref interimEndIndex);
                                bool sourceColumnNullMapping = Convert.ToBoolean(interimCommand.Substring(interimBeginIndex + 1, interimEndIndex - interimBeginIndex - 1));

                                UpdateDelimIndexes(interimCommand, '"', ref interimBeginIndex, ref interimEndIndex);
                                object sqlValue = (interimCommand.Substring(interimBeginIndex + 1, interimEndIndex - interimBeginIndex - 1));
                                if (sqlValue.ToString() == "#")
                                {
                                    sqlValue = null;
                                }

                                UpdateDelimIndexes(interimCommand, '"', ref interimBeginIndex, ref interimEndIndex);
                                string typeName = (interimCommand.Substring(interimBeginIndex + 1, interimEndIndex - interimBeginIndex - 1));
                                if (typeName == "#")
                                {
                                    typeName = "";
                                }

                                UpdateDelimIndexes(interimCommand, '"', ref interimBeginIndex, ref interimEndIndex);
                                string udtTypeName = (interimCommand.Substring(interimBeginIndex + 1, interimEndIndex - interimBeginIndex - 1));
                                if (udtTypeName == "#")
                                {
                                    udtTypeName = "";
                                }

                                SqlCmdParams sqlParams = new SqlCmdParams(sqlType, value);
                                sqlParams.CmpInfo                 = compareOptions;
                                sqlParams.Direction               = paramDirection;
                                sqlParams.IsNullable              = isNullable;
                                sqlParams.LocaleID                = localeId;
                                sqlParams.Offset                  = offset;
                                sqlParams.Precision               = precision;
                                sqlParams.Scale                   = scale;
                                sqlParams.ParamSize               = size;
                                sqlParams.SourceColumn            = sourceColumn;
                                sqlParams.SourceColumnNullMapping = sourceColumnNullMapping;
                                sqlParams.SqlValue                = sqlValue;
                                sqlParams.SrcVersion              = srcVersion;
                                sqlParams.TypeName                = typeName;
                                sqlParams.UdtName                 = udtTypeName;
                                cmdParams.Add(key, sqlParams);
                            }
                        }

                        if (cmdParams.Count > 0)
                        {
                            expirationHint = new SqlYukonCacheDependency(connectionString, queryString, cmdType, cmdParams);
                        }
                        else
                        {
                            expirationHint = new SqlYukonCacheDependency(connectionString, queryString, cmdType, new Hashtable());
                        }
                    }
                }

                if (interimCommand != "INNER" && isInner && expirationHint != null)
                {
                    aggregateExpiration.Add(expirationHint);
                }
            } while (endQuoteIndex > -1);

            return(aggregateExpiration == null ? expirationHint : aggregateExpiration);
        }
Example #5
0
        public override CacheDependency GetCacheDependency(
            string connectionString,
            object key)
        {
            var cmdType =
                IsStoredProcedure ?
                SqlCommandType.StoredProcedure :
                SqlCommandType.Text;

            string cmdText = GetCommand();

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

            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 SqlCmdParams();
                cmdParam.Value     = key;
                cmdParam.Type      = GetCommandParamType(PrimaryKeyDbType);
                cmdParam.Direction = SqlParamDirection.Input;

                var cmdParamKey = IsStoredProcedure ?
                                  $"{PrimaryKeyInputParameter}" :
                                  $"@{PrimaryKeyInputParameter}";

                cmdParams.Add(cmdParamKey, 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. Please check your " +
                                  "dependency configuration");
                    }
                    var cmdParam = new SqlCmdParams();
                    cmdParam.Type      = GetCommandParamType(pairType);
                    cmdParam.Direction = SqlParamDirection.Output;
                    cmdParam.Size      = int.MaxValue;

                    cmdParams.Add(pairKey, cmdParam);
                }
            }

            return(new SqlCacheDependency(
                       connectionString,
                       cmdText,
                       cmdType,
                       cmdParams));
        }
Example #6
0
        private static YukonDependency GetYukonDependency(SqlYukonCacheDependency yukonDep)
        {
            YukonDependency protoYukonDep = new YukonDependency();

            protoYukonDep.commandType      = (int)yukonDep.CommandType;
            protoYukonDep.connectionString = yukonDep.ConnectionString;
            protoYukonDep.query            = yukonDep.QueryString;

            foreach (DictionaryEntry entry in yukonDep.CommandParams)
            {
                SqlCmdParams yukonCommandParams = (SqlCmdParams)entry.Value;

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

                param.cmdParam                   = new YukonCommandParam();
                param.cmdParam.cmpOptions        = (int)yukonCommandParams.CmpInfo;
                param.cmdParam.direction         = (int)yukonCommandParams.Direction;
                param.cmdParam.isNullable        = yukonCommandParams.IsNullable;
                param.cmdParam.localeId          = yukonCommandParams.LocaleID;
                param.cmdParam.offset            = yukonCommandParams.Offset;
                param.cmdParam.precision         = yukonCommandParams.Precision;
                param.cmdParam.scale             = yukonCommandParams.Scale;
                param.cmdParam.size              = yukonCommandParams.ParamSize;
                param.cmdParam.sourceColumn      = yukonCommandParams.SourceColumn;
                param.cmdParam.sourceColumnNull  = yukonCommandParams.SourceColumnNullMapping;
                param.cmdParam.sqlValue          = yukonCommandParams.SqlValue.ToString();
                param.cmdParam.version           = (int)yukonCommandParams.SrcVersion;
                param.cmdParam.typeId            = (int)yukonCommandParams.DbType;
                param.cmdParam.typeName          = yukonCommandParams.TypeName;
                param.cmdParam.udtTypeName       = yukonCommandParams.UdtName;
                param.cmdParam.nullValueProvided = yukonCommandParams.Value == null;

                if (!param.cmdParam.nullValueProvided)
                {
                    if (yukonCommandParams.DbType == SqlDbType.Binary || yukonCommandParams.DbType == SqlDbType.VarBinary || yukonCommandParams.DbType == SqlDbType.Image || yukonCommandParams.DbType == SqlDbType.Timestamp)
                    {
                        byte[] val = yukonCommandParams.Value as byte[];
                        System.Text.UTF8Encoding encoding = new System.Text.UTF8Encoding();
                        param.cmdParam.value = encoding.GetString(val);
                    }
                    else if (yukonCommandParams.DbType == SqlDbType.DateTime || yukonCommandParams.DbType == SqlDbType.DateTime2 || yukonCommandParams.DbType == SqlDbType.Date || yukonCommandParams.DbType == SqlDbType.SmallDateTime)
                    {
                        DateTime val = (DateTime)yukonCommandParams.Value;
                        param.cmdParam.value = val.Ticks.ToString();
                    }
                    else if (yukonCommandParams.DbType == SqlDbType.Time)
                    {
                        TimeSpan val = (TimeSpan)yukonCommandParams.Value;
                        param.cmdParam.value = val.Ticks.ToString();
                    }
                    else if (yukonCommandParams.DbType == SqlDbType.DateTimeOffset)
                    {
                        DateTimeOffset val = (DateTimeOffset)yukonCommandParams.Value;
                        param.cmdParam.value = String.Concat(val.Date.Ticks, ",", val.Offset.Minutes);
                    }
                    else
                    {
                        param.cmdParam.value = yukonCommandParams.Value.ToString();
                    }
                }

                protoYukonDep.param.Add(param);
            }

            return(protoYukonDep);
        }
Example #7
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);
        }
Example #8
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);
        }