public void TestInterfaceWithConstructor()
        {
            var cp = new object[] {};

            CrossDomainCompiler.Call(@"test\ImplWithConstructor.cs", @"test\SimpleInterface.json",
                                     typeof(SimpleInterface), "CallMe", ref cp);
        }
Esempio n. 2
0
        public void TestLoadAndInterfaceWithConstructor()
        {
            CrossDomainCompiler.LoadScript(@"test\SimpleInterface.json", @"test");
            var cp = new object[] {};

            CrossDomainCompiler.Call(@"test", typeof(SimpleInterface), "ImplWithConstructor", "CallMe", ref cp);
        }
Esempio n. 3
0
        public void TestLoadAndCallMethodWithArgumentImpl()
        {
            CrossDomainCompiler.LoadScript(@"test\SimpleInterface.json", @"test");
            var cp = new object[] {};
            var mp = new object[] { "Hellow world!" };

            CrossDomainCompiler.Call(@"test", typeof(MethodWithArgument), "MethodWithArgumentImpl", "CallMe", ref cp, ref mp);
        }
        public void TestMethodWithArgumentImpl()
        {
            var cp = new object[] {};
            var mp = new object[] { "Hellow world!" };

            CrossDomainCompiler.Call(@"test\MethodWithArgumentImpl.cs", @"test\SimpleInterface.json",
                                     typeof(MethodWithArgument), "CallMe", ref cp, ref mp);
        }
Esempio n. 5
0
        public void TestLoadAndCallMethodWithArgumentModifyImpl()
        {
            CrossDomainCompiler.LoadScript(@"test\SimpleInterface.json", @"test");
            var cp = new object[] {};
            var mp = new object[] { "Hellow world!" };

            CrossDomainCompiler.Call(@"test", typeof(MethodWithArgumentChanged), "MethodWithArgumentChangedImpl", "CallMe", ref cp, ref mp);
            StringAssert.AreEqualIgnoringCase("Hello Unit.", (string)mp[0]);
        }
        public void TestMethodWithArgumentImplModify()
        {
            var cp     = new object[] {};
            var change = "Hello world";
            var mp     = new object[] { change };

            CrossDomainCompiler.Call(@"test\MethodWithArgumentChangedImpl.cs", @"test\SimpleInterface.json",
                                     typeof(MethodWithArgumentChanged), "CallMe", ref cp, ref mp);
            StringAssert.AreEqualIgnoringCase("Hello Unit.", (string)mp[0]);
        }
Esempio n. 7
0
        public static string CallTemplateHandle(TemplateHandlerPrams para, string handleName)
        {
            const string method     = "WriteFile";
            string       dependPath = Path.GetFullPath(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, DependPath));
            string       templateHandleRootDirPath = Path.GetFullPath(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, TemplateHandleRootDirPath));
            string       templateHandlePath        = MonitorReportFile.GetTemplateHandlePath(templateHandleRootDirPath, handleName);
            var          cp = new object[] { para };

            CrossDomainCompiler.Call(templateHandlePath, dependPath, typeof(TemplateHandleBase), method, ref cp);
            return(para.FileFullName);
        }
Esempio n. 8
0
        public void TestLoadAndCallPerf()
        {
            CrossDomainCompiler.LoadScript(@"test\SimpleInterface.json", @"test");
            var       start = DateTime.Now;
            const int upper = 100;

            for (var i = 0; i < upper; i++)
            {
                CrossDomainCompiler.Call(@"test", typeof(SimpleInterface), "ImplWithConstructor", "CallMe");
            }
            var end      = DateTime.Now;
            var tpercall = ((end.Ticks - start.Ticks) / upper / 10000);

            Assert.Less(tpercall, 20);
        }
        public void TestSimpleInterfacePerf()
        {
            var       start = DateTime.Now;
            const int upper = 10;

            for (var i = 0; i < upper; i++)
            {
                CrossDomainCompiler.Call(@"test\SimpleInterfaceImpl.cs", @"test\SimpleInterface.json",
                                         typeof(SimpleInterface), "CallMe");
            }
            var end      = DateTime.Now;
            var tpercall = ((end.Ticks - start.Ticks) / upper / 10000);

            Assert.Less(tpercall, 1000);
        }
