Ejemplo n.º 1
0
        public static APIResult <T> GetAPIProtobuf <T>(string url, object request)
        {
            try
            {
                url = url + "?__sertype=" + SerType.protobuf.ToString();
                HttpRequestEx httprequest = new HttpRequestEx();
                byte[]        buff        = null;
                if (request != null)
                {
                    using (MemoryStream ms = new MemoryStream())
                    {
                        ProtoBuf.Serializer.Serialize(ms, request);
                        buff = ms.ToArray();
                    }
                }
                var response = httprequest.DoRequest(url, buff);

                if (response.Successed)
                {
                    using (MemoryStream ms = new MemoryStream(response.ResponseBytes))
                    {
                        APIResult <T> result = ProtoBuf.Serializer.Deserialize <APIResult <T> >(ms);

                        return(result);
                    }
                }
                else
                {
                    return(new APIResult <T>
                    {
                        ResponseBody = default(T),
                        ResultCode = 0,
                        ResultMessage = response.ErrorMsg.Message,
                    });
                }
            }
            catch (Exception ex)
            {
                return(new APIResult <T>
                {
                    ResponseBody = default(T),
                    ResultCode = 0,
                    ResultMessage = ex.Message,
                });
            }
        }
Ejemplo n.º 2
0
        public static T GetResponse <T>(string url, object request)
        {
            HttpRequestEx httprequest = new HttpRequestEx();
            string        data        = string.Empty;

            if (request != null)
            {
                data = JsonConvert.SerializeObject(request);
            }
            Dictionary <string, string> dic = new Dictionary <string, string>();

            dic.Add("data", data);
            var response = httprequest.DoFormRequest(url, dic);

            if (response.Successed)
            {
                return(JsonConvert.DeserializeObject <T>(response.ResponseContent));
            }

            return(default(T));
        }
Ejemplo n.º 3
0
        public static APIResult <T> GetAPIResponse <T>(string url, object request)
        {
            try
            {
                HttpRequestEx httprequest = new HttpRequestEx();
                string        data        = string.Empty;

                if (request != null)
                {
                    data = JsonConvert.SerializeObject(request);
                }
                Dictionary <string, string> dic = new Dictionary <string, string>();
                dic.Add("data", data);
                var response = httprequest.DoFormRequest(url, dic);

                if (response.Successed)
                {
                    return(JsonConvert.DeserializeObject <APIResult <T> >(response.ResponseContent));
                }
                else
                {
                    return(new APIResult <T>
                    {
                        ResponseBody = default(T),
                        ResultCode = 0,
                        ResultMessage = response.ErrorMsg.Message,
                    });
                }
            }
            catch (Exception ex)
            {
                return(new APIResult <T>
                {
                    ResponseBody = default(T),
                    ResultCode = 0,
                    ResultMessage = ex.Message,
                });
            }
        }
