コード例 #1
0
        /// <summary>
        /// Method is processing integration config or integration folder item.
        /// </summary>
        /// <param name="processIntegrationItemsOptions">The process integration items options.</param>
        /// <param name="integrationConfigDataSource">The item which contains integration config data.</param>
        public virtual void ProcessTree([NotNull] ProcessIntegrationItemsOptions processIntegrationItemsOptions, [NotNull] Item integrationConfigDataSource)
        {
            Assert.ArgumentNotNull(processIntegrationItemsOptions, "processIntegrationItemsOptions");
            Assert.ArgumentNotNull(integrationConfigDataSource, "integrationConfigDataSource");

            CacheableIntegrationConfigData it = IntegrationCache.GetIntegrationConfigData(integrationConfigDataSource.ID);

            if (!IntegrationDisabler.CurrentValue && (processIntegrationItemsOptions.Force || it == null || it.IsExpired))
            {
                using (new IntegrationDisabler())
                {
                    SynchContext synchContext;
                    try
                    {
                        synchContext = new SynchContext(integrationConfigDataSource);
                    }
                    catch (Exception ex)
                    {
                        Log.Error(string.Format("Synchronization context can not be created for \"{0}\" integration config data source item.", integrationConfigDataSource.Name), ex, this);
                        return;
                    }

                    IntegrationPipelinesRunner.SynchronizeTree(processIntegrationItemsOptions, synchContext);
                }
            }
        }
コード例 #2
0
        /// <summary>
        /// Methos is deleting item in SharePoint.
        /// </summary>
        /// <param name="sharepointItemUniqueID">The sharepoint unique id.</param>
        /// <param name="integrationConfigDataSource">The item which contains integration config data for the target intergation item.</param>
        public static bool DeleteSharepointItem([NotNull] string sharepointItemUniqueID, [NotNull] Item integrationConfigDataSource)
        {
            Assert.ArgumentNotNull(sharepointItemUniqueID, "sharepointItemUniqueID");
            Assert.ArgumentNotNull(integrationConfigDataSource, "integrationConfigDataSource");

            var synchContext = new SynchContext(integrationConfigDataSource);

            ProcessSharepointItemArgs pipelineArgs = IntegrationPipelinesRunner.DeleteSharepointItem(sharepointItemUniqueID, synchContext);

            return(pipelineArgs != null);
        }
コード例 #3
0
        public static FolderItem CreateFolderItem([NotNull] string itemName, [NotNull] SynchContext synchContext)
        {
            Assert.ArgumentNotNull(itemName, "itemName");
            Assert.ArgumentNotNull(synchContext, "synchContext");

            var folderItem = new FolderItem(itemName, synchContext.IntegrationConfigData.Folder, synchContext.IntegrationConfigData.List, new Uri(StringUtil.RemovePostfix('/', synchContext.IntegrationConfigData.Server) + StringUtil.EnsurePrefix('/', synchContext.IntegrationConfigData.Web)), synchContext.Context);

            folderItem.Update();

            return(folderItem);
        }
コード例 #4
0
        public static SharepointBaseItem CreateSharepointItem([NotNull] string itemName, [NotNull] Item destination, [NotNull] ID templateId)
        {
            Assert.ArgumentNotNull(itemName, "itemName");
            Assert.ArgumentNotNull(destination, "destination");
            Assert.ArgumentNotNull(templateId, "templateId");

            var synchContext = new SynchContext(destination);

            ProcessSharepointItemArgs pipelineArgs = IntegrationPipelinesRunner.CreateSharepointItem(itemName, templateId, synchContext);

            return(pipelineArgs != null ? pipelineArgs.SharepointItem : null);
        }
コード例 #5
0
        public static DocumentItem CreateDocumentItem([NotNull] string itemName, [NotNull] SynchContext synchContext, Stream stream = null)
        {
            Assert.ArgumentNotNull(itemName, "itemName");
            Assert.ArgumentNotNull(synchContext, "synchContext");

            var documentItem = new DocumentItem(itemName, synchContext.IntegrationConfigData.Folder, synchContext.IntegrationConfigData.List, new Uri(StringUtil.RemovePostfix('/', synchContext.IntegrationConfigData.Server) + StringUtil.EnsurePrefix('/', synchContext.IntegrationConfigData.Web)), synchContext.Context);

            documentItem.SetStream(stream ?? Stream.Null);
            documentItem.Update();

            return(documentItem);
        }
コード例 #6
0
        public static void UpdateItem(
            [NotNull] Item sourceIntegrationItem,
            [NotNull] SharepointBaseItem targetSharepointItem,
            [NotNull] SynchContext synchContext)
        {
            Assert.ArgumentNotNull(sourceIntegrationItem, "sourceIntegrationItem");
            Assert.ArgumentNotNull(targetSharepointItem, "targetSharepointItem");
            Assert.ArgumentNotNull(synchContext, "synchContext");

            CopyFieldValues(sourceIntegrationItem, targetSharepointItem, synchContext.IntegrationConfigData);

            var documentItem = targetSharepointItem as DocumentItem;

            if (documentItem != null)
            {
                CopyBlobValue(sourceIntegrationItem, documentItem);
            }

            targetSharepointItem.Update();
        }
