// sync local with remote item private void SyncOneItem(ReplicatedItem replicatedItem, ConcurrentContentList items) { var local = items.Get(replicatedItem.ID); // get local match for item if (local != null && local.Published.HasValue) { if (IsSlave) // import if newer than local { if (replicatedItem.IsNewerThan(local.Published.Value) || !ExistsLocal(local)) { _journal.LogItem("import {0} published {1} vs. {2} update", replicatedItem.ID, replicatedItem.PublishedDateUtc, local.Published.Value.ToUniversalTime()); ImportItem(replicatedItem); } } if (IsMaster) { if (replicatedItem.IsOlderThan(local.Published.Value)) { _journal.LogItem("export {0} published {1} vs. {2} update", replicatedItem.ID, replicatedItem.PublishedDateUtc, local.Published.Value.ToUniversalTime()); _repstore.ExportItem(local); } } // TODO check version is bigger than replaced version items.Remove(local); } else { if (IsSlave) // TODO and newer published date { _journal.LogItem("import {0} published {1} create", replicatedItem.ID, replicatedItem.PublishedDateUtc); ImportItem(replicatedItem); } if (IsMaster) { // item is not published anymore -> delete replicated item // TODO signalling - check edge cases, e.g. non-published items that should stay _journal.LogItem("DELETE item {0} published {1}", replicatedItem.ID, replicatedItem.PublishedDateUtc); _repstore.DeleteItem(replicatedItem); } } replicatedItem.Processed = true; }
// get a list of all local page items to be synchronized private ConcurrentContentList GetLocalItems() { lock (_syncLock) { var result = new ConcurrentContentList(_finder.AllOfType <ContentItem>() .Where(p => p.IsPage && p.IsPublished() && !(p is ISystemNode))); // exclude non managed items // add root page (if exists) as that may not be derived from our page base class var rootPage = _finder.AllOfType <ContentItem>().FirstOrDefault(i => i is IRootPage); if (rootPage != null && !result.Contains(rootPage)) // avoid duplicates { result.Insert(0, rootPage); } return(result); } }