/// <summary>
        /// This method inserts items in cache with named tags.
        /// </summary>
        private static void InsertItemsWithNamedTags()
        {
            NamedTagsDictionary nameTagDict = new NamedTagsDictionary();

            nameTagDict.Add("Employee", "DavidBrown");
            nameTagDict.Add("Department", "Mathematics");

            _cache.Add("Employee:DavidBrown", "Department:Mathematics", nameTagDict);

            Console.WriteLine("Items added in cache.");
        }
        /// <summary>
        /// This method inserts items in the cache with named tags and a predefined index using NCache Manager.
        /// </summary>
        private static void InsertItemsWithNamedTagsAndIndex(Product product)
        {
            //Querying indexed object via NamedTags

            var nameTagDict = new NamedTagsDictionary();

            nameTagDict.Add("ProductName", "HTCPhone");
            nameTagDict.Add("Class", "Electronics");

            _cache.Insert("Product:CellularPhoneHTC", product, nameTagDict);
        }
Beispiel #3
0
        /// <summary>
        /// Creates a distributed list to which instances of customers are to be added
        /// </summary>
        /// be the key against which distributed list is to be stored.</param>
        private static void CreateListWithDataTypeAttributes()
        {
            //Attribute NamedTags Dictionary
            NamedTagsDictionary namedTags = new NamedTagsDictionary();

            namedTags.Add("Customers", "Loyal");
            //Expiration
            Expiration expiration = new Expiration(ExpirationType.Absolute, new TimeSpan(0, 1, 0));
            //with Tag Frequent
            Tag tag = new Tag("Frequent");

            //Group for distributed datatype
            string group = "Potential";

            // Item priority Default
            CacheItemPriority cacheItemPriority = CacheItemPriority.Default;

            // Resync Operation is disabled
            ResyncOptions resyncOptions = new ResyncOptions(false);

            DataTypeAttributes attributes = new DataTypeAttributes
            {
                Expiration    = expiration,
                NamedTags     = namedTags,
                Group         = group,
                ResyncOptions = resyncOptions,
                Priority      = cacheItemPriority
            };

            // Creating distributed list with the defined attributes
            _cache.DataTypeManager.CreateList <Customer>(_datatype, attributes);
        }
        private static NamedTagsDictionary GetNamedTagsDictionary(Product product)
        {
            NamedTagsDictionary nameTagDict = new NamedTagsDictionary();

            switch (product.Name)
            {
            case "Chai":
            case "Chang":
            case "Aniseed Syrup":
                nameTagDict.Add("Supplier", "Exotic Liquids");
                break;

            case "IKura":
            case "Tofu":
                nameTagDict.Add("Supplier", "Tokyo Traders");
                break;
            }

            return(nameTagDict);
        }
Beispiel #5
0
        /// <summary>
        /// Executing this method will perform the operations of the sample using Named tags.
        /// </summary>
        public static void Run()
        {
            // Initialize cache
            InitializeCache();

            // Creating named tag dictionary.
            NamedTagsDictionary namedTagDict = new NamedTagsDictionary();

            namedTagDict.Add("Category", "Beverages");
            namedTagDict.Add("ProductName", "Coke");

            // Add Items in cache with named tags
            AddItems(namedTagDict);

            // Fetch Items from the cache
            GetItems();

            // Dispose cache once done
            _cache.Dispose();
        }
