Example #1
0
        private string GetTemplate(string fileName)
        {
            var cache = CacheManagerFactory.CreateManager();
            var expir = new FileDependency(fileName);

            return(cache.TryGet(fileName, () => File.ReadAllText(fileName, Encoding.Default), () => expir));
        }
Example #2
0
        /// <summary>
        /// 依赖文件缓存(包含移除刷新事件)
        /// </summary>
        /// <param name="key"></param>
        /// <param name="value"></param>
        /// <param name="action"></param>
        /// <param name="dependFilePath"></param>
        public static void Add(string key, object value, ICacheItemRefreshAction action, string dependFilePath)
        {
            FileDependency depen = new FileDependency(dependFilePath);

            cache.Add(key, value, CacheItemPriority.Normal, action, depen);
            AddKey(key);
        }
Example #3
0
        public void ExpiresReturnsTrueIfFileDisappears()
        {
            FileDependency dependency = new FileDependency("TestFile");

            File.Delete("TestFile");

            Assert.IsTrue(dependency.HasExpired(), "Deleted files should always be considered expired");
        }
 // ReSharper disable once UnusedParameter.Local
 public T4SecondaryDocumentGenerationResult([NotNull] IPsiSourceFile sourceFile, [NotNull] string text, [NotNull] PsiLanguageType language,
     [NotNull] ISecondaryRangeTranslator secondaryRangeTranslator, [NotNull] ILexerFactory lexerFactory,
     [NotNull] FileDependency fileDependency, [NotNull] OneToSetMap<FileSystemPath, FileSystemPath> includedFiles)
     : base(text, language, secondaryRangeTranslator, lexerFactory)
 {
     _fileDependency = fileDependency;
     _includedFiles = includedFiles;
 }
Example #5
0
        public void should_be_after_is_false_for_unrelated_scripts()
        {
            var s1 = new FileDependency("1");
            var s2 = new FileDependency("2");

            s1.MustBeAfter(s2).ShouldBeFalse();
            s2.MustBeAfter(s1).ShouldBeFalse();
        }
        public void ExpiresReturnsTrueIfFileDisappears()
        {
            FileDependency dependency = new FileDependency("TestFile");

            File.Delete("TestFile");

            Assert.IsTrue(dependency.HasExpired(), "Deleted files should always be considered expired");
        }
Example #7
0
 private void AddDependency()
 {
     if (FileDependencies == null)
     {
         FileDependencies = new ObservableCollection <FileDependency>();
     }
     FileDependencies.Add(FileDependency.Create());
 }
Example #8
0
 public T4SecondaryDocumentGenerationResult([NotNull] IPsiSourceFile sourceFile, [NotNull] string text, [NotNull] PsiLanguageType language,
                                            [NotNull] ISecondaryRangeTranslator secondaryRangeTranslator, [NotNull] ILexerFactory lexerFactory,
                                            [NotNull] FileDependency fileDependency, [NotNull] OneToSetMap <FileSystemPath, FileSystemPath> includedFiles)
     : base(sourceFile, text, language, secondaryRangeTranslator, lexerFactory)
 {
     _fileDependency = fileDependency;
     _includedFiles  = includedFiles;
 }
        public void Refresh(string removedKey, object expiredValue, CacheItemRemovedReason removalReason)
        {
            var cacheManager  = EnterpriseLibraryContainer.Current.GetInstance <ICacheManager>();
            var fileContents  = File.ReadAllText(_filename);
            var refreshAction = new FileRefreshAction(_filename);
            var expiration    = new FileDependency(_filename);

            cacheManager.Add(removedKey, fileContents, CacheItemPriority.Normal, refreshAction, expiration);
        }
Example #10
0
        /// <summary>
        /// 文件依赖
        /// </summary>
        /// <param name="objId"></param>
        /// <param name="o"></param>
        /// <param name="files"></param>
        public void AddObjectWithFileChange(string objId, object o, string files)
        {
            if (objId == null || objId.Length == 0 || o == null)
            {
                return;
            }
            FileDependency _fileDep = new FileDependency(files);

            CacheFactory.GetCacheManager().Add(objId, o, CacheItemPriority.High, null, _fileDep);
        }
