コード例 #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);
        }