Esempio n. 10
0
        /// <summary>
        /// 创建新报表
        /// </summary>
        /// <returns>新报表信息</returns>
        protected override ReportTaskResult Create()
        {
            //ReportTaskResult result;
            Log.InfoFormat("开始生成【{0}】", ReportInfo.Name);
            string filePath = Path.GetDirectoryName(reportInfo.FullName);

            if (!Directory.Exists(filePath))
            {
                if (!DirectoryHelper.CreateDirectory(filePath))
                {
                    Log.Error(string.Format("创建路径{0},失败", filePath));
                    return(CreateTaskResult(Result.Failed));
                }
            }

            if (File.Exists(ReportInfo.FullName))
            {
                if (!DeleteOldFile(reportInfo))
                {
                    Log.Info(string.Format("删除已有{0}失败,本次不生成新文件", reportInfo.FullName));
                    return(CreateTaskResult(Result.Failed));
                }
            }
            Log.Debug("创建目录成功");
            foreach (var template in ReportGroup.Templates)
            {
                TemplateHandlerPrams para = this.GetHandlerPara(template);
                var cp = new object[] { para };
                try
                {
                    string templateHandleRootDirPath = Path.GetFullPath(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, TemplateHandleRootDirPath));
                    string dependPath         = Path.GetFullPath(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, DependPath));
                    string templateHandlePath = GetTemplateHandlePath(templateHandleRootDirPath, template.HandleName);
                    Log.Debug("开始写文件");
                    CrossDomainCompiler.Call(templateHandlePath, dependPath, typeof(TemplateHandleBase), "WriteFile", ref cp);
                    Log.Debug("写文件结束");
                }
                catch (Exception e)
                {
                    Log.Error(string.Format("{0}生成失败", ReportInfo.Name), e);
                    DeleteWrongReport(this.fileFullName);
                    return(CreateTaskResult(Result.Failed));
                }
            }

            Log.InfoFormat("生成【{0}】成功", ReportInfo.Name);
            return(CreateTaskResult(Result.Successful));
        }
Esempio n. 11
0
 public void TestLoadAndCall()
 {
     CrossDomainCompiler.LoadScript(@"test\SimpleInterface.json", @"test");
     CrossDomainCompiler.Call(@"test", typeof(SimpleInterface), "ImplWithConstructor", "CallMe");
 }
Esempio n. 12
0
 public void TestLoadCompilerNotFoundCauseNotLoad()
 {
     CrossDomainCompiler.Call(@"test", typeof(SimpleInterface), "ImplWithConstructor", "CallMe");
 }
 public void TestCompileErrorException()
 {
     CrossDomainCompiler.Call(@"test\error\CompileError.cs", @"test\SimpleInterface.json",
                              typeof(SimpleInterface), "CallMe");
 }
 public void TestSimpleInterface()
 {
     CrossDomainCompiler.Call(@"test\SimpleInterfaceImpl.cs", @"test\SimpleInterface.json",
                              typeof(SimpleInterface), "CallMe");
 }
 public void TestArgumentException()
 {
     CrossDomainCompiler.Call(@"test\error\NoImplementsError.cs", @"test\SimpleInterface.json",
                              typeof(String), "CallMe");
 }
 public void TestNoImplementsError()
 {
     CrossDomainCompiler.Call(@"test\error\NoImplementsError.cs", @"test\SimpleInterface.json",
                              typeof(SimpleInterface), "CallMe");
 }
