Beispiel #1
0
        //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 ?? "");
            });
        }