Пример #1
0
 public void add2(cReportFormula formula, String name)
 {
     try
     {
         Add(name, formula);
         formula.setNotSave(true);
     }
     catch
     {
     }
 }
Пример #2
0
 private void releaseReferences()
 {
     if (m_sectionLines != null)
     {
         if (m_sectionLines.getCopyColl() != null)
         {
             m_sectionLines.getCopyColl().clear();
             m_sectionLines.setCopyColl(null);
         }
         m_sectionLines = null;
     }
     m_aspect      = null;
     m_formulaHide = null;
 }
Пример #3
0
 public cReportFormula add(String name)
 {
     try
     {
         cReportFormula c = new cReportFormula();
         c.setName(name);
         Add(name, c);
         return(c);
     }
     catch
     {
         return(null);
     }
 }
 private static string getFunctionCall(string code, cReportFormula formula)
 { 
     int n = code.IndexOf("(");
     var functionName = cUtil.subString(code, 8, n-8);
     var parameters = "";
     for (int _i = 0; _i < formula.getFormulasInt().count(); _i++)
     {
         var fint = formula.getFormulasInt().item(_i);
         parameters += "globals.getVar(\"p__" + _i + "__\").getValue(),";
     }
     if (parameters.Length > 0)
     {
         parameters = parameters.Substring(0, parameters.Length - 1);
     }
     return functionName + "(" + parameters + ")";
 }
Пример #5
0
        private static string getFunctionCall(string code, cReportFormula formula)
        {
            int n            = code.IndexOf("(");
            var functionName = cUtil.subString(code, 8, n - 8);
            var parameters   = "";

            for (int _i = 0; _i < formula.getFormulasInt().count(); _i++)
            {
                var fint = formula.getFormulasInt().item(_i);
                parameters += "globals.getVar(\"p__" + _i + "__\").getValue(),";
            }
            if (parameters.Length > 0)
            {
                parameters = parameters.Substring(0, parameters.Length - 1);
            }
            return(functionName + "(" + parameters + ")");
        }
Пример #6
0
        private void releaseReferences()
        {
            setCopyColl(null);

            if (m_controls != null)
            {
                if (m_controls.getCopyColl() != null)
                {
                    m_controls.getCopyColl().clear();
                    m_controls.setCopyColl(null);
                }
                m_controls.clear();
                m_controls = null;
            }

            m_aspect      = null;
            m_formulaHide = null;
        }
