private static void ReadBlocks(XmlReader objReader, ref MainModel objMain) { if (!objReader.IsEmptyElement) { //set product properties while (objReader.Read()) { //if it's the end Element if (objReader.NodeType == XmlNodeType.EndElement && objReader.Name.Equals(CONST_S_NODE_BLOCKS, StringComparison.CurrentCultureIgnoreCase)) { break; } if (objReader.Name.Equals(CONST_S_NODE_BLOCKGROUP, StringComparison.CurrentCultureIgnoreCase)) { BlockGroupModel objBGroup = new BlockGroupModel(objReader.GetAttribute(CONST_S_ATT_NAME)); objMain.LstGroup.Add(objBGroup); ReadBlockGroup(objReader, ref objMain); } else { throw new Exception("Unexpected element: '" + objReader.Name + "'"); } } } }
private void DelBlock_Click(object sender, RoutedEventArgs e) { //Check if there any selected block in lvBlocks if (lvBlocks.SelectedIndex == -1) { MessageBox.Show("Select one block first.", "Delete Block", MessageBoxButton.OK, MessageBoxImage.Exclamation); return; } BlockModel objBlock = lvBlocks.SelectedValue as BlockModel; //Ask to user MessageBoxResult result = MessageBox.Show("Are you sure to delete the block \"" + objBlock.Name + "\".", "Delete Block", MessageBoxButton.YesNo, MessageBoxImage.Exclamation); if (result == MessageBoxResult.No) { return; } //Delet BlockModel BlockGroupModel objBlockGroup = cbMain.SelectedValue as BlockGroupModel; objBlockGroup.LstBlock.Remove(objBlock); //Delet BlockDWG using (Database dbRef = new Database(false, true)) { // Read the DWG dbRef.ReadDwgFile(ArCaRefMgrController.DBPath, FileShare.ReadWrite, true, ""); using (Transaction trRef = dbRef.TransactionManager.StartTransaction()) { BlockTable bt = trRef.GetObject(dbRef.BlockTableId, OpenMode.ForRead) as BlockTable; DBObject obj = trRef.GetObject(bt[objBlock.Name], OpenMode.ForWrite); obj.Erase(); trRef.Commit(); } dbRef.SaveAs(ArCaRefMgrController.DBPath, DwgVersion.Current); } //Write XML ArCaRefMgrParser.WriteXML(); //MessageBox.Show("Block \"" + objBlock.Name + "\" was successfully deleted.", "Block Deleted", MessageBoxButton.OK, MessageBoxImage.Information); }
/// <summary> /// Creates a new block of the specified type. /// </summary> /// <param name="type">The block type</param> /// <returns>The new block</returns> public async Task <AsyncResult <BlockModel> > CreateBlockAsync(string type) { var blockType = App.Blocks.GetByType(type); if (blockType != null) { var block = (Extend.Block)(await _factory.CreateBlockAsync(type)); if (block is Extend.BlockGroup) { var item = new BlockGroupModel { Type = block.Type, Meta = new BlockMeta { Name = blockType.Name, Title = block.GetTitle(), Icon = blockType.Icon, Component = "block-group", IsGroup = true } }; if (blockType.Display != BlockDisplayMode.MasterDetail) { item.Meta.Component = blockType.Display == BlockDisplayMode.Horizontal ? "block-group-horizontal" : "block-group-vertical"; } item.Fields = ContentUtils.GetBlockFields(block); return(new AsyncResult <BlockModel> { Body = item }); } else { if (!blockType.IsGeneric) { // Regular block model return(new AsyncResult <BlockModel> { Body = new BlockItemModel { Model = block, Meta = new BlockMeta { Name = blockType.Name, Title = block.GetTitle(), Icon = blockType.Icon, Component = blockType.Component } } }); } else { // Generic block model return(new AsyncResult <BlockModel> { Body = new BlockGenericModel { Model = ContentUtils.GetBlockFields(block), Type = block.Type, Meta = new BlockMeta { Name = blockType.Name, Title = block.GetTitle(), Icon = blockType.Icon, Component = blockType.Component } } }); } } } return(null); }
private PostEditModel Transform(DynamicPost post, bool isDraft) { var config = new Config(_api); var type = App.PostTypes.GetById(post.TypeId); var route = type.Routes.FirstOrDefault(r => r.Route == post.Route) ?? type.Routes.FirstOrDefault(); var model = new PostEditModel { Id = post.Id, BlogId = post.BlogId, TypeId = post.TypeId, PrimaryImage = post.PrimaryImage, Title = post.Title, Slug = post.Slug, MetaTitle = post.MetaTitle, MetaKeywords = post.MetaKeywords, MetaDescription = post.MetaDescription, OgTitle = post.OgTitle, OgDescription = post.OgDescription, OgImage = post.OgImage, Excerpt = post.Excerpt, Published = post.Published?.ToString("yyyy-MM-dd HH:mm"), RedirectUrl = post.RedirectUrl, RedirectType = post.RedirectType.ToString(), EnableComments = post.EnableComments, CloseCommentsAfterDays = post.CloseCommentsAfterDays, CommentCount = post.CommentCount, State = post.GetState(isDraft), UseBlocks = type.UseBlocks, UsePrimaryImage = type.UsePrimaryImage, UseExcerpt = type.UseExcerpt, UseHtmlExcerpt = config.HtmlExcerpt, SelectedRoute = route == null ? null : new RouteModel { Title = route.Title, Route = route.Route }, Permissions = App.Permissions .GetPublicPermissions() .Select(p => new KeyValuePair <string, string>(p.Name, p.Title)) .ToList(), SelectedPermissions = post.Permissions }; foreach (var r in type.Routes) { model.Routes.Add(new RouteModel { Title = r.Title, Route = r.Route }); } foreach (var regionType in type.Regions) { var region = new RegionModel { Meta = new RegionMeta { Id = regionType.Id, Name = regionType.Title, Description = regionType.Description, Placeholder = regionType.ListTitlePlaceholder, IsCollection = regionType.Collection, Expanded = regionType.ListExpand, Icon = regionType.Icon, Display = regionType.Display.ToString().ToLower() } }; var regionListModel = ((IDictionary <string, object>)post.Regions)[regionType.Id]; if (!regionType.Collection) { var regionModel = (IRegionList)Activator.CreateInstance(typeof(RegionList <>).MakeGenericType(regionListModel.GetType())); regionModel.Add(regionListModel); regionListModel = regionModel; } foreach (var regionModel in (IEnumerable)regionListModel) { var regionItem = new RegionItemModel(); foreach (var fieldType in regionType.Fields) { var appFieldType = App.Fields.GetByType(fieldType.Type); var field = new FieldModel { Meta = new FieldMeta { Id = fieldType.Id, Name = fieldType.Title, Component = appFieldType.Component, Placeholder = fieldType.Placeholder, IsHalfWidth = fieldType.Options.HasFlag(FieldOption.HalfWidth), Description = fieldType.Description } }; if (typeof(SelectFieldBase).IsAssignableFrom(appFieldType.Type)) { foreach (var item in ((SelectFieldBase)Activator.CreateInstance(appFieldType.Type)).Items) { field.Meta.Options.Add(Convert.ToInt32(item.Value), item.Title); } } if (regionType.Fields.Count > 1) { field.Model = (IField)((IDictionary <string, object>)regionModel)[fieldType.Id]; if (regionType.ListTitleField == fieldType.Id) { regionItem.Title = field.Model.GetTitle(); field.Meta.NotifyChange = true; } } else { field.Model = (IField)regionModel; field.Meta.NotifyChange = true; regionItem.Title = field.Model.GetTitle(); } regionItem.Fields.Add(field); } if (string.IsNullOrWhiteSpace(regionItem.Title)) { regionItem.Title = "..."; } region.Items.Add(regionItem); } model.Regions.Add(region); } foreach (var block in post.Blocks) { var blockType = App.Blocks.GetByType(block.Type); if (block is BlockGroup blockGroup) { var group = new BlockGroupModel { Id = block.Id, Type = block.Type, Meta = new BlockMeta { Name = blockType.Name, Icon = blockType.Icon, Component = "block-group", IsGroup = true, isCollapsed = config.ManagerDefaultCollapsedBlocks, ShowHeader = !config.ManagerDefaultCollapsedBlockGroupHeaders } }; if (blockType.Display != BlockDisplayMode.MasterDetail) { group.Meta.Component = blockType.Display == BlockDisplayMode.Horizontal ? "block-group-horizontal" : "block-group-vertical"; } group.Fields = ContentUtils.GetBlockFields(block); bool firstChild = true; foreach (var child in blockGroup.Items) { blockType = App.Blocks.GetByType(child.Type); if (!blockType.IsGeneric) { group.Items.Add(new BlockItemModel { IsActive = firstChild, Model = child, Meta = new BlockMeta { Name = blockType.Name, Title = child.GetTitle(), Icon = blockType.Icon, Component = blockType.Component } }); } else { // Generic block item model group.Items.Add(new BlockGenericModel { IsActive = firstChild, Model = ContentUtils.GetBlockFields(child), Type = child.Type, Meta = new BlockMeta { Name = blockType.Name, Title = child.GetTitle(), Icon = blockType.Icon, Component = blockType.Component, } }); } firstChild = false; } model.Blocks.Add(group); } else { if (!blockType.IsGeneric) { // Regular block item model model.Blocks.Add(new BlockItemModel { Model = block, Meta = new BlockMeta { Name = blockType.Name, Title = block.GetTitle(), Icon = blockType.Icon, Component = blockType.Component, isCollapsed = config.ManagerDefaultCollapsedBlocks } }); } else { // Generic block item model model.Blocks.Add(new BlockGenericModel { Model = ContentUtils.GetBlockFields(block), Type = block.Type, Meta = new BlockMeta { Name = blockType.Name, Title = block.GetTitle(), Icon = blockType.Icon, Component = blockType.Component, isCollapsed = config.ManagerDefaultCollapsedBlocks } }); } } } // Custom editors foreach (var editor in type.CustomEditors) { model.Editors.Add(new EditorModel { Component = editor.Component, Icon = editor.Icon, Name = editor.Title }); } return(model); }
private PostEditModel Transform(DynamicPost post, bool isDraft) { var type = App.PostTypes.GetById(post.TypeId); var model = new PostEditModel { Id = post.Id, BlogId = post.BlogId, TypeId = post.TypeId, Title = post.Title, Slug = post.Slug, MetaKeywords = post.MetaKeywords, MetaDescription = post.MetaDescription, Published = post.Published.HasValue ? post.Published.Value.ToString("yyyy-MM-dd HH:mm") : null, RedirectUrl = post.RedirectUrl, RedirectType = post.RedirectType.ToString(), State = GetState(post, isDraft), UseBlocks = type.UseBlocks }; foreach (var regionType in type.Regions) { var region = new RegionModel { Meta = new RegionMeta { Id = regionType.Id, Name = regionType.Title, Description = regionType.Description, Placeholder = regionType.ListTitlePlaceholder, IsCollection = regionType.Collection, Icon = regionType.Icon, Display = regionType.Display.ToString().ToLower() } }; var regionListModel = ((IDictionary <string, object>)post.Regions)[regionType.Id]; if (!regionType.Collection) { var regionModel = (IRegionList)Activator.CreateInstance(typeof(RegionList <>).MakeGenericType(regionListModel.GetType())); regionModel.Add(regionListModel); regionListModel = regionModel; } foreach (var regionModel in (IEnumerable)regionListModel) { var regionItem = new RegionItemModel(); foreach (var fieldType in regionType.Fields) { var appFieldType = App.Fields.GetByType(fieldType.Type); var field = new FieldModel { Meta = new FieldMeta { Id = fieldType.Id, Name = fieldType.Title, Component = appFieldType.Component, Placeholder = fieldType.Placeholder, IsHalfWidth = fieldType.Options.HasFlag(FieldOption.HalfWidth), Description = fieldType.Description } }; if (typeof(Extend.Fields.SelectFieldBase).IsAssignableFrom(appFieldType.Type)) { foreach (var item in ((Extend.Fields.SelectFieldBase)Activator.CreateInstance(appFieldType.Type)).Items) { field.Meta.Options.Add(Convert.ToInt32(item.Value), item.Title); } } if (regionType.Fields.Count > 1) { field.Model = (Extend.IField)((IDictionary <string, object>)regionModel)[fieldType.Id]; if (regionType.ListTitleField == fieldType.Id) { regionItem.Title = field.Model.GetTitle(); field.Meta.NotifyChange = true; } } else { field.Model = (Extend.IField)regionModel; field.Meta.NotifyChange = true; regionItem.Title = field.Model.GetTitle(); } regionItem.Fields.Add(field); } if (string.IsNullOrWhiteSpace(regionItem.Title)) { regionItem.Title = "..."; } region.Items.Add(regionItem); } model.Regions.Add(region); } foreach (var block in post.Blocks) { var blockType = App.Blocks.GetByType(block.Type); if (block is Extend.BlockGroup) { var group = new BlockGroupModel { Id = block.Id, Type = block.Type, Meta = new BlockMeta { Name = blockType.Name, Icon = blockType.Icon, Component = "block-group", IsGroup = true } }; if (blockType.Display != BlockDisplayMode.MasterDetail) { group.Meta.Component = blockType.Display == BlockDisplayMode.Horizontal ? "block-group-horizontal" : "block-group-vertical"; } foreach (var prop in block.GetType().GetProperties(App.PropertyBindings)) { if (typeof(Extend.IField).IsAssignableFrom(prop.PropertyType)) { var fieldType = App.Fields.GetByType(prop.PropertyType); group.Fields.Add(new FieldModel { Model = (Extend.IField)prop.GetValue(block), Meta = new FieldMeta { Id = prop.Name, Name = prop.Name, Component = fieldType.Component, } }); } } bool firstChild = true; foreach (var child in ((Extend.BlockGroup)block).Items) { blockType = App.Blocks.GetByType(child.Type); group.Items.Add(new BlockItemModel { IsActive = firstChild, Model = child, Meta = new BlockMeta { Name = blockType.Name, Title = child.GetTitle(), Icon = blockType.Icon, Component = blockType.Component } }); firstChild = false; } model.Blocks.Add(group); } else { model.Blocks.Add(new BlockItemModel { Model = block, Meta = new BlockMeta { Name = blockType.Name, Title = block.GetTitle(), Icon = blockType.Icon, Component = blockType.Component } }); } } // Custom editors foreach (var editor in type.CustomEditors) { model.Editors.Add(new EditorModel { Component = editor.Component, Icon = editor.Icon, Name = editor.Title }); } return(model); }
/// <summary> /// Creates a new block of the specified type. /// </summary> /// <param name="type">The block type</param> /// <returns>The new block</returns> public AsyncResult <BlockModel> CreateBlock(string type) { var blockType = App.Blocks.GetByType(type); if (blockType != null) { var block = (Extend.Block)_factory.CreateBlock(type); if (block is Extend.BlockGroup) { var item = new BlockGroupModel { Type = block.Type, Meta = new BlockMeta { Name = blockType.Name, Title = block.GetTitle(), Icon = blockType.Icon, Component = "block-group", IsGroup = true } }; if (blockType.Display != BlockDisplayMode.MasterDetail) { item.Meta.Component = blockType.Display == BlockDisplayMode.Horizontal ? "block-group-horizontal" : "block-group-vertical"; } foreach (var prop in block.GetType().GetProperties(App.PropertyBindings)) { if (typeof(Extend.IField).IsAssignableFrom(prop.PropertyType)) { var fieldType = App.Fields.GetByType(prop.PropertyType); // Create the block field var field = new FieldModel { Model = (Extend.IField)prop.GetValue(block), Meta = new FieldMeta { Id = prop.Name, Name = prop.Name, Component = fieldType.Component, } }; PopulateFieldOptions(fieldType, field); // Check if we have field meta-data available var attr = prop.GetCustomAttribute <Extend.FieldAttribute>(); if (attr != null) { field.Meta.Name = !string.IsNullOrWhiteSpace(attr.Title) ? attr.Title : field.Meta.Name; field.Meta.Placeholder = attr.Placeholder; field.Meta.IsHalfWidth = attr.Options.HasFlag(FieldOption.HalfWidth); } // Check if we have field description meta-data available var descAttr = prop.GetCustomAttribute <Extend.FieldDescriptionAttribute>(); if (descAttr != null) { field.Meta.Description = descAttr.Text; } item.Fields.Add(field); } } return(new AsyncResult <BlockModel> { Body = item }); } else { return(new AsyncResult <BlockModel> { Body = new BlockItemModel { Model = block, Meta = new BlockMeta { Name = blockType.Name, Title = block.GetTitle(), Icon = blockType.Icon, Component = blockType.Component } } }); } } return(null); }
private PageEditModel Transform(DynamicPage page, bool isDraft) { var config = new Config(_api); var type = App.PageTypes.GetById(page.TypeId); var route = type.Routes.FirstOrDefault(r => r.Route == page.Route) ?? type.Routes.FirstOrDefault(); var model = new PageEditModel { Id = page.Id, SiteId = page.SiteId, ParentId = page.ParentId, OriginalId = page.OriginalPageId, SortOrder = page.SortOrder, TypeId = page.TypeId, Title = page.Title, NavigationTitle = page.NavigationTitle, Slug = page.Slug, MetaKeywords = page.MetaKeywords, MetaDescription = page.MetaDescription, IsHidden = page.IsHidden, Published = page.Published.HasValue ? page.Published.Value.ToString("yyyy-MM-dd HH:mm") : null, RedirectUrl = page.RedirectUrl, RedirectType = page.RedirectType.ToString(), State = GetState(page, isDraft), UseBlocks = type.UseBlocks, SelectedRoute = route == null ? null : new RouteModel { Title = route.Title, Route = route.Route } }; foreach (var r in type.Routes) { model.Routes.Add(new RouteModel { Title = r.Title, Route = r.Route }); } foreach (var regionType in type.Regions) { var region = new RegionModel { Meta = new RegionMeta { Id = regionType.Id, Name = regionType.Title, Description = regionType.Description, Placeholder = regionType.ListTitlePlaceholder, IsCollection = regionType.Collection, Icon = regionType.Icon, Display = regionType.Display.ToString().ToLower() } }; var regionListModel = ((IDictionary <string, object>)page.Regions)[regionType.Id]; if (!regionType.Collection) { var regionModel = (IRegionList)Activator.CreateInstance(typeof(RegionList <>).MakeGenericType(regionListModel.GetType())); regionModel.Add(regionListModel); regionListModel = regionModel; } foreach (var regionModel in (IEnumerable)regionListModel) { var regionItem = new RegionItemModel(); foreach (var fieldType in regionType.Fields) { var appFieldType = App.Fields.GetByType(fieldType.Type); var field = new FieldModel { Meta = new FieldMeta { Id = fieldType.Id, Name = fieldType.Title, Component = appFieldType.Component, Placeholder = fieldType.Placeholder, IsHalfWidth = fieldType.Options.HasFlag(FieldOption.HalfWidth), Description = fieldType.Description } }; if (typeof(Extend.Fields.SelectFieldBase).IsAssignableFrom(appFieldType.Type)) { foreach (var item in ((Extend.Fields.SelectFieldBase)Activator.CreateInstance(appFieldType.Type)).Items) { field.Meta.Options.Add(Convert.ToInt32(item.Value), item.Title); } } if (regionType.Fields.Count > 1) { field.Model = (Extend.IField)((IDictionary <string, object>)regionModel)[fieldType.Id]; if (regionType.ListTitleField == fieldType.Id) { regionItem.Title = field.Model.GetTitle(); field.Meta.NotifyChange = true; } } else { field.Model = (Extend.IField)regionModel; field.Meta.NotifyChange = true; regionItem.Title = field.Model.GetTitle(); } regionItem.Fields.Add(field); } if (string.IsNullOrWhiteSpace(regionItem.Title)) { regionItem.Title = "..."; } region.Items.Add(regionItem); } model.Regions.Add(region); } foreach (var block in page.Blocks) { var blockType = App.Blocks.GetByType(block.Type); if (block is Extend.BlockGroup) { var group = new BlockGroupModel { Id = block.Id, Type = block.Type, Meta = new BlockMeta { Name = blockType.Name, Icon = blockType.Icon, Component = "block-group", IsGroup = true, IsReadonly = page.OriginalPageId.HasValue, isCollapsed = config.ManagerDefaultCollapsedBlocks, ShowHeader = !config.ManagerDefaultCollapsedBlockGroupHeaders } }; if (blockType.Display != BlockDisplayMode.MasterDetail) { group.Meta.Component = blockType.Display == BlockDisplayMode.Horizontal ? "block-group-horizontal" : "block-group-vertical"; } foreach (var prop in block.GetType().GetProperties(App.PropertyBindings)) { if (typeof(Extend.IField).IsAssignableFrom(prop.PropertyType)) { var fieldType = App.Fields.GetByType(prop.PropertyType); var field = new FieldModel { Model = (Extend.IField)prop.GetValue(block), Meta = new FieldMeta { Id = prop.Name, Name = prop.Name, Component = fieldType.Component, } }; // Check if this is a select field if (typeof(Extend.Fields.SelectFieldBase).IsAssignableFrom(fieldType.Type)) { foreach (var item in ((Extend.Fields.SelectFieldBase)Activator.CreateInstance(fieldType.Type)).Items) { field.Meta.Options.Add(Convert.ToInt32(item.Value), item.Title); } } // Check if we have field meta-data available var attr = prop.GetCustomAttribute <Extend.FieldAttribute>(); if (attr != null) { field.Meta.Name = !string.IsNullOrWhiteSpace(attr.Title) ? attr.Title : field.Meta.Name; field.Meta.Placeholder = attr.Placeholder; field.Meta.IsHalfWidth = attr.Options.HasFlag(FieldOption.HalfWidth); } // Check if we have field description meta-data available var descAttr = prop.GetCustomAttribute <Extend.FieldDescriptionAttribute>(); if (descAttr != null) { field.Meta.Description = descAttr.Text; } group.Fields.Add(field); } } bool firstChild = true; foreach (var child in ((Extend.BlockGroup)block).Items) { blockType = App.Blocks.GetByType(child.Type); group.Items.Add(new BlockItemModel { IsActive = firstChild, Model = child, Meta = new BlockMeta { Name = blockType.Name, Title = child.GetTitle(), Icon = blockType.Icon, Component = blockType.Component } }); firstChild = false; } model.Blocks.Add(group); } else { model.Blocks.Add(new BlockItemModel { Model = block, Meta = new BlockMeta { Name = blockType.Name, Title = block.GetTitle(), Icon = blockType.Icon, Component = blockType.Component, IsReadonly = page.OriginalPageId.HasValue, isCollapsed = config.ManagerDefaultCollapsedBlocks } }); } } // Custom editors foreach (var editor in type.CustomEditors) { model.Editors.Add(new EditorModel { Component = editor.Component, Icon = editor.Icon, Name = editor.Title }); } return(model); }
/// <summary> /// Creates a new block of the specified type. /// </summary> /// <param name="type">The block type</param> /// <returns>The new block</returns> public AsyncResult <BlockModel> CreateBlock(string type) { var blockType = App.Blocks.GetByType(type); if (blockType != null) { var block = (Extend.Block)_factory.CreateBlock(type); if (block is Extend.BlockGroup) { var item = new BlockGroupModel { Type = block.Type, Meta = new BlockMeta { Name = blockType.Name, Title = block.GetTitle(), Icon = blockType.Icon, Component = "block-group", IsGroup = true } }; if (blockType.Display != BlockDisplayMode.MasterDetail) { item.Meta.Component = blockType.Display == BlockDisplayMode.Horizontal ? "block-group-horizontal" : "block-group-vertical"; } foreach (var prop in block.GetType().GetProperties(App.PropertyBindings)) { if (typeof(Extend.IField).IsAssignableFrom(prop.PropertyType)) { var fieldType = App.Fields.GetByType(prop.PropertyType); item.Fields.Add(new FieldModel { Model = (Extend.IField)prop.GetValue(block), Meta = new FieldMeta { Name = prop.Name, Component = fieldType.Component, } }); } } return(new AsyncResult <BlockModel> { Body = item }); } else { return(new AsyncResult <BlockModel> { Body = new BlockItemModel { Model = block, Meta = new BlockMeta { Name = blockType.Name, Title = block.GetTitle(), Icon = blockType.Icon, Component = blockType.Component } } }); } } return(null); }
public async Task <PageEditModel> GetById(Guid id) { var page = await _api.Pages.GetByIdAsync(id); if (page != null) { var type = App.PageTypes.GetById(page.TypeId); var model = new PageEditModel { Id = page.Id, SiteId = page.SiteId, ParentId = page.ParentId, SortOrder = page.SortOrder, TypeId = page.TypeId, Title = page.Title, NavigationTitle = page.NavigationTitle, Slug = page.Slug, MetaKeywords = page.MetaKeywords, MetaDescription = page.MetaDescription, Published = page.Published.HasValue ? page.Published.Value.ToString("yyyy-MM-dd HH:mm") : null }; foreach (var regionType in type.Regions) { var region = new RegionModel { Meta = new RegionMeta { Id = regionType.Id, Name = regionType.Title, Description = regionType.Description, Placeholder = regionType.ListTitlePlaceholder, IsCollection = regionType.Collection, Icon = regionType.Icon, Display = regionType.Display.ToString().ToLower() } }; var regionListModel = ((IDictionary <string, object>)page.Regions)[regionType.Id]; if (!regionType.Collection) { var regionModel = (IRegionList)Activator.CreateInstance(typeof(RegionList <>).MakeGenericType(regionListModel.GetType())); regionModel.Add(regionListModel); regionListModel = regionModel; } foreach (var regionModel in (IEnumerable)regionListModel) { var regionItem = new RegionItemModel(); foreach (var fieldType in regionType.Fields) { var appFieldType = App.Fields.GetByType(fieldType.Type); var field = new FieldModel { Meta = new FieldMeta { Id = fieldType.Id, Name = fieldType.Title, Component = appFieldType.Component, Placeholder = fieldType.Placeholder, IsHalfWidth = fieldType.Options.HasFlag(FieldOption.HalfWidth) } }; if (regionType.Fields.Count > 1) { field.Model = (Extend.IField)((IDictionary <string, object>)regionModel)[fieldType.Id]; if (regionType.ListTitleField == fieldType.Id) { regionItem.Title = field.Model.GetTitle(); field.Meta.NotifyChange = true; } } else { field.Model = (Extend.IField)regionModel; field.Meta.NotifyChange = true; regionItem.Title = field.Model.GetTitle(); } regionItem.Fields.Add(field); } if (string.IsNullOrWhiteSpace(regionItem.Title)) { regionItem.Title = "..."; } region.Items.Add(regionItem); } model.Regions.Add(region); } foreach (var block in page.Blocks) { var blockType = App.Blocks.GetByType(block.Type); if (block is Extend.BlockGroup) { var group = new BlockGroupModel { Id = block.Id, Type = block.Type, Meta = new BlockMeta { Name = blockType.Name, Icon = blockType.Icon, Component = "block-group", IsGroup = true } }; if (blockType.Display != BlockDisplayMode.MasterDetail) { group.Meta.Component = blockType.Display == BlockDisplayMode.Horizontal ? "block-group-horizontal" : "block-group-vertical"; } foreach (var prop in block.GetType().GetProperties(App.PropertyBindings)) { if (typeof(Extend.IField).IsAssignableFrom(prop.PropertyType)) { var fieldType = App.Fields.GetByType(prop.PropertyType); group.Fields.Add(new FieldModel { Model = (Extend.IField)prop.GetValue(block), Meta = new FieldMeta { Id = prop.Name, Name = prop.Name, Component = fieldType.Component, } }); } } bool firstChild = true; foreach (var child in ((Extend.BlockGroup)block).Items) { blockType = App.Blocks.GetByType(child.Type); group.Items.Add(new BlockItemModel { IsActive = firstChild, Model = child, Meta = new BlockMeta { Name = blockType.Name, Title = child.GetTitle(), Icon = blockType.Icon, Component = blockType.Component } }); firstChild = false; } model.Blocks.Add(group); } else { model.Blocks.Add(new BlockItemModel { Model = block, Meta = new BlockMeta { Name = blockType.Name, Title = block.GetTitle(), Icon = blockType.Icon, Component = blockType.Component } }); } } return(model); } return(null); }
/// <summary> /// Creates a new block of the specified type. /// </summary> /// <param name="type">The block type</param> /// <returns>The new block</returns> public async Task <AsyncResult <BlockModel> > CreateBlockAsync(string type) { var blockType = App.Blocks.GetByType(type); if (blockType != null) { var block = (Block)(await _factory.CreateBlockAsync(type, true)); if (block is BlockGroup) { var item = new BlockGroupModel { Type = block.Type, Meta = new BlockMeta { Name = blockType.Name, Title = block.GetTitle(), Icon = blockType.Icon, Component = blockType.Component, Width = blockType.Width.ToString().ToLower(), IsGroup = true } }; item.Fields = ContentUtils.GetBlockFields(block); return(new AsyncResult <BlockModel> { Body = item }); } else { if (!blockType.IsGeneric) { // Regular block model return(new AsyncResult <BlockModel> { Body = new BlockItemModel { Model = block, Meta = new BlockMeta { Name = blockType.Name, Title = block.GetTitle(), Icon = blockType.Icon, Component = blockType.Component, Width = blockType.Width.ToString().ToLower() } } }); } else { var blockModel = new BlockGenericModel { Model = ContentUtils.GetBlockFields(block), Type = block.Type, Meta = new BlockMeta { Name = blockType.Name, Title = block.GetTitle(), Icon = blockType.Icon, Component = blockType.Component, Width = blockType.Width.ToString().ToLower() } }; if (blockModel.Model.Count == 1) { blockModel.Model[0].Meta.NotifyChange = true; } else { foreach (var blockField in blockModel.Model) { blockField.Meta.NotifyChange = blockField.Meta.Id == blockType.ListTitleField; } } // Generic block model return(new AsyncResult <BlockModel> { Body = blockModel }); } } } return(null); }
private void btOk_Click(object sender, RoutedEventArgs e) { if (tbName.Text == "") { MessageBox.Show("The field \"Name\" must be filled.", "Field is not filled", MessageBoxButton.OK, MessageBoxImage.Exclamation); return; } if (cbCategory.SelectedIndex == -1) { MessageBox.Show("You must select one category.", "Category not selected", MessageBoxButton.OK, MessageBoxImage.Exclamation); return; } if (objIdColl.Count == 0) { MessageBox.Show("Select at least one object.", "Objects not selected", MessageBoxButton.OK, MessageBoxImage.Exclamation); return; } //Check ambiguous block name if (_objBlockModOld.Name != _objBlockModNew.Name) { using (Database dbRef = new Database(false, true)) { //Read dbRef dbRef.ReadDwgFile(ArCaRefMgrController.DBPath, FileShare.ReadWrite, true, ""); using (Transaction trRef = dbRef.TransactionManager.StartTransaction()) { BlockTable btRef = trRef.GetObject(dbRef.BlockTableId, OpenMode.ForRead) as BlockTable; BlockTableRecord btr; foreach (ObjectId objId in btRef) { btr = trRef.GetObject(objId, OpenMode.ForRead) as BlockTableRecord; if (btr.Name == _objBlockModNew.Name) { MessageBox.Show("The block called \"" + _objBlockModNew.Name + "\" already exists in the library block. Choose another name.", "Invalid Name", MessageBoxButton.OK, MessageBoxImage.Exclamation); trRef.Abort(); return; } } trRef.Abort(); } } } Database dbLocal = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Database; Point3d basePoint = new Point3d(Convert.ToDouble(tbX.Text), Convert.ToDouble(tbY.Text), Convert.ToDouble(tbZ.Text)); using (dbLocal) { //-----------------Add Mode-------------- if (_IsAddMode) { //-----------Selection Block Mode------------ if (_SelectionIsABlock) { //Start Transaction to change BlockTableRecord using (Transaction trLocal = dbLocal.TransactionManager.StartTransaction()) { Document Doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument; using (DocumentLock dl = Doc.LockDocument()) { BlockTable bt = trLocal.GetObject(dbLocal.BlockTableId, OpenMode.ForRead) as BlockTable; BlockTableRecord BlocRec = trLocal.GetObject(bt[_objBlockModNew.Name], OpenMode.ForWrite) as BlockTableRecord; //Change PreviewIcon BlocRec.PreviewIcon = bmpPreview; } trLocal.Commit(); } using (Database dbRef = new Database(false, true)) { //Read dbRef dbRef.ReadDwgFile(ArCaRefMgrController.DBPath, FileShare.ReadWrite, true, ""); // Copy blocks from source to destination database IdMapping mapping = new IdMapping(); dbLocal.WblockCloneObjects(objIdColl, dbRef.BlockTableId, mapping, DuplicateRecordCloning.Replace, false); //Save dbRef dbRef.SaveAs(ArCaRefMgrController.DBPath, DwgVersion.Current); } } //------------------Selection Objects Mode------------------ else { using (Database dbAux = new Database()) { //Create dbAux (block) dbLocal.Wblock(dbAux, objIdColl, basePoint, DuplicateRecordCloning.Ignore); using (Database dbRef = new Database(false, true)) { //Read dbRef dbRef.ReadDwgFile(ArCaRefMgrController.DBPath, FileShare.ReadWrite, true, ""); //Insert dbAuc (Block) in dbRef ObjectId obj = dbRef.Insert(_objBlockModNew.Name, dbAux, true); //Start Transaction to change BlockTableRecord using (Transaction trRef = dbRef.TransactionManager.StartTransaction()) { BlockTableRecord BlocRec = trRef.GetObject(obj, OpenMode.ForWrite) as BlockTableRecord; //Change PreviewIcon BlocRec.PreviewIcon = bmpPreview; } //Save dbRef dbRef.SaveAs(ArCaRefMgrController.DBPath, DwgVersion.Current); } } } } //----------------Edit Mode---------------- else { //-------------Selection was not changed------------- if (_bDbIsInExternalDWG) { using (Database dbRef = new Database(false, true)) { //Read dbRef dbRef.ReadDwgFile(ArCaRefMgrController.DBPath, FileShare.ReadWrite, true, ""); //Start Transaction to change BlockTableRecord using (Transaction trRef = dbRef.TransactionManager.StartTransaction()) { BlockTable btRef = trRef.GetObject(dbRef.BlockTableId, OpenMode.ForRead) as BlockTable; BlockTableRecord BlocRec = trRef.GetObject(btRef[_objBlockModOld.Name], OpenMode.ForWrite) as BlockTableRecord; //Change Origin BlocRec.Origin = basePoint; //Chage Name BlocRec.Name = _objBlockModNew.Name; trRef.Commit(); } //Save dbRef dbRef.SaveAs(ArCaRefMgrController.DBPath, DwgVersion.Current); } } //----------------Selection was changed------------------ else { using (Database dbAux = new Database()) { //Create dbAux (block) dbLocal.Wblock(dbAux, objIdColl, basePoint, DuplicateRecordCloning.Ignore); using (Database dbRef = new Database(false, true)) { //Read dbRef dbRef.ReadDwgFile(ArCaRefMgrController.DBPath, FileShare.ReadWrite, true, ""); //*************Delete Old Block************ //Start Transaction to delet BlockTableRecord using (Transaction trRef = dbRef.TransactionManager.StartTransaction()) { BlockTable btRef = trRef.GetObject(dbRef.BlockTableId, OpenMode.ForRead) as BlockTable; BlockTableRecord BlocRec = trRef.GetObject(btRef[_objBlockModOld.Name], OpenMode.ForWrite) as BlockTableRecord; //Delet BlockTableRecord BlocRec.Erase(); trRef.Commit(); } //************Insert New Block************** //-----------Selection Block Mode------------ if (_SelectionIsABlock) { //Start Transaction to change BlockTableRecord using (Transaction trLocal = dbLocal.TransactionManager.StartTransaction()) { Document Doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument; using (DocumentLock dl = Doc.LockDocument()) { BlockTable btRef = trLocal.GetObject(dbLocal.BlockTableId, OpenMode.ForRead) as BlockTable; BlockTableRecord BlocRec = trLocal.GetObject(btRef[_objBlockModNew.Name], OpenMode.ForWrite) as BlockTableRecord; //Change PreviewIcon BlocRec.PreviewIcon = bmpPreview; } trLocal.Commit(); } // Copy blocks from source to destination database IdMapping mapping = new IdMapping(); dbLocal.WblockCloneObjects(objIdColl, dbRef.BlockTableId, mapping, DuplicateRecordCloning.Replace, false); //Save dbRef dbRef.SaveAs(ArCaRefMgrController.DBPath, DwgVersion.Current); } //--------------Selection Objects Mode-------------- else { //Insert dbAuc (Block) in dbRef ObjectId obj = dbRef.Insert(_objBlockModNew.Name, dbAux, true); //Start Transaction to change BlockTableRecord using (Transaction trRef = dbRef.TransactionManager.StartTransaction()) { BlockTableRecord BlocRec = trRef.GetObject(obj, OpenMode.ForWrite) as BlockTableRecord; //Change PreviewIcon BlocRec.PreviewIcon = bmpPreview; //Change Origin BlocRec.Origin = basePoint; //Chage Name BlocRec.Name = _objBlockModNew.Name; trRef.Commit(); } } //*********************************************** //Save dbRef dbRef.SaveAs(ArCaRefMgrController.DBPath, DwgVersion.Current); } } } } } var lstFound = ArCaRefMgrController.ObjMain.LstGroup.Where(objTag => objTag.Name.Equals((cbCategory.SelectedValue as BlockGroupModel).Name)); BlockGroupModel objBlockGroup = lstFound.First(); //Remove in all Lists bool IsInserted = false; foreach (BlockGroupModel objIt in ArCaRefMgrController.ObjMain.LstGroup) { if (objIt.LstBlock.Contains(_objBlockModOld)) { int position = objIt.LstBlock.IndexOf(_objBlockModOld); objIt.LstBlock.Remove(_objBlockModOld); if (objBlockGroup == objIt) { //Insert if is in the same group objBlockGroup.LstBlock.Insert(position, _objBlockModNew); IsInserted = true; } } } //If not inset, add in correct group if (!IsInserted) { objBlockGroup.LstBlock.Add(_objBlockModNew); } //Write XML ArCaRefMgrParser.WriteXML(); this.Close(); }