private void ProcessSitecoreEventArgsBasedRequest(EventArgs args, int parameterPosition, bool isDeleteOperation = true)
        {
            if (args == null)
                return;

            var sitecoreEventArgs = args as SitecoreEventArgs;
            if (sitecoreEventArgs == null)
                return;
            var item = sitecoreEventArgs.Parameters[parameterPosition] as Item;

            ItemSaveOnMediaTemplate(item);

            if (!EnvironmentSettings.CanEnableCDNOnServer)
                return;
            try
            {

                if (!cdnHelper.IsItemAnMediaWithCdnField(item))
                    return;

                bool status = true;
                foreach (var eachItem in cdnHelper.GetItemWithAllVersionAndLanguage(item))
                {
                    if (isDeleteOperation)//Item Deleted
                    {
                        cdnMediaItem.DeleteFile(eachItem.GetFieldValue(Constants.CdnBaseTemplateFields.UrlOnCDNServer));
                    }
                    else//Item Save Action
                    {
                        //To Skip the Update on AWS if no changes went.
                        if (//eachItem.HasValue(Constants.CdnBaseTemplateFields.UrlOnCDNServer) &&
                             eachItem.GetFieldValue(Constants.MediaTemplateFields.UpdatedOn).Equals(eachItem.GetFieldValue(Constants.CdnBaseTemplateFields.CdnSyncedOn)))
                            continue;

                        var op = cdnMediaItem.BeginUploadToCdn(eachItem);
                        status = status && (op == null || !op.Any());
                    }

                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Beispiel #2
0
        protected List <string> SyncItemsWithChildren(Item item, bool UpdateItemAsSilent = true)
        {
            var isMediaFolder = cdnHelper.IsItemAMediaFolderItem(item);

            if (!isMediaFolder && !cdnHelper.IsItemAnMediaWithCdnField(item))
            {
                return(new List <string>());
            }

            return((isMediaFolder)
                        ? SyncChildrenItems(item, UpdateItemAsSilent)
                        : SyncItemWithVersions(item, UpdateItemAsSilent).Union(SyncChildrenItems(item, UpdateItemAsSilent)).Distinct().ToList());
        }