Ejemplo n.º 4
0
        public static IEnumerable <StockQuote> GetStockDayQuote(string code, DateTime bein, DateTime end)
        {
            var      quotetblist = BigEntityTableEngine.LocalEngine.Scan <EMStockDayQuote>(TBName, QuoteIndexName, new object[] { code, bein }, new object[] { code, end }, 1, int.MaxValue).ToList();
            DateTime last        = DateTime.MinValue;

            if (quotetblist.Count() > 0)
            {
                last = quotetblist.Last().Time;
                if (last.DayOfWeek == DayOfWeek.Friday)
                {
                    last = last.AddDays(2);
                }
            }
            if (last >= end)
            {
                foreach (var item in quotetblist)
                {
                    yield return(item);
                }
            }
            else
            {
                if (code.StartsWith("6"))
                {
                    code += 1;
                }
                else
                {
                    code += 2;
                }
                var    token    = Guid.NewGuid().ToString("N");
                var    enurl    = "cMXn904uKPCJelRpEAcghwYB+4nSbdyWjKrUHW3qLbz4FB7QUU31MroUMQusDPABRPqEytkH3h3xLQDn6ej4Q5TTKDy4FKH7xE9krSqGDCSNzATn2VqYX6KPuyKt4rpzUY5EKBZ1gsO/CQRe4u8hU799cUo5UIac/jDtZTQQ6t0=";
                string url      = string.Format(new LJC.FrameWork.Comm.EncryHelper().Decrypto(enurl), token, code, DateTimeHelper.GetTimeStamp());
                byte[] data     = null;
                var    respjson = new HttpRequestEx().DoRequest(url, data);
                respjson.ResponseContent = Encoding.UTF8.GetString(respjson.ResponseBytes);
                var resp = JsonUtil <EMDayQuoteResponse> .Deserialize(respjson.ResponseContent.Substring(respjson.ResponseContent.IndexOf('(') + 1).TrimEnd(')'));

                if (resp.stats)
                {
                    List <EMStockDayQuote> insertlist = new List <EMStockDayQuote>();
                    foreach (var s in resp.data)
                    {
                        var arr   = s.Split(',');
                        var quote = new EMStockDayQuote
                        {
                            Time       = DateTime.Parse(arr[0]).Date,
                            Open       = ConvertPrice(arr[1]),
                            Close      = ConvertPrice(arr[2]),
                            High       = ConvertPrice(arr[3]),
                            Low        = ConvertPrice(arr[4]),
                            Volumne    = ConvertPrice(arr[5]),
                            Amount     = ConvertPrice(arr[6]),
                            ChangeRate = ConvertPrice(arr[7]),
                            InnerCode  = resp.code,
                        };
                        quote.Key = resp.code + "_" + quote.Time.ToString("yyyyMMdd");

                        if (quote.Time == DateTime.Now.Date)
                        {
                            continue;
                        }

                        if (quote.Time > last)
                        {
                            insertlist.Add(quote);
                        }

                        if (quote.Time >= bein && quote.Time <= end)
                        {
                            yield return(quote);
                        }
                    }

                    if (DateTime.Now.Date >= bein && DateTime.Now.Date <= end && resp.info != null)
                    {
                        yield return(new StockQuote
                        {
                            Close = ConvertPrice(resp.info.c),
                            High = ConvertPrice(resp.info.h),
                            Open = ConvertPrice(resp.info.o),
                            Low = ConvertPrice(resp.info.l),
                            Volumne = ConvertPrice(resp.info.v),
                            Amount = ConvertPrice(resp.info.a),
                            Time = DateTime.Parse(resp.info.time),
                            InnerCode = resp.code
                        });
                    }

                    if (insertlist.Count > 0)
                    {
                        BigEntityTableEngine.LocalEngine.InsertBatch(TBName, insertlist);
                    }
                }
            }
        }
