public string GetWidget(Parameters parameters) { var testFolder = ConfigurationManager.AppSettings["WidgetFolder"]; var testWidget = parameters.Widget.CreateWidget(); string html = testWidget; while (html.Contains("<widget")) { var poss = html.IndexOf("<widget", 0, System.StringComparison.Ordinal); var pose = html.IndexOf(">", poss, System.StringComparison.Ordinal); var widget = html.Substring(poss, pose - poss + 1); var posNs = widget.IndexOf("name=\"", 0, System.StringComparison.Ordinal) + 6; var posNe = widget.IndexOf("\"", posNs, System.StringComparison.Ordinal); var widgetName = widget.Substring(posNs, posNe - posNs); var widgetFileName = System.IO.Path.Combine(testFolder, widgetName + ".json"); var dWidget = new WebWidget(); if (dWidget.ReadWidgetFile(widgetFileName)) { var wHtml = dWidget.CreateWidget(); html = html.Replace(widget, wHtml); } } return(html); }
private void Menu_FileOpenOnClick(object sender, RoutedEventArgs e) { // Create OpenFileDialog var dlg = new Microsoft.Win32.OpenFileDialog { DefaultExt = ".json", Filter = "Widget Files (.json)|*.json|All files (*.*)|*.*", CheckPathExists = true, CheckFileExists = true }; // Display OpenFileDialog by calling ShowDialog method var result = dlg.ShowDialog(); // Get the selected file name and display in a TextBox if (result == true) { // Open document TextBoxWidgetFolder.Text = System.IO.Path.GetDirectoryName(dlg.FileName); TextBoxWidgetFile.Text = dlg.SafeFileName; // Read Selected File // http://james.newtonking.com/json/help/index.html // if (!string.IsNullOrWhiteSpace(TextBoxWidgetFolder.Text) || !string.IsNullOrWhiteSpace(TextBoxWidgetFile.Text)) { if (workWidget.ReadWidgetFile(System.IO.Path.Combine(TextBoxWidgetFolder.Text, TextBoxWidgetFile.Text))) { UpdateWidgetDisplayFields(); } else { TextBoxErrorMessage.Text = workWidget.ErrorMessage; } } } }