Exemplo n.º 1
0
        /// <summary>
        /// This method will load all ips to memory
        /// in order to update the ipdetails and keep track
        /// of the progress. If its not null then another process is
        /// on and will be skiped
        /// </summary>
        /// <param name="ips"></param>
        public bool LoadIpsToMemory(UpdateIpDetails update)
        {
            if (_cache.Get("IpUpdate") == null)
            {
                _cache.Set("IpUpdate", update);

                return(true);
            }

            return(false);
        }
Exemplo n.º 2
0
        private UpdateIpDetails CreateObjectForUpdate(HashSet <string> ips)
        {
            UpdateIpDetails update = new UpdateIpDetails
            {
                Ips       = ips,
                Total     = ips.Count(),
                Id        = Guid.NewGuid().ToString(),
                Completed = 0
            };

            return(update);
        }
Exemplo n.º 3
0
        public UpdateIpDetails InitiateUpdateInformation()
        {
            /// Get all the ips from DB for the update
            HashSet <string> ips = _ctx.IPDetails.Select(x => x.Ip).ToHashSet();

            /// Create the object that will be stored in memory and keep the
            /// progress status
            UpdateIpDetails update = CreateObjectForUpdate(ips);

            /// Load the object to the memory
            bool clearOfOtherProcess = _memory.LoadIpsToMemory(update);

            if (!clearOfOtherProcess)
            {
                //  return "Another process is running! Please try again later.";
            }

            return(update);
        }
Exemplo n.º 4
0
        private async Task StartUpdatingIps(UpdateIpDetails update)
        {
            /// End the process
            if (update.Ips.Count() == 0)
            {
                _memory.RemoveItem("Update");
                return;
            }

            List <IPDetails> result;

            /// Take 10 and continue if there are plenty left
            if (update.Ips.Count() >= 10)
            {
                HashSet <string> ipToProcess = update.Ips.Take(10).ToHashSet();

                result = await _ipInfoProvider.GetDetailsForMany(ipToProcess);

                UpdateMultipleIps(result, ipToProcess);

                update.Ips = update.Ips.Skip(10).ToHashSet();

                update.Completed += 10;

                _memory.InsertToMemory("IpUpdate", update);

                await StartUpdatingIps(update).ConfigureAwait(false);

                return;
            }

            /// Take the last items and finish
            result = await _ipInfoProvider.GetDetailsForMany(update.Ips).ConfigureAwait(false);

            UpdateMultipleIps(result, update.Ips);

            _memory.RemoveItem("Update");
        }
Exemplo n.º 5
0
 public void UpdateAllInfo(UpdateIpDetails update)
 {
     /// Start the update method and return the Id to the user
     Task.Run(() => StartUpdatingIps(update));
 }