private void Button_Click(object sender, RoutedEventArgs e) { if (sender == build) { if (filelst.ItemsSource == null) { return; } IList <FileModel> selist = ((IList <FileModel>)(filelst.ItemsSource)).Where(f => f.ISCHECKED).ToList(); if (selist.Count == 0) { if (MessageBox.Show("No file is checked, process all?", "CONFIRM", MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.No) { return; } selist = (IList <FileModel>)(filelst.ItemsSource); } var ui = new BuildUI() { Owner = this, ShowInTaskbar = false }; ui.FileList = selist; ui.ShowDialog(); return; } if (sender == exit) { this.Close(); return; } if (sender == dir) { bool usedef; var loc = LoaderImpl.SelectDirectory(out usedef, Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments)); if (usedef) { if (string.IsNullOrEmpty(LoaderImpl.SaveLocation)) { LoaderImpl.SaveLocation = loc; } } else { LoaderImpl.SaveLocation = loc; } location.Text = LoaderImpl.SaveLocation; LoaderImpl.SaveSettings(); LoadRootDirectory(); return; } }
private void Browser_LoadCompleted(object sender, NavigationEventArgs e) { LoaderImpl.Mask(this, null, () => { var timer = new System.Timers.Timer(); timer.Interval = 600; timer.Elapsed += (aa, bb) => { timer.Stop(); Dispatcher.Invoke(() => Real_Browser_LoadCompleted(sender, e)); }; timer.Start(); //System.Windows.Application.Current.Dispatcher.BeginInvoke(new System.Action(), DispatcherPriority.ContextIdle); }); }
public bool SaveDirect() { try { var provider = CoreImpl.applicationServiceProvider; var _UO = provider.GetService(CoreImpl.tyIBrowserManager); if (_UO == null) { return(false); } var browserManager = new IBrowserManager(_UO); var contentBrowser = browserManager.ActiveBrowser; if (contentBrowser == null) { return(false); } helpBrowse = new IHelpViewerBrowser(contentBrowser._UO); var meta = helpBrowse.TopicMetadata; this.Title = meta.HelpId; var ie = helpBrowse.WebBrowser; var location_Text = LoaderImpl.SaveLocation; if (string.IsNullOrEmpty(location_Text)) { location_Text = Environment.CurrentDirectory; } var id = meta.HelpId; var fname = EncodeAsFileName(id); location_Text = System.IO.Path.Combine(location_Text, fname + ".html"); var doc = (HTMLDocument)ie.Document; dynamic item = doc.getElementsByTagName("html"); var html = (string)item[0].outerHTML; System.IO.File.WriteAllText(location_Text, html, Encoding.UTF8); return(true); } catch (Exception ex) { LoaderImpl.ShowException(ex); return(false); } }
private void Button_Click(object sender, RoutedEventArgs e) { if (sender == cancel) { this.Close(); return; } if (sender == save) { if (string.IsNullOrEmpty(location.Text)) { return; } try { var meta = helpBrowse.TopicMetadata; var id = meta.HelpId; var ie = helpBrowse.WebBrowser; var doc = (HTMLDocument)ie.Document; dynamic item = doc.getElementsByTagName("html"); var html = (string)item[0].outerHTML; var file = location.Text; System.IO.File.WriteAllText(file, html, Encoding.UTF8); this.Close(); } catch (Exception ex) { MessageBox.Show(ex.ToString(), "ERROR", MessageBoxButton.OK, MessageBoxImage.Error); } return; } if (sender == dir) { bool usedef; var loc = LoaderImpl.SelectDirectory(out usedef); if (!string.IsNullOrEmpty(loc)) { location.Text = loc; } return; } }
/// <summary> /// Initializes the loader. /// </summary> /// <param name="locator">The runtime locator.</param> /// <exception cref="ArgumentNullException">Thrown if <paramref name="locator"/> is null.</exception> /// <exception cref="InvalidOperationException">Thrown if the loader has already been initialized.</exception> /// <exception cref="LoaderException">Thrown if the loader could not be initialized.</exception> public static void Initialize(RuntimeLocator locator) { if (locator == null) { throw new ArgumentNullException("locator"); } if (loader != null) { throw new InvalidOperationException("The loader has already been initialized."); } string runtimePath = locator.GetValidatedRuntimePathOrThrow(); string gallioAssemblyPath = locator.GetGallioAssemblyPath(runtimePath); LoaderImpl newLoader = new LoaderImpl(runtimePath, gallioAssemblyPath); newLoader.Initialize(); loader = newLoader; }
private void Button_Click(object sender, RoutedEventArgs e) { if (sender == build1 || sender == build2) { var filelst = FileList; if (filelst == null) { return; } IList <FileModel> selist = null; if (sender == build1) { selist = filelst.Where(f => f.ISCHECKED).ToList(); if (selist.Count == 0) { if (MessageBox.Show($"No file is checked, process all ({filelst.Count} Items)?", "CONFIRM", MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.No) { return; } selist = filelst; } } else if (filelstbox.SelectedItem != null) { selist = new List <FileModel>() { (FileModel)filelstbox.SelectedItem }; } if (selist == null || selist.Count == 0) { browser.Navigate("about:blank"); } else { LoaderImpl.Mask(this, null, () => { var timer = new System.Timers.Timer(); timer.Interval = 600; timer.Elapsed += (aa, bb) => { timer.Stop(); Stream stream = null; try { stream = File.Create("$__tmp.mhtml"); foreach (var fm in selist) { var bytes = System.IO.File.ReadAllBytes(fm.PATH); stream.Write(bytes, 0, bytes.Length); } stream.Flush(); stream.Seek(0, SeekOrigin.Begin); Dispatcher.Invoke(() => browser.NavigateToStream(stream)); m_stream = stream; } catch { LoaderImpl.Unmask(); if (stream != null) { stream.Close(); } } }; timer.Start(); //System.Windows.Application.Current.Dispatcher.BeginInvoke(new System.Action(), DispatcherPriority.ContextIdle); }); } return; } if (sender == beautify) { Browser_LoadCompleted(browser, null); return; } if (sender == exit) { LoaderImpl.NoSeeAlso = !sAlso.IsChecked.GetValueOrDefault(); LoaderImpl.NoFooter = !sFooter.IsChecked.GetValueOrDefault(); LoaderImpl.NoRelated = !sRelated.IsChecked.GetValueOrDefault(); LoaderImpl.AutoBeautify = pAuto.IsChecked.GetValueOrDefault(); LoaderImpl.SaveSettings(); this.Close(); return; } if (sender == top) { var sel = (FileModel)filelstbox.SelectedItem; if (sel == null) { return; } FileList.Remove(sel); FileList.Insert(0, sel); filelstbox.SelectedItem = sel; filelstbox.ScrollIntoView(sel); return; } if (sender == btm) { var sel = (FileModel)filelstbox.SelectedItem; if (sel == null) { return; } FileList.Remove(sel); FileList.Add(sel); filelstbox.SelectedItem = sel; filelstbox.ScrollIntoView(sel); return; } if (sender == up1) { var sel = (FileModel)filelstbox.SelectedItem; var seli = filelstbox.SelectedIndex; if (sel == null) { return; } FileList.RemoveAt(seli); FileList.Insert(Math.Max(0, seli - 1), sel); filelstbox.SelectedItem = sel; filelstbox.ScrollIntoView(sel); return; } if (sender == dw1) { var sel = (FileModel)filelstbox.SelectedItem; var seli = filelstbox.SelectedIndex; if (sel == null) { return; } FileList.RemoveAt(seli); FileList.Insert(Math.Min(FileList.Count, seli + 1), sel); filelstbox.SelectedItem = sel; filelstbox.ScrollIntoView(sel); return; } if (sender == sav) { if (FileList == null) { return; } if (MessageBox.Show("Do you want to save this order?", "CONFIRM", MessageBoxButton.OKCancel, MessageBoxImage.Question) != MessageBoxResult.OK) { return; } var sel = (FileModel)filelstbox.SelectedItem; int i = 0; foreach (var f in FileList) { var of = f.PATH; i++; int k = f.FILE.IndexOf('#'); f.FILE = i.ToString("0000") + "#" + f.FILE.Substring(k + 1); f.PATH = System.IO.Path.Combine(System.IO.Path.GetDirectoryName(f.PATH), f.FILE); System.IO.File.Move(of, f.PATH); } var lst = FileList; FileList = null; FileList = lst; filelstbox.SelectedItem = sel; return; } }
private void Real_Browser_LoadCompleted(object sender, NavigationEventArgs e) { try { // remove logo,copyright,annoy note dynamic doc = browser.Document; for ( ; ;) { dynamic item = doc.getElementsByClassName("OH_feedbacklink"); for (int i = 0; i < item.length; i++) { var _this = item[i]; var pr = _this.parentNode; if (pr == null) { continue; } pr.removeChild(_this); } if (item.length == 0) { break; } } for ( ; ;) { dynamic item = doc.getElementsByClassName("OH_disclaimersSection"); for (int i = 0; i < item.length; i++) { var _this = item[i]; var pr = _this.parentNode; if (pr == null) { continue; } pr.removeChild(_this); } if (item.length == 0) { break; } } for (; ;) { dynamic item = doc.getElementsByClassName("OH_CodeSnippetToolBarText"); if (item.length == 0) { break; } bool bk = true; for (int i = 0; i < item.length; i++) { var _this = item[i]; if (_this.style.display != "none") { bk = false; _this.style.display = "none"; } /*var pr = _this.parentNode; * if (pr == null) continue; * pr.removeChild(_this);*/ } if (bk) { break; } } if (e != null && !pAuto.IsChecked.GetValueOrDefault()) { LoaderImpl.Unmask(); return; } for (; !sFooter.IsChecked.GetValueOrDefault();) { dynamic item = doc.getElementsByClassName("OH_footer"); for (int i = 0; i < item.length; i++) { var _this = item[i]; var pr = _this.parentNode; if (pr == null) { continue; } pr.removeChild(_this); } if (item.length == 0) { break; } } for ( ; !sAlso.IsChecked.GetValueOrDefault();) { dynamic item = doc.getElementById("see_also"); if (item == null) { break; } var pr = item.parentNode; if (pr != null) { var sb = pr.nextSibling; if (sb != null && sb.tagName.ToLower() == "dl") { if (sb.parentNode != null) { sb.parentNode.removeChild(sb); } } if (pr.tagName.ToLower().StartsWith("h")) { if (pr.parentNode != null) { pr.parentNode.removeChild(pr); } } } } for ( ; !sRelated.IsChecked.GetValueOrDefault();) { dynamic item = doc.getElementById("related_topics"); if (item == null) { break; } var pr = item.parentNode; if (pr != null) { var sb = pr.nextSibling; if (sb != null && sb.tagName.ToLower() == "dl") { if (sb.parentNode != null) { sb.parentNode.removeChild(sb); } } if (pr.tagName.ToLower().StartsWith("h")) { if (pr.parentNode != null) { pr.parentNode.removeChild(pr); } } } } LoaderImpl.Unmask(); } catch (Exception ex) { LoaderImpl.Unmask(); LoaderImpl.ShowException(ex); } }
public static void Worker(string args) { System.Windows.MessageBox.Show(args); if (myTools != null) { return; } myTag = new object(); try { System.Windows.Forms.Application.EnableVisualStyles(); LoadSettings(); var appAssembly = Application.Current.GetType().Assembly; // init types CoreImpl.tyBrowserDockView = typeof(Microsoft.VisualStudio.Help.Viewer.DockViews.BrowserDockView); CoreImpl.tyIDockViewManager = appAssembly.GetType(IDockViewManager._FullName); CoreImpl.tyIBrowserManager = appAssembly.GetType(IBrowserManager._FullName); CoreImpl.tyIContentBrowser = appAssembly.GetType(IContentBrowser._FullName); // get ApplicationServiceProvider var pi = appAssembly.GetType(ApplicationServiceProvider._FullName).GetProperty("Instance", BindingFlags.Public | BindingFlags.Static); var _UO = pi.GetValue(null, null); CoreImpl.applicationServiceProvider = new ApplicationServiceProvider(_UO); Application.Current.MainWindow.PreviewKeyDown += MainWindow_KeyDown; var serviceUO = CoreImpl.applicationServiceProvider.GetService(CoreImpl.tyIDockViewManager); if (serviceUO != null) { try { var dockMgr = new IDockViewManager(serviceUO); AdjustHlpViwContextMenu(dockMgr.ActiveView); dockMgr.Activated += (aa, bb) => { AdjustHlpViwContextMenu(aa); }; } catch (Exception ex) { LoaderImpl.ShowException(ex); } } var ty = Application.Current.MainWindow.GetType(); var ftb = ty.GetField("viewerToolBar", BindingFlags.Instance | BindingFlags.NonPublic); if (ftb == null) { System.Windows.MessageBox.Show("viewerToolBar field is not found"); return; } var tb = ftb.GetValue(Application.Current.MainWindow) as FrameworkElement; if (tb == null) { System.Windows.MessageBox.Show("viewerToolBar instance not found"); return; } var fbd = tb.GetType().GetField("mainToolBar", BindingFlags.Instance | BindingFlags.NonPublic); if (fbd == null) { System.Windows.MessageBox.Show("viewerToolBar does not contain mainToolBar"); return; } var bd = fbd.GetValue(tb) as Border; if (bd == null) { System.Windows.MessageBox.Show("mainToolBar is not a Border"); return; } var wp = bd.Child as WrapPanel; if (bd == null) { System.Windows.MessageBox.Show("mainToolBar does not have a WrapPanel child"); return; } var mytb = new MainTool() { Margin = new Thickness(16, 0, 0, 0) }; wp.Children.Add(mytb); myTools = mytb; var fly = ty.GetField("LayoutRoot", BindingFlags.Instance | BindingFlags.NonPublic); if (fly == null) { System.Windows.MessageBox.Show("LayoutRoot field is not found"); return; } var layout = fly.GetValue(Application.Current.MainWindow) as Grid; if (layout == null) { System.Windows.MessageBox.Show("LayoutRoot is not a Grid"); return; } var ViewerStatusBar = layout.Children.OfType <FrameworkElement>().FirstOrDefault(d => d.GetType().Name == "ViewerStatusBar"); if (ViewerStatusBar != null) { var navi = new NaviTool(); navi.Height = ViewerStatusBar.ActualHeight; Grid.SetColumn(navi, Grid.GetColumn(ViewerStatusBar)); Grid.SetRow(navi, Grid.GetRow(ViewerStatusBar)); Grid.SetRowSpan(navi, Grid.GetRowSpan(ViewerStatusBar)); Grid.SetColumnSpan(navi, Grid.GetColumnSpan(ViewerStatusBar)); layout.Children.Remove(ViewerStatusBar); navi.StubContent = ViewerStatusBar; layout.Children.Add(navi); } } catch (Exception ex) { MessageBox.Show(ex.ToString()); } }