Esempio n. 17
0
        private SensorAcqResult RequestGprsSensor(Sensor si, IDtuConnection conn, int timeout)
        {
            var r = new SensorAcqResult
            {
                DtuCode   = conn.DtuID,
                Sensor    = si,
                Request   = null,
                Response  = null,
                Data      = null,
                ErrorCode = (int)Errors.ERR_DEFAULT
            };

            this.SendSensorCollectMsg(CollectState.Request, r);
            var senadapter = this._adapterManager.GetAdapter(si.ProtocolType);

            //var senadapter = _adapterManager.GetSensorAdapter(si.ProtocolType);
            if (senadapter == null)
            {
                return(this.CreateAcqResult(conn.DtuID, si, (int)Errors.ERR_UNKNOW_PROTOCOL, "Sensor has no ProtocolCode"));
            }

            try
            {
                //senadapter.Request(ref r);
                var      mp = new object[] { r };
                object[] cp = null;
                CrossDomainCompiler.Call(senadapter.ScriptPath, typeof(ISensorAdapter), senadapter.ClassName, "Request", ref cp, ref mp);
                r = mp[0] as SensorAcqResult;
            }
            catch (Exception ex)
            {
                log.ErrorFormat("dtu{0} sensor:{1} create cmd error {2}", conn.DtuID, si.SensorID, ex.Message);
                return(this.CreateAcqResult(conn.DtuID, si, (int)Errors.ERR_COMPILED, "internal error: SensorAdapter ERROR"));
            }
            if (r == null)
            {
                return(this.CreateAcqResult(conn.DtuID, si, (int)Errors.ERR_CREATE_CMD, "create cmd error: SensorAdapter ERROR"));
            }
            r.RequestTime = DateTime.Now;
            if (r.ErrorCode != (int)Errors.SUCCESS)
            {
                return(CreateAcqResult(conn.DtuID, si, r.ErrorCode, "Sensor has no SensorAdapter"));
            }
            // send
            if (r.ErrorCode == (int)Errors.SUCCESS && r.Request != null)
            {
                DtuMsg msg = conn.Ssend(r.Request, timeout);
                if (msg == null)
                {
                    return(this.CreateAcqResult(conn.DtuID, si, (int)Errors.ERR_NULL_RECEIVED_DATA, "Receive buff is null !"));
                }
                r.ResponseTime = msg.Refreshtime; // 若结果错误, 该时间无意义。
                // Parse
                if (msg.IsOK())
                {
                    try
                    {
                        r.Response = msg.Databuffer;
                        if (r.Response != null)
                        {
                            //senadapter.ParseResult(ref r);
                            var      mp = new object[] { r };
                            object[] cp = null;
                            CrossDomainCompiler.Call(senadapter.ScriptPath, typeof(ISensorAdapter), senadapter.ClassName, "ParseResult", ref cp, ref mp);
                            r = mp[0] as SensorAcqResult;
                        }
                        else
                        {
                            log.ErrorFormat("sensor:{0}, error Received buff is null", r.Sensor.SensorID);
                        }
                    }
                    catch (Exception ex)
                    {
                        log.ErrorFormat("dtu:{0},s[sid:{2}-m:{3}-c:{4}] , ERR_COMPILED {1}", conn.DtuID, ex.Message, si.SensorID, si.ModuleNo, si.ChannelNo);
                        return(this.CreateAcqResult(conn.DtuID, si, (int)Errors.ERR_COMPILED, "internal error: COMPILED ERROR"));
                    }
                    if (r == null)
                    {
                        return(this.CreateAcqResult(conn.DtuID, si, (int)Errors.ERR_DATA_PARSEFAILED, "internal error: SensorAdapter ERROR"));
                    }

                    r.ErrorMsg = r.ErrorCode == (int)Errors.SUCCESS ? "OK!" : ValueHelper.CreateJsonResultStr(si.SensorID, EnumHelper.GetDescription((Errors)r.ErrorCode));
                }
                else
                {
                    r.ErrorCode = msg.ErrorCode;
                    r.ErrorMsg  = msg.ErrorMsg;
                }
                r.Elapsed = msg.Elapsed;
            }
            else
            {
                if (r.ErrorCode == (int)Errors.ERR_DEFAULT)
                {
                    r.ErrorCode = (int)Errors.ERR_UNKNOW;
                }
                r.ErrorMsg = "create cmd error";
            }
            if (r.ErrorCode != (int)Errors.SUCCESS)
            {
                r.Data = new SensorErrorData(r.Sensor.SensorID, r.ErrorCode);
            }
            this.SendSensorCollectMsg(CollectState.Response, r);
            return(r);
        }
 public void TestFileNotFoundException()
 {
     CrossDomainCompiler.Call(@"test\error\NotExist.cs", @"test\SimpleInterface.json",
                              typeof(SimpleInterface), "CallMe");
 }