PageRenderTime 55ms CodeModel.GetById 23ms RepoModel.GetById 1ms app.codeStats 0ms

/JMMClient/JMMClient/UserControls/UnrecognisedVideos.xaml.cs

https://bitbucket.org/gibwar/jmm-test
C# | 843 lines | 677 code | 138 blank | 28 comment | 101 complexity | 316b2f0d5a6e34bfdfad568731cd0f01 MD5 | raw file
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Windows;
  6. using System.Windows.Controls;
  7. using System.Windows.Data;
  8. using System.Windows.Documents;
  9. using System.Windows.Input;
  10. using System.Windows.Media;
  11. using System.Windows.Media.Imaging;
  12. using System.Windows.Navigation;
  13. //using System.Windows.Shapes;
  14. using System.Collections.ObjectModel;
  15. using JMMClient.ViewModel;
  16. using System.ComponentModel;
  17. using System.IO;
  18. using System.Diagnostics;
  19. using JMMClient.Forms;
  20. namespace JMMClient.UserControls
  21. {
  22. /// <summary>
  23. /// Interaction logic for UnrecognisedVideos.xaml
  24. /// </summary>
  25. public partial class UnrecognisedVideos : UserControl
  26. {
  27. public ICollectionView ViewFiles { get; set; }
  28. public ObservableCollection<VideoLocalVM> UnrecognisedFiles { get; set; }
  29. public ICollectionView ViewSeries { get; set; }
  30. public ObservableCollection<AnimeSeriesVM> AllSeries { get; set; }
  31. public static readonly DependencyProperty AnyVideosSelectedProperty = DependencyProperty.Register("AnyVideosSelected",
  32. typeof(bool), typeof(UnrecognisedVideos), new UIPropertyMetadata(false, null));
  33. public static readonly DependencyProperty OneVideoSelectedProperty = DependencyProperty.Register("OneVideoSelected",
  34. typeof(bool), typeof(UnrecognisedVideos), new UIPropertyMetadata(false, null));
  35. public static readonly DependencyProperty OneVideoTypeRangeProperty = DependencyProperty.Register("OneVideoTypeRange",
  36. typeof(bool), typeof(UnrecognisedVideos), new UIPropertyMetadata(false, null));
  37. public static readonly DependencyProperty OneVideoTypeSingleProperty = DependencyProperty.Register("OneVideoTypeSingle",
  38. typeof(bool), typeof(UnrecognisedVideos), new UIPropertyMetadata(false, null));
  39. public static readonly DependencyProperty MultipleVideosSelectedProperty = DependencyProperty.Register("MultipleVideosSelected",
  40. typeof(bool), typeof(UnrecognisedVideos), new UIPropertyMetadata(false, null));
  41. public static readonly DependencyProperty MultipleTypeRangeProperty = DependencyProperty.Register("MultipleTypeRange",
  42. typeof(bool), typeof(UnrecognisedVideos), new UIPropertyMetadata(false, null));
  43. public static readonly DependencyProperty MultipleTypeSingleProperty = DependencyProperty.Register("MultipleTypeSingle",
  44. typeof(bool), typeof(UnrecognisedVideos), new UIPropertyMetadata(false, null));
  45. public static readonly DependencyProperty FileCountProperty = DependencyProperty.Register("FileCount",
  46. typeof(int), typeof(UnrecognisedVideos), new UIPropertyMetadata(0, null));
  47. public int FileCount
  48. {
  49. get { return (int)GetValue(FileCountProperty); }
  50. set { SetValue(FileCountProperty, value); }
  51. }
  52. public bool AnyVideosSelected
  53. {
  54. get { return (bool)GetValue(AnyVideosSelectedProperty); }
  55. set { SetValue(AnyVideosSelectedProperty, value); }
  56. }
  57. public bool OneVideoSelected
  58. {
  59. get { return (bool)GetValue(OneVideoSelectedProperty); }
  60. set { SetValue(OneVideoSelectedProperty, value); }
  61. }
  62. public bool OneVideoTypeRange
  63. {
  64. get { return (bool)GetValue(OneVideoTypeRangeProperty); }
  65. set { SetValue(OneVideoTypeRangeProperty, value); }
  66. }
  67. public bool OneVideoTypeSingle
  68. {
  69. get { return (bool)GetValue(OneVideoTypeSingleProperty); }
  70. set { SetValue(OneVideoTypeSingleProperty, value); }
  71. }
  72. public bool MultipleVideosSelected
  73. {
  74. get { return (bool)GetValue(MultipleVideosSelectedProperty); }
  75. set { SetValue(MultipleVideosSelectedProperty, value); }
  76. }
  77. public bool MultipleTypeRange
  78. {
  79. get { return (bool)GetValue(MultipleTypeRangeProperty); }
  80. set { SetValue(MultipleTypeRangeProperty, value); }
  81. }
  82. public bool MultipleTypeSingle
  83. {
  84. get { return (bool)GetValue(MultipleTypeSingleProperty); }
  85. set { SetValue(MultipleTypeSingleProperty, value); }
  86. }
  87. public UnrecognisedVideos()
  88. {
  89. InitializeComponent();
  90. UnrecognisedFiles = new ObservableCollection<VideoLocalVM>();
  91. ViewFiles = CollectionViewSource.GetDefaultView(UnrecognisedFiles);
  92. ViewFiles.SortDescriptions.Add(new SortDescription("FileName", ListSortDirection.Ascending));
  93. ViewFiles.Filter = FileSearchFilter;
  94. AllSeries = new ObservableCollection<AnimeSeriesVM>();
  95. ViewSeries = CollectionViewSource.GetDefaultView(AllSeries);
  96. ViewSeries.SortDescriptions.Add(new SortDescription("SeriesName", ListSortDirection.Ascending));
  97. ViewSeries.Filter = SeriesSearchFilter;
  98. btnRefresh.Click += new RoutedEventHandler(btnRefresh_Click);
  99. btnConfirm.Click += new RoutedEventHandler(btnConfirm_Click);
  100. btnAddSeries.Click += new RoutedEventHandler(btnAddSeries_Click);
  101. btnRescan.Click += new RoutedEventHandler(btnRescan_Click);
  102. txtSeriesSearch.TextChanged += new TextChangedEventHandler(txtSeriesSearch_TextChanged);
  103. lbSeries.SelectionChanged += new SelectionChangedEventHandler(lbSeries_SelectionChanged);
  104. cboEpisodes.SelectionChanged += new SelectionChangedEventHandler(cboEpisodes_SelectionChanged);
  105. lbVideos.SelectionChanged += new SelectionChangedEventHandler(lbVideos_SelectionChanged);
  106. txtStartEpNum.TextChanged += new TextChangedEventHandler(txtStartEpNum_TextChanged);
  107. txtEndEpNumSingle.TextChanged += new TextChangedEventHandler(txtEndEpNumSingle_TextChanged);
  108. cboMultiType.Items.Add(Properties.Resources.MultiTypeRange);
  109. cboMultiType.Items.Add(Properties.Resources.MultiTypeSingle);
  110. cboMultiType.SelectedIndex = 1;
  111. cboMultiType.SelectionChanged += new SelectionChangedEventHandler(cboMultiType_SelectionChanged);
  112. SetConfirmDetails();
  113. OneVideoSelected = lbVideos.SelectedItems.Count == 1;
  114. MultipleVideosSelected = lbVideos.SelectedItems.Count > 1;
  115. btnClearSearch.Click += new RoutedEventHandler(btnClearSearch_Click);
  116. txtFileSearch.TextChanged += new TextChangedEventHandler(txtFileSearch_TextChanged);
  117. btnLogs.Click += new RoutedEventHandler(btnLogs_Click);
  118. btnRefreshSeriesList.Click += new RoutedEventHandler(btnRefreshSeriesList_Click);
  119. }
  120. void btnRefreshSeriesList_Click(object sender, RoutedEventArgs e)
  121. {
  122. try
  123. {
  124. if (!JMMServerVM.Instance.ServerOnline) return;
  125. this.Cursor = Cursors.Wait;
  126. RefreshSeries();
  127. this.Cursor = Cursors.Arrow;
  128. }
  129. catch (Exception ex)
  130. {
  131. Utils.ShowErrorMessage(ex);
  132. }
  133. finally
  134. {
  135. this.Cursor = Cursors.Arrow;
  136. }
  137. }
  138. void btnLogs_Click(object sender, RoutedEventArgs e)
  139. {
  140. try
  141. {
  142. string appPath = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location);
  143. string logPath = Path.Combine(appPath, "logs");
  144. Process.Start(new ProcessStartInfo(logPath));
  145. }
  146. catch (Exception ex)
  147. {
  148. Utils.ShowErrorMessage(ex);
  149. }
  150. }
  151. void btnRescan_Click(object sender, RoutedEventArgs e)
  152. {
  153. try
  154. {
  155. if (!JMMServerVM.Instance.ServerOnline) return;
  156. this.Cursor = Cursors.Wait;
  157. JMMServerVM.Instance.clientBinaryHTTP.RescanUnlinkedFiles();
  158. this.Cursor = Cursors.Arrow;
  159. MessageBox.Show("Files queued for AniDB scan", "Complete", MessageBoxButton.OK, MessageBoxImage.Information);
  160. }
  161. catch (Exception ex)
  162. {
  163. Utils.ShowErrorMessage(ex);
  164. }
  165. finally
  166. {
  167. this.Cursor = Cursors.Arrow;
  168. }
  169. }
  170. void txtFileSearch_TextChanged(object sender, TextChangedEventArgs e)
  171. {
  172. ViewFiles.Refresh();
  173. }
  174. void btnClearSearch_Click(object sender, RoutedEventArgs e)
  175. {
  176. txtFileSearch.Text = "";
  177. }
  178. void txtEndEpNumSingle_TextChanged(object sender, TextChangedEventArgs e)
  179. {
  180. SetConfirmDetails();
  181. }
  182. void cboMultiType_SelectionChanged(object sender, SelectionChangedEventArgs e)
  183. {
  184. SetConfirmDetails();
  185. }
  186. void btnAddSeries_Click(object sender, RoutedEventArgs e)
  187. {
  188. try
  189. {
  190. NewSeries frm = new NewSeries();
  191. frm.Owner = GetTopParent();
  192. frm.Init(0, "");
  193. bool? result = frm.ShowDialog();
  194. if (result.HasValue && result.Value == true)
  195. {
  196. RefreshSeries();
  197. AnimeSeriesVM ser = frm.AnimeSeries;
  198. txtSeriesSearch.Text = ser.AniDB_Anime.FormattedTitle;
  199. }
  200. }
  201. catch (Exception ex)
  202. {
  203. Utils.ShowErrorMessage(ex);
  204. }
  205. }
  206. private Window GetTopParent()
  207. {
  208. DependencyObject dpParent = this.Parent;
  209. do
  210. {
  211. dpParent = LogicalTreeHelper.GetParent(dpParent);
  212. }
  213. while (dpParent.GetType().BaseType != typeof(Window));
  214. return dpParent as Window;
  215. }
  216. private void EnableDisableControls(bool val)
  217. {
  218. lbSeries.IsEnabled = val;
  219. lbVideos.IsEnabled = val;
  220. btnAddSeries.IsEnabled = val;
  221. btnConfirm.IsEnabled = val;
  222. btnRefresh.IsEnabled = val;
  223. txtSeriesSearch.IsEnabled = val;
  224. txtStartEpNum.IsEnabled = val;
  225. cboEpisodes.IsEnabled = val;
  226. ccDetail.IsEnabled = val;
  227. ccDetailMultiple.IsEnabled = val;
  228. }
  229. void btnConfirm_Click(object sender, RoutedEventArgs e)
  230. {
  231. try
  232. {
  233. Window parentWindow = Window.GetWindow(this);
  234. // if only one video selected
  235. if (OneVideoSelected)
  236. {
  237. EnableDisableControls(false);
  238. VideoLocalVM vid = lbVideos.SelectedItem as VideoLocalVM;
  239. if (cboMultiType.SelectedIndex == 0)
  240. {
  241. // single file to multiple episodes
  242. // eg a file is a double episode
  243. int startEpNum = 0, endEpNum = 0;
  244. int.TryParse(txtStartEpNum.Text, out startEpNum);
  245. int.TryParse(txtEndEpNumSingle.Text, out endEpNum);
  246. string result = "";
  247. // make sure the episode range is valid
  248. // make sure the last episode number is within the valid range
  249. AnimeSeriesVM series = lbSeries.SelectedItem as AnimeSeriesVM;
  250. if (series.LatestRegularEpisodeNumber < endEpNum || startEpNum <= 0 && endEpNum <= 0 && endEpNum <= startEpNum)
  251. {
  252. // otherwise allow the user to refresh it from anidb
  253. MessageBoxResult res = MessageBox.Show(Properties.Resources.MSG_ERR_InvalidEpGetAnime, "Error", MessageBoxButton.YesNo, MessageBoxImage.Exclamation);
  254. if (res == MessageBoxResult.Yes)
  255. {
  256. result = JMMServerVM.Instance.clientBinaryHTTP.UpdateAnimeData(series.AniDB_ID);
  257. if (result.Length > 0)
  258. {
  259. MessageBox.Show(result, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
  260. EnableDisableControls(true);
  261. return;
  262. }
  263. else
  264. {
  265. // check again
  266. if (series.LatestRegularEpisodeNumber < endEpNum)
  267. {
  268. MessageBox.Show(Properties.Resources.MSG_ERR_InvalidEp, "Error", MessageBoxButton.OK, MessageBoxImage.Exclamation);
  269. EnableDisableControls(true);
  270. return;
  271. }
  272. }
  273. }
  274. else
  275. {
  276. EnableDisableControls(true);
  277. return;
  278. }
  279. }
  280. result = JMMServerVM.Instance.clientBinaryHTTP.AssociateSingleFileWithMultipleEpisodes(vid.VideoLocalID, series.AnimeSeriesID.Value, startEpNum, endEpNum);
  281. if (result.Length > 0)
  282. {
  283. MessageBox.Show(result, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
  284. }
  285. else
  286. {
  287. RefreshUnrecognisedFiles();
  288. }
  289. }
  290. else
  291. {
  292. // single file to a single episode
  293. AnimeEpisodeVM ep = cboEpisodes.SelectedItem as AnimeEpisodeVM;
  294. string result = JMMServerVM.Instance.clientBinaryHTTP.AssociateSingleFile(vid.VideoLocalID, ep.AnimeEpisodeID);
  295. if (result.Length > 0)
  296. {
  297. MessageBox.Show(result, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
  298. }
  299. else
  300. {
  301. RefreshUnrecognisedFiles();
  302. //MainListHelperVM.Instance.UpdateHeirarchy(ep, ((MainWindow)parentWindow).epListMain);
  303. MainListHelperVM.Instance.UpdateHeirarchy(ep);
  304. }
  305. }
  306. }
  307. // if multiple videos selected
  308. if (MultipleVideosSelected)
  309. {
  310. int startEpNum = 0, endEpNum = 0;
  311. int.TryParse(txtStartEpNum.Text, out startEpNum);
  312. if (MultipleTypeRange)
  313. endEpNum = startEpNum + lbVideos.SelectedItems.Count - 1;
  314. else
  315. endEpNum = startEpNum;
  316. // make sure the last episode number is within the valid range
  317. AnimeSeriesVM series = lbSeries.SelectedItem as AnimeSeriesVM;
  318. if (series.LatestRegularEpisodeNumber < endEpNum && startEpNum > 0)
  319. {
  320. // otherwise allow the user to refresh it from anidb
  321. MessageBoxResult res = MessageBox.Show(Properties.Resources.MSG_ERR_InvalidEpGetAnime, "Error", MessageBoxButton.YesNo, MessageBoxImage.Exclamation);
  322. if (res == MessageBoxResult.Yes)
  323. {
  324. string result = JMMServerVM.Instance.clientBinaryHTTP.UpdateAnimeData(series.AniDB_ID);
  325. if (result.Length > 0)
  326. {
  327. MessageBox.Show(result, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
  328. EnableDisableControls(true);
  329. return;
  330. }
  331. else
  332. {
  333. // check again
  334. if (series.LatestRegularEpisodeNumber < endEpNum)
  335. {
  336. MessageBox.Show(Properties.Resources.MSG_ERR_InvalidEp, "Error", MessageBoxButton.OK, MessageBoxImage.Exclamation);
  337. EnableDisableControls(true);
  338. return;
  339. }
  340. }
  341. }
  342. else
  343. {
  344. EnableDisableControls(true);
  345. return;
  346. }
  347. }
  348. // get all the selected videos
  349. List<int> vidIDs = new List<int>();
  350. foreach (object obj in lbVideos.SelectedItems)
  351. {
  352. VideoLocalVM vid = obj as VideoLocalVM;
  353. vidIDs.Add(vid.VideoLocalID);
  354. }
  355. string msg = JMMServerVM.Instance.clientBinaryHTTP.AssociateMultipleFiles(vidIDs, series.AnimeSeriesID.Value, startEpNum, MultipleTypeSingle);
  356. if (msg.Length > 0)
  357. {
  358. MessageBox.Show(msg, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
  359. }
  360. else
  361. {
  362. RefreshUnrecognisedFiles();
  363. //MainListHelperVM.Instance.UpdateHeirarchy(ep, ((MainWindow)parentWindow).epListMain);
  364. //ep.RefreshFilesForEpisode();
  365. }
  366. }
  367. }
  368. catch (Exception ex)
  369. {
  370. Utils.ShowErrorMessage(ex);
  371. }
  372. EnableDisableControls(true);
  373. }
  374. void txtStartEpNum_TextChanged(object sender, TextChangedEventArgs e)
  375. {
  376. SetConfirmDetails();
  377. }
  378. private void CommandBinding_OpenFolder(object sender, ExecutedRoutedEventArgs e)
  379. {
  380. object obj = e.Parameter;
  381. if (obj == null) return;
  382. if (obj.GetType() == typeof(VideoLocalVM))
  383. {
  384. VideoLocalVM vid = obj as VideoLocalVM;
  385. if (File.Exists(vid.FullPath))
  386. {
  387. Utils.OpenFolderAndSelectFile(vid.FullPath);
  388. }
  389. else
  390. {
  391. MessageBox.Show(Properties.Resources.MSG_ERR_FileNotFound, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
  392. }
  393. }
  394. }
  395. private void CommandBinding_IgnoreFile(object sender, ExecutedRoutedEventArgs e)
  396. {
  397. try
  398. {
  399. Window parentWindow = Window.GetWindow(this);
  400. object obj = e.Parameter;
  401. if (obj == null) return;
  402. if (obj.GetType() == typeof(VideoLocalVM))
  403. {
  404. VideoLocalVM vid = obj as VideoLocalVM;
  405. EnableDisableControls(false);
  406. string result = JMMServerVM.Instance.clientBinaryHTTP.SetIgnoreStatusOnFile(vid.VideoLocalID, true);
  407. if (result.Length > 0)
  408. MessageBox.Show(result, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
  409. else
  410. RefreshUnrecognisedFiles();
  411. }
  412. if (obj.GetType() == typeof(MultipleVideos))
  413. {
  414. MultipleVideos mv = obj as MultipleVideos;
  415. foreach (int id in mv.VideoLocalIDs)
  416. {
  417. string result = JMMServerVM.Instance.clientBinaryHTTP.SetIgnoreStatusOnFile(id, true);
  418. if (result.Length > 0)
  419. MessageBox.Show(result, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
  420. }
  421. RefreshUnrecognisedFiles();
  422. }
  423. }
  424. catch (Exception ex)
  425. {
  426. Utils.ShowErrorMessage(ex);
  427. }
  428. EnableDisableControls(true);
  429. }
  430. private void CommandBinding_PlayVideo(object sender, ExecutedRoutedEventArgs e)
  431. {
  432. Window parentWindow = Window.GetWindow(this);
  433. object obj = e.Parameter;
  434. if (obj == null) return;
  435. try
  436. {
  437. if (obj.GetType() == typeof(VideoLocalVM))
  438. {
  439. VideoLocalVM vid = obj as VideoLocalVM;
  440. MainWindow.videoHandler.PlayVideo(vid);
  441. }
  442. }
  443. catch (Exception ex)
  444. {
  445. Utils.ShowErrorMessage(ex);
  446. }
  447. }
  448. private void CommandBinding_DeleteFile(object sender, ExecutedRoutedEventArgs e)
  449. {
  450. try
  451. {
  452. Window parentWindow = Window.GetWindow(this);
  453. object obj = e.Parameter;
  454. if (obj == null) return;
  455. if (obj.GetType() == typeof(VideoLocalVM))
  456. {
  457. VideoLocalVM vid = obj as VideoLocalVM;
  458. MessageBoxResult res = MessageBox.Show(string.Format("Are you sure you want to delete this file: {0}", vid.FullPath),
  459. "Confirm", MessageBoxButton.YesNo, MessageBoxImage.Question);
  460. if (res == MessageBoxResult.Yes)
  461. {
  462. string result = JMMServerVM.Instance.clientBinaryHTTP.DeleteVideoLocalAndFile(vid.VideoLocalID);
  463. if (result.Length > 0)
  464. MessageBox.Show(result, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
  465. else
  466. RefreshUnrecognisedFiles();
  467. }
  468. }
  469. }
  470. catch (Exception ex)
  471. {
  472. Utils.ShowErrorMessage(ex);
  473. }
  474. }
  475. private void CommandBinding_RehashFile(object sender, ExecutedRoutedEventArgs e)
  476. {
  477. try
  478. {
  479. Window parentWindow = Window.GetWindow(this);
  480. object obj = e.Parameter;
  481. if (obj == null) return;
  482. if (obj.GetType() == typeof(VideoLocalVM))
  483. {
  484. VideoLocalVM vid = obj as VideoLocalVM;
  485. EnableDisableControls(false);
  486. JMMServerVM.Instance.clientBinaryHTTP.RehashFile(vid.VideoLocalID);
  487. }
  488. if (obj.GetType() == typeof(MultipleVideos))
  489. {
  490. MultipleVideos mv = obj as MultipleVideos;
  491. foreach (int id in mv.VideoLocalIDs)
  492. {
  493. JMMServerVM.Instance.clientBinaryHTTP.RehashFile(id);
  494. }
  495. }
  496. MessageBox.Show(Properties.Resources.MSG_INFO_AddedQueueCmds, "Done", MessageBoxButton.OK, MessageBoxImage.Information);
  497. }
  498. catch (Exception ex)
  499. {
  500. Utils.ShowErrorMessage(ex);
  501. }
  502. EnableDisableControls(true);
  503. }
  504. private void CommandBinding_RescanFile(object sender, ExecutedRoutedEventArgs e)
  505. {
  506. try
  507. {
  508. Window parentWindow = Window.GetWindow(this);
  509. object obj = e.Parameter;
  510. if (obj == null) return;
  511. if (obj.GetType() == typeof(VideoLocalVM))
  512. {
  513. VideoLocalVM vid = obj as VideoLocalVM;
  514. EnableDisableControls(false);
  515. JMMServerVM.Instance.clientBinaryHTTP.RescanFile(vid.VideoLocalID);
  516. }
  517. MessageBox.Show(Properties.Resources.MSG_INFO_AddedQueueCmds, "Done", MessageBoxButton.OK, MessageBoxImage.Information);
  518. }
  519. catch (Exception ex)
  520. {
  521. Utils.ShowErrorMessage(ex);
  522. }
  523. EnableDisableControls(true);
  524. }
  525. void lbVideos_SelectionChanged(object sender, SelectionChangedEventArgs e)
  526. {
  527. try
  528. {
  529. ccDetail.Content = null;
  530. ccDetailMultiple.Content = null;
  531. AnyVideosSelected = lbVideos.SelectedItems.Count > 0;
  532. OneVideoSelected = lbVideos.SelectedItems.Count == 1;
  533. MultipleVideosSelected = lbVideos.SelectedItems.Count > 1;
  534. MultipleTypeRange = cboMultiType.SelectedIndex == 0;
  535. MultipleTypeSingle = cboMultiType.SelectedIndex == 1;
  536. // if only one video selected
  537. if (OneVideoSelected)
  538. {
  539. VideoLocalVM vid = lbVideos.SelectedItem as VideoLocalVM;
  540. ccDetail.Content = vid;
  541. }
  542. // if only one video selected
  543. if (MultipleVideosSelected)
  544. {
  545. MultipleVideos mv = new MultipleVideos();
  546. mv.SelectedCount = lbVideos.SelectedItems.Count;
  547. mv.VideoLocalIDs = new List<int>();
  548. mv.VideoLocals = new List<VideoLocalVM>();
  549. foreach (object obj in lbVideos.SelectedItems)
  550. {
  551. VideoLocalVM vid = obj as VideoLocalVM;
  552. mv.VideoLocalIDs.Add(vid.VideoLocalID);
  553. mv.VideoLocals.Add(vid);
  554. }
  555. ccDetailMultiple.Content = mv;
  556. }
  557. SetConfirmDetails();
  558. }
  559. catch (Exception ex)
  560. {
  561. Utils.ShowErrorMessage(ex);
  562. }
  563. }
  564. void cboEpisodes_SelectionChanged(object sender, SelectionChangedEventArgs e)
  565. {
  566. SetConfirmDetails();
  567. }
  568. void lbSeries_SelectionChanged(object sender, SelectionChangedEventArgs e)
  569. {
  570. try
  571. {
  572. if (lbSeries.Items.Count == 0) return;
  573. if (lbSeries.SelectedItem == null) return;
  574. AnimeSeriesVM series = lbSeries.SelectedItem as AnimeSeriesVM;
  575. List<AnimeEpisodeVM> eps = series.AllEpisodes;
  576. List<SortPropOrFieldAndDirection> sortCriteria = new List<SortPropOrFieldAndDirection>();
  577. sortCriteria.Add(new SortPropOrFieldAndDirection("EpisodeType", false, SortType.eInteger));
  578. sortCriteria.Add(new SortPropOrFieldAndDirection("EpisodeNumber", false, SortType.eInteger));
  579. eps = Sorting.MultiSort<AnimeEpisodeVM>(eps, sortCriteria);
  580. cboEpisodes.ItemsSource = eps;
  581. if (cboEpisodes.Items.Count > 0)
  582. cboEpisodes.SelectedIndex = 0;
  583. SetConfirmDetails();
  584. }
  585. catch (Exception ex)
  586. {
  587. Utils.ShowErrorMessage(ex);
  588. }
  589. }
  590. private void SetConfirmDetails()
  591. {
  592. try
  593. {
  594. MultipleTypeRange = cboMultiType.SelectedIndex == 0;
  595. MultipleTypeSingle = cboMultiType.SelectedIndex == 1;
  596. btnConfirm.Visibility = System.Windows.Visibility.Hidden;
  597. cboEpisodes.Visibility = System.Windows.Visibility.Visible;
  598. if (lbVideos.SelectedItems.Count == 0)
  599. btnConfirm.Visibility = System.Windows.Visibility.Hidden;
  600. // evaluate selected single file
  601. if (OneVideoSelected)
  602. {
  603. if (cboMultiType.SelectedIndex == 0)
  604. {
  605. // episode range
  606. int startEpNum = 0, endEpNum = 0;
  607. int.TryParse(txtStartEpNum.Text, out startEpNum);
  608. int.TryParse(txtEndEpNumSingle.Text, out endEpNum);
  609. if (startEpNum > 0 && endEpNum > 0 && endEpNum > startEpNum)
  610. btnConfirm.Visibility = System.Windows.Visibility.Visible;
  611. }
  612. else
  613. {
  614. // single episode
  615. if (lbVideos.SelectedItem != null && cboEpisodes.SelectedItem != null)
  616. btnConfirm.Visibility = System.Windows.Visibility.Visible;
  617. }
  618. }
  619. // evaluate multiple selected files
  620. if (MultipleVideosSelected)
  621. {
  622. if (cboMultiType.SelectedIndex == 0)
  623. {
  624. // episode range
  625. int startEpNum = 0;
  626. int.TryParse(txtStartEpNum.Text, out startEpNum);
  627. if (startEpNum > 0)
  628. {
  629. btnConfirm.Visibility = System.Windows.Visibility.Visible;
  630. int endEpNum = startEpNum + lbVideos.SelectedItems.Count - 1;
  631. txtEndEpNum.Text = endEpNum.ToString();
  632. }
  633. }
  634. else
  635. {
  636. // single episode
  637. if (cboEpisodes.SelectedItem != null)
  638. btnConfirm.Visibility = System.Windows.Visibility.Visible;
  639. }
  640. }
  641. }
  642. catch (Exception ex)
  643. {
  644. Utils.ShowErrorMessage(ex);
  645. }
  646. }
  647. void txtSeriesSearch_TextChanged(object sender, TextChangedEventArgs e)
  648. {
  649. ViewSeries.Refresh();
  650. }
  651. void btnRefresh_Click(object sender, RoutedEventArgs e)
  652. {
  653. RefreshUnrecognisedFiles();
  654. }
  655. public void RefreshUnrecognisedFiles()
  656. {
  657. try
  658. {
  659. UnrecognisedFiles.Clear();
  660. if (!JMMServerVM.Instance.ServerOnline) return;
  661. List<JMMServerBinary.Contract_VideoLocal> vids = JMMServerVM.Instance.clientBinaryHTTP.GetUnrecognisedFiles(JMMServerVM.Instance.CurrentUser.JMMUserID.Value);
  662. FileCount = vids.Count;
  663. foreach (JMMServerBinary.Contract_VideoLocal vid in vids)
  664. {
  665. UnrecognisedFiles.Add(new VideoLocalVM(vid));
  666. }
  667. }
  668. catch (Exception ex)
  669. {
  670. Utils.ShowErrorMessage(ex);
  671. }
  672. }
  673. public void RefreshSeries()
  674. {
  675. try
  676. {
  677. MainListHelperVM.Instance.AllAnimeDetailedDictionary = null;
  678. AllSeries.Clear();
  679. if (!JMMServerVM.Instance.ServerOnline) return;
  680. foreach (JMMServerBinary.Contract_AnimeSeries ser in JMMServerVM.Instance.clientBinaryHTTP.GetAllSeries(JMMServerVM.Instance.CurrentUser.JMMUserID.Value))
  681. {
  682. AllSeries.Add(new AnimeSeriesVM(ser));
  683. }
  684. }
  685. catch (Exception ex)
  686. {
  687. Utils.ShowErrorMessage(ex);
  688. }
  689. }
  690. private bool SeriesSearchFilter(object obj)
  691. {
  692. AnimeSeriesVM servm = obj as AnimeSeriesVM;
  693. if (servm == null) return true;
  694. return GroupSearchFilterHelper.EvaluateSeriesTextSearch(servm, txtSeriesSearch.Text);
  695. }
  696. private bool FileSearchFilter(object obj)
  697. {
  698. VideoLocalVM vid = obj as VideoLocalVM;
  699. if (vid == null) return true;
  700. int index = vid.FilePath.IndexOf(txtFileSearch.Text.Trim(), 0, StringComparison.InvariantCultureIgnoreCase);
  701. if (index > -1) return true;
  702. return false;
  703. }
  704. }
  705. }