Ejemplo n.º 5
0
        static void Main(string[] args)
        {
            LJC.FrameWork.Comm.HttpRequestEx httpreq = new HttpRequestEx();
            httpreq.Accept         = "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3";
            httpreq.AcceptLanguage = "zh-CN,zh;q=0.9";

            httpreq.UserAgent = "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.142 Safari/537.36";
            var resp = httpreq.DoRequest("https://hippo.gf.com.cn/?source=STORE&needLoginTrade=true#StockTrade", string.Empty);

            MySession server = new MySession();

            server.StartServer();

            Console.Read();

            //foreach (var item in new HeapSortTool<int>(new[] { 100, 2, 4, 5, 1, 3, 6, 9, 7, 8, 0, 4 }).Sort())
            //{
            //    Console.Write(item + " ");
            //}

            //Console.Read();
            //return;
            List <string> names = new List <string>();

            for (int ii = 0; ii < 100000; ii++)
            {
                names.Add("name" + ii);
            }
            SortTool <string> ss = new HeapSortTool <string>(names);

            DateTime time = DateTime.Now;
            //names= names.OrderBy(p => p).ToList();
            var results = ss.Sort();

            Console.WriteLine("用时:" + DateTime.Now.Subtract(time).TotalMilliseconds + ",比较次数:" + ss.CompareCount + ",置换次数:" + ss.ExchangeCount);
            foreach (var item in results)
            {
                Console.WriteLine(item);
                Thread.Sleep(100);
            }
            Console.Read();
            return;


            TestLocaldb();
            TestLocaldbRead();

            ShellUtil.CallShell(@"E:\Work\learn\Git\Ljc.JFrameWork\lib\JavaService-2.0.10.64\install.bat", null);
            return;

            int cnt = 0;

            while ((cnt++) < 3)
            {
                long l1 = Environment.TickCount & long.MaxValue;
                for (int ik = 0; ik < 10000; ik++)
                {
                    var info = LJC.FrameWork.SOA.ESBClient.DoSOARequest2 <GetPersonResponse>(1000, 1, new GetPersonRequest
                    {
                        Id = 9999
                    });
                }

                long l2 = Environment.TickCount & long.MaxValue;

                Console.WriteLine(l2 - l1);
            }

            Console.Read();

            return;

            int ix = 0;

            while (true)
            {
                var msgtxt = @"据了解,群众提出的意见主要集中在单身申请家庭年龄、离婚限制年限、住房转出记录、东西城房源以及能否落户、入学等方面。
  制定政策引导单身青年先租房
  一是关于单身申请年龄。有群众反映30岁年龄限制过高,同时也有群众赞成,认为共有产权住房应优先保障家庭结构稳定且人口较多的家庭。不满30周岁单身家庭可“先租后买”,形成梯度消费。据此,市住建委表示下一步,将制定支持政策,引导单身青年通过租房方式解决住房困难问题,实现有效衔接。
  “无住房转出记录”将明确为“在本市无住房转出记录”
  二是关于离婚、有住房转出记录人员限制申请。对于离婚人员申请问题,市住建委已在《办法》中明确仅限制“有住房家庭夫妻离异后单独提出申请”的情形,对离婚前家庭成员无住房或再婚家庭,不受此限制。
  对于要求无住房转出记录,目的是聚焦无房刚需家庭首次购房需求,符合回归自住属性、杜绝投资投机需求。同时,采纳部分群众提出应将“无住房转出记录”明确为“在本市无住房转出记录”的意见建议,在《办法》中予以修改。";

                var enbytes       = LJC.FrameWork.EntityBuf.EntityBufCore.Serialize(msgtxt, false);
                var comparebytes  = LJC.FrameWork.Comm.GZip.Compress(enbytes);
                var obytest       = System.Text.Encoding.UTF8.GetBytes(msgtxt);
                var comparebytes2 = LJC.FrameWork.Comm.GZip.Compress(obytest);

                var str = LJC.FrameWork.SOA.ESBClient.DoSOARequest2 <string>(100, 100, msgtxt + (ix++));
                Console.WriteLine(str);

                Thread.Sleep(1000);
            }
            Console.Read();


            LJC.FrameWork.SocketApplication.SocketEasyUDP.Server.SessionServer serverbase = new LJC.FrameWork.SocketApplication.SocketEasyUDP.Server.SessionServer(19000);
            serverbase.StartServer();

            Console.WriteLine("服务启动...");

            Console.Read();

            var list = LJC.FrameWork.Data.QuickDataBase.DataContextMoudelFactory <RunConfig> .GetDataContext().ExecuteList();

            var newrunconfig = list.FirstOrDefault();

            newrunconfig.ID = 0;
            LJC.FrameWork.Data.QuickDataBase.DataContextMoudelFactory <RunConfig> .GetDataContext(newrunconfig).Add();

            var list2 = LJC.FrameWork.Data.QuickDataBase.DataContextMoudelFactory <RunConfig> .GetDataContext().ExecuteList();

            newrunconfig.UserID = "123456";
            LJC.FrameWork.Data.QuickDataBase.DataContextMoudelFactory <RunConfig> .GetDataContext(newrunconfig).Update();

            list2 = LJC.FrameWork.Data.QuickDataBase.DataContextMoudelFactory <RunConfig> .GetDataContext().ExecuteList();

            LJC.FrameWork.Data.QuickDataBase.DataContextMoudelFactory <RunConfig> .GetDataContext(new RunConfig { ID = list2.Last().ID }).Del();

            list2 = LJC.FrameWork.Data.QuickDataBase.DataContextMoudelFactory <RunConfig> .GetDataContext().ExecuteList();

            Console.Read();
            return;

            ThreadPool.SetMinThreads(100, 100);



            //TestGZIP();
            //TestMs();

            //Console.Read();
            //return;

            var client = LJC.FrameWork.Redis.RedisManager.GetClient("Host_Redis");

            client.Set("name", "ljc123456asdfasdfdsaf");

            int i = 0;

            System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch();
            sw.Restart();
            while (i++ < 100000)
            {
                var s = client.Get <string>("name");
            }

            sw.Stop();

            Console.WriteLine("取到数据,用时ms:" + sw.ElapsedMilliseconds);

            Console.Read();
        }