protected override void DoValidate(object objectToValidate, object currentTarget, string key,
                                           ValidationResults validationResults)
        {
            var tag = (string)objectToValidate;

            if (tag.Contains(","))
            {
                LogValidationResult(validationResults, "A comma is not supported", currentTarget, key);
                return;
            }
            using (var conn = new DataConnection())
            {
                List <Tags> tags = conn.Get <Tags>().Where(t => t.Tag == tag).ToList();
                if (tags.Any())
                {
                    Guid workflowInstanceId = WorkflowEnvironment.WorkflowInstanceId;
                    var  id = (Guid)WorkflowFacade.GetFormData(workflowInstanceId).Bindings["Id"];
                    if (tags.Find(t => t.Id == id) == null)
                    {
                        LogValidationResult(validationResults, "The tag with the same name already exists",
                                            currentTarget, key);
                    }
                }
            }
        }
Esempio n. 2
0
        private void initialCodeActivity_ExecuteCode(object sender, EventArgs e)
        {
            var entityToken = EntityToken as AssociatedDataElementProviderHelperEntityToken;

            if (!string.IsNullOrEmpty(entityToken?.Payload))
            {
                var type = TypeManager.GetType(entityToken.Payload);
                var id   = type.GetImmutableTypeId();
                var dataTypeDescriptor = DataMetaDataFacade.GetDataTypeDescriptor(id);
                UpdateBinding("DataTypeDescriptor", dataTypeDescriptor);

                UpdateBinding(BindingNames.PageId, new Guid(entityToken.Id));

                if (!PermissionsFacade.GetPermissionsForCurrentUser(EntityToken).Contains(PermissionType.Publish) || !typeof(IPublishControlled).IsAssignableFrom(type))
                {
                    var formData = WorkflowFacade.GetFormData(InstanceId, true);

                    if (formData.ExcludedEvents == null)
                    {
                        formData.ExcludedEvents = new List <string>();
                    }

                    formData.ExcludedEvents.Add("SaveAndPublish");
                }
            }
        }
        private void Initialize()
        {
            if (_dataTypeDescriptorFormsHelper == null)
            {
                if (String.IsNullOrEmpty(this.Payload))
                {
                    throw new InvalidOperationException("The interface type should be a part of the workflows payload");
                }

                Dictionary <string, string> serializedValues = StringConversionServices.ParseKeyValueCollection(this.Payload);

                _dataPayload = serializedValues;
            }

            if (!PermissionsFacade.GetPermissionsForCurrentUser(EntityToken).Contains(PermissionType.Publish) ||
                !typeof(IPublishControlled).IsAssignableFrom(InterfaceType))
            {
                FormData formData = WorkflowFacade.GetFormData(InstanceId, true);

                if (formData.ExcludedEvents == null)
                {
                    formData.ExcludedEvents = new List <string>();
                }

                formData.ExcludedEvents.Add("SaveAndPublish");
            }
        }
Esempio n. 4
0
            private FormData GetFormData()
            {
                var formData = WorkflowFacade.GetFormData(WorkflowId);

                Verify.IsNotNull(formData, "Failed to get form data, workflow may have been aborted!");

                return(formData);
            }
        private void initialCodeActivity_Initialize_ExecuteCode(object sender, EventArgs e)
        {
            var type = GetInterfaceType();

            if (!PermissionsFacade.GetPermissionsForCurrentUser(EntityToken).Contains(PermissionType.Publish) || !typeof(IPublishControlled).IsAssignableFrom(type))
            {
                var formData = WorkflowFacade.GetFormData(InstanceId, true);

                if (formData.ExcludedEvents == null)
                {
                    formData.ExcludedEvents = new List <string>();
                }

                formData.ExcludedEvents.Add("SaveAndPublish");
            }


            var helper = GetDataTypeDescriptorFormsHelper();

            helper.UpdateWithNewBindings(Bindings);

            var newData = DataFacade.BuildNew(type);

            var publishControlled = newData as IPublishControlled;

            if (publishControlled != null)
            {
                publishControlled.PublicationStatus = GenericPublishProcessController.Draft;
            }

            if (!string.IsNullOrEmpty(Payload))
            {
                var values = new Dictionary <string, string>();

                var serializedValues = StringConversionServices.ParseKeyValueCollection(Payload);
                foreach (var kvp in serializedValues)
                {
                    values.Add(kvp.Key, StringConversionServices.DeserializeValueString(kvp.Value));
                }

                newData.SetValues(values);
            }

            helper.ObjectToBindings(newData, Bindings);

            GeneratedTypesHelper.SetNewIdFieldValue(newData);

            Bindings.Add("NewData", newData);
        }
        private void editDataCodeActivity_ExecuteCode(object sender, EventArgs e)
        {
            var helper = GetDataTypeDescriptorFormsHelper();

            helper.LayoutIconHandle = "associated-data-edit";

            var data = ((DataEntityToken)EntityToken).Data;
            var publishedControlled = data as IPublishControlled;

            if (!PermissionsFacade.GetPermissionsForCurrentUser(EntityToken).Contains(PermissionType.Publish) || publishedControlled == null)
            {
                var formData = WorkflowFacade.GetFormData(InstanceId, true);

                if (formData.ExcludedEvents == null)
                {
                    formData.ExcludedEvents = new List <string>();
                }

                formData.ExcludedEvents.Add("SaveAndPublish");
            }

            if (publishedControlled != null)
            {
                if (publishedControlled.PublicationStatus == GenericPublishProcessController.Published)
                {
                    publishedControlled.PublicationStatus = GenericPublishProcessController.Draft;
                }
            }

            helper.UpdateWithBindings(data, Bindings);

            DeliverFormData(
                _typeName,
                StandardUiContainerTypes.Document,
                helper.GetForm(),
                Bindings,
                helper.GetBindingsValidationRules(data)
                );
        }
