Esempio n. 1
0
 public void StartContentMigration(PullItemModel model)
 {
     _model = model;
     if (model.PullParent)
     {
         foreach (var id in model.Ids.Select(Guid.Parse).Where(x => _sitecoreAccess.GetItemData(x) == null))
         {
             var item   = _remoteContent.GetRemoteItemData(id, model.Server);
             var parent = _sitecoreAccess.GetItemData(item.ParentId);
             while (parent == null)
             {
                 item = _remoteContent.GetRemoteItemData(item.ParentId, model.Server);
                 _puller.ItemsToInstall.Add(item);
                 parent = _sitecoreAccess.GetItemData(item.ParentId);
             }
         }
     }
     Task.Run(() =>
     {
         if (model.RemoveLocalNotInRemote)
         {
             _installer.SetupTrackerForUnwantedLocalItems(model.Ids.Select(Guid.Parse));
         }
         _puller.StartGatheringItems(model.Ids.Select(Guid.Parse), _registration.GetScsRegistration <ContentMigrationRegistration>()?.RemoteThreads ?? 1, model.Children, model.Server, _cancellation.Token, model.IgnoreRevId);
         _installer.StartInstallingItems(model, _puller.ItemsToInstall, _registration.GetScsRegistration <ContentMigrationRegistration>()?.WriterThreads ?? 1, _cancellation.Token);
     });
 }
        public void BuildDiff(string server)
        {
            Compare = new Dictionary <string, List <Tuple <string, string> > >();
            IItemData itemData = null;

            itemData = _remoteContent.GetRemoteItemData(Guid.Parse(Id), server);
            using (new SecurityDisabler())
            {
                var localItem = Factory.GetDatabase("master", true).DataManager.DataEngine.GetItem(new ID(Id), LanguageManager.DefaultLanguage, Sitecore.Data.Version.Latest);

                foreach (var chk in itemData.SharedFields)
                {
                    if (AreFieldsEqual(localItem.Fields[new ID(chk.FieldId)], chk))
                    {
                        continue;
                    }

                    if (!Compare.ContainsKey("shared"))
                    {
                        Compare["shared"] = new List <Tuple <string, string> >();
                    }

                    Compare["shared"].Add(chk.BlobId != null
                                                ? new Tuple <string, string>(chk.NameHint, "Blob value changed")
                                                : new Tuple <string, string>(chk.NameHint, HtmlDiff.HtmlDiff.Execute(HttpUtility.HtmlEncode(localItem[new ID(chk.FieldId)].Replace("\r", "")), HttpUtility.HtmlEncode(chk.Value.Replace("\r", "")))));
                }
                Dictionary <string, int> tracker = new Dictionary <string, int>();
                foreach (var ver in itemData.Versions)
                {
                    if (!tracker.ContainsKey(LanguageManager.GetLanguage(ver.Language.Name).Name))
                    {
                        tracker.Add(LanguageManager.GetLanguage(ver.Language.Name).Name, 1);
                    }
                    else
                    {
                        tracker[LanguageManager.GetLanguage(ver.Language.Name).Name]++;
                    }
                    Item verItem = localItem.Database.DataManager.DataEngine.GetItem(new ID(Id), LanguageManager.GetLanguage(ver.Language.Name), Version.Parse(ver.VersionNumber));
                    foreach (var verfield in ver.Fields)
                    {
                        if (AreFieldsEqual(verItem.Fields[new ID(verfield.FieldId)], verfield))
                        {
                            continue;
                        }
                        string key = ver.Language.Name + " v" + ver.VersionNumber;
                        if (!Compare.ContainsKey(key))
                        {
                            Compare[key] = new List <Tuple <string, string> >();
                        }
                        Compare[key].Add(verfield.BlobId != null
                                                        ? new Tuple <string, string>(verfield.NameHint, "Blob value changed")
                                                        : new Tuple <string, string>(verfield.NameHint, HtmlDiff.HtmlDiff.Execute(HttpUtility.HtmlEncode(localItem[new ID(verfield.FieldId)].Replace("\r", "")), HttpUtility.HtmlEncode(verfield.Value.Replace("\r", "")))));
                    }
                }
                foreach (var lang in localItem.Languages.Where(x => !tracker.ContainsKey(x.Name)))
                {
                    Item langItem = localItem.Database.DataManager.DataEngine.GetItem(new ID(Id), lang, Version.Latest);
                    for (int ver = 1; ver <= langItem.Versions.Count; ver++)
                    {
                        string key = "Extra version";
                        if (!Compare.ContainsKey(key))
                        {
                            Compare[key] = new List <Tuple <string, string> >();
                        }
                        Compare[key].Add(new Tuple <string, string>("Extra local version exists that's not on the remote.", $"{lang.Name} v{ver}"));
                    }
                }
                foreach (var lang in localItem.Languages.Where(x => tracker.ContainsKey(x.Name)))
                {
                    Item langItem = localItem.Database.DataManager.DataEngine.GetItem(new ID(Id), lang, Version.Latest);
                    for (int ver = tracker[lang.Name] + 1; ver <= langItem.Versions.Count; ver++)
                    {
                        string key = "Extra version";
                        if (!Compare.ContainsKey(key))
                        {
                            Compare[key] = new List <Tuple <string, string> >();
                        }
                        Compare[key].Add(new Tuple <string, string>("Extra local version exists that's not on the remote.", $"{lang.Name} v{ver}"));
                    }
                }
                foreach (var unver in itemData.UnversionedFields)
                {
                    Item verItem = localItem.Database.DataManager.DataEngine.GetItem(new ID(Id), LanguageManager.GetLanguage(unver.Language.Name), Version.Latest);
                    foreach (var unverfield in unver.Fields)
                    {
                        if (AreFieldsEqual(verItem.Fields[new ID(unverfield.FieldId)], unverfield))
                        {
                            continue;
                        }
                        if (!Compare.ContainsKey(unver.Language.Name))
                        {
                            Compare[verItem.Language.Name] = new List <Tuple <string, string> >();
                        }
                        Compare[unver.Language.Name].Add(unverfield.BlobId != null
                                                        ? new Tuple <string, string>(unverfield.NameHint, "Blob value changed")
                                                        : new Tuple <string, string>(unverfield.NameHint, HtmlDiff.HtmlDiff.Execute(HttpUtility.HtmlEncode(localItem[new ID(unverfield.FieldId)].Replace("\r", "")), HttpUtility.HtmlEncode(unverfield.Value.Replace("\r", "")))));
                    }
                }
            }
        }