/// <summary>
        /// 
        /// </summary>
        /// <param name="interfaceType"></param>
        /// <param name="existingDataTypeDescriptor">Use null to get existing data type descriptor</param>
        /// <param name="errorMessage"></param>
        /// <returns></returns>
        public static bool Validate(Type interfaceType, DataTypeDescriptor existingDataTypeDescriptor, out string errorMessage)
        {
            if (existingDataTypeDescriptor == null)
            {
                existingDataTypeDescriptor = DataMetaDataFacade.GetDataTypeDescriptor(interfaceType.GetImmutableTypeId());

                if (existingDataTypeDescriptor == null)
                {
                    errorMessage = null;
                    return true;
                }
            }

            errorMessage = _typeSpecificValidations.GetOrAdd(
                interfaceType,
                f =>
                {
                    string message;
                    bool isValid = DataTypeValidator.Validate(interfaceType, existingDataTypeDescriptor, out message);

                    if (isValid) return null;

                    var sb = new StringBuilder();
                    sb.AppendLine(string.Format("The data type interface '{0}' did not validate and can't be used at the moment.", interfaceType));
                    sb.AppendLine(message);

                    return sb.ToString();
                }
            );

            return errorMessage == null;
        }
        /// <summary>
        /// This method will return the type of the empty data class type.
        /// If the type does not exist, one will be runtime code generated
        /// using the type to get a data type descriptor.
        /// </summary>
        /// <param name="interfaceType">The data interface type to get the empty class type for.</param>
        /// <param name="forceReCompilation">
        /// If this is true a new empty class will be 
        /// compiled at runtime regardless if it exists or not.
        /// Use with caution!
        /// </param>
        /// <returns>The empty class type for the given data interface type.</returns>
        public static Type GetEmptyDataClassType(Type interfaceType, bool forceReCompilation = false)
        {
            VerifyAssemblyLocation(interfaceType);

            var dataTypeDescriptor = DataMetaDataFacade.GetDataTypeDescriptor(interfaceType.GetImmutableTypeId(), true);

            return GetEmptyDataClassType(dataTypeDescriptor, forceReCompilation);
        }
示例#3
0
        // Overload
        /// <exclude />
        public static DataTypeDescriptor GetDataTypeDescriptor(Type typeToDescript)
        {
            DataTypeDescriptor dataTypeDescriptor;

            if (!TryGetDataTypeDescriptor(typeToDescript.GetImmutableTypeId(), out dataTypeDescriptor))
            {
                dataTypeDescriptor = BuildNewDataTypeDescriptor(typeToDescript);
            }

            return dataTypeDescriptor;
        }
        internal void UpdateSupportedDataTypeStore(Type interfaceType, XmlDataTypeStore xmlDataTypeStore)
        {
            Type type = _dataTypeStores.Where(f => f.Value.DataTypeDescriptor.DataTypeId == interfaceType.GetImmutableTypeId()).Select(f => f.Key).Single();
            _dataTypeStores.Remove(type);
            _dataTypeStores.Add(interfaceType, xmlDataTypeStore);

            _supportedInterface.Remove(type);
            _supportedInterface.Add(interfaceType);

            _knownInterface.Remove(type);
            _knownInterface.Add(interfaceType);
        }
        /// <exclude />
        public static IUnpublishSchedule GetUnpublishSchedule(Type dataType, string id, string cultureName)
        {
            Guid dataTypeId = dataType.GetImmutableTypeId();
            var query = DataFacade.GetData<IUnpublishSchedule>().Where(ps => ps.DataId == id && ps.DataTypeId == dataTypeId);

            if (DataLocalizationFacade.IsLocalized(dataType))
            {
                query = query.Where(ps => ps.LocaleCultureName == cultureName);
            }

            return query.FirstOrDefault();
        }
        /// <summary>
        /// This method will return the type of the empty data class type.
        /// If the type does not exist, one will be runtime code generated
        /// using the type to get a data type descriptor.
        /// </summary>
        /// <param name="interfaceType">The data interface type to get the empty class type for.</param>
        /// <param name="forceReCompilation">
        /// If this is true a new empty class will be 
        /// compiled at runtime regardless if it exists or not.
        /// Use with caution!
        /// </param>
        /// <returns>The empty class type for the given data interface type.</returns>
        public static Type GetEmptyDataClassType(Type interfaceType, bool forceReCompilation = false)
        {
            if (!DataTypeTypesManager.IsAllowedDataTypeAssembly(interfaceType))
            {
                string message = string.Format("The data interface '{0}' is not located in an assembly in the website Bin folder. Please move it to that location", interfaceType);
                Log.LogError("EmptyDataClassTypeManager", message);
                throw new InvalidOperationException(message);
            }

            DataTypeDescriptor dataTypeDescriptor = DataMetaDataFacade.GetDataTypeDescriptor(interfaceType.GetImmutableTypeId(), true);

            return GetEmptyDataClassType(dataTypeDescriptor, forceReCompilation);
        }
        /// <exclude />
        public static void CreateUnpublishSchedule(Type dataType, string id, string cultureName, DateTime date, WorkflowInstance workflow)
        {
            var unpublishSchedule = DataFacade.BuildNew<IUnpublishSchedule>();

            unpublishSchedule.Id = Guid.NewGuid();
            unpublishSchedule.DataTypeId = dataType.GetImmutableTypeId();
            unpublishSchedule.DataId = id;
            unpublishSchedule.UnpublishDate = date;
            unpublishSchedule.WorkflowInstanceId = workflow.InstanceId;
            unpublishSchedule.LocaleCultureName = DataLocalizationFacade.IsLocalized(dataType) ? cultureName : "";

            DataFacade.AddNew(unpublishSchedule);
        }
