Пример #1
0
        private async void ShowUnauthorizedAccessError()
        {
            _errorOccurred = true;
            var dialog = new ContentDialog();

            dialog.Title = Resources.AuthorizationFileSystemContentDialogTitle;
            var markdown = new MarkdownTextBlock();

            markdown.Text  = Resources.AuthorizationFileSystemContentDialogDescription;
            dialog.Content = markdown;
            dialog.PrimaryButtonCommand = new DelegateCommand(async() =>
            {
                await Windows.System.Launcher.LaunchUriAsync(new Uri("ms-settings:privacy-broadfilesystemaccess"));
                Prism.PrismApplicationBase.Current.Exit();
            });
            dialog.PrimaryButtonText      = Resources.AuthorizationFileSystemContentDialogPrimaryBTN;
            dialog.PrimaryButtonStyle     = App.Current.Resources["AccentButtonStyle"] as Style;
            dialog.SecondaryButtonText    = Resources.AuthorizationFileSystemContentDialogSecondaryBTN;
            dialog.SecondaryButtonCommand = new DelegateCommand(() =>
            {
                Prism.PrismApplicationBase.Current.Exit();
            });
            var result = await DialogService.ShowAsync(dialog);

            if (result == ContentDialogResult.None)
            {
                Prism.PrismApplicationBase.Current.Exit();
            }
        }
        /// <summary>
        /// Fired when we should load the content.
        /// </summary>
        /// <param name="source"></param>
        public async void OnPrepareContent()
        {
            // Since some of this can be costly, delay the work load until we aren't animating.
            await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Low, () =>
            {
                m_markdownBlock = new MarkdownTextBlock();
                m_markdownBlock.OnMarkdownLinkTapped += MarkdownBlock_OnMarkdownLinkTapped;
                m_markdownBlock.OnMarkdownReady      += MarkdownBox_OnMarkdownReady;
                m_markdownBlock.Markdown              = m_base.Source.SelfText;
                m_markdownBlock.Foreground            = new SolidColorBrush(global::Windows.UI.Colors.Black);
                m_markdownBlock.FontSize              = 12;
                ui_contentRoot.Children.Add(m_markdownBlock);

                if (m_base.Source.post != null)
                {
                    votesText.Text     = m_base.Source.post.Score.ToString();
                    authorText.Text    = m_base.Source.post.Author;
                    subredditText.Text = m_base.Source.post.Subreddit;
                    titleText.Text     = m_base.Source.post.Title;
                    commentsText.Text  = m_base.Source.post.NumComments.ToString() + " comments";
                }

                m_context = m_base.Source.context;
            });
        }
Пример #3
0
        public async static void UnauthorizedAccessUseLocalFileDialog()
        {
            var dialog = new ContentDialog
            {
                Title = Strings.Resources.AuthorizationFileSystemContentDialogTitle
            };
            var markdown = new MarkdownTextBlock
            {
                Text = Strings.Resources.AuthorizationFileSystemContentDialogDescription
            };

            dialog.Content = markdown;
            dialog.PrimaryButtonCommand = new DelegateCommand(async() =>
            {
                await Windows.System.Launcher.LaunchUriAsync(new Uri("ms-settings:privacy-broadfilesystemaccess"));
                Prism.PrismApplicationBase.Current.Exit();
            });
            dialog.CloseButtonCommand = new DelegateCommand(() =>
            {
                dialog.Hide();
            });
            dialog.CloseButtonText    = Resources.ButtonTextCancel;
            dialog.PrimaryButtonText  = Strings.Resources.AuthorizationFileSystemContentDialogPrimaryBTN;
            dialog.PrimaryButtonStyle = App.Current.Resources["AccentButtonStyle"] as Style;
            //dialog.SecondaryButtonText = Strings.Resources.AuthorizationFileSystemContentDialogSecondaryBTN;
            //dialog.SecondaryButtonCommand = new DelegateCommand(() =>
            //{
            //    Prism.PrismApplicationBase.Current.Exit();
            //});
            var dialogService = App.Current.Container.Resolve <IDialogService>();
            await dialogService.ShowAsync(dialog);
        }
