Ejemplo n.º 1
0
        private void saceNewTypeCodeActivity_Save_ExecuteCode(object sender, EventArgs e)
        {
            bool saveResult = false;

            try
            {
                string typeName = this.GetBinding<string>(this.NewTypeNameBindingName);
                string typeNamespace = this.GetBinding<string>(this.NewTypeNamespaceBindingName);
                string typeTitle = this.GetBinding<string>(this.NewTypeTitleBindingName);
                bool hasRecycleBin = this.GetBinding<bool>(this.HasRecycleBinBindingName);
                bool hasPublishing = this.GetBinding<bool>(this.HasPublishingBindingName);
                bool hasLocalization = this.GetBinding<bool>(this.HasLocalizationBindingName);
                string labelFieldName = this.GetBinding<string>(this.LabelFieldNameBindingName);
                var dataFieldDescriptors = this.GetBinding<List<DataFieldDescriptor>>(this.DataFieldDescriptorsBindingName);

                var helper = new GeneratedTypesHelper();
                helper = new GeneratedTypesHelper();

                string errorMessage;
                if (!helper.ValidateNewTypeName(typeName, out errorMessage))
                {
                    this.ShowFieldMessage("NewTypeName", errorMessage);
                    SetSaveStatus(false);
                    return;
                }

                if (!helper.ValidateNewTypeNamespace(typeNamespace, out errorMessage))
                {
                    this.ShowFieldMessage("NewTypeNamespace", errorMessage);
                    SetSaveStatus(false);
                    return;
                }

                if (!helper.ValidateNewTypeFullName(typeName, typeNamespace, out errorMessage))
                {
                    this.ShowFieldMessage("NewTypeName", errorMessage);
                    SetSaveStatus(false);
                    return;
                }

                if (!helper.ValidateNewFieldDescriptors(dataFieldDescriptors, null, out errorMessage))
                {
                    this.ShowMessage(
                            DialogType.Warning,
                            "${Composite.Management, AssociatedDataElementProviderHelper.AddDataFolderExCreateNewType.ErrorTitle}",
                            errorMessage
                        );
                    SetSaveStatus(false);
                    return;
                }

                if (helper.IsEditProcessControlledAllowed)
                {
                    helper.SetPublishControlled(hasPublishing);
                    helper.SetLocalizedControlled(hasLocalization);
                }

                helper.SetNewTypeFullName(typeName, typeNamespace);
                helper.SetNewTypeTitle(typeTitle);

                // TODO: fix and check where the workflow is actually used
                helper.SetNewFieldDescriptors(dataFieldDescriptors, null, labelFieldName);

                Type targetType = TypeManager.GetType(this.Payload);
                helper.SetForeignKeyReference(targetType, Composite.Data.DataAssociationType.Aggregation);

                helper.CreateType(false);

                this.UpdateBinding(this.SelectedTypeBindingName, helper.InterfaceType);

                UserSettings.LastSpecifiedNamespace = typeNamespace;

                saveResult = true;
            }
            catch (Exception ex)
            {
                Log.LogCritical("AddNewAggregationTypeWorkflow", ex);

                this.ShowMessage(DialogType.Error, ex.Message, ex.Message);                
            }

            SetSaveStatus(saveResult);
        }
