private BlockJsonResponse LoadFromMetablock(TapestryDesignerMetablock parent, int level, string selectedBlockName) { BlockJsonResponse item = new BlockJsonResponse() { Name = parent.Name, Value = "", Selected = false, IsMetablock = true, Level = level, ChildBlocks = new List <BlockJsonResponse>() }; foreach (TapestryDesignerBlock block in parent.Blocks.OrderBy(b => b.Name)) { item.ChildBlocks.Add(new BlockJsonResponse() { Name = block.Name, Value = block.Name, Selected = block.Name == selectedBlockName, IsMetablock = false, Level = level + 1, ChildBlocks = null }); } foreach (TapestryDesignerMetablock mBlock in parent.Metablocks.OrderBy(m => m.Name)) { item.ChildBlocks.Add(LoadFromMetablock(mBlock, level + 1, selectedBlockName)); } return(item); }
public void AddNewApp(AjaxAppProperties postData) { try { DBEntities context = COREobject.i.Context; var newApp = new Application { Name = postData.DisplayName.RemoveDiacritics(), DisplayName = postData.DisplayName, TileWidth = postData.TileWidth, TileHeight = postData.TileHeight, Color = postData.Color, Icon = postData.Icon }; context.Applications.Add(newApp); context.SaveChanges(); var newRootMetablock = new TapestryDesignerMetablock { Name = "Root metablock", ParentApp = newApp }; context.TapestryDesignerMetablocks.Add(newRootMetablock); context.SaveChanges(); } catch (Exception ex) { string errorMessage = $"App manager: error creating new application (POST api/master/apps). Exception message: {ex.Message}"; throw GetHttpInternalServerErrorResponseException(errorMessage); } }
private void GetBlockTree(TapestryDesignerMetablock metablock, ref JArray blockTree, int level) { JObject item = new JObject(); item["Id"] = ""; item["Name"] = metablock.Name; item["IsMetablock"] = true; item["Level"] = level; item["Items"] = JArray.Parse("[]"); blockTree.Add(item); foreach (TapestryDesignerBlock block in metablock.Blocks) { JObject bi = new JObject(); bi["Id"] = block.Id; bi["Name"] = block.Name; bi["IsMetablock"] = false; bi["Level"] = level; ((JArray)item["Items"]).Add(bi); } foreach (TapestryDesignerMetablock mb in metablock.Metablocks) { GetBlockTree(mb, ref blockTree, level + 1); } }
private void GetMetablockList(TapestryDesignerMetablock item, ref JArray list, int level) { list.Add(JToken.Parse($"{{ Id: \"{item.Id}\", Name: \"{item.Name}\", Level: \"{level.ToString()}\" }}")); foreach (TapestryDesignerMetablock mb in item.Metablocks.Where(m => m.IsDeleted == false)) { GetMetablockList(mb, ref list, level + 1); } }
public ActionResult LoadBlockList(int appId, string selectedBlockName) { DBEntities e = COREobject.i.Context; TapestryDesignerMetablock root = e.TapestryDesignerMetablocks.Where(b => b.ParentAppId == appId && b.ParentMetablock_Id == null).FirstOrDefault(); BlockJsonResponse blockList = LoadFromMetablock(root, 0, selectedBlockName); return(Json(blockList)); }
private Application GetApplication(TapestryDesignerMetablock parentMetablock, int metablockId, DBEntities context) { int?rootMetablockId = metablockId; if (parentMetablock != null) { while (parentMetablock.ParentMetablock_Id != null) { parentMetablock = context.TapestryDesignerMetablocks.Include("ParentMetablock") .Where(b => b.Id == parentMetablock.ParentMetablock_Id).First(); } rootMetablockId = parentMetablock.Id; } return(context.Applications.SingleOrDefault(a => a.TapestryDesignerMetablocks.Any(mb => mb.Id == rootMetablockId))); }
public ActionResult Index(FormCollection formParams) { COREobject core = COREobject.i; DBEntities context = core.Context; JArray metablockList = JArray.Parse("[]"); if (Request.HttpMethod == "POST") { int metablockId = 0; TapestryDesignerMetablock parentMetablock = null; if (formParams["appId"] != null) { int appId = int.Parse(formParams["appId"]); core.User.DesignAppId = appId; context.SaveChanges(); var app = context.Applications.Find(appId); var rootMetablock = app.TapestryDesignerRootMetablock; if (rootMetablock == null) { var newRootMetablock = new TapestryDesignerMetablock { Name = "Root metablock", ParentApp = app }; context.TapestryDesignerMetablocks.Add(newRootMetablock); context.SaveChanges(); metablockId = newRootMetablock.Id; } else { metablockId = rootMetablock.Id; } ViewData["appName"] = context.Applications.Find(appId).DisplayName; ViewData["currentAppId"] = appId; GetMetablockList(rootMetablock, ref metablockList, 0); } else { metablockId = int.Parse(formParams["metablockId"]); parentMetablock = context.TapestryDesignerMetablocks.Include("ParentMetablock") .Where(c => c.Id == metablockId).First().ParentMetablock; Application app = GetApplication(parentMetablock, metablockId, context); ViewData["appName"] = app.Name; ViewData["currentAppId"] = app.Id; GetMetablockList(app.TapestryDesignerRootMetablock, ref metablockList, 0); } ViewData["metablockId"] = metablockId; if (parentMetablock == null) { ViewData["parentMetablockId"] = 0; } else { ViewData["parentMetablockId"] = parentMetablock.Id; } } else { var userApp = core.User.DesignApp; if (userApp == null) { userApp = context.Applications.First(); } ViewData["metablockId"] = userApp.TapestryDesignerRootMetablock.Id; ViewData["parentMetablockId"] = 0; ViewData["appName"] = userApp.DisplayName; ViewData["currentAppId"] = userApp.Id; GetMetablockList(userApp.TapestryDesignerRootMetablock, ref metablockList, 0); } ViewData["metablockList"] = metablockList; return(View()); }
private WorkFlow saveMetablock(TapestryDesignerMetablock metaBlock, bool init = false) { try { string metaBlockName = metaBlock.Name.RemoveDiacritics(); WorkFlow resultWF = _app.WorkFlows.SingleOrDefault(w => w.Name == metaBlockName); if (resultWF == null) { resultWF = new WorkFlow { ApplicationId = _app.Id, Name = metaBlock.Name.RemoveDiacritics(), IsTemp = false }; _context.WorkFlows.Add(resultWF); } resultWF.IsInMenu = metaBlock.IsInMenu; resultWF.Type = init ? _context.WorkFlowTypes.Single(t => t.Name == "Init") : _context.WorkFlowTypes.Single(t => t.Name == "Partial"); _context.SaveChanges(); // child meta block foreach (TapestryDesignerMetablock childMetablock in metaBlock.Metablocks.Where(mb => !mb.IsDeleted)) { WorkFlow wf = saveMetablock(childMetablock); wf.Parent = resultWF; } _context.SaveChanges(); // child block List <TapestryDesignerBlock> designerToBuild = _rebuildInAction ? metaBlock.Blocks.Where(b => !b.IsDeleted).ToList() : metaBlock.Blocks.Where(b => !b.IsDeleted && b.IsChanged).ToList(); foreach (TapestryDesignerBlock childBlock in designerToBuild) { try { TapestryDesignerBlockCommit commit = childBlock.BlockCommits.OrderByDescending(c => c.Timestamp).FirstOrDefault(); string modelName = null; if (commit != null) { if (!string.IsNullOrEmpty(commit.ModelTableName)) { modelName = commit.ModelTableName; } else if (!string.IsNullOrEmpty(commit.AssociatedTableName)) { modelName = commit.AssociatedTableName.Split(',').First(); } } // find already builded string blockName = childBlock.Name.RemoveDiacritics(); Block resultBlock = resultWF.Blocks.SingleOrDefault(b => b.Name == blockName); // create block if (resultBlock == null) { resultBlock = new Block(); resultWF.Blocks.Add(resultBlock); } else { IQueryable <int?> cgsToRemove = null; if (_context != _masterContext) { cgsToRemove = _context.ActionRules.Where(ar => (ar.SourceBlock.IsVirtualForBlockId == resultBlock.Id || ar.SourceBlockId == resultBlock.Id) && ar.ConditionGroup != null).Select(ar => ar.ConditionGroupId); } foreach (var ar in _context.ActionRules.Where(ar => ar.SourceBlockId == resultBlock.Id)) { ar.ConditionGroup = null; _context.ActionRules.Remove(ar); } foreach (var ar in _context.ActionRules.Where(ar => ar.TargetBlockId == resultBlock.Id || ar.TargetBlock.IsVirtualForBlockId == resultBlock.Id)) { ar.ConditionGroup = null; _context.ActionRules.Remove(ar); } _context.ResourceMappingPairs.RemoveRange(_context.ResourceMappingPairs.Where(mp => mp.BlockId == resultBlock.Id)); _context.SaveChanges(); _context.Blocks.RemoveRange(_context.Blocks.Where(b => b.IsVirtualForBlockId == resultBlock.Id)); resultBlock.InitForWorkFlow.Clear(); if (_context != _masterContext) { _context.TapestryDesignerConditionGroups.RemoveRange(_context.TapestryDesignerConditionGroups.Where(cg => cgsToRemove.Contains(cg.Id))); } } // update resultBlock.Name = childBlock.Name.RemoveDiacritics(); resultBlock.DisplayName = childBlock.Name; resultBlock.ModelName = modelName; // add init if (childBlock.IsInitial) { resultBlock.InitForWorkFlow.Add(resultWF); } _blockMapping.Add(childBlock, resultBlock); _blocksToBuild.Add(childBlock); } catch (Exception e) { throw new Exception($"Block [{childBlock.Name}]: {e.Message}", e); } } _context.SaveChanges(); // remove deleted List <string> currentDesignerBlockNames = _masterContext.TapestryDesignerBlocks.Where(db => db.ParentMetablock_Id == metaBlock.Id && !db.IsDeleted).Select(b => b.Name).ToList(); var deletedBlocks = _context.Blocks.Where(b => b.WorkFlowId == resultWF.Id && b.IsVirtualForBlock == null && !currentDesignerBlockNames.Contains(b.DisplayName)); _context.Blocks.RemoveRange(deletedBlocks); _context.SaveChanges(); // map rest if (!_rebuildInAction) { foreach (TapestryDesignerBlock childBlock in metaBlock.Blocks.Where(b => !b.IsDeleted && !b.IsChanged)) { string blockName = childBlock.Name.RemoveDiacritics(); _blockMapping[childBlock] = _context.Blocks.SingleOrDefault(b => b.WorkFlowId == resultWF.Id && b.Name == blockName); } } // DONE :) _progressHandler.IncrementProgress("block"); return(resultWF); } catch (Exception e) { throw new Exception($"Metablock [{metaBlock.Name}]: {e.Message}", e); } }