Example #1
0
        public IEnumerable <EntityToken> GetParents(EntityToken entityToken)
        {
            if (entityToken is GeneratedDataTypesElementProviderRootEntityToken)
            {
                yield break;
            }
            else if (entityToken is GeneratedDataTypesElementProviderTypeEntityToken)
            {
                GeneratedDataTypesElementProviderTypeEntityToken castedToken = entityToken as GeneratedDataTypesElementProviderTypeEntityToken;

                Type type = TypeManager.TryGetType(castedToken.SerializedTypeName);

                if (type != null)
                {
                    yield return(new GeneratedDataTypesElementProviderRootEntityToken(entityToken.Source, castedToken.Id));
                }
                else
                {
                    yield return(null);
                }
            }
            else
            {
                throw new NotImplementedException();
            }
        }
        private DataTypeDescriptor GetDataTypeDescriptor()
        {
            GeneratedDataTypesElementProviderTypeEntityToken entityToken = (GeneratedDataTypesElementProviderTypeEntityToken)this.EntityToken;
            Type type = TypeManager.GetType(entityToken.SerializedTypeName);

            Guid guid = type.GetImmutableTypeId();

            return(DataMetaDataFacade.GetDataTypeDescriptor(guid));
        }
        private void finalizeCodeActivity_ExecuteCode(object sender, EventArgs e)
        {
            GeneratedDataTypesElementProviderTypeEntityToken castedEntityToken = (GeneratedDataTypesElementProviderTypeEntityToken)this.EntityToken;

            DataFacade.Delete <IGeneratedTypeWhiteList>(f => f.TypeManagerTypeName == castedEntityToken.SerializedTypeName);

            ParentTreeRefresher parentTreeRefresher = this.CreateParentTreeRefresher();

            parentTreeRefresher.PostRefreshMesseges(this.EntityToken, 3);
        }
