Exemple #1
0
        public void LoadUri(Uri uri, HelpArticle sourceArticle = null)
        {
            try
            {
                var webClient = new WebClient();
                markdownDocument.BaseUri = uri;

                this.sourceArticle = sourceArticle;

                try
                {
                    // put in controls from the feed that show relevant printer information
                    WebCache.RetrieveText(uri.ToString(),
                                          (markDown) =>
                    {
                        UiThread.RunOnIdle(() =>
                        {
                            this.Markdown = markDown;
                        });
                    });
                }
                catch
                {
                }
            }
            catch
            {
                // On error, revert to empty content
                this.Markdown = "";
            }
        }
        private void AddExportMenu(PopupMenu popupMenu, IEnumerable <PrintTask> printTasks)
        {
            var exportPrintHistory = popupMenu.CreateMenuItem("Export History".Localize() + "...");

            exportPrintHistory.Enabled = printTasks.Any();
            exportPrintHistory.Click  += (s, e) =>
            {
                if (ApplicationController.Instance.IsMatterControlPro())
                {
                    ExportToCsv(printTasks);
                }
                else                 // upsell MatterControl Pro
                {
                    string text = "Exporting print history is a MatterControl Pro feature. Upgrade to Pro to unlock MatterControl Pro.".Localize();
                    WebCache.RetrieveText(
                        "https://matterhackers.github.io/MatterControl-Docs/ProContent/Unlock_Export_Print_History.md",
                        (markDown) =>
                    {
                        // push the new text into the widget
                        text = markDown;
                    });

                    StyledMessageBox.ShowMessageBox(text,
                                                    "Upgrade to Pro".Localize(),
                                                    StyledMessageBox.MessageType.OK,
                                                    useMarkdown: true,
                                                    width: 540,
                                                    height: 400);
                }
            };
        }
 private void CheckForUpdate()
 {
     WebCache.RetrieveText(
         "https://matterhackers.github.io/MatterControl-Docs/ProContent/Upgrade_To_Pro.md",
         (markDown) =>
     {
         UiThread.RunOnIdle(() =>
         {
             markdownWidget.Markdown = markDown;
         });
     });
 }
Exemple #4
0
        public override void OnLoad(EventArgs args)
        {
            base.OnLoad(args);

            FeedData explorerFeed = null;

            // Force layout to change to get it working
            var oldMargin = this.Margin;

            this.Margin = new BorderDouble(20);
            this.Margin = oldMargin;

            Task.Run(() =>
            {
                // Construct directly from cache
                WebCache.RetrieveText($"https://www.matterhackers.com/feeds/{relativeUrl}", (newData) =>
                {
                    lock (locker)
                    {
                        explorerFeed = JsonConvert.DeserializeObject <FeedData>(newData);

                        if (explorerFeed != null)
                        {
                            var container = new List <GuiWidget>();

                            // Add controls for content
                            GuiWidget currentContentContainer = null;
                            foreach (var content in explorerFeed.Content)
                            {
                                AddContentItem(container, ref currentContentContainer, theme, content);
                            }

                            this.CloseChildren();
                            foreach (var widget in container)
                            {
                                this.AddChild(widget);
                            }
                            UiThread.RunOnIdle(() =>
                            {
                                // Force layout to change to get it working
                                this.Margin = new BorderDouble(20);
                                this.Margin = oldMargin;
                            });
                        }
                    }
                });
            });
        }
        public override void Load()
        {
            var uri = $"https://api.github.com/repos/{Account}/{Repository}/contents/{RepoDirectory}";

            // get the directory contents
            WebCache.RetrieveText(uri,
                                  (content) =>
            {
                lock (locker)
                {
                    ParseJson(content);
                }
            },
                                  false,
                                  AddCromeHeaders);
        }
        public override async void OnLoad(EventArgs args)
        {
            if (string.IsNullOrEmpty(this.StoreID) &&
                File.Exists(printerInfo.ProfilePath))
            {
                // load up the printer profile so we can get the MatterHackers Skew-ID out of it
                var printerSettings = PrinterSettings.LoadFile(printerInfo.ProfilePath);

                // Use the make-model mapping table
                if (OemSettings.Instance.OemPrinters.TryGetValue($"{printerInfo.Make}-{ printerInfo.Model}", out StorePrinterID storePrinterID))
                {
                    this.StoreID = storePrinterID?.SID;
                }
            }

            if (!string.IsNullOrWhiteSpace(StoreID))
            {
                try
                {
                    // put in controls from the feed that show relevant printer information
                    WebCache.RetrieveText($"https://mh-pls-prod.appspot.com/p/1/product-sid/{StoreID}?IncludeListingData=True",
                                          (json) =>
                    {
                        UiThread.RunOnIdle(() =>
                        {
                            var result = JsonConvert.DeserializeObject <ProductSidData>(json);
                            productDataContainer.RemoveAllChildren();
                            CreateProductDataWidgets(result.ProductSku);
                        });
                    });
                }
                catch (Exception ex)
                {
                    Trace.WriteLine("Error collecting or loading printer details: " + ex.Message);
                }

                // add a section to hold the data about the printer
                this.AddChild(productDataContainer = new FlowLayoutWidget(FlowDirection.TopToBottom)
                {
                    HAnchor = HAnchor.Stretch
                });
            }

            headingRow.Visible = this.ShowHeadingRow;

            base.OnLoad(args);
        }
