コード例 #1
0
        private static ExpirationHint GetExpirationHint(CacheDependency cacheDependency, AggregateExpirationHint aggregateHint)
        {
            if (cacheDependency == null)
            {
                return(null);
            }

            ExpirationHint hint = null;

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

                aggregateHint.Add(hint);
            }


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

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

                aggregateHint.Add(hint);
            }

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

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

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

                aggregateHint.Add(hint);
            }


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

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

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



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

                Hashtable parameters = new Hashtable();

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

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

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


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

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

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

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

            return(aggregateHint);
        }
コード例 #2
0
ファイル: APILogger.cs プロジェクト: wangchengqun/NCache
        public void LogInternal(APILogItem logItem)
        {
            using (StreamWriter w = File.AppendText(getFileName(logItem.LoggingTime)))
            {
                w.WriteLine(logItem.LoggingTime.ToString("MM/dd/yyyy hh:mm:ss.fff tt") + "\t" + logItem.Signature);
                if (logItem.NoOfKeys > 1)
                {
                    w.WriteLine(String.Format("{0,-30}\t Number of Keys = {1}", "", logItem.NoOfKeys.ToString()));
                }

                if (!String.IsNullOrEmpty(logItem.Key))
                {
                    w.WriteLine(String.Format("{0,-30}\t Key = {1}", " ", logItem.Key));
                }

                if (logItem.AbsolueExpiration != null)
                {
                    w.WriteLine(String.Format("{0,-30}\t Absolute Expiration = {1}", " ",
                                              logItem.AbsolueExpiration.ToString()));
                }
                if (logItem.SlidingExpiration != null)
                {
                    w.WriteLine(String.Format("{0,-30}\t Sliding Expiration = {1} milliseconds", " ",
                                              logItem.SlidingExpiration.Value.TotalMilliseconds));
                }

                if (!String.IsNullOrEmpty(logItem.Group))
                {
                    w.WriteLine(String.Format("{0,-30}\t Group = {1}", " ", logItem.Group));
                }
                if (!String.IsNullOrEmpty(logItem.SubGroup))
                {
                    w.WriteLine(String.Format("{0,-30}\t SubGroup = {1}", " ", logItem.SubGroup));
                }

                if (logItem.Tags != null && logItem.Tags.Length != 0)
                {
                    w.WriteLine(String.Format("{0,-30}\t Tags:", " "));
                    foreach (Tag t in logItem.Tags)
                    {
                        w.WriteLine(String.Format("{0,-30}\t\tValue = {1}", " ", t != null ? t.TagName : ""));
                    }
                }

                if (logItem.NamedTags != null && logItem.NamedTags.Count != 0)
                {
                    w.WriteLine(String.Format("{0,-30}\t NamedTags:", " "));
                    IEnumerator ie = logItem.NamedTags.GetEnumerator();
                    while (ie.MoveNext())
                    {
                        DictionaryEntry de = (DictionaryEntry)ie.Current;
                        w.WriteLine(String.Format(
                                        "{0,-30}\t\t Key = " + de.Key.ToString() + "\tValue = " + de.Value.ToString(), " "));
                    }
                }

                if (logItem.Priority != null)
                {
                    w.WriteLine(String.Format("{0,-30}\t Priority = {1}", " ", logItem.Priority.ToString()));
                }

                if (logItem.Dependency != null)
                {
                    w.WriteLine(String.Format("{0,-30}\t Dependency = {1}", " ", logItem.Dependency.GetType().Name));
                    if ((logItem.Dependency as Runtime.Dependencies.KeyDependency) != null)
                    {
                        w.WriteLine(String.Format("{0,-30}\t\t Keys:", " "));
                        Runtime.Dependencies.KeyDependency kd = (Runtime.Dependencies.KeyDependency)logItem.Dependency;
                        foreach (string key in kd.CacheKeys)
                        {
                            w.WriteLine(String.Format("{0,-30}\t\t\tValue = {1}", " ", key));
                        }
                    }
                    else if ((logItem.Dependency as Runtime.Dependencies.FileDependency) != null)
                    {
                        w.WriteLine(String.Format("{0,-30}\t\t Files:", " "));
                        Runtime.Dependencies.FileDependency fd =
                            (Runtime.Dependencies.FileDependency)logItem.Dependency;
                        foreach (string fileName in fd.fileNames)
                        {
                            w.WriteLine(String.Format("{0,-30}\t\t\tValue = {1}", " ", fileName));
                        }
                    }
                }

                if (logItem.SyncDependency != null)
                {
                    w.WriteLine(String.Format("{0,-30}\t SyncDependency = {1}", " ",
                                              logItem.SyncDependency.ToString()));
                }
                if (logItem.IsResyncRequired != null)
                {
                    w.WriteLine(String.Format("{0,-30}\t IsResyncRequired = {1}", " ",
                                              logItem.IsResyncRequired.ToString()));
                }


                if (!String.IsNullOrEmpty(logItem.ProviderName))
                {
                    w.WriteLine(String.Format("{0,-30}\t ProviderName = {1}", " ", logItem.ProviderName));
                }

                if (!String.IsNullOrEmpty(logItem.ResyncProviderName))
                {
                    w.WriteLine(String.Format("{0,-30}\t ResyncProviderName = {1}", " ", logItem.ResyncProviderName));
                }

                if (logItem.DSWriteOption != null)
                {
                    w.WriteLine(String.Format("{0,-30}\t DSWriteOption = {1}", " ", logItem.DSWriteOption.ToString()));
                }

                if (logItem.DSReadOption != null)
                {
                    w.WriteLine(String.Format("{0,-30}\t DSReadOption = {1}", " ", logItem.DSReadOption.ToString()));
                }


                if (logItem.ContinuousQuery != null)
                {
                    w.WriteLine(String.Format("{0,-30}\t ContinuousQuery:", " "));
                    w.WriteLine(String.Format("{0,-30}\t\t Query = {1}", " ", logItem.ContinuousQuery.Query));
                    w.WriteLine(String.Format("{0,-30}\t\t Values:", " "));
                    IDictionaryEnumerator ide = logItem.ContinuousQuery.Values.GetEnumerator();
                    while (ide.MoveNext())
                    {
                        w.WriteLine(String.Format(
                                        "{0,-30}\t\t\t Key = " + ide.Key.ToString() + "\tValue = " + ide.Value.ToString(), " "));
                    }
                }


                if (!string.IsNullOrEmpty(logItem.Query))
                {
                    w.WriteLine(String.Format("{0,-30}\t Query = {1}", " ", logItem.Query.ToString()));
                }
                if (logItem.QueryValues != null)
                {
                    w.WriteLine(String.Format("{0,-30}\t Values:", " "));
                    IDictionaryEnumerator ide = logItem.QueryValues.GetEnumerator();
                    while (ide.MoveNext())
                    {
                        w.WriteLine(String.Format(
                                        "{0,-30}\t\t Key = " + ide.Key.ToString() + "\tValue = " + ide.Value.ToString(), " "));
                    }
                }

                if (logItem.LockTimeout != null)
                {
                    w.WriteLine(String.Format("{0,-30}\t LockTimeout = {1} milliseconds", " ",
                                              logItem.LockTimeout.Value.TotalMilliseconds.ToString()));
                }
                if (logItem.AcquireLock != null)
                {
                    w.WriteLine(String.Format("{0,-30}\t AcquireLock = {1}", " ", logItem.AcquireLock.ToString()));
                }


                if (logItem.StreamMode != null)
                {
                    w.WriteLine(String.Format("{0,-30}\t SreamMode = {1}", " ", logItem.StreamMode.ToString()));
                }

                if (logItem.CacheItemVersion != null)
                {
                    w.WriteLine(String.Format("{0,-30}\t CacheItemVersion = {1}", " ",
                                              logItem.CacheItemVersion.ToString()));
                }

                if (logItem.RuntimeAPILogItem != null)
                {
                    RuntimeAPILogItem rtLogItem = logItem.RuntimeAPILogItem;
                    string            avg       = rtLogItem.IsBulk ? "Average " : "";
                    if (rtLogItem.IsBulk)
                    {
                        w.WriteLine(String.Format("{0,-30}\t Number of Objects = {1}", " ",
                                                  rtLogItem.NoOfObjects.ToString()));
                    }
                    w.WriteLine(String.Format("{0,-30}\t {1}Object Size (bytes) = {2}", " ", avg,
                                              rtLogItem.SizeOfObject));
                }

                if (logItem.NoOfObjectsReturned != null)
                {
                    w.WriteLine(String.Format("{0,-30}\t Number of Objects Returned = {1}", " ",
                                              logItem.NoOfObjectsReturned.ToString()));
                }
                if (logItem.ExceptionMessage != null)
                {
                    w.WriteLine(String.Format("{0,-30}\t Exception = {1}", " ", logItem.ExceptionMessage));
                }

                w.WriteLine();
            }
        }