Esempio n. 7
0
        private void editCodeActivity_DisplayForm_ExecuteCode(object sender, EventArgs e)
        {
            IData data = ((DataEntityToken)this.EntityToken).Data;

            if (!PermissionsFacade.GetPermissionsForCurrentUser(EntityToken).Contains(PermissionType.Publish) ||
                !(data is IPublishControlled))
            {
                FormData formData = WorkflowFacade.GetFormData(InstanceId, true);

                if (formData.ExcludedEvents == null)
                {
                    formData.ExcludedEvents = new List <string>();
                }

                formData.ExcludedEvents.Add("SaveAndPublish");
            }

            if (data is IPublishControlled)
            {
                IPublishControlled publishControlledData = (IPublishControlled)data;
                if (publishControlledData.PublicationStatus == GenericPublishProcessController.Published)
                {
                    publishControlledData.PublicationStatus = GenericPublishProcessController.Draft;
                }
            }

            this.FormsHelper.UpdateWithBindings(data, this.Bindings);
            this.FormsHelper.LayoutLabel = data.GetLabel(true);

            this.DeliverFormData(
                this.TypeName,
                StandardUiContainerTypes.Document,
                this.FormsHelper.GetForm(),
                this.Bindings,
                this.FormsHelper.GetBindingsValidationRules(data)
                );
        }
 private FormData GetFormData()
 {
     return(WorkflowFacade.GetFormData(WorkflowId));
 }