Пример #4
0
 private void InitEditableProperties()
 {
     EditableProperties = new List <EditableProperty>();
     foreach (var property in MarkdownTextBlock.GetType().GetProperties(BindingFlags.Instance | BindingFlags.Public).OrderBy(p => p.Name))
     {
         var propertyType = property.PropertyType;
         if (property.CanRead == false || property.CanWrite == false)
         {
             continue;
         }
         if (!(propertyType == typeof(string)) && !(propertyType == typeof(double)) &&
             !(propertyType == typeof(bool)) && !(propertyType == typeof(int)) &&
             !(propertyType == typeof(Thickness)) && !(propertyType == typeof(FontFamily)) &&
             !(propertyType == typeof(FontWeight)) && !(propertyType == typeof(Brush)) &&
             !(typeof(Enum).IsAssignableFrom(propertyType)))
         {
             continue;
         }
         if (property.Name == "Markdown" || property.Name == "Name")
         {
             continue;
         }
         EditableProperties.Add(new EditableProperty(MarkdownTextBlock, property));
     }
 }
        public Control_Settings(View_Main _main, MarkdownTextBlock _content)
        {
            m_main    = _main;
            m_content = _content;

            string path = Directory.GetCurrentDirectory() + "\\Assets\\Settings.txt";

            m_content.Text = File.ReadAllText(path);
        }
Пример #6
0
 public EditableProperty(MarkdownTextBlock instance, PropertyInfo property)
 {
     this.instance  = instance;
     this.property  = property;
     this.CanRead   = property.CanRead;
     this.CanWrite  = property.CanWrite;
     this.GetMethod = property.GetGetMethod();
     this.Name      = property.Name;
     this.value     = ConvertToString(property.GetValue(instance));
 }
Пример #7
0
 /// <summary>
 /// Fired when we should load the content.
 /// </summary>
 /// <param name="source"></param>
 public async void OnPrepareContent()
 {
     // Since some of this can be costly, delay the work load until we aren't animating.
     await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Low, () =>
     {
         m_markdownBlock = new MarkdownTextBlock();
         m_markdownBlock.OnMarkdownLinkTapped += MarkdownBlock_OnMarkdownLinkTapped;
         m_markdownBlock.OnMarkdownReady      += MarkdownBox_OnMarkdownReady;
         m_markdownBlock.Markdown              = m_base.Source.SelfText;
         ui_contentRoot.Children.Add(m_markdownBlock);
     });
 }
Пример #8
0
        /// <summary>
        /// Fired when we should destroy our content.
        /// </summary>
        public void OnDestroyContent()
        {
            // Clear the markdown
            if (_markdownBlock != null)
            {
                _markdownBlock.OnMarkdownReady      -= MarkdownBox_OnMarkdownReady;
                _markdownBlock.OnMarkdownLinkTapped -= MarkdownBlock_OnMarkdownLinkTapped;
            }
            _markdownBlock = null;

            // Clear the UI
            ui_contentRoot.Children.Clear();
        }
