Exemplo n.º 1
0
 /// <summary>
 /// remove list entry by Customer
 /// </summary>
 /// <param name="distributedList"></param>
 public void RemoveListValue(IDistributedList <object> distributedList)
 {
     distributedList.WriteThruOptions = new WriteThruOptions(WriteMode.WriteThru, WriteThruProviderName);
     distributedList.Remove(new Customer()
     {
         CustomerID = CustomerID,
     });
 }
Exemplo n.º 2
0
 /// <summary>
 /// displays list objects
 /// </summary>
 /// <param name="distributedList">List to display</param>
 private void DisplayListData(IDistributedList <object> distributedList)
 {
     Console.WriteLine("Result count: " + distributedList.Count);
     foreach (Customer listCustomer in distributedList)
     {
         Console.WriteLine("--");
         DisplayCustomerData(listCustomer);
     }
 }
Exemplo n.º 3
0
        /// <summary>
        /// Remove an object in distributed list by index
        /// </summary>
        /// <param name="index">Index of object to be deleted from distributed list</param>
        private static void RemoveObjectFromList(int index)
        {
            IDistributedList <Customer> list = _cache.DataTypeManager.GetList <Customer>(_datatype);

            // Remove the existing customer
            list.RemoveAt(index);

            // Print output on console.
            Console.WriteLine("\nObject is removed from distributed list.");
        }
Exemplo n.º 4
0
        /// <summary>
        /// Remove an object in distributed list by instance of object
        /// </summary>
        /// <param name="customer">Instance of object to be deleted from distributed list</param>
        private static void RemoveObjectFromList(Customer customer)
        {
            IDistributedList <Customer> list = _cache.DataTypeManager.GetList <Customer>(_datatype);
            // Remove the existing customer
            // Expensive operation use carefully
            bool removed = list.Remove(customer);

            //Print output on console.
            Console.WriteLine("\nObject is" + ((removed) ? " " : " not ") + "removed from distributed List.");
        }
Exemplo n.º 5
0
        public void DistributedListNameTest()
        {
            using (var gridion = GridionFactory.Start())
            {
                IDistributedList <string> list = gridion.GetList <string>("name");

                Assert.IsNotNull(list, "list != null");
                Assert.AreEqual("name", list.Name, "The name is incorrect.");
            }
        }
Exemplo n.º 6
0
        /// <summary>
        ///  This method UnLock List Datastructure
        ///
        /// </summary>
        private static void UnLockList()
        {
            IDistributedList <Customer> list = _cache.DataTypeManager.GetList <Customer>(_datatype);

            //Unlock the Distributed Datatype
            list.Unlock();

            //Print output on console.
            Console.WriteLine("\nDistributed Datatype:{0} Unlocked", _datatype);
        }
Exemplo n.º 7
0
        /// <summary>
        /// This method adds objects to distributed list
        /// </summary>
        /// <param name="customer"> Instances of Customer that will be added to
        /// distributed list</param>
        private static void AddObjectsToDatatype(Customer[] customers)
        {
            IDistributedList <Customer> list = _cache.DataTypeManager.GetList <Customer>(_datatype);

            //Add Bulk into Distributed List
            list.AddRange(customers);

            // Print output on console.
            Console.WriteLine("\nObjects are added to distributed list.");
        }
Exemplo n.º 8
0
        /// <summary>
        /// This method acquire lock on Distributed datatype
        /// </summary>
        private static void LockDatatype()
        {
            // Get Distributed datatype
            IDistributedList <Customer> list = _cache.DataTypeManager.GetList <Customer>(_datatype);

            // Acquire Lock
            bool locked = list.Lock(new TimeSpan(0, 1, 0));

            // Print output on console.
            Console.WriteLine("\nDistributed Datatype: {0} " + ((locked) ? "Locked" : "Cannot be Locked"), _datatype);
        }
