예제 #1
0
        private void GenerateInitBlock(string blockName)
        {
            CodeBuilder result = new CodeBuilder();

            foreach (string use in _usings)
            {
                result.AppendLine($"using {use};");
            }
            result.AppendLine($"namespace {Tapestry.BlockNamespace(_application.Name)}");
            result.StartBlock();
            result.AppendLine($"public class __INIT__ : {blockName}");
            result.StartBlock();
            result.AppendLine("public __INIT__(COREobject core) : base(core)");
            result.AppendLine("{ }");
            /// AppDomain
            //result.AppendLine("~__INIT__()");
            //result.StartBlock();
            //result.AppendLine("_core.Destroy();");
            //result.EndBlock();
            result.EndBlock();
            result.EndBlock();

            string filePath = Path.Combine(Tapestry.PathOutputTemp, $"App_{_application.Name}__INIT__.cs");

            File.WriteAllText(filePath, result.ToString());
        }
예제 #2
0
        private void GenerateBlock()
        {
            string blockName   = _currentBlockCommit.Name.RemoveDiacritics();
            string DisplayName = _currentBlockCommit.Name;
            string ModelName   = _currentBlockCommit.ModelTableName;

            _threadMethods = new CodeBuilder();
            _varNames      = new HashSet <string>();

            CodeBuilder result = new CodeBuilder();

            // usings
            foreach (string use in _usings)
            {
                result.AppendLine($"using {use};");
            }
            // class
            result.AppendLine($"namespace {Tapestry.BlockNamespace(_application.Name)}");
            result.StartBlock();
            string attribute = $"Name = \"{blockName}\", DisplayName = \"{_currentBlockCommit.Name}\"";

            if (!string.IsNullOrEmpty(_currentBlockCommit.ModelTableName))
            {
                attribute += $", ModelTableName = \"{_currentBlockCommit.ModelTableName}\"";
            }
            else if (!string.IsNullOrEmpty(_currentBlockCommit.AssociatedTableName))
            {
                attribute += $", ModelTableName = \"{_currentBlockCommit.AssociatedTableName.Split(',').First()}\"";
            }
            if (!string.IsNullOrEmpty(_currentBlockCommit.AssociatedBootstrapPageIds))
            {
                attribute += $", BootstrapPageId = {_currentBlockCommit.AssociatedBootstrapPageIds.Split(',').First()}";
            }
            if (!string.IsNullOrEmpty(_currentBlockCommit.AssociatedPageIds))
            {
                attribute += $", MozaicPageId = {_currentBlockCommit.AssociatedPageIds.Split(',').Where(pId => _context.MozaicEditorPages.Find(Convert.ToInt32(pId))?.IsModal == false).First()}";
            }
            result.AppendLine($"[Block({attribute})]");
            result.AppendLine($"public class {blockName} : {_tapestryNameSpace}");
            result.StartBlock();
            result.AppendLine($"public {blockName}(COREobject core) : base(core)");
            result.AppendLine("{ }");
            /// AppDomain
            //result.AppendLine($"~{blockName}()");
            //result.StartBlock();
            //result.AppendLine("_core.Destroy();");
            //result.EndBlock();

            // ActionRule
            _progressHandler.SetMessage("T2_wfRule", progressSteps: _currentBlockCommit.WorkflowRules.Count);
            foreach (TapestryDesignerWorkflowRule workflowRule in _currentBlockCommit.WorkflowRules)
            {
                try
                {
                    _currentWFRule = workflowRule;
                    DrainWorkflowRule(result, workflowRule);
                    _progressHandler.IncrementProgress("T2_wfRule");
                }
                catch (TapestrySyntacticOmniusException ex)
                {
                    ex.ApplicationName = _application.Name;
                    ex.BlockName       = _currentBlockCommit.Name;
                    ex.WorkflowName    = workflowRule.Name;
                    throw;
                }
                catch (Exception ex)
                {
                    throw new TapestrySyntacticOmniusException(ex.Message, _application.Name, _currentBlockCommit.Name, workflowRule.Name, ex);
                }
            }

            // thread method
            result.Append(_threadMethods);
            // variables
            foreach (var varName in _varNames)
            {
                result.AppendLine("[IsVariable]");
                result.AppendLine($"public object {varName} {{ get; set; }}");
            }

            result.EndBlock(); // end class
            result.EndBlock(); // end namespace

            string filePath = Path.Combine(Tapestry.PathOutputTemp, $"App_{_application.Name}_{blockName}.cs");

            File.WriteAllText(filePath, result.ToString());
        }