private void WebView_NavigationStarting(object sender, WebViewControlNavigationStartingEventArgs e) { Debug.WriteLine(callerName()); if (IsMain) { if (Keyboard.IsKeyDown(Key.LeftCtrl)) { RequestLoadInSubview.OnNext(e.Uri.ToString()); e.Cancel = true; return; } } if (!Keyboard.IsKeyDown(Key.LeftCtrl)) { var driver = DxxDriverManager.Instance.FindDriver(e.Uri.ToString()); if (driver != null) { var du = new DxxUrl(e.Uri, driver, driver.GetNameFromUri(e.Uri, "link"), ""); if (du.IsContainer || du.IsTarget) { if (IsMain) { MainViewBeginAutoDownload.OnNext(du); } DxxDriverManager.Instance.Download(e.Uri.ToString(), null, ""); e.Cancel = true; return; } } } LMonitor.Renew(); UpdateHistory(); }
private void InitializeProperties() { IsDownloadable = IsContainer.CombineLatest(IsTarget, (c, t) => { return(c || t); }).ToReadOnlyReactiveProperty(); Url.Subscribe((v) => { var driver = DxxDriverManager.Instance.FindDriver(v); if (driver != null) { Driver.Value = driver; Uri uri = new Uri(v); var dxxUrl = new DxxUrl(uri, driver, driver.GetNameFromUri(uri, "main"), ""); IsTarget.Value = driver.LinkExtractor.IsTarget(dxxUrl); IsContainer.Value = driver.LinkExtractor.IsContainer(dxxUrl); IsContainerList.Value = driver.LinkExtractor.IsContainerList(dxxUrl); } else { Driver.Value = DxxDriverManager.NOP; IsTarget.Value = false; IsContainer.Value = false; IsContainerList.Value = false; } IsBookmarked.Value = Bookmarks.Value.FindBookmark(v) != null; }); }
//struct Pending { // public enum Command { // None, // Load, // GoBack, // GoForward, // Reload, // } // public Command Waiting; // public string Url; // public Pending(Command cmd, string url=null) { // Waiting = Command.None; // Url = null; // } //} //Pending PendingCommand = new Pending(Pending.Command.None); void Navigate(string url) { var uri = DxxUrl.FixUpUrl(url); if (null == uri) { return; } Browser?.Navigate(url); }
public async void Download(IEnumerable <DxxTargetInfo> targets) { if (Utils.IsNullOrEmpty(targets)) { return; } await DxxActivityWatcher.Instance.Execute <object>(async (cancellationToken) => { try { foreach (var t in targets) { cancellationToken.ThrowIfCancellationRequested(); var driver = DxxDriverManager.Instance.FindDriver(t.Url); if (driver != null) { if (driver.LinkExtractor.IsTarget(t)) { driver.Download(t); } else { var du = new DxxUrl(t, driver); var cnt = await driver.LinkExtractor.ExtractContainerList(du); if (cnt != null && cnt.Count > 0) { DxxLogger.Instance.Comment(LOG_CAT, $"{cnt.Count} containers in {du.FileName}"); Download(cnt); } var tgt = await driver.LinkExtractor.ExtractTargets(du); if (tgt != null && tgt.Count > 0) { DxxLogger.Instance.Comment(LOG_CAT, $"{tgt.Count} targets in {du.FileName}"); Download(tgt); } } } } } catch (Exception e) { if (e is OperationCanceledException) { DxxLogger.Instance.Cancel(LOG_CAT, "Download Cancelled."); } else { DxxLogger.Instance.Error(LOG_CAT, $"Download Error: {e.Message}"); } } return(null); }, null); }
//private DxxUrl CreateDxxUrl() { // var driver = Driver.Value; // var uri = new Uri(Url.Value); // return new DxxUrl(uri, driver, driver.GetNameFromUri(uri, "link"), IsMain ? "from main" : "from sub"); //} private void InitializeCommands() { GoBackCommand.Subscribe(() => { GoBack(); }); GoForwardCommand.Subscribe(() => { GoForward(); }); ReloadCommand.Subscribe(() => { Reload(); }); StopCommand.Subscribe(() => { Stop(); }); BookmarkCommand.Subscribe((v) => { if (string.IsNullOrEmpty(v) || !v.StartsWith("http")) { IsBookmarked.Value = false; return; } if (IsBookmarked.Value) { Bookmarks.Value.AddBookmark("", v); } else { Bookmarks.Value.RemoveBookmark(v); Url.Value = v; } }); NavigateCommand.Subscribe((v) => { Navigate(v); }); ClearURLCommand.Subscribe((v) => { Url.Value = ""; }); AnalyzeCommand.Subscribe((v) => { if (v == null) { v = Url.Value; } var aw = new DxxAnalysisWindow(v); //aw.Owner = Owner; aw.Show(); }); CopyCommand.Subscribe((v) => { Clipboard.SetData(DataFormats.Text, v); }); DownloadCommand.Subscribe(() => { if (IsTarget.Value || IsContainer.Value) { DxxDriverManager.Instance.Download(Url.Value, null, ""); } }); ListingCommand.Subscribe(async() => { if (IsContainerList.Value) { var uri = new Uri(Url.Value); var dxxUrl = new DxxUrl(uri, Driver.Value, Driver.Value.GetNameFromUri(uri), ""); var targets = await Driver.Value.LinkExtractor.ExtractTargets(dxxUrl); if (targets != null && targets.Count > 0) { TargetList.Value = new ObservableCollection <DxxTargetInfo>(targets); } else { TargetList.Value?.Clear(); } } }); SetupDriverCommand.Subscribe(() => { DxxDriverManager.Instance.Setup(Driver.Value, Owner); }); FrameSelectCommand.Subscribe((v) => { if (IsMain) { RequestLoadInSubview.OnNext(v); } else { Navigate(v); } }); }
private void InitializeCommands() { BeginAnalysis.Subscribe((v) => { BaseUrl.Value = EnsureUri(v)?.ToString(); Load(); }); ApplyXPath.Subscribe((v) => { SetXPath(v); }); CopyLinkUrl.Subscribe((v) => { Debug.WriteLine(v.Value); var url = EnsureUri(v.Value)?.ToString(); if (url != null) { Clipboard.SetData(DataFormats.Text, url); } }); ExecuteLinkUrl.Subscribe((v) => { Debug.WriteLine(v); var url = EnsureUri(v.Value)?.ToString(); if (url != null) { try { System.Diagnostics.Process.Start(url); } catch (Exception ex) { Debug.WriteLine(ex.ToString()); } } }); AnalizeLinkUrl.Subscribe((v) => { Debug.WriteLine(v); BeginAnalysis.Execute(v.Value); }); AnalizeNewLinkUrl.Subscribe((v) => { Debug.WriteLine(v); var url = EnsureUri(v.Value)?.ToString(); if (url != null) { var aw = new DxxAnalysisWindow(url); aw.Show(); } }); DownloadLinkUrl.Subscribe((v) => { using (var dlg = new CommonSaveFileDialog("Download to file.")) { var uri = EnsureUri(v.Value); if (uri != null) { var ti = new DxxTargetInfo(uri, DxxUrl.GetFileName(uri), ""); dlg.OverwritePrompt = true; dlg.DefaultFileName = DxxUrl.TrimName(ti.Name); dlg.RestoreDirectory = true; if (dlg.ShowDialog(Owner) == CommonFileDialogResult.Ok) { DxxDownloader.Instance.Reserve(ti, dlg.FileName, 0, (f) => { Owner.Dispatcher.InvokeAsync(() => { if (f == DxxDownloadingItem.DownloadStatus.Completed) { DxxFileDispositionDialog.Show(dlg.FileName, Owner); } }); }); } } } }); SelectParent.Subscribe((v) => { var parent = v.Node.ParentNode; if (null != parent) { ApplyXPath.Execute(parent.XPath); } }); SelectThisNode.Subscribe((v) => { //Debug.WriteLine(v); ApplyXPath.Execute(v.Node.XPath); }); CopyAttrName.Subscribe((v) => { Clipboard.SetData(DataFormats.Text, v.Name); }); CopyAttrValue.Subscribe((v) => { Clipboard.SetData(DataFormats.Text, v.Value ?? ""); }); }