Пример #7
0
        private static string putCodeInClass(string code, cReportFormula formula)
        {
            if (cUtil.subString(code, 0, 8).ToLower() == "function")
            {
                return("Public Class util\r\n"
                       + "Implements CSReportScript.cIReportScriptType\r\n"
                       + code + "\r\n"
                       + "Public Function RunScript(globals As CSReportScript.cReportCompilerGlobals) As String Implements CSReportScript.cIReportScriptType.RunScript\r\n"
                       + "  dim value__ = " + getFunctionCall(code, formula) + "\r\n"

                       // TODO: remove debug info

                       /*
                        + "  System.Console.WriteLine(\"" + formula.getName() + "\")\r\n"
                        + "  Dim var__\r\nFor Each var__ In globals\r\n System.Console.WriteLine(var__.ToString() + \" : \" + globals.getVar(var__).getValue().ToString())\r\nNext\r\n"
                        + "  System.Console.WriteLine(value__.ToString())\r\n"
                        + "  System.Console.WriteLine(\"---------------\")\r\n"
                        */
                       // end debug info

                       + "  Select Case Microsoft.VisualBasic.Information.VarType(value__)\r\n"
                       + "    Case 11\r\n"
                       + "      RunScript = System.Convert.ToInt32(value__)\r\n"
                       + "    Case 7\r\n"
                       + "      RunScript = String.Format(\"{0:MM/dd/yyyy}\", value__)\r\n"
                       + "    Case Else\r\n"
                       + "      RunScript = value__\r\n"
                       + "  End Select\r\n"
                       + "End Function\r\n"
                       + "Function Now()\r\n"
                       + "  Now = Microsoft.VisualBasic.Now\r\n"
                       + "End Function\r\n"
                       + "Function FormatDateTime(aDate, format) As String\r\n"
                       + "    FormatDateTime = Microsoft.VisualBasic.Strings.FormatDateTime(aDate, format)\r\n"
                       + "End Function\r\n"
                       + "End Class");
            }
            else
            {
                // TODO: implement c# scripting
                //
                return("public class util: cIReportScriptType { public " + code + "}");
            }
        }
        private static string putCodeInClass(string code, cReportFormula formula)
        {
            if (cUtil.subString(code, 0, 8).ToLower() == "function")
            {
                return "Public Class util\r\n"
                     + "Implements CSReportScript.cIReportScriptType\r\n"
                     + code + "\r\n"
                     + "Public Function RunScript(globals As CSReportScript.cReportCompilerGlobals) As String Implements CSReportScript.cIReportScriptType.RunScript\r\n"
                     + "  dim value__ = " + getFunctionCall(code, formula) + "\r\n"

                     // TODO: remove debug info
                     /*
                     + "  System.Console.WriteLine(\"" + formula.getName() + "\")\r\n"
                     + "  Dim var__\r\nFor Each var__ In globals\r\n System.Console.WriteLine(var__.ToString() + \" : \" + globals.getVar(var__).getValue().ToString())\r\nNext\r\n"
                     + "  System.Console.WriteLine(value__.ToString())\r\n"
                     + "  System.Console.WriteLine(\"---------------\")\r\n"
                      */ 
                     // end debug info

                     + "  Select Case Microsoft.VisualBasic.Information.VarType(value__)\r\n"
                     + "    Case 11\r\n"
                     + "      RunScript = System.Convert.ToInt32(value__)\r\n"
                     + "    Case 7\r\n"
                     + "      RunScript = String.Format(\"{0:MM/dd/yyyy}\", value__)\r\n"
                     + "    Case Else\r\n"
                     + "      RunScript = value__\r\n"
                     + "  End Select\r\n"
                     + "End Function\r\n"
                     + "Function Now()\r\n"
                     + "  Now = Microsoft.VisualBasic.Now\r\n"
                     + "End Function\r\n"
                     + "Function FormatDateTime(aDate, format) As String\r\n"
                     + "    FormatDateTime = Microsoft.VisualBasic.Strings.FormatDateTime(aDate, format)\r\n"
                     + "End Function\r\n"
                     + "End Class";
            }
            else
            {
                // TODO: implement c# scripting
                //
                return "public class util: cIReportScriptType { public " + code + "}";
            }            
        }