Пример #9
0
        public void OnXamlRendered(FrameworkElement control)
        {
            _toolbar = control.FindChild("Toolbar") as TextToolbar;

            if (control.FindChild("EditZone") is RichEditBox editZone)
            {
                editZone.TextChanged += EditZone_TextChanged;
            }

            if (control.FindChild("Previewer") is MarkdownTextBlock previewer)
            {
                _previewer              = previewer;
                _previewer.LinkClicked += Previewer_LinkClicked;
            }
        }
        public void OnXamlRendered(FrameworkElement control)
        {
            unformattedText = control.FindChild("UnformattedText") as TextBox;

            markdownText = control.FindChild("MarkdownText") as MarkdownTextBlock;

            if (markdownText != null)
            {
                markdownText.RequestedTheme      = SampleController.Current.GetCurrentTheme();
                markdownText.LinkClicked        += MarkdownText_LinkClicked;
                markdownText.ImageClicked       += MarkdownText_ImageClicked;
                markdownText.CodeBlockResolving += MarkdownText_CodeBlockResolving;
            }

            SetInitalText("Loading text...");
            LoadData();
        }
        public void OnXamlRendered(FrameworkElement control)
        {
            _toolbar = control.FindChildByName("Toolbar") as TextToolbar;

            var editZone = control.FindChildByName("EditZone") as RichEditBox;

            if (editZone != null)
            {
                editZone.TextChanged += EditZone_TextChanged;
            }

            _previewer = control.FindChildByName("Previewer") as MarkdownTextBlock;
            if (_previewer != null)
            {
                _previewer.LinkClicked += Previewer_LinkClicked;
            }
        }
Пример #12
0
        /// <summary>
        /// Checks and starts Windows Hello login, if possible and desired
        /// </summary>
        public async void CheckCapabilityWindowsHello()
        {
            if (await KeyCredentialManager.IsSupportedAsync())
            {
                WindowsHelloIsUsable = true;
                var settings = SettingsService.Instance;
                if (settings.PreferWindowsHello == Services.Enums.WindowsHelloPreferEnum.None)
                {
                    var dialog   = new ContentDialog();
                    var markdown = new MarkdownTextBlock
                    {
                        Text = Resources.WindowsHelloPreferMessage
                    };
                    dialog.Content             = markdown;
                    dialog.PrimaryButtonText   = Resources.Yes;
                    dialog.SecondaryButtonText = Resources.No;
                    var result = await _dialogService.ShowAsync(dialog);

                    switch (result)
                    {
                    case ContentDialogResult.None:
                        break;

                    case ContentDialogResult.Primary:
                        settings.PreferWindowsHello = Services.Enums.WindowsHelloPreferEnum.Prefer;
                        WindowsHelloLogin();
                        break;

                    case ContentDialogResult.Secondary:
                        settings.PreferWindowsHello = Services.Enums.WindowsHelloPreferEnum.No;
                        break;

                    default:
                        break;
                    }
                }
                else if (settings.PreferWindowsHello == Services.Enums.WindowsHelloPreferEnum.Prefer)
                {
                    if (!IsLogout)
                    {
                        WindowsHelloLogin();
                    }
                }
            }
        }
        public void OnXamlRendered(FrameworkElement control)
        {
            _toolbar = control.FindChildByName("Toolbar") as TextToolbar;

            if (control.FindChildByName("EditZone") is RichEditBox editZone)
            {
                editZone.TextChanged += EditZone_TextChanged;
            }

            if (control.FindChildByName("Previewer") is MarkdownTextBlock previewer)
            {
                _previewer              = previewer;
                _previewer.LinkClicked += Previewer_LinkClicked;
            }

            if (ToolbarFormat != null && (Format)ToolbarFormat.Value == Format.Custom)
            {
                UseCustomFormatter();
            }
        }
Пример #14
0
        /// <summary>
        /// Fired when we should load the content.
        /// </summary>
        public async void OnPrepareContent()
        {
            // Since some of this can be costly, delay the work load until we aren't animating.
            await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Low, () =>
            {
                _markdownBlock = new MarkdownTextBlock();
                _markdownBlock.OnMarkdownLinkTapped += MarkdownBlock_OnMarkdownLinkTapped;
                _markdownBlock.OnMarkdownReady      += MarkdownBox_OnMarkdownReady;
                _markdownBlock.Markdown              = _contentPanelBase.Source.SelfText;

                var fontSizeBinding = new Binding
                {
                    Source = App.BaconMan.UiSettingsMan,
                    Path   = new PropertyPath("PostView_Markdown_FontSize")
                };
                _markdownBlock.SetBinding(FontSizeProperty, fontSizeBinding);

                ui_contentRoot.Children.Add(_markdownBlock);
            });
        }
