Exemple #1
0
        /// <summary>
        /// rename / move a file
        /// </summary>
        /// <param name="sourceFileName">source pathname</param>
        /// <param name="destinationFileName">destination pathname</param>
        /// <param name="allowOverwrite">set to true to overwrite an existing destination file</param>
        public void FileRename(string sourceFileName, string destinationFileName, bool allowOverwrite)
        {
            if (MtpPath.IsMtpPath(sourceFileName) || MtpPath.IsMtpPath(destinationFileName))
            {
                throw new NotImplementedException();
            }

            _fileUtilities.FileRename(sourceFileName, destinationFileName, allowOverwrite);
        }
        void ClientDownloadFileCompleted(object sender, AsyncCompletedEventArgs e)
        {
            StatusUpdateEventArgs args = null;

            lock (_lock)
            {
                var syncItem = e.UserState as SyncItem;
                if (syncItem == null)
                {
                    args = new StatusUpdateEventArgs(StatusUpdateLevel.Error, "Missing token from download completed", false, null);
                }
                else if (e.Cancelled)
                {
                    args = new StatusUpdateEventArgs(StatusUpdateLevel.Status, string.Format(CultureInfo.InvariantCulture, "{0} Cancelled", syncItem.EpisodeTitle), false, syncItem);
                }
                else if (e.Error != null && e.Error.InnerException != null)
                {
                    args = new StatusUpdateEventArgs(StatusUpdateLevel.Error, string.Format(CultureInfo.InvariantCulture, "Error in: {0}", syncItem.EpisodeTitle), e.Error.InnerException, false, syncItem);
                }
                else if (e.Error != null)
                {
                    args = new StatusUpdateEventArgs(StatusUpdateLevel.Error, string.Format(CultureInfo.InvariantCulture, "Error in: {0}", syncItem.EpisodeTitle), e.Error, false, syncItem);
                }
                else
                {
                    args = new StatusUpdateEventArgs(StatusUpdateLevel.Status, string.Format(CultureInfo.InvariantCulture, "{0} Completed", syncItem.EpisodeTitle), true, syncItem);

                    _fileUtilities.FileRename(GetDownloadFilename(), _syncItem.DestinationPath, true);
                    RecordHighTideMark(syncItem);
                    ExecutePostDownloadCommand();
                }

                OnStatusUpdate(args);

                _client.Dispose();
                _client = null;

                _complete = true;
                _counterFactory.CreateAverageCounter(Constants.PodcastUtilitiesCommonCounterCategory,
                                                     Constants.AverageTimeToDownload,
                                                     Constants.NumberOfDownloads).RegisterTime(_stopWatch);
                _counterFactory.CreateAverageCounter(Constants.PodcastUtilitiesCommonCounterCategory,
                                                     Constants.AverageMBDownload,
                                                     Constants.SizeOfDownloads).RegisterValue(ConvertBytesToMB(_bytesDownloaded));
                TaskComplete.Set();
            }
        }