Пример #9
0
        private void pSetFormulaIndexGroup(cReportFormula formula, cReportSection sec)
        { // TODO: Use of ByRef founded Private Function pSetFormulaIndexGroup(ByRef Formula As cReportFormula, ByRef Sec As cReportSection) As Boolean
            cReportFormulaInt fint = null;
            int indexGroup = 0;

            for (int _i = 0; _i < formula.getFormulasInt().count(); _i++)
            {
                fint = formula.getFormulasInt().item(_i);

                if (pIsGroupFormula((int)fint.getFormulaType()))
                {
                    if (fint.getFormulaType() == csRptFormulaType.CSRPTGROUPPERCENT)
                    {
                        formula.setIdxGroup2(0);
                        indexGroup = cUtil.valAsInt(fint.getParameters().item(3).getValue());
                    }
                    else
                    {
                        indexGroup = cUtil.valAsInt(fint.getParameters().item(2).getValue());
                    }
                    if (fint.getParameters().item(cReportGlobals.C_KEYINDEXGROUP) == null)
                    {
                        fint.getParameters().add2("", cReportGlobals.C_KEYINDEXGROUP);
                    }
                    if (indexGroup == -1)
                    {
                        if (sec.getTypeSection() == csRptSectionType.GROUP_HEADER
                            || sec.getTypeSection() == csRptSectionType.GROUP_FOOTER)
                        {
                            // index of the group
                            //
                            fint.getParameters().item(cReportGlobals.C_KEYINDEXGROUP).setValue(sec.getIndex().ToString());
                            formula.setIdxGroup(sec.getIndex());
                        }
                        else if (sec.getTypeSection() == csRptSectionType.MAIN_DETAIL)
                        {
                            // index of the most internal group
                            //
                            fint.getParameters().item(cReportGlobals.C_KEYINDEXGROUP).setValue(m_groups.count().ToString());
                            formula.setIdxGroup(m_groups.count()-1);
                        }
                        else
                        {
                            fint.getParameters().item(cReportGlobals.C_KEYINDEXGROUP).setValue("0");
                            formula.setIdxGroup(0);
                        }
                    }
                    else
                    {
                        fint.getParameters().item(cReportGlobals.C_KEYINDEXGROUP).setValue(indexGroup.ToString());
                        formula.setIdxGroup(indexGroup);
                    }
                }
            }
        }
 private object pExecScriptCode(String code, cReportFormula formula)
 {
     try
     {
         code = pPipeToColon(code);
         if (formula.getCompiledScript() == null)
         {
             formula.setCompiledScript(cReportScriptEngine.compileCode(code, formula));
         }
         return cReportScriptEngine.eval(formula.getCompiledScript(), m_objGlobals);
     }
     catch (Exception ex)
     {
         String msg = ex.Source
                     + ex.Message + "\n\nCode:\n=====\n\n" + code + "\n\n"
                     + ex.HelpLink;
         throw new ReportException(csRptErrors.ERROR_IN_SCRIPT, C_MODULE, msg);
     }
 }
        private object pEvalSyntax(String functionName, String code, bool bParam, cReportFormula formula)
        {
            int i = 0;
            String s = "";

            code = removeReturns(code);

            if (functionName.Length > 0)
            {
                return pCheckInternalFunction(functionName, code);
            }
            else if (code.Length == 0)
            {
                return "";
            }
            else if (code == "\"\"")
            {
                return "";
            }
            else if (G.isNumeric(code))
            {
                return code;
            }
            else if (cReportGlobals.isDate(code))
            {
                return code;
            }
            else if (pIsTime(code))
            {
                return code;
            }
            else if (!bParam)
            {
                pExecScriptCode(code, formula);
                return code;
            }
            else
            {

                String[] vParams = null;
                String parameters = "";

                parameters = code.Trim();
                if (parameters.Length > 2)
                {
                    parameters = parameters.Substring(2, parameters.Length - 2);
                    parameters = parameters.Trim();
                    vParams = parameters.Split('|');
                }

                try
                {
                    for (i = 0; i < vParams.Length; i++)
                    {
                        try
                        {
                            // if it is a number we don't need to evaluate it
                            //
                            if (!G.isNumeric(vParams[i]))
                            {

                                if (!pIsControl(vParams[i]))
                                {
                                    // Si se produce un error es por que se trata
                                    // de un parametro a la funcion, la asignacion
                                    // no se llevara a cabo, y no perdere el valor
                                    // del parametro
                                    s = C_TEMPFUNCTIONB + vParams[i] + C_TEMPFUNCTIONE;
                                    vParams[i] = pExecScriptCode(s, formula).ToString();
                                }
                            }
                            code = vParams[i] + "|";
                        }
                        catch 
                        {
                            // we don't care about errors here
                        }
                    }

                    code = cUtil.removeLastColon(code);
                    return code;
                }
                catch
                {
                    // we don't care about errors here
                }
            }
            return null;
        }
        public void evalFunction(cReportFormula formula)
        {
            String codeC = "";

            m_objGlobals.setMode(eReportCompilerMode.C_EVAL);

            pEvalGroupFunctions(formula);

            cReportError.gDebugSection = formula.getSectionName();
            cReportError.gDebugSectionLine = formula.getSectionLineIndex();
            cReportError.gDebugControl = formula.getControlName();

            m_formula = formula;

            pCompile(formula.getText(), false, codeC);

            if (formula.getFormulasInt().count() > 0)
            {
                if (G.isNumeric(codeC))
                {
                    pEvalSyntax("", codeC, false, formula);
                }
                else
                {
                    if (cUtil.subString(codeC.Trim(), 0, 8).ToLower() == "function")
                    {
                        pEvalSyntax("", codeC, false, formula);
                    }
                }
            }
            else
            {
                pEvalSyntax("", codeC, false, formula);
            }
            m_formula = null;
        }
        public void evalFunctionGroup(cReportFormula formula)
        {
            cReportFormulaInt fint = null;

            for (int _i = 0; _i < formula.getFormulasInt().count(); _i++)
            {
                fint = formula.getFormulasInt().item(_i);
                pEvalFunctionGroup(fint);
            }
        }
        public object resultFunction(cReportFormula formula)
        {
            String code = "";
            object[] vResult = null;

            m_objGlobals.setMode(eReportCompilerMode.C_RESULT);
            m_ctrlName = formula.getControlName();

            vResult = new object[formula.getFormulasInt().count()];

            cReportFormulaInt fint = null;

            for (int _i = 0; _i < formula.getFormulasInt().count(); _i++)
            {
                fint = formula.getFormulasInt().item(_i);
                vResult[_i] = pResultFunctionInt(fint);
            }

            // we check if the code has scripting or is only 
            // calls to internal functions
            //
            code = formula.getTextC().Replace(C_KEYFUNCINT, "");
            code = code.Replace(" ", "");

            // if after removing calls to internal functions and spaces
            // there is only a number we don't have scripting
            //
            if (G.isNumeric(code))
            {
                if (vResult.Length > 0)
                {
                    formula.setLastResult(vResult[0]);
                    formula.setHaveToEval(false);
                    return formula.getLastResult();
                }
                // the function can be only a constant (it is used in Cairo navigation)
                //
                else
                {
                    return code;
                }
            }
            else
            {
                code = formula.getTextC();
                var parameters = "";

                for (int i = 0; i < vResult.Length; i++)
                {
                    // if one argument is null it means we don't have a row for this formula
                    // so we don't need to compile the code
                    //
                    if (vResult[i] == null) 
                    { 
                        return null; 
                    }

                    /* TODO: remove me
                    code = code.Replace(C_KEYFUNCINT + cReportGlobals.format(i + 1, "000"), 
                                            getNumericVal(vResult[i].ToString()));
                     * */

                    var parameter = "p__" + i + "__";
                    parameters += parameter + ",";
                    code = code.Replace(C_KEYFUNCINT + cReportGlobals.format(i + 1, "000"), parameter);

                    var paramValue = m_objGlobals.getVar(parameter);
                    if (paramValue == null) {
                        paramValue = m_objGlobals.addVar(parameter);
                    }
                    paramValue.setValue(vResult[i]);
                }

                if (parameters.Length > 0)
                {
                    parameters = parameters.Substring(0, parameters.Length - 1);
                    code = insertParametersIntoFunction(code, parameters);
                }

                formula.setLastResult(pExecScriptCode(code, formula));
                formula.setHaveToEval(false);
                return formula.getLastResult();
            }
        }
        private void pEvalGroupFunctions(cReportFormula formula)
        {
            cReportFormulaInt fint = null;

            for (int _i = 0; _i < formula.getFormulasInt().count(); _i++)
            {
                fint = formula.getFormulasInt().item(_i);

                switch (fint.getFormulaType())
                {
                    case csRptFormulaType.CSRPTGROUPTOTAL:
                        evalGroupTotal(fint);

                        break;
                    case csRptFormulaType.CSRPTGROUPMAX:
                        evalGroupMax(fint);

                        break;
                    case csRptFormulaType.CSRPTGROUPMIN:
                        evalGroupMin(fint);

                        break;
                    case csRptFormulaType.CSRPTGROUPAVERAGE:
                        evalGroupAverage(fint);

                        break;
                    case csRptFormulaType.CSRPTGROUPPERCENT:
                        evalGroupPercent(fint);

                        break;
                    case csRptFormulaType.CSRPTGROUPCOUNT:
                        evalGroupCount(fint);

                        break;
                    case csRptFormulaType.CSRPTGROUPLINENUMBER:
                        evalGroupLineNumber(fint);

                        break;
                }
            }
        }
        public void initVariable(cReportFormula formula)
        {
            cReportVariable var = null;
            cReportFormulaInt fint = null;
            cStructTime st = null;

            for (int _i = 0; _i < formula.getFormulasInt().count(); _i++)
            {
                fint = formula.getFormulasInt().item(_i);
                for (int _j = 0; _j < fint.getVariables().count(); _j++)
                {
                    var = fint.getVariables().item(_j);

                    System.TypeCode typeCode = System.Type.GetTypeCode(var.getValue().GetType());
                    switch (typeCode)
                    {

                        case System.TypeCode.DBNull:
                            break;
                        case System.TypeCode.Decimal:
                        case System.TypeCode.Double:
                        case System.TypeCode.Int16:
                        case System.TypeCode.Int32:
                        case System.TypeCode.Int64:
                        case System.TypeCode.Single:
                        case System.TypeCode.UInt16:
                        case System.TypeCode.UInt32:
                        case System.TypeCode.UInt64:
                        case System.TypeCode.Byte:
                        case System.TypeCode.SByte:
                        case System.TypeCode.DateTime:
                        case System.TypeCode.Boolean:
                            var.setValue(0);
                            break;
                        case System.TypeCode.Char:
                        case System.TypeCode.String:
                            var.setValue("");
                            break;
                        case System.TypeCode.Object:
                            if (var.getValue() is cStructTime)
                            {
                                st = (cStructTime)var.getValue();
                                st.setHour(0);
                                st.setMinute(0);
                                st.setSecond(0);
                            }
                            break;
                        case System.TypeCode.Empty:
                            break;
                        default:
                            break;
                    }
                }
            }
        }
        // it compiles the code of every formula
        // first it replaces every internal function by 
        // dummy return values (of the type of the internal function)
        // if after the replace there is code it call cReportScriptEngine.compileCode
        // if there are no errors it returns true
        // 
        public bool checkSyntax(cReportFormula formula)
        {
            try
            {
                String code = "";

                m_formula = formula;
                m_formula.getFormulasInt().clear();

                // check syntax
                code = formula.getText();
                m_formula.setTextC(code);

                pCheckSyntax(code);

                return true;
            }
            catch (Exception ex)
            {
                cError.mngError(ex, "checkSyntax", C_MODULE, "");

                m_formula = null;
                m_fint = null;

                return false;
            }

        }
 public void add2(cReportFormula formula, String name)
 { 
     try
     {
         Add(name, formula);
         formula.setNotSave(true);
     }
     catch 
     {
     }
 }
