Пример #1
0
        /*
         * When the application is suspending we save the current room name, so
         * we can come back to it in case of "tombstoning".
         */
        private void App_Suspending(object sender, SuspendingEventArgs e)
        {
            ApplicationDataContainer Appsettings = ApplicationData.Current.LocalSettings;

            Appsettings.Values["CurrentPage"] = _currentRoom.Title;
            Appsettings.Values["TimeStamp"]   = DateTime.Now.Hour;
            ErrorMessage.DisplayErrorDialog("Suspending" + _currentRoom.Title);
        }
Пример #2
0
        /*
         * Request access for the background task, before conducting business.
         */
        private async void RequestBackgroundAccess()
        {
            var result = await BackgroundExecutionManager.RequestAccessAsync();

            if (result == BackgroundAccessStatus.Denied)
            {
                //TODO
                ErrorMessage.DisplayErrorDialog("Cannot Sense Room");
            }
        }
Пример #3
0
        /*
         * Navigates to createsurfaces page if an existing room is found, otherwise it shows
         * and error prompt.
         */
        private void ExistingRoom_Click(object sender, Windows.UI.Xaml.RoutedEventArgs e)
        {
            var name = RoomNameBox.Text;

            Room room = DatabaseRepository.GetRoom(name);

            if (room != null)
            {
                Frame.Navigate(typeof(CreateSurfacesPage), room);
            }
            else
            {
                ErrorMessage.DisplayErrorDialog("Room not found.");
            }
        }
        /*
         * Gets the users location when creating the room, the method has switch-cases depending on the
         * access status. if we are allowed to use the position we create an instance of geolocator and locate
         * the "rooms" position. Otherwise we use a default location value {0,0}
         */
        public async void GetRoomLocation()
        {
            var accessStatus = await Geolocator.RequestAccessAsync();

            try
            {
                switch (accessStatus)
                {
                case GeolocationAccessStatus.Allowed:

                    Geolocator geolocator = new Geolocator {
                        DesiredAccuracyInMeters = 50
                    };

                    // Subscribe to the PositionChanged event to get location updates.
                    geolocator.PositionChanged += OnPositionChanged;
                    var position = await geolocator.GetGeopositionAsync();

                    var myposition = position.Coordinate.Point;

                    LatiValue.Text  = myposition.Position.Latitude.ToString();
                    LongtValue.Text = myposition.Position.Longitude.ToString();
                    break;

                case GeolocationAccessStatus.Denied:
                    ErrorMessage.DisplayErrorDialog("Location access denied");
                    LatiValue.Text  = "0.0";
                    LongtValue.Text = "0.0";
                    break;

                case GeolocationAccessStatus.Unspecified:
                    ErrorMessage.DisplayErrorDialog("Some kind of error occured, please try again!");
                    LatiValue.Text  = "0.0";
                    LongtValue.Text = "0.0";
                    break;
                }
            }
            catch (Exception)
            {
                LatiValue.Text  = "0.0";
                LongtValue.Text = "0.0";
            }
        }
        /*
         * Here is the interesting part for creating new rooms. We start of by checking if we
         * have gotten our location values, If we have then we continue on to check the input
         * values and try to create the room. We get an status message back from the database
         * if successful or else not (null).
         */
        private void CreateBtn_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                // Get position values.
                double lat   = double.Parse(LatiValue.Text);
                double longt = double.Parse(LongtValue.Text);
            }
            catch
            {
                // Do nothing if incorrect position values!
                return;
            }
            // Check if title already exists!
            if (!IsTitleAllowed(Title.Text))
            {
                ErrorMessage.DisplayErrorDialog("Please, check yo title again!");
                return;
            }
            // If is empty
            if (Description.Text == "")
            {
                ErrorMessage.DisplayErrorDialog("Please, check yo description again!");
                return;
            }
            // Creates the room if it doesn't exist
            var room = DatabaseRepository.CreateRoom(Title.Text, Description.Text,
                                                     0.0, double.Parse(LatiValue.Text), double.Parse(LongtValue.Text));

            // Navigate to next page if successful
            if (room != null)
            {
                Frame.Navigate(typeof(CreateSurfacesPage), room);
            }
            else
            {
                ErrorMessage.DisplayErrorDialog("Error, room probably already exists!");
            }
        }