示例#8
0
        /// <summary>
        /// Removes a data folder type for the given page
        /// </summary>
        /// <param name="page"></param>
        /// <param name="dataFolderType"></param>
        /// <param name="deleteExistingFolderData"></param>
        public static void RemoveFolderDefinition(this IPage page, Type dataFolderType, bool deleteExistingFolderData = true)
        {
            Guid dataFolderTypeId = dataFolderType.GetImmutableTypeId();

            if (!deleteExistingFolderData)
            {
                RemoveFolderDefinitionInternal(page.Id, dataFolderTypeId);
                return;
            }

            using (TransactionScope transactionScope = TransactionsFacade.CreateNewScope())
            {
                DataFacade.ForEachDataScope(dataFolderType, () =>
                {
                    IEnumerable<IData> dataset = page.GetFolderData(dataFolderType);
                    DataFacade.Delete(dataset);
                });


                RemoveFolderDefinitionInternal(page.Id, dataFolderTypeId);

                transactionScope.Complete();
            }
        }
示例#9
0
 /// <summary>
 /// Adds a data folder type to the given page
 /// </summary>
 /// <param name="page"></param>
 /// <param name="dataFolderType"></param>
 // Overload
 public static void AddFolderDefinition(this IPage page, Type dataFolderType)
 {
     AddFolderDefinition(page, dataFolderType.GetImmutableTypeId());
 }
示例#10
0
        /// <summary>
        /// Returns the id of a folder definition given the page and folder type
        /// </summary>
        /// <param name="page"></param>
        /// <param name="folderType"></param>
        /// <returns></returns>
        public static Guid GetFolderDefinitionId(this IPage page, Type folderType)
        {
            Verify.ArgumentNotNull(page, "page");

            return GetFolderDefinitionId(page, folderType.GetImmutableTypeId());
        }
示例#11
0
 // Overload
 /// <exclude />
 public static bool TryGetDataTypeDescriptor(Type interfaceType, out DataTypeDescriptor dataTypeDescriptor)
 {
     return _dynamicTypeManager.TryGetDataTypeDescriptor(interfaceType.GetImmutableTypeId(), out dataTypeDescriptor);
 }
示例#12
0
        /// <summary>
        /// For internal use only!!!
        /// This method will create the store if the interfaceType has not been configured.
        /// </summary>
        /// <param name="interfaceType"></param>
        /// <param name="providerName"></param>
        // Helper
        public static void EnsureCreateStore(Type interfaceType, string providerName)
        {
            IEnumerable<string> dynamicProviderNames;

            if (providerName == null)
            {
                // Checking if any of existing dynamic data providers already has a store for the specified interface type
                providerName = DataProviderRegistry.DefaultDynamicTypeDataProviderName;
                dynamicProviderNames = DataProviderRegistry.DynamicDataProviderNames;
            }
            else
            {
                dynamicProviderNames = new[] {providerName};
            }

            var possibleMatches = dynamicProviderNames
                .Select(DataProviderPluginFacade.GetDataProvider)
                .Cast<IDynamicDataProvider>()
                .SelectMany(dynamicDataProvider => dynamicDataProvider.GetKnownInterfaces())
                .Where(i => i.FullName == interfaceType.FullName);

            foreach(var match in possibleMatches)
            {
                if(match == interfaceType) return;

                if (match.GetImmutableTypeId() == interfaceType.GetImmutableTypeId())
                {
                    throw new InvalidOperationException($"The same type '{match.FullName}' is loaded in memory twice. Location 1: '{match.Assembly.Location}', location 2: {interfaceType.Assembly.Location}");
                }
            }

            var dataTypeDescriptor = BuildNewDataTypeDescriptor(interfaceType);

            CreateStore(providerName, dataTypeDescriptor, true);

            if (!SystemSetupFacade.SetupIsRunning)
            {
                CodeGenerationManager.GenerateCompositeGeneratedAssembly(true);
            }
        }
示例#13
0
        /// <summary>
        /// This method will return the data type descriptor for the given data type id.
        /// If the data type descriptor has not yet been created (file not existing) and
        /// the <paramref name="allowTypeMetaDataCreation"/> is set to true,
        /// this method will try getting it through the <see cref="Composite.Data.DynamicTypes.Foundation.ReflectionBasedDescriptorBuilder"/>
        /// based on <paramref name="interfaceType"/>.
        /// </summary>
        /// <param name="interfaceType">The data type.</param>
        /// <param name="allowTypeMetaDataCreation">
        /// If this is true and the data type descriptor does not exists, it will be created.
        /// </param>
        /// <returns></returns>
        public static DataTypeDescriptor GetDataTypeDescriptor(Type interfaceType, bool allowTypeMetaDataCreation = false)
        {
            Verify.ArgumentNotNull(interfaceType, nameof(interfaceType));

            Initialize();

            DataTypeDescriptor dataTypeDescriptor;

            Guid dataTypeId = interfaceType.GetImmutableTypeId();

            _dataTypeDescriptorCache.TryGetValue(dataTypeId, out dataTypeDescriptor);

            if (dataTypeDescriptor != null) return dataTypeDescriptor;

            if (!allowTypeMetaDataCreation) return null;

            var newDataTypeDescriptor = ReflectionBasedDescriptorBuilder.Build(interfaceType);
            PersistMetaData(newDataTypeDescriptor);

            return newDataTypeDescriptor;
        }