Beispiel #1
0
        /// <summary>
        /// Gets called when a download is done. Does not necessarily indicate an error
        /// unless the NSError parameter is not null.
        /// </summary>
        /// <param name="session">NSUrl Session.</param>
        /// <param name="task">Session Task.</param>
        /// <param name="error">Error received.</param>
        public override void DidCompleteWithError(NSUrlSession session, NSUrlSessionTask task, NSError error)
        {
            if (error == null)
            {
                AppSettings.CurrentSettings.MmpkDownloadDate = DateTime.Now;

                // Save user settings
                Task.Run(() => AppSettings.SaveSettings(Path.Combine(DownloadViewModel.GetDataFolder(), "AppSettings.xml")));
                return;
            }

            // If error indeed occured, cancel the task
            task.Cancel();
        }
        /// <summary>
        /// Overrides the behavior of the application when it has entered background mode
        /// </summary>
        /// <param name="application">Main Application.</param>
        public override async void DidEnterBackground(UIApplication application)
        {
            // Begin Finite-Length Task.
            this.taskID = UIApplication.SharedApplication.BeginBackgroundTask(null);

            // Start saving the user choices.
            await Task.Run(() => AppSettings.SaveSettings(Path.Combine(DownloadViewModel.GetDataFolder(), "AppSettings.xml")));

            // End Finite-Length Task, finished.
            if (this.taskID != -1)
            {
                UIApplication.SharedApplication.EndBackgroundTask(this.taskID);
                this.taskID = -1;
            }
        }
Beispiel #3
0
        /// <summary>
        /// Overrides the behavior of the application when it has entered background mode
        /// </summary>
        /// <param name="application">Main Application.</param>
        public override void DidEnterBackground(UIApplication application)
        {
            // Begin Finite-Length Task.
            _taskId = UIApplication.SharedApplication.BeginBackgroundTask(null);

            // Start saving the user choices.
            Task.Run(() => {
                try
                {
                    AppSettings.LocalizedCurrentLocationString = "CurrentLocationLabel".Localize();
                    AppSettings.SaveSettings(Path.Combine(DownloadViewModel.GetDataFolder(), "AppSettings.xml"));
                    UIApplication.SharedApplication.EndBackgroundTask(_taskId);
                }
                catch (Exception ex)
                {
                    ErrorLogger.Instance.LogException(ex);
                }
            });
        }
Beispiel #4
0
        /// <summary>
        /// Gets called when the download has been completed.
        /// </summary>
        /// <param name="session">NSUrl Session.</param>
        /// <param name="downloadTask">Download task.</param>
        /// <param name="location">NSUrl Location.</param>
        public override void DidFinishDownloading(NSUrlSession session, NSUrlSessionDownloadTask downloadTask, NSUrl location)
        {
            // The download location is the location of the file
            var sourceFile = location.Path;

            // Copy over to documents folder. Note that we must use NSFileManager here! File.Copy() will not be able to access the source location.
            var fileManager = NSFileManager.DefaultManager;

            // Remove any existing files in our destination
            NSError error;

            fileManager.Remove(Path.Combine(DownloadViewModel.GetDataFolder(), AppSettings.CurrentSettings.PortalItemName), out error);
            var success = fileManager.Copy(sourceFile, Path.Combine(DownloadViewModel.GetDataFolder(), AppSettings.CurrentSettings.PortalItemName), out error);

            if (!success)
            {
                Console.WriteLine("Error during the copy: {0}", error.LocalizedDescription);
            }

            this.InvokeOnMainThread(() => this.controller.LoadMapView());
        }
        /// <summary>
        /// Sets the home location for the user and saves it into settings.
        /// </summary>
        /// <param name="locationText">Location text.</param>
        /// <returns>Async task</returns>
        private async void SetHomeLocationAsync(string locationText)
        {
            try
            {
                GeocodeResult homeLocation = await _viewModel.GetSearchedLocationAsync(locationText);

                Feature homeFeature = await _viewModel.GetRoomFeatureAsync(locationText);

                if (homeFeature != null)
                {
                    AppSettings.CurrentSettings.HomeCoordinates = new[]
                    {
                        new SerializableKeyValuePair <string, double>("X", homeLocation.DisplayLocation.X),
                        new SerializableKeyValuePair <string, double>("Y", homeLocation.DisplayLocation.Y),
                        new SerializableKeyValuePair <string, double>("WKID", homeLocation.DisplayLocation.SpatialReference.Wkid)
                    };
                    AppSettings.CurrentSettings.HomeFloorLevel = homeFeature
                                                                 .Attributes[AppSettings.CurrentSettings.RoomsLayerFloorColumnName].ToString();
                    AppSettings.CurrentSettings.HomeLocation = locationText;
                }
                else
                {
                    AppSettings.CurrentSettings.HomeCoordinates = null;
                    AppSettings.CurrentSettings.HomeFloorLevel  = null;
                    AppSettings.CurrentSettings.HomeLocation    = null;
                }

                await Task.Run(() =>
                               AppSettings.SaveSettings(Path.Combine(DownloadViewModel.GetDataFolder(), "AppSettings.xml")));

                _viewModel.UpdateHomeLocation();
            }
            catch (Exception ex)
            {
                ErrorLogger.Instance.LogException(ex);
            }

            NavigationController.PopViewController(true);
        }
Beispiel #6
0
 /// <summary>
 /// Handles when user toggles the Current Location switch on/off
 /// </summary>
 /// <param name="sender">Sender control.</param>
 partial void CurrentLocationSwitchValueChanged(UISwitch sender)
 {
     AppSettings.CurrentSettings.IsLocationServicesEnabled = ((UISwitch)sender).On;
     Task.Run(() => AppSettings.SaveSettings(Path.Combine(DownloadViewModel.GetDataFolder(), "AppSettings.xml")));
 }