Exemplo n.º 1
0
        public void CalculatedDistanceExpectedPrecision(double lat1, double lon1, double lat2, double lon2,
                                                        double expectedDistanceInKm, int decimalPlacesPrecision)
        {
            var calculated = GeoSpatial.GetDistance(lat1, lon1, lat2, lon2, GeoSpatialDistanceUnit.Kilometer);

            Assert.Equal(calculated, expectedDistanceInKm, decimalPlacesPrecision);
        }
        /// <summary>
        /// Generate Email Model method
        /// </summary>
        /// <returns> The <see cref="DealsEmailModel"/>. </returns>
        /// <exception cref="ModelContentException"> The input is insufficient for email model creation </exception>
        public DailyDealsContract GenerateModel(EmailTemplateData modelData)
        {
            DailyDealsContract dailyDealsContract  = null;
            DealsTemplateData  dailyDealsModelData = modelData as DealsTemplateData;

            if (dailyDealsModelData != null)
            {
                var            dealsList     = dailyDealsModelData.Deals == null ? null : dailyDealsModelData.Deals.ToList();
                DealContract[] dealsContract = null;
                if (dealsList != null)
                {
                    if (dailyDealsModelData.DealEmailType == DealEmailType.WeeklyDeal && dealsList.Count() <= 3)
                    {
                        throw new ModelContentException(string.Format("Number of deals is: {0}. This is insufficient for email model creation", dealsList.Count()));
                    }

                    dealsContract = new DealContract[dealsList.Count];
                    for (int i = 0; i < dealsList.Count; ++i)
                    {
                        DealContract dealContract = ConvertDeal(dealsList[i]);
                        if (dealContract != null)
                        {
                            dealsContract[i] = dealContract;
                        }
                    }

                    if (dailyDealsModelData.DealEmailType == DealEmailType.WeeklyDeal && dealsContract.Length <= 3)
                    {
                        throw new ModelContentException(string.Format("Number of deals is: {0}. This is insufficient for email model creation", dealsList.Count()));
                    }
                }

                var location    = Users.Dal.DataModel.Location.Parse(dailyDealsModelData.LocationId);
                var locationStr = string.Empty;
                if (location.Type == LocationType.Postal || location.Type == LocationType.City)
                {
                    Log.Info("Getting Location for user: {0}, locationId: {1}", dailyDealsModelData.EmailAddress, dailyDealsModelData.LocationId);
                    var geoCodePoint = GeoSpatial.GetGeoData(WebUtility.HtmlEncode(string.Format("{0} {1} {2}", location.CountryCode, location.AdminDistrict, location.Value)), GeoSpatial.GeoSource.VirtualEarth);
                    if (geoCodePoint != null && geoCodePoint.Location != null)
                    {
                        locationStr = geoCodePoint.Location.Locality;
                        Log.Info("Retrieved Location info : {0} for user: {1}, locationId: {2}", locationStr, dailyDealsModelData.EmailAddress, dailyDealsModelData.LocationId);
                    }
                    else
                    {
                        Log.Warn("Couldn't fetch location data for user: {0}, locationId: {1}", dailyDealsModelData.EmailAddress, location);
                    }
                }

                dailyDealsContract = new DailyDealsContract {
                    UnsubscribeUrl = dailyDealsModelData.UnsubscribeUrl, Deals = dealsContract, Location = locationStr
                };
            }

            return(dailyDealsContract);
        }