Beispiel #6
0
        ProviderCacheItem GetProviderCacheItemFromCacheEntry(CacheEntry cacheEntry, object value, OperationContext operationContext)
        {
            ProviderCacheItem providerCacheItem = new ProviderCacheItem(value);

            if (cacheEntry.EvictionHint != null && cacheEntry.EvictionHint._hintType == EvictionHintType.PriorityEvictionHint)
            {
                providerCacheItem.ItemPriority = ((PriorityEvictionHint)cacheEntry.EvictionHint).Priority;
            }
            else
            {
                providerCacheItem.ItemPriority = cacheEntry.Priority;
            }
            if (cacheEntry.GroupInfo != null)
            {
                providerCacheItem.Group    = cacheEntry.GroupInfo.Group;
                providerCacheItem.SubGroup = cacheEntry.GroupInfo.SubGroup;
            }

            DateTime absoluteExpiration = DateTime.MaxValue.ToUniversalTime();
            TimeSpan slidingExpiration  = TimeSpan.Zero;

            ExpirationHint hint = cacheEntry.ExpirationHint;

            if (hint != null)
            {
                providerCacheItem.ResyncItemOnExpiration = hint.NeedsReSync;
                AutoExpiration.DependencyHelper helper = new AutoExpiration.DependencyHelper();
                providerCacheItem.Dependency = helper.GetActualCacheDependency(hint, ref absoluteExpiration, ref slidingExpiration);
            }

            if (absoluteExpiration != DateTime.MaxValue.ToUniversalTime())
            {
                providerCacheItem.AbsoluteExpiration = absoluteExpiration.ToLocalTime();
            }
            providerCacheItem.SlidingExpiration = slidingExpiration;

            if (cacheEntry.QueryInfo != null)
            {
                if (cacheEntry.QueryInfo["tag-info"] != null)
                {
                    Hashtable tagInfo = cacheEntry.QueryInfo["tag-info"] as Hashtable;
                    if (tagInfo != null)
                    {
                        ArrayList tagsList = tagInfo["tags-list"] as ArrayList;
                        if (tagsList != null && tagsList.Count > 0)
                        {
                            Tag[] tags = new Tag[tagsList.Count];
                            int   i    = 0;
                            foreach (string tag in tagsList)
                            {
                                tags[i++] = new Tag(tag);
                            }

                            providerCacheItem.Tags = tags;
                        }
                    }
                }

                if (cacheEntry.QueryInfo["named-tag-info"] != null)
                {
                    Hashtable tagInfo = cacheEntry.QueryInfo["named-tag-info"] as Hashtable;
                    if (tagInfo != null)
                    {
                        Hashtable tagsList = tagInfo["named-tags-list"] as Hashtable;
                        if (tagsList != null)
                        {
                            NamedTagsDictionary namedTags = new NamedTagsDictionary();

                            foreach (DictionaryEntry tag in tagsList)
                            {
                                Type   tagType = tag.Value.GetType();
                                string tagKey  = tag.Key.ToString();

                                if (tagType == typeof(int))
                                {
                                    namedTags.Add(tagKey, (int)tag.Value);
                                }
                                else if (tagType == typeof(long))
                                {
                                    namedTags.Add(tagKey, (long)tag.Value);
                                }
                                else if (tagType == typeof(float))
                                {
                                    namedTags.Add(tagKey, (float)tag.Value);
                                }
                                else if (tagType == typeof(double))
                                {
                                    namedTags.Add(tagKey, (double)tag.Value);
                                }
                                else if (tagType == typeof(decimal))
                                {
                                    namedTags.Add(tagKey, (decimal)tag.Value);
                                }
                                else if (tagType == typeof(bool))
                                {
                                    namedTags.Add(tagKey, (bool)tag.Value);
                                }
                                else if (tagType == typeof(char))
                                {
                                    namedTags.Add(tagKey, (char)tag.Value);
                                }
                                else if (tagType == typeof(string))
                                {
                                    namedTags.Add(tagKey, (string)tag.Value);
                                }
                                else if (tagType == typeof(DateTime))
                                {
                                    namedTags.Add(tagKey, (DateTime)tag.Value);
                                }
                            }

                            if (namedTags.Count > 0)
                            {
                                providerCacheItem.NamedTags = namedTags;
                            }
                        }
                    }
                }
            }
            providerCacheItem.ResyncProviderName = cacheEntry.ResyncProviderName;
            return(providerCacheItem);
        }
