protected override void Ready( ) { ResourceProxy proxy = new ResourceProxy(_resource); proxy.BeginUpdate(); if (!Successfull) { proxy.SetProp(Props.EnclosureDownloadingState, DownloadState.Failed); string lastException = null; if (LastException != null) { lastException = LastException.Message; } proxy.SetProp(Props.EnclosureFailureReason, lastException); proxy.DeleteProp(Props.EnclosureTempFile); ShowDesktopAlert(DownloadState.Failed, "Downloading Failed", _resource.DisplayName, lastException); } else { proxy.SetProp(Props.EnclosureDownloadingState, DownloadState.Completed); ShowDesktopAlert(DownloadState.Completed, "Downloading Completed", _resource.DisplayName, null); } proxy.EndUpdate(); _queued = false; EnclosureDownloadManager.DownloadNextEnclosure(); }
public static void Do(DateTime at, IResource feedItem) { string enclosureUrl = feedItem.GetPropText(Props.EnclosureURL).Trim(); if (enclosureUrl.Length == 0) { return; } IResource feed = feedItem.GetLinkProp(-Props.RSSItem); string directory = FindDownloadDirectory(feedItem, feed); try { Directory.CreateDirectory(directory); string destFullPath = null; FileStream file = null; int startPosition = 0; if (feedItem.GetIntProp(Props.EnclosureDownloadingState) == DownloadState.InProgress) { string enclosureTempFile = feedItem.GetPropText(Props.EnclosureTempFile); if (File.Exists(enclosureTempFile)) { try { file = File.OpenWrite(enclosureTempFile); destFullPath = enclosureTempFile; startPosition = (int)file.Length; file.Seek(startPosition, SeekOrigin.Begin); } catch (Exception exception) { Tracer._TraceException(exception); } } } if (destFullPath == null && file == null) { destFullPath = FindFreeFileName(enclosureUrl, directory, true); file = File.Create(destFullPath); } new ResourceProxy(feedItem).SetProp(Props.EnclosureTempFile, destFullPath); Core.NetworkAP.QueueJobAt(at, new DownloadEnclosure(feedItem, file, directory, startPosition)); _queued = true; } catch (Exception exception) { _queued = false; ResourceProxy proxy = new ResourceProxy(feedItem); proxy.BeginUpdate(); proxy.SetProp(Props.EnclosureDownloadingState, DownloadState.Failed); proxy.SetProp(Props.EnclosureFailureReason, exception.Message); proxy.EndUpdate(); ShowDesktopAlert(DownloadState.Failed, "Downloading Failed", feedItem.DisplayName, exception.Message); EnclosureDownloadManager.DownloadNextEnclosure(); } }
public override void OK() { _chkDownloadPeriod.Checked = _chkDownloadPeriod.Checked && _edtStartDownload.TimeParseable() && _edtFinishDownload.TimeParseable(); Settings.EnclosureDownloadStartHour.Save(_edtStartDownload.Value); Settings.EnclosureDownloadFinishHour.Save(_edtFinishDownload.Value); Settings.EnclosurePath.Save(_browseForFolderControl.SelectedPath); SettingSaver.Save(Controls); Settings.LoadSettings(); Core.ResourceAP.QueueJob(new UpdateDefaultsDelegate(UpdateDefaults), _oldUpdateFrequency, _oldUpdatePeriod); EnclosureDownloadManager.DownloadNextEnclosure(); }
protected override void Execute() { if (_resource.Id != -1 && _resource.GetIntProp(Props.EnclosureDownloadingState) != DownloadState.NotDownloaded) { // Determine if we want update some of the resource properties (create proxy for that) int nTotalLength = GetLength(); bool bUpdateState = _resource.GetIntProp(Props.EnclosureDownloadingState) != DownloadState.InProgress; bool bUpdateLength = ((nTotalLength > 0) && (nTotalLength != _resource.GetIntProp(Props.EnclosureSize))); if ((bUpdateState) || (bUpdateLength)) { ResourceProxy proxy = new ResourceProxy(_resource); proxy.BeginUpdate(); if (bUpdateState) { proxy.SetProp(Props.EnclosureDownloadingState, DownloadState.InProgress); } if (bUpdateLength) { proxy.SetProp(Props.EnclosureSize, nTotalLength + _startPosition); } proxy.EndUpdateAsync(); } // Check if the downloaded size should be updated // As we take the actual size from the disc file, not from the property, its accuracy is not needed; overwrite the property only if the percent value changes, as it's used only for the percentage display if (nTotalLength > 0) // The total-size info is available (if it's not, we do not have the percentage anyway) { int nSize = GetDownloadedSize(); // Size we've downloaded int nOldSize = _resource.GetIntProp(Props.EnclosureDownloadedSize); // The prev size property value if ((nSize * 100 / nTotalLength) != (nOldSize * 100 / nTotalLength)) // Percentage has changed, should write a new value { Core.UserInterfaceAP.QueueJob("Update Enclosure Downloaded Size", new UpdateDownloadedSizeDelegate(UpdateDownloadedSize), nSize); // Schedulle to the UI AP so that it merges the too-frequent updates for enclosures that download too fast, that reduces flicker } } // Do the download step base.Execute(); } else { InvokeAfterWait(null, null); new ResourceProxy(_resource).SetProp(Props.EnclosureDownloadingState, DownloadState.NotDownloaded); _queued = false; EnclosureDownloadManager.DownloadNextEnclosure(); } }