/// <exclude />
        public static XhtmlDocument RenderDataList <T>(IVisualFunction function, XhtmlDocument xhtmlDocument, DataTypeDescriptor typeDescriptor, FunctionContextContainer functionContextContainer, Expression <Func <T, bool> > filter)
            where T : class, IData
        {
            if (function == null)
            {
                throw new ArgumentNullException("function");
            }
            if (xhtmlDocument == null)
            {
                throw new ArgumentNullException("xhtmlDocument");
            }
            if (typeDescriptor == null)
            {
                throw new ArgumentNullException("typeDescriptor");
            }
            if (functionContextContainer == null)
            {
                throw new ArgumentNullException("functionContextContainer");
            }

            Type dataType = typeDescriptor.GetInterfaceType();

            if (dataType == null)
            {
                throw new InvalidOperationException(string.Format("'{0}' is not a known type manager type.", typeDescriptor.TypeManagerTypeName));
            }

            List <T> allData = DataFacade.GetData <T>(filter).ToList();

            List <T> itemsToList;

            if (function.OrderbyFieldName == "(random)")
            {
                int itemsInList  = allData.Count();
                int itemsToFetch = Math.Min(itemsInList, function.MaximumItemsToList);

                itemsToList = new List <T>();

                while (itemsToFetch > 0)
                {
                    int itemToGet = (Math.Abs(Guid.NewGuid().GetHashCode()) % itemsInList); // (new Random()).Next(0, itemsInList);

                    itemsToList.Add(allData[itemToGet]);
                    allData.RemoveAt(itemToGet);

                    itemsToFetch--;
                    itemsInList--;
                }
            }
            else
            {
                IComparer <T> comparer = GenericComparer <T> .Build(typeDescriptor.GetInterfaceType(), function.OrderbyFieldName, function.OrderbyAscending);

                allData.Sort(comparer);

                itemsToList = allData.Take(function.MaximumItemsToList).ToList();
            }

            return(RenderDataListImpl <T>(xhtmlDocument, typeDescriptor, itemsToList, functionContextContainer));
        }
예제 #2
0
        public XmlDataTypeStore(DataTypeDescriptor dataTypeDescriptor, Type dataProviderHelperType, Type dataIdClassType, IEnumerable <XmlDataTypeStoreDataScope> xmlDateTypeStoreDataScopes, bool isGeneratedDataType)
        {
            DataTypeDescriptor     = dataTypeDescriptor ?? throw new ArgumentNullException(nameof(dataTypeDescriptor));
            DataProviderHelperType = dataProviderHelperType ?? throw new ArgumentNullException(nameof(dataProviderHelperType));
            DataIdClassType        = dataIdClassType ?? throw new ArgumentNullException(nameof(dataIdClassType));
            IsGeneratedDataType    = isGeneratedDataType;

            _xmlDateTypeStoreDataScopes = xmlDateTypeStoreDataScopes.Evaluate();

            var ordering = new List <Func <XElement, IComparable> >();

            foreach (string key in dataTypeDescriptor.KeyPropertyNames)
            {
                XName localKey = key;
                ordering.Add(f => (string)f.Attribute(localKey) ?? "");
            }
            Func <IEnumerable <XElement>, IOrderedEnumerable <XElement> > orderer = f => ordering.Skip(1).Aggregate(f.OrderBy(ordering.First()), Enumerable.ThenBy);

            foreach (XmlDataTypeStoreDataScope xmlDataTypeStoreDataScope in _xmlDateTypeStoreDataScopes)
            {
                DataScopeIdentifier dataScopeIdentifier = DataScopeIdentifier.Deserialize(xmlDataTypeStoreDataScope.DataScopeName);
                CultureInfo         culture             = CultureInfo.CreateSpecificCulture(xmlDataTypeStoreDataScope.CultureName);
                Type dataType = dataTypeDescriptor.GetInterfaceType();

                Action cacheFlush = () => DataEventSystemFacade.FireExternalStoreChangedEvent(dataType, dataScopeIdentifier.ToPublicationScope(), culture);
                XmlDataProviderDocumentCache.RegisterExternalFileChangeAction(xmlDataTypeStoreDataScope.Filename, cacheFlush);

                XmlDataProviderDocumentWriter.RegisterFileOrderer(xmlDataTypeStoreDataScope.Filename, orderer);
            }
        }
        /// <exclude />
        public GeneratedTypesHelper(DataTypeDescriptor oldDataTypeDescriptor)
        {
            Verify.ArgumentNotNull(oldDataTypeDescriptor, "oldDataTypeDescriptor");

            _oldType = oldDataTypeDescriptor.GetInterfaceType();
            _oldDataTypeDescriptor = oldDataTypeDescriptor;

            Initialize();
        }
        /// <exclude />
        public static XhtmlDocument RenderCompleteDataList(IVisualFunction function, XhtmlDocument xhtmlDocument, DataTypeDescriptor typeDescriptor, FunctionContextContainer functionContextContainer)
        {
            Type typeofClassWithGenericStaticMethod = typeof(RenderingHelper);

            // Grabbing the specific static method
            MethodInfo methodInfo = typeofClassWithGenericStaticMethod.GetMethod("RenderCompleteDataListImpl", System.Reflection.BindingFlags.Static | BindingFlags.NonPublic);

            // Binding the method info to generic arguments
            Type[]     genericArguments  = new Type[] { typeDescriptor.GetInterfaceType() };
            MethodInfo genericMethodInfo = methodInfo.MakeGenericMethod(genericArguments);

            // Simply invoking the method and passing parameters
            // The null parameter is the object to call the method from. Since the method is
            // static, pass null.
            return((XhtmlDocument)genericMethodInfo.Invoke(null, new object[] { function, xhtmlDocument, typeDescriptor, functionContextContainer }));
        }