Пример #15
0
        public async static Task CheckVersion()
        {
            try
            {
                var url    = $"https://pic.nsapps.cn/biliuwp/biliv4.json?ts{Utils.GetTimestampS()}";
                var result = await HttpHelper.GetString(url);

                var ver = JsonConvert.DeserializeObject <NewVersion>(result);
                var num = $"{ SystemInformation.ApplicationVersion.Major }{ SystemInformation.ApplicationVersion.Minor.ToString("00")}{ SystemInformation.ApplicationVersion.Build.ToString("00")}";
                var v   = int.Parse(num);
                if (ver.version_num > v)
                {
                    var dialog = new ContentDialog();

                    dialog.Title = $"发现新版本 Ver {ver.version}";
                    MarkdownTextBlock markdownText = new MarkdownTextBlock()
                    {
                        Text                   = ver.version_desc,
                        TextWrapping           = Windows.UI.Xaml.TextWrapping.Wrap,
                        IsTextSelectionEnabled = true,
                        Background             = new SolidColorBrush(Colors.Transparent)
                    };
                    markdownText.LinkClicked += new EventHandler <LinkClickedEventArgs>(async(sender, args) =>
                    {
                        await Launcher.LaunchUriAsync(new Uri(args.Link));
                    });
                    dialog.Content             = markdownText;
                    dialog.PrimaryButtonText   = "查看详情";
                    dialog.SecondaryButtonText = "忽略";

                    dialog.PrimaryButtonClick += new Windows.Foundation.TypedEventHandler <ContentDialog, ContentDialogButtonClickEventArgs>(async(sender, e) =>
                    {
                        await Windows.System.Launcher.LaunchUriAsync(new Uri(ver.url));
                    });
                    await dialog.ShowAsync();
                }
            }
            catch (Exception)
            {
            }
        }
Пример #16
0
        private async void ShowUri(Setting setting)
        {
            var uri = setting.Uri;

            if (uri.Scheme == "ms-appx" && uri.AbsoluteUri.LastIndexOf(".md") > 0)
            {
                var content = await InteropManager.Read(uri);

                var child = new MarkdownTextBlock {
                    Text = content
                };
                var scroller = new ScrollViewer {
                    Content = child
                };
                await ShowDetails(scroller);
            }
            else
            {
                await InteropManager.LaunchUri(setting.Uri);
            }
        }
Пример #17
0
        /// <summary>
        /// Deletes an account from the collection
        /// </summary>
        /// <param name="parameter"></param>
        private async void DeleteAccountFromCollection(object parameter)
        {
            if (parameter is TwoFACodeModel model)
            {
                ContentDialog dialog = new ContentDialog();
                dialog.Title = Resources.DeleteAccountContentDialogTitle;
                var markdown = new MarkdownTextBlock
                {
                    Text = Resources.DeleteAccountContentDialogDescription
                };
                dialog.Content              = markdown;
                dialog.PrimaryButtonText    = Resources.Confirm;
                dialog.SecondaryButtonText  = Resources.ButtonTextCancel;
                dialog.SecondaryButtonStyle = App.Current.Resources["AccentButtonStyle"] as Style;
                ContentDialogResult result = await PageDialogService.ShowAsync(dialog);

                if (result == ContentDialogResult.Primary)
                {
                    TempDeletedTFAModel = model;
                    TwoFADataService.Collection.Remove(model);
                }
            }
        }
Пример #18
0
 public MarkdownHandler(MarkdownTextBlock markdownText)
 {
     _markdownText = markdownText;
     _markdownText.ImageClicked += ImageClicked;
     _markdownText.LinkClicked  += LinkClicked;
 }
