Esempio n. 1
0
        private static void ProcessHistoryEnginePackage(RemotingPackage package, IConfiguration configuration, DateTime ifModifiedSince)
        {
            // TODO: need to "coalesce" history so we are not replaying more events than we need to
            // e.g. create then move in one sync will cause the created item to not be present as a serialized item
            // in the package because it was moved so the create fails

            package.Manifest.Strategy = RemotingStrategy.Differential;

            using (new SecurityDisabler())
            {
                var serializationProvider = package.SerializationProvider;

                var roots = configuration.Resolve <PredicateRootPathResolver>().GetRootSourceItems();

                var historyDatabases = roots.Select(x => x.DatabaseName).Distinct().Select(Factory.GetDatabase).ToArray();

                foreach (var historyDatabase in historyDatabases)
                {
                    var localHistory = GetMergedHistory(ifModifiedSince, historyDatabase);

                    foreach (var historyEntry in localHistory)
                    {
                        if (historyEntry.Action == HistoryAction.Moved)
                        {
                            var item = historyDatabase.GetItem(historyEntry.ItemId);

                            if (item == null)
                            {
                                continue;                                           // invalid history entry - item deleted
                            }
                            var manifestEntry = RemotingPackageManifestEntry.FromEntry(historyEntry, historyDatabase.Name);

                            manifestEntry.OldItemPath = historyEntry.ItemPath;                    // on a moved entry, the itempath is the pre-move path
                            manifestEntry.ItemPath    = item.Paths.Path;                          // the path from the Item is the post-move path

                            package.Manifest.AddEntry(manifestEntry);
                        }
                        else if (historyEntry.Action == HistoryAction.Deleted)
                        {
                            package.Manifest.AddEntry(RemotingPackageManifestEntry.FromEntry(historyEntry, historyDatabase.Name));
                        }
                        else
                        {
                            var item = historyDatabase.GetItem(historyEntry.ItemId);

                            if (item == null)
                            {
                                continue;                                           // invalid history entry - item deleted
                            }
                            // serialize updated item to package directory
                            serializationProvider.SerializeItem(new SitecoreSourceItem(item));

                            package.Manifest.AddEntry(RemotingPackageManifestEntry.FromEntry(historyEntry, historyDatabase.Name));
                        }
                    }
                }

                package.Manifest.LastSynchronized = DateTime.UtcNow;
            }
        }