Esempio n. 1
0
        public AddDownloadViewModel(AddItemsAsyncDelegate addItemsAsync, ShowPreviewDelegate showPreview)
        {
            _addItemsAsync = addItemsAsync;
            AddCommand     = new RelayCommand <object>(Add, Add_CanExecute);
            PreviewCommand = new RelayCommand <object>(Preview, Add_CanExecute);

            _clipboardService = new ClipboardObserver();

            if (Settings.Default.LastSavedLocation.Trim().Length > 0)
            {
                this.SaveToFolder = Settings.Default.LastSavedLocation;
            }
            else
            {
                this.SaveToFolder = AppPaths.DownloadsFolder;
            }
            this.AddToQueue    = Settings.Default.AddItemsToQueue;
            this.StartDownload = Settings.Default.StartDownloadingAddedItems;
            this.Urls          = string.Empty;
            this.ShowPreview   = showPreview;

            var clipText = _clipboardService.GetText();

            if (clipText.Contains("http") || clipText.Contains("ftp"))
            {
                this.Urls += clipText.Trim() + "\n";
            }
        }
Esempio n. 2
0
        private async Task MonitorClipboardAsync()
        {
            _ctsClipboard = new CancellationTokenSource();

            while (!_ctsClipboard.Token.IsCancellationRequested)
            {
                List <string> source = Regex.Replace(_clipboardService.GetText(), @"\t|\r", "").Split('\n').ToList();
                List <string> dest   = Regex.Replace(this.Urls, @"\r|\t", "").Split('\n').ToList();
                foreach (var url in source)
                {
                    var f_url = Regex.Replace(url, @"\n", "");
                    if ((f_url.Contains("http") || f_url.Contains("ftp")) && !dest.Contains(f_url))
                    {
                        this.Urls += f_url + '\n';
                        _clipboardService.Clear();
                    }
                }
                RaisePropertyChanged(nameof(this.Urls));
                await Task.Delay(1000);
            }

            _ctsClipboard = null;
        }