Пример #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);
                }
            }
        }
        public void Prepare(ClientPipelineArgs args)
        {
            Assert.ArgumentNotNull(args, "args");
            Assert.ArgumentNotNull(args, "args");
            Database   database = GetDatabase(args);
            ListString list     = new ListString(args.Parameters["items"], '|');

            foreach (string id in list)
            {
                Item item = database.GetItem(id);
                if (SharepointProvider.IsActiveIntegrationConfigItem(item))
                {
                    args.Parameters[CancelationKey] = "1";
                }

                if (SharepointProvider.IsActiveIntegrationDataItem(item))
                {
                    if (item != null)
                    {
                        CacheableIntegrationItemInfo cacheableIntegrationItemInfo = IntegrationCache.GetIntegrationItemInfo(item.ID);
                        if (cacheableIntegrationItemInfo != null)
                        {
                            args.Parameters[id] = cacheableIntegrationItemInfo.ParentItemId.ToString();
                            args.Parameters[id + "uniqueId"] = cacheableIntegrationItemInfo.SharepointItemId;
                        }
                    }
                }
            }
        }
        private void CheckFoldersStructure(Action <object, EventArgs> action, Func <Item, EventArgs> constructArgs)
        {
            var subFolderId = ID.NewID;
            var subFolder   = new ItemMock(subFolderId).WithTemplate(TemplateIDs.IntegrationFolder).PutConfigDataToCache();

            var folderId = ID.NewID;
            var folder   = new ItemMock(folderId)
                           .WithChild(subFolder)
                           .WithTemplate(TemplateIDs.IntegrationFolder).PutConfigDataToCache();


            var configurationItem = new ItemMock().AsConfigurationItem().WithChild(folder).WithField(FieldIDs.IntegrationConfigData, string.Empty);

            using (new ItemIsContentItem(configurationItem))
            {
                var eventArgs = constructArgs(configurationItem);

                // Act
                action(this, eventArgs);

                // Assert
                IntegrationCache.GetIntegrationConfigData(folderId).Should().BeNull();
                IntegrationCache.GetIntegrationConfigData(subFolderId).Should().BeNull();
            }
        }
        private static SynchContext CreateSyncContext()
        {
            var item = PrepareDbWithItemTree();

            IntegrationCache.AddIntegrationConfigData(item.ID, new IntegrationConfigData("server", "list", "templateID"), 0);
            return(new SynchContext(item));
        }
Пример #5
0
        /// <summary>
        /// Method is processing integration config or integration folder item.
        /// </summary>
        /// <param name="integrationConfigDataSource">The item which contains integration config data.</param>
        /// <param name="processIntegrationItemsOptions">The process integration items options.</param>
        public static void ProcessTree([NotNull] Item integrationConfigDataSource, [NotNull] ProcessIntegrationItemsOptions processIntegrationItemsOptions)
        {
            Assert.ArgumentNotNull(integrationConfigDataSource, "integrationConfigDataSource");
            Assert.ArgumentNotNull(processIntegrationItemsOptions, "processIntegrationItemsOptions");

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

            if (!IntegrationDisabler.CurrentValue && (processIntegrationItemsOptions.Force || it == null || it.IsExpired))
            {
                if (processIntegrationItemsOptions.AsyncIntegration)
                {
                    string jobName    = string.Format("SharePoint_Integration_{0}", integrationConfigDataSource.ID);
                    var    parameters = new object[]
                    {
                        processIntegrationItemsOptions, integrationConfigDataSource
                    };

                    JobUtil.StartJob(jobName, Instance, "ProcessTree", parameters);
                }
                else
                {
                    Instance.ProcessTree(processIntegrationItemsOptions, integrationConfigDataSource);
                }
            }
        }
 public static ItemMock PutConfigDataToCache(this ItemMock item, IntegrationConfigData configData = null)
 {
     IntegrationCache.AddIntegrationConfigData(
         item.ID,
         configData ?? new IntegrationConfigData("server", "list", "templateID"),
         60);
     return(item);
 }
 private static void RemoveChildIntegrationFoldersFromCache(Item item)
 {
     IntegrationCache.RemoveIntegrationConfigData(item.ID);
     foreach (Item child in item.Children.Where(SharepointProvider.IsIntegrationFolder))
     {
         RemoveChildIntegrationFoldersFromCache(child);
     }
 }
        private SynchContext CreateSynchContext(IntegrationConfigData integrationConfigData)
        {
            var id = ID.NewID;

            IntegrationCache.AddIntegrationConfigData(id, integrationConfigData, 0);
            var synchContext = new SynchContext(id, Substitute.For <Database>());

            return(synchContext);
        }
Пример #9
0
        public void ShouldStartSyncForFolderParent()
        {
            // Arrange
            Item item = Substitute.For <Database>().CreateConfigurationFolder();

            IntegrationCache.RemoveIntegrationConfigData(item.ParentID);
            var args = this.CreateItemArgs(item);

            // Act
            this.processor.Process(args);

            // Assert
            item.ParentID.WasSyncStarted().Should().BeTrue();
        }
        private void CheckConfigurationItem(Action <object, EventArgs> action, Func <Item, EventArgs> constructArgs)
        {
            // Arrange
            Item configurationItem = new ItemMock().AsConfigurationItem().WithField(FieldIDs.IntegrationConfigData, string.Empty);

            using (new ItemIsContentItem(configurationItem))
            {
                var eventArgs = constructArgs(configurationItem);

                // Act
                action(this, eventArgs);

                // Assert
                IntegrationCache.GetIntegrationConfigData(configurationItem.ID).Should().BeNull();
            }
        }
        public void ShouldNotStartSyncIfIntegrationDisabled()
        {
            // Arrange
            Item item = new ItemMock();

            IntegrationCache.RemoveIntegrationConfigData(item.ID);
            var args = new GetChildrenArgs(this.itemProvider, item, SecurityCheck.Disable, ChildListOptions.None);

            // Act
            using (new IntegrationDisabler())
            {
                this.processor.Process(args);
            }

            // Assert
            item.ID.WasSyncStarted().Should().BeFalse();
        }
