Пример #1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="repoPath">Tuple with Repository, path and branch</param>
        /// <returns></returns>
        public async Task Load(Tuple <Repository, string, string> repoPath)
        {
            IsSupportedFile = true;
            Repository      = repoPath.Item1;
            Path            = repoPath.Item2;

            if (!GlobalHelper.IsInternet())
            {
                //Sending NoInternet message to all viewModels
                Messenger.Default.Send(new GlobalHelper.LocalNotificationMessageType {
                    Message = "No Internet", Glyph = "\uE704"
                });
            }
            else
            {
                isLoading = true;

                if (string.IsNullOrWhiteSpace(repoPath.Item3))
                {
                    SelectedBranch = await RepositoryUtility.GetDefaultBranch(Repository.Id);
                }
                else
                {
                    SelectedBranch = repoPath.Item3;
                }

                IsImage = false;

                if ((Path.ToLower().EndsWith(".exe")) ||
                    (Path.ToLower().EndsWith(".pdf")) ||
                    (Path.ToLower().EndsWith(".ttf")) ||
                    (Path.ToLower().EndsWith(".suo")) ||
                    (Path.ToLower().EndsWith(".mp3")) ||
                    (Path.ToLower().EndsWith(".mp4")) ||
                    (Path.ToLower().EndsWith(".avi")))
                {
                    /*
                     * Unsupported file types
                     */
                    IsSupportedFile = false;
                    isLoading       = false;
                    return;
                }
                if ((Path.ToLower()).EndsWith(".png") ||
                    (Path.ToLower()).EndsWith(".jpg") ||
                    (Path.ToLower()).EndsWith(".jpeg") ||
                    (Path.ToLower().EndsWith(".gif")))
                {
                    /*
                     * Image file types
                     */

                    IsImage = true;
                    String uri = (await RepositoryUtility.GetRepositoryContentByPath(Repository, Path, SelectedBranch))?[0].Content.DownloadUrl;
                    if (!string.IsNullOrWhiteSpace(uri))
                    {
                        ImageFile = new BitmapImage(new Uri(uri));
                    }
                    isLoading = false;
                    return;
                }
                if ((Path.ToLower()).EndsWith(".md"))
                {
                    /*
                     *  Files with .md extension
                     */
                    TextContent = (await RepositoryUtility.GetRepositoryContentByPath(Repository, Path, SelectedBranch))?[0].Content.Content;
                    isLoading   = false;
                    return;
                }

                /*
                 *  Code files
                 */

                String content = (await RepositoryUtility.GetRepositoryContentByPath(Repository, Path, SelectedBranch))?[0].Content.Content;
                if (content == null)
                {
                    IsSupportedFile = false;
                    isLoading       = false;
                    return;
                }
                SyntaxHighlightStyleEnum style = (SyntaxHighlightStyleEnum)SettingsService.Get <int>(SettingsKeys.HighlightStyleIndex);
                bool lineNumbers = SettingsService.Get <bool>(SettingsKeys.ShowLineNumbers);
                HTMLContent = await HiliteAPI.TryGetHighlightedCodeAsync(content, Path, style, lineNumbers, CancellationToken.None);

                if (HTMLContent == null)
                {
                    /*
                     *  Plain text files (Getting HTML for syntax highlighting failed)
                     */

                    RepositoryContent result = await RepositoryUtility.GetRepositoryContentTextByPath(Repository, Path, SelectedBranch);

                    if (result != null)
                    {
                        TextContent = result.Content;
                    }
                }

                if (HTMLContent == null && TextContent == null)
                {
                    IsSupportedFile = false;
                }

                isLoading = false;
            }
        }
Пример #2
0
        public async Task Load(Tuple <Repository, string, string> repoPath)  //This page recieves RepositoryId and name of the file
        {
            IsSupportedFile = true;
            Repository      = repoPath.Item1;
            Path            = repoPath.Item2;

            if (string.IsNullOrWhiteSpace(repoPath.Item3))
            {
                SelectedBranch = await RepositoryUtility.GetDefaultBranch(Repository.Id);
            }
            else
            {
                SelectedBranch = repoPath.Item3;
            }


            MarkdownOptions options = new MarkdownOptions
            {
                AsteriskIntraWordEmphasis = true,
                AutoNewlines     = true,
                StrictBoldItalic = true,
                AutoHyperlink    = false,
                LinkEmails       = true
            };
            Markdown markDown = new Markdown(options);

            if (!GlobalHelper.IsInternet())
            {
                Messenger.Default.Send(new GlobalHelper.NoInternetMessageType()); //Sending NoInternet message to all viewModels
            }
            else
            {
                Messenger.Default.Send(new GlobalHelper.HasInternetMessageType()); //Sending Internet available message to all viewModels
                isLoading = true;
                IsImage   = false;

                if ((Path.ToLower().EndsWith(".exe")) ||
                    (Path.ToLower().EndsWith(".pdf")) ||
                    (Path.ToLower().EndsWith(".ttf")) ||
                    (Path.ToLower().EndsWith(".suo")) ||
                    (Path.ToLower().EndsWith(".mp3")) ||
                    (Path.ToLower().EndsWith(".mp4")) ||
                    (Path.ToLower().EndsWith(".avi")))
                {
                    /*
                     * Unsupported file types
                     */
                    IsSupportedFile = false;
                    isLoading       = false;
                    return;
                }
                if ((Path.ToLower()).EndsWith(".png") ||
                    (Path.ToLower()).EndsWith(".jpg") ||
                    (Path.ToLower()).EndsWith(".jpeg") ||
                    (Path.ToLower().EndsWith(".gif")))
                {
                    /*
                     * Image file types
                     */

                    IsImage = true;
                    // TODO: loading the WHOLE files list is really necessary here?
                    var uri = (await RepositoryUtility.GetRepositoryContentByPath(Repository, Path, SelectedBranch))[0].Content.DownloadUrl;
                    ImageFile = new BitmapImage(uri);
                    isLoading = false;
                    return;
                }
                if ((Path.ToLower()).EndsWith(".md"))
                {
                    /*
                     *  Files with .md extension will be shown with full markdown
                     */
                    HTMLBackgroundColor = Colors.White;
                    var str = (await RepositoryUtility.GetRepositoryContentByPath(Repository, Path, SelectedBranch))[0].Content.Content;
                    HTMLContent = "<html><head><meta charset = \"utf-8\" /></head><body style=\"font-family: sans-serif\">" + markDown.Transform(str) + "</body></html>";
                    isLoading   = false;
                    return;
                }

                String content = (await RepositoryUtility.GetRepositoryContentByPath(Repository, Path, SelectedBranch))?[0].Content.Content;
                if (content == null)
                {
                    IsSupportedFile = false;
                    isLoading       = false;
                    return;
                }
                SyntaxHighlightStyle style = (SyntaxHighlightStyle)SettingsService.Get <int>(SettingsKeys.HighlightStyleIndex);
                bool lineNumbers           = SettingsService.Get <bool>(SettingsKeys.ShowLineNumbers);
                HTMLContent = await HiliteAPI.TryGetHighlightedCodeAsync(content, Path, style, lineNumbers, CancellationToken.None);

                IsSupportedFile = HTMLContent != null;
                isLoading       = false;
            }
        }