示例#1
0
        /// <summary>
        /// Creates an object with total count of all ips
        /// and the ips that will be processed for update.
        /// A counter of how many have been completed is also provided
        /// along with a Guid that a user can use to keep track
        /// </summary>
        /// <param name="ips"></param>
        /// <returns>An object with the guid for the user to use</returns>

        public async Task <IPDetails> FetchIpDetails(string ip)
        {
            IPDetails result;

            /// <summary>
            /// Returns data from memory if exists
            /// </summary>
            result = _memory.FetchFromMemory(ip);

            if (result != null)
            {
                return(result);
            }

            /// <summary>
            /// Returns data from database if exists
            /// and adds it to memory
            /// </summary>
            var domainDetails = await _ctx.IPDetails.FirstOrDefaultAsync(x => x.Ip == ip)
                                .ConfigureAwait(false);

            var details = IPDetailsExtended.DomainToView(domainDetails);

            if (details != null)
            {
                _memory.InsertToMemory(ip, details);

                return(details);
            }

            /// <summary>
            /// Gets ip info from the library
            /// If it is not null we add it to db and to memory
            /// and finally we return the value
            /// </summary>

            result = await _ipInfoProvider.GetDetails(ip).ConfigureAwait(false);

            if (result != null)
            {
                _memory.InsertToMemory(ip, result);

                await InsertIPDetails(result, ip).ConfigureAwait(false);

                return(result);
            }

            return(result);
        }