Beispiel #7
0
        public static void Main(string[] args)
        {
            //----------------------------------------------------------------------------------------------
            //Initializing some temporary variables for testing.

            string cacheName        = "SampleCache";
            string filePath         = @"D://test.txt";
            string customerKey      = "Customer:0";
            string topicName        = "CustomerTopic";
            string subscriptionName = "CustomerSubscription";
            string groupName1       = "Good Customers";
            string groupName2       = "Bad Customers";

            var customer = new Customer
            {
                CustomerId   = 0,
                ContactName  = "Nikola Kovac",
                CompanyName  = "Faze Clan",
                ContactTitle = "Lurker",
                Address      = "Sweden"
            };

            var customer1 = new Customer
            {
                CustomerId   = 1,
                ContactName  = "David Jones",
                CompanyName  = "Google",
                ContactTitle = "Developer",
                Address      = "32-Newel Road, Palo Alto"
            };

            var customer2 = new Customer
            {
                CustomerId   = 2,
                ContactName  = "Mike Harry",
                CompanyName  = "Uber",
                ContactTitle = "Barrister",
                Address      = "Sydney, Australia"
            };

            var customer3 = new Customer
            {
                CustomerId   = 3,
                ContactName  = "Kratos",
                CompanyName  = "WarLord",
                ContactTitle = "Adventurer",
                Address      = "Nowhere"
            };

            var customer4 = new Customer
            {
                CustomerId   = 4,
                ContactName  = "Ezio Auditore",
                CompanyName  = "Ubisoft",
                ContactTitle = "Assassin",
                Address      = "Paris, France"
            };

            var customer5 = new Customer
            {
                CustomerId   = 5,
                ContactName  = "Lara Croft",
                CompanyName  = "Square Enix",
                ContactTitle = "Explorer",
                Address      = "London, England"
            };

            Customer[] customerArray = new Customer[]
            {
                customer1,
                customer2,
                customer3,
                customer4,
                customer5
            };


            string[] keys = new string[5];

            for (int i = 0; i < 5; i++)
            {
                keys[i] = "Customer:" + i + 1;
            }

            string[] KeysFirstHalf = new string[3]
            {
                keys[0],
                keys[1],
                keys[2]
            };

            string[] KeysSecondHalf = new string[2]
            {
                keys[3],
                keys[4],
            };

            NamedTagsDictionary nameTag = new NamedTagsDictionary();

            nameTag.Add("FlashSaleDiscount", 0.5);

            Tag[] newTags = new Tag[5]
            {
                new Tag("Type 1 Customers"),
                new Tag("Type 2 Customers"),
                new Tag("Type 3 Customers"),
                new Tag("Type 4 Customers"),
                new Tag("Type 5 Customers")
            };

            //----------------------------------------------------------------------------------------------
            //Callouts

            Program program = new Program(cacheName);

            //program.ClearCache();
            //var item = program.Get($"Customer:{80}");
            //Console.WriteLine("CustomerId: " + item.CustomerId + " --------- retrieved through loaded data");
            //Console.WriteLine("ContactName: " + item.ContactName + " --------- retrieved through loaded data");
            //Console.WriteLine("CompanyName: " + item.CompanyName + " --------- retrieved through loaded data");
            //Console.WriteLine("ContactTitle: " + item.ContactTitle + " --------- retrieved through loaded data");
            //Console.WriteLine("Address: " + item.Address + " --------- retrieved through loaded data");

            //program.Update(customerKey, customer);

            //program.AddBulk(keys,customerArray);

            //var item = program.GetBulk(keys);
            //foreach (var entry in item)
            //{
            //    Console.WriteLine("Customer: " + entry.ContactName + " retrieved by bulk call");
            //}

            //program.AddGroup(KeysFirstHalf,groupName1);
            //program.AddGroup(KeysSecondHalf,groupName2);

            //program.RemoveGroup(KeysSecondHalf);

            //program.AddTags(KeysSecondHalf,newTags);

            //var item = program.GetByAnyTag(newTags);

            //foreach (var entry in item)
            //{
            //    Console.WriteLine("Customer: " + entry.ContactName + " retrieved by tags");
            //}

            //program.AddNamedTag(KeysFirstHalf,nameTag);

            //program.SearchByNamedTags();

            //program.CreateTopic(topicName);
            //program.PublicMessagesToTopics(topicName, customer);
            //program.SubscribeForTopicMessages(topicName);


            //program.DeleteTopic(topicName);


            //program.DurableSubscription(topicName, subscriptionName);
            //program.PatternBasedSubscription(topicName);
            //program.PatternBasedDurableSubscription(topicName, subscriptionName);
            //program.PatternBasedSubscriptionWithFailureNotification(topicName);



            //----------------------------------------------------------------------------------------------
            //Pub Sub PowerShell Commands

            //Get-Topics -CacheName SampleCache
            //Get-Topics -CacheName SampleCache -Detail
            //Get-Topics -CacheName SampleCache -ShowAll



            //----------------------------------------------------------------------------------------------
            //Write timestamps to a file

            //using (StreamWriter writer = new StreamWriter("D://test.txt"))
            //{
            //    int counter = 0;
            //    while (counter < 10000)
            //    {
            //        writer.WriteLine("TimeStamp:  Hour: " + DateTime.Now.Hour + ",  Minute: " + DateTime.Now.Minute + ",  Second: " + DateTime.Now.Second + ", Millisecond: " + DateTime.Now.Millisecond);
            //        counter++;
            //    }
            //}

            //string readText = File.ReadAllText("D://test.txt");
            //Console.WriteLine(readText);


            Console.WriteLine();
            Console.WriteLine("End of the program");
        }
