public static OfferClass generateOfferClass(string issuerId, string classId)
        {
            IList<RenderSpec> renderSpec = new List<RenderSpec>();

              RenderSpec listRenderSpec = new RenderSpec();
              listRenderSpec.ViewName = "g_list";
              listRenderSpec.TemplateFamily = "1.offer1_list";

              RenderSpec expandedRenderSpec = new RenderSpec();
              expandedRenderSpec.ViewName = "g_expanded";
              expandedRenderSpec.TemplateFamily = "1.offer1_expanded";

              renderSpec.Add(listRenderSpec);
              renderSpec.Add(expandedRenderSpec);

              IList<LatLongPoint> locations = new List<LatLongPoint>();

              LatLongPoint llp1 = new LatLongPoint();
              llp1.Latitude = 37.442087;
              llp1.Longitude = -122.161446;

              LatLongPoint llp2 = new LatLongPoint();
              llp2.Latitude = 37.429379;
              llp2.Longitude = -122.122730;

              LatLongPoint llp3 = new LatLongPoint();
              llp3.Latitude = 37.333646;
              llp3.Longitude = -121.884853;

              locations.Add(llp1);
              locations.Add(llp2);
              locations.Add(llp3);

              OfferClass wobClass = new OfferClass();
              wobClass.Id = issuerId + "." + classId;
              wobClass.Version = "1";
              wobClass.IssuerName = "Baconrista Coffee";
              wobClass.Title = "20% off one cup of coffee";
              wobClass.Provider = "Baconrista Deals";
              wobClass.Details = "20% off one cup of coffee at all Baconristas";

              Uri homepageUri = new Uri();
              homepageUri.UriValue = "http://baconrista.com/";
              homepageUri.Description = "Website";
              wobClass.HomepageUri = homepageUri;

              Uri imageUri = new Uri();
              imageUri.UriValue = "http://3.bp.blogspot.com/-AvC1agljv9Y/TirbDXOBIPI/AAAAAAAACK0/hR2gs5h2H6A/s1600/Bacon%2BWallpaper.png";
              Image titleImage = new Image();
              titleImage.SourceUri = imageUri;
              wobClass.TitleImage = titleImage;

              wobClass.RenderSpecs = renderSpec;
              wobClass.RedemptionChannel = "both";
              wobClass.ReviewStatus = "underReview";
              wobClass.Locations = locations;
              wobClass.AllowMultipleUsersPerObject = true;

              return wobClass;
        }
Ejemplo n.º 2
0
        private static void GetRainMeasurements()
        {
            var timeBetweenMeasurements = new TimeSpan(0, 0, 1, 0);
            var publicDataService       = new PublicDataService(_authenticationToken);

            double latitute  = Convert.ToDouble(ConfigurationManager.AppSettings["Latitude"]);
            double longitude = Convert.ToDouble(ConfigurationManager.AppSettings["Longitude"]);

            var             center  = new LatLongPoint(latitute, longitude);
            LocationBoundry boundry = LocationBoundry.ComputeBoundry(center);

            Console.WriteLine("Count\tWith gauge\tWith Rain\tAverage\tMin\tMax\t");
            do
            {
                // Get the public data
                PublicData publicData = publicDataService.Get(boundry);

                // The total number of stations returned in the geographic area.
                int totalNumberOfStations = publicData.Stations.Count();

                // The stations that have a rain gauge.
                var rainStations = GetStationsWithRainSensors(publicData);
                int numberOfStationsWithRainGauge = rainStations.Count();

                // Stations where the rain gauge is reporting a level above the threshold.
                var stationsWithRain = rainStations.Where(x => x.Value > RainingThreshold).ToList();

                ShowComputedStatistics(totalNumberOfStations, numberOfStationsWithRainGauge, stationsWithRain);

                WaitForNextMeasurementTime(timeBetweenMeasurements);
            } while (!CancellationToken.IsCancellationRequested);
        }
Ejemplo n.º 3
0
 private void ShowStationInfo(List <PublicDataStation> stations, LatLongPoint center)
 {
     foreach (PublicDataStation station in stations)
     {
         ShowStationDistances(station, center);
     }
 }
