private void FileAdded(object sender, ObservedListEventArgs observedListEventArgs) { var itemAdded = observedListEventArgs.Item as FtpListItem; if (itemAdded == null) return; downloadList.SafeInvoke(x => x.Items.Add(itemAdded.Name)); }
private void downloadListOnOnAdd(object sender, ObservedListEventArgs observedListEventArgs) { var item = observedListEventArgs.Item as FtpListItem; if (item != null && _viewModel.DownloadList.All(x => x.Item.FullName != item.FullName)) { if (_factory == null) { _factory = new MediaFactory(); } MainWindowDownloadList itemToAdd; var status = observedListEventArgs.IsPriority ? "Found - Priority" : "Found"; try { var media = _factory.CreateMediaObject(item.Name); itemToAdd = new MainWindowDownloadList { Item = item, Status = status, ParsedName = media.DisplayName, ParsedType = media.TypeName }; } catch { itemToAdd = new MainWindowDownloadList { Item = item, Status = status, ParsedName = "", ParsedType = "" }; } var firstFound = _viewModel.DownloadList.FirstOrDefault(x => x.Status == "Found"); var index = _viewModel.DownloadList.IndexOf(firstFound); if (observedListEventArgs.IsPriority && index >= 0) { Application.Current.Dispatcher.Invoke(delegate { _viewModel.DownloadList.Insert(index, itemToAdd); }); } else { Application.Current.Dispatcher.Invoke(delegate { _viewModel.DownloadList.Add(itemToAdd); }); } } foreach ( var expiredItem in _viewModel.DownloadList.Where(x => x.LastUpdated <= DateTime.Now.AddDays(-1) && x.Status == "Moved").ToList()) { Application.Current.Dispatcher.Invoke(delegate { _viewModel.DownloadList.Remove(expiredItem); }); } }
private void RemoveFileFromList(object sender, ObservedListEventArgs observedListEventArgs) { var itemRemoved = observedListEventArgs.Item as FtpListItem; if (itemRemoved == null) return; downloadList.SafeInvoke(x => x.Items.Remove(itemRemoved.Name)); }