Esempio n. 1
0
		public void Add_Get_With_Tags()
		{
			// Testing simple Add/Get on a Region with Tags
			// without Version
			// Each object will have a unique key
			// Each object can have multiple tags, hence the tag[]
			// Multiple Objects can have the same tag
			Console.WriteLine("----------------------");
			Console.WriteLine("Testing Simple Add/GetByTag");
			Console.WriteLine("Cache       = default");
			Console.WriteLine("Region      = " + myRegion);
			Console.WriteLine("Tags        = yes");
			Console.WriteLine("Version     = <none>");

			const int totalTags = 5;
			Tag[] allMyTags = new System.Data.Caching.Tag[totalTags]
			                  {
			                  	new Tag("Tag1"), new Tag("Tag2"),
			                  	new Tag("Tag3"), new Tag("Tag4"),
			                  	new Tag("Tag5")
			                  };
			List<KeyValuePair<string, object>> getByTagReturnKeyValuePair;
			int totalObjects = 10;
			try
			{
				for (int objectid = 0; objectid < totalObjects; objectid++)
				{
					if ((itemVersion = _defaultCache.Add(myRegion, "MyKey" + objectid,
					                                     myObjectForCaching, allMyTags)) != null)
						Console.WriteLine("PASS----->Add-Object " +
						                  "MyKey" + objectid +
						                  " added to Cache, with all tags");
					else
						Console.WriteLine("**FAIL----->Add-Object did not add to cache");
				}
				for (int objectid = 0; objectid < totalObjects; objectid++)
					for (int tagid = 0; tagid < totalTags; tagid++)
						if ((getByTagReturnKeyValuePair = _defaultCache.GetByTag(myRegion, allMyTags[tagid])) != null)
							Console.WriteLine("PASS----->GetByTag-Object " +
							                  getByTagReturnKeyValuePair.ElementAt(tagid).Key +
							                  " get from cache. Using Tag " + tagid);
						else
							Console.WriteLine("**FAIL----->GetByTag-Object did not Get from cache");
			}
			catch (CacheException ex)
			{
				Console.WriteLine("**FAIL----->Add-GetByTag-This is failing probably because you are running this sample test");
				Console.WriteLine("          within 10mins (default timeout)");
				Console.Write("**FAIL----->Distributed Cache Generated Exception:");
				Console.WriteLine(ex.Message);
			}
		}
        public void Add_Get_With_Tags()
        {
            // Testing simple Add/Get on a Region with Tags
            // without Version
            // Each object will have a unique key
            // Each object can have multiple tags, hence the tag[]
            // Multiple Objects can have the same tag
            Console.WriteLine("----------------------");
            Console.WriteLine("Testing Simple Add/GetByTag");
            Console.WriteLine("Cache       = default");
            Console.WriteLine("Region      = " + myRegion);
            Console.WriteLine("Tags        = yes");
            Console.WriteLine("Version     = <none>");

            const int totalTags = 5;

            Tag[] allMyTags = new System.Data.Caching.Tag[totalTags]
            {
                new Tag("Tag1"), new Tag("Tag2"),
                new Tag("Tag3"), new Tag("Tag4"),
                new Tag("Tag5")
            };
            List <KeyValuePair <string, object> > getByTagReturnKeyValuePair;
            int totalObjects = 10;

            try
            {
                for (int objectid = 0; objectid < totalObjects; objectid++)
                {
                    if ((itemVersion = _defaultCache.Add(myRegion, "MyKey" + objectid,
                                                         myObjectForCaching, allMyTags)) != null)
                    {
                        Console.WriteLine("PASS----->Add-Object " +
                                          "MyKey" + objectid +
                                          " added to Cache, with all tags");
                    }
                    else
                    {
                        Console.WriteLine("**FAIL----->Add-Object did not add to cache");
                    }
                }
                for (int objectid = 0; objectid < totalObjects; objectid++)
                {
                    for (int tagid = 0; tagid < totalTags; tagid++)
                    {
                        if ((getByTagReturnKeyValuePair = _defaultCache.GetByTag(myRegion, allMyTags[tagid])) != null)
                        {
                            Console.WriteLine("PASS----->GetByTag-Object " +
                                              getByTagReturnKeyValuePair.ElementAt(tagid).Key +
                                              " get from cache. Using Tag " + tagid);
                        }
                        else
                        {
                            Console.WriteLine("**FAIL----->GetByTag-Object did not Get from cache");
                        }
                    }
                }
            }
            catch (CacheException ex)
            {
                Console.WriteLine("**FAIL----->Add-GetByTag-This is failing probably because you are running this sample test");
                Console.WriteLine("          within 10mins (default timeout)");
                Console.Write("**FAIL----->Distributed Cache Generated Exception:");
                Console.WriteLine(ex.Message);
            }
        }