Пример #19
0
        public bool checkSyntax(String code) {
            cReportFormula f = null;

            f = new cReportFormula();

            if (m_fProperties != null)
            {
                f.setName(m_fProperties.getFormulaName());
            }
            else if (m_fSecProperties != null)
            {
                f.setName(m_fSecProperties.getFormulaName());
            }
            else
            {
                f.setName(cMainEditor.getCtrlTreeBox().getFormulaName());
            }

            f.setText(code);

            return m_report.getCompiler().checkSyntax(f);
        }
Пример #20
0
 private void addFormula(cReportFormula formula, String name)
 {
     if (m_formulas.item(name) == null)
     {
         m_formulas.add2(formula, name);
     }
 }
Пример #21
0
 private void releaseReferences()
 {
     if (m_sectionLines != null)
     {
         if (m_sectionLines.getCopyColl() != null)
         {
             m_sectionLines.getCopyColl().clear();
             m_sectionLines.setCopyColl(null);
         }
         m_sectionLines = null;
     }
     m_aspect = null;
     m_formulaHide = null;
 }
        private void releaseReferences()
        {
            setCopyColl(null);

            if (m_controls != null)
            {
                if (m_controls.getCopyColl() != null)
                {
                    m_controls.getCopyColl().clear();
                    m_controls.setCopyColl(null);
                }
                m_controls.clear();
                m_controls = null;
            }

            m_aspect = null;
            m_formulaHide = null;
        }
        internal static Assembly compileCode(string code, cReportFormula formula)
        {
            // Create a code provider
            // This class implements the 'CodeDomProvider' class as its base. All of the current .Net languages (at least Microsoft ones)
            // come with thier own implemtation, thus you can allow the user to use the language of thier choice (though i recommend that
            // you don't allow the use of c++, which is too volatile for scripting use - memory leaks anyone?)

            CodeDomProvider provider;

            if (cUtil.subString(code, 0, 8).ToLower() == "function")
            {
                provider = new Microsoft.VisualBasic.VBCodeProvider();
            }
            else 
            {
                provider = new Microsoft.CSharp.CSharpCodeProvider();
            }

            // Setup our options
            CompilerParameters options = new CompilerParameters();
            options.GenerateExecutable = false; // we want a Dll (or "Class Library" as its called in .Net)
            options.GenerateInMemory = true; // Saves us from deleting the Dll when we are done with it, though you could set this to false and save start-up time by next time by not having to re-compile
            // And set any others you want, there a quite a few, take some time to look through them all and decide which fit your application best!

            // Add any references you want the users to be able to access, be warned that giving them access to some classes can allow
            // harmful code to be written and executed. I recommend that you write your own Class library that is the only reference it allows
            // thus they can only do the things you want them to.
            // (though things like "System.Xml.dll" can be useful, just need to provide a way users can read a file to pass in to it)
            // Just to avoid bloatin this example to much, we will just add THIS program to its references, that way we don't need another
            // project to store the interfaces that both this class and the other uses. Just remember, this will expose ALL public classes to
            // the "script"

            var assemblies = Assembly.GetExecutingAssembly().GetReferencedAssemblies();

            foreach (AssemblyName assemblyName in assemblies)
            {
                if (assemblyName.Name == "CSReportScript")
                {
                    foreach (Assembly assembly in AppDomain.CurrentDomain.GetAssemblies())
                    {
                        if (assembly.GetName().Name == assemblyName.Name)
                        {
                            options.ReferencedAssemblies.Add(assembly.Location);
                            break;                        
                        }
                    }
                    break;
                }
            }            

            // Compile our code
            CompilerResults result;
            string classCode = putCodeInClass(code, formula);
            result = provider.CompileAssemblyFromSource(options, classCode);

            if (result.Errors.HasErrors)
            {
                var errors = "";

                for (int i = 0; i < result.Errors.Count; i++)
                {
                    errors += result.Errors[0].ErrorText + "\r\n";
                }

                cWindow.msgError(errors + "\r\n\r\nSource code:\r\n\r\n" + classCode + "\r\n\r\n");

                return null;
            }

            if (result.Errors.HasWarnings)
            {
                // TODO: tell the user about the warnings, might want to prompt them if they want to continue
                // runnning the "script"
            }

            return result.CompiledAssembly;
        }
