Example #1
0
 /// <summary>
 /// Creates a <see cref="BasicGeoposition"/> from <see cref="windows.Devices.Geolocation.BasicGeoposition"/>.
 /// </summary>
 /// <param name="args">The <see cref="windows.Devices.Geolocation.BasicGeoposition"/> instance containing the event data.</param>
 /// <returns><see cref="BasicGeoposition"/></returns>
 public static BasicGeoposition FromBasicGeoposition(windows.Devices.Geolocation.BasicGeoposition args)
 {
     return(new BasicGeoposition()
     {
         Latitude = args.Latitude, Longitude = args.Longitude, Altitude = args.Altitude
     });
 }
        private async void myMap_Loaded(object sender, RoutedEventArgs e)
        {
            if (myMap.Layers.Count == 0)
            {
                // Specify a known location.
                var cityPosition = new windows.Devices.Geolocation.BasicGeoposition()
                {
                    Latitude  = 47.604,
                    Longitude = -122.329
                };
                var cityCenter = new windows.Devices.Geolocation.Geopoint(cityPosition);
                var icon       = new windows.UI.Xaml.Controls.Maps.MapIcon()
                {
                    Location = cityCenter,
                };

                var elements = new System.Collections.Generic.List <windows.UI.Xaml.Controls.Maps.MapElement>()
                {
                    icon,
                };
                var layer = new windows.UI.Xaml.Controls.Maps.MapElementsLayer()
                {
                    ZIndex      = 1,
                    MapElements = elements,
                };
                myMap.Layers.Add(layer);

                // Set the map location.
                await myMap.TrySetViewAsync(cityCenter, 12).ConfigureAwait(false);
            }
        }
Example #3
0
        private void CreateDevicesForBulkRegistration()
        {
            List <BasicGeoposition> coordinates = Item.Project.Coordinates;

            BasicGeoposition centroid  = GeopositionHandler.GetPolygonCentroid(coordinates);
            BasicGeoposition northwest = GeopositionHandler.GetNorthWestPosition(coordinates, centroid);
            BasicGeoposition southeast = GeopositionHandler.GetSouthEastPosition(coordinates, centroid);

            var projectName = Item.Project.Name.Substring(0, 3).ToUpper(CultureInfo.InvariantCulture);
            var length      = 16;

            Item.Devices.Clear();

            for (int i = 0; i < Item.NMessages; i++)
            {
                var now = DateTime.Now;

                var datetime = now.Ticks.ToString(CultureInfo.InvariantCulture);
                var deviceID = projectName + i + datetime.Substring(datetime.Length - length, length);

                Windows.Devices.Geolocation.BasicGeoposition devicePosition = new Windows.Devices.Geolocation.BasicGeoposition()
                {
                    Latitude  = MathHandler.GetRandomNumber(southeast.Latitude, northwest.Latitude),
                    Longitude = MathHandler.GetRandomNumber(northwest.Longitude, southeast.Longitude),
                };

                Item.Devices.Add(new Device(deviceID, devicePosition));
            }
        }
        public Geopoint(BasicGeoposition basicGeoposition)
        {
            this.basicGeoposition = new Windows.Devices.Geolocation.BasicGeoposition()
            {
                Latitude  = basicGeoposition.Latitude,
                Longitude = basicGeoposition.Longitude,
                Altitude  = basicGeoposition.Altitude
            };

            UwpInstance = new Windows.Devices.Geolocation.Geopoint(this.basicGeoposition);
        }
