예제 #1
0
        internal void ProcessItem(PullItemModel args, IItemData localData, IItemData remoteData)
        {
            AllowedItems.Remove(remoteData.Id);
            if (args.Preview)
            {
                if (localData != null)
                {
                    var results = _comparer.Compare(remoteData, localData);
                    if (results.AreEqual)
                    {
                        _logger.BeginEvent(remoteData, LogStatus.Skipped, GetSrc(_sitecore.GetIconSrc(localData)), false);
                    }
                    else if (results.IsMoved)
                    {
                        _logger.BeginEvent(remoteData, LogStatus.Moved, GetSrc(_sitecore.GetIconSrc(localData)), false);
                    }
                    else if (results.IsRenamed)
                    {
                        _logger.BeginEvent(remoteData, LogStatus.Renamed, GetSrc(_sitecore.GetIconSrc(localData)), false);
                    }
                    else if (results.IsTemplateChanged)
                    {
                        _logger.BeginEvent(remoteData, LogStatus.TemplateChange, GetSrc(_sitecore.GetIconSrc(localData)), false);
                    }
                    else if (args.Overwrite)
                    {
                        _logger.BeginEvent(remoteData, LogStatus.Changed, GetSrc(_sitecore.GetIconSrc(localData)), false);
                    }
                    else
                    {
                        _logger.BeginEvent(remoteData, LogStatus.Skipped, GetSrc(_sitecore.GetIconSrc(localData)), false);
                    }
                }
                else
                {
                    _logger.BeginEvent(remoteData, LogStatus.Created, "", false);
                }
            }
            else
            {
                bool skip = false;
                if (!args.Overwrite && localData != null)
                {
                    _logger.BeginEvent(remoteData, LogStatus.Skipped, GetSrc(_sitecore.GetIconSrc(localData)), false);
                    skip = true;
                }
                if (!skip && localData != null)
                {
                    var results = _comparer.Compare(remoteData, localData);
                    if (results.AreEqual)
                    {
                        _logger.BeginEvent(remoteData, LogStatus.Skipped, GetSrc(_sitecore.GetIconSrc(localData)), false);
                        skip = true;
                    }
                }
                else if (!skip && !args.UseItemBlaster)
                {
                    while (CurrentlyProcessing.Contains(remoteData.ParentId))
                    {
                        if (Errors.Contains(remoteData.ParentId))
                        {
                            Errors.Add(remoteData.Id);
                            skip = true;
                            break;
                        }

                        Task.Delay(WaitForParentDelay).Wait();
                    }
                }
                if (!skip)
                {
                    try
                    {
                        if (localData != null || !args.UseItemBlaster)
                        {
                            _logger.BeginEvent(remoteData, LogStatus.Changed, GetSrc(_sitecore.GetIconSrc(localData)), true);
                            _scDatastore.Save(remoteData);
                        }
                        else if (args.UseItemBlaster)
                        {
                            string icon = remoteData.SharedFields.FirstOrDefault(x => x.NameHint == "__Icon")?.Value;
                            if (string.IsNullOrWhiteSpace(icon))
                            {
                                icon = _sitecore.GetIcon(remoteData.TemplateId);
                            }
                            _logger.BeginEvent(remoteData, LogStatus.Created, $"/scs/platform/scsicon.scsvc?icon={icon}", false);
                            _logger.AddToLog($"{DateTime.Now:h:mm:ss tt} [Created] Staging creation of item using Data Blaster {remoteData.Name} - {remoteData.Id}");
                            _itemsToCreate.Add(remoteData);
                        }
                        else
                        {
                            _scDatastore.Save(remoteData);
                        }
                    }
                    catch (TemplateMissingFieldException tm)
                    {
                        _logger.BeginEvent(new ErrorItemData()
                        {
                            Name = remoteData.Name, Path = tm.ToString()
                        }, LogStatus.Warning, "", false);
                    }
                    catch (ParentItemNotFoundException)
                    {
                        _logger.BeginEvent(remoteData, LogStatus.SkippedParentError, "", false);
                        Errors.Add(remoteData.Id);
                    }
                    catch (Exception e)
                    {
                        Errors.Add(remoteData.Id);
                        _logger.BeginEvent(new ErrorItemData()
                        {
                            Name = remoteData?.Name ?? "Unknown item", Path = e.ToString()
                        }, LogStatus.Error, "", false);
                    }
                    if (localData != null)
                    {
                        if (_logger.HasLinesSupportEvents(localData.Id.ToString()))
                        {
                            _logger.CompleteEvent(localData.Id.ToString());
                        }
                        else
                        {
                            _logger.BeginEvent(localData, LogStatus.Skipped, _logger.GetSrc(GetSrc(_sitecore.GetIconSrc(localData))), false);
                        }
                    }
                }
            }
        }
        internal async Task ProcessItem(PullItemModel args, IItemData localData, IItemData remoteData)
        {
            AllowedItems.Remove(remoteData.Id);
            if (args.Preview)
            {
                if (localData != null)
                {
                    var results = _comparer.Compare(remoteData, localData);
                    if (results.AreEqual)
                    {
                        _logger.BeginEvent(remoteData, LogStatus.Skipped, GetSrc(_sitecore.GetIconSrc(localData)), false);
                    }
                    else if (results.IsMoved)
                    {
                        _logger.BeginEvent(remoteData, LogStatus.Moved, GetSrc(_sitecore.GetIconSrc(localData)), false);
                    }
                    else if (results.IsRenamed)
                    {
                        _logger.BeginEvent(remoteData, LogStatus.Renamed, GetSrc(_sitecore.GetIconSrc(localData)), false);
                    }
                    else if (results.IsTemplateChanged)
                    {
                        _logger.BeginEvent(remoteData, LogStatus.TemplateChange, GetSrc(_sitecore.GetIconSrc(localData)), false);
                    }
                    else if (args.Overwrite)
                    {
                        _logger.BeginEvent(remoteData, LogStatus.Changed, GetSrc(_sitecore.GetIconSrc(localData)), false);
                    }
                    else
                    {
                        _logger.BeginEvent(remoteData, LogStatus.Skipped, GetSrc(_sitecore.GetIconSrc(localData)), false);
                    }
                }
                else
                {
                    _logger.BeginEvent(remoteData, LogStatus.Created, "", false);
                }
            }
            else
            {
                bool skip = false;
                if (!args.Overwrite && localData != null)
                {
                    _logger.BeginEvent(remoteData, LogStatus.Skipped, GetSrc(_sitecore.GetIconSrc(localData)), false);
                    skip = true;
                }
                if (!skip && localData != null)
                {
                    var results = _comparer.Compare(remoteData, localData);
                    if (results.AreEqual)
                    {
                        _logger.BeginEvent(remoteData, LogStatus.Skipped, GetSrc(_sitecore.GetIconSrc(localData)), false);
                        skip = true;
                    }
                }
                else if (!skip)
                {
                    while (CurrentlyProcessing.Contains(remoteData.ParentId))
                    {
                        if (Errors.Contains(remoteData.ParentId))
                        {
                            Errors.Add(remoteData.Id);
                            skip = true;
                            break;
                        }

                        await Task.Delay(WaitForParentDelay).ConfigureAwait(false);
                    }
                }
                if (!skip)
                {
                    try
                    {
                        if (localData != null)
                        {
                            _logger.BeginEvent(remoteData, LogStatus.Changed, _logger.GetSrc(GetSrc(_sitecore.GetIconSrc(localData))), true);
                        }
                        _scDatastore.Save(remoteData);
                    }
                    catch (TemplateMissingFieldException tm)
                    {
                        _logger.BeginEvent(new ErrorItemData()
                        {
                            Name = remoteData.Name, Path = tm.ToString()
                        }, LogStatus.Warning, "", false);
                    }
                    catch (ParentItemNotFoundException)
                    {
                        _logger.BeginEvent(remoteData, LogStatus.SkippedParentError, "", false);
                        Errors.Add(remoteData.Id);
                    }
                    catch (Exception e)
                    {
                        Errors.Add(remoteData.Id);
                        _logger.BeginEvent(new ErrorItemData()
                        {
                            Name = remoteData?.Name ?? "Unknown item", Path = e.ToString()
                        }, LogStatus.Error, "", false);
                    }
                    if (localData != null)
                    {
                        if (!_logger.HasLinesSupportEvents(localData.Id.ToString()))
                        {
                            _logger.CompleteEvent(localData.Id.ToString());
                        }
                        else
                        {
                            _logger.BeginEvent(localData, LogStatus.Skipped, _logger.GetSrc(GetSrc(_sitecore.GetIconSrc(localData))), false);
                        }
                    }
                }
            }
        }