예제 #5
0
        internal void AddDataTypeData(Type type)
        {
            IEnumerable <Type> globalDataTypeInterfaces = DataFacade
                                                          .GetAllInterfaces(UserType.Developer)
                                                          .Where(interfaceType => interfaceType.Assembly != typeof(IData).Assembly)
                                                          .OrderBy(t => t.FullName)
                                                          .Except(PageFolderFacade.GetAllFolderTypes())
                                                          .Except(PageMetaDataFacade.GetAllMetaDataTypes());

            IEnumerable <Type> pageDataTypeInterfaces = PageFolderFacade.GetAllFolderTypes();
            IEnumerable <Type> pageMetaTypeInterfaces = PageMetaDataFacade.GetAllMetaDataTypes();

            DataTypeDescriptor dataTypeDescriptor = DynamicTypeManager.GetDataTypeDescriptor(type);

            var resolvedType = dataTypeDescriptor.GetInterfaceType();

            // TODO: make by association
            if (globalDataTypeInterfaces.Contains(resolvedType))
            {
                AddData(type);
            }
            else if (pageDataTypeInterfaces.Contains(resolvedType))
            {
                AddData <IPageFolderDefinition>(d => d.FolderTypeId == dataTypeDescriptor.DataTypeId);
                AddData(type);
            }
            else if (pageMetaTypeInterfaces.Contains(resolvedType))
            {
                foreach (var j in DataFacade.GetData <IPageMetaDataDefinition>(d => d.MetaDataTypeId == dataTypeDescriptor.DataTypeId))
                {
                    //Add only one MetaTypeTab
                    AddData <ICompositionContainer>(d => d.Id == j.MetaDataContainerId);
                }
                AddData <IPageMetaDataDefinition>(d => d.MetaDataTypeId == dataTypeDescriptor.DataTypeId);
                AddData(type);
            }
        }