Пример #12
0
        public void ShouldNotStartSyncIfIntegrationDisabled()
        {
            // Arrange
            Item item = Substitute.For <Database>().CreateConfigurationFolder();

            IntegrationCache.RemoveIntegrationConfigData(item.ID);
            var args = this.CreateItemArgs(item);

            // Act
            using (new IntegrationDisabler())
            {
                this.processor.Process(args);
            }

            // Assert
            item.ParentID.WasSyncStarted().Should().BeFalse();
        }
        public void ShouldStartSyncForFolder()
        {
            Item item = Substitute.For <Database>().CreateConfigurationFolder();

            using (new ItemIsContentItem(item))
            {
                // Arrange
                IntegrationCache.RemoveIntegrationConfigData(item.ID);
                var args = new GetChildrenArgs(this.itemProvider, item, SecurityCheck.Disable, ChildListOptions.None);

                // Act
                this.processor.Process(args);

                // Assert
                item.ID.WasSyncStarted().Should().BeTrue();
            }
        }
Пример #14
0
        protected bool UpdateIntegrationConfigData(Item item)
        {
            IntegrationConfigData integrationData = null;

            try
            {
                integrationData = IntegrationConfigDataProvider.GetFromItem(item);
                if (integrationData == null)
                {
                    return(true);
                }

                var context = SpContextProviderBase.Instance.CreateDataContext(integrationData);

                string listId;
                listId = BaseList.GetList(integrationData.Web, integrationData.List, context).ID;

                Assert.IsNotNullOrEmpty(listId, "listId");

                if (integrationData.List == listId)
                {
                    return(true);
                }
                integrationData.List = listId;

                IntegrationConfigDataProvider.SaveToItem(integrationData, item);
                IntegrationCache.RemoveIntegrationConfigData(item.ID);

                return(true);
            }
            catch (Exception exception)
            {
                var errorMessage = new StringBuilder("Updating integration config data has been failed.");
                errorMessage.AppendLine(string.Format("Integration config item: {0}", item.ID));
                if (integrationData != null)
                {
                    errorMessage.AppendLine(string.Format("SharePoint list: {0}{1}{2}", integrationData.Server.Trim('/'), StringUtil.EnsurePrefix('/', StringUtil.EnsurePostfix('/', integrationData.Web)), integrationData.List.Trim('/')));
                }

                Log.Error(errorMessage.ToString(), exception, this);

                return(false);
            }
        }
        public void should_process_tree_for_queued_events()
        {
            // Arrange
            Item item = new ItemMock().AsConfigurationItem();

            IntegrationCache.RemoveIntegrationConfigData(item.ID);

            string jobName = string.Format("SharePoint_Integration_{0}", item.ID);

            SharepointProvider.Instance.Should().NotBeNull();

            this.factory.GetDatabase(item.Database.Name).Returns(item.Database);

            // Act
            EventManager.RaiseEvent(new ProcessTreeRemoteEvent(item.ID, item.Database.Name));

            // Assert
            JobManager.GetJobs().Any(x => x.Name == jobName).Should().BeTrue();
        }
Пример #16
0
        public void should_update_exired_interval()
        {
            // Arrange
            var processor = new UpdateExpirationInterval();
            var args      = new SynchronizeTreeArgs
            {
                Context = this.synchContext
            };
            var configData = IntegrationCache.GetIntegrationConfigData(this.itemId);

            configData.ExpirationDate = DateTime.Now.AddDays(-1);
            configData.IsExpired.Should().BeTrue();

            // Act
            processor.Process(args);

            // Assert
            IntegrationCache.GetIntegrationConfigData(this.itemId).IsExpired.Should().BeFalse();
        }
Пример #17
0
        /// <exception cref="NullReferenceException">Throws <c>NullReferenceException</c> if Integration Config Data of the current Integration item is not specified.</exception>
        protected void Initialize()
        {
            CacheableIntegrationConfigData integrationConfigData = IntegrationCache.GetIntegrationConfigData(this.ParentID);

            if (integrationConfigData != null)
            {
                this.IntegrationConfigData = integrationConfigData.Data;
            }
            else
            {
                this.IntegrationConfigData = IntegrationConfigDataProvider.GetFromItem(this.ParentItem);
            }

            if (this.IntegrationConfigData == null)
            {
                string message = string.Format("Integration Config Data of Integration item \"{0}\" is not specified.", this.ParentItem.Paths.FullPath);
                throw new NullReferenceException(message);
            }
        }
Пример #18
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);
        }
        public void Process(SynchronizeTreeArgs args)
        {
            Assert.ArgumentNotNull(args, "args");

            IntegrationCache.AddIntegrationConfigData(args.Context.ParentID, args.Context.IntegrationConfigData, (args.Context.IntegrationConfigData.ExpirationInterval > 0) ? args.Context.IntegrationConfigData.ExpirationInterval : SharepointProvider.DefaultTimeout);
        }
Пример #20
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);
                    }
                }
            }
        }