Exemplo n.º 9
0
        /// <summary>
        ///  This method unregister notification on Distributed Datatype
        /// </summary>
        ///
        private static void UnRegisterNotification()
        {
            IDistributedList <Customer> list = _cache.DataTypeManager.GetList <Customer>(_datatype);

            //unregister notifications for all Event types
            list.UnRegisterNotification(OnDataNotificationCallback,
                                        EventType.ItemAdded | EventType.ItemRemoved | EventType.ItemUpdated);

            //Print output on console.
            Console.WriteLine("\nNotifications unregistered on Distributed Datatype: {0}", _datatype);
        }
        /// <summary>
        /// Empty all updates on the specified match name
        /// </summary>
        /// <param name="matchName">name of match</param>
        public void ClearUpdates(string matchName)
        {
            // fetch list handler from cache
            IDistributedList <MatchUpdate> distributedList = _cache.DataTypeManager.GetList <MatchUpdate>(matchName, readThruOptions);

            // check if list already exists
            if (distributedList != null)
            {
                // clear the list
                distributedList.Clear();
            }
        }
Exemplo n.º 11
0
        /// <summary>
        /// This method gets an object from distributed list specified by index
        /// </summary>
        /// <returns>Returns instance of Customer retrieved from distributed list
        /// by index</returns>
        private static Customer GetObjectFromList(int index)
        {
            IDistributedList <Customer> list = _cache.DataTypeManager.GetList <Customer>(_datatype);
            Customer cachedCustomer          = list[index];

            // Print output on console.
            Console.WriteLine("\nObject is fetched from distributed list");

            PrintCustomerDetails(cachedCustomer);

            return(cachedCustomer);
        }
 public IDistributedList <string> CreateListInCache(string key)
 {
     try
     {
         IDistributedList <string> list = cache.DataTypeManager.CreateList <string>(key);
         return(list);
     }
     catch (Exception ex)
     {
         throw;
     }
 }
Exemplo n.º 13
0
        /// <summary>
        /// This method register notifications for Add,Update and Remove on List
        /// </summary>
        private static void RegisterNotification()
        {
            IDistributedList <Customer> list = _cache.DataTypeManager.GetList <Customer>(_datatype);

            //register callback for notification when item is added , removed or Updated in Distributed Datatype with DataFilter as None
            list.RegisterNotification(new DataTypeDataNotificationCallback(OnDataNotificationCallback),
                                      EventType.ItemAdded | EventType.ItemRemoved | EventType.ItemUpdated
                                      , DataTypeEventDataFilter.None);

            //Print output on console.
            Console.WriteLine("\nNotifications are registered on Dictionary: {0}", _datatype);
        }
Exemplo n.º 14
0
        private static void InitializeCache()
        {
            string cache = ConfigurationManager.AppSettings["CacheID"];

            if (String.IsNullOrEmpty(cache))
            {
                Console.WriteLine("The CacheID cannot be null or empty.");
                return;
            }

            Cache = CacheManager.GetCache(cache);
            Console.WriteLine(string.Format("\nCache '{0}' is initialized.", cache));
            string topic = ConfigurationManager.AppSettings["TopicName"];

            if (String.IsNullOrEmpty(topic))
            {
                Console.WriteLine("Topic name cannot be null or empty.");
                return;
            }

            Topic = Cache.MessagingService.GetTopic(topic);

            if (Topic == null)
            {
                Topic = Cache.MessagingService.CreateTopic(topic);
            }

            Topic.CreateSubscription(TaxiFareDataUpdated);
            string datasetKey = ConfigurationManager.AppSettings["TrainingData"];

            if (String.IsNullOrEmpty(datasetKey))
            {
                Console.WriteLine("Training data key cannot be null or empty.");
                return;
            }

            TrainingData = Cache.DataTypeManager.GetList <TaxiTrip>(datasetKey);

            var modelpath = Cache.Get <string>(ModelPath);

            if (modelpath != null)
            {
                ModelTrained = true;
                ModelPath    = modelpath;
            }

            if (TrainingData == null)
            {
                TrainingData = Cache.DataTypeManager.CreateList <TaxiTrip>(datasetKey);
            }
        }
        /// <summary>
        /// store new update in cache
        /// </summary>
        /// <param name="matchName">name of match</param>
        /// <param name="matchUpdate">instance of <seealso cref="MatchUpdate"/> containing a single update</param>
        public void SaveUpdates(string matchName, MatchUpdate matchUpdate)
        {
            // fetch list handler from cache
            IDistributedList <MatchUpdate> distributedList = _cache.DataTypeManager.GetList <MatchUpdate>(matchName, readThruOptions);

            // if there is no list initialized, create new list with writethru enabled
            if (distributedList == null)
            {
                distributedList = _cache.DataTypeManager.CreateList <MatchUpdate>(matchName, null, writeThruOptions);
            }

            // add new update to list
            distributedList.Add(matchUpdate);
        }