Пример #24
0
        private void pSetIndexColInGroupFormula(cReportFormula formula, List<object[]> recordsets)
        {
            cReportFormulaInt fint = null;
            String colName = "";
            DataTable rs = null;

            if (!m_reportDisconnected)
            {
                rs = (DataTable)recordsets[0][0];

                for (int _i = 0; _i < formula.getFormulasInt().count(); _i++)
                {
                    fint = formula.getFormulasInt().item(_i);

                    if (pIsGroupFormula((int)fint.getFormulaType()))
                    {
                        colName = fint.getParameters().item(0).getValue();
                        pSetColIndexInGroupFormulaAux(rs, fint, colName, cReportGlobals.C_KEYINDEXCOL);

                        if (fint.getFormulaType() == csRptFormulaType.CSRPTGROUPPERCENT)
                        {
                            colName = fint.getParameters().item(1).getValue();
                            pSetColIndexInGroupFormulaAux(rs, fint, colName, cReportGlobals.C_KEYINDEXCOL2);
                        }
                    }
                }
            }
        }
Пример #25
0
        internal static Assembly compileCode(string code, cReportFormula formula)
        {
            // Create a code provider
            // This class implements the 'CodeDomProvider' class as its base. All of the current .Net languages (at least Microsoft ones)
            // come with thier own implemtation, thus you can allow the user to use the language of thier choice (though i recommend that
            // you don't allow the use of c++, which is too volatile for scripting use - memory leaks anyone?)

            CodeDomProvider provider;

            if (cUtil.subString(code, 0, 8).ToLower() == "function")
            {
                provider = new Microsoft.VisualBasic.VBCodeProvider();
            }
            else
            {
                provider = new Microsoft.CSharp.CSharpCodeProvider();
            }

            // Setup our options
            CompilerParameters options = new CompilerParameters();

            options.GenerateExecutable = false; // we want a Dll (or "Class Library" as its called in .Net)
            options.GenerateInMemory   = true;  // Saves us from deleting the Dll when we are done with it, though you could set this to false and save start-up time by next time by not having to re-compile
            // And set any others you want, there a quite a few, take some time to look through them all and decide which fit your application best!

            // Add any references you want the users to be able to access, be warned that giving them access to some classes can allow
            // harmful code to be written and executed. I recommend that you write your own Class library that is the only reference it allows
            // thus they can only do the things you want them to.
            // (though things like "System.Xml.dll" can be useful, just need to provide a way users can read a file to pass in to it)
            // Just to avoid bloatin this example to much, we will just add THIS program to its references, that way we don't need another
            // project to store the interfaces that both this class and the other uses. Just remember, this will expose ALL public classes to
            // the "script"

            var assemblies = Assembly.GetExecutingAssembly().GetReferencedAssemblies();

            foreach (AssemblyName assemblyName in assemblies)
            {
                if (assemblyName.Name == "CSReportScript")
                {
                    foreach (Assembly assembly in AppDomain.CurrentDomain.GetAssemblies())
                    {
                        if (assembly.GetName().Name == assemblyName.Name)
                        {
                            options.ReferencedAssemblies.Add(assembly.Location);
                            break;
                        }
                    }
                    break;
                }
            }

            // Compile our code
            CompilerResults result;
            string          classCode = putCodeInClass(code, formula);

            result = provider.CompileAssemblyFromSource(options, classCode);

            if (result.Errors.HasErrors)
            {
                var errors = "";

                for (int i = 0; i < result.Errors.Count; i++)
                {
                    errors += result.Errors[0].ErrorText + "\r\n";
                }

                cWindow.msgError(errors + "\r\n\r\nSource code:\r\n\r\n" + classCode + "\r\n\r\n");

                return(null);
            }

            if (result.Errors.HasWarnings)
            {
                // TODO: tell the user about the warnings, might want to prompt them if they want to continue
                // runnning the "script"
            }

            return(result.CompiledAssembly);
        }
Пример #26
0
        private void m_fFormula_CheckSintaxis(out bool cancel, String code) { 
            cReportFormula f = null;
            f = new cReportFormula();
            if (m_fProperties != null) {
                f.setName(m_fProperties.getFormulaName());
            } 
            else {
                f.setName(m_fSecProperties.getFormulaName());
            }
            f.setText(code);
			cancel = !m_report.getCompiler().checkSyntax(f);
        }
 public cReportFormula add(String name)
 {
     try
     {
         cReportFormula c = new cReportFormula();
         c.setName(name);
         Add(name, c);
         return c;
     }
     catch 
     {
         return null;
     }
 }