public static IActionTokenProvider GetActionTokenProvider(Type elementProviderType, string actionTypeName)
        {
            Dictionary<string, IActionTokenProvider> actionTokenProviders;

            using (_resourceLocker.Locker)
            {
                if (_resourceLocker.Resources.ActionTokenProviderCache.TryGetValue(elementProviderType, out actionTokenProviders) == false)
                {
                    actionTokenProviders = new Dictionary<string, IActionTokenProvider>();

                    var pairs =
                        (from t in elementProviderType.GetCustomAttributesRecursively<ActionTokenProviderAttribute>()
                         select new { ActionTypeName = t.ActionTypeName, ActionTokenProviderType = t.ActionTokenProviderType });

                    foreach (var pair in pairs)
                    {
                        if (actionTokenProviders.ContainsKey(pair.ActionTypeName) == false)
                        {
                            IActionTokenProvider newActionTokenProvider = (IActionTokenProvider)Activator.CreateInstance(pair.ActionTokenProviderType);

                            actionTokenProviders.Add(pair.ActionTypeName, newActionTokenProvider);
                        }
                    }

                    _resourceLocker.Resources.ActionTokenProviderCache.Add(elementProviderType, actionTokenProviders);
                }

                IActionTokenProvider actionTokenProvider;

                actionTokenProviders.TryGetValue(actionTypeName, out actionTokenProvider);

                return actionTokenProvider;
            }
        }
        public static bool IsActionIgnored(Type elementProviderType, string actionTypeName)
        {
            List<string> ignoredActionTypes;

            using (_resourceLocker.Locker)
            {
                if (_resourceLocker.Resources.IgnoreActionCache.TryGetValue(elementProviderType, out ignoredActionTypes) == false)
                {
                    ignoredActionTypes =
                        (from t in elementProviderType.GetCustomAttributesRecursively<IgnoreActionAttribute>()
                         select t.ActionTypeName).Distinct().ToList();

                    _resourceLocker.Resources.IgnoreActionCache.Add(elementProviderType, ignoredActionTypes);
                }
            }

            return ignoredActionTypes.Contains(actionTypeName);
        }
        /// <exclude />
        public static DataTypeDescriptor Build(Type type)
        {
            Verify.ArgumentNotNull(type, "type");
            Verify.ArgumentCondition(typeof(IData).IsAssignableFrom(type), "type", "{0} does not implement {1}".FormatWith(type.FullName, typeof(IData).FullName));

            Guid dataTypeId = DynamicTypeReflectionFacade.GetImmutableTypeId(type);

            bool isCodeGenerated = type.GetCustomInterfaceAttributes<CodeGeneratedAttribute>().Any();

            var typeDescriptor = new DataTypeDescriptor(dataTypeId, type.Namespace, type.Name, TypeManager.SerializeType(type), isCodeGenerated)
            {
                Title = DynamicTypeReflectionFacade.GetTitle(type),
                LabelFieldName = DynamicTypeReflectionFacade.GetLabelPropertyName(type),
                InternalUrlPrefix = DynamicTypeReflectionFacade.GetInternalUrlPrefix(type),
                DataAssociations = DynamicTypeReflectionFacade.GetDataTypeAssociationDescriptors(type)
            };
            
            List<Type> superInterfaces = type.GetInterfacesRecursively(t => typeof(IData).IsAssignableFrom(t) && t != typeof(IData));
            typeDescriptor.SetSuperInterfaces(superInterfaces);
            
            Type buildNewHandlerType = DynamicTypeReflectionFacade.GetBuildNewHandlerType(type);
            if (buildNewHandlerType != null) typeDescriptor.BuildNewHandlerTypeName = TypeManager.SerializeType(buildNewHandlerType);


            foreach (PropertyInfo propertyInfo in type.GetProperties())
            {
                DataFieldDescriptor fieldDescriptor = BuildFieldDescriptor(propertyInfo, false);

                typeDescriptor.Fields.Add(fieldDescriptor);
            }

            foreach (Type superInterfaceType in superInterfaces)
            {
                foreach (PropertyInfo propertyInfo in superInterfaceType.GetProperties())
                {
                    if (propertyInfo.Name == nameof(IPageData.PageId) && propertyInfo.DeclaringType == typeof(IPageData))
                    {
                        continue;
                    }

                    DataFieldDescriptor fieldDescriptor = BuildFieldDescriptor(propertyInfo, true);

                    typeDescriptor.Fields.Add(fieldDescriptor);
                }
            }

            ValidateAndAddKeyProperties(typeDescriptor.KeyPropertyNames, typeDescriptor.VersionKeyPropertyNames, type);

            string[] storeSortOrder = DynamicTypeReflectionFacade.GetSortOrder(type);
            if (storeSortOrder != null)
            {
                foreach (string name in storeSortOrder)
                {
                    typeDescriptor.StoreSortOrderFieldNames.Add(name);
                }
            }

            CheckSortOrder(typeDescriptor);

            foreach (var dataScopeIdentifier in DynamicTypeReflectionFacade.GetDataScopes(type))
            {
                if (!typeDescriptor.DataScopes.Contains(dataScopeIdentifier))
                {
                    typeDescriptor.DataScopes.Add(dataScopeIdentifier);
                }
            }

            foreach (string keyPropertyName in type.GetKeyPropertyNames())
            {
                if (typeDescriptor.Fields[keyPropertyName] == null)
                {
                    throw new InvalidOperationException(
                        $"The type '{type}' has a non existing key property specified by the attribute '{typeof (KeyPropertyNameAttribute)}'");
                }
            }

            var indexes = new List<DataTypeIndex>();
            foreach (var indexAttribute in type.GetCustomAttributesRecursively<IndexAttribute>())
            {
                foreach (var field in indexAttribute.Fields)
                {
                    if (typeDescriptor.Fields[field.Item1] == null)
                    {
                        throw new InvalidOperationException($"Index field '{field.Item1}' is not defined");
                    }
                }

                indexes.Add(new DataTypeIndex(indexAttribute.Fields) { Clustered = indexAttribute.Clustered });
            }

            indexes.Sort((a,b) => string.Compare(a.ToString(), b.ToString(), StringComparison.Ordinal));

            typeDescriptor.Indexes = indexes;

            return typeDescriptor;
        }
            private static void AddProcessController(Resources resources, Type interfaceType, Type superProcessControllerInterfaceType, Type attributeType, Dictionary<Type, Type> processControllerTypes)
            {
                var publishAttributes = interfaceType.GetCustomAttributesRecursively(attributeType).Cast<ProcessControllerTypeAttribute>().ToList();

                if (publishAttributes.Count == 0) return;

                Type processControllerType = publishAttributes[0].ProcessControllerType;

                foreach (ProcessControllerTypeAttribute attribute in publishAttributes.Skip(1))
                {
                    Verify.That(attribute.ProcessControllerType != processControllerType,
                        "Only one '{0}' is allowed on the data type '{1}' or all attributes should have same process controller type", 
                        processControllerType, interfaceType);
                }

                processControllerTypes.Add(superProcessControllerInterfaceType, processControllerType);

                if (!resources.ProcessControllerTypes.Contains(processControllerType))
                {
                    resources.ProcessControllerTypes.Add(processControllerType);
                }
            }
