Ejemplo n.º 1
0
 /// <summary>
 /// Populates the page with content passed during navigation.  Any saved state is also
 /// provided when recreating a page from a prior session.
 /// </summary>
 /// <param name="sender">
 /// The source of the event; typically <see cref="NavigationHelper"/>
 /// </param>
 /// <param name="e">Event data that provides both the navigation parameter passed to
 /// <see cref="Frame.Navigate(Type, Object)"/> when this page was initially requested and
 /// a dictionary of state preserved by this page during an earlier
 /// session.  The state will be null the first time a page is visited.</param>
 private void NavigationHelper_LoadState(object sender, LoadStateEventArgs e)
 {
     // About message
     string[] aboutInfo = CommonTaskClient.AboutInfo();
     this.DefaultViewModel["AppTitle"] = aboutInfo[0];
     this.DefaultViewModel["DetailInfo"] = aboutInfo[1]; 
 }
Ejemplo n.º 2
0
 /// <summary>
 /// Populates the page with content passed during navigation.  Any saved state is also
 /// provided when recreating a page from a prior session.
 /// </summary>
 /// <param name="sender">
 /// The source of the event; typically <see cref="NavigationHelper"/>
 /// </param>
 /// <param name="e">Event data that provides both the navigation parameter passed to
 /// <see cref="Frame.Navigate(Type, Object)"/> when this page was initially requested and
 /// a dictionary of state preserved by this page during an earlier
 /// session.  The state will be null the first time a page is visited.</param>
 private void NavigationHelper_LoadState(object sender, LoadStateEventArgs e)
 {
     PostCodeItem postCodeItem = (PostCodeItem)e.NavigationParameter;
     this.DefaultViewModel[PostCodeItemName] = postCodeItem;
 }
Ejemplo n.º 3
0
 /// <summary>
 /// Populates the page with content passed during navigation. Any saved state is also
 /// provided when recreating a page from a prior session.
 /// </summary>
 /// <param name="sender">
 /// The source of the event; typically <see cref="NavigationHelper"/>.
 /// </param>
 /// <param name="e">Event data that provides both the navigation parameter passed to
 /// <see cref="Frame.Navigate(Type, Object)"/> when this page was initially requested and
 /// a dictionary of state preserved by this page during an earlier
 /// session.  The state will be null the first time a page is visited.</param>
 private void NavigationHelper_LoadState(object sender, LoadStateEventArgs e)
 {
     // TODO: Create an appropriate data model for your problem domain to replace the sample data.
     _currentDistrict = (District)e.NavigationParameter;
     this.DefaultViewModel[DistrictDataName] = _currentDistrict;
 }
Ejemplo n.º 4
0
        /// <summary>
        /// Populates the page with content passed during navigation. Any saved state is also
        /// provided when recreating a page from a prior session.
        /// </summary>
        /// <param name="sender">
        /// The source of the event; typically <see cref="NavigationHelper"/>.
        /// </param>
        /// <param name="e">Event data that provides both the navigation parameter passed to
        /// <see cref="Frame.Navigate(Type, Object)"/> when this page was initially requested and
        /// a dictionary of state preserved by this page during an earlier
        /// session. The state will be null the first time a page is visited.</param>
        private async void NavigationHelper_LoadState(object sender, LoadStateEventArgs e)
        {
            if (ApplicationData.Current.LocalSettings.Values["Launched"] == null)
            {
                ApplicationData.Current.LocalSettings.Values["Launched"] = true;
                _isUpdateChecked = true;
                _isDownloading = true;
                ShowUpdateStatus("正在准备数据");
                UpdateProgress updateProgress = ChangeProgress;
                try
                {
                    await CommonTaskClient.Download(updateProgress);
                    await CommonTaskClient.UpdateFileVersion();
                }
                catch (HttpRequestException)
                {
                    ShowUpdateStatus("下载邮编数据失败");
                    _isDeletingFile = true;
                }
                if (_isDeletingFile)
                {
                    var folder = ApplicationData.Current.LocalFolder;
                    var file = await folder.GetFileAsync("DistrictData.json");
                    await file.DeleteAsync();
                    var backupFile = await StorageFile.GetFileFromApplicationUriAsync(new Uri("ms-appx:///DataModel/DistrictDataBackup.json"));
                    // var backupFile = await StorageFile.GetFileFromApplicationUriAsync(new Uri(@"ms-appx:///DataModel/DistrictData.json"));
                    backupFile.MoveAsync(folder, backupFile.DisplayName, NameCollisionOption.ReplaceExisting);
                }
            }
            // TODO: Create an appropriate data model for your problem domain to replace the sample data
            DistrictDataSource dataSource = DistrictDataSource.GetInstance();
            try
            {
                await dataSource.GetDistrictData();
                _defaultViewModel[DistrictDataSetName] = dataSource;
            }
            catch (FileNotFoundException)
            {
                ShowUpdateStatus("本地邮编数据库加载失败");
            }
            
            // Async check update
            _isUpdateChecked = (e.PageState == null || !e.PageState.ContainsKey("IsUpdateChecked")) ? _isUpdateChecked : (bool)e.PageState["IsUpdateChecked"];
            if (!_isUpdateChecked)
            {
                _isUpdateChecked = true;
                bool isCheckUpdateSucceed = true;

                ShowUpdateStatus("正在检查更新...");
                _statusBar.ProgressIndicator.ShowAsync();

                try
                {
                    bool isUpdateAvailable = await CommonTaskClient.IsUpdateAvailable();
                    await Task.Delay(500);
                    if (isUpdateAvailable)
                    {
                        ShowUpdateStatus("邮编数据库有新版本");  
                        MessageDialog updateAvalible = new MessageDialog("有可用的邮编数据库更新,要下载吗?", "提示");
                        updateAvalible.Commands.Add(new UICommand("开始下载", UpdateDialogCommanHander, 0));
                        updateAvalible.Commands.Add(new UICommand("以后再说", null, 1));
                        updateAvalible.DefaultCommandIndex = 0;
                        updateAvalible.CancelCommandIndex = 1;
                        await updateAvalible.ShowAsync();
                    }
                    else
                    {
                        ShowUpdateStatus("无可用更新");
                        _statusBar.ProgressIndicator.HideAsync();
                    }
                }
                catch (HttpRequestException)
                {
                    isCheckUpdateSucceed = false;
                }
                catch (WebException)
                {
                    isCheckUpdateSucceed = false;
                }
                if (!isCheckUpdateSucceed)
                {
                    ShowUpdateStatus("获取更新失败");
                    _statusBar.ProgressIndicator.HideAsync();
                }
                await Task.Delay(500);
                _defaultViewModel["UpdateStatus"] = "";
            }
        }