Exemple #1
0
 public ProgramEngine(HomeGenieService hg)
 {
     homegenie     = hg;
     scriptingHost = new CSharpAppFactory(homegenie);
     macroRecorder = new MacroRecorder(this);
     scheduler     = new SchedulerService(this);
     scheduler.Start();
 }
Exemple #2
0
 public ProgramEngine(HomeGenieService hg)
 {
     homegenie = hg;
     scriptingHost = new CSharpAppFactory(homegenie);
     macroRecorder = new MacroRecorder(this);
     scheduler = new SchedulerService(this);
     scheduler.Start();
 }
Exemple #3
0
        private List <ProgramError> CompileCsharp(ProgramBlock program)
        {
            List <ProgramError> errors = new List <ProgramError>();

            // dispose assembly and interrupt current task
            program.AppAssembly = null;
            program.IsEnabled   = false;
            // clean up old assembly files
            if (!Directory.Exists(Path.GetDirectoryName(program.AssemblyFile)))
            {
                Directory.CreateDirectory(Path.GetDirectoryName(program.AssemblyFile));
            }
            if (File.Exists(program.AssemblyFile))
            {
                File.Delete(program.AssemblyFile);
            }
            if (File.Exists(program.AssemblyFile + ".mdb"))
            {
                File.Delete(program.AssemblyFile + ".mdb");
            }
            if (File.Exists(program.AssemblyFile + ".pdb"))
            {
                File.Delete(program.AssemblyFile + ".pdb");
            }

            // DO NOT CHANGE THE FOLLOWING LINES OF CODE
            // it is a lil' trick for mono compatibility
            // since it will be caching the assembly when using the same name
            // and use the old one instead of the new one
            string tmpfile = Path.Combine("programs", Guid.NewGuid().ToString() + ".dll");

            System.CodeDom.Compiler.CompilerResults result = new System.CodeDom.Compiler.CompilerResults(null);
            try
            {
                result = CSharpAppFactory.CompileScript(program.ScriptCondition, program.ScriptSource, tmpfile);
            }
            catch (Exception ex)
            {
                // report errors during post-compilation process
                result.Errors.Add(new System.CodeDom.Compiler.CompilerError(program.Name, 0, 0, "-1", ex.Message));
            }

            if (result.Errors.Count == 0)
            {
                program.AppAssembly = result.CompiledAssembly;
                File.Move(tmpfile, program.AssemblyFile);
                if (File.Exists(tmpfile + ".mdb"))
                {
                    File.Move(tmpfile + ".mdb", program.AssemblyFile + ".mdb");
                }
                if (File.Exists(tmpfile + ".pdb"))
                {
                    File.Move(tmpfile + ".pdb", program.AssemblyFile + ".pdb");
                }
            }
            else
            {
                int sourceLines = program.ScriptSource.Split('\n').Length;
                foreach (System.CodeDom.Compiler.CompilerError error in result.Errors)
                {
                    //if (!ce.IsWarning)
                    {
                        int    errorRow  = (error.Line - CSharpAppFactory.PROGRAM_CODE_OFFSET);
                        string blockType = "CR";
                        if (errorRow >= sourceLines + CSharpAppFactory.CONDITION_CODE_OFFSET)
                        {
                            errorRow -= (sourceLines + CSharpAppFactory.CONDITION_CODE_OFFSET);
                            blockType = "TC";
                        }
                        errors.Add(new ProgramError()
                        {
                            Line         = errorRow,
                            Column       = error.Column,
                            ErrorMessage = error.ErrorText,
                            ErrorNumber  = error.ErrorNumber,
                            CodeBlock    = blockType
                        });
                    }
                }
            }

            return(errors);
        }
Exemple #4
0
        private List <ProgramError> CompileCsharp(ProgramBlock program)
        {
            List <ProgramError> errors = new List <ProgramError>();

            // dispose assembly and interrupt current task
            program.AppAssembly = null;
            program.IsEnabled   = false;

            if (!Directory.Exists(Path.GetDirectoryName(program.AssemblyFile)))
            {
                Directory.CreateDirectory(Path.GetDirectoryName(program.AssemblyFile));
            }
            // DO NOT CHANGE THE FOLLOWING LINES OF CODE
            // it is a lil' trick for mono compatibility
            // since it was caching the assembly when using the same name
            string tmpfile = Guid.NewGuid().ToString() + ".dll";

            // delete old assembly
            System.CodeDom.Compiler.CompilerResults result = new System.CodeDom.Compiler.CompilerResults(null);
            try
            {
                result = CSharpAppFactory.CompileScript(program.ScriptCondition, program.ScriptSource, tmpfile);
                if (File.Exists(program.AssemblyFile))
                {
                    // delete old assebly
                    File.Delete(program.AssemblyFile);
                }
                // move newly compiled assembly to programs folder
                if (result.Errors.Count == 0)
                {
                    // submitting new assembly
                    File.Move(tmpfile, program.AssemblyFile);
                }
            }
            catch (Exception ex)
            {
                // report errors during post-compilation process
                result.Errors.Add(new System.CodeDom.Compiler.CompilerError(program.Name, 0, 0, "-1", ex.Message));
            }

            int startCodeLine       = 19;
            int conditionCodeOffset = 7;

            //
            if (result.Errors.Count == 0)
            {
                program.AppAssembly = result.CompiledAssembly;
            }
            else
            {
                int sourceLines = program.ScriptSource.Split('\n').Length;
                foreach (System.CodeDom.Compiler.CompilerError error in result.Errors)
                {
                    //if (!ce.IsWarning)
                    {
                        int    errorRow  = (error.Line - startCodeLine);
                        string blockType = "CR";
                        if (errorRow >= sourceLines + conditionCodeOffset)
                        {
                            errorRow -= (sourceLines + conditionCodeOffset);
                            blockType = "TC";
                        }
                        errors.Add(new ProgramError()
                        {
                            Line         = errorRow,
                            Column       = error.Column,
                            ErrorMessage = error.ErrorText,
                            ErrorNumber  = error.ErrorNumber,
                            CodeBlock    = blockType
                        });
                    }
                }
            }

            return(errors);
        }