/// <summary>
        /// Gets a dictionary containg the pre values associated with a property matching the
        /// specified <code>contentTypeAlias</code> and <code>propertyAlias</code>.
        /// </summary>
        /// <param name="contentTypeAlias">The alias of the content type.</param>
        /// <param name="propertyAlias">The alias of the property.</param>
        public static IDictionary <string, string> GetPreValues(string contentTypeAlias, string propertyAlias)
        {
            // Get a reference to the content type
            IContentType contentType = ContentTypeService.GetContentType(contentTypeAlias);

            if (contentType == null)
            {
                return(new Dictionary <string, string>());
            }

            // Find the property matching the specified property alias
            PropertyType property = (
                contentType.PropertyTypes.FirstOrDefault(x => x.Alias == propertyAlias)
                ??
                contentType.CompositionPropertyTypes.FirstOrDefault(x => x.Alias == propertyAlias)
                );

            // Get the pre values based on the data type definition ID
            return(property == null ? new Dictionary <string, string>() : GetPreValues(property.DataTypeDefinitionId));
        }
Ejemplo n.º 2
0
        public void Process(IEnumerable <DocumentTypeMetadata> types)
        {
            var contentTypes        = new List <IContentType>();
            var dataTypeDefinitions = DataTypeService.GetAllDataTypeDefinitions().ToArray();

            foreach (var type in types)
            {
                var ct = ContentTypeService.GetContentType(type.Alias) ?? new ContentType(-1);

                ct.Name          = type.Name;
                ct.Alias         = type.Alias;
                ct.AllowedAsRoot = type.AllowAsRoot;
                ct.Description   = type.Description;
                ct.Icon          = type.Icon;
                ct.Thumbnail     = type.Thumbnail;

                var properties = ct.PropertyTypes.ToArray();

                var newProperties = type.Properties.Where(p => !properties.Any(x => x.Alias == p.Alias));

                foreach (var property in newProperties)
                {
                    var p = new PropertyType(dataTypeDefinitions.First(dtd => dtd.Name == property.DataType))
                    {
                        Name        = property.Name,
                        Alias       = property.Alias,
                        Description = property.Description
                    };

                    if (property.Tab == null)
                    {
                        ct.AddPropertyType(p);
                    }
                    else
                    {
                        ct.AddPropertyType(p, property.Tab.ToString());
                    }
                }

                var modifiedProperties = type.Properties.Join(properties, p => p.Alias, p => p.Alias, (meta, p) => new
                {
                    Metadata     = meta,
                    PropertyType = p
                });

                foreach (var property in modifiedProperties)
                {
                    var p    = property.PropertyType;
                    var meta = property.Metadata;

                    p.Name = meta.Name;
                    p.DataTypeDefinitionId = dataTypeDefinitions.First(dtd => dtd.Name == meta.DataType).Id;
                    p.Description          = meta.Description;

                    //the following hack is brought to you be the letter F
                    var fn = p.GetType().GetProperty("PropertyGroupId", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic).GetValue(p) as System.Lazy <int>;
                    if (fn != null)
                    {
                        var tabId      = fn.Value;
                        var tab        = ct.PropertyGroups.FirstOrDefault(t => t.Id == tabId);
                        var newTabName = meta.Tab.ToString();
                        var newTab     = ct.PropertyGroups.FirstOrDefault(t => t.Name == newTabName);

                        if (tab != null && tab.Name != newTabName)
                        {
                            if (newTab == null)
                            {
                                ct.AddPropertyGroup(newTabName);
                            }

                            ct.MovePropertyType(p.Alias, newTabName);
                        }
                    }
                }

                contentTypes.Add(ct);
            }

            ContentTypeService.Save(contentTypes);

            var preprocessedData = contentTypes
                                   .Join(types, x => x.Alias, x => x.Alias, (ct, m) => new { ct, m })
                                   .ToDictionary(x => x.ct, x => x.m);

            SetupAllowedChildren(preprocessedData);
            SetupTemplates(preprocessedData);

            ContentTypeService.Save(contentTypes);
        }
