예제 #1
0
        private dynamic dispatchBaseMethod(BaseMethod method, dynamic args)
        {
            switch (method)
            {
            case BaseMethod.init:
                if (args.path == null && args.settings == null)
                {
                    return(this._init());
                }
                if (args.path == null && args.settings != null)
                {
                    return(this._init(parseConfig(args.settings)));
                }
                if (args.path != null && args.settings == null)
                {
                    return(this._init((string)args.path));
                }

                return(this._init((string)args.path, parseConfig(args.settings)));

            case BaseMethod.dispose:
                return(this._dispose());

            case BaseMethod.get_config:
                return(this._getConfig());

            case BaseMethod.test:
                return(this._test());

            default:
                throw new InvalidOperationException();
            }
        }
 public async Task PublishAsync(BaseSubscription subscription, BaseMethod method)
 {
     await _hubContext
     .Clients
     .Group(subscription.GetSubscriptionString())
     .SendCoreAsync(method.GetName(), method.GetArgs());
 }
예제 #3
0
        public void ExpandedMD(object sender)
        {
            var         a   = this;
            DataGridRow row = BaseMethod.FindVisualParent <DataGridRow>(sender as Expander);

            row.DetailsVisibility = System.Windows.Visibility.Visible;
        }
 public override int GetHashCode()
 {
     unchecked
     {
         return(((BaseMethod != null ? BaseMethod.GetHashCode() : 0) * 397) ^ (GenericTypes != null ? GenericTypes.GetHashCode() : 0));
     }
 }
 public async Task PublishAsync(string connectionId, BaseMethod method)
 {
     await _hubContext
     .Clients
     .Client(connectionId)
     .SendCoreAsync(method.GetName(), method.GetArgs());
 }
예제 #6
0
 /// <summary>
 /// 从基本方法信息的实例中获取所有Action标记并为Attributes属性赋值
 /// </summary>
 private void SetActionAttributes()
 {
     if (BaseMethod != null)
     {
         Attributes =
             BaseMethod.GetCustomAttributes(typeof(AttributeBase), true) as AttributeBase[];
     }
 }
        protected override void Invoke(Func <TTarget, Func <TResult>, TResult> action, IInvocation invocation)
        {
            var baseInvoker = new BaseMethod {
                Target = (TTarget)invocation.Proxy, Method = baseMethod
            };

            invocation.ReturnValue = action(baseInvoker.Target, baseInvoker.Invoke);
        }
        protected override void Invoke(Action <TTarget, Action> action, IInvocation invocation)
        {
            var baseInvoker = new BaseMethod {
                Target = (TTarget)invocation.Proxy, Method = baseMethod
            };

            action(baseInvoker.Target, baseInvoker.Invoke);
        }
예제 #9
0
        /// <summary>
        /// 执行
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="method"></param>
        /// <returns></returns>
        /// <exception cref="MethodValidationException"></exception>
        /// <exception cref="NotSupportedException">Method 的 ClientSetupType 对应的类型,没有导出为 IClientSetup </exception>
        public async Task <T> Execute <T>(BaseMethod <T> method)
        {
            if (method == null)
            {
                throw new ArgumentNullException("method");
            }

            if (!this.SetupDic.ContainsKey(method.ClientSetupType))
            {
                throw new NotSupportedException(string.Format("{0} not Export as IClient", method.ClientSetupType.FullName));
            }

            if (!IsInitilized)
            {
                throw new Exception("ApiClient must Init befor use it.");
            }

            //TODO 参数验证
            //var results = method.Validate();
            //if (!results.IsValid) {
            //    var msg = string.Join(";", results.Select(m => m.Message));
            //    this.DealException(method, ErrorTypes.ParameterError, new MethodValidationException(results), msg);
            //    return default(T);
            //}

            var setup = this.SetupDic[method.ClientSetupType];

            if (!setup.IsValid)
            {
                //验证配置
                this.DealException(method, ErrorTypes.SetupError, new ClientSetupException(setup));
                return(default(T));
            }

            try {
                var data = await method.Execute(Option, setup);

                //如果方法设置允许缓存,则保存到缓存
                if (method.AllowCache)
                {
                    await ApiClientCacheProvider.Default.Store(method, data);
                }
                return(data);
            } catch (HttpRequestException ex) {
                this.DealException(method, ErrorTypes.Unknow, ex);
            } catch (ParseException ex) {
                this.DealException(method, ErrorTypes.ParseError, ex);
            } catch (MethodRequestException ex) {
                this.DealException(method, ex.ErrorType, ex);
            } catch (ContentWithErrorException ex) {
                this.DealException(method, ErrorTypes.ResponsedWithErrorInfo, ex);
            } catch (NetworkException ex) {
                this.DealException(method, ErrorTypes.Network, ex);
            } catch (Exception ex) {
                this.DealException(method, ErrorTypes.Unknow, ex);
            }
            return(default(T));
        }
예제 #10
0
 public string GetUrl(BaseMethod mth, bool useSandbox)
 {
     if (useSandbox)
     {
         return($"{this.SandboxBaseUri}/{mth.Module}");
     }
     else
     {
         return($"{this.BaseUri}/{mth.Module}");
     }
 }
