Esempio n. 1
0
        /// <exclude />
        protected virtual DocumentFieldFacet.FacetValuePreviewDelegate GetFacetValuePreviewFunction(PropertyInfo propertyInfo)
        {
            var foreignKey = propertyInfo.GetCustomAttributes <ForeignKeyAttribute>().FirstOrDefault();

            if (foreignKey != null)
            {
                var targetType = foreignKey.InterfaceType;
                if (targetType != null &&
                    DynamicTypeManager.TryGetDataTypeDescriptor(targetType, out DataTypeDescriptor typeDescriptor) &&
                    !string.IsNullOrEmpty(typeDescriptor.LabelFieldName))
                {
                    return(key =>
                    {
                        if (key == null)
                        {
                            return string.Empty;
                        }

                        var data = DataFacade.TryGetDataByUniqueKey(targetType, key);
                        return data?.GetLabel() ?? key.ToString();
                    });
                }
            }

            return(obj => obj);
        }
Esempio n. 2
0
        /// <summary>
        /// Gets a value indicating if data caching is possible for a specific data type
        /// </summary>
        /// <param name="interfaceType">The data type to check</param>
        /// <returns>True if caching is possible</returns>
        public static bool IsTypeCacheable(Type interfaceType)
        {
            Guid dataTypeId;
            DataTypeDescriptor dataTypeDescriptor;

            return(_isEnabled &&
                   (DataAttributeFacade.GetCachingType(interfaceType) == CachingType.Full ||
                    (interfaceType.TryGetImmutableTypeId(out dataTypeId) &&
                     DynamicTypeManager.TryGetDataTypeDescriptor(interfaceType, out dataTypeDescriptor) &&
                     dataTypeDescriptor.Cachable)));
        }
        private DataTypeDescriptor GetDataTypeDescriptor()
        {
            Type sourceDataType = GetSourceDataType();

            DataTypeDescriptor dataTypeDescriptor = null;

            if (DynamicTypeManager.TryGetDataTypeDescriptor(sourceDataType, out dataTypeDescriptor) == false)
            {
                dataTypeDescriptor = DynamicTypeManager.BuildNewDataTypeDescriptor(sourceDataType);
            }

            return(dataTypeDescriptor);
        }
Esempio n. 4
0
        /// <exclude />
        public virtual string GetFieldLabel(PropertyInfo propertyInfo)
        {
            var fieldName = GetDocumentFieldName(propertyInfo);

            if (fieldName == DocumentFieldNames.Description)
            {
                return(Texts.FieldNames_Description);
            }

            if (fieldName == DocumentFieldNames.LastUpdated)
            {
                return(Texts.FieldNames_LastUpdated);
            }
            if (propertyInfo.Name == nameof(IChangeHistory.ChangedBy))
            {
                return(Texts.FieldNames_UpdatedBy);
            }
            if (propertyInfo.Name == nameof(IMediaFile.MimeType))
            {
                return(Texts.FieldNames_MimeType);
            }
            if (propertyInfo.Name == nameof(IPage.PageTypeId))
            {
                return(Texts.FieldNames_PageTypeId);
            }

            var frpAttribute = propertyInfo.GetCustomAttribute <FormRenderingProfileAttribute>();

            if (!string.IsNullOrEmpty(frpAttribute?.Label))
            {
                return(frpAttribute.Label);
            }

            Guid immutableTypeId;
            DataTypeDescriptor dataTypeDescriptor;

            if (propertyInfo.DeclaringType.TryGetImmutableTypeId(out immutableTypeId) &&
                DynamicTypeManager.TryGetDataTypeDescriptor(immutableTypeId, out dataTypeDescriptor))
            {
                var fieldDescriptor = dataTypeDescriptor?.Fields.FirstOrDefault(f => f.Name == propertyInfo.Name);
                var label           = fieldDescriptor?.FormRenderingProfile?.Label;
                if (label != null)
                {
                    return(label);
                }
            }

            return(propertyInfo.Name);
        }