Ejemplo n.º 3
0
        public void DrawContent(
            Graphics g,
            SolidPenBrush color,
            int x, int y,
            TileBase content)
        {
            var contentType = _contentTypeService.GetContentType(content);
            var isDoor      = _contentTypeService.IsDoor(content);

            const int TO_WALL_MARGIN = 4;

            var topCorner = new Point(
                x,
                y + TO_WALL_MARGIN);
            var bottomCorner = new Point(
                x,
                y + (HHeight * 2) - TO_WALL_MARGIN);
            var leftCorner = new Point(
                x - HWidth + (TO_WALL_MARGIN * 2),
                y + HHeight);
            var rightCorner = new Point(
                x + HWidth - (TO_WALL_MARGIN * 2),
                y + HHeight);

            switch (contentType)
            {
            case ContentTypes.Content:
                SetGroundPath(x, y);
                g.FillPath(
                    color.Brush,
                    _content);
                break;

            case ContentTypes.Ground:
                SetGroundPath(x, y);
                g.FillPath(
                    color.LightBrush,
                    _content);
                break;

            case ContentTypes.NorthFence:
                g.DrawLine(
                    color.LightPen,
                    topCorner,
                    rightCorner);
                break;

            case ContentTypes.NorthWall:
                g.DrawLine(
                    color.Pen,
                    topCorner,
                    rightCorner);

                if (isDoor)
                {
                    g.DrawLine(
                        color.Pen,
                        topCorner,
                        Point.Add(rightCorner, new Size(-10, 4)));
                }
                break;

            case ContentTypes.WestFence:
                g.DrawLine(
                    color.LightPen,
                    topCorner,
                    leftCorner);
                break;

            case ContentTypes.WestWall:
                g.DrawLine(
                    color.Pen,
                    topCorner,
                    leftCorner);

                if (isDoor)
                {
                    g.DrawLine(
                        color.Pen,
                        Point.Add(topCorner, new Size(6, 8)),
                        leftCorner);
                }
                break;

            case ContentTypes.NorthWallWithWindow:
                DrawWindow(
                    g,
                    color,
                    topCorner,
                    rightCorner);
                break;

            case ContentTypes.WestWallWithWindow:
                DrawWindow(
                    g,
                    color,
                    topCorner,
                    leftCorner);
                break;

            case ContentTypes.SouthWall:
                g.DrawLine(
                    color.Pen,
                    leftCorner,
                    bottomCorner);
                break;

            case ContentTypes.EastWall:
                g.DrawLine(
                    color.Pen,
                    bottomCorner,
                    rightCorner);
                break;

            case ContentTypes.NW_To_SE:
                g.DrawLine(
                    color.Pen,
                    topCorner,
                    bottomCorner);
                break;

            case ContentTypes.NE_To_SW:
                g.DrawLine(
                    color.Pen,
                    leftCorner,
                    rightCorner);
                break;

            case ContentTypes.NorthWestCorner:
                g.DrawLine(
                    color.Pen,
                    Point.Add(topCorner, new Size(-4, 0)),
                    Point.Add(topCorner, new Size(4, 0)));
                break;

            case ContentTypes.NorthEastCorner:
                g.DrawLine(
                    color.Pen,
                    Point.Add(rightCorner, new Size(0, -4)),
                    Point.Add(rightCorner, new Size(0, 4)));
                break;

            case ContentTypes.SouthEastCorner:
                g.DrawLine(
                    color.Pen,
                    Point.Add(bottomCorner, new Size(-4, 0)),
                    Point.Add(bottomCorner, new Size(4, 0)));
                break;

            case ContentTypes.SouthWestCorner:
                g.DrawLine(
                    color.Pen,
                    Point.Add(leftCorner, new Size(0, -4)),
                    Point.Add(leftCorner, new Size(0, 4)));
                break;
            }
        }