예제 #11
0
        /// <summary>
        /// 项目扣分
        /// </summary>
        /// <param name="kch">考车号</param>
        /// <param name="xmbh">项目编号,包含项目编号和错误编号,用@分隔</param>
        /// <param name="time">时间</param>
        /// <returns></returns>
        private bool HandleM17C53(int kch, string xmbh, string time)
        {
            string errorMsg = string.Empty;

            string[] strArray = BaseMethod.SplitString(xmbh, BaseDefine.SPLIT_CHAR_AT, out errorMsg);
            if (!string.IsNullOrEmpty(errorMsg) || strArray.Length != 2)
            {
                Log.GetLogger().ErrorFormat("17C53 接口存在错误,{0}", errorMsg);
                return(false);
            }
            string strXmCode     = strArray[0];
            string strErrrorCode = strArray[1];
            int    xmCode        = string.IsNullOrEmpty(strXmCode) ? 0 : int.Parse(strXmCode);

            int kskm = BaseMethod.INIGetIntValue(BaseDefine.CONFIG_FILE_PATH_ENV, BaseDefine.CONFIG_SECTION_CONFIG,
                                                 BaseDefine.CONFIG_KEY_KSKM, 0); //考试科目
            string xmName = string.Empty;                                        //项目名称

            if (BaseDefine.CONFIG_VALUE_KSKM_3 == kskm)                          //科目三
            {
                xmName = GetKM3Name(xmCode);
            }
            else  //科目二
            {
                xmName = GetKM2Name(xmCode);
            }

            //扣分类型、扣除分数
            if (!m_dicJudgeRules.ContainsKey(strErrrorCode))
            {
                Log.GetLogger().ErrorFormat("数据库扣分规则表中不存在错误编号为 {0} 的记录,请检查配置。", strErrrorCode);
                return(false);
            }
            string kflx = m_dicJudgeRules[strErrrorCode].JudgementType;
            int    kcfs = m_dicJudgeRules[strErrrorCode].Points;

            if (!m_dicExamProcedures.ContainsKey(kch))
            {
                Log.GetLogger().ErrorFormat("m_dicExamProcedures 字典找不到考车号 : {0}", kch);
                return(false);
            }
            ExamProcedure examProcedure = m_dicExamProcedures[kch];

            if (!examProcedure.Handle17C53(xmName, kflx, kcfs))
            {
                Log.GetLogger().ErrorFormat("examProcedure.Handle17C53 failed, kch={0}", kch);
                return(false);
            }

            Log.GetLogger().InfoFormat("HandleM17C53 end, kch={0}, xmName={1}, kflx={2}, kcfs={3}", kch, xmName, kflx, kcfs);
            return(true);
        }
예제 #12
0
 private void DealException(BaseMethod method, ErrorTypes type, Exception ex, string msg = null)
 {
     if (OnMessage != null)
     {
         OnMessage.Invoke(method, new MessageArgs()
         {
             ErrorType = type,
             Message   = msg ?? ex.GetBaseException().Message
         });
     }
     method.ErrorType = type;
     method.ErrorMsg  = msg ?? ex.GetBaseException().Message;
 }
예제 #13
0
파일: GoodsSet.cs 프로젝트: 0455YYB/WMS-2.0
        private GoodsSet()
        {
            InitializeComponent();
            string selectUnit     = "select code,name from unit where status=0 ";
            string selectType     = "select code,name from type where status=0";
            string selectSupplier = "select code,name from supplier where status=0";

            SetUnable();
            LoadUnit(CB_unit, selectUnit);
            LoadUnit(CB_type, selectType);
            LoadUnit(CB_supplier, selectSupplier);
            BaseMethod.LoadStop(this.CB_stop);
            LoadDGV_goods();
        }
예제 #14
0
        private void QHThreadProc(object obj)
        {
            XmInfo xmInfo = (XmInfo)obj;

            int kch    = xmInfo.Kch;
            int xmCode = xmInfo.XmCode;

            string section   = string.Format("{0}{1}", BaseDefine.CONFIG_SECTION_Q, xmCode);
            int    sleepTime = BaseMethod.INIGetIntValue(BaseDefine.CONFIG_FILE_PATH_ZZIPChannel, section,
                                                         BaseDefine.CONFIG_KEY_TIME, 2000);

            System.Threading.Thread.Sleep(sleepTime);

            HandleM17C52(kch, 1);
        }
예제 #15
0
        public async Task Store <T>(BaseMethod <T> mth, T result)
        {
            if (result == null)
            {
                return;
            }

            var str = JsonConvert.SerializeObject(result);

            var folder = await FileSystem.Current.LocalStorage.CreateFolderAsync("ApiCache", CreationCollisionOption.OpenIfExists);

            var key  = this.GetKey(mth);
            var file = await folder.CreateFileAsync(key, CreationCollisionOption.ReplaceExisting);

            await file.WriteAllTextAsync(str);
        }