Example #11
0
        public static void Set(string key, object value, int minuteAbsoluteExpiration, string cachePath, string fileName)
        {
            //Creating Absolute Time Expiration
            AbsoluteTime _AbsoulteTime = new AbsoluteTime(TimeSpan.FromMinutes(minuteAbsoluteExpiration));
            //Creating FileDependecy Object
            FileDependency _objFileDependency = new FileDependency(fileName); //"MyFile.XML"

            // Using ICacheItemExpiration To Set multiple Cache Expiration policy
            cacheManager.Add(key, value, CacheItemPriority.Normal, null, new ICacheItemExpiration[] { _AbsoulteTime, _objFileDependency });
        }
Example #12
0
        public void should_be_after_a_direct_dependency()
        {
            var s1 = new FileDependency("1");
            var s2 = new FileDependency("2");

            s2.AddDependency(s1);

            s1.MustBeAfter(s2).ShouldBeFalse();
            s2.MustBeAfter(s1).ShouldBeTrue();
        }
Example #13
0
        public void extender_scenario()
        {
            var s1 = new FileDependency("1");
            var s2 = new FileDependency("2");

            s2.AddDependency(s1);

            s2.MustBeAfter(s1).ShouldBeTrue();
            s1.MustBeAfter(s2).ShouldBeFalse();
        }
Example #14
0
        private void method_11()
        {
            this.class617_7.MaxDecompressedPageSize = 128;
            FileDependencyCollection dependencyCollection = new FileDependencyCollection();

            if (dependencyCollection.Count > 1)
            {
                this.class617_7.MaxDecompressedPageSize = 128 * dependencyCollection.Count;
            }
            this.class617_7.Encrypted = 2;
            MemoryStream  memoryStream = new MemoryStream();
            Class889      class889     = Class889.Create((Stream)memoryStream, this.dxfVersion_0, this.encoding_0);
            List <string> stringList   = new List <string>();

            foreach (FileDependency.Key key in dependencyCollection.Keys)
            {
                if (!stringList.Contains(key.FeatureName))
                {
                    stringList.Add(key.FeatureName);
                }
            }
            class889.vmethod_9(stringList.Count);
            foreach (string str in stringList)
            {
                class889.vmethod_22(str);
            }
            class889.vmethod_9(dependencyCollection.Count);
            DateTime dateTime = new DateTime(1980, 1, 1);

            foreach (FileDependency.Key key in dependencyCollection.Keys)
            {
                FileDependency fileDependency = dependencyCollection[key];
                if (fileDependency.FeatureName == "Acad:Text")
                {
                    string str = DxfTextStyle.smethod_2(Class1043.smethod_2(this.dxfModel_0.Filename), fileDependency.FullFilename);
                    if (!string.IsNullOrEmpty(str) && File.Exists(str))
                    {
                        FileInfo fileInfo = new FileInfo(str);
                        fileDependency.TimeStamp = fileInfo.LastWriteTime;
                        fileDependency.FileSize  = (int)fileInfo.Length;
                    }
                }
                class889.vmethod_22(fileDependency.FullFilename);
                class889.vmethod_22(fileDependency.FoundPath);
                class889.vmethod_22(fileDependency.FingerPrintGuid);
                class889.vmethod_22(fileDependency.VersionGuid);
                class889.vmethod_9(stringList.IndexOf(fileDependency.FeatureName));
                TimeSpan timeSpan = fileDependency.TimeStamp - dateTime;
                class889.vmethod_9((int)timeSpan.TotalSeconds);
                class889.vmethod_9(fileDependency.FileSize);
                class889.vmethod_5(fileDependency.AffectsGraphics ? (short)1 : (short)0);
                class889.vmethod_9(fileDependency.References.Count);
            }
            this.method_23(this.class617_7, memoryStream, false);
        }