Пример #19
0
 private async Task LoadMarkdownComponent(MarkdownTextBlock markdownTextBlock, string filePath)
 {
     markdownTextBlock.SetRenderer <CodeMarkdownRenderer>();
     markdownTextBlock.Text = await ReadFileAsync(filePath);
 }
 /// <summary>
 /// 从指定元素获取 FileUri 依赖项属性的值。
 /// </summary>
 /// <param name="obj">从中读取属性值的元素。</param>
 /// <returns>从属性存储获取的属性值。</returns>
 public static Uri GetFileUri(MarkdownTextBlock obj) => (Uri)obj.GetValue(FileUriProperty);
Пример #21
0
        /// <summary>
        /// Displays a FileNotFoundException message and the option for factory reset or correcting the path
        /// </summary>
        private async void ShowFileOrFolderNotFoundError()
        {
            var dialogService = App.Current.Container.Resolve <IDialogService>();

            try
            {
                //TODO current workaround: check permission to the file system (broadFileSystemAccess)
                string path = @"C:\Windows\explorer.exe";
                var    file = await StorageFile.GetFileFromPathAsync(path);
            }
            catch (UnauthorizedAccessException)
            {
                ErrorDialogs.UnauthorizedAccessDialog();
            }
            _errorOccurred = true;
            // disable shell navigation
            App.ShellPageInstance.NavigationIsAllowed = false;
            Logger.Log("no datafile found", Category.Exception, Priority.High);
            bool selectedOption = false;

            var dialog = new ContentDialog();

            dialog.Closed += Dialog_Closed;
            dialog.Title   = Resources.ErrorHandle;
            var markdown = new MarkdownTextBlock();

            markdown.Text = Resources.ExceptionDatafileNotFound;
            var stackPanel = new StackPanel();

            stackPanel.Children.Add(markdown);

            var changePathBTN = new Button();

            changePathBTN.Margin  = new Thickness(0, 10, 0, 0);
            changePathBTN.Content = Resources.ChangeDatafilePath;
            changePathBTN.Command = new DelegateCommand(async() =>
            {
                selectedOption = true;
                dialog.Hide();
                var result = await dialogService.ShowAsync(new UpdateDatafileContentDialog());
                if (result == ContentDialogResult.Primary)
                {
                    ErrorResolved();
                    CheckDatafile();
                }
                if (result == ContentDialogResult.None)
                {
                    ShowFileOrFolderNotFoundError();
                }
            });
            stackPanel.Children.Add(changePathBTN);

            var factoryResetBTN = new Button();

            factoryResetBTN.Margin  = new Thickness(0, 10, 0, 10);
            factoryResetBTN.Content = Resources.FactoryReset;
            factoryResetBTN.Command = new DelegateCommand(async() =>
            {
                var passwordHash = await App.Repository.Password.GetAsync();
                //delete password in the secret vault
                SecretService.Helper.RemoveSecret(Constants.ContainerName, passwordHash.Hash);
                // reset data and restart app
                await ApplicationData.Current.ClearAsync();
                await CoreApplication.RequestRestartAsync("Factory reset");
            });
            stackPanel.Children.Add(factoryResetBTN);

            dialog.Content              = stackPanel;
            dialog.PrimaryButtonText    = Resources.CloseApp;
            dialog.PrimaryButtonStyle   = App.Current.Resources["AccentButtonStyle"] as Style;
            dialog.PrimaryButtonCommand = new DelegateCommand(() =>
            {
                Prism.PrismApplicationBase.Current.Exit();
            });

            async void Dialog_Closed(ContentDialog sender, ContentDialogClosedEventArgs args)
            {
                if (!(Window.Current.Content is ShellPage))
                {
                    Prism.PrismApplicationBase.Current.Exit();
                }
                else
                {
                    if (!selectedOption)
                    {
                        await dialogService.ShowAsync(dialog);
                    }
                }
            }

            await dialogService.ShowAsync(dialog);
        }