using PushInfo.Act.BLL;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Threading;
using System.Runtime.Serialization;
using System.Reflection;
using PushTest.BLL;
using PushService.Act;
using PushService.Act.BLL;
using PushPlatform.Common.Util;
using Apache.NMS;
using MG.Core.Model;
using Newtonsoft.Json.Linq;
using PushPlatform.Common.Enumerate;
using PushPlatform.Common.Mq;
using PushInfo.Core.BLL;
using PushInfo.Core.Models.QueryResults;
using PushInfo.Core.Models.Tables;

namespace PushTest
{
    class Program
    {
        static void Main(string[] args)
        {
            var field1 = "<field>501a4360-5648-45be-8aaa-935d5f6673c3</field>"; //体重
            var field2 = "<field>c7142c7b-2372-4a79-8626-6ae218e9ae0b</field>"; //身高
            using (PushPlatform.Common.NewSmsService.SmsServiceClient sms = new PushPlatform.Common.NewSmsService.SmsServiceClient())
            {
                var r = sms.AliSendCode("124", "91Trial", "SMS_213772733", "18918344035", "");
            }




            //if (!string.IsNullOrEmpty(field1) && !string.IsNullOrEmpty(field2))
            //{
            //    Double Value1;
            //    Double Value2;
            //    Double Value3;

            //    if (Double.TryParse(field1, out Value1))
            //    {
            //        if (Double.TryParse(field2, out Value2))
            //        {
            //            Value3 = Value2 * Value2;
            //            Value3 = Value1 / Value3;
            //            Value3 = Value3 * 10000;
            //            return Value3;
            //        }
            //    }
            //}
            //return 20;
            //Task.Run(() =>
            //{
            //    Thread.Sleep(1000);
            //    Console.WriteLine("test1");
            //});
            //Console.WriteLine("test2");


            //QuartzBLL.Start();

            #region 推送body截取属性测试
            //List<string> returnModel = new List<string>();
            //string test = "[afaf]你需要随访患者数[nums],病例[needvalue],测试[bage]";
            //int indexNums = 0;
            //int startIndex = test.IndexOf("[");
            //int endIndex = 0;
            //while (startIndex>-1)
            //{
            //    endIndex = test.IndexOf("]", startIndex + 1);
            //    if(endIndex>-1)
            //    {
            //        returnModel.Add(test.Substring(startIndex+1, endIndex- startIndex - 1));
            //    }
            //    startIndex = test.IndexOf("[",endIndex);
            //    if(++indexNums>100)  //防止陷入死循环
            //    {
            //        break;
            //    }
            //}
            #endregion

            #region 线程测试
            //var result = test();
            //var result2 = test2();
            ////Console.WriteLine(result.Result);
            //Task.Run(() => { Thread.Sleep(1000); Console.WriteLine("task"); });
            //Task.WaitAll(new Task[] { result2 });
            ////result.Wait();
            ////Thread.Sleep(1600);
            //Console.WriteLine("主线程");
            #endregion

            //OutProcessTaskBLL.SendPushOfProCfg("123b854b-0f39-488f-a2e7-7cfef0719b06", "E65D65E3-F7B9-4C77-80F4-434D9B8D5F29");
            using (pushPfWebserver.PushPfServiceSoapClient push = new pushPfWebserver.PushPfServiceSoapClient())
            {
                push.SendPushOfProject("524a898e-8b3d-4d8f-a7f8-49d73bdb0e0c", "ca471a7c-4b72-48d6-8aa2-7c653d81bf31", "{\"@id\":\"d3f9d140-0d02-43ad-b333-af99ae3c1604\",\"@type\":\"药品\"}");
                //var test = push.QueryPushMsgList("05f845e0-cf77-40f8-acbb-44a15fbb4e6a", new int[] { 5 }, null, 1, 10);
                //var result = push.UpPushMsgRead("fa01e0e3-3014-464f-9675-0104eca5bba2");

            }
            //SocketClient.SendInfo();
            //PushInfo.Act.BLL.QuartzBLL.Start();
            //Dictionary<string, string> dic = new Dictionary<string, string>();
            ////dic.Add("@House_Id", "851d5845-6294-437d-8fca-4fae8f4cbfcc");
            ////dic.Add("@medicineId", "8d8f8a14-8040-4c3e-af08-0d521acabf21");
            ////dic.Add("@conversionId", "5f2968d3-eb90-45d6-9924-23ba52f35c18");
            //dic.Add("@Operator", "席世全");
            //dic.Add("@patientId", "1");
            //dic.Add("@visitId", "cf124afa-17c2-4b62-b074-3681269c1e1e");
            //dic.Add("@houseId", "851d5845-6294-437d-8fca-4fae8f4cbfcc");
            //string str = JsonUtil.ConvertToJson(dic);

            //Dictionary<string, string> dic = new Dictionary<string, string>();
            //dic.Add("@visitId", "1484955e-baaf-4a04-bec1-e2c7033e18d8");
            //dic.Add("@hosId", "1");
            //string str = JsonUtil.ConvertToJson(dic);
            //using (pushPfWebserver.PushPfServiceSoapClient push = new pushPfWebserver.PushPfServiceSoapClient())
            //{
            //    //push.SendPushOfPCValmap("3c3b61a7-ae08-4192-9a97-6d7833fed618","", str);
            //    //push.SendPushOfPCValmap("90120daf-2f27-48cb-9707-f5915d47bd2a", "", str);
            //    //push.SendPushOfPCValmap("e90a08e2-3dfe-48f7-be34-7faacf7e5c94", "", "");
            //    push.SendPushOfProject("9e5ab4af-1e57-478e-92eb-63939d931369", "b8617c54-e25f-4850-ab31-cdc75c3a1036", str);
            //    //var result = push.SendMessage("0c54b311-a620-4684-a6ca-bdd4f990e2f1", "15317808813", "nihao");
            //}
            //Console.Read();


            //Console.WriteLine("====1.开始监听数据=====");
            //MG.Core.Mipf.MgMethod md = new MG.Core.Mipf.MgMethod();
            //md.Listener += new MG.Core.Mipf.MgListenerCollection.MgListener(MipfRandomChange);
            //md.StartListener("MipfQueue_EdcRandomChange");
            //Console.ReadKey();
            //ActiveMQHelper.CreateMQProducer("string", MQMode.Queue,new DataCenterMessage() {MsgData = "xsq"},DateTime.Now.AddSeconds(5) );

            //ActiveMQHelper.CreateMQConsumer("string", MQMode.Queue, msg =>
            //{
            //    try
            //    {
            //        Console.WriteLine(msg.MsgData);
            //    }
            //    catch (Exception ex)
            //    {
            //        Console.WriteLine(ex);
            //    }
            //});
            MqBLL mqBll = new MqBLL();
            mqBll.ReleaseTaskMq();
            LogHelper.Debug("任务消息队列：【服务启动】");
            //proBll.ReleaseTaskMq();
            Console.Read();
        }