예제 #16
0
        /// <summary>
        /// Initializes the RPCDetectorCore.
        /// </summary>
        public static void Init(Harmony harmony, RPCDetectorPlugin instance)
        {
            instance.m_Logger.LogInformation("Loading RPCDetectorCore...");
            Plugin = instance;
            Logger = new RPCLogger();
            Dictionary <MethodInfo, MethodInfo> patchMappings = new Dictionary <MethodInfo, MethodInfo>();

            foreach (MethodInfo patchMethod in typeof(RPCDetectorCore).GetMethods(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static).Where(x => Attribute.IsDefined(x, typeof(MPatch))))
            {
                var patchParameters = patchMethod.GetParameters().ToList();

                patchParameters.RemoveAll(x => x.Name.StartsWith("__"));

                foreach (MethodInfo BaseMethod in typeof(SteamChannel).GetMethods(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.Instance))
                {
                    var baseParameters = BaseMethod.GetParameters();
                    if (patchMethod.Name.Equals(BaseMethod.Name, StringComparison.InvariantCultureIgnoreCase) && patchParameters.Count == baseParameters.Length)
                    {
                        bool equal = true;
                        for (int i = 0; i < baseParameters.Length; i++)
                        {
                            if (patchParameters[i].ParameterType != baseParameters[i].ParameterType)
                            {
                                equal = false;
                            }
                        }

                        if (equal && !patchMappings.ContainsKey(patchMethod))
                        {
                            patchMappings.Add(patchMethod, BaseMethod);
                        }
                    }
                }
            }

            foreach (var patchMapping in patchMappings)
            {
                harmony.CreateProcessor(patchMapping.Value)
                .AddPrefix(patchMapping.Key)
                .Patch();
            }
            lock (Logger)
                Logger.CallReceived += Logger_CallReceived;
            Plugin.m_Logger.Log(LogLevel.Information, "RPCDetectorCore loaded; Created {0} patches.", patchMappings.Count);
        }
        public MethodMetadata MapUp(BaseMethod model)
        {
            MethodMetadata methodModel = new MethodMetadata();

            methodModel.Name      = model.Name;
            methodModel.Extension = model.Extension;
            Type         type = model.GetType();
            PropertyInfo genericArgumentsProperty = type.GetProperty("GenericArguments",
                                                                     BindingFlags.Instance | BindingFlags.Public | BindingFlags.DeclaredOnly);

            if (genericArgumentsProperty?.GetValue(model) != null)
            {
                List <BaseType> genericArguments =
                    (List <BaseType>)Helper.ConvertList(typeof(BaseType),
                                                        (IList)genericArgumentsProperty?.GetValue(model));
                methodModel.GenericArguments =
                    genericArguments.Select(g => TypeMapper.EmitType(g)).ToList();
            }

            methodModel.Modifiers = model.Modifiers;

            PropertyInfo parametersProperty = type.GetProperty("Parameters",
                                                               BindingFlags.Instance | BindingFlags.Public | BindingFlags.DeclaredOnly);

            if (parametersProperty?.GetValue(model) != null)
            {
                List <BaseParameter> parameters =
                    (List <BaseParameter>)Helper.ConvertList(typeof(BaseParameter),
                                                             (IList)parametersProperty?.GetValue(model));

                methodModel.Parameters = parameters
                                         .Select(p => new ParameterMapper().MapUp(p)).ToList();
            }

            PropertyInfo returnTypeProperty = type.GetProperty("ReturnType",
                                                               BindingFlags.Instance | BindingFlags.Public | BindingFlags.DeclaredOnly);
            BaseType returnType = (BaseType)returnTypeProperty?.GetValue(model);

            if (returnType != null)
            {
                methodModel.ReturnType = TypeMapper.EmitType(returnType);
            }
            return(methodModel);
        }
예제 #18
0
        /// <summary>
        /// 考试完成
        /// </summary>
        /// <param name="kch">考车号</param>
        /// <param name="kscj">考试成绩</param>
        /// <returns></returns>
        private bool HandleM17C56(int kch, int kscj)
        {
            int kshgfs = 0; //考试合格分数

            if (!m_dicExamProcedures.ContainsKey(kch))
            {
                Log.GetLogger().ErrorFormat("HandleM17C56错误,找不到考车 {0}", kch);
                return(false);
            }
            ExamProcedure examPorcedure = m_dicExamProcedures[kch];

            int kskm = BaseMethod.INIGetIntValue(BaseDefine.CONFIG_FILE_PATH_ENV, BaseDefine.CONFIG_SECTION_CONFIG,
                                                 BaseDefine.CONFIG_KEY_KSKM, 0); //考试科目

            if (BaseDefine.CONFIG_VALUE_KSKM_3 == kskm)                          //科目三
            {
                kshgfs = BaseDefine.CONFIG_VALUE_KSHGFS_3;
            }
            else  //科目二
            {
                kshgfs = BaseDefine.CONFIG_VALUE_KSHGFS_2;
            }

            bool bPass = (kscj >= kshgfs) ? true : false;

            examPorcedure.Handle17C56(bPass);

            //try
            //{
            //    if (kscj >= kshgfs) //考试合格
            //    {
            //        BaseMethod.TF17C56(kch, 1, kscj);
            //    }
            //}
            //catch (Exception e)
            //{
            //    Log.GetLogger().ErrorFormat("TF17C56 catch an error : {0}, 考车号={1}, 科目{2}, 考试成绩={3}", e.Message,
            //        kch, kskm, kscj);
            //    return false;
            //}

            Log.GetLogger().InfoFormat("TF17C56 end, 考车号={0}, 科目{1}, 考试成绩={2}", kch, kskm, kscj);
            return(true);
        }
예제 #19
0
        //设置串口参数
        public override void SetCom(ComParam param)
        {
            if (string.IsNullOrEmpty(param.Com) || param.Rate <= 0)
            {
                logger.ErrorFormat("SetCom param error, portname={0}, baudrate={1}", param.Com, param.Rate);
                return;
            }

            string errorMsg = string.Empty;

            signalData = BaseMethod.SplitString(param.Pwd, ',', out errorMsg);
            if (!string.IsNullOrEmpty(errorMsg))
            {
                logger.ErrorFormat("SetCom param error, pwd={0}", param.Pwd);
                return;
            }

            com = new BekUtils.Communication.ComUtil(param.Com, param.Rate, param.DataBits);
        }
예제 #20
0
        public async Task <T> Restore <T>(BaseMethod <T> mth)
        {
            var folder = await FileSystem.Current.LocalStorage.CreateFolderAsync("ApiCache", CreationCollisionOption.OpenIfExists);

            var key = this.GetKey(mth);

            if (await folder.CheckExistsAsync(key) != ExistenceCheckResult.FileExists)
            {
                return(default(T));
            }

            var file = await folder.GetFileAsync(key);

            if (file == null)
            {
                return(default(T));
            }
            else
            {
                var str = await file.ReadAllTextAsync();

                return(JsonConvert.DeserializeObject <T>(str));
            }
        }