Exemplo n.º 16
0
        /// <summary>
        /// This method updates object in distributed list
        /// </summary>
        /// <param name="index">Index of object to be updated at in distributed list</param>
        /// <param name="customer">Instance of Customer that will be updated in the distributed list</param>
        private static void UpdateObjectsInList(int index)
        {
            IDistributedList <Customer> list = _cache.DataTypeManager.GetList <Customer>(_datatype);
            // Modify company name of customer

            Customer customer = list[index];

            customer.CompanyName = "Gourmet Lanchonetes";

            // Update object via indexer
            list[index] = customer;

            // Print output on console.
            Console.WriteLine("\nObject is updated in distributed list.");
        }
 // add a customer info in cache
 public void AddtCustomerInCache(string key, DataTypeAttributes attributes, FraudRequest customer)
 {
     try
     {
         // create a list with write behind option
         // so whenever a cahcnge happen in data it is upadated back to data source
         WriteThruOptions options             = new WriteThruOptions(WriteMode.WriteBehind);
         IDistributedList <FraudRequest> list = cache.DataTypeManager.CreateList <FraudRequest>(key, attributes);
         list.WriteThruOptions = options;
         list.Add(customer);
     }
     catch (Exception ex)
     {
         throw;
     }
 }
        /// <summary>
        /// Creates a distributed list to which instances of customers are to be added
        /// </summary>
        private static IList <Customer> GetOrCreateList()
        {
            IDistributedList <Customer> distributedList = _cache.DataTypeManager.GetList <Customer>(_listName);

            if (distributedList == null)
            {
                DataTypeAttributes attributes = new DataTypeAttributes
                {
                    Expiration = new Expiration(ExpirationType.Absolute, new TimeSpan(0, 1, 0))
                };

                // Creating distributed list with absolute expiration of 1 minute
                distributedList = _cache.DataTypeManager.CreateList <Customer>(_listName, attributes);
            }

            return(distributedList);
        }
        /// <summary>
        /// fetch stored updates from cache
        /// </summary>
        /// <param name="matchName">name of match</param>
        /// <returns>list of <seealso cref="MatchUpdate"/></returns>
        public List <MatchUpdate> FetchUpdates(string matchName)
        {
            // fetch list handler from cache
            IDistributedList <MatchUpdate> distributedList = _cache.DataTypeManager.GetList <MatchUpdate>(matchName, readThruOptions);

            // if there is no list initialized, create new list with writethru enabled
            if (distributedList == null)
            {
                distributedList = _cache.DataTypeManager.CreateList <MatchUpdate>(matchName, null, writeThruOptions);
            }

            // fetch list of updates
            List <MatchUpdate> list = (from matchUpdate in distributedList select matchUpdate).ToList();

            // return list to user
            return(list);
        }
Exemplo n.º 20
0
 /// <summary>
 /// Modifies first entry of list
 /// </summary>
 /// <param name="distributedList"></param>
 private void ModifyListValue(IDistributedList <object> distributedList)
 {
     distributedList.WriteThruOptions = new WriteThruOptions(WriteMode.WriteThru, WriteThruProviderName);
     InputDataFromUser();
     distributedList[0] = new Customer()
     {
         CustomerID  = CustomerID,
         ContactName = ContactName,
         CompanyName = CompanyName,
         Address     = Address,
         City        = City,
         Country     = Country,
         PostalCode  = PostalCode,
         ContactNo   = Phone,
         Fax         = Fax,
     };
 }
