Пример #1
0
        public override void Process(MediaSyncItemImportArgs args)
        {
            Assert.ArgumentNotNull(args, "args");
            Assert.ArgumentNotNull(args.Entity, "args.Entity");
            Assert.ArgumentNotNull(args.AccountItem, "args.AccountItem");
            Assert.ArgumentNotNull(args.Synchronizer, "args.Synchronizer");

            if (!this.ValidateActivity(args, SyncAllowActivity.DatabaseFallback))
            {
                return;
            }

            if (args.SearchResultItem == null && args.Item == null)
            {
                args.SearchResultItem = args.Synchronizer.Fallback(args.Entity, args.AccountItem);

                if (args.SearchResultItem != null)
                {
                    LogHelper.Debug("Search result item has been found by fallback. SearchResult:" + args.SearchResultItem.Uri, this);
                }
                else
                {
                    LogHelper.Debug("Search result item does not found by fallback. Entity:" + args.Entity, this);
                }
            }
        }
        protected virtual bool ValidateActivity(MediaSyncItemImportArgs args, SyncAllowActivity allowActivity)
        {
            if ((args.SyncAllowActivity & allowActivity) != allowActivity)
            {
                LogHelper.Debug(string.Format("{0} is not enabled. Entity:{1}", allowActivity, args.Entity), this);
                return(false);
            }

            return(true);
        }
        protected virtual Item GetItem(MediaSyncItemImportArgs args)
        {
            if (args.Item != null)
            {
                return(args.Item);
            }

            if (args.SearchResultItem != null)
            {
                //TODO:try catch & logs
                return(args.SearchResultItem.GetItem());
            }

            return(null);
        }
        public override void Process(MediaSyncItemImportArgs args)
        {
            Assert.ArgumentNotNull(args, "args");
            Assert.ArgumentNotNull(args.Entity, "args.Entity");
            Assert.ArgumentNotNull(args.AccountItem, "args.AccountItem");
            Assert.ArgumentNotNull(args.Synchronizer, "args.Synchronizer");

            if (!this.ValidateActivity(args, SyncAllowActivity.SyncReferences))
            {
                return;
            }

            if (args.Synchronizer.References.Count > 0)
            {
                LogHelper.Debug(string.Format("{0} has {1} reference synchronizers", args.Synchronizer.GetType().Name, args.Synchronizer.References.Count), this);
            }
            else
            {
                return;
            }

            Item item = this.GetItem(args);

            if (this.CheckEdit(item))
            {
                LogHelper.Debug(string.Format("Item({0}) references sync has been started", item.ID), this);

                foreach (var reference in args.Synchronizer.References)
                {
                    Item syncItem = reference.SyncReference(args.Entity, args.AccountItem, item);

                    LogHelper.Debug(string.Format("Item({0}) reference has been sync by: {1}.", item.ID, reference.GetType().Name), this);

                    if (args.Item == null)
                    {
                        args.Item = syncItem;
                    }
                }

                //args.Item = args.Synchronizer.SyncReferences(args.Entity, args.AccountItem, item) ?? args.Item;
            }
            else
            {
                LogHelper.Debug("Item is null. Entity:" + args.Entity, this);
            }
        }
        public override void Process(MediaSyncItemImportArgs args)
        {
            Assert.ArgumentNotNull(args, "args");
            Assert.ArgumentNotNull(args.Entity, "args.Entity");
            Assert.ArgumentNotNull(args.AccountItem, "args.AccountItem");
            Assert.ArgumentNotNull(args.Synchronizer, "args.Synchronizer");

            if (!this.ValidateActivity(args, SyncAllowActivity.UpdateItem))
            {
                return;
            }

            Item item = this.GetItemForUpdate(args);

            if (this.CheckEdit(item))
            {
                args.Item = args.Synchronizer.UpdateItem(args.Entity, args.AccountItem, item);
            }
        }
        public override void Process(MediaSyncItemImportArgs args)
        {
            Assert.ArgumentNotNull(args, "args");
            Assert.ArgumentNotNull(args.Entity, "args.Entity");
            Assert.ArgumentNotNull(args.AccountItem, "args.AccountItem");
            Assert.ArgumentNotNull(args.Synchronizer, "args.Synchronizer");

            if (!this.ValidateActivity(args, SyncAllowActivity.CreateItem))
            {
                return;
            }

            if (args.SearchResultItem == null && args.Item == null)
            {
                Item rootItem = args.Synchronizer.GetRootItem(args.Entity, args.AccountItem);

                if (this.CheckCreate(rootItem))
                {
                    var mediaData = args.Synchronizer.GetMediaData(args.Entity);

                    string itemName = ItemUtil.ProposeValidItemName(mediaData.EntityName);

                    ID itemId = this.GenerateItemId(args.AccountItem, mediaData);

                    args.Item = this.Create(itemName, mediaData.TemplateId, rootItem, itemId);

                    if (args.Item != null)
                    {
                        LogHelper.Debug(string.Format("Item has been created. Entity:{0}; Item: {1}", args.Entity, args.Item.Uri), this);
                    }
                    else
                    {
                        LogHelper.Debug("Item could not be created. Entity:" + args.Entity, this);
                    }
                }
            }
        }
        protected virtual Item GetItemForUpdate(MediaSyncItemImportArgs args)
        {
            if (args.Item != null)
            {
                return(args.Item);
            }

            if (args.SearchResultItem != null)
            {
                if (args.Synchronizer.NeedUpdate(args.Entity, args.AccountItem, args.SearchResultItem))
                {
                    LogHelper.Debug("NeedUpdate returns 'true'. SearchResult:" + args.SearchResultItem.Uri, this);

                    return(args.SearchResultItem.GetItem());
                }
                LogHelper.Debug("NeedUpdate returns 'false'. SearchResult:" + args.SearchResultItem.Uri, this);
            }
            else
            {
                LogHelper.Debug("SearchResultItem is null. Entity:" + args.Entity, this);
            }

            return(null);
        }
 /// <summary>
 /// Ingests items
 /// </summary>
 /// <param name="args">
 /// The args.
 /// </param>
 public abstract void Process(MediaSyncItemImportArgs args);
 /// <summary>
 /// The run.
 /// </summary>
 /// <param name="args">
 /// The args.
 /// </param>
 public static void Run(MediaSyncItemImportArgs args)
 {
     Assert.ArgumentNotNull(args, "args");
     CorePipeline.Run("mediaFramework.mediaSyncItemImport", args);
 }