Exemplo n.º 5
0
        private static void AddNewType(Type interfaceType)
        {
            List<DataAssociationAttribute> attributes = interfaceType.GetCustomAttributesRecursively<DataAssociationAttribute>().ToList();

            if (attributes.Count == 0)
            {
                return;
            }

            var dataAssociationInfos = new Dictionary<Type, DataAssociationInfo>();

            foreach (DataAssociationAttribute attribute in attributes)
            {
                if (attribute.AssociationType == DataAssociationType.None) throw new ArgumentException(string.Format("The associationType on the attribute '{0}' on the interface type '{1}' may not be '{2}'", typeof(DataAssociationAttribute), interfaceType, DataAssociationType.None));
                if (attribute.AssociatedInterfaceType == null) throw new ArgumentNullException(string.Format("The associatedInterfaceType on the attribute '{0}' on the interface type '{1}' is null", typeof(DataAssociationAttribute), interfaceType));

                List<Type> associatedTypes;

                Type associatedInterface = attribute.AssociatedInterfaceType;

                if (_associatedTypes.TryGetValue(associatedInterface, out associatedTypes) == false)
                {
                    associatedTypes = new List<Type>();

                    _associatedTypes.Add(associatedInterface, associatedTypes);

                    DataEventSystemFacade.SubscribeToDataAfterUpdate(associatedInterface, OnAfterDataUpdated, false);
                }

                associatedTypes.Add(interfaceType);


                PropertyInfo propertyInfo =
                    (from pi in interfaceType.GetAllProperties()
                     where pi.Name == attribute.ForeignKeyPropertyName
                     select pi).FirstOrDefault();

                if (propertyInfo == null) throw new ArgumentException(string.Format("The foreign key property name '{0}' set on the attribute '{1}' does not exist on the interface '{2}'", attribute.ForeignKeyPropertyName, typeof(DataAssociationAttribute), interfaceType));

                

                var dataAssociationInfo = new DataAssociationInfo
                {
                    AssociatedInterfaceType = associatedInterface,
                    ForeignKeyPropertyName = attribute.ForeignKeyPropertyName,
                    ForeignKeyPropertyInfo = propertyInfo,
                    AssociationType = attribute.AssociationType,
                };

                Verify.IsFalse(dataAssociationInfos.ContainsKey(associatedInterface), "Failed to register interface '{0}'. Data association already exist, type: '{1}'".FormatWith(interfaceType, associatedInterface));
                dataAssociationInfos.Add(associatedInterface, dataAssociationInfo);

                if (!DataProviderRegistry.AllInterfaces.Contains(associatedInterface))
                {
                    Log.LogCritical("DataReferenceRegistry", string.Format("The one type '{0}' is associated to the non supported data type '{1}'", interfaceType, associatedInterface));
                }
            }

            _dataAssociations.Add(interfaceType, dataAssociationInfos);
        }