Example #15
0
        public void ExpiresIfTouched()
        {
            FileDependency dependency = new FileDependency("TestFile");
            Thread.Sleep(1500);
            using (FileStream outputStream = File.OpenWrite("TestFile"))
            {
                outputStream.WriteByte(0x00);
            }

            Assert.IsTrue(dependency.HasExpired(), "File was touched, so it should be considered expired");
        }
        public void ExpiresIfTouched()
        {
            FileDependency dependency = new FileDependency("TestFile");

            Thread.Sleep(1500);
            using (FileStream outputStream = File.OpenWrite("TestFile"))
            {
                outputStream.WriteByte(0x00);
            }

            Assert.IsTrue(dependency.HasExpired(), "File was touched, so it should be considered expired");
        }
Example #17
0
        public void should_be_after_a_direct_dependency_2_deep()
        {
            var s1 = new FileDependency("1");
            var s2 = new FileDependency("2");
            var s3 = new FileDependency("3");

            s3.AddDependency(s2);
            s2.AddDependency(s1);

            s3.MustBeAfter(s1).ShouldBeTrue();
            s3.MustBeAfter(s2).ShouldBeTrue();
        }
Example #18
0
 private void RemoveDependency(FileDependency param)
 {
     if (FileDependencies == null)
     {
         return;
     }
     FileDependencies.Remove(param);
     if (FileDependencies.Count == 0)
     {
         FileDependencies = null;
     }
 }
Example #19
0
        public void ClassCanSerializeCorrectly()
        {
            FileDependency dependency = new FileDependency("TestFile");

            BinaryFormatter formatter = new BinaryFormatter();
            MemoryStream stream = new MemoryStream();
            formatter.Serialize(stream, dependency);
            stream.Position = 0;
            FileDependency dependency2 = (FileDependency)formatter.Deserialize(stream);

            Assert.AreEqual(dependency.FileName, dependency2.FileName);
            Assert.AreEqual(dependency.LastModifiedTime, dependency2.LastModifiedTime);
        }
Example #20
0
        private static Hashtable LoadResource(ResourceManagerType resourceType, Hashtable target, string language, string cacheKey, string fileName)
        {
            string filePath = GlobalSettings.PhysicalPath("Languages\\" + language + "\\" + fileName);

            FileDependency dp;
            XmlDocument    d = new XmlDocument();

            try
            {
                dp = new FileDependency(filePath);
                d.Load(filePath);
            }
            catch
            {
                return(target);
            }
            foreach (XmlNode n in d.SelectSingleNode("root").ChildNodes)
            {
                if (n.NodeType != XmlNodeType.Comment)
                {
                    switch (resourceType)
                    {
                    case ResourceManagerType.ErrorMessage:
                        Message m = new Message(n);
                        target[m.MessageID] = m;
                        break;

                    case ResourceManagerType.String:
                        if (target[n.Attributes["name"].Value] == null)
                        {
                            target.Add(n.Attributes["name"].Value, n.InnerText);
                        }
                        else
                        {
                            target[n.Attributes["name"].Value] = n.InnerText;
                        }
                        break;

                    case ResourceManagerType.UserLicence:
                        if (target["licence"] == null)
                        {
                            target.Add("licence", n.InnerText);
                        }
                        break;
                    }
                }
            }
            HHCache.Instance.Max(cacheKey, target, dp);
            return(target);
        }
        public void ClassCanSerializeCorrectly()
        {
            FileDependency dependency = new FileDependency("TestFile");

            BinaryFormatter formatter = new BinaryFormatter();
            MemoryStream    stream    = new MemoryStream();

            formatter.Serialize(stream, dependency);
            stream.Position = 0;
            FileDependency dependency2 = (FileDependency)formatter.Deserialize(stream);

            Assert.AreEqual(dependency.FileName, dependency2.FileName);
            Assert.AreEqual(dependency.LastModifiedTime, dependency2.LastModifiedTime);
        }
