Beispiel #1
0
        /// <summary>
        /// Generate workflow cs files
        /// </summary>
        private void GenerateCsFiles()
        {
            List <TapestryDesignerBlock> designerBlocksToBuild = _rebuild
                ? _application.TapestryDesignerMetablocks.SelectMany(mb => mb.Blocks).Where(b => !b.IsDeleted).ToList()
                : _application.TapestryDesignerMetablocks.SelectMany(mb => mb.Blocks).Where(b => !b.IsDeleted && b.IsChanged).ToList();

            _progressHandler.SetMessage("T2_block", "Creating blocks", MessageType.InProgress, designerBlocksToBuild.Count(b => b.BlockCommits.Any()));
            _progressHandler.SetMessage("T2_wfRule", "Creating workflow rules", MessageType.InProgress);

            foreach (TapestryDesignerBlock designerBlock in designerBlocksToBuild)
            {
                TapestryDesignerBlockCommit blockCommit = designerBlock.BlockCommits.OrderByDescending(bc => bc.Timestamp).FirstOrDefault();
                if (blockCommit == null)
                {
                    continue;
                }

                try
                {
                    // init block
                    if (designerBlock.IsInitial)
                    {
                        GenerateInitBlock(blockCommit.Name.RemoveDiacritics());
                    }

                    //
                    _currentBlockCommit = blockCommit;
                    GenerateBlock();
                    designerBlock.IsChanged = false;
                    _context.SaveChanges();
                }
                catch (Exception ex)
                {
                    _progressHandler.Error(
                        (ex is TapestrySyntacticOmniusException)
                            ? $"[Block:{(ex as TapestrySyntacticOmniusException).BlockName},WF:{(ex as TapestrySyntacticOmniusException).WorkflowName},WFItemId:{(ex as TapestrySyntacticOmniusException).WFItemId}] {ex.Message}"
                            : ex.Message
                        );
                    designerBlock.IsChanged = true;
                    _context.SaveChanges();
                }
                finally
                {
                    _progressHandler.IncrementProgress("T2_block");
                }
            }

            GenerateAssemblyInfoFile();

            _progressHandler.SetMessage("T2_block", "Create blocks - complete", MessageType.Success);
            _progressHandler.SetMessage("T2_wfRule", "Create workflow rules - complete", MessageType.Success, 0);
        }
Beispiel #2
0
        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);
            }
        }
        private void GenerateTables(DbSchemeCommit dbSchemeCommit)
        {
            _progressHandler.SetMessage("GenerateTables", type: MessageType.InProgress, progressSteps: dbSchemeCommit.Tables.Count);

            foreach (DbTable efTable in dbSchemeCommit.Tables)
            {
                //// Table ////
                DBTable entitronTable = _db.Table(efTable.Name);
                // new
                if (!_db.Exists(entitronTable.Name, ETabloid.ApplicationTables))
                {
                    // columns
                    foreach (DbColumn column in efTable.Columns)
                    {
                        AddColumn(entitronTable, efTable, column);
                    }

                    // add indexes
                    foreach (DBIndex index in MergeSchemeIndexUnique(entitronTable, efTable))
                    {
                        entitronTable.Indexes.Add(index);
                    }

                    // create table & columns & costraints & indexes
                    entitronTable.Create();
                }
                // update existing
                else
                {
                    /// columns
                    UpdateColumns(entitronTable, efTable);

                    /// Indexes
                    List <DBIndex> designerIndexes = MergeSchemeIndexUnique(entitronTable, efTable);
                    foreach (DBIndex designerIndex in designerIndexes)
                    {
                        // create
                        DBIndex entitronIndex = entitronTable.Indexes.SingleOrDefault(ei => ei.Columns.Count == designerIndex.Columns.Count && ei.Columns.All(eic => designerIndex.Columns.Contains(eic)));
                        if (entitronIndex == null)
                        {
                            entitronTable.Indexes.Add(designerIndex);
                        }

                        // modify - isUnique changed
                        else if (entitronIndex.isUnique != designerIndex.isUnique)
                        {
                            entitronTable.Indexes.Remove(entitronIndex);
                            entitronTable.Indexes.Add(designerIndex);
                        }
                    }

                    // drop
                    IEnumerable <DBIndex> deletedIndeces = entitronTable.Indexes.Where(ei => !designerIndexes.Any(di => di.Columns.Count == ei.Columns.Count && ei.Columns.All(eic => di.Columns.Contains(eic)))).ToList();
                    foreach (DBIndex index in deletedIndeces)
                    {
                        entitronTable.Indexes.Remove(index);
                    }
                }

                _progressHandler.IncrementProgress();
            } //end foreach efTable

            /// SAVE
            _db.SaveChanges();
            _ent.SaveChanges();

            _progressHandler.SetMessage("GenerateTables", type: MessageType.Success);
        }