Exemplo n.º 6
0
        private bool HasEntityTokenLockAttribute(Type workflowType)
        {
            bool hasEntityLockAttribute;
            if (!_hasEntityTokenLockAttributeCache.TryGetValue(workflowType, out hasEntityLockAttribute))
            {
                hasEntityLockAttribute = workflowType.GetCustomAttributesRecursively<EntityTokenLockAttribute>().Any();

                _hasEntityTokenLockAttributeCache.Add(workflowType, hasEntityLockAttribute);
            }

            return hasEntityLockAttribute;
        }
Exemplo n.º 7
0
        private void SetWorkflowPersistingType(Type workflowType, Guid instanceId)
        {
            List<AllowPersistingWorkflowAttribute> attributes = workflowType.GetCustomAttributesRecursively<AllowPersistingWorkflowAttribute>().ToList();

            Verify.That(attributes.Count <= 1, "More than one attribute of type '{0}' found", typeof(AllowPersistingWorkflowAttribute).FullName);

            var persistenceType = attributes.Count == 1 ? attributes[0].WorkflowPersistingType : WorkflowPersistingType.Never;

            using (_resourceLocker.Locker)
            {
                _resourceLocker.Resources.WorkflowPersistingTypeDictionary.Add(instanceId, persistenceType);
            }
        }
        public static ResourceHandle GetActionResourceHandle(Type elementProviderType, string actionTypeName)
        {
            Dictionary<string, ResourceHandle> actionResourceHandles;

            using (_resourceLocker.Locker)
            {
                if (_resourceLocker.Resources.ActionResourceHandleCache.TryGetValue(elementProviderType, out actionResourceHandles) == false)
                {
                    actionResourceHandles = new Dictionary<string, ResourceHandle>();

                    var pairs =
                        (from t in elementProviderType.GetCustomAttributesRecursively<ActionResourceHandleAttribute>()
                         select new { ActionTypeName = t.ActionTypeName, ActionResourceHandle = t.ActionResourceHandle });

                    foreach (var pair in pairs)
                    {
                        if (actionResourceHandles.ContainsKey(pair.ActionTypeName) == false)
                        {
                            actionResourceHandles.Add(pair.ActionTypeName, pair.ActionResourceHandle);
                        }
                    }

                    _resourceLocker.Resources.ActionResourceHandleCache.Add(elementProviderType, actionResourceHandles);
                }

                ResourceHandle actionResourceHandle;

                actionResourceHandles.TryGetValue(actionTypeName, out actionResourceHandle);

                return actionResourceHandle;
            }
        }