예제 #21
0
 public Method GetRootBaseMethod()
 {
     return(BaseMethod == null || BaseMethod.BaseMethod == null ?
            BaseMethod : BaseMethod.GetRootBaseMethod());
 }
예제 #22
0
        //采样线程函数
        private void SampleThreadProc()
        {
            while (true)
            {
                #region 连接串口
                if (!com.IsOpen)
                {
                    int nRet = com.ConnectSerialPort();
                    if (-1 == nRet)
                    {
                        logger.ErrorFormat("ConnectSerialPort faild, retry after sleep");
                        Thread.Sleep(BaseDefine.COMMON_VALUE_SLEEP_2500);
                        continue;
                    }
                    else if (-2 == nRet)
                    {
                        logger.ErrorFormat("ConnectSerialPort faild, abort sample thread");
                        sampleThread.Abort();
                        return;
                    }
                }
                #endregion

                //读 OBD 数据
                string   errorMsg = string.Empty;
                string   retStr   = string.Empty;
                int      nLen     = com.ReadSerialPort(ref retStr);
                string[] destList = BaseMethod.SplitString(retStr, '$', out errorMsg);
                if (!string.IsNullOrEmpty(errorMsg))
                {
                    logger.ErrorFormat(errorMsg);
                    Thread.Sleep(BaseDefine.COMMON_VALUE_SLEEP_200);
                    continue;
                }

                //解析 OBD 数据
                for (int i = 0; i < destList.Length; i++)
                {
                    string   tempError = string.Empty;
                    string[] dest      = BaseMethod.SplitString(destList[i], ',', out tempError);
                    if (!string.IsNullOrEmpty(tempError))
                    {
                        logger.InfoFormat("OBD 存在空数据,destList[{0}]={1}", i, destList[i]);
                        continue;
                    }

                    if (BaseDefine.DATA_TYPE_OBD_DT == dest[0])
                    {
                        if (dest.Length >= 22)
                        {
                            #region 从协议取值
                            lock (lockObj)
                            {
                                #region 安全带
                                if ("1" == dest[12])
                                {
                                    sampleData.Aqd = 1;
                                }
                                else if ("#" == dest[12])
                                {
                                    sampleData.Aqd = 9;
                                }
                                else
                                {
                                    sampleData.Aqd = 0;
                                }
                                #endregion

                                #region 脚刹
                                if ("1" == dest[7])
                                {
                                    sampleData.Js = 1;
                                }
                                else if ("#" == dest[7])
                                {
                                    sampleData.Js = 9;
                                }
                                else
                                {
                                    sampleData.Js = 0;
                                }
                                #endregion

                                #region 关门
                                if ("1" == dest[13])
                                {
                                    sampleData.Gm = 1;
                                }
                                else if ("#" == dest[13])
                                {
                                    sampleData.Gm = 9;
                                }
                                else
                                {
                                    sampleData.Gm = 0;
                                }
                                #endregion

                                #region 离合
                                if ("1" == dest[6])
                                {
                                    sampleData.Lh = 1;
                                }
                                else if ("#" == dest[6])
                                {
                                    sampleData.Lh = 9;
                                }
                                else
                                {
                                    sampleData.Lh = 0;
                                }
                                #endregion

                                #region 左转向灯
                                if ("1" == dest[14])
                                {
                                    sampleData.Zzxd = 1;
                                }
                                else if ("#" == dest[14])
                                {
                                    sampleData.Zzxd = 9;
                                }
                                else
                                {
                                    sampleData.Zzxd = 0;
                                }
                                #endregion

                                #region 右转向灯
                                if ("1" == dest[15])
                                {
                                    sampleData.Yzxd = 1;
                                }
                                else if ("#" == dest[15])
                                {
                                    sampleData.Yzxd = 9;
                                }
                                else
                                {
                                    sampleData.Yzxd = 0;
                                }
                                #endregion

                                #region 喇叭
                                if ("1" == dest[10])
                                {
                                    sampleData.Lb = 1;
                                }
                                else if ("#" == dest[10])
                                {
                                    sampleData.Lb = 9;
                                }
                                else
                                {
                                    sampleData.Lb = 0;
                                }
                                #endregion

                                #region 近光灯
                                if ("1" == dest[17])
                                {
                                    sampleData.Jgd = 1;
                                }
                                else if ("#" == dest[17])
                                {
                                    sampleData.Jgd = 9;
                                }
                                else
                                {
                                    sampleData.Jgd = 0;
                                }
                                #endregion

                                #region 远光灯
                                if ("1" == dest[18])
                                {
                                    sampleData.Ygd = 1;
                                }
                                else if ("#" == dest[18])
                                {
                                    sampleData.Ygd = 9;
                                }
                                else
                                {
                                    sampleData.Ygd = 0;
                                }
                                #endregion

                                #region 危险告警灯
                                if ("1" == dest[19])
                                {
                                    sampleData.Gjd = 1;
                                }
                                else if ("#" == dest[19])
                                {
                                    sampleData.Gjd = 9;
                                }
                                else
                                {
                                    sampleData.Gjd = 0;
                                }
                                #endregion

                                #region 雾灯
                                if ("1" == dest[20])
                                {
                                    sampleData.Wd = 1;
                                }
                                else if ("#" == dest[20])
                                {
                                    sampleData.Wd = 9;
                                }
                                else
                                {
                                    sampleData.Wd = 0;
                                }
                                #endregion

                                #region 倒车
                                if ("1" == dest[21])
                                {
                                    sampleData.Dc = 1;
                                }
                                else if ("#" == dest[21])
                                {
                                    sampleData.Dc = 9;
                                }
                                else
                                {
                                    sampleData.Dc = 0;
                                }
                                #endregion

                                #region 速度
                                if ("#" == dest[3])
                                {
                                    sampleData.Ycsd = -1;
                                }
                                else
                                {
                                    float fSd = 0;
                                    float.TryParse(dest[3], out fSd);
                                    sampleData.Ycsd = fSd;
                                }
                                #endregion

                                #region 转速
                                if ("#" == dest[2])
                                {
                                    sampleData.Zs = -1;
                                }
                                else
                                {
                                    int nZs = 0;
                                    int.TryParse(dest[2], out nZs);
                                    sampleData.Zs = nZs;
                                }
                                #endregion

                                #region 档位
                                if (BaseDefine.DATA_TYPE_DW_MN == dest[5] || BaseDefine.DATA_TYPE_DW_AN == dest[5])
                                {
                                    sampleData.Dw = (byte)DwDefine.DW_N;
                                }
                                else if (BaseDefine.DATA_TYPE_DW_M1 == dest[5] || BaseDefine.DATA_TYPE_DW_A1 == dest[5])
                                {
                                    sampleData.Dw = (byte)DwDefine.DW_1;
                                }
                                else if (BaseDefine.DATA_TYPE_DW_M2 == dest[5] || BaseDefine.DATA_TYPE_DW_A2 == dest[5])
                                {
                                    sampleData.Dw = (byte)DwDefine.DW_2;
                                }
                                else if (BaseDefine.DATA_TYPE_DW_M3 == dest[5] || BaseDefine.DATA_TYPE_DW_A3 == dest[5])
                                {
                                    sampleData.Dw = (byte)DwDefine.DW_3;
                                }
                                else if (BaseDefine.DATA_TYPE_DW_M4 == dest[5] || BaseDefine.DATA_TYPE_DW_A4 == dest[5])
                                {
                                    sampleData.Dw = (byte)DwDefine.DW_4;
                                }
                                else if (BaseDefine.DATA_TYPE_DW_M5 == dest[5] || BaseDefine.DATA_TYPE_DW_A5 == dest[5])
                                {
                                    sampleData.Dw = (byte)DwDefine.DW_5;
                                }
                                else if (BaseDefine.DATA_TYPE_DW_MR == dest[5] || BaseDefine.DATA_TYPE_DW_AR == dest[5])
                                {
                                    sampleData.Dw = (byte)DwDefine.DW_R;
                                }
                                else if (BaseDefine.DATA_TYPE_DW_AP == dest[5])
                                {
                                    sampleData.Dw = (byte)DwDefine.DW_P;
                                }
                                else if (BaseDefine.DATA_TYPE_DW_AD == dest[5])
                                {
                                    sampleData.Dw = (byte)DwDefine.DW_D;
                                }
                                else
                                {
                                    sampleData.Dw = (byte)DwDefine.DW_OTHER;
                                }
                                #endregion
                            }
                            #endregion
                        }
                    }
                    else if (BaseDefine.DATA_TYPE_OBD_INFO == dest[0])
                    {
                        logger.InfoFormat("dest[0]={0}, continue", BaseDefine.DATA_TYPE_OBD_INFO);
                        continue;
                    }
                    else if (BaseDefine.DATA_TYPE_OBD_IO == dest[0])
                    {
                        if (signalData != null && dest.Length >= signalData.Length + 1)
                        {
                            tempError = string.Empty;
                            for (int j = 0; j < signalData.Length; j++)
                            {
                                string[] tempSz = BaseMethod.SplitString(signalData[j], '@', out tempError);
                                if (tempSz != null && tempSz.Length >= 2)
                                {
                                    #region 从协议取值
                                    lock (lockObj)
                                    {
                                        if ("1" == tempSz[1])
                                        {
                                            if ("1" == tempSz[0])
                                            {
                                                tempSz[0] = "0";
                                            }
                                            else
                                            {
                                                tempSz[0] = "1";
                                            }
                                        }

                                        byte byteTemp;
                                        byte.TryParse(dest[j + 1], out byteTemp);
                                        switch (tempSz[0])
                                        {
                                        case "1":       //安全带
                                            sampleData.Aqd = byteTemp;
                                            break;

                                        case "2":       //左转向灯
                                            sampleData.Zzxd = byteTemp;
                                            break;

                                        case "3":       //右转向灯
                                            sampleData.Yzxd = byteTemp;
                                            break;

                                        case "4":       //熄火
                                            sampleData.Yzxd = byteTemp;
                                            break;

                                        case "5":       //点火
                                            sampleData.Dh = byteTemp;
                                            break;

                                        case "6":       //手刹
                                            sampleData.Ss = byteTemp;
                                            break;

                                        case "7":       //右转向灯
                                            sampleData.Yzxd = byteTemp;
                                            break;

                                        case "8":       //档位??????????????????????????????????????????
                                            sampleData.Dw = byteTemp;
                                            break;

                                        case "9":       //近光灯
                                            sampleData.Jgd = byteTemp;
                                            break;

                                        case "10":       //远光灯
                                            sampleData.Ygd = byteTemp;
                                            break;

                                        case "11":       //脚刹
                                            sampleData.Js = byteTemp;
                                            break;

                                        case "12":       //倒车
                                            sampleData.Dc = byteTemp;
                                            break;

                                        case "13":       //雾灯
                                            sampleData.Wd = byteTemp;
                                            break;

                                        case "14":       //喇叭
                                            sampleData.Lb = byteTemp;
                                            break;

                                        case "15":       //油箱
                                            sampleData.Yx = byteTemp;
                                            break;

                                        case "16":       //副刹
                                            sampleData.Fs = byteTemp;
                                            break;

                                        case "17":       //离合
                                            sampleData.Lh = byteTemp;
                                            break;

                                        case "18":       //危险告警灯
                                            sampleData.Gjd = byteTemp;
                                            break;

                                        case "19":       //示廓灯
                                            sampleData.Skd = byteTemp;
                                            break;

                                        default:
                                            break;
                                        }
                                    }
                                    #endregion
                                }
                            }
                        }
                    }
                }

                Thread.Sleep(BaseDefine.COMMON_VALUE_SLEEP_200);
            }
        }
