Exemplo n.º 1
0
        public override SimDirectiveResult Process(string cmdResult)
        {
            if (!isEnd(cmdResult))
            {
                return(new SimDirectiveResult(false, "指令未结束"));
            }

            var arr = cmdResult.Split("\r\n".ToArray(), StringSplitOptions.RemoveEmptyEntries);

            if (arr.Length <= 2)
            {
                return(new SimDirectiveResult(false, "指令返回结果未能解析"));
            }
            var ret = arr.FirstOrDefault(each => each.IndexOf("+CENG: 0", StringComparison.Ordinal) == 0);

            Debug.WriteLine(ret);
            if (string.IsNullOrEmpty(ret))
            {
                return(new SimDirectiveResult(false, "指令解析失败"));
            }

            if (arr[0] != DirectiveText)
            {
                return(new SimDirectiveResult(false, "指令不匹配"));
            }

            var cnet = new CnetScan().Resovlex(ret);

            Debug.WriteLine(cnet.Cellid + "," + cnet.Lac);


            if (Array.IndexOf(arr, "OK") != -1)
            {
                return(new SimDirectiveResult(true, true, cnet));
            }
            else
            {
                return(new SimDirectiveResult(true, false));
            }
        }
Exemplo n.º 2
0
        private static async Task SendByHttp(string url, CnetScan cnetScans, Action <string> cb)
        {
            using (HttpClient client = new HttpClient())
            {
                try
                {
                    var uri = new Uri($"http://{Config.SERVER_ADDR}:{Config.SERVER_PORT}/api/sim/location?mcc={cnetScans.MCC}&mnc={cnetScans.MNC}&lac={cnetScans.Lac}&ci={cnetScans.Cellid}&deviceid={Common.Utility.Common.GetUniqueId()}");
                    HttpResponseMessage response = await client.GetAsync(uri);

                    if (response.EnsureSuccessStatusCode().StatusCode.ToString().ToLower() == "ok")
                    {
                        string responseBody = await response.Content.ReadAsStringAsync();

                        cb?.Invoke(responseBody);
                    }
                }
                catch (HttpRequestException ex)
                {
                    LogFactory.Create().Info(ex.Message);
                }
            }
        }