Example #5
0
        public void AddDeviceButNoListings(string deviceID, string deviceName, Windows.Devices.Geolocation.BasicGeoposition position)
        {
            if (Devices.Exists(e => e.DeviceID.Equals(deviceID)))
            {
                return;
            }

            Windows.Devices.Geolocation.BasicGeoposition snPosition = new Windows.Devices.Geolocation.BasicGeoposition {
                Latitude = position.Latitude, Longitude = position.Longitude
            };

            Devices.Insert(0, new Device {
                DeviceID = deviceID, DeviceName = deviceName, DevicePosition = snPosition, Latitude = snPosition.Latitude, Longitude = snPosition.Longitude
            });
        }
        /// <summary>
        /// Sets when this item is relevant.
        /// When an item is considered relevant, it will be promoted to the top spot in the Wallet summary view list
        /// and a toast notifcation will also be shown in a pop-up on the user's phone.
        /// </summary>
        /// <returns>An asynchronous action.</returns>
        public async Task AddRelevancyAsync()
        {
            if (walletItem == null)
            {
                rootPage.NotifyUser("Item does not exist. Add item using Scenario2", NotifyType.ErrorMessage);
                return;
            }

            try
            {
                // For this example, we will clear all relevancy data from the wallet item
                // to ensure that adding the item below does not fail because it already exists.
                walletItem.RelevantLocations.Clear();

                // Create a new relevant location object.
                WalletRelevantLocation location = new WalletRelevantLocation();
                location.DisplayMessage = "Welcome to Contoso Coffee on 5th";

                // Set the desired location.
                var position = new Windows.Devices.Geolocation.BasicGeoposition();
                position.Latitude  = 47.63;
                position.Longitude = -122.2147;
                location.Position  = position;

                // Add this location to the RelevantLocations collection on the item.
                // Note: The key for each entry must be unique in the collection.
                walletItem.RelevantLocations.Add("5thId", location);

                // Add a relevant date.
                walletItem.RelevantDate = DateTime.Now;
                walletItem.RelevantDateDisplayMessage = "Free coffee day";

                // Update the item in Wallet.
                await wallet.UpdateAsync(walletItem);

                rootPage.NotifyUser("Relevancy data added. Open Wallet to see this card promoted to the top of the list because it is relevant (relevant date was defined as today).", NotifyType.StatusMessage);
            }
            catch (Exception ex)
            {
                string errorMessage = String.Format("Could not add relevancy data. {0}", ex.Message);
                rootPage.NotifyUser(errorMessage, NotifyType.ErrorMessage);
            }
        }
        /// <summary>
        /// Sets when this item is relevant.
        /// When an item is considered relevant, it will be promoted to the top spot in the Wallet summary view list
        /// and a toast notifcation will also be shown in a pop-up on the user's phone. 
        /// </summary>
        /// <returns>An asynchronous action.</returns>
        public async Task AddRelevancyAsync()
        {
            if (walletItem == null)
            {
                rootPage.NotifyUser("Item does not exist. Add item using Scenario2", NotifyType.ErrorMessage);
                return;
            }

            try
            {
                // For this example, we will clear all relevancy data from the wallet item 
                // to ensure that adding the item below does not fail because it already exists.
                walletItem.RelevantLocations.Clear();

                // Create a new relevant location object.
                WalletRelevantLocation location = new WalletRelevantLocation();
                location.DisplayMessage = "Welcome to Contoso Coffee on 5th";

                // Set the desired location.
                var position = new Windows.Devices.Geolocation.BasicGeoposition();
                position.Latitude = 47.63;
                position.Longitude = -122.2147;
                location.Position = position;

                // Add this location to the RelevantLocations collection on the item.
                // Note: The key for each entry must be unique in the collection. 
                walletItem.RelevantLocations.Add("5thId", location);

                // Add a relevant date.
                walletItem.RelevantDate = DateTime.Now;
                walletItem.RelevantDateDisplayMessage = "Free coffee day";

                // Update the item in Wallet.
                await wallet.UpdateAsync(walletItem);
                rootPage.NotifyUser("Relevancy data added. Open Wallet to see this card promoted to the top of the list because it is relevant (relevant date was defined as today).", NotifyType.StatusMessage);
            }
            catch (Exception ex)
            {
                string errorMessage = String.Format("Could not add relevancy data. {0}", ex.Message);
                rootPage.NotifyUser(errorMessage, NotifyType.ErrorMessage);
            }

        }