コード例 #7
0
        public static bool UpdateSharepointItem([NotNull] Item sourceIntegrationItem)
        {
            Assert.ArgumentNotNull(sourceIntegrationItem, "sourceIntegrationItem");

            CacheableIntegrationItemInfo cacheableIntegrationItemInfo = IntegrationCache.GetIntegrationItemInfo(sourceIntegrationItem.ID);

            if (cacheableIntegrationItemInfo == null)
            {
                Log.Warn("Can't find item in the Sharepoint cache and so can't update Sharepoint item. ", sourceIntegrationItem);
                return(false);
            }

            var synchContext = new SynchContext(cacheableIntegrationItemInfo.ParentItemId, sourceIntegrationItem.Database);

            ProcessSharepointItemArgs pipelineArgs = IntegrationPipelinesRunner.UpdateSharepointItem(
                cacheableIntegrationItemInfo.SharepointItemId,
                sourceIntegrationItem,
                synchContext);

            return(pipelineArgs != null);
        }
コード例 #8
0
        public static Item CreateItem(
            [NotNull] ID integrationItemID,
            [NotNull] ID integrationItemTemplateID,
            [NotNull] SharepointBaseItem sourceSharepointItem,
            [NotNull] SynchContext synchContext)
        {
            Assert.ArgumentNotNull(integrationItemID, "integrationItemID");
            Assert.ArgumentNotNull(integrationItemTemplateID, "integrationItemTemplateID");
            Assert.ArgumentNotNull(sourceSharepointItem, "sourceSharepointItem");
            Assert.ArgumentNotNull(synchContext, "synchContext");

            var validName = MediaPathManager.ProposeValidMediaPath(sourceSharepointItem.Title);

            Item integrationItem = ItemManager.AddFromTemplate(validName, integrationItemTemplateID, synchContext.ParentItem, integrationItemID);

            var folderItem = sourceSharepointItem as FolderItem;

            if (folderItem != null && integrationItem != null)
            {
                UpdateIntegrationConfigData(integrationItem, folderItem, synchContext);
            }

            return(integrationItem);
        }
コード例 #9
0
        protected virtual void ProcessTree([NotNull] ProcessIntegrationItemsOptions processIntegrationItemsOptions, [NotNull] SynchContext synchContext)
        {
            Assert.ArgumentNotNull(processIntegrationItemsOptions, "processIntegrationItemsOptions");
            Assert.ArgumentNotNull(synchContext, "synchContext");

            IntegrationCache.AddIntegrationConfigData(synchContext.ParentID, synchContext.IntegrationConfigData, (synchContext.IntegrationConfigData.ExpirationInterval > 0) ? synchContext.IntegrationConfigData.ExpirationInterval : DefaultTimeout);

            // IDList existenChildrenList = new IDList();
            // foreach (Item it in SynchContext.ParentItem.GetChildren())
            // {
            //   existenChildrenList.Add(it.ID);
            // }
            IDList existenChildrenList = synchContext.Database.DataManager.DataSource.GetChildIDs(synchContext.ParentID);

            var existenList = new List <ID>(existenChildrenList.Cast <ID>());

            foreach (SharepointBaseItem listItem in this.GetSubItems(this.GetList(synchContext.IntegrationConfigData), synchContext.IntegrationConfigData))
            {
                ID id = Utils.GetID(synchContext.ParentID.ToString(), listItem.UniqueID);

                bool itemExist = existenList.IndexOf(id) != -1;

                if (Switcher <bool, SynchDisabler> .CurrentValue == false)
                {
                    if (itemExist)
                    {
                        if (IsActiveIntegrationDataItem(id, synchContext.Database))
                        {
                            IntegrationPipelinesRunner.UpdateIntegrationItem(id, listItem, synchContext, processIntegrationItemsOptions, EventSender.Sharepoint);
                        }

                        existenChildrenList.Remove(id);
                    }
                    else
                    {
                        IntegrationPipelinesRunner.CreateIntegrationItem(id, listItem, synchContext, processIntegrationItemsOptions, EventSender.Sharepoint);
                    }
                }

                if (listItem is FolderItem)
                {
                    if (IsActiveIntegrationDataItem(id, synchContext.Database))
                    {
                        var newSynchContext = new SynchContext(id, synchContext.Database);
                        if (processIntegrationItemsOptions.Recursive)
                        {
                            ProcessTree(processIntegrationItemsOptions, newSynchContext);
                        }
                    }
                }

                IntegrationCache.AddIntegrationItemInfo(id, listItem, synchContext.ParentID, (synchContext.IntegrationConfigData.ExpirationInterval > 0) ? synchContext.IntegrationConfigData.ExpirationInterval : DefaultTimeout);
            }

            if (Switcher <bool, SynchDisabler> .CurrentValue == false)
            {
                foreach (ID id in existenChildrenList)
                {
                    if (IsActiveIntegrationDataItem(id, synchContext.Database))
                    {
                        IntegrationPipelinesRunner.DeleteIntegrationItem(id, synchContext);
                    }
                }
            }
        }