예제 #23
0
        private void DataHandlerThreadProc()
        {
            string errorMsg = string.Empty;

            //解析车载数据
            string[] retArray = BaseMethod.SplitString(m_data, BaseDefine.SPLIT_CHAR_ASTERISK, out errorMsg);
            if (!string.IsNullOrEmpty(errorMsg))
            {
                goto END;
            }

            int nLength = retArray.Length;

            if (nLength != BaseDefine.INTERFACE_FIELD_COUNT_KM2 &&
                nLength != BaseDefine.INTERFACE_FIELD_COUNT_KM3)
            {
                errorMsg = string.Format("车载数据格式不正确,{0} 数量不对", BaseDefine.SPLIT_CHAR_ASTERISK);
                goto END;
            }

            string strKch  = retArray[1];
            int    nKch    = string.IsNullOrEmpty(strKch) ? 0 : int.Parse(strKch);   //考车号
            string strType = retArray[2];
            int    nType   = string.IsNullOrEmpty(strType) ? 0 : int.Parse(strType); //类型
            string strXmbh = retArray[5];                                            //项目编号
            string strZkzh = retArray[6];                                            //准考证号
            string strTime = retArray[7];                                            //时间

            if (!m_dicCars.ContainsKey(nKch))
            {
                Log.GetLogger().ErrorFormat("找不到考车{0},请检查配置", nKch);
                return;
            }
            Log.GetLogger().InfoFormat(
                "接收到车载接口信息,考车号={0}, 类型={1}, 项目编号={2}, 准考证号={3}, 时间={4}",
                nKch, nType, strXmbh, strZkzh, strTime);

            switch (nType)
            {
            case BaseDefine.PACK_TYPE_M17C51:       //考试开始
            {
                HandleM17C51(nKch, strZkzh);
            }
            break;

            case BaseDefine.PACK_TYPE_M17C52:       //项目开始
            {
                HandleM17C52(nKch, strZkzh, strXmbh);
            }
            break;

            case BaseDefine.PACK_TYPE_M17C53:       //扣分
            {
                HandleM17C53(nKch, strXmbh, strTime);
            }
            break;

            case BaseDefine.PACK_TYPE_M17C54:
            {
                //项目抓拍照片,这里不需要处理
            }
            break;

            case BaseDefine.PACK_TYPE_M17C55:       //项目完成
            {
                HandleM17C55(nKch, strZkzh, strXmbh);
            }
            break;

            case BaseDefine.PACK_TYPE_M17C56:       //考试完成
            {
                string score = retArray[5];         //17C56时该字段为考试成绩
                int    kscj  = string.IsNullOrEmpty(score) ? 0 : int.Parse(score);

                Log.GetLogger().InfoFormat("车载传过来的考试成绩为:{0}", kscj);

                if (kscj < 0)
                {
                    kscj = 0;
                }

                HandleM17C56(nKch, kscj);
            }
            break;

            default:
                break;
            }

END:
            {
                if (!string.IsNullOrEmpty(errorMsg))
                {
                    Log.GetLogger().ErrorFormat("处理车载数据(DataHandlerThreadProc)时产生错误,{0}", errorMsg);
                }
                else
                {
                    Log.GetLogger().InfoFormat("DataHandlerThreadProc 执行结束");
                }
            }

            return;
        }