Beispiel #8
0
        private static void Main(string[] args)
        {
            //----------------------------------------------------------------------------------------------
            //Initializing some temporary variables for testing.

            string cacheName        = "NiftyCache";
            string cacheName4       = "S1mple";
            string clientCacheName4 = "S1mpleClientCache";
            string cacheName2       = "MirrorCache";
            string cacheName3       = "PartitionedCache";
            string clientCacheName2 = "MirrorClientCache";
            string clientCacheName  = "ElectronicCache";
            string clientCacheName3 = "P_ClientCache";

#pragma warning disable CS0219 // The variable 'filePath' is assigned but its value is never used
            string filePath = @"F://timestamps.txt";
#pragma warning restore CS0219 // The variable 'filePath' is assigned but its value is never used
#pragma warning disable CS0219 // The variable 'customerKey' is assigned but its value is never used
            string customerKey = "Customer:VAMP";
#pragma warning restore CS0219 // The variable 'customerKey' is assigned but its value is never used
#pragma warning disable CS0219 // The variable 'topicName' is assigned but its value is never used
            string topicName = "CustomerTopic";
#pragma warning restore CS0219 // The variable 'topicName' is assigned but its value is never used
#pragma warning disable CS0219 // The variable 'subscriptionName' is assigned but its value is never used
            string subscriptionName = "CustomerSubscription";
#pragma warning restore CS0219 // The variable 'subscriptionName' is assigned but its value is never used
#pragma warning disable CS0219 // The variable 'groupName1' is assigned but its value is never used
            string groupName1 = "GoodCustomers";
#pragma warning restore CS0219 // The variable 'groupName1' is assigned but its value is never used
#pragma warning disable CS0219 // The variable 'groupName2' is assigned but its value is never used
            string groupName2 = "BadCustomers";
#pragma warning restore CS0219 // The variable 'groupName2' is assigned but its value is never used

            var customer = new Customer
            {
                CustomerId   = "NIKO",
                ContactName  = "Nikola Kovac",
                CompanyName  = "Faze Clan",
                ContactTitle = "Rifler",
                Address      = "Sweden"
            };
            var customer1 = new Customer
            {
                CustomerId   = "KMNOP",
                ContactName  = "David Jones",
                CompanyName  = "Google",
                ContactTitle = "Developer",
                Address      = "32-Newel Road, Palo Alto"
            };
            var customer2 = new Customer
            {
                CustomerId   = "RSTUV",
                ContactName  = "Mike Harry",
                CompanyName  = "Uber",
                ContactTitle = "Barrister",
                Address      = "Sydney, Australia"
            };
            var customer3 = new Customer
            {
                CustomerId   = "WXYZZ",
                ContactName  = "Kratos",
                CompanyName  = "WarLord",
                ContactTitle = "Adventurer",
                Address      = "Nowhere"
            };
            var customer4 = new Customer
            {
                CustomerId   = "BVCSG",
                ContactName  = "Ezio Auditore",
                CompanyName  = "Ubisoft",
                ContactTitle = "Assassin",
                Address      = "Paris, France"
            };
            var customer5 = new Customer
            {
                CustomerId   = "Drome",
                ContactName  = "Lara Croft",
                CompanyName  = "Square Enix",
                ContactTitle = "Explorer",
                Address      = "London, England"
            };
            var customer7 = new Customer()
            {
                CustomerId   = "QWERT",
                ContactName  = "Sasha",
                ContactTitle = "Awper",
                CompanyName  = "Natus Vincere",
                Address      = "Russia"
            };
            var customer8 = new Customer()
            {
                CustomerId   = "NewID",
                ContactTitle = "Rifler",
                ContactName  = "Denis",
                CompanyName  = "Astralis",
                Address      = "Greenland"
            };
            var customer9 = new Customer()
            {
                CustomerId   = "Right",
                ContactTitle = "Lurker",
                ContactName  = "Get_Right",
                CompanyName  = "Ninjas In Pajamas"
            };

            Customer[] customerArray = new Customer[]
            {
                customer1,
                customer2,
                customer3,
                customer4,
                customer5
            };

            string[] keys = new string[5]
            {
                $"Customer:GHOST",
                $"Customer:RSTUV",
                $"Customer: WXYZZ",
                $"Customer: BVCSG",
                $"Customer: Drome"
            };

            string[] KeysFirstHalf = new string[3]
            {
                keys[0],
                keys[1],
                keys[2]
            };

            string[] KeysSecondHalf = new string[2]
            {
                keys[3],
                keys[4],
            };

            NamedTagsDictionary nameTag = new NamedTagsDictionary();
            nameTag.Add("ImportantCustomer", 0.5);

            Tag[] newTags = new Tag[5]
            {
                new Tag("Type 1 Customers"),
                new Tag("Type 2 Customers"),
                new Tag("Type 3 Customers"),
                new Tag("Type 4 Customers"),
                new Tag("Type 5 Customers")
            };

            var product1 = new Product()
            {
                ProductId    = 3,
                ProductName  = "Cheese",
                UnitPrice    = 1,
                UnitsInStock = 50,
                Discontinued = false,
                SupplierId   = 17
            };
            var product2 = new Product()
            {
                ProductId    = 4,
                ProductName  = "Milk",
                UnitPrice    = 3,
                UnitsInStock = 50,
                Discontinued = false,
                SupplierId   = 17
            };
            var product3 = new Product()
            {
                ProductId    = 5,
                ProductName  = "Sugar",
                UnitPrice    = 6,
                UnitsInStock = 50,
                Discontinued = false,
                SupplierId   = 17
            };
            var product4 = new Product()
            {
                ProductId    = 7,
                ProductName  = "Beef",
                UnitPrice    = 8,
                UnitsInStock = 50,
                Discontinued = false,
                SupplierId   = 17
            };
            var product5 = new Product()
            {
                ProductId    = 8,
                ProductName  = "Mutton",
                UnitPrice    = 9,
                UnitsInStock = 50,
                Discontinued = false,
                SupplierId   = 17
            };
            var product6 = new Product()
            {
                ProductId    = 9,
                ProductName  = "RTX 3090",
                UnitPrice    = 10,
                UnitsInStock = 50,
                Discontinued = false,
                SupplierId   = 17
            };

            Product[] products = new Product[6]
            {
                product1,
                product2,
                product3,
                product4,
                product5,
                product6
            };

            int      count       = 0;
            string[] productKeys = new string[6];

            foreach (var product in products)
            {
                productKeys[count] = $"Product{product.ProductId}";
                count++;
            }

            //----------------------------------------------------------------------------------------------
            //Callouts

            //-----------------------------------------------
            //Client Side

            Program program = new Program(cacheName3, clientCacheName3);

            //program.ClearCache();
            NewLine();
            program.GetCount();
            NewLine();
            //program.GetOutputCacheData();
            program.GetAllKeys();

            //program.Get("Chat");

            //program.GetSessionData();
            //program.GetViewStateData();

            //string[] keyset = new string[10000];
            //Customer[] customerss = new Customer[10000];
            //for (int i = 0; i < 10000; i++)
            //{
            //    keyset[i] = $"Customer:{i + 4000}";
            //    customerss[i] = customer;
            //}
            //program.AddBulk(keyset, customerss);

            //program.AddBulk(productKeys, products);
            //program.ContinuousQueryForProductUnitPrice(3, 10);

            //program.TestExtensibleDependency("ABCDE");

            //program.RemoveCacheItem(customerKey);
            //program.AddCacheItem(customerKey, customer2);
            //NewLine();

            //program.AddCacheItem(customerKey, customer5);
            //program.PessimisticLocking(customerKey);
            //program.UpdateCacheItem(customerKey, customer2);

            //program.AddWithGroup(customerKey, customer1, groupName2);
            //program.ContinuousQuerySearchByGroupName(groupName2);

            //program.CheckCache(customerKey);
            //program.Remove(customerKey);
            //program.Add(customerKey, customer);
            //program.Update(customerKey, customer3);
            //program.Remove(customerKey);
            //program.Update(customerKey, customer2);

            //program.AddBulk(keys, customerArray);
            //program.UpdateCacheItem(customerKey, customer);
            //program.ClearCache();

            //program.GetCount();

            //program.AddSqlDependencies();

            //string tempKey = "Customer:LINOD";
            //var item = program.Get(tempKey);
            //if (item!=null)
            //{
            //    Console.WriteLine("CustomerId: " + item.CustomerId);
            //    Console.WriteLine("ContactName: " + item.ContactName);
            //    Console.WriteLine("Mapper Status:" + item.WentThroughMapper.ToString());
            //    Console.WriteLine("CompanyName: " + item.CompanyName);
            //    Console.WriteLine("ContactTitle: " + item.ContactTitle);
            //    Console.WriteLine("Address: " + item.Address);
            //}
            //else
            //{
            //    Console.WriteLine($"Key: {tempKey} doesn't exist in cache");
            //}

            //program.RemoveCacheItem("ABCDE");
            //program.RemoveCacheItem("RSTUV");

            //program.TestExtensibleDependency("ABCDE");

            //var item = program.GetBulk(keys);
            //foreach (var entry in item)
            //{
            //    Console.WriteLine("Customer: " + entry.ContactName + " retrieved by bulk call");
            //}

            //program.AddGroup(KeysFirstHalf, groupName1);
            //program.AddGroup(KeysSecondHalf, groupName2);

            //program.RemoveGroup(KeysSecondHalf);

            //program.AddTags(KeysSecondHalf, newTags);

            //var item = program.GetByAnyTag(newTags);

            //foreach (var entry in item)
            //{
            //    Console.WriteLine("Customer: " + entry.ContactName + " retrieved by tags");
            //}

            //program.AddNamedTag(KeysFirstHalf,nameTag);

            //program.SearchByNamedTags();

            //program.CreateTopic(topicName);
            //program.PublicMessagesToTopics(topicName, customer);
            //program.SubscribeForTopicMessages(topicName);

            //program.DeleteTopic(topicName);

            //program.DurableSubscription(topicName, subscriptionName);
            //program.PatternBasedSubscription(topicName);
            //program.PatternBasedDurableSubscription(topicName, subscriptionName);
            //program.PatternBasedSubscriptionWithFailureNotification(topicName);


            //----------------------------------------------------------------------------------------------
            //Pub Sub PowerShell Commands

            //Get-Topics -CacheName SampleCache
            //Get-Topics -CacheName SampleCache -Detail
            //Get-Topics -CacheName SampleCache -ShowAll

            //program.CreateTopic(topicName);
            //program.PublicMessagesToTopics(topicName, customer3);
            //program.SubscribeForTopicMessages(topicName);
            //program.SubscribeForTopicMessages(topicName);
            //program.SubscribeForTopicMessages(topicName);
            //program.PublicMessagesToTopics(topicName, customer4);


            //-----------------------------------------------
            //Server Side

            //program.EntryProcessor(customerKey, customer);
            //program.TestAggregate();
            //program.MapReduceExecutor();

            //----------------------------------------------------------------------------------------------
            //Write timestamps to a file

            //using (StreamWriter writer = new StreamWriter("F://timestamps.txt"))
            //{
            //    int counter = 0;
            //    while (counter < 10000)
            //    {
            //        writer.WriteLine("TimeStamp:  Hrs: " + DateTime.Now.Hour + ",  Mins: " + DateTime.Now.Minute + ",  Sec: " + DateTime.Now.Second + ", mSec: " + DateTime.Now.Millisecond);
            //        counter++;
            //    }
            //}

            //string readText = File.ReadAllText("F://timestamps.txt");
            //Console.WriteLine(readText);

            NewLine();
            Console.WriteLine("End of the program");
        }