예제 #6
0
        public void DropStore(DataTypeDescriptor dataTypeDescriptor)
        {
            using (TimerProfilerFacade.CreateTimerProfiler())
            {
                SqlStoreManipulator.DropStoresForType(_dataProviderContext.ProviderName, dataTypeDescriptor);

                InterfaceConfigurationManipulator.Remove(_dataProviderContext.ProviderName, dataTypeDescriptor);
                InterfaceConfigurationElement oldElement = _interfaceConfigurationElements.FirstOrDefault(f => f.DataTypeId == dataTypeDescriptor.DataTypeId);
                if (oldElement != null)
                {
                    _interfaceConfigurationElements.Remove(oldElement);
                }

                Guid dataTypeId    = dataTypeDescriptor.DataTypeId;
                int  storesRemoved = _createdSqlDataTypeStoreTables.RemoveAll(item => item.DataTypeId == dataTypeId);

                if (storesRemoved > 0)
                {
                    Type interfaceType = dataTypeDescriptor.GetInterfaceType();

                    _sqlDataTypeStoresContainer.ForgetInterface(interfaceType);
                }
            }
        }
        private static XhtmlDocument RenderDataListImpl <T>(XhtmlDocument templateDocument, DataTypeDescriptor typeDescriptor, List <T> dataList, FunctionContextContainer functionContextContainer)
            where T : class, IData
        {
            XhtmlDocument outputDocument = new XhtmlDocument();

            if (dataList.Count > 0)
            {
                Type     interfaceType = typeDescriptor.GetInterfaceType();
                XElement templateBody  = new XElement(templateDocument.Body);

                Dictionary <string, PropertyInfo> propertyInfoLookup =
                    interfaceType.GetPropertiesRecursively(p => typeof(IData).IsAssignableFrom(p.DeclaringType)).ToList().ToDictionary(p => p.Name);

                List <string> fieldsWithReferenceRendering = new List <string>();

                foreach (PropertyInfo dataPropertyInfo in propertyInfoLookup.Values)
                {
                    Type referencedType = null;
                    if (dataPropertyInfo.TryGetReferenceType(out referencedType))
                    {
                        bool canRender = DataXhtmlRenderingServices.CanRender(referencedType, XhtmlRenderingType.Embedable);

                        if (canRender)
                        {
                            fieldsWithReferenceRendering.Add(dataPropertyInfo.Name);
                        }
                    }
                }


                // any optimization would do wonders
                foreach (IData data in dataList)
                {
                    XElement currentRowElementsContainer = new XElement(templateBody);

                    List <DynamicTypeMarkupServices.FieldReferenceDefinition> references =
                        DynamicTypeMarkupServices.GetFieldReferenceDefinitions(currentRowElementsContainer, typeDescriptor.TypeManagerTypeName).ToList();

                    // perf waste - if some props are not used;
                    Dictionary <string, object> objectValues =
                        propertyInfoLookup.ToDictionary(f => f.Key, f => f.Value.GetValue(data, new object[] { }));

                    foreach (DynamicTypeMarkupServices.FieldReferenceDefinition reference in references)
                    {
                        object value = null;

                        if (fieldsWithReferenceRendering.Contains(reference.FieldName))
                        {
                            // reference field with rendering...
                            Type referencedType = null;
                            if (propertyInfoLookup[reference.FieldName].TryGetReferenceType(out referencedType))
                            {
                                if (objectValues[reference.FieldName] != null)
                                {
                                    IDataReference dataReference = DataReferenceFacade.BuildDataReference(referencedType, objectValues[reference.FieldName]);
                                    try
                                    {
                                        value = DataXhtmlRenderingServices.Render(dataReference, XhtmlRenderingType.Embedable).Root;
                                    }
                                    catch (Exception)
                                    {
                                        value = objectValues[reference.FieldName];
                                    }
                                }
                            }
                        }
                        else
                        {
                            if (objectValues.ContainsKey(reference.FieldName)) // prevents unknown props from creating exceptions
                            {
                                value = objectValues[reference.FieldName];
                            }
                        }

                        if (value != null)
                        {
                            if (value.GetType() == typeof(DateTime))
                            {
                                DateTime dateTimeValue = (DateTime)value;

                                if (dateTimeValue.TimeOfDay.TotalSeconds > 0)
                                {
                                    value = string.Format("{0} {1}", dateTimeValue.ToShortDateString(), dateTimeValue.ToShortDateString());
                                }
                                else
                                {
                                    value = dateTimeValue.ToShortDateString();
                                }
                            }

                            if (value.GetType() == typeof(string))
                            {
                                string stringValue = (string)value;

                                if (stringValue.StartsWith("<html") && stringValue.Contains(Namespaces.Xhtml.NamespaceName))
                                {
                                    try
                                    {
                                        value = XElement.Parse(stringValue);
                                    }
                                    catch { }
                                }
                                else if (stringValue.Contains('\n'))
                                {
                                    string valueEncodedWithBr = HttpUtility.HtmlEncode(stringValue).Replace("\n", "<br/>");
                                    value = XElement.Parse(string.Format("<body xmlns='{0}'>{1}</body>", Namespaces.Xhtml, valueEncodedWithBr)).Nodes();
                                }
                            }
                        }


                        reference.FieldReferenceElement.ReplaceWith(value);
                    }

                    FunctionContextContainer fcc = new FunctionContextContainer(functionContextContainer, objectValues);

                    PageRenderer.ExecuteEmbeddedFunctions(currentRowElementsContainer, fcc);

                    outputDocument.Body.Add(currentRowElementsContainer.Elements());
                }
            }

            return(outputDocument);
        }
        /// <exclude />
        public bool ValidateNewTypeFullName(string typeName, string typeNamespace, out string message)
        {
            Verify.ArgumentNotNullOrEmpty(typeName, "typeName");
            Verify.ArgumentNotNullOrEmpty(typeNamespace, "typeNamespace");

            message = null;

            if (typeNamespace.Split('.').Contains(typeName))
            {
                message = Texts.TypeNameInNamespace(typeName, typeNamespace);
                return(false);
            }

            if (_oldDataTypeDescriptor != null)
            {
                if (_oldDataTypeDescriptor.Name == typeName &&
                    _oldDataTypeDescriptor.Namespace == typeNamespace)
                {
                    return(true);
                }

                var interfaceType = _oldDataTypeDescriptor.GetInterfaceType();

                if (interfaceType.GetRefereeTypes().Count > 0)
                {
                    message = Texts.TypesAreReferencing;
                    return(false);
                }
            }

            var typeFullname = StringExtensionMethods.CreateNamespace(typeNamespace, typeName, '.');

            foreach (var dtd in DataMetaDataFacade.GeneratedTypeDataTypeDescriptors)
            {
                var fullname = StringExtensionMethods.CreateNamespace(dtd.Namespace, dtd.Name, '.');
                if (typeFullname == fullname)
                {
                    message = Texts.TypesNameClash;

                    return(false);
                }
            }

            var partNames = typeFullname.Split('.');
            var sb        = new StringBuilder(partNames[0]);

            for (var i = 1; i < partNames.Length; i++)
            {
                var exists = TypeManager.HasTypeWithName(sb.ToString());
                if (exists)
                {
                    message = Texts.NameSpaceIsTypeTypeName(sb.ToString());

                    return(false);
                }

                sb.Append(".");
                sb.Append(partNames[i]);
            }

            return(true);
        }