Esempio n. 5
0
 /// <exclude />
 public static IEnumerable <IPageTypeMetaDataTypeLink> RemoveDeadLinks(this IEnumerable <IPageTypeMetaDataTypeLink> pageTypeMetaDataTypeLinks)
 {
     foreach (IPageTypeMetaDataTypeLink pageTypeMetaDataTypeLink in pageTypeMetaDataTypeLinks)
     {
         DataTypeDescriptor dataTypeDescriptor;
         if (DynamicTypeManager.TryGetDataTypeDescriptor(pageTypeMetaDataTypeLink.DataTypeId, out dataTypeDescriptor) == false)
         {
             DataFacade.Delete <IPageTypeMetaDataTypeLink>(pageTypeMetaDataTypeLink);
         }
         else
         {
             yield return(pageTypeMetaDataTypeLink);
         }
     }
 }
        public static string CreateStaticDataType(Guid dataTypeId)
        {
            DataTypeDescriptor dataTypeDescriptor;

            DynamicTypeManager.TryGetDataTypeDescriptor(dataTypeId, out dataTypeDescriptor);

            var codeTypeDeclaration = Reflection.CallStaticMethod <CodeTypeDeclaration>("Composite.Data.GeneratedTypes.InterfaceCodeGenerator", "CreateCodeTypeDeclaration", dataTypeDescriptor);
            var csCompiler          = new CSharpCodeProvider();
            var sb = new StringBuilder();

            using (var sw = new StringWriter(sb))
            {
                csCompiler.GenerateCodeFromMember(codeTypeDeclaration, sw, new CodeGeneratorOptions());
            }
            return(sb.ToString());
        }
        private void finalizeCodeActivity_Finalize_ExecuteCode(object sender, EventArgs e)
        {
            IPageTypeMetaDataTypeLink pageTypeMetaDataTypeLink = this.GetDataItemFromEntityToken <IPageTypeMetaDataTypeLink>();

            DeleteTreeRefresher deleteTreeRefresher = this.CreateDeleteTreeRefresher(this.EntityToken);

            DataTypeDescriptor dataTypeDescriptor;

            if (DynamicTypeManager.TryGetDataTypeDescriptor(pageTypeMetaDataTypeLink.DataTypeId, out dataTypeDescriptor))
            {
                PageMetaDataFacade.RemoveDefinition(pageTypeMetaDataTypeLink.PageTypeId, pageTypeMetaDataTypeLink.Name);
            }

            DataFacade.Delete <IPageTypeMetaDataTypeLink>(pageTypeMetaDataTypeLink);

            deleteTreeRefresher.PostRefreshMesseges();
        }
        private void ValidateTypeExistence(object sender, ConditionalEventArgs e)
        {
            e.Result = true;

            IPageTypeMetaDataTypeLink pageTypeMetaDataTypeLink = this.GetDataItemFromEntityToken <IPageTypeMetaDataTypeLink>();

            DataTypeDescriptor dataTypeDescriptor;

            if (!DynamicTypeManager.TryGetDataTypeDescriptor(pageTypeMetaDataTypeLink.DataTypeId, out dataTypeDescriptor))
            {
                e.Result = false;

                DeleteTreeRefresher deleteTreeRefresher = CreateDeleteTreeRefresher(this.EntityToken);

                DataFacade.Delete <IPageTypeMetaDataTypeLink>(pageTypeMetaDataTypeLink);

                this.ShowMessage(
                    DialogType.Warning,
                    GetText("PageType.EditPageTypeMetaDataFieldWorkflow.ValidationError.MetaDataTypeNotExisting.Title"),
                    GetText("PageType.EditPageTypeMetaDataFieldWorkflow.ValidationError.MetaDataTypeNotExisting.Message"));

                deleteTreeRefresher.PostRefreshMesseges();
            }
        }