Ejemplo n.º 1
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);
        }
Ejemplo n.º 2
0
        internal static Hashtable GetJavaNamedTagsInfo(string fullName, NamedTagsDictionary namedTags, TypeInfoMap typeMap)
        {
            CheckJavaDuplicateIndexName(fullName, namedTags, typeMap);

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

            Hashtable tagInfo  = new Hashtable();
            Hashtable tagsList = new Hashtable();

            foreach (DictionaryEntry nameValue in namedTags)
            {
                if (nameValue.Value == null)
                {
                    throw new ArgumentNullException("Named Tag value cannot be null");
                }

                tagsList.Add(nameValue.Key, nameValue.Value);
            }

            string typeName = fullName;

            typeName = typeName.Replace("+", ".");

            tagInfo["type"]            = typeName;
            tagInfo["named-tags-list"] = tagsList;

            return(tagInfo);
        }
Ejemplo n.º 3
0
        private static void CheckJavaDuplicateIndexName(string fullName, NamedTagsDictionary namedTags, TypeInfoMap typeMap)
        {
            if (namedTags == null || typeMap == null)
            {
                return;
            }

            string typeName = fullName;

            typeName = typeName.Replace("+", ".");

            int handleId = typeMap.GetHandleId(typeName);

            if (handleId != -1)
            {
                ArrayList attributes = typeMap.GetAttribList(handleId);
                foreach (string name in attributes)
                {
                    if (namedTags.Contains(name))
                    {
                        throw new Exception("Key in named tags conflicts with the indexed attribute name of the specified object.");
                    }
                }
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// This method adds items in the cache along with namedTags.
        /// </summary>
        /// <param name="namedTagDict"> Named tags that will be added with the items. </param>
        private static void AddItems(NamedTagsDictionary namedTagDict)
        {
            AddNamedTagDataToCache(14, "Andrew Ng", "USA", namedTagDict);
            AddNamedTagDataToCache(15, "Jhon Getsby", "France", namedTagDict);

            Console.WriteLine("Items added in cache.");
        }
Ejemplo n.º 5
0
 /// <summary>
 /// Verifica se existem itens com o nome publicados.
 /// </summary>
 /// <param name="value">Instancia.</param>
 /// <param name="namedTags">Dicionário com as tags nomeadas.</param>
 /// <param name="typeMap"></param>
 private static void CheckDuplicateIndexName(object value, NamedTagsDictionary namedTags, TypeInfoMap typeMap)
 {
     if (namedTags != null && value != null && typeMap != null)
     {
         int handleId = 0;
         if (value is CacheItemRecord)
         {
             handleId = typeMap.GetHandleId(((CacheItemRecord)value).TypeName);
         }
         else
         {
             handleId = typeMap.GetHandleId(value.GetType());
         }
         if (handleId != -1)
         {
             foreach (string str2 in typeMap.GetAttribList(handleId))
             {
                 if (namedTags.Contains(str2))
                 {
                     throw new Exception(ResourceMessageFormatter.Create(() => Properties.Resources.Exception_DuplicateIndexName).Format());
                 }
             }
         }
     }
 }
Ejemplo n.º 6
0
        /// <summary>
        /// Recupera as informações das tags nomeadas.
        /// </summary>
        /// <param name="value"></param>
        /// <param name="namedTags"></param>
        /// <param name="typeMap"></param>
        /// <returns></returns>
        internal static Hashtable GetNamedTagsInfo(object value, NamedTagsDictionary namedTags, TypeInfoMap typeMap)
        {
            CheckDuplicateIndexName(value, namedTags, typeMap);
            if ((namedTags == null) || (namedTags.Count == 0))
            {
                return(null);
            }
            Hashtable hashtable  = new Hashtable();
            Hashtable hashtable2 = new Hashtable();

            foreach (DictionaryEntry entry in namedTags)
            {
                if (entry.Value == null)
                {
                    throw new ArgumentNullException("Named Tag value cannot be null");
                }
                hashtable2.Add(entry.Key, entry.Value);
            }
            hashtable["is-itemrecord"] = value is CacheItemRecord;
            string str = null;

            if (value is CacheItemRecord)
            {
                str = ((CacheItemRecord)value).TypeName.FullName;
            }
            else
            {
                str = value.GetType().FullName.Replace("+", ".");
            }
            hashtable["type"]            = str;
            hashtable["named-tags-list"] = hashtable2;
            return(hashtable);
        }
Ejemplo n.º 7
0
        private static void CheckDuplicateIndexName(object value, NamedTagsDictionary namedTags, TypeInfoMap typeMap)
        {
            if (namedTags == null || value == null || typeMap == null)
            {
                return;
            }

            string typeName = value.GetType().FullName;

            typeName = typeName.Replace("+", ".");

            int handleId = typeMap.GetHandleId(typeName);

            if (handleId != -1)
            {
                ArrayList attributes = typeMap.GetAttribList(handleId);
                foreach (string name in attributes)
                {
                    if (namedTags.Contains(name)) //@UH whether this should be case insensitive
                    {
                        throw new Exception("Key in named tags conflicts with the indexed attribute name of the specified object.");
                    }
                }
            }
        }
        /// <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);
        }
Ejemplo n.º 10
0
        /// <summary>
        /// This method inserts items in cache with named tags.
        /// </summary>
        private static void InsertItemsWithNamedTags(IList <Product> products)
        {
            foreach (var product in products)
            {
                NamedTagsDictionary namedTagDictionary = GetNamedTagsDictionary(product);
                CacheItem           cacheItem          = new CacheItem(product);
                cacheItem.NamedTags = namedTagDictionary;
                _cache.Add($"Product:{product.Id}", cacheItem);
            }

            Console.WriteLine("Items added in cache with NamedTag 'Supplier'.");
        }
Ejemplo n.º 11
0
        /// <summary>
        /// This method adds items in the cache along with namedTags.
        /// </summary>
        /// <param name="namedTagDict"> Named tags that will be added with the items. </param>
        private static void AddItems(NamedTagsDictionary namedTagDict)
        {
            _cache.Add("Order:1", new Order()
            {
                OrderID = 1, ShipName = "Andrew Ng", ShipCountry = "USA"
            }, namedTagDict);
            _cache.Add("Order:2", new Order()
            {
                OrderID = 2, ShipName = "Jhon Getsby", ShipCountry = "France"
            }, namedTagDict);

            Console.WriteLine("Items added in cache.");
        }
Ejemplo n.º 12
0
 public APILogItem(string key, CacheItem item, string exceptionMessage)
 {
     _key                  = key;
     _group                = item.Group;
     _subGroup             = item.SubGroup;
     _tags                 = item.Tags;
     _namedTags            = item.NamedTags;
     _abs                  = item.AbsoluteExpiration;
     _sld                  = item.SlidingExpiration;
     _p                    = item.Priority;
     _dep                  = item.Dependency;
     _syncDep              = item.SyncDependency;
     _resyncProviderName   = item.ResyncProviderName;
     _version              = item.Version;
     _isResyncRequired     = item.IsResyncExpiredItems;
     this.ExceptionMessage = exceptionMessage;
 }
Ejemplo n.º 13
0
        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);
        }