Example #8
0
        pkPassConversionResult parsePkpassType(IReadOnlyList<Windows.Storage.StorageFile> files)
        {
            try
            {
                WalletItem item = null;
                CurrentInfo = "Opening pass.json...";
                JObject o = getJsonData(files.Where(x => x.Name == "pass.json").First());
                //Determine the type of the card and return it.
                if (o["boardingPass"] != null)
                {
                    pkPassType = "boardingPass";
                    item = new WalletItem(WalletItemKind.BoardingPass, o["description"].Value<string>());
                }
                else if (o["coupon"] != null)
                {
                    pkPassType = "coupon";
                    item = new WalletItem(WalletItemKind.Deal, o["description"].Value<string>());
                }
                else if (o["eventTicket"] != null)
                {
                    pkPassType = "eventTicket";
                    item = new WalletItem(WalletItemKind.Ticket, o["description"].Value<string>());
                }
                else if (o["storeCard"] != null)
                {
                    pkPassType = "storeCard";
                    item = new WalletItem(WalletItemKind.MembershipCard, o["description"].Value<string>());
                }
                else if (o["generic"] != null)
                {
                    pkPassType = "generic";
                    item = new WalletItem(WalletItemKind.General, o["description"].Value<string>());
                }
                else throw new Exception();

                //Get images
                CurrentInfo = "Fetching images...";
                item.Logo99x99 = item.Logo159x159 = item.Logo336x336 = getImageFromName("icon.png", contents);
                item.HeaderBackgroundImage = getImageFromName("logo.png", contents);
                item.BodyBackgroundImage = getImageFromName("background.png", contents);

                CurrentInfo = "Fetching colors...";
                item.BodyColor = HelperMethods.getColorFromRGBString(o["backgroundColor"].Value<string>());
                item.BodyFontColor = HelperMethods.getColorFromRGBString(o["foregroundColor"].Value<string>());
                item.HeaderColor = item.BodyColor;
                item.HeaderFontColor = HelperMethods.getColorFromRGBString(o["labelColor"].Value<string>());

                int i = 0;
                if (o[pkPassType]["primaryFields"] != null)
                {
                    foreach (JObject jo in o[pkPassType]["primaryFields"])
                    {
                        WalletItemCustomProperty prop = new WalletItemCustomProperty(jo["label"].Value<string>(), jo["value"].Value<string>());
                        if (i == 0) prop.DetailViewPosition = WalletDetailViewPosition.PrimaryField1;
                        else if (i == 1) prop.DetailViewPosition = WalletDetailViewPosition.PrimaryField2;
                        else throw new InvalidDataException();
                        item.DisplayProperties[jo["key"].Value<string>()] = prop;
                        i++;
                    }
                }

                //Secondary fields
                i = 0;
                if (o[pkPassType]["secondaryFields"] != null)
                {
                    foreach (JObject jo in o[pkPassType]["secondaryFields"])
                    {
                        WalletItemCustomProperty prop = new WalletItemCustomProperty(jo["label"].Value<string>(), jo["value"].Value<string>());
                        if (i == 0) prop.DetailViewPosition = WalletDetailViewPosition.SecondaryField1;
                        else if (i == 1) prop.DetailViewPosition = WalletDetailViewPosition.SecondaryField2;
                        else if (i == 2) prop.DetailViewPosition = WalletDetailViewPosition.SecondaryField3;
                        else if (i == 3) prop.DetailViewPosition = WalletDetailViewPosition.SecondaryField4;
                        else if (i == 4) prop.DetailViewPosition = WalletDetailViewPosition.SecondaryField5;
                        else throw new InvalidDataException();
                        item.DisplayProperties[jo["key"].Value<string>()] = prop;
                        i++;
                    }
                }

                //Auxiliary fields
                i = 0;
                if (o[pkPassType]["auxiliaryFields"] != null)
                {
                    foreach (JObject jo in o[pkPassType]["auxiliaryFields"])
                    {
                        WalletItemCustomProperty prop = new WalletItemCustomProperty(jo["label"].Value<string>(), jo["value"].Value<string>());
                        if (i == 0) prop.DetailViewPosition = WalletDetailViewPosition.FooterField1;
                        else if (i == 1) prop.DetailViewPosition = WalletDetailViewPosition.FooterField2;
                        else if (i == 2) prop.DetailViewPosition = WalletDetailViewPosition.FooterField3;
                        else if (i == 3) prop.DetailViewPosition = WalletDetailViewPosition.FooterField4;
                        else throw new InvalidDataException();
                        item.DisplayProperties[jo["key"].Value<string>()] = prop;
                        i++;
                    }
                }

                //Header fields
                i = 0;
                if (o[pkPassType]["headerFields"] != null)
                {
                    foreach (JObject jo in o[pkPassType]["headerFields"])
                    {
                        WalletItemCustomProperty prop = new WalletItemCustomProperty(jo["label"].Value<string>(), jo["value"].Value<string>());
                        if (i == 0) prop.DetailViewPosition = WalletDetailViewPosition.HeaderField1;
                        else if (i == 1) prop.DetailViewPosition = WalletDetailViewPosition.HeaderField2;
                        else throw new InvalidDataException();
                        item.DisplayProperties[jo["key"].Value<string>()] = prop;
                        i++;
                    }
                }

                //Header fields
                if (o[pkPassType]["backFields"] != null)
                {
                    foreach (JObject jo in o[pkPassType]["backFields"])
                    {
                        WalletItemCustomProperty prop = new WalletItemCustomProperty(jo["label"].Value<string>(), jo["value"].Value<string>());
                        prop.SummaryViewPosition = WalletSummaryViewPosition.Hidden;
                        item.DisplayProperties[jo["key"].Value<string>()] = prop;
                    }
                }

                if (o["barcode"] != null)
                {
                    WalletBarcodeSymbology sym = new WalletBarcodeSymbology();
                    switch (o["barcode"]["format"].Value<string>())
                    {
                        case "PKBarcodeFormatQR": sym = WalletBarcodeSymbology.Qr; break;
                        case "PKBarcodeFormatPDF417": sym = WalletBarcodeSymbology.Pdf417; break;
                        case "PKBarcodeFormatAztec": sym = WalletBarcodeSymbology.Aztec; break;
                        default: throw new InvalidDataException();
                    }
                    item.Barcode = new WalletBarcode(sym, o["barcode"]["message"].Value<string>());
                }

                if (o["locations"] != null)
                {
                    i = 0;
                    foreach (JObject jo in o["locations"])
                    {
                        WalletRelevantLocation location = new WalletRelevantLocation();
                        if (jo["relevantText"] != null)
                        {
                            location.DisplayMessage = jo["relevantText"].Value<string>();
                        }
                        var position = new Windows.Devices.Geolocation.BasicGeoposition();
                        position.Latitude = jo["latitude"].Value<double>();
                        position.Longitude = jo["longitude"].Value<double>();
                        try
                        {
                            position.Altitude = jo["altitude"].Value<double>();
                        }
                        catch (Exception)
                        {
                            System.Diagnostics.Debug.WriteLine("An altitude does not exist for location " + location.DisplayMessage);
                        }
                        location.Position = position;
                        //Check one doesn't already exist.
                        if (item.RelevantLocations.Where(x => x.Key == i.ToString()).Count() > 0)
                            i++;
                        else
                            item.RelevantLocations.Add(i.ToString(), location);
                        i++;
                    }
                }

                if (o["relevantDate"] != null)
                {
                    item.RelevantDate = DateTime.Parse(o["relevantDate"].Value<string>());
                }

                if (o["expirationDate"] != null)
                {
                    item.ExpirationDate = DateTime.Parse(o["expirationDate"].Value<string>());
                }

                string cardId = o["serialNumber"].Value<string>();

                pkPassConversionResult result = new pkPassConversionResult();
                result.item = item; result.cardId = cardId;
                return result;
            }
            catch (Exception ex)
            {
                CurrentInfo = "Exception: " + ex.Message;
                return null;
            }
        }
