public static void OnInitialized()
        {
            Composite.GlobalInitializerFacade.InitializeTheSystem();
            try
            {
                var config = XElement.Load(PathUtil.Resolve("~/App_Data/Composite.Community.Twitter.FeedAggregator/Config.xml"));
                int delay;
                if (int.TryParse(config.AttributeValue("autoRefresh"), out delay))
                {
                    var queries         = config.Elements("Search").Select(d => d.AttributeValue("term")).NotNull().ToList();
                    var refreshWorkflow = WorkflowFacade.CreateNewWorkflow(
                        typeof(RefreshWorkflow),
                        new Dictionary <string, object> {
                        { "Delay", delay },
                        { "Queries", queries }
                    }
                        );

                    refreshWorkflow.Start();
                    LoggingService.LogInformation("FeedAggregator", "Run RefreshWorkflow");
                    WorkflowFacade.RunWorkflow(refreshWorkflow);
                }
                else
                {
                    throw new InvalidOperationException("Wrong autoRefresh config value");
                }
            }
            catch (Exception e)
            {
                LoggingService.LogError("FeedAggregator", e);
            }
        }
        public static bool PublishIfNeeded(IData data, bool doPublish, IDictionary <string, object> binding, Action <DialogType, string, string> messageAction)
        {
            if (!(data is IPublishControlled))
            {
                return(false);
            }

            WorkflowInstance publishWorkflowInstance   = null;
            WorkflowInstance unpublishWorkflowInstance = null;

            var publishDate   = binding.ContainsKey("PublishDate") ? (DateTime?)binding["PublishDate"] : null;
            var unpublishDate = binding.ContainsKey("UnpublishDate") ? (DateTime?)binding["UnpublishDate"] : null;

            string cultureName = UserSettings.ActiveLocaleCultureInfo.Name;

            HandlePublishUnpublishWorkflows(data, cultureName, publishDate, unpublishDate, ref publishWorkflowInstance, ref unpublishWorkflowInstance);

            if (publishWorkflowInstance != null)
            {
                publishWorkflowInstance.Start();

                WorkflowFacade.RunWorkflow(publishWorkflowInstance);
            }

            if (unpublishWorkflowInstance != null)
            {
                unpublishWorkflowInstance.Start();

                WorkflowFacade.RunWorkflow(unpublishWorkflowInstance);
            }

            if (!doPublish)
            {
                return(false);
            }

            if (publishWorkflowInstance == null || publishDate < DateTime.Now)
            {
                var actionToken      = new GenericPublishProcessController.PublishActionToken();
                var serviceContainer = WorkflowFacade.GetFlowControllerServicesContainer(WorkflowEnvironment.WorkflowInstanceId);

                ActionExecutorFacade.Execute(data.GetDataEntityToken(), actionToken, serviceContainer);

                return(true);
            }

            var title   = Texts.Website_Forms_Administrative_EditPage_PublishDatePreventPublishTitle;
            var message = Texts.Website_Forms_Administrative_EditPage_PublishDatePreventPublish;

            messageAction(DialogType.Warning, title, message);

            return(false);
        }
Ejemplo n.º 3
0
        public static void Run(int delay, RefreshFunctionDelegate refreshFunction)
        {
            var refreshWorkflow = WorkflowFacade.CreateNewWorkflow(
                typeof(RefreshWorkflow),
                new Dictionary <string, object> {
                { "Delay", delay },
                { "RefreshFunction", refreshFunction }
            }
                );

            refreshWorkflow.Start();

            WorkflowFacade.RunWorkflow(refreshWorkflow);
        }
        /// <exclude />
        public static void Initialize()
        {
            WorkflowFacade.RunWhenInitialized(() =>
            {
                lock (_lock)
                {
                    if (_initialized == false)
                    {
                        WorkflowInstance workflowInstance = WorkflowFacade.CreateNewWorkflow(WorkflowFacade.GetWorkflowType("Composite.C1Console.Actions.Workflows.FlowInformationScavengerWorkflow"));
                        workflowInstance.Start();
                        WorkflowFacade.RunWorkflow(workflowInstance);

                        Log.LogVerbose(LogTitle, "Flow scavenger started");

                        _initialized = true;
                    }
                }
            });
        }
