public bool ChangeCollection(IBlog blog, Collection oldItem, Collection newItem) { if (oldItem == null || newItem == null) { return(false); } if (QueueManager.Items.Any(x => x.Blog.Name == blog.Name && x.Blog.OriginalBlogType == blog.OriginalBlogType)) { _messageService.ShowWarning(Resources.CannotChangeCollectionOfQueuedBlog); return(false); } var oldFilenameIndex = Path.Combine(blog.Location, blog.Name) + "." + blog.OriginalBlogType; var oldFilenameChild = blog.ChildId; var newRootFolder = Path.Combine(newItem.DownloadLocation, "Index"); var newFilenameIndex = Path.Combine(newRootFolder, blog.Name) + "." + blog.OriginalBlogType; var newFilenameChild = Path.Combine(newRootFolder, Path.GetFileName(oldFilenameChild)); Directory.CreateDirectory(newRootFolder); if (File.Exists(newFilenameIndex) || File.Exists(newFilenameChild)) { _messageService.ShowWarning(Resources.CannotChangeCollectionDestFileExists); return(false); } blog.CollectionId = newItem.Id; blog.Location = newRootFolder; blog.FileDownloadLocation = null; blog.ChildId = newFilenameChild; blog.Save(); File.Delete(oldFilenameIndex); File.Move(oldFilenameChild, newFilenameChild); _managerService.BlogFiles.Remove(blog); _managerService.EnsureUniqueFolder(blog); if (blog.Dirty) { blog.Save(); } if (_shellService.Settings.LoadAllDatabases) { _managerService.RemoveDatabase(_managerService.Databases.FirstOrDefault(db => db.Name.Equals(blog.Name) && db.BlogType.Equals(blog.OriginalBlogType))); } _managerService.BlogFiles.Add(blog); if (_shellService.Settings.LoadAllDatabases) { _managerService.AddDatabase(Files.Load(blog.ChildId)); } return(true); }
public async Task Crawl(IProgress <DownloadProgress> progress, CancellationToken ct, PauseToken pt) { Logger.Verbose("TumblrDownloader.Crawl:Start"); Task grabber = GetUrlsAsync(progress, ct, pt); Task <bool> downloader = DownloadBlogAsync(progress, ct, pt); await grabber; UpdateProgressQueueInformation(progress, Resources.ProgressUniqueDownloads); blog.DuplicatePhotos = DetermineDuplicates(PostTypes.Photo); blog.DuplicateVideos = DetermineDuplicates(PostTypes.Video); blog.DuplicateAudios = DetermineDuplicates(PostTypes.Audio); blog.TotalCount = (blog.TotalCount - blog.DuplicatePhotos - blog.DuplicateAudios - blog.DuplicateVideos); CleanCollectedBlogStatistics(); await downloader; if (!ct.IsCancellationRequested) { blog.LastCompleteCrawl = DateTime.Now; } blog.Save(); UpdateProgressQueueInformation(progress, ""); }
private void SaveBlog(IBlog blog) { if (blog.Save()) { AddToManager(blog); } }
public async Task Crawl(IProgress <DownloadProgress> progress, CancellationToken ct, PauseToken pt) { Logger.Verbose("TumblrDownloader.Crawl:Start"); Task <Tuple <ulong, bool> > grabber = GetUrlsAsync(progress, ct, pt); Task <bool> downloader = DownloadBlogAsync(progress, ct, pt); Tuple <ulong, bool> grabberResult = await grabber; bool apiLimitHit = grabberResult.Item2; UpdateProgressQueueInformation(progress, Resources.ProgressUniqueDownloads); blog.DuplicatePhotos = DetermineDuplicates(PostTypes.Photo); blog.DuplicateVideos = DetermineDuplicates(PostTypes.Video); blog.DuplicateAudios = DetermineDuplicates(PostTypes.Audio); blog.TotalCount = (blog.TotalCount - blog.DuplicatePhotos - blog.DuplicateAudios - blog.DuplicateVideos); bool finishedDownloading = await downloader; if (!ct.IsCancellationRequested) { blog.LastCompleteCrawl = DateTime.Now; if (finishedDownloading && !apiLimitHit) { blog.LastId = grabberResult.Item1; } } blog.Save(); UpdateProgressQueueInformation(progress, ""); }
/// <summary> /// Upload a file to the server /// </summary> /// <param name="blogItem">The blog item the file is attached to</param> /// <param name="title">The title of the attachment</param> /// <param name="file">The raw file to be attached</param> /// <returns>The blog file that was created </returns> public BlogFile UploadFile(IBlog blog, IBlogItem blogItem, String title, IFormFile file) { // The blog file to be returned BlogFile blogFile = null; // Make sure there is actually a file if (file != null) { if (blogItem != null) { // The content of the file ready to pass to the data provider Byte[] fileContent = null; // Empty by default // Create a memory stream to read the file using (MemoryStream memoryStream = new MemoryStream()) { file.CopyTo(memoryStream); // Copy the file in to a memory stream fileContent = memoryStream.ToArray(); // convert the steam of data to a byte array memoryStream.Close(); // It's in a using anyway but just incase } // Something to save? if (fileContent != null && fileContent.Length != 0) { // Get the content header ContentDispositionHeaderValue parsedContentDisposition = ContentDispositionHeaderValue.Parse(file.ContentDisposition); // Create the new blog file for saving blogFile = new BlogFile() { Content = fileContent, Filename = parsedContentDisposition.FileName.Replace("\"", ""), Tags = new List <String>(), Title = title ?? ("File: " + Guid.NewGuid().ToString()) }; // Add the file to the blog file list blogItem.Files.Add(blogFile); // Save the blog item and with it the new file blog.Save(blogItem); } } } // Saved so do the common redirect return(blogFile); }