Example #1
0
        /// <summary>
        /// Method to get all locations
        /// </summary>
        /// <returns>
        ///     A list of Locations
        /// </returns>
        private List <Location> getAllLocationsNonCacheStreamParallel()
        {
            try
            {
                List <Location> lLocations = new List <Location>();
                string          dataSource = ConfigurationManager.AppSettings["dataSource"];
                switch (dataSource)
                {
                case "CSV":
                    string fileName = ConfigurationManager.AppSettings["fileLocations"];
                    using (ExcelDL edl = new ExcelDL())
                    {
                        lLocations = edl.getAllLocationsStreamParallel(fileName);
                    }
                    break;

                default:
                    break;
                }
                return(lLocations);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
 public void getAllLocationsParallelTest()
 {
     ExcelDL target = new ExcelDL(); // TODO: Initialize to an appropriate value
     string filename = @"E:\Fran\Projects\GeoLocalizationService\GeoLocalizationDL\Data\locationsBig.csv";
     int nRows = 1013352;
     List<Location> actual;
     actual = target.getAllLocationsStreamParallel(filename);
     Assert.AreEqual(nRows, actual.Count);
 }
Example #3
0
        /// <summary>
        /// Method to get all locations using the Memory Cache and reading the source of data using Stream Object and ParallelFor.
        /// </summary>
        /// <returns>
        ///     A list of Locations
        /// </returns>
        /// <remarks>
        ///     After testing this is the best option
        /// </remarks>
        private List <Location> getAllLocationsCacheStreamParallel()
        {
            try
            {
                List <Location> lLocations = new List <Location>();

                //Check if the list of Locations is already in Cache
                if (MemCache == null)
                {
                    MemCache = new MemoryCache("MemCache");
                }

                //If not makes the search
                if (!MemCache.Contains("ListOfLocations"))
                {
                    string dataSource = ConfigurationManager.AppSettings["dataSource"];

                    switch (dataSource)
                    {
                    case "CSV":
                        string fileName = ConfigurationManager.AppSettings["fileLocations"];
                        using (ExcelDL edl = new ExcelDL())
                        {
                            lLocations = edl.getAllLocationsStreamParallel(fileName);
                        }

                        break;

                    default:
                        break;
                    }

                    //Add to the Cache
                    CacheItemPolicy policy = getacheItemPolicy();
                    MemCache.Set("ListOfLocations", lLocations, policy);
                }
                else
                {
                    lLocations = (List <Location>)MemCache["ListOfLocations"];
                }

                return(lLocations);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        /// <summary>
        /// Method to get all locations using the Memory Cache and reading the source of data using Stream Object and ParallelFor.        
        /// </summary>
        /// <returns>
        ///     A list of Locations
        /// </returns>
        /// <remarks>
        ///     After testing this is the best option
        /// </remarks>
        private List<Location> getAllLocationsCacheStreamParallel()
        {
            try
            {
                List<Location> lLocations = new List<Location>();

                //Check if the list of Locations is already in Cache
                if (MemCache == null) MemCache = new MemoryCache("MemCache");
                
                //If not makes the search
                if (!MemCache.Contains("ListOfLocations"))
                {
                    
                    string dataSource = ConfigurationManager.AppSettings["dataSource"];                   

                    switch (dataSource)
                    {
                        case "CSV":
                            string fileName = ConfigurationManager.AppSettings["fileLocations"];
                            using (ExcelDL edl = new ExcelDL())
                            {
                                lLocations = edl.getAllLocationsStreamParallel(fileName);
                            }
                            
                            break;
                        default:
                            break;
                    }

                    //Add to the Cache
                    CacheItemPolicy policy = getacheItemPolicy();                   
                    MemCache.Set("ListOfLocations", lLocations, policy);
                }
                else lLocations = (List<Location>)MemCache["ListOfLocations"];

                return lLocations;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
 /// <summary>
 /// Method to get all locations 
 /// </summary>
 /// <returns>
 ///     A list of Locations
 /// </returns>
 private List<Location> getAllLocationsNonCacheStreamParallel()
 {
     try
     {
         List<Location> lLocations = new List<Location>();
         string dataSource = ConfigurationManager.AppSettings["dataSource"];
         switch (dataSource)
         {
             case "CSV":
                 string fileName = ConfigurationManager.AppSettings["fileLocations"];
                 using (ExcelDL edl = new ExcelDL())
                 {
                     lLocations = edl.getAllLocationsStreamParallel(fileName);
                 }
                 break;
             default:
                 break;
         }
         return lLocations;
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }