protected virtual async void EditOnTryMudBlazor()
        {
            // We use a seperator that wont be in code so we can send 2 files later
            var codeFiles = "__Main.razor" + (char)31 + Snippets.GetCode(Code);

            // Add dialogs for dialog examples
            if (Code.StartsWith("Dialog"))
            {
                var regex          = new Regex(@"\Show<(Dialog.*?_Dialog)\>");
                var dialogCodeName = regex.Match(codeFiles).Groups[1].Value;
                if (dialogCodeName != string.Empty)
                {
                    var dialogCodeFile = dialogCodeName + ".razor" + (char)31 + Snippets.GetCode(dialogCodeName);
                    codeFiles = codeFiles + (char)31 + dialogCodeFile;
                }
            }

            // Add Element.cs model for webapi periodic table
            if (codeFiles.Contains("webapi/periodictable", StringComparison.InvariantCultureIgnoreCase))
            {
                var elementCodeFile = "Element.cs" + (char)31 + Snippets.GetCode("Element");
                codeFiles = codeFiles + (char)31 + elementCodeFile;
            }

            var codeFileEncoded = codeFiles.ToCompressedEncodedUrl();
            // var tryMudBlazorLocation = "https://localhost:5001/";
            var tryMudBlazorLocation = "https://try.mudblazor.com/";
            var url = $"{tryMudBlazorLocation}snippet/{codeFileEncoded}";
            await DomService.OpenInNewTab(url);
        }
Beispiel #2
0
 protected virtual async void EditOnTryMudBlazor()
 {
     // We use a seperator that wont be in code so we can send 2 files later
     var codeFile        = "__Main.razor" + (char)31 + Snippets.GetCode(Code);
     var codeFileEncoded = codeFile.ToCompressedEncodedUrl();
     // var tryMudBlazorLocation = "https://localhost:5001/";
     var tryMudBlazorLocation = "https://try.mudblazor.com/";
     var url = $"{tryMudBlazorLocation}snippet/{codeFileEncoded}";
     await DomService.OpenInNewTab(url);
 }
Beispiel #3
0
    protected virtual async void RunOnTryMudBlazor()
    {
        string firstFile = "";

        if (Codes != null)
        {
            firstFile = Codes.FirstOrDefault().code;
        }
        else
        {
            firstFile = Code;
        }

        // We use a separator that wont be in code so we can send 2 files later
        var codeFiles = "__Main.razor" + (char)31 + Snippets.GetCode(firstFile);

        // Add dialogs for dialog examples
        if (firstFile.StartsWith("Dialog"))
        {
            var regex          = new Regex(@"\Show<(Dialog.*?_Dialog)\>");
            var dialogCodeName = regex.Match(codeFiles).Groups[1].Value;
            if (dialogCodeName != string.Empty)
            {
                var dialogCodeFile = dialogCodeName + ".razor" + (char)31 + Snippets.GetCode(dialogCodeName);
                codeFiles = codeFiles + (char)31 + dialogCodeFile;
            }
        }

        // Data models
        if (codeFiles.Contains("MudBlazor.Examples.Data.Models"))
        {
            if (Regex.Match(codeFiles, @"\bElement\b").Success)
            {
                var elementCodeFile = "Element.cs" + (char)31 + Snippets.GetCode("Element");
                codeFiles = codeFiles + (char)31 + elementCodeFile;
            }

            if (Regex.Match(codeFiles, @"\bServer\b").Success)
            {
                var serverCodeFile = "Server.cs" + (char)31 + Snippets.GetCode("Server");
                codeFiles = codeFiles + (char)31 + serverCodeFile;
            }
        }

        var codeFileEncoded = codeFiles.ToCompressedEncodedUrl();
        // var tryMudBlazorLocation = "https://localhost:5001/";
        var tryMudBlazorLocation = "https://try.mudblazor.com/";
        var url = $"{tryMudBlazorLocation}snippet/{codeFileEncoded}";
        await JsApiService.OpenInNewTabAsync(url);
    }
        public void CompressedUrlRoundtripTest()
        {
            var    snippet = Snippets.GetCode("TableServerSidePaginateExample");
            string urlEncodedBase64compressedCode, base64compressedCode, snippet1;

            byte[] bytes;
            // compression
            using (var uncompressed = new MemoryStream(Encoding.UTF8.GetBytes(snippet)))
                using (var compressed = new MemoryStream())
                    using (var compressor = new DeflateStream(compressed, CompressionMode.Compress))
                    {
                        uncompressed.CopyTo(compressor);
                        compressor.Close();
                        bytes = compressed.ToArray();
                        base64compressedCode = Convert.ToBase64String(bytes);
                        //Console.WriteLine(base64compressedCode);
                        urlEncodedBase64compressedCode = Uri.EscapeDataString(base64compressedCode);
                        Console.WriteLine(urlEncodedBase64compressedCode);
                        Console.WriteLine("Length code: " + snippet.Length);
                        Console.WriteLine("Length compressed: " + urlEncodedBase64compressedCode.Length);
                    }
            // uncompress
            base64compressedCode = Uri.UnescapeDataString(urlEncodedBase64compressedCode);
            bytes = Convert.FromBase64String(base64compressedCode);
            using (var uncompressed = new MemoryStream())
                using (var compressedStream = new MemoryStream(bytes))
                    using (var uncompressor = new DeflateStream(compressedStream, CompressionMode.Decompress))
                    {
                        uncompressor.CopyTo(uncompressed);
                        uncompressor.Close();
                        //uncompressed.Position = 0;
                        snippet1 = Encoding.UTF8.GetString(uncompressed.ToArray());
                    }
            // compare
            snippet1.Should().Be(snippet);
        }
 private async Task CopyTextToClipboard()
 {
     await JsApiService.CopyToClipboardAsync(Snippets.GetCode(Code));
 }
        private async Task OnCopyCode()
        {
            await JSRuntime.InvokeVoidAsync("blazoriseDocs.code.copyToClipboard", Snippets.GetCode(Code));

            await NotificationService.Info($"Copied code example!");
        }
 private async Task CopyTextToClipboard()
 {
     await JSRuntime.InvokeVoidAsync("clipboardCopy.copyText", Snippets.GetCode(Code));
 }