Example #22
0
 /// <summary>
 /// 将Cache的数据加到缓存manager中
 /// </summary>
 /// <param name="cacheData"></param>
 /// <param name="entityCfg"></param>
 private void addCacheDataToContainer(string key, CacheData cacheData, EntityCfg entityCfg)
 {
     if (entityCfg != null)
     {
         List <ICacheItemExpiration> cacheItemExpiration = new List <ICacheItemExpiration>();
         foreach (var cacheExpireCfg in entityCfg.Expirations)
         {
             if (cacheExpireCfg.ExpirationType == CacheExpirationType.AbsoluteTime)
             {
                 TimeSpan ts = TimeSpan.FromMilliseconds(cacheExpireCfg.ExpireTime);
                 if (ts.TotalMilliseconds > 0)
                 {
                     AbsoluteTime absoluteTime = new AbsoluteTime(ts);
                     cacheItemExpiration.Add(absoluteTime);
                 }
             }
             else if (cacheExpireCfg.ExpirationType == CacheExpirationType.SlidingTime)
             {
                 TimeSpan ts = TimeSpan.FromMilliseconds(cacheExpireCfg.ExpireTime);
                 if (ts.TotalMilliseconds > 0)
                 {
                     SlidingTime slidingTime = new SlidingTime(ts);
                     cacheItemExpiration.Add(slidingTime);
                 }
             }
             else if (cacheExpireCfg.ExpirationType == CacheExpirationType.FileDependency)
             {
                 if (System.IO.File.Exists(cacheExpireCfg.FilePath))
                 {
                     FileDependency fileDependency = new FileDependency(cacheExpireCfg.FilePath);
                     cacheItemExpiration.Add(fileDependency);
                 }
             }
         }
         if (entityCfg.IsCacheItemRefreshed)
         {
             _EntitySetCache.Add(key, cacheData, entityCfg.CacheItemPriority, new CacheItemRefreshAction(entityCfg, key), cacheItemExpiration.ToArray());
         }
         else
         {
             _EntitySetCache.Add(key, cacheData, entityCfg.CacheItemPriority, null, cacheItemExpiration.ToArray());
         }
     }
     else
     {
         _EntitySetCache.Add(key, cacheData);
     }
 }
        public void AddListTestSimpleScenario()
        {
            FileDependencyCollection collection = new FileDependencyCollection();

            FileDependency[] fdList = new FileDependency[2];
            FileDependency   fd1    = new FileDependencyMock(@"c:\test1.txt");
            FileDependency   fd2    = new FileDependencyMock(@"c:\test2.txt");

            fdList[0] = fd1;
            fdList[1] = fd2;

            collection.Add(fdList);

            Assert.IsTrue(collection.Contains(fd1));
            Assert.IsTrue(collection.Contains(fd2));
        }