Ejemplo n.º 5
0
        /// <exclude />
        public static void Initialize()
        {
            WorkflowFacade.RunWhenInitialized(() =>
            {
                lock (_lock)
                {
                    if (!_initialized)
                    {
                        WorkflowInstance workflowInstance = WorkflowFacade.CreateNewWorkflow(WorkflowFacade.GetWorkflowType("Composite.C1Console.Events.Workflows.UserConsoleInformationScavengerWorkflow"));
                        workflowInstance.Start();
                        WorkflowFacade.RunWorkflow(workflowInstance);

                        if (RuntimeInformation.IsDebugBuild)
                        {
                            Log.LogVerbose(LogTitle, "Scavenger started");
                        }
                        _initialized = true;
                    }
                }
            });
        }
Ejemplo n.º 6
0
        private void saveCodeActivity_ExecuteCode(object sender, EventArgs e)
        {
            var updateTreeRefresher = CreateUpdateTreeRefresher(EntityToken);

            var selectedPage = GetBinding <IPage>("SelectedPage");
            var originalPage = DataFacade.GetData <IPage>(f => f.Id == selectedPage.Id).SingleOrDefault();

            var viewLabelUpdated = originalPage == null ||
                                   selectedPage.MenuTitle != originalPage.MenuTitle ||
                                   selectedPage.Title != originalPage.Title;

            var treeviewRequiresRefreshing = false;

            var dataToAdd    = new Dictionary <string, IData>();
            var dataToUpdate = new Dictionary <string, IData>();

            var dataValidated = true;

            WorkflowInstance publishWorkflowInstance   = null;
            WorkflowInstance unpublishWorkflowInstance = null;

            try
            {
                using (var transactionScope = TransactionsFacade.CreateNewScope())
                {
                    dataValidated = PrepareAddUpdateMetaData(selectedPage, dataToAdd, dataToUpdate);

                    if (dataValidated)
                    {
                        PublishControlledHelper.HandlePublishUnpublishWorkflows(selectedPage, UserSettings.ActiveLocaleCultureInfo.Name, PublishDate, UnpublishDate, ref publishWorkflowInstance, ref unpublishWorkflowInstance);

                        if (selectedPage.PageTypeId != originalPage.PageTypeId)
                        {
                            // Adding metadata fields
                            var oldPageMetaDataDefinitions = originalPage.GetAllowedMetaDataDefinitions().Except(selectedPage.GetAllowedMetaDataDefinitions(), new PageMetaDataDefinitionEqualityComparer());

                            foreach (var pageMetaDataDefinition in oldPageMetaDataDefinitions)
                            {
                                var oldMetaData = selectedPage.GetMetaData(pageMetaDataDefinition.Name, pageMetaDataDefinition.MetaDataTypeId);
                                if (oldMetaData != null)
                                {
                                    ProcessControllerFacade.FullDelete(oldMetaData);
                                }
                            }


                            // Adding page folders
                            var pageTypeDataFolderTypeLinks =
                                DataFacade.GetData <IPageTypeDataFolderTypeLink>().
                                Where(f => f.PageTypeId == selectedPage.PageTypeId).
                                Evaluate().
                                RemoveDeadLinks();

                            foreach (var pageTypeDataFolderTypeLink in pageTypeDataFolderTypeLinks)
                            {
                                if (selectedPage.GetFolderDefinitionId(pageTypeDataFolderTypeLink.DataTypeId) != Guid.Empty)
                                {
                                    continue;
                                }

                                selectedPage.AddFolderDefinition(pageTypeDataFolderTypeLink.DataTypeId);
                                treeviewRequiresRefreshing = true;
                            }



                            // Adding applications
                            var pageTypeTreeLinks =
                                DataFacade.GetData <IPageTypeTreeLink>().
                                Where(f => f.PageTypeId == selectedPage.PageTypeId).
                                Evaluate().
                                RemoveDeadLinks();

                            foreach (var pageTypeTreeLink in pageTypeTreeLinks)
                            {
                                var tree = TreeFacade.GetTree(pageTypeTreeLink.TreeId);
                                if (tree.HasAttachmentPoints(selectedPage.GetDataEntityToken()))
                                {
                                    continue;
                                }

                                TreeFacade.AddPersistedAttachmentPoint(pageTypeTreeLink.TreeId, typeof(IPage), selectedPage.Id);
                                treeviewRequiresRefreshing = true;
                            }
                        }


                        foreach (var data in dataToAdd.Values)
                        {
                            DataFacade.AddNew(data);
                        }

                        foreach (var data in dataToUpdate.Values)
                        {
                            var publishControlled = data as IPublishControlled;
                            publishControlled.PublicationStatus = GenericPublishProcessController.Draft;

                            DataFacade.Update(data);
                        }

                        treeviewRequiresRefreshing |= (originalPage.Title != selectedPage.Title) ||
                                                      (originalPage.Description != selectedPage.Description) ||
                                                      (originalPage.PublicationStatus != selectedPage.PublicationStatus);

                        // NOTE: updating originalPage object, in order to make XML & SQL provider work in the same way
                        originalPage.TemplateId        = selectedPage.TemplateId;
                        originalPage.PageTypeId        = selectedPage.PageTypeId;
                        originalPage.Title             = selectedPage.Title;
                        originalPage.MenuTitle         = selectedPage.MenuTitle;
                        originalPage.UrlTitle          = selectedPage.UrlTitle;
                        originalPage.FriendlyUrl       = selectedPage.FriendlyUrl;
                        originalPage.Description       = selectedPage.Description;
                        originalPage.PublicationStatus = selectedPage.PublicationStatus;
                        originalPage.SourceCultureName = selectedPage.SourceCultureName;
                        DataFacade.Update(originalPage);

                        var contentDictionary = GetBinding <Dictionary <string, string> >("NamedXhtmlFragments");
                        var existingContents  = DataFacade.GetData <IPagePlaceholderContent>(f => f.PageId == selectedPage.Id).ToList();

                        foreach (var existingContent in existingContents)
                        {
                            if (contentDictionary.ContainsKey(existingContent.PlaceHolderId))
                            {
                                existingContent.Content           = contentDictionary[existingContent.PlaceHolderId];
                                existingContent.PublicationStatus = GenericPublishProcessController.Draft;
                                DataFacade.Update(existingContent);
                            }
                            else
                            {
                                DataFacade.Delete(existingContent);
                            }
                        }

                        foreach (var contentDictionaryElement in contentDictionary.Where(f => existingContents.Any(existing => existing.PlaceHolderId == f.Key) == false))
                        {
                            var newContent = DataFacade.BuildNew <IPagePlaceholderContent>();
                            newContent.PageId            = selectedPage.Id;
                            newContent.PlaceHolderId     = contentDictionaryElement.Key;
                            newContent.Content           = contentDictionaryElement.Value;
                            newContent.SourceCultureName = UserSettings.ActiveLocaleCultureInfo.Name;
                            newContent.PublicationStatus = GenericPublishProcessController.Draft;

                            DataFacade.AddNew(newContent);
                        }
                    }

                    transactionScope.Complete();
                }

                if (publishWorkflowInstance != null)
                {
                    publishWorkflowInstance.Start();
                    WorkflowFacade.RunWorkflow(publishWorkflowInstance);
                }

                if (unpublishWorkflowInstance != null)
                {
                    unpublishWorkflowInstance.Start();
                    WorkflowFacade.RunWorkflow(unpublishWorkflowInstance);
                }

                if (_doPublish)
                {
                    if (publishWorkflowInstance == null || PublishDate < DateTime.Now)
                    {
                        var actionToken = new GenericPublishProcessController.PublishActionToken();

                        var serviceContainer = WorkflowFacade.GetFlowControllerServicesContainer(WorkflowEnvironment.WorkflowInstanceId);

                        ActionExecutorFacade.Execute(EntityToken, actionToken, serviceContainer);

                        treeviewRequiresRefreshing = false;
                    }
                    else
                    {
                        var title   = StringResourceSystemFacade.GetString("Composite.Management", "Website.Forms.Administrative.EditPage.PublishDatePreventPublishTitle");
                        var message = StringResourceSystemFacade.GetString("Composite.Management", "Website.Forms.Administrative.EditPage.PublishDatePreventPublish");
                        ShowMessage(DialogType.Warning, title, message);
                    }
                }

                if (treeviewRequiresRefreshing)
                {
                    updateTreeRefresher.PostRefreshMesseges(selectedPage.GetDataEntityToken());
                }

                UpdateBinding("OldPublicationStatus", selectedPage.PublicationStatus);

                if (viewLabelUpdated)
                {
                    RerenderView();
                }
            }
            catch (Exception ex)
            {
                var mostSpecificException = ex;
                while (mostSpecificException.InnerException != null)
                {
                    mostSpecificException = mostSpecificException.InnerException;
                }
                ShowMessage(DialogType.Error, "Save failed", string.Format("Save failed: {0}", mostSpecificException.Message));
                Log.LogError("Page save", ex);
            }
            finally
            {
                SetSaveStatus(dataValidated);
            }
        }