Esempio n. 1
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);
        }
Esempio n. 2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="CacheDependency"/> class that monitors an array of file paths (to files or
        /// directories), an array of cache keys, or both for changes. It also
        /// makes itself dependent upon another instance of the <see cref="CacheDependency"/>
        /// class and a time when the change monitoring begins.
        /// </summary>
        /// <param name="fileNames">An array of file paths (to files or directories) that the cached object
        /// is dependent upon. When any of these resources change, the cached object becomes obsolete and
        /// is removed from the cache.</param>
        /// <param name="cacheKeys">An array of cache keys that the new object monitors for changes. When
        /// any of these cache keys change, the cached object associated with this dependency object
        /// becomes obsolete and is removed from the cache.</param>
        /// <param name="dependency">Another instance of the <see cref="CacheDependency"/> class that this
        /// instance is dependent upon.</param>
        /// <param name="start">The time when change tracking begins.</param>
        /// <exception cref="ArgumentNullException"><paramref name="fileNames"/> or <paramref name="cacheKeys"/> contains a
        /// null reference (Nothing in Visual Basic).</exception>
        /// <remarks>
        /// If any of the files or directories in the array were to change or be removed from the array,
        /// the cached item becomes obsolete and is removed from the application's <see cref="Cache"/> object.
        /// <para>
        /// Also, if any of the directories or files specified in the <paramref name="fileNames"/> parameter is not found in the
        /// file system, they are treated as missing files. If any of them are created after the object with the
        /// dependency is added to the <see cref="Cache"/>, the cached object will be removed from the <see cref="Cache"/>.For example,
        /// assume that you add an object to the <see cref="Cache"/> with a dependency on the following file path:
        /// c:\stocks\xyz.dat. If that file is not found when the <see cref="CacheDependency"/> object is created, but is
        /// created later, the cached object is removed upon the creation of the xyz.dat file.
        /// </para>
        /// </remarks>


        public CacheDependency(string[] fileNames, string[] cacheKeys, CacheDependency dependency, DateTime start)//:base(start)
        {
            CacheDependency fileDependency = null;
            CacheDependency keyDependency  = null;

            if (fileNames != null)
            {
                if (fileNames.Length == 0)
                {
                    throw new ArgumentException("fileNames array must have atleast one file name");
                }
                foreach (string fileName in fileNames)
                {
                    if (fileName == null)
                    {
                        throw new ArgumentNullException("fileName");
                    }
                    if (fileName == string.Empty)
                    {
                        throw new ArgumentException("fileName cannot be empty string");
                    }
                }

                fileDependency = new FileDependency(fileNames, start);
            }

            if (cacheKeys != null)
            {
                if (cacheKeys.Length == 0)
                {
                    throw new ArgumentException("fileNames array must have atleast one file name");
                }

                foreach (string cachekey in cacheKeys)
                {
                    if (cachekey == null)
                    {
                        throw new ArgumentNullException("cacheKey");
                    }
                    if (cachekey == string.Empty)
                    {
                        throw new ArgumentException("cacheKey cannot be empty string");
                    }
                }

                keyDependency = new KeyDependency(cacheKeys, start);
            }

            if (fileDependency != null || keyDependency != null || dependency != null)
            {
                if (_dependencies == null)
                {
                    _dependencies = new List <CacheDependency>();
                }

                if (fileDependency != null)
                {
                    _dependencies.Add(fileDependency);
                }

                if (keyDependency != null)
                {
                    _dependencies.Add(keyDependency);
                }

                if (dependency != null)
                {
                    _dependencies.Add(dependency);
                }
            }

            _startAfter = start;
        }