예제 #24
0
        public void CollapsedMD(object sender)
        {
            DataGridRow row = BaseMethod.FindVisualParent <DataGridRow>(sender as Expander);

            row.DetailsVisibility = System.Windows.Visibility.Collapsed;
        }
예제 #25
0
        /// <summary>
        /// 获取考生信息
        /// </summary>
        /// <param name="zkzmbh">准考证明</param>
        /// <param name="arrayZp">身份证照片信息</param>
        /// <param name="arrayMjzp">签到照片信息</param>
        /// <returns></returns>
        private bool GetStudentInfo(string zkzmbh, ref StudentInfo studentInfo)
        {
            //获取考生照片
            Byte[] arrayZp   = null; //照片
            Byte[] arrayMjzp = null; //门禁照片,现场采集
            string sql       = string.Format("select {0},{1} from {2} where {3}='{4}'",
                                             BaseDefine.DB_FIELD_ZP,
                                             BaseDefine.DB_FIELD_MJZP,
                                             BaseDefine.DB_TABLE_STUDENTPHOTO,
                                             BaseDefine.DB_FIELD_ZKZMBH,
                                             zkzmbh);

            Log.GetLogger().DebugFormat("获取考生照片 sql : {0}", sql);
            try
            {
                DataSet ds = m_sqlDataProvider.RetriveDataSet(sql);
                if (ds != null && ds.Tables[0] != null && ds.Tables[0].Rows != null)
                {
                    try
                    {
                        arrayZp = (Byte[])ds.Tables[0].Rows[0][0];
                    }
                    catch (Exception e)
                    {
                        Log.GetLogger().InfoFormat("照片获取失败,{0}", e.Message);
                    }

                    try
                    {
                        arrayMjzp = (Byte[])ds.Tables[0].Rows[0][1];
                    }
                    catch (Exception e)
                    {
                        Log.GetLogger().InfoFormat("门禁照片获取失败,{0}", e.Message);
                    }
                }
            }
            catch (Exception e)
            {
                Log.GetLogger().ErrorFormat("查询 StudentPhoto 表发生异常: {0}, zkzmbh={1}, sql = {2}", e.Message, zkzmbh, sql);
                //return false;
            }

            Log.GetLogger().DebugFormat("HQW TEMP");

            //获取考生信息
            string kch      = string.Empty; //考车号
            string bz       = string.Empty; //备注(车牌号)
            string kscx     = string.Empty; //考试车型
            string xingming = string.Empty; //姓名
            string xb       = string.Empty; //性别
            string date     = string.Empty; //日期
            string lsh      = string.Empty; //流水号
            string sfzmbh   = string.Empty; //身份证明编号
            string jxmc     = string.Empty; //驾校名称
            string ksy1     = string.Empty; //考试员1
            string ksyyCode = string.Empty; //考试原因编号
            string ksyyDes  = string.Empty; //考试原因描述
            string drcs     = string.Empty; //当日次数

            string sqlFormat = string.Empty;
            int    dbType    = BaseMethod.INIGetIntValue(BaseDefine.CONFIG_FILE_PATH_ENV, BaseDefine.CONFIG_SECTION_CONFIG,
                                                         BaseDefine.CONFIG_KEY_SQLORACLE, 0);

            if (1 == dbType)
            {
                sqlFormat = "select {0},{1}.{2},{3},{4},{5},(Select CONVERT(varchar(100), GETDATE(), 23)) as DATE, {6},{7},{8},{9},{10},{11},{12} from {13} left join {14} on {15}={16} left join {17} on {18}={19} where {20}='{21}'";
            }
            else
            {
                sqlFormat = "select {0},{1}.{2},{3},{4},{5},to_char(sysdate,'yyyy-mm-dd') as MYDATE, {6},{7},{8},{9},{10},{11},{12} from {13} left join {14} on {15}={16} left join {17} on {18}={19} where {20}='{21}'";
            }

            sql = string.Format(
                sqlFormat,
                BaseDefine.DB_FIELD_KCH,
                BaseDefine.DB_TABLE_SYSCFG,
                BaseDefine.DB_FIELD_BZ,
                BaseDefine.DB_FIELD_KSCX,
                BaseDefine.DB_FIELD_XINGMING,
                BaseDefine.DB_FIELD_XB,
                BaseDefine.DB_FIELD_LSH,
                BaseDefine.DB_FIELD_SFZMBH,
                BaseDefine.DB_FIELD_JXMC,
                BaseDefine.DB_FIELD_KSY1,
                BaseDefine.DB_FIELD_KSYY,
                BaseDefine.DB_FIELD_ZKZMBH,
                BaseDefine.DB_FIELD_DRCS,
                BaseDefine.DB_TABLE_STUDENTINFO,
                BaseDefine.DB_TABLE_SCHOOLINFO,
                BaseDefine.DB_FIELD_DLR,
                BaseDefine.DB_FIELD_JXBH,
                BaseDefine.DB_TABLE_SYSCFG,
                BaseDefine.DB_FIELD_KCH,
                BaseDefine.DB_FIELD_XIANGMU,
                BaseDefine.DB_FIELD_ZKZMBH,
                zkzmbh
                );
            Log.GetLogger().DebugFormat("获取考生信息 sql : {0}", sql);
            try
            {
                DataSet ds = m_sqlDataProvider.RetriveDataSet(sql);
                if (ds != null && ds.Tables[0] != null && ds.Tables[0].Rows != null)
                {
                    kch      = (null == ds.Tables[0].Rows[0][0]) ? string.Empty : ds.Tables[0].Rows[0][0].ToString();
                    bz       = (null == ds.Tables[0].Rows[0][1]) ? string.Empty : ds.Tables[0].Rows[0][1].ToString();
                    kscx     = (null == ds.Tables[0].Rows[0][2]) ? string.Empty : ds.Tables[0].Rows[0][2].ToString();
                    xingming = (null == ds.Tables[0].Rows[0][3]) ? string.Empty : ds.Tables[0].Rows[0][3].ToString();
                    xb       = (null == ds.Tables[0].Rows[0][4]) ? string.Empty : ds.Tables[0].Rows[0][4].ToString();
                    date     = (null == ds.Tables[0].Rows[0][5]) ? string.Empty : ds.Tables[0].Rows[0][5].ToString();
                    lsh      = (null == ds.Tables[0].Rows[0][6]) ? string.Empty : ds.Tables[0].Rows[0][6].ToString();
                    sfzmbh   = (null == ds.Tables[0].Rows[0][7]) ? string.Empty : ds.Tables[0].Rows[0][7].ToString();
                    jxmc     = (null == ds.Tables[0].Rows[0][8]) ? string.Empty : ds.Tables[0].Rows[0][8].ToString();
                    ksy1     = (null == ds.Tables[0].Rows[0][9]) ? string.Empty : ds.Tables[0].Rows[0][9].ToString();

                    ksyyCode = (null == ds.Tables[0].Rows[0][10]) ? string.Empty : ds.Tables[0].Rows[0][10].ToString();
                    ksyyDes  = getKsyy(ksyyCode);

                    drcs = (null == ds.Tables[0].Rows[0][12]) ? string.Empty : ds.Tables[0].Rows[0][12].ToString();

                    //if (string.IsNullOrEmpty(kch) || string.IsNullOrEmpty(bz) || string.IsNullOrEmpty(kscx) || string.IsNullOrEmpty(xingming)
                    //    || string.IsNullOrEmpty(xb) || string.IsNullOrEmpty(date) || string.IsNullOrEmpty(lsh) || string.IsNullOrEmpty(sfzmbh)
                    //    || string.IsNullOrEmpty(jxmc) || string.IsNullOrEmpty(ksy1))
                    //{
                    //    Log.GetLogger().ErrorFormat("查询 StudentInfo 表值为空,sql={0}", sql);
                    //    return false;
                    //}

                    Log.GetLogger().DebugFormat("kch={0}, bz={1}, kscx={2}, xingming={3},xb={4},date={5},lsh={6},sfzmbh={7},jxmc={8},ksy1={9}, ksyyCode={10}, ksyyDes={11}, drcs={12}",
                                                kch, bz, kscx, xingming, xb, date, lsh, sfzmbh, jxmc, ksy1, ksyyCode, ksyyDes, drcs);
                }
            }
            catch (Exception e)
            {
                Log.GetLogger().ErrorFormat("查询 StudentInfo 表发生异常: {0}, zkzmbh={1}", e.Message, zkzmbh);
                return(false);
            }

            studentInfo = new StudentInfo(kch, bz, kscx, xingming, xb, date, lsh, sfzmbh, jxmc, ksy1, ksyyDes, drcs, arrayZp, arrayMjzp);

            Log.GetLogger().DebugFormat("GetStudentInfo success, zkzmbh={0}", zkzmbh);
            return(true);
        }