Ejemplo n.º 2
0
        private void finalizeStateCodeActivity_ExecuteCode(object sender, EventArgs e)
        {
            try
            {
                Type oldType = GetOldTypeFromBindings();

                string typeName = this.GetBinding<string>(BindingNames.TypeName);
                string typeNamespace = this.GetBinding<string>(BindingNames.TypeNamespace);
                string typeTitle = this.GetBinding<string>(BindingNames.TypeTitle);
                bool hasCaching = this.GetBinding<bool>(BindingNames.HasCaching);
                bool hasPublishing = this.GetBinding<bool>(BindingNames.HasPublishing);
                string keyFieldName = this.GetBinding<string>(BindingNames.KeyFieldName);
                string labelFieldName = this.GetBinding<string>(BindingNames.LabelFieldName);
                string internalUrlPrefix = this.GetBinding<string>(BindingNames.InternalUrlPrefix);
                var dataFieldDescriptors = this.GetBinding<List<DataFieldDescriptor>>(BindingNames.DataFieldDescriptors);

                var helper = new GeneratedTypesHelper(oldType);
                bool hasLocalization = typeof (ILocalizedControlled).IsAssignableFrom(oldType);

                string errorMessage;
                if (!helper.ValidateNewTypeName(typeName, out errorMessage))
                {
                    this.ShowFieldMessage(BindingNames.TypeName, errorMessage);
                    return;
                }

                if (!helper.ValidateNewTypeNamespace(typeNamespace, out errorMessage))
                {
                    this.ShowFieldMessage(BindingNames.TypeNamespace, errorMessage);
                    return;
                }

                if (!helper.ValidateNewTypeFullName(typeName, typeNamespace, out errorMessage))
                {
                    this.ShowFieldMessage(BindingNames.TypeName, errorMessage);
                    return;
                }

                if (!helper.ValidateNewFieldDescriptors(dataFieldDescriptors, keyFieldName, out errorMessage))
                {
                    this.ShowMessage(
                            DialogType.Warning,
                            Texts.EditInterfaceTypeStep1_ErrorTitle,
                            errorMessage
                        );
                    return;
                }


                helper.SetNewTypeFullName(typeName, typeNamespace);
                helper.SetNewTypeTitle(typeTitle);
                helper.SetNewInternalUrlPrefix(internalUrlPrefix);
                
                helper.SetNewFieldDescriptors(dataFieldDescriptors, keyFieldName, labelFieldName);

                if (helper.IsEditProcessControlledAllowed)
                {
                    helper.SetCachable(hasCaching);
                    helper.SetPublishControlled(hasPublishing);
                    helper.SetLocalizedControlled(hasLocalization);
                }

                bool originalTypeHasData = DataFacade.HasDataInAnyScope(oldType);

                if (!helper.TryValidateUpdate(originalTypeHasData, out errorMessage))
                {
                    this.ShowMessage(
                            DialogType.Warning,
                            Texts.EditInterfaceTypeStep1_ErrorTitle,
                            errorMessage
                        );
                    return;
                }


                if (!IsPageFolder)
                {
                    string oldSerializedTypeName = GetSerializedTypeName(GetBinding<string>(BindingNames.OldTypeNamespace), GetBinding<string>(BindingNames.OldTypeName));
                    string newSerializedTypeName = GetSerializedTypeName(typeNamespace, typeName);
                    if (newSerializedTypeName != oldSerializedTypeName)
                    {
                        UpdateWhiteListedGeneratedTypes(oldSerializedTypeName, newSerializedTypeName);
                    }
                }

                helper.CreateType(originalTypeHasData);

                UpdateBinding(BindingNames.OldTypeName, typeName);
                UpdateBinding(BindingNames.OldTypeNamespace, typeNamespace);

                SetSaveStatus(true);

                var rootEntityToken = new GeneratedDataTypesElementProviderRootEntityToken(this.EntityToken.Source, 
                    IsPageFolder ? GeneratedDataTypesElementProviderRootEntityToken.PageDataFolderTypeFolderId
                                 : GeneratedDataTypesElementProviderRootEntityToken.GlobalDataTypeFolderId);

                SpecificTreeRefresher specificTreeRefresher = this.CreateSpecificTreeRefresher();
                specificTreeRefresher.PostRefreshMesseges(rootEntityToken);

                IFile markupFile = DynamicTypesAlternateFormFacade.GetAlternateFormMarkupFile(typeNamespace, typeName);
                if (markupFile != null)
                {
                    ShowMessage(DialogType.Message, 
                        Texts.FormMarkupInfo_Dialog_Label,
                        Texts.FormMarkupInfo_Message(Texts.EditFormMarkup, markupFile.GetRelativeFilePath()));
                }
            }
            catch (Exception ex)
            {
                Log.LogCritical(this.GetType().Name, ex);

                this.ShowMessage(DialogType.Error, ex.Message, ex.Message);
            }
        }
        private void saveTypeCodeActivity_Save_ExecuteCode(object sender, EventArgs e)
        {
            try
            {
                Type oldType = GetOldTypeFromBindings();

                string typeName = this.GetBinding<string>("TypeName");
                string typeNamespace = this.GetBinding<string>("TypeNamespace");
                string typeTitle = this.GetBinding<string>("TypeTitle");
                bool hasCaching = this.GetBinding<bool>("HasCaching");
                bool hasPublishing = this.GetBinding<bool>("HasPublishing");
                string labelFieldName = this.GetBinding<string>("LabelFieldName");
                var dataFieldDescriptors = this.GetBinding<List<DataFieldDescriptor>>("DataFieldDescriptors");

                var helper = new GeneratedTypesHelper(oldType);

                string errorMessage;
                if (!helper.ValidateNewTypeName(typeName, out errorMessage))
                {
                    this.ShowFieldMessage("NewTypeName", errorMessage);
                    return;
                }

                if (!helper.ValidateNewTypeNamespace(typeNamespace, out errorMessage))
                {
                    this.ShowFieldMessage("NewTypeNamespace", errorMessage);
                    return;
                }

                if (!helper.ValidateNewTypeFullName(typeName, typeNamespace, out errorMessage))
                {
                    this.ShowFieldMessage("NewTypeName", errorMessage);
                    return;
                }

                if (!helper.ValidateNewFieldDescriptors(dataFieldDescriptors, null, out errorMessage))
                {
                    this.ShowMessage(
                            DialogType.Warning,
                            Texts.EditCompositionTypeWorkflow_ErrorTitle,
                            errorMessage
                        );
                    return;
                }

                helper.SetNewTypeFullName(typeName, typeNamespace);
                helper.SetNewTypeTitle(typeTitle);
                // TODO: fix
                helper.SetNewFieldDescriptors(dataFieldDescriptors, null, labelFieldName);
                helper.SetCachable(hasCaching);

                if (helper.IsEditProcessControlledAllowed)
                {
                    helper.SetPublishControlled(hasPublishing);
                }

                bool originalTypeDataExists = DataFacade.HasDataInAnyScope(oldType);

                if (!helper.TryValidateUpdate(originalTypeDataExists, out errorMessage))
                {
                    this.ShowMessage(
                            DialogType.Warning,
                            Texts.EditCompositionTypeWorkflow_ErrorTitle,
                            errorMessage
                        );
                    return;
                }

                helper.CreateType(originalTypeDataExists);

                UpdateBinding("OldTypeName", typeName);
                UpdateBinding("OldTypeNamespace", typeNamespace);

                SetSaveStatus(true);
                
                var rootEntityToken = new GeneratedDataTypesElementProviderRootEntityToken(this.EntityToken.Source, GeneratedDataTypesElementProviderRootEntityToken.PageMetaDataTypeFolderId);
                SpecificTreeRefresher specificTreeRefresher = this.CreateSpecificTreeRefresher();
                specificTreeRefresher.PostRefreshMesseges(rootEntityToken);

                IFile markupFile = DynamicTypesCustomFormFacade.GetCustomFormMarkupFile(typeNamespace, typeName);
                if (markupFile != null)
                {
                    ShowMessage(DialogType.Message,
                        Texts.FormMarkupInfo_Dialog_Label,
                        Texts.FormMarkupInfo_Message(Texts.EditFormMarkup, markupFile.GetRelativeFilePath()));
                }
            }
            catch (Exception ex)
            {
                Log.LogCritical("EditCompositionTypeWorkflow", ex);

                this.ShowMessage(DialogType.Error, ex.Message, ex.Message);
            }
        }