Ejemplo n.º 4
0
        private void ShowStationDistances(PublicDataStation station, LatLongPoint center)
        {
            Distance distance = station.ComputeDistanceAway(center);

            string message = string.Format("Station: {0} is {1} away", station, distance);

            Trace.WriteLine(message);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Compute distance between two points.
        /// </summary>
        /// <param name="point2"></param>
        /// <param name="point1"></param>
        /// <see cref="https://msdn.microsoft.com/en-us/library/system.device.location.geocoordinate.aspx"/>
        /// <returns></returns>
        public static Distance ComputeDistance(LatLongPoint point1, LatLongPoint point2)
        {
            var p1 = new GeoCoordinate(point1.Latitude, point1.Longitude);
            var p2 = new GeoCoordinate(point2.Latitude, point2.Longitude);

            var distanceMeters = p1.GetDistanceTo(p2);

            return(new Distance {
                Value = distanceMeters, Unit = DistanceUnit.Meters
            });
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Compute a square around the center point.
        /// </summary>
        /// <param name="center"></param>
        /// <returns></returns>
        public static LocationBoundry ComputeBoundry(LatLongPoint center)
        {
            var boundry = new LocationBoundry
            {
                // Hack to create a box of "fixed" size around the center point.
                NorthEast = new LatLongPoint(center.Latitude + 0.35D, center.Longitude + 0.7),
                SouthWest = new LatLongPoint(center.Latitude - 0.35D, center.Longitude - 0.7),
            };

            return(boundry);
        }
Ejemplo n.º 7
0
        private static LocationBoundry GetLocationBoundry()
        {
            double latitute  = Convert.ToDouble(ConfigurationManager.AppSettings["Latitude"]);
            double longitude = Convert.ToDouble(ConfigurationManager.AppSettings["Longitude"]);

            _center = new LatLongPoint(latitute, longitude);

            // Generate a boundry 2km around the center point.
            LocationBoundry boundry = LocationBoundry.ComputeBoundry(_center, 20);

            return(boundry);
        }
Ejemplo n.º 8
0
        public CountryGeoModel Create(JObject jObject)
        {
            var innerbody = JObject.FromObject(JArray.FromObject(jObject.GetValue("features")).First);
            var type      = JObject.FromObject(innerbody.GetValue("geometry")).GetValue("type").ToString();
            var country   = JObject.FromObject(innerbody.GetValue("properties")).GetValue("cca2").ToString();
            var polygons  = new List <Polygon <LatLongPoint> >();

            if (type.Equals("Polygon"))
            {
                var coordinateArray = JArray.FromObject(JArray
                                                        .FromObject(JObject.FromObject(innerbody.GetValue("geometry")).GetValue("coordinates")).First);

                var coordinateList = new List <LatLongPoint>();
                foreach (var coordinates in coordinateArray)
                {
                    var newPoint = new LatLongPoint
                    {
                        X = float.Parse(coordinates.Last.ToString()), //Longitude is always X in other systems
                        Y = float.Parse(coordinates.First.ToString()) //Latitude is always Y in other systems
                    };
                    coordinateList.Add(newPoint);
                }
                polygons.Add(new Polygon <LatLongPoint>(coordinateList));
            }
            else
            {
                var coordinateArray = JArray.FromObject(JArray
                                                        .FromObject(JObject.FromObject(innerbody.GetValue("geometry")).GetValue("coordinates")));
                foreach (var jToken in coordinateArray)
                {
                    var coordinateList = new List <LatLongPoint>();
                    foreach (var coordinates in jToken.First)
                    {
                        var newPoint = new LatLongPoint
                        {
                            X = float.Parse(coordinates.Last.ToString()), //Longitude is always X in other systems
                            Y = float.Parse(coordinates.First.ToString()) //Latitude is always Y in other systems
                        };
                        coordinateList.Add(newPoint);
                    }
                    polygons.Add(new Polygon <LatLongPoint>(coordinateList));
                }
            }

            return(new CountryGeoModel
            {
                CountryName = country,
                Polygons = polygons
            });
        }
Ejemplo n.º 9
0
        [TestCase(49.281974, -123.117857)] // Vancouver, BC, Canada
        public void DifferentLocations(double latitute, double longitude)
        {
            // Arrange
            var publicDataService = new PublicDataService(_authenticationToken, new HttpWrapper());

            var             center  = new LatLongPoint(latitute, longitude);
            LocationBoundry boundry = LocationBoundry.ComputeBoundry(center, 10);

            // Act
            PublicData publicData = publicDataService.Get(boundry).Result;

            // Assert
            Assert.IsNotNull(publicData);

            ShowStationInfo(publicData.Stations, center);
            ShowRainInfo(publicData);
        }
Ejemplo n.º 10
0
        /// <summary>
        /// Compute distance between two points. From http://www.geodatasource.com/developers/c-sharp
        /// </summary>
        /// <param name="point2"></param>
        /// <param name="unit"></param>
        /// <param name="point1"></param>
        /// <returns></returns>
        public static Distance ComputeDistance(LatLongPoint point1, LatLongPoint point2, DistanceUnit unit)
        {
            double theta = point1.Longitude - point1.Longitude;

            double distanceRadians = Math.Sin(DegreesToRadians(point1.Latitude)) *
                                     Math.Sin(DegreesToRadians(point2.Latitude)) +
                                     Math.Cos(DegreesToRadians(point1.Latitude)) *
                                     Math.Cos(DegreesToRadians(point2.Latitude)) *
                                     Math.Cos(DegreesToRadians(theta));

            distanceRadians = Math.Acos(distanceRadians);

            var distanceDegrees = RadiansToDegrees(distanceRadians);

            distanceDegrees = distanceDegrees * 60 * 1.1515;

            return(CreateDistanceByUnit(unit, distanceDegrees));
        }
Ejemplo n.º 11
0
        public void GetPublicData()
        {
            // Arrange
            var publicDataService = new PublicDataService(_authenticationToken, new HttpWrapper());

            // home
            double latitute  = Convert.ToDouble(ConfigurationManager.AppSettings["Latitude"]);
            double longitude = Convert.ToDouble(ConfigurationManager.AppSettings["Longitude"]);

            var             center  = new LatLongPoint(latitute, longitude);
            LocationBoundry boundry = LocationBoundry.ComputeBoundry(center, 10);

            // Act
            PublicData publicData = publicDataService.Get(boundry).Result;

            // Assert
            Assert.IsNotNull(publicData);

            ShowStationInfo(publicData.Stations, center);

            ShowRainInfo(publicData);
        }
Ejemplo n.º 12
0
        public void GetPublicData()
        {
            // Arrange
            var publicDataService = new PublicDataService(_authenticationToken);

            double latitute  = Convert.ToDouble(ConfigurationManager.AppSettings["Latitude"]);
            double longitude = Convert.ToDouble(ConfigurationManager.AppSettings["Longitude"]);

            var             center  = new LatLongPoint(latitute, longitude);
            LocationBoundry boundry = LocationBoundry.ComputeBoundry(center);

            // Act
            PublicData publicData = publicDataService.Get(boundry);

            // Assert
            Assert.IsNotNull(publicData);


            IList <SensorMeasurement> rainStations = new List <SensorMeasurement>();

            foreach (var station in publicData.Stations)
            {
                var rainMeasurement = station.Measurements.FirstOrDefault(y => y is RainMeasurement);
                if (rainMeasurement != null)
                {
                    rainStations.Add(rainMeasurement);
                }
            }

            Trace.WriteLine("All Stations: ");
            ShowComputedStatistics(rainStations);

            Trace.WriteLine("Stations with Rain: ");
            var stationsWithRain = rainStations.Where(x => x.Value > 0.1M).ToList();

            ShowComputedStatistics(stationsWithRain);
        }
        /// <summary>
        /// Generates a Loyalty Class
        /// </summary>
        /// <param name="issuerId"> </param>
        /// <param name="classId"> </param>
        /// <returns> loyaltyClass </returns>
        public static LoyaltyClass generateLoyaltyClass(string issuerId, string classId)
        {
            // Define general messages
            IList<WalletObjectMessage> messages = new List<WalletObjectMessage>();
            WalletObjectMessage message = new WalletObjectMessage();
            message.Header = "Welcome";
            message.Body = "Welcome to Banconrista Rewards!";

            Uri imageUri = new Uri();
            imageUri.UriValue = "https://ssl.gstatic.com/codesite/ph/images/search-48.gif";
            Image messageImage = new Image();
            messageImage.SourceUri = imageUri;
            message.Image = messageImage;

            Uri actionUri = new Uri();
            actionUri.UriValue = "http://baconrista.com";
            message.ActionUri = actionUri;

            messages.Add(message);

            // Define rendering templates per view
            IList<RenderSpec> renderSpec = new List<RenderSpec>();

            RenderSpec listRenderSpec = new RenderSpec();
            listRenderSpec.ViewName = "g_list";
            listRenderSpec.TemplateFamily = "1.loyaltyCard1_list";

            RenderSpec expandedRenderSpec = new RenderSpec();
            expandedRenderSpec.ViewName = "g_expanded";
            expandedRenderSpec.TemplateFamily = "1.loyaltyCard1_expanded";

            renderSpec.Add(listRenderSpec);
            renderSpec.Add(expandedRenderSpec);

            // Define Geofence locations
            IList<LatLongPoint> locations = new List<LatLongPoint>();

            LatLongPoint llp1 = new LatLongPoint();
            llp1.Latitude = 37.422601;
            llp1.Longitude = -122.085286;

            LatLongPoint llp2 = new LatLongPoint();
            llp2.Latitude = 37.429379;
            llp2.Longitude = -122.122730;

            locations.Add(llp1);
            locations.Add(llp2);

            // Create class
            LoyaltyClass wobClass = new LoyaltyClass();
            wobClass.Id = issuerId + "." + classId;
            wobClass.Version = "1";
            wobClass.IssuerName = "Baconrista";
            wobClass.ProgramName = "Baconrista Rewards";

            Uri homepageUri = new Uri();
            homepageUri.UriValue = "https://www.example.com";
            homepageUri.Description = "Website";
            wobClass.HomepageUri = homepageUri;

            Uri logoImageUri = new Uri();
            logoImageUri.UriValue = "http://www.google.com/landing/chrome/ugc/chrome-icon.jpg";
            Image logoImage = new Image();
            logoImage.SourceUri = logoImageUri;
            wobClass.ProgramLogo = logoImage;

            wobClass.RewardsTierLabel= "Tier";
            wobClass.RewardsTier = "Gold";
            wobClass.AccountNameLabel = "Member Name";
            wobClass.AccountIdLabel = "Member Id";
            wobClass.RenderSpecs = renderSpec;
            wobClass.Messages = messages;
            wobClass.ReviewStatus = "underReview";
            wobClass.AllowMultipleUsersPerObject = true;
            wobClass.Locations = locations;

            return wobClass;
        }