コード例 #10
0
        /// <summary>
        /// Update fields of integration item in CMS from SharePoint.
        /// </summary>
        /// <param name="targetIntegrationItem">The item.</param>
        /// <param name="sourceSharepointItem">The source.</param>
        /// <param name="synchContext">The synchronization context.</param>
        public static void UpdateFields([NotNull] Item targetIntegrationItem, [NotNull] SharepointBaseItem sourceSharepointItem, [NotNull] SynchContext synchContext)
        {
            Assert.ArgumentNotNull(targetIntegrationItem, "targetIntegrationItem");
            Assert.ArgumentNotNull(sourceSharepointItem, "sourceSharepointItem");
            Assert.ArgumentNotNull(synchContext, "synchContext");

            var folderItem = sourceSharepointItem as FolderItem;

            if (folderItem != null)
            {
                UpdateIntegrationConfigData(targetIntegrationItem, folderItem, synchContext);
            }

            using (new EditContext(targetIntegrationItem))
            {
                if (string.IsNullOrEmpty(targetIntegrationItem.Fields[FieldNames.GUID].Value))
                {
                    if (targetIntegrationItem.Template.GetField(SharepointFieldIDs.IsIntegrationItem) != null)
                    {
                        new CheckboxField(targetIntegrationItem.Fields[SharepointFieldIDs.IsIntegrationItem]).Checked = true;
                    }
                }

                targetIntegrationItem.Fields[FieldNames.GUID].Value = sourceSharepointItem.GUID;

                foreach (IntegrationConfigData.FieldMapping mapping in synchContext.IntegrationConfigData.FieldMappings)
                {
                    if (targetIntegrationItem.Fields[mapping.Target] != null)
                    {
                        TranslateSharepointValueArgs pipelineArgs = TranslateSynchValuePipelinesRunner.TranslateSharepointValue(sourceSharepointItem, mapping.Source, targetIntegrationItem, mapping.Target);
                        if (pipelineArgs != null)
                        {
                            targetIntegrationItem[mapping.Target] = pipelineArgs.TranslatedValue;
                        }
                    }
                }
            }
        }
コード例 #11
0
        /// <summary>
        /// Set integration configuration data for integration folder or integration configuration item.
        /// </summary>
        /// <param name="synchContext">The synchronization context.</param>
        /// <param name="sourceSharepointFolderItem">The source.</param>
        /// <param name="targetIntegrationItem">The item  .</param>
        private static void UpdateIntegrationConfigData([NotNull] Item targetIntegrationItem, [NotNull] FolderItem sourceSharepointFolderItem, [NotNull] SynchContext synchContext)
        {
            Assert.ArgumentNotNull(targetIntegrationItem, "targetIntegrationItem");
            Assert.ArgumentNotNull(sourceSharepointFolderItem, "sourceSharepointFolderItem");
            Assert.ArgumentNotNull(synchContext, "synchContext");

            IntegrationConfigData integrationConfigData = synchContext.IntegrationConfigData.Clone();

            integrationConfigData.Folder = StringUtil.RemovePrefix('/', StringUtil.EnsurePostfix('/', synchContext.IntegrationConfigData.Folder) + sourceSharepointFolderItem.Title + "/");

            IntegrationConfigDataProvider.SaveToItem(integrationConfigData, targetIntegrationItem);
        }
コード例 #12
0
        /// <summary>
        /// Update blob field from SharePoint to CMS item.
        /// </summary>
        /// <param name="targetIntegrationItem">The item.</param>
        /// <param name="sourceSharepointDocumentItem">The source.</param>
        /// <param name="synchContext">The synchronization context.</param>
        public static void UpdateBlob([NotNull] Item targetIntegrationItem, [NotNull] DocumentItem sourceSharepointDocumentItem, [NotNull] SynchContext synchContext)
        {
            Assert.ArgumentNotNull(targetIntegrationItem, "targetIntegrationItem");
            Assert.ArgumentNotNull(sourceSharepointDocumentItem, "sourceSharepointDocumentItem");
            Assert.ArgumentNotNull(synchContext, "synchContext");

            using (new IntegrationDisabler())
            {
                if (targetIntegrationItem.Fields[FieldNames.Blob] != null)
                {
                    string extension = StringUtil.GetLastPostfix(sourceSharepointDocumentItem.Title, '.');
                    var    mediaItem = new MediaItem(targetIntegrationItem);
                    Media  media     = MediaManager.GetMedia(mediaItem);
                    media.SetStream(sourceSharepointDocumentItem.GetStream(), extension);
                }

                using (new EditContext(targetIntegrationItem))
                {
                    if (targetIntegrationItem.Fields[FieldNames.SharepointDataModified] != null)
                    {
                        DateTime owsModified = Convert.ToDateTime(sourceSharepointDocumentItem["ows_Modified"]);
                        targetIntegrationItem[FieldNames.SharepointDataModified] = DateUtil.ToIsoDate(owsModified);
                    }
                }
            }
        }