Beispiel #1
0
        private XWorkbook createXFormulas(string expressionText, XWorkbook xWorkbook)
        {
            PSWOclCompiler oclCompiler = new PSWOclCompiler(environment, tracker);
            List <object>  nodes       = oclCompiler.compileOclStream(expressionText, "",
                                                                      new StreamWriter(Console.OpenStandardOutput()), typeof(CSTContextDeclarationCS));
            CSTOperationContextCS operationContextCS = ((CSTOperationContextCS)nodes[0]);
            var constraints = operationContextCS.getConstraintsNodesCS();
            CSTOperationConstraintCS operationConstraint = (CSTOperationConstraintCS)constraints[0];
            ExpressionInOcl          expressionInOcl     = operationConstraint.getExpressionInOCL();
            OclExpressionImpl        bodyExpression      = (OclExpressionImpl)expressionInOcl.getBodyExpression();

            XFormulaCreatorVisitor visitor = new XFormulaCreatorVisitor();

            bodyExpression.accept(visitor);
            string formula = visitor.getFormula();

            CoreClassifier classifier  = (CoreClassifier)expressionInOcl.getContextualElement();
            XDataTable     targetTable = getTargetTable(xWorkbook, classifier);

            var operation = operationContextCS.getOperationNodeCS();
            var name      = operation.getOperationName();
            XDataTableColumn targetColumn =
                targetTable.getDataTableColumns().FirstOrDefault(c => c.getName().Equals(name));

            if (targetColumn == null)
            {
                throw new Exception("Coluna não encontrada!");
            }

            XTextExp xtext = new XTextExp();

            xtext.setTextSymbol(formula);
            targetColumn.setDataContent(xtext);

            MessageBox.Show(formula);

            var extraColumns = visitor.getExtraColumns();

            foreach (KeyValuePair <string, string> pair in extraColumns)
            {
                string columnName    = pair.Key;
                string columnFormula = pair.Value;

                targetTable = getTargetTable(xWorkbook, visitor.getCurrentClassifier());

                var newTableColumn = new XDataTableColumn();
                newTableColumn.setName(columnName);
                newTableColumn.setDataTable(targetTable);
                updateDataTable(targetTable, newTableColumn);

                XTextExp xColumnFormula = new XTextExp();
                xColumnFormula.setTextSymbol(columnFormula);
                newTableColumn.setDataContent(xColumnFormula);
            }

            return(xWorkbook);
        }
Beispiel #2
0
        /// <summary>
        /// Retorna a representação de uma planilha em memória que satisfaz o modelo passado como parâmetro
        /// </summary>
        /// <param name="classDiagramPath">caminho para o arquivo .classdiagram que contém o modelo</param>
        /// <returns>represetação da planilha em memória</returns>
        public XWorkbook createXWorkbook(string classDiagramPath)
        {
            ModelReader   reader = new VscdReader(classDiagramPath);
            CoreModelImpl model  = (CoreModelImpl)reader.getModel();

            OclTypesFactory.setEnvironment(model);

            XWorkbook xWorkbook = new XWorkbook();

            xWorkbook.setName(model.getName());

            environment = model.getEnvironmentWithoutParents();
            IEnumerable <CoreClassifier> modelClasses = getClasses(model);

            foreach (CoreClassifier coreClassifier in modelClasses)
            {
                XWorksheet xWorksheet = new XWorksheet();
                xWorksheet.setName(coreClassifier.getName());
                xWorksheet.setWorkbook(xWorkbook);
                updateWorkbook(xWorkbook, xWorksheet);

                XDataTable xDataTable = new XDataTable();
                xDataTable.setName(coreClassifier.getName());
                xDataTable.setWorksheet(xWorksheet);
                updateWorksheet(xWorksheet, xDataTable);

                createFeatureColumns(coreClassifier, xDataTable, model);
                createAssociationColumn(model, coreClassifier, xDataTable);
            }

            IEnumerable <CoreClassifier> enumerations = getEnumerations(model);
            var iEnumerable = enumerations as IList <CoreClassifier> ?? enumerations.ToList();

            if (enumerations != null && iEnumerable.Any())
            {
                foreach (CoreClassifier enumeration in iEnumerable)
                {
                    XWorksheet xWorksheet = new XWorksheet();
                    xWorksheet.setName(enumeration.getName());
                    xWorksheet.setWorkbook(xWorkbook);
                    updateWorkbook(xWorkbook, xWorksheet);

                    XDataTable xDataTable = new XDataTable();
                    xDataTable.setName(enumeration.getName());
                    xDataTable.setWorksheet(xWorksheet);
                    updateWorksheet(xWorksheet, xDataTable);

                    XDataTableColumn xDataTableColumn = new XDataTableColumn();
                    xDataTableColumn.setName(enumeration.getName());
                    xDataTableColumn.setDataTable(xDataTable);
                    updateDataTable(xDataTable, xDataTableColumn);

                    XDataArray dataArray   = new XDataArray();
                    var        arraySymbol =
                        (from CoreAttributeImpl attribute in
                         enumeration.getClassifierFeatures().Where(f => f is CoreAttributeImpl)
                         select attribute.getName()).ToList();
                    dataArray.setArray(arraySymbol);
                    xDataTableColumn.setDataContent(dataArray);
                }
            }

            return(xWorkbook);
        }