Example #9
0
        private async void Timer_Tick(object sender, object e)
        {
            try
            {
                //emotion api calling
                float humidity    = BMP280.GetHumidity();
                float temperature = BMP280.GetTemperature();

                Scores scores = await client.RecognizeAsync(Person[PersonIndex]);

                HappyModel model = new HappyModel(Store[StoreIndex].StoreName, temperature, humidity,
                                                  Store[StoreIndex].Longitude.ToString(),
                                                  Store[StoreIndex].Latitude.ToString(),
                                                  scores);

                DisplayModel(model);

                //Image setting
                Image       img         = sender as Image;
                BitmapImage bitmapImage = new BitmapImage();
                bitmapImage.UriSource = new Uri(Person[PersonIndex]);

                imgPerson.Source = bitmapImage;


                //Map Setting
                Windows.Devices.Geolocation.BasicGeoposition geo = new Windows.Devices.Geolocation.BasicGeoposition();
                geo.Latitude  = Store[StoreIndex].Latitude;
                geo.Longitude = Store[StoreIndex].Longitude;

                Windows.UI.Xaml.Controls.Maps.MapIcon icon = new Windows.UI.Xaml.Controls.Maps.MapIcon();
                icon.Location = new Windows.Devices.Geolocation.Geopoint(geo);
                icon.NormalizedAnchorPoint = new Point(1, 1);
                icon.Title = Store[StoreIndex].StoreName;

                mapStoreLocation.MapElements.Clear();
                mapStoreLocation.MapElements.Add(icon);

                await mapStoreLocation.TrySetViewAsync(new Windows.Devices.Geolocation.Geopoint(geo), 18, 0, 0, Windows.UI.Xaml.Controls.Maps.MapAnimationKind.Bow);

                //IoTHubProxy data sending
                try
                {
                    IoTProxy.SendMessage(model);
                }
                catch (Exception ex)
                {
                    Debug.WriteLine("IoTHub======" + ex.Message);
                }

                PersonIndex++;
                StoreIndex++;


                //Init index
                if (PersonIndex == Person.Count() - 1)
                {
                    PersonIndex = 0;
                }
                if (StoreIndex == Store.Count() - 1)
                {
                    StoreIndex = 0;
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine("System======" + ex.Message);
            }
        }