private object ItemDataWithChildren(string id)
        {
            var  ret  = new ChildrenItemDataModel();
            Guid guid = Guid.Parse(id);

            ret.Item     = _yamlSerializationService.SerializeYaml(_sitecore.GetItemData(guid));
            ret.Children = _sitecore.GetChildrenIds(guid);
            return(ret);
        }
Example #2
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);
        }
 internal void GatherItems(bool getChildren, string server, CancellationToken cancellationToken, bool ignoreRevId)
 {
     while (!Completed)
     {
         try
         {
             Guid id;
             if (!ProcessingIds.TryTake(out id, int.MaxValue, cancellationToken))
             {
                 break;
             }
             lock (_locker)
                 _processing++;
             ChildrenItemDataModel remoteContentItem = _remoteContent.GetRemoteItemDataWithChildren(id, server, ignoreRevId ? null : _sitecore.GetItemAndChildrenRevision(id));
             foreach (var item in (getChildren ? remoteContentItem.Items : remoteContentItem.Items.Where(x => x.Key == id)))
             {
                 if (item.Value != null)
                 {
                     IItemData itemData = _yamlSerializationService.DeserializeYaml(item.Value, item.Key.ToString());
                     GatheredRemoteItems.Add(itemData, cancellationToken);
                 }
                 else
                 {
                     GatheredRemoteItems.Add(_sitecore.GetItemData(item.Key), cancellationToken);
                 }
             }
             if (getChildren && remoteContentItem.GrandChildren != null)
             {
                 foreach (var child in remoteContentItem.GrandChildren)
                 {
                     ProcessingIds.Add(child, cancellationToken);
                 }
             }
         }
         catch (OperationCanceledException e)
         {
             _log.Warn("Content migration operation was cancelled", e, this);
             break;
         }
         catch (Exception e)
         {
             _log.Error("error processing ids to gather remote content", e, this);
         }
         lock (_locker)
         {
             _processing--;
             if (_processing > 0 || ProcessingIds.Count != 0)
             {
                 continue;
             }
         }
         Completed = true;
         ProcessingIds.CompleteAdding();
         GatheredRemoteItems.CompleteAdding();
     }
 }
 internal void GatherItems(bool getChildren, string server, CancellationToken cancellationToken)
 {
     while (!Completed)
     {
         try
         {
             Guid id;
             if (!ProcessingIds.TryTake(out id, int.MaxValue, cancellationToken))
             {
                 break;
             }
             lock (_locker)
                 _processing++;
             ChildrenItemDataModel remoteContentItem = _remoteContent.GetRemoteItemDataWithChildren(id, server);
             IItemData             itemData          = _yamlSerializationService.DeserializeYaml(remoteContentItem.Item, id.ToString());
             GatheredRemoteItems.Add(itemData, cancellationToken);
             if (getChildren && remoteContentItem.Children != null)
             {
                 foreach (var child in remoteContentItem.Children)
                 {
                     ProcessingIds.Add(child, cancellationToken);
                 }
             }
         }
         catch (OperationCanceledException e)
         {
             _log.Warn("Content migration operation was cancelled", e, this);
             break;
         }
         catch (Exception e)
         {
             _log.Error("error processing ids to gather remote content", e, this);
         }
         lock (_locker)
         {
             _processing--;
             if (_processing > 0 || ProcessingIds.Count != 0)
             {
                 continue;
             }
         }
         Completed = true;
         ProcessingIds.CompleteAdding();
         GatheredRemoteItems.CompleteAdding();
     }
 }
        public void StartGatheringItems(IEnumerable <Guid> rootIds, int threads, bool getChildren, string server, CancellationTokenSource cancellation)
        {
            int processing = 0;

            foreach (Guid id in rootIds)
            {
                _processingIds.Add(id);
            }
            for (int i = 0; i < threads; i++)
            {
                Task.Run(() =>
                {
                    Thread.CurrentThread.Priority = ThreadPriority.Lowest;
                    while (!Completed)
                    {
                        try
                        {
                            Guid id;
                            if (!_processingIds.TryTake(out id, int.MaxValue, cancellation.Token))
                            {
                                break;
                            }
                            lock (_locker)
                                processing++;
                            ChildrenItemDataModel remoteContentItem = _remoteContent.GetRemoteItemDataWithChildren(id, server);
                            IItemData itemData = DeserializeYaml(remoteContentItem.Item, id.ToString());
                            _gatheredRemoteItems.Add(itemData);
                            if (getChildren)
                            {
                                foreach (var child in remoteContentItem.Children)
                                {
                                    _processingIds.Add(child);
                                }
                            }
                        }
                        catch (OperationCanceledException e)
                        {
                            Log.Warn("Content migration operation was cancelled", e, this);
                            lock (_locker)
                            {
                                processing--;
                                if (processing > 0 || _processingIds.Count != 0)
                                {
                                    continue;
                                }
                            }
                            Completed = true;
                            _processingIds.CompleteAdding();
                            _gatheredRemoteItems.CompleteAdding();
                            break;
                        }
                        catch (Exception e)
                        {
                            Log.Error("error processing ids to gather remote content", e, this);
                        }
                        lock (_locker)
                        {
                            processing--;
                            if (processing > 0 || _processingIds.Count != 0)
                            {
                                continue;
                            }
                        }
                        Completed = true;
                        _processingIds.CompleteAdding();
                        _gatheredRemoteItems.CompleteAdding();
                    }
                });
            }
        }