Beispiel #4
0
        private void BuildMozaic()
        {
            progressHandler.SetActiveSection(EModule.Mozaic);

            if (masterApp.MozaicChangedSinceLastBuild || _rebuildInAction)
            {
                progressHandler.SetMessage("directory", "Create directories", MessageType.Info);
                //progressHandler.SetMessage("css", "Create CSS template", MessageType.Info);
                progressHandler.SetMessage("pages", "Generate legacy pages", MessageType.Info);
                progressHandler.SetMessage("bootstrapPages", "Generate bootstrap pages", MessageType.Info);

                // dirs
                progressHandler.SetMessage("directory", "Creating directories", MessageType.InProgress);
                if (!Directory.Exists(applicationViewPath))
                {
                    Directory.CreateDirectory(applicationViewPath);
                }
                if (!Directory.Exists(applicationPageViewPath))
                {
                    Directory.CreateDirectory(applicationPageViewPath);
                }
                progressHandler.SetMessage("directory", "Directories created", MessageType.Success);

                //// create template
                //if (masterContext != context && masterApp.CssTemplate != null)
                //{
                //    progressHandler.SetMessage("css", "Creating CSS template", MessageType.InProgress);
                //    app.CssTemplate = new MozaicCssTemplate
                //    {
                //        Name = masterApp.CssTemplate.Name,
                //        Url = masterApp.CssTemplate.Url
                //    };
                //    progressHandler.SetMessage("css", "CSS template created", MessageType.Success);
                //}
                //else
                //    progressHandler.SetMessage("css", "CSS template is not necessary to actualize", MessageType.Info);

                // pages
                progressHandler.SetMessage("pages", "Generating legacy pages", MessageType.InProgress, masterApp.MozaicEditorPages.Count);

                foreach (var editorPage in masterApp.MozaicEditorPages.Where(p => !p.IsDeleted))
                {
                    editorPage.Recompile();
                    string requestedPath = $"{applicationPageViewPath}\\{editorPage.Id}.cshtml";
                    var    oldPage       = context.Pages.FirstOrDefault(c => c.ViewPath == requestedPath);
                    if (oldPage == null)
                    {
                        var newPage = new Page
                        {
                            ViewName    = editorPage.Name,
                            ViewPath    = requestedPath,
                            ViewContent = editorPage.CompiledPartialView,
                            IsBootstrap = false
                        };
                        context.Pages.Add(newPage);
                        context.SaveChanges();
                        editorPage.CompiledPageId = newPage.Id;
                    }
                    else
                    {
                        oldPage.ViewName          = editorPage.Name;
                        oldPage.ViewContent       = editorPage.CompiledPartialView;
                        oldPage.IsBootstrap       = false;
                        editorPage.CompiledPageId = oldPage.Id;
                    }

                    File.WriteAllText(requestedPath, editorPage.CompiledPartialView);

                    progressHandler.IncrementProgress("pages");
                }
                progressHandler.SetMessage("pages", "Generating legacy pages completed", MessageType.Success);

                progressHandler.SetMessage("bootstrapPages", "Generating bootstrap pages", MessageType.InProgress, masterApp.MozaicBootstrapPages.Count);
                Builder bootstrapBuilder = new Builder(context, applicationPageViewPath);
                foreach (var bootstrapPage in masterApp.MozaicBootstrapPages)
                {
                    bootstrapBuilder.BuildPage(bootstrapPage);
                    progressHandler.IncrementProgress("bootstrapPages");
                }
                progressHandler.SetMessage("bootstrapPages", "Generating bootstrap pages completed", MessageType.Success);

                masterApp.MozaicChangedSinceLastBuild = false;
                masterContext.SaveChanges();

                progressHandler.SetMessage("final", "Pages done", MessageType.Success);
                progressHandler.SetMessage(type: MessageType.Success);
            }
            else
            {
                progressHandler.SetMessage(type: MessageType.Info, message: "Pages is not necessary to actualize");
            }
        }