示例#1
0
        private static Resume Resume(string firstnameLastname)
        {
            Assert.ValidInput(firstnameLastname, "firstname-lastname");

            firstnameLastname = firstnameLastname.Scrub();

            if (ServiceCache.IsInCache <Resume>(firstnameLastname))
            {
                var cachedResume = (Resume)ServiceCache.GetFromCache <Resume>(firstnameLastname);
                if (cachedResume != null)
                {
                    return(cachedResume);
                }
            }

            var linkedInEmailAddress = ConfigurationManager.AppSettings["LinkedInEmailAddress"];
            var linkedInPassword     = ConfigurationManager.AppSettings["LinkedInPassword"];

            var resumeSniffer = new LinkedInResumeSniffer(linkedInEmailAddress, linkedInPassword, firstnameLastname);

            Resume resume = null;

            try
            {
                resume = resumeSniffer.GetResume();
            }
            catch (Exception)
            {
                HandleErrors(linkedInEmailAddress);
            }

            HandleErrors(resumeSniffer.Errors);

            return(resume.AddToCache(firstnameLastname));
        }
示例#2
0
        private static WhoisEnhancedRecord WhoisEnhanced(string ipAddress, string filters, string referrer)
        {
            if (filters != null)
            {
                filters = filters.Scrub();
                Assert.ValidInput(filters, "filters");
            }
            if (referrer != null)
            {
                referrer = referrer.Scrub();
                Assert.ValidInput(referrer, "referrer");
            }

            var hash = BuildHashKey(ipAddress, filters);

            if (ServiceCache.IsInCache <WhoisEnhancedRecord>(hash))
            {
                var cachedRecord = (WhoisEnhancedRecord)ServiceCache.GetFromCache <WhoisEnhancedRecord>(hash);
                if (cachedRecord != null)
                {
                    return(cachedRecord);
                }
            }

            var whoisEnhancedRecord = new WhoisEnhancedRecord(Whois(ipAddress), filters, referrer);

            return(whoisEnhancedRecord.AddToCache(hash));
        }
示例#3
0
        private static WhoisRecord Whois(string ipAddress)
        {
            ipAddress = ipAddress.Scrub();
            if (string.IsNullOrEmpty(ipAddress))
            {
                ipAddress = GetIpAddressFromRequest(ipAddress);
            }
            Assert.ValidInput(ipAddress, "ipAddress");

            if (ServiceCache.IsInCache <WhoisRecord>(ipAddress))
            {
                var cachedRecord = (WhoisRecord)ServiceCache.GetFromCache <WhoisRecord>(ipAddress);
                if (cachedRecord != null)
                {
                    return(cachedRecord);
                }
            }

            var whoisClient = new WhoisClient(ipAddress);
            var record      = whoisClient.GetWhoisRecord();

            HandleErrors(whoisClient.Errors);

            return(record.AddToCache(ipAddress));
        }
示例#4
0
 private static T GetFromCache <T>(string key)
 {
     if (ServiceCache.IsInCache <T>(key))
     {
         return((T)ServiceCache.GetFromCache <T>(key));
     }
     return(default(T));
 }
示例#5
0
        private static Wishlist Wishlist(string listId)
        {
            Assert.ValidInput(listId, "listId");

            if (ServiceCache.IsInCache <Wishlist>(listId))
            {
                var cachedWishlist = (Wishlist)ServiceCache.GetFromCache <Wishlist>(listId);
                if (cachedWishlist != null)
                {
                    return(cachedWishlist);
                }
            }

            var amazonResponse = new AmazonFactory(BuildRequest(null, listId)).GetResponse();

            HandleErrors(amazonResponse.Errors);

            return(new Wishlist(amazonResponse.Products.OrderBy(p => p.AuthorsMLA).ThenBy(p => p.Title)).AddToCache(listId));
        }
示例#6
0
        private static Reviews Reviews(string customerId)
        {
            Assert.ValidInput(customerId, "customerId");

            if (ServiceCache.IsInCache <Reviews>(customerId))
            {
                var cachedReviews = (Reviews)ServiceCache.GetFromCache <Reviews>(customerId);
                if (cachedReviews != null)
                {
                    return(cachedReviews);
                }
            }

            var amazonResponse = new AmazonFactory(BuildRequest(customerId, null)).GetResponse();

            HandleErrors(amazonResponse.Errors);

            return(new Reviews(amazonResponse.Reviews.OrderByDescending(r => r.Date)).AddToCache(customerId));
        }
示例#7
0
        private static Profile DiscoverUser(string username)
        {
            username = username.Scrub();
            Assert.ValidInput(username, "username");

            if (ServiceCache.IsInCache <Profile>(username))
            {
                var cachedProfile = (Profile)ServiceCache.GetFromCache <Profile>(username);
                if (cachedProfile != null)
                {
                    return(cachedProfile);
                }
            }

            var sniffer = new ProfileSniffer(username);

            var profile = sniffer.GetProfile();

            HandleErrors(sniffer.Errors);

            return(profile.AddToCache(username));
        }