Ejemplo n.º 1
0
        private object ItemDataWithChildren(string id)
        {
            var  ret  = new ChildrenItemDataModel();
            Guid guid = Guid.Parse(id);

            ret.Item     = _sitecore.GetItem(guid).GetYaml();
            ret.Children = _sitecore.GetChildrenIds(guid);
            return(ret);
        }
Ejemplo n.º 2
0
 public void StartContentMigration(PullItemModel model)
 {
     _model = model;
     if (model.PullParent)
     {
         foreach (var id in model.Ids.Select(Guid.Parse).Where(x => _sitecoreAccess.GetItem(x) == null))
         {
             var item   = _remoteContent.GetRemoteItemData(id, model.Server);
             var parent = _sitecoreAccess.GetItem(item.ParentId);
             while (parent == null)
             {
                 item = _remoteContent.GetRemoteItemData(item.ParentId, model.Server);
                 _puller.ItemsToInstall.Add(item);
                 parent = _sitecoreAccess.GetItem(item.ParentId);
             }
         }
     }
     if (model.RemoveLocalNotInRemote)
     {
         _installer.SetupTrackerForUnwantedLocalItems(model.Ids.Select(Guid.Parse));
     }
     _puller.StartGatheringItems(model.Ids.Select(Guid.Parse), _registration.GetScsRegistration <ContentMigrationRegistration>().RemoteThreads, model.Children, model.Server, _cancellation);
     _installer.StartInstallingItems(model, _puller.ItemsToInstall, _registration.GetScsRegistration <ContentMigrationRegistration>().WriterThreads, _cancellation);
 }
Ejemplo n.º 3
0
        public void StartInstallingItems(PullItemModel args, BlockingCollection <IItemData> itemsToInstall, int threads, CancellationTokenSource cancellation)
        {
            Status.StartedTime = DateTime.Now;
            Status.RootNodes   = args.Ids.Select(x => new ContentTreeNode(x));
            Status.IsPreview   = args.Preview;
            Status.Server      = args.Server;
            int items = 0;

            for (int i = 0; i < threads; i++)
            {
                Task.Run(async() =>
                {
                    Thread.CurrentThread.Priority = ThreadPriority.Lowest;
                    BulkUpdateContext bu          = null;
                    EventDisabler ed = null;
                    try
                    {
                        if (args.BulkUpdate)
                        {
                            bu = new BulkUpdateContext();
                        }
                        if (args.EventDisabler)
                        {
                            ed = new EventDisabler();
                        }
                        using (new SecurityDisabler())
                        {
                            while (!Completed)
                            {
                                IItemData remoteData;
                                if (!itemsToInstall.TryTake(out remoteData, int.MaxValue, cancellation.Token))
                                {
                                    lock (_locker)
                                    {
                                        if (!Completed && !_currentlyProcessing.Any())
                                        {
                                            Finalize(items, args);
                                        }
                                    }
                                    break;
                                }
                                _currentlyProcessing.Add(remoteData.Id);
                                Item localItem      = _sitecore.GetItem(remoteData.Id);
                                IItemData localData = localItem == null ? null : new Rainbow.Storage.Sc.ItemData(localItem);
                                await ProcessItem(args, localData, remoteData, localItem);
                                lock (_locker)
                                {
                                    items++;
                                    _currentlyProcessing.Remove(remoteData.Id);
                                    if (_currentlyProcessing.Any() || !itemsToInstall.IsAddingCompleted || itemsToInstall.Count != 0)
                                    {
                                        continue;
                                    }

                                    if (!Completed)
                                    {
                                        Finalize(items, args);
                                    }
                                }
                            }
                        }
                    }
                    catch (OperationCanceledException e)
                    {
                        Log.Warn("Content migration operation was cancelled", e, this);
                        Status.Cancelled = true;
                        lock (_locker)
                        {
                            if (!Completed)
                            {
                                Finalize(items, args);
                            }
                        }
                    }
                    catch (Exception e)
                    {
                        Log.Error("Catastrophic error when installing items", e, this);
                    }
                    finally
                    {
                        if (args.BulkUpdate)
                        {
                            bu?.Dispose();
                        }
                        if (args.EventDisabler)
                        {
                            ed?.Dispose();
                        }
                    }
                });
            }
        }