Exemplo n.º 1
0
        internal bool OneTest(string nameTest, TestRequestDataDrv request, TestResult res, Func <MsgTest> func, bool error = false)
        {
            bool            result          = true;
            TestDriverError testDriverError = null;
            MsgTest         readResult      = null;

            try
            {
                readResult = func();
                if ((!readResult.OperationResult.IsGood) && (!error))
                {
                    testDriverError = new TestDriverError(false, "{0}, {1}", nameTest, readResult.OperationResult.ErrorMsg);
                    result          = false;
                }
            }
            catch (Exception e)
            {
                testDriverError = new TestDriverError(false, "{0}, {1}", nameTest, e.GetFullMessageDisplay());
                result          = false;
            }
            if (testDriverError != null)
            {
                res.Add(testDriverError);
            }

            if (Log.Trace.IsOn(1))
            {
                var mgg = String.Format("{0}: {1}", nameTest, (result) ? readResult.Message : testDriverError.Message);
                if ((readResult.OperationResult.IsGood) || (error))
                {
                    Log.Trace.Info(1, mgg);
                }
                else
                {
                    Log.Trace.Error(1, mgg);
                }
            }
            return(result);
        }
Exemplo n.º 2
0
        public override TestResult Test(TestRequestDataDrv request)
        {
            TestResult result = new TestResult();

            var          drvSetting = request.GetDriverSetting(() => new DriverSetting());
            var          cs         = request.GetContentSetting <EmeraContentSetting>(() => new EmeraContentSetting());
            EmeraRequest emera      = new EmeraRequest(this, drvSetting, ReadTimeOutRequestMSec());

            //var sr = new Def.ShortRequest(cs.Address);

            if ((request.TestLevel == TestLevel.Ping) || (request.TestLevel == TestLevel.Search))
            {
                DateTimeUtc dateTimeUtc;
                int         timeTwoSidePathMsec;
                if (!DataBusSetting.StubData)
                {
                    var readRes = emera.TryReadDateTime(this.Channel, cs.Address, cs.Psw, TimeZoneMap.Local, out dateTimeUtc, out timeTwoSidePathMsec);
                    if (!readRes.IsGood)
                    {
                        result.Add(new TestDriverError(false, "Error Connect. {0}", readRes.ErrorMsg));
                    }
                }
            }
            else if (request.TestLevel == TestLevel.Full)
            {
                DateTimeUtc dateTimeUtcPrb = DateTimeUtc.MinValue;
                int         timeTwoSidePathMsec;
                if (!OneTest(SR.Test_DT, request, result, () =>
                {
                    var res = emera.TryReadDateTime(this.Channel, cs.Address, cs.Psw, TimeZoneMap.Local, out dateTimeUtcPrb, out timeTwoSidePathMsec);
                    return(new MsgTest(res, res.IsGood ? dateTimeUtcPrb.ToLocal().ToString() : string.Empty));
                }))
                {
                    return(result);
                }
                TimeSpan diffTime = DateTimeUtc.Now - dateTimeUtcPrb;

                string sn = string.Empty;
                if (!OneTest(SR.Test_SN, request, result, () =>
                {
                    var res = emera.TryReadSerialNumber(this.Channel, cs.Address, cs.Psw, out sn);
                    return(new MsgTest(res, res.IsGood ? sn : string.Empty));
                }))
                {
                    return(result);
                }

                string deviceConfiguration = string.Empty;
                if (!OneTest(SR.Test_SV, request, result, () =>
                {
                    var res = emera.TryReadDeviceConfiguration(this.Channel, cs.Address, cs.Psw, out deviceConfiguration, true);
                    return(new MsgTest(res, res.IsGood ? deviceConfiguration.ToString() : string.Empty));
                }))
                {
                    return(result);
                }

                /*if (!OneTest(SR.Test_Error_Req, request, result, () =>
                 * {
                 * Energy eRead;
                 * var res = emera.TryReadSlicesEnergy(this.Channel, DeviceCompOn.Default, SlicesQuery.GetEmulError(sr.Address), TypeInfo.Imp, out eRead);
                 * return new MsgTest(res, res.IsGood ? "" : "Ok");
                 * }, true)) return result;*/

                result.Message = String.Format("Сер.Номер: {0}, Временной разрыв: {1} sec, Конфигурация: {2}", sn, (int)diffTime.TotalSeconds, deviceConfiguration);
            }
            return(result);
        }