Example #24
0
        public void should_be_after_bouncing_through_a_set()
        {
            var s1 = new FileDependency("1");
            var s2 = new FileDependency("2");
            var s3 = new FileDependency("3");

            var set = new AssetSet();

            set.Add(s1);

            s2.AddDependency(set);
            s3.AddDependency(s2);

            s3.MustBeAfter(s1).ShouldBeTrue();
            s3.MustBeAfter(s2).ShouldBeTrue();
        }
        public static List <Menu> GetProfileMenus()
        {
            string      cacheKey = CacheKeyManager.ProfileMenuKey;
            List <Menu> menus    = HHCache.Instance.Get(cacheKey) as List <Menu>;

            if (menus == null || menus.Count == 0)
            {
                string         path = GlobalSettings.MapPath("~/pages/profiles/menu.config");
                FileDependency fd   = new FileDependency(path);
                menus = new List <Menu>();
                Menu            menu  = null;
                List <MenuItem> items = null;
                MenuItem        item  = null;

                XmlDocument xmlDoc = new XmlDocument();
                xmlDoc.Load(path);
                foreach (XmlNode xn in xmlDoc.SelectSingleNode("menus").ChildNodes)
                {
                    if (xn.NodeType == XmlNodeType.Element)
                    {
                        items = new List <MenuItem>();
                        foreach (XmlNode n in xn.ChildNodes)
                        {
                            if (n.NodeType == XmlNodeType.Element)
                            {
                                item = new MenuItem(n.Attributes["name"].Value,
                                                    xn.Attributes["name"].Value,
                                                    n.Attributes["itemTitle"].Value,
                                                    n.Attributes["url"].Value,
                                                    n.Attributes["roles"].Value);
                                items.Add(item);
                            }
                        }

                        menu = new Menu(xn.Attributes["name"].Value, xn.Attributes["menuTitle"].Value, xn.Attributes["roles"].Value, items);
                        menus.Add(menu);
                    }
                }
                HHCache.Instance.Max(cacheKey, menus, fd);
            }
            return(menus);
        }
        public void AddListTestNullValueInList()
        {
            FileDependencyCollection collection = new FileDependencyCollection();

            FileDependency[] fdList = new FileDependency[1];
            fdList[0] = null;

            try
            {
                collection.Add(fdList);

                Assert.IsTrue(false, "Adding a null value to the collection should throw an InvalidOretationException.");
            }
            catch (InvalidOperationException e)
            {
                Console.Write(e);
                // pass if we get here
                Assert.IsTrue(true);
            }
        }
        public void NoPermissionToReadWhenCheckingExpiration()
        {
            FileDependency dependency = new FileDependency("TestFile");

            FileIOPermission denyPermission =
                new FileIOPermission(FileIOPermissionAccess.Read, Path.GetFullPath("TestFile"));

            PermissionSet permissions = new PermissionSet(PermissionState.None);
            permissions.AddPermission(denyPermission);
            permissions.Deny();

            try
            {
                dependency.HasExpired();
            }
            finally
            {
                CodeAccessPermission.RevertDeny();
            }
        }
        /// <summary>
        /// 获取缓存配置实例
        /// </summary>
        /// <returns></returns>
        public static SearchConfiguration GetConfig()
        {
            SearchConfiguration config = HHCache.Instance.Get(CacheKeyManager.SearchConfigurationKey) as SearchConfiguration;

            if (config == null)
            {
                lock (configLocker)
                {
                    config = HHCache.Instance.Get(CacheKeyManager.SearchConfigurationKey) as SearchConfiguration;
                    if (config == null)
                    {
                        XmlNode node = HHConfiguration.GetConfig().GetConfigSection("HHOnline/LuceneSearch");
                        config = new SearchConfiguration(node);
                        //添加到缓存
                        FileDependency dp = new FileDependency(HHConfiguration.ConfigFilePath);
                        HHCache.Instance.Max(CacheKeyManager.SearchConfigurationKey, config, dp);
                    }
                }
            }
            return(config);
        }
        public void NoPermissionToReadWhenCheckingExpiration()
        {
            FileDependency dependency = new FileDependency("TestFile");

            FileIOPermission denyPermission =
                new FileIOPermission(FileIOPermissionAccess.Read, Path.GetFullPath("TestFile"));

            PermissionSet permissions = new PermissionSet(PermissionState.None);

            permissions.AddPermission(denyPermission);
            permissions.Deny();

            try
            {
                dependency.HasExpired();
            }
            finally
            {
                CodeAccessPermission.RevertDeny();
            }
        }
        public void AddListTestDuplicatedValue()
        {
            FileDependencyCollection collection = new FileDependencyCollection();

            FileDependency[] fdList = new FileDependency[1];
            FileDependency   fd1    = new FileDependencyMock(@"c:\test1.txt");

            fdList[0] = new FileDependencyMock(@"c:\test1.txt");

            collection.Add(fd1);

            try
            {
                collection.Add(fdList);

                Assert.IsTrue(false, "Adding a duplicate value to the collection should throw an InvalidOretationException.");
            }
            catch (InvalidOperationException e)
            {
                Console.Write(e);
                // pass if we get here
                Assert.IsTrue(true);
            }
        }
Example #31
0
 public void ConstructingWithANullFileThrowsException()
 {
     FileDependency fileDependency = new FileDependency(null);
 }
 public void ConstructingWithANullFileThrowsException()
 {
     FileDependency fileDependency = new FileDependency(null);
 }
 public T4GeneratedDocumentService([NotNull] FileDependency fileDependency, [NotNull] DirectiveInfoManager directiveInfoManager)
 {
     _fileDependency = fileDependency;
     _directiveInfoManager = directiveInfoManager;
 }
 public T4GeneratedDocumentService([NotNull] FileDependency fileDependency, [NotNull] DirectiveInfoManager directiveInfoManager)
 {
     _fileDependency       = fileDependency;
     _directiveInfoManager = directiveInfoManager;
 }
Example #35
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 #36
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;
        }