        public static void MipfRandomChange(Apache.NMS.IMessage msgInfo)
        {
            string text = ((ITextMessage)msgInfo).Text;
            LogHelper.Info(text);
            JObject param = JObject.Parse(text);

            using (PushPlatform.Common.MIPFService.EdcMipfServiceSoapClient mipfBll = new PushPlatform.Common.MIPFService.EdcMipfServiceSoapClient())
            {
                string projectId = param.GetValue<string>("projectId")!=null? param.GetValue<string>("projectId").ToString() : "";
                string hosId = param.GetValue<string>("hosId") != null ? param.GetValue<string>("hosId").ToString() : "";
                string groupId = param.GetValue<string>("groupId") != null ? param.GetValue<string>("groupId").ToString() : "";
                string patientName = param.GetValue<string>("patientName") != null ? param.GetValue<string>("patientName").ToString() : "";
                string patientNumber = param.GetValue<string>("patientNumber") != null ? param.GetValue<string>("patientNumber").ToString() : "";
                string gender = param.GetValue<string>("gender") != null ? param.GetValue<string>("gender").ToString() : "";
                string createUser = param.GetValue<string>("createUser") != null ? param.GetValue<string>("createUser").ToString() : "";
                DateTime changeDate = DateTime.Now;
                DateTime? birthday = null;
                DateTime inDate = DateTime.Now;
                if(DateTime.TryParse(param.GetValue<string>("birthday") != null ? param.GetValue<string>("birthday").ToString() : "",out changeDate))
                {
                    birthday = changeDate;
                }
                if(DateTime.TryParse(param.GetValue<string>("inDate") != null ? param.GetValue<string>("inDate").ToString() : "", out changeDate))
                {
                    inDate = changeDate;
                }
                mipfBll.InsertPatientAsync("4e6985e0-6993-47d9-877a-e266236fb4f6", "5fa5432e-0856-48ac-a06a-0d3a15000740", groupId, patientName, patientNumber, gender, createUser, birthday, inDate);
            }
            Console.WriteLine(text);
        }

        public static void chart(ChangeMgModel model)
        {
            Console.WriteLine(model.ProjectId);
        }

        private static Task<string> test()
        {
            return getstrasync();
        }

        private static Task<string> test2()
        {
            return getstrasync2();
        }

        private async static Task<string> getstrasync()
        {
           await Task.Run(() =>
            {
                Thread.Sleep(1000);
                Console.WriteLine("test1");
            });
            Console.WriteLine("test11");
            return "123";
        }
        private async static Task<string> getstrasync2()
        {
            return await Task.Run(() =>
            {
                Thread.Sleep(500);
                Console.WriteLine("test2");
                return "test2";
            });
        }
    }

    public class test
    {
        public Dictionary<string, string> dicValue { get; set; }
        public string data { get; set; }
    }
}