Esempio n. 9
0
        private void editStateCodeActivity_ExecuteCode(object sender, EventArgs e)
        {
            if (!PermissionsFacade.GetPermissionsForCurrentUser(EntityToken).Contains(PermissionType.Publish))
            {
                var formData = WorkflowFacade.GetFormData(InstanceId, true);

                if (formData.ExcludedEvents == null)
                {
                    formData.ExcludedEvents = new List <string>();
                }

                formData.ExcludedEvents.Add("SaveAndPublish");
            }


            IPage selectedPage;

            if (!BindingExist("SelectedPage"))
            {
                selectedPage = GetDataItemFromEntityToken <IPage>();

                if (selectedPage.PublicationStatus == GenericPublishProcessController.Published)
                {
                    selectedPage.PublicationStatus = GenericPublishProcessController.Draft;
                }
                Bindings.Add("SelectedPage", selectedPage);
            }
            else
            {
                selectedPage = GetBinding <IPage>("SelectedPage");
            }

            if (!BindingExist("UrlTitleIsRequired"))
            {
                var isRootPage = PageManager.GetParentId(selectedPage.Id) == Guid.Empty;

                Bindings["UrlTitleIsRequired"] = !isRootPage;
                Bindings["IsRootPage"]         = isRootPage;
            }

            IFormMarkupProvider markupProvider = new FormDefinitionFileMarkupProvider(@"\Administrative\EditPage.xml");

            XDocument formDocument;

            using (var reader = markupProvider.GetReader())
            {
                formDocument = XDocument.Load(reader);
            }

            var bindingsXElement  = formDocument.Root.Element(DataTypeDescriptorFormsHelper.CmsNamespace + FormKeyTagNames.Bindings);
            var layoutXElement    = formDocument.Root.Element(DataTypeDescriptorFormsHelper.CmsNamespace + FormKeyTagNames.Layout);
            var tabPanelsXElement = layoutXElement.Element(DataTypeDescriptorFormsHelper.MainNamespace + "TabPanels");


            IEnumerable <ICompositionContainer> compositionContainers = selectedPage.GetAllowedMetaDataContainers().Evaluate();

            var compositionTabs = new Dictionary <Guid, XElement>();

            foreach (var compositionContainer in compositionContainers)
            {
                var element = new XElement(Namespaces.BindingFormsStdUiControls10 + "PlaceHolder");
                element.Add(new XAttribute("Label", StringResourceSystemFacade.ParseString(compositionContainer.Label)));

                compositionTabs.Add(compositionContainer.Id, element);
            }

            var clientValidationRules = new Dictionary <string, List <ClientValidationRule> >();

            var pageMetaDataDefinitions = selectedPage.GetAllowedMetaDataDefinitions();

            foreach (var pageMetaDataDefinition in pageMetaDataDefinitions)
            {
                var metaDatTypeId = pageMetaDataDefinition.MetaDataTypeId;

                var dataTypeDescriptor = DynamicTypeManager.GetDataTypeDescriptor(metaDatTypeId);
                Verify.IsNotNull(dataTypeDescriptor, "Failed to get meta data type by id '{0}'. If data type was purposely removed, in order to fix this exception you should remove IPageMetaDataDefinition records that reference this data type.", metaDatTypeId);

                var metaDataType = TypeManager.TryGetType(dataTypeDescriptor.TypeManagerTypeName);
                Verify.IsNotNull(metaDataType, "Failed to get meta data type '{0}', id: {1}. If it has been removed, references from '{2}' have to be removed as well",
                                 dataTypeDescriptor.TypeManagerTypeName, metaDatTypeId, typeof(IPageMetaDataDefinition).Name);

                var helper = CreateDataTypeDescriptorFormsHelper(pageMetaDataDefinition, dataTypeDescriptor);

                var metaData = selectedPage.GetMetaData(pageMetaDataDefinition.Name, metaDataType);
                if (metaData == null)
                {
                    metaData = DataFacade.BuildNew(metaDataType);

                    PageMetaDataFacade.AssignMetaDataSpecificValues(metaData, pageMetaDataDefinition.Name, selectedPage);

                    var localizedData = metaData as ILocalizedControlled;
                    if (localizedData != null)
                    {
                        localizedData.SourceCultureName = UserSettings.ActiveLocaleCultureInfo.Name;
                    }

                    var publishControlled = metaData as IPublishControlled;
                    publishControlled.PublicationStatus = GenericPublishProcessController.Draft;

                    helper.UpdateWithNewBindings(Bindings);
                    helper.ObjectToBindings(metaData, Bindings);
                }
                else
                {
                    helper.UpdateWithBindings(metaData, Bindings);
                }


                bindingsXElement.Add(helper.BindingXml.Elements());
                compositionTabs[pageMetaDataDefinition.MetaDataContainerId].Add(helper.PanelXml);

                clientValidationRules.AddDictionary(helper.GetBindingsValidationRules(metaData));
            }


            var previewTabPanel = tabPanelsXElement.Elements().Last();

            foreach (var element in compositionTabs.Values)
            {
                previewTabPanel.AddBeforeSelf(element);
            }



            IDictionary <string, string> transitionNames = new Dictionary <string, string>();

            transitionNames.Add(GenericPublishProcessController.Draft, StringResourceSystemFacade.GetString("Composite.Management", "PublishingStatus.draft"));
            transitionNames.Add(GenericPublishProcessController.AwaitingApproval, StringResourceSystemFacade.GetString("Composite.Management", "PublishingStatus.awaitingApproval"));

            var username = UserValidationFacade.GetUsername();
            var userPermissionDefinitions      = PermissionTypeFacade.GetUserPermissionDefinitions(username);
            var userGroupPermissionDefinitions = PermissionTypeFacade.GetUserGroupPermissionDefinitions(username);
            var currentPermissionTypes         = PermissionTypeFacade.GetCurrentPermissionTypes(UserValidationFacade.GetUserToken(), EntityToken, userPermissionDefinitions, userGroupPermissionDefinitions);

            foreach (var permissionType in currentPermissionTypes)
            {
                if (GenericPublishProcessController.AwaitingPublicationActionPermissionType.Contains(permissionType))
                {
                    transitionNames.Add(GenericPublishProcessController.AwaitingPublication, StringResourceSystemFacade.GetString("Composite.Management", "PublishingStatus.awaitingPublication"));
                    break;
                }
            }


            var contents            = DataFacade.GetData <IPagePlaceholderContent>(f => f.PageId == selectedPage.Id && f.VersionId == selectedPage.VersionId).ToList();
            var namedXhtmlFragments = contents.ToDictionary(content => content.PlaceHolderId, content => content.Content ?? "");


            UpdateBinding("SelectablePageTypeIds", GetSelectablePageTypes());
            UpdateBinding("SelectableTemplateIds", GetSelectablePageTemplates());
            UpdateBinding("NamedXhtmlFragments", namedXhtmlFragments);
            UpdateBinding("StateOptions", transitionNames);


            var formDefinition = formDocument.GetDocumentAsString();

            DeliverFormData(
                selectedPage.Title,
                StandardUiContainerTypes.Document,
                formDefinition,
                Bindings,
                clientValidationRules
                );
        }