Ejemplo n.º 14
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();
        }
Ejemplo n.º 15
0
        //-

        internal static Hashtable GetNamedTagsInfo(object value, NamedTagsDictionary namedTags, TypeInfoMap typeMap)
        {
            CheckDuplicateIndexName(value, namedTags, typeMap);

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

            Hashtable tagInfo  = new Hashtable();
            Hashtable tagsList = new Hashtable();

            foreach (DictionaryEntry nameValue in namedTags)
            {
                if (nameValue.Key != null && string.IsNullOrEmpty(nameValue.Key.ToString().Trim()))
                {
                    throw new ArgumentException("Named Tag key cannot be null or empty");
                }

                if (nameValue.Value == null)
                {
                    throw new ArgumentNullException("Named Tag value cannot be null");
                }

                tagsList.Add(nameValue.Key, nameValue.Value);
            }

            string typeName = value.GetType().FullName;

            typeName = typeName.Replace("+", ".");

            tagInfo["type"]            = typeName;
            tagInfo["named-tags-list"] = tagsList;

            return(tagInfo);
        }
Ejemplo n.º 16
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);
        }
Ejemplo n.º 17
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");
        }
Ejemplo n.º 18
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");
        }
Ejemplo n.º 19
0
        private static void AddNamedTagDataToCache(int orderID, string shipName, string shipCountry, NamedTagsDictionary namedTagDict)
        {
            Order order = new Order()
            {
                OrderID = orderID, ShipName = shipName, ShipCountry = shipCountry
            };

            // create object key
            string key = "Order:" + order.OrderID.ToString();

            // add object to cache
            _cache.Add(key, order, namedTagDict);
        }
Ejemplo n.º 20
0
        /// <summary>
        /// Add Named Tags data to Cache
        /// </summary>
        /// <param name="productId"></param>
        /// <param name="productName"></param>
        /// <param name="group"></param>
        /// <param name="className"></param>
        /// <param name="category"></param>
        private static void AddNamedTagDataToCache(int orderID, string shipName, string shipCountry, NamedTagsDictionary namedTagDict)
        {
            Order order = new Order()
            {
                OrderID = orderID, ShipName = shipName, ShipCountry = shipCountry
            };

            // create object key
            string key = "Order:" + order.OrderID.ToString();

            // create CacheItem with your desired object
            CacheItem item = new CacheItem(order);

            // assign NameTags to CacheItem object
            item.NamedTags = namedTagDict;

            // add CacheItem object to cache
            _cache.Add(key, item);
        }