예제 #26
0
 private void StopSample()
 {
     BaseMethod.StopThread(sampleThread);
 }
예제 #27
0
 private string GetKey <T>(BaseMethod <T> mth)
 {
     return($"{mth.GetType().FullName}_{mth.BuildUrl("")}".ToMD5());
 }
예제 #28
0
 /// <summary>
 /// 从缓存中取数据
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <param name="method"></param>
 /// <returns></returns>
 public async Task <T> GetDataFromCache <T>(BaseMethod <T> method)
 {
     return(await ApiClientCacheProvider.Default.Restore <T>(method));
 }
예제 #29
0
 public string GetUrl(BaseMethod baseMethod, bool useSandbox)
 {
     return($"http://api.map.baidu.com/{baseMethod.Module}/v2/?ak={this.AK}&callback=_&output=json&pois=1");
 }
예제 #30
0
        private void _Start()
        {
            string absoluteUri = request.Uri.AbsolutePath;

            while (absoluteUri.IndexOf("//") >= 0)
            {
                absoluteUri = absoluteUri.Replace("//", "/");
            }

            if (absoluteUri.StartsWith("/api"))
            {
                if (!request.Headers.Contains("Authorization"))
                {
                    RespondWithJSON("Please authenticate", false, 401, new Dictionary <string, string> {
                        { "WWW-Authenticate", "Basic realm=\"CorsairLinkPlusPlus API\"" }
                    });
                    return;
                }

                currentUser = GetCurrentUser(request.Headers["Authorization"]);
                if (currentUser == null)
                {
                    RespondWithJSON("Invalid login", false, 401, new Dictionary <string, string> {
                        { "WWW-Authenticate", "Basic realm=\"CorsairLinkPlusPlus API\"" }
                    });
                    return;
                }

                if (request.HttpMethod == "OPTIONS" || request.HttpMethod == "HEAD")
                {
                    RespondWithJSON("Yep yep, no need for these");
                    return;
                }

                try
                {
                    IDevice device = RootDevice.FindDeviceByPath(absoluteUri.Substring(4));

                    if (device == null)
                    {
                        RespondWithJSON("Device not found", false, 404);
                        return;
                    }

                    if (request.HttpMethod == "POST")
                    {
                        if (currentUser.Value.readOnly)
                        {
                            RespondWithJSON("Your user is read-only", false, 403);
                            return;
                        }

                        JSONMethodCall methodCall;
                        using (StreamReader bodyReader = new StreamReader(request.Body))
                        {
                            methodCall = JsonConvert.DeserializeObject <JSONMethodCall>(bodyReader.ReadToEnd());
                        }
                        BaseMethod.Execute(methodCall.Name, device, methodCall.Params);
                        RespondWithJSON("OK");
                        return;
                    }

                    RespondWithDevice(device);
                    return;
                }
                catch (Exception e)
                {
                    try
                    {
                        RespondWithJSON(e.Message, false, 500);

                        Console.Error.WriteLine("------------------");
                        Console.Error.WriteLine("Error in HTTP");
                        Console.Error.WriteLine(e);
                        Console.Error.WriteLine("------------------");
                    }
                    catch (Exception se)
                    {
                        Console.Error.WriteLine("------------------");
                        Console.Error.WriteLine("Error in HTTP error handler");
                        Console.Error.WriteLine(se);
                        Console.Error.WriteLine("Caused by");
                        Console.Error.WriteLine(e);
                        Console.Error.WriteLine("------------------");
                    }
                    return;
                }
            }
            else
            {
                if (absoluteUri == "/" || absoluteUri == "")
                {
                    absoluteUri = "index.html";
                }
                else
                {
                    absoluteUri = absoluteUri.Substring(1);
                }

                FileInfo fileInfo = new FileInfo(Program.WEB_ROOT_ABSOLUTE + '/' + absoluteUri);

                if (!fileInfo.Exists)
                {
                    RespondWithJSON("Static content not found", false, 404);
                    return;
                }

                if (fileInfo.Attributes.HasFlag(FileAttributes.Directory))
                {
                    RespondWithJSON("Static content is a directory", false, 403);
                    return;
                }

                DirectoryInfo directory = fileInfo.Directory;
                do
                {
                    if (Program.WEB_ROOT_ABSOLUTE.Equals(directory.FullName))
                    {
                        break;
                    }
                    directory = directory.Parent;
                } while (directory != null);

                if (directory == null)
                {
                    RespondWithJSON("Nope, sorry!", false, 403);
                    return;
                }

                string mineType = MIMEAssistant.GetMIMEType(fileInfo.Extension);

                RespondWithRaw(fileInfo.OpenRead(), 200, mineType);
            }
        }