public void Import(ImportSettings importSettings, ContentItem parentContentItem, ICollection <Post> posts, int batchNumber) { Console.WriteLine("Started Batch Number {0}", batchNumber); int i = 0; foreach (var post in posts) { _blogPostImportStrategy.Import(importSettings, post, parentContentItem); _contentManager.Clear(); i++; Console.WriteLine("Batch Number {0}, Imported record {1}", batchNumber, i); } Console.WriteLine("Finished Batch Number {0}", batchNumber); }
private void ImportPostsInBatches(ImportSettings importSettings, IContent parentContentItem, ICollection <Post> posts) { _contentManager.Clear(); const int batchSize = 100; int batchNo = 1; for (var i = 0; i < posts.Count; i += batchSize) { var postBatch = posts.Skip(i).Take(batchSize).ToList(); _processingEngine.AddTask( _shellSettings, _shellDescriptorManager.GetShellDescriptor(), "IScheduledBlogPostCollectionImport.Import", new Dictionary <string, object> { { "importSettings", importSettings }, { "parentContentItem", parentContentItem }, { "posts", postBatch }, { "batchNumber", batchNo } }); batchNo++; } }
public ContentItem Get(string id, string contentTypeHint = null) { var contentIdentity = new ContentIdentity(id); // lookup in local cache if (_identities.ContainsKey(contentIdentity)) { var result = _contentManager.Get(_identities[contentIdentity], VersionOptions.DraftRequired); // if two identities are conflicting, then ensure that there types are the same // e.g., importing a blog as home page (alias=) and the current home page is a page, the blog // won't be imported, and blog posts will be attached to the page if (contentTypeHint == null || result.ContentType == contentTypeHint) { return(result); } } // no result ? then check if there are some more content items to load from the db if (_lastIndex != int.MaxValue) { var equalityComparer = new ContentIdentity.ContentIdentityEqualityComparer(); IEnumerable <ContentItem> block; // load identities in blocks while ((block = _contentManager.HqlQuery() .ForVersion(VersionOptions.Latest) .OrderBy(x => x.ContentItemVersion(), x => x.Asc("Id")) .Slice(_lastIndex, BulkPage)).Any()) { foreach (var item in block) { _lastIndex++; // ignore content item if it has already been imported if (_contentItemIds.ContainsKey(item.Id)) { continue; } var identity = _contentManager.GetItemMetadata(item).Identity; // ignore content item if the same identity is already present if (_identities.ContainsKey(identity)) { continue; } _identities.Add(identity, item.Id); _contentItemIds.Add(item.Id, identity); if (equalityComparer.Equals(identity, contentIdentity)) { return(_contentManager.Get(item.Id, VersionOptions.DraftRequired)); } } _contentManager.Flush(); _contentManager.Clear(); } } _lastIndex = int.MaxValue; if (!_contentTypes.ContainsKey(contentIdentity)) { throw new ArgumentException("Unknown content type for " + id); } var contentItem = _contentManager.Create(_contentTypes[contentIdentity], VersionOptions.Draft); _identities[contentIdentity] = contentItem.Id; _contentItemIds[contentItem.Id] = contentIdentity; return(contentItem); }
public ContentItem Get(string id) { var contentIdentity = new ContentIdentity(id); // lookup in local cache if (_identities.ContainsKey(contentIdentity)) { return(_contentManager.Get(_identities[contentIdentity], VersionOptions.DraftRequired)); } // no result ? then check if there are some more content items to load from the db if (_lastIndex != int.MaxValue) { var equalityComparer = new ContentIdentity.ContentIdentityEqualityComparer(); IEnumerable <ContentItem> block; // load identities in blocks while ((block = _contentManager.HqlQuery() .ForVersion(VersionOptions.Latest) .OrderBy(x => x.ContentItemVersion(), x => x.Asc("Id")) .Slice(_lastIndex, BulkPage)).Any()) { foreach (var item in block) { _lastIndex++; // ignore content item if it has already been imported if (_contentItemIds.ContainsKey(item.Id)) { continue; } var identity = _contentManager.GetItemMetadata(item).Identity; // ignore content item if the same identity is already present if (_identities.ContainsKey(identity)) { continue; } _identities.Add(identity, item.Id); _contentItemIds.Add(item.Id, identity); if (equalityComparer.Equals(identity, contentIdentity)) { return(_contentManager.Get(item.Id, VersionOptions.DraftRequired)); } } _contentManager.Flush(); _contentManager.Clear(); } } _lastIndex = int.MaxValue; if (!_contentTypes.ContainsKey(contentIdentity)) { throw new ArgumentException("Unknown content type for " + id); } var contentItem = _contentManager.Create(_contentTypes[contentIdentity], VersionOptions.Draft); _identities.Add(contentIdentity, contentItem.Id); _contentItemIds.Add(contentItem.Id, contentIdentity); return(contentItem); }