Exemplo n.º 21
0
        static void Main(string[] args)
        {
            string cache = ConfigurationManager.AppSettings["CacheID"];

            if (String.IsNullOrEmpty(cache))
            {
                Console.WriteLine("The CacheID cannot be null or empty.");
                return;
            }

            Cache = CacheManager.GetCache(cache);

            string topic = ConfigurationManager.AppSettings["TopicName"];

            if (String.IsNullOrEmpty(topic))
            {
                Console.WriteLine("Topic name cannot be null or empty.");
                return;
            }

            Topic = Cache.MessagingService.GetTopic(topic);
            string datasetKey = ConfigurationManager.AppSettings["TrainingData"];

            if (String.IsNullOrEmpty(datasetKey))
            {
                Console.WriteLine("Training data key cannot be null or empty.");
                return;
            }
            TrainingData = Cache.DataTypeManager.GetList <TaxiTrip>(datasetKey);

            if (Topic == null)
            {
                Topic = Cache.MessagingService.CreateTopic(topic);
            }

            //Load new data
            Thread loadData = new Thread(LoadDataInCache);

            loadData.Start();
            Console.WriteLine("Data streaming started....");
        }
        public void UpdateTrainedDataInCache(string key, string traineddata)
        {
            try
            {
                IDistributedList <string> list = null;
                if (cache.Contains(key))
                {
                    list = cache.DataTypeManager.GetList <string>(key);
                }
                else
                {
                    list = CreateListInCache(key);
                }

                list.Add(traineddata);
            }
            catch
            {
                //throw;
            }
        }
Exemplo n.º 23
0
        public void DistributedListTest2Nodes()
        {
            var configuration  = new GridionConfiguration("127.0.0.1", 24000);
            var configuration2 = new GridionConfiguration("127.0.0.1", 24001);

            using (var gridion = GridionFactory.Start(configuration))
            {
                using (var gridion2 = GridionFactory.Start(configuration2))
                {
                    IDistributedList <string> list = gridion.GetList <string>("name");

                    Assert.IsNotNull(list, "list != null");
                    Assert.AreEqual("name", list.Name, "The name is incorrect.");

                    IDistributedList <string> list2 = gridion2.GetList <string>("name");

                    Assert.IsNotNull(list2, "dictionary != null");
                    Assert.AreEqual("name", list2.Name, "The name is incorrect.");
                }
            }
        }
 public void UpdateCustomerInfoInCache(string key, FraudRequest cutomerInfo)
 {
     try
     {
         // update info of a customer aginst its id
         WriteThruOptions options             = new WriteThruOptions(WriteMode.WriteBehind);
         IDistributedList <FraudRequest> list = cache.DataTypeManager.GetList <FraudRequest>(key);
         if (list == null)
         {
             AddtCustomerInCache(key, null, cutomerInfo);
         }
         else
         {
             list.WriteThruOptions = options;
             list.Add(cutomerInfo);
         }
     }
     catch
     {
         throw;
     }
 }
Exemplo n.º 25
0
        private static void LoadInitialDataInCache(string initialData)
        {
            var    currentLine = string.Empty;
            string datapath    = ConfigurationManager.AppSettings["BaseDataRelativePath"];

            if (String.IsNullOrEmpty(datapath))
            {
                Console.WriteLine("Data path cannot be null or empty.");
                return;
            }

            string filepath = GetAbsolutePath($"{datapath}/taxi-fare-initial.csv");
            IDistributedList <TaxiTrip> initialDataList = Cache.DataTypeManager.GetList <TaxiTrip>(initialData);

            if (initialDataList == null)
            {
                initialDataList = Cache.DataTypeManager.CreateList <TaxiTrip>(initialData);

                using (StreamReader r = new StreamReader(filepath))
                {
                    while ((currentLine = r.ReadLine()) != null)
                    {
                        string[] incomingData = currentLine.Split(",");
                        TaxiTrip data         = new TaxiTrip();

                        data.RateCode       = float.Parse(incomingData[0]);
                        data.PassengerCount = float.Parse(incomingData[1]);
                        data.TripTime       = float.Parse(incomingData[2]);
                        data.TripDistance   = float.Parse(incomingData[3]);
                        data.FareAmount     = float.Parse(incomingData[4]);

                        initialDataList.Add(data);
                        TrainingData.Add(data);
                    }
                }
            }
        }