/// <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);
        }
 // 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;
     }
 }
        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;
            }
        }
 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;
     }
 }
Example #5
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);
                    }
                }
            }
        }