Example #4
0
        private DataTypeDescriptor GetDataTypeDescriptor()
        {
            Type type;

            if ((this.EntityToken is Composite.C1Console.Elements.ElementProviderHelpers.AssociatedDataElementProviderHelper.AssociatedDataElementProviderHelperEntityToken))
            {
                Composite.C1Console.Elements.ElementProviderHelpers.AssociatedDataElementProviderHelper.AssociatedDataElementProviderHelperEntityToken castedEntityToken = this.EntityToken as Composite.C1Console.Elements.ElementProviderHelpers.AssociatedDataElementProviderHelper.AssociatedDataElementProviderHelperEntityToken;

                type = TypeManager.GetType(castedEntityToken.Payload);
            }
            else
            {
                GeneratedDataTypesElementProviderTypeEntityToken entityToken = (GeneratedDataTypesElementProviderTypeEntityToken)this.EntityToken;
                type = TypeManager.GetType(entityToken.SerializedTypeName);
            }

            Guid guid = type.GetImmutableTypeId();

            return(DataMetaDataFacade.GetDataTypeDescriptor(guid));
        }
        private void codeActivity1_ExecuteCode(object sender, EventArgs e)
        {
            try
            {
                string typeName             = this.GetBinding <string>(BindingNames.NewTypeName);
                string typeNamespace        = this.GetBinding <string>(BindingNames.NewTypeNamespace);
                string typeTitle            = this.GetBinding <string>(BindingNames.NewTypeTitle);
                bool   hasCaching           = this.GetBinding <bool>(BindingNames.HasCaching);
                bool   hasPublishing        = this.GetBinding <bool>(BindingNames.HasPublishing);
                bool   hasLocalization      = this.GetBinding <bool>(BindingNames.HasLocalization);
                bool   isSearchable         = this.GetBinding <bool>(BindingNames.IsSearchable);
                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);

                GeneratedTypesHelper helper;
                Type interfaceType = null;
                if (this.BindingExist(BindingNames.InterfaceType))
                {
                    interfaceType = this.GetBinding <Type>(BindingNames.InterfaceType);

                    helper = new GeneratedTypesHelper(interfaceType);
                }
                else
                {
                    helper = new GeneratedTypesHelper();
                }

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

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

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

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

                if (interfaceType != null)
                {
                    if (hasLocalization != DataLocalizationFacade.IsLocalized(interfaceType) &&
                        DataFacade.GetData(interfaceType).ToDataEnumerable().Any())
                    {
                        this.ShowMessage(
                            DialogType.Error,
                            Texts.AddNewInterfaceTypeStep1_ErrorTitle,
                            "It's not possible to change localization through the current tab"
                            );
                        return;
                    }
                }


                if (helper.IsEditProcessControlledAllowed)
                {
                    helper.SetCacheable(hasCaching);
                    helper.SetPublishControlled(hasPublishing);
                    helper.SetLocalizedControlled(hasLocalization);
                    helper.SetSearchable(isSearchable);
                }

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


                if (IsPageDataFolder && !this.BindingExist(BindingNames.InterfaceType))
                {
                    Type targetType = TypeManager.GetType(this.Payload);

                    helper.SetForeignKeyReference(targetType, Composite.Data.DataAssociationType.Aggregation);
                }

                bool originalTypeDataExists = false;
                if (interfaceType != null)
                {
                    originalTypeDataExists = DataFacade.HasDataInAnyScope(interfaceType);
                }

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


                helper.CreateType(originalTypeDataExists);

                string serializedTypeName = TypeManager.SerializeType(helper.InterfaceType);

                EntityToken entityToken = new GeneratedDataTypesElementProviderTypeEntityToken(
                    serializedTypeName,
                    this.EntityToken.Source,
                    IsPageDataFolder ? GeneratedDataTypesElementProviderRootEntityToken.PageDataFolderTypeFolderId
                                     : GeneratedDataTypesElementProviderRootEntityToken.GlobalDataTypeFolderId
                    );

                if (originalTypeDataExists)
                {
                    SetSaveStatus(true);
                }
                else
                {
                    SetSaveStatus(true, entityToken);
                }


                if (!this.BindingExist(BindingNames.InterfaceType))
                {
                    this.AcquireLock(entityToken);
                }

                this.UpdateBinding(BindingNames.InterfaceType, helper.InterfaceType);
                this.UpdateBinding(BindingNames.KeyFieldReadOnly, true);

                this.UpdateBinding(BindingNames.ViewLabel, typeTitle);
                RerenderView();

                //this.WorkflowResult = TypeManager.SerializeType(helper.InterfaceType);


                UserSettings.LastSpecifiedNamespace = typeNamespace;

                var parentTreeRefresher = this.CreateParentTreeRefresher();
                parentTreeRefresher.PostRefreshMessages(entityToken);
            }
            catch (Exception ex)
            {
                Log.LogCritical("Add New Interface Failed", ex);

                this.ShowMessage(DialogType.Error, ex.Message, ex.Message);
            }
        }
        private void codeActivity1_ExecuteCode(object sender, EventArgs e)
        {
            try
            {
                string typeName = this.GetBinding<string>(BindingNames.NewTypeName);
                string typeNamespace = this.GetBinding<string>(BindingNames.NewTypeNamespace);
                string typeTitle = this.GetBinding<string>(BindingNames.NewTypeTitle);
                bool hasCaching = this.GetBinding<bool>(BindingNames.HasCaching);
                bool hasPublishing = this.GetBinding<bool>(BindingNames.HasPublishing);
                bool hasLocalization = this.GetBinding<bool>(BindingNames.HasLocalization);
                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);

                GeneratedTypesHelper helper;
                Type interfaceType = null;
                if (this.BindingExist(BindingNames.InterfaceType))
                {
                    interfaceType = this.GetBinding<Type>(BindingNames.InterfaceType);

                    helper = new GeneratedTypesHelper(interfaceType);
                }
                else
                {
                    helper = new GeneratedTypesHelper();
                }

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

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

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

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

                if(interfaceType != null)
                {
                    if(hasLocalization != DataLocalizationFacade.IsLocalized(interfaceType)
                        && DataFacade.GetData(interfaceType).ToDataEnumerable().Any())
                    {
                        this.ShowMessage(
                            DialogType.Error,
                            Texts.AddNewInterfaceTypeStep1_ErrorTitle,
                            "It's not possible to change localization through the current tab"
                        );
                        return;             
                    }
                }


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

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


                if (IsPageDataFolder && !this.BindingExist(BindingNames.InterfaceType))
                {
                    Type targetType = TypeManager.GetType(this.Payload);

                    helper.SetForeignKeyReference(targetType, Composite.Data.DataAssociationType.Aggregation);
                }

                bool originalTypeDataExists = false;
                if (interfaceType != null)
                {
                    originalTypeDataExists = DataFacade.HasDataInAnyScope(interfaceType);
                }

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


                helper.CreateType(originalTypeDataExists);

                string serializedTypeName = TypeManager.SerializeType(helper.InterfaceType);

                EntityToken entityToken = new GeneratedDataTypesElementProviderTypeEntityToken(
                    serializedTypeName, 
                    this.EntityToken.Source, 
                    IsPageDataFolder ? GeneratedDataTypesElementProviderRootEntityToken.PageDataFolderTypeFolderId
                                     : GeneratedDataTypesElementProviderRootEntityToken.GlobalDataTypeFolderId
                );

                if(originalTypeDataExists)
                {
                    SetSaveStatus(true);
                }
                else
                {
                    SetSaveStatus(true, entityToken);
                }
                

                if (!this.BindingExist(BindingNames.InterfaceType))
                {                    
                    this.AcquireLock(entityToken);
                }

                this.UpdateBinding(BindingNames.InterfaceType, helper.InterfaceType);
                this.UpdateBinding(BindingNames.KeyFieldReadOnly, true);

                this.UpdateBinding(BindingNames.ViewLabel, typeTitle);
                RerenderView();

                //this.WorkflowResult = TypeManager.SerializeType(helper.InterfaceType);


                UserSettings.LastSpecifiedNamespace = typeNamespace;

                var parentTreeRefresher = this.CreateParentTreeRefresher();
                parentTreeRefresher.PostRefreshMessages(entityToken);
            }
            catch (Exception ex)
            {
                Log.LogCritical("Add New Interface Failed", ex);

                this.ShowMessage(DialogType.Error, ex.Message, ex.Message);
            }
        }
        private void saveTypeCodeActivity_Save_ExecuteCode(object sender, EventArgs e)
        {
            try
            {
                string typeName = this.GetBinding<string>(this.NewTypeNameBindingName);
                string typeNamespace = this.GetBinding<string>(this.NewTypeNamespaceBindingName);
                string typeTitle = this.GetBinding<string>(this.NewTypeTitleBindingName);
                bool hasCaching = this.GetBinding<bool>(this.HasCachingNameBindingName);
                bool hasPublishing = this.GetBinding<bool>(this.HasPublishingBindingName);
                bool hasLocalization = this.GetBinding<bool>("HasLocalization");
                string labelFieldName = this.GetBinding<string>(this.LabelFieldNameBindingName);
                var dataFieldDescriptors = this.GetBinding<List<DataFieldDescriptor>>(this.DataFieldDescriptorsBindingName);


                GeneratedTypesHelper helper;

                Type interfaceType = null;
                if (this.BindingExist("InterfaceType"))
                {
                    interfaceType = this.GetBinding<Type>("InterfaceType");

                    helper = new GeneratedTypesHelper(interfaceType);
                }
                else
                {
                    helper = new GeneratedTypesHelper();
                }

                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,
                            "${Composite.Plugins.GeneratedDataTypesElementProvider, AddNewCompositionTypeWorkflow.ErrorTitle}",
                            errorMessage
                        );
                    return;
                }

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

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

                if (!this.BindingExist("InterfaceType"))
                {
                    Type targetType = TypeManager.GetType(this.Payload);

                    helper.SetForeignKeyReference(targetType, Composite.Data.DataAssociationType.Composition);
                }

                bool originalTypeDataExists = false;
                if (interfaceType != null)
                {
                    originalTypeDataExists = DataFacade.HasDataInAnyScope(interfaceType);
                }

                if (helper.TryValidateUpdate(originalTypeDataExists, out errorMessage) == false)
                {
                    this.ShowMessage(
                            DialogType.Warning,
                            "${Composite.Plugins.GeneratedDataTypesElementProvider, AddNewCompositionTypeWorkflow.ErrorTitle}",
                            errorMessage
                        );
                    return;
                }

                helper.CreateType(originalTypeDataExists);

                if (originalTypeDataExists)
                {
                    SetSaveStatus(true);
                }
                else
                {
                    string serializedTypeName = TypeManager.SerializeType(helper.InterfaceType);
                    EntityToken entityToken = new GeneratedDataTypesElementProviderTypeEntityToken(
                        serializedTypeName,
                        this.EntityToken.Source,
                        GeneratedDataTypesElementProviderRootEntityToken.PageMetaDataTypeFolderId);

                    SetSaveStatus(true, entityToken);
                }



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

                this.WorkflowResult = TypeManager.SerializeType(helper.InterfaceType);

                UserSettings.LastSpecifiedNamespace = typeNamespace;

                ParentTreeRefresher parentTreeRefresher = this.CreateParentTreeRefresher();
                parentTreeRefresher.PostRefreshMesseges(this.EntityToken);
            }
            catch (Exception ex)
            {
                LoggingService.LogCritical("AddNewCompositionTypeWorkflow", ex);

                this.ShowMessage(DialogType.Error, ex.Message, ex.Message);
            }
        }
        private void saveTypeCodeActivity_Save_ExecuteCode(object sender, EventArgs e)
        {
            try
            {
                string typeName             = this.GetBinding <string>(this.NewTypeNameBindingName);
                string typeNamespace        = this.GetBinding <string>(this.NewTypeNamespaceBindingName);
                string typeTitle            = this.GetBinding <string>(this.NewTypeTitleBindingName);
                bool   hasCaching           = this.GetBinding <bool>(this.HasCachingNameBindingName);
                bool   hasPublishing        = this.GetBinding <bool>(this.HasPublishingBindingName);
                bool   hasLocalization      = this.GetBinding <bool>("HasLocalization");
                string labelFieldName       = this.GetBinding <string>(this.LabelFieldNameBindingName);
                var    dataFieldDescriptors = this.GetBinding <List <DataFieldDescriptor> >(this.DataFieldDescriptorsBindingName);


                GeneratedTypesHelper helper;

                Type interfaceType = null;
                if (this.BindingExist("InterfaceType"))
                {
                    interfaceType = this.GetBinding <Type>("InterfaceType");

                    helper = new GeneratedTypesHelper(interfaceType);
                }
                else
                {
                    helper = new GeneratedTypesHelper();
                }

                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,
                        "${Composite.Plugins.GeneratedDataTypesElementProvider, AddNewCompositionTypeWorkflow.ErrorTitle}",
                        errorMessage
                        );
                    return;
                }

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

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

                if (!this.BindingExist("InterfaceType"))
                {
                    Type targetType = TypeManager.GetType(this.Payload);

                    helper.SetForeignKeyReference(targetType, Composite.Data.DataAssociationType.Composition);
                }

                bool originalTypeDataExists = false;
                if (interfaceType != null)
                {
                    originalTypeDataExists = DataFacade.HasDataInAnyScope(interfaceType);
                }

                if (helper.TryValidateUpdate(originalTypeDataExists, out errorMessage) == false)
                {
                    this.ShowMessage(
                        DialogType.Warning,
                        "${Composite.Plugins.GeneratedDataTypesElementProvider, AddNewCompositionTypeWorkflow.ErrorTitle}",
                        errorMessage
                        );
                    return;
                }

                helper.CreateType(originalTypeDataExists);

                if (originalTypeDataExists)
                {
                    SetSaveStatus(true);
                }
                else
                {
                    string      serializedTypeName = TypeManager.SerializeType(helper.InterfaceType);
                    EntityToken entityToken        = new GeneratedDataTypesElementProviderTypeEntityToken(
                        serializedTypeName,
                        this.EntityToken.Source,
                        GeneratedDataTypesElementProviderRootEntityToken.PageMetaDataTypeFolderId);

                    SetSaveStatus(true, entityToken);
                }



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

                this.WorkflowResult = TypeManager.SerializeType(helper.InterfaceType);

                UserSettings.LastSpecifiedNamespace = typeNamespace;

                ParentTreeRefresher parentTreeRefresher = this.CreateParentTreeRefresher();
                parentTreeRefresher.PostRefreshMesseges(this.EntityToken);
            }
            catch (Exception ex)
            {
                LoggingService.LogCritical("AddNewCompositionTypeWorkflow", ex);

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