Exemple #7
0
        public override void Load()
        {
            var uri = $"https://api.github.com/repos/{Account}/{Repository}/contents/{RepoDirectory}";

            // get the directory contents
            WebCache.RetrieveText(uri,
                                  (content) =>
            {
                lock (locker)
                {
                    if (content.Contains("rate limit exceeded"))
                    {
                        HeaderMarkdown = content;
                        OnContentChanged();
                        return;
                    }
                    ParseJson(content);
                }
            },
                                  false,
                                  AddCromeHeaders);
        }
Exemple #8
0
        private void ParseJson(string jsonStr)
        {
            // parse result
            FileInfo[] dirContents = JsonConvert.DeserializeObject <FileInfo[]>(jsonStr);

            var childContainers = new SafeList <ILibraryContainerLink>();

            this.Items.Clear();

            // read in data
            foreach (FileInfo file in dirContents)
            {
                if (file.type == "dir")
                {
                    if (file.name == ".images")
                    {
                        ImageUrlCache = new List <(string name, string url)>();
                        // do the initial load
                        LoadFolderImageUrlCache().Wait();
                    }
                    else
                    {
                        childContainers.Add(new GitHubContainerLink(file.name,
                                                                    Account,
                                                                    Repository,
                                                                    RepoDirectory + "/" + file.name));
                    }
                }
                else if (file.type == "file")
                {
                    if (Path.GetExtension(file.name).ToLower() == ".library")
                    {
                        childContainers.Add(new GitHubLibraryLink(Path.GetFileNameWithoutExtension(file.name),
                                                                  Account,
                                                                  Repository,
                                                                  file.download_url));
                    }
                    else if (file.name == "index.md")
                    {
                        var uri = $"https://raw.githubusercontent.com/{Account}/{Repository}/main/{RepoDirectory}/index.md";
                        WebCache.RetrieveText(uri,
                                              (content) =>
                        {
                            HeaderMarkdown = content;
                            OnContentChanged();
                        },
                                              true,
                                              AddCromeHeaders);
                    }
                    else
                    {
                        this.Items.Add(new GitHubLibraryItem(file.name, file.download_url));
                    }
                }
            }

            Task.Run(async() =>
            {
                foreach (var item in this.Items)
                {
                    // check if we have any of the images cached
                    var thumbnail = await Task.Run(() => ApplicationController.Instance.Thumbnails.LoadCachedImage(item, 256, 256));

                    if (thumbnail != null &&
                        thumbnail.Width == 256)
                    {
                        // save so it is easy to create the upload data for GitHub folders
                        var filename = ApplicationController.CacheablePath(
                            Path.Combine("GitHubImages", this.Repository, this.RepoDirectory.Replace("/", "\\"), ".images"),
                            $"{Path.GetFileNameWithoutExtension(item.Name)}.png");
                        if (!File.Exists(filename))
                        {
                            ImageIO.SaveImageData(filename, thumbnail);
                        }
                    }
                }
            });

            this.ChildContainers = childContainers;

            OnContentChanged();
        }