private void tryloadUri() { try { string text = Clipboard.GetText(); URLInfo = RemoteUrl.Parse(text) as IRemoteUrl; if (URLInfo != null) { DownloadUri = text; } } catch { } }
public void TestRemoteUrl() { VideoInfo[] vInfos = new VideoInfo[] { new VideoInfo("video1", 2, "Name1"), new VideoInfo("video2", 2), }; IUrl url = new RemoteUrl("127.0.0.1", 10000, new DateTime(2016, 1, 1), new DateTime(2016, 1, 2), vInfos, @"d:\path"); string urlString = url.ToString(); Console.WriteLine(urlString); var urlNew = RemoteUrl.Parse(urlString); Assert.AreEqual(url.LocalPath, urlNew.LocalPath); Assert.AreEqual(url.VideoInfos.Length, urlNew.VideoInfos.Length); (url as RemoteUrl).CheckValid(); }
private void this_PropertyChanged(object sender, PropertyChangedEventArgs e) { switch (e.PropertyName) { case nameof(DownloadUri): URLInfo = null; ErrorInfo = null; IsEnabledDirectory = false; IsEnabledDownload = false; VideoInfos = new ObservableCollection <DownloadVideoInfo>(); try { URLInfo = RemoteUrl.Parse(DownloadUri) as IRemoteUrl; BeginTime = toShowTime(URLInfo.BeginTime); EndTime = toShowTime(URLInfo.EndTime); DownloadName = GlobalProcess.GetFolderName(URLInfo); foreach (VideoInfo vi in URLInfo.VideoInfos) { VideoInfos.Add(new DownloadVideoInfo() { VideoId = vi.VideoId, VideoName = string.IsNullOrWhiteSpace(vi.VideoName)? "未知名称": vi.VideoName, StreamId = vi.StreamId, }); } if (!string.IsNullOrWhiteSpace(URLInfo.LocalPath)) { DownloadDirectory = new DirectoryInfo(URLInfo.LocalPath).FullName; } else { IsEnabledDirectory = true; } IsEnabledDownload = true; } catch (Exception ex) { ErrorInfo = ex.Message; initData(); } break; } }
public void TestRemoteUrl_Pause() { string urlStr = @"CCTV2:REMOTE/time=63587203200-63587289600/source=127.0.0.1:10000/path=d:\path/videos=video1,2,Name1|video2,2"; var url = RemoteUrl.Parse(urlStr); Assert.AreEqual(2, url.VideoInfos.Length); string invalidUrlStr0 = @"CCTV1:REMOTE/time=63587203200-63587289600/source=127.0.0.1:10000/path=d:\path/videos=video1,2,Name1|video2,2"; ExceptionManager.CheckInvalidOperationException(() => RemoteUrl.Parse(invalidUrlStr0)); string invalidUrlStr1 = @"CCTV2:LOCAL/time=63587203200-63587289600/source=127.0.0.1:10000/path=d:\path/videos=video1,2,Name1|video2,2"; Assert.IsNull(RemoteUrl.Parse(invalidUrlStr1)); string invalidUrlStr2 = @"CCTV2:REMOTE/time=63587203200-63587289600/source=127.0.0.1:10000/path=d:\path/videos=video1,2,Name1|video2"; ExceptionManager.CheckInvalidOperationException(() => RemoteUrl.Parse(invalidUrlStr2)); string invalidUrlStr3 = @"CCTV2:REMOTE/time=63587203200-63587289600/source=127.0.0.1:10000/"; var url3 = RemoteUrl.Parse(invalidUrlStr3); Assert.AreEqual(invalidUrlStr3, url3.ToString()); }
private void btnOk_Click(object sender, RoutedEventArgs e) { try { IRemoteUrl ui = RemoteUrl.Parse(txtUrl.Text.Trim()) as IRemoteUrl; if (ui == null) { DialogUtil.ShowWarning("不支持导入数据源格式。"); return; } ImportUrl = ui; this.DialogResult = true; this.Close(); } catch (Exception ex) { Common.Log.Logger.Default.Error(ex); DialogUtil.ShowError(ex.Message); } }
private void initSettings(string[] args) { if (args.Length > 0) { string url = args[0]; try { IUrl ui = null; try { ui = LocalUrl.Parse(url); } catch { } if (ui == null) { try { ui = RemoteUrl.Parse(url); } catch { } } if (ui != null) { return; } if (!tryToRemote(url)) { throw new ErrorMessageException("URL未能正确解析!"); } } catch (ErrorMessageException ae) { Common.Log.Logger.Default.Error(ae); Util.DialogUtil.ShowError(ae.Message); } } }