public async Task ExecuteBatchTest()
        {
            string xml = @"<?xml version=""1.0"" encoding=""utf-8""?>
<response>
      <acknowledgement>
            <status>success</status>
      </acknowledgement>
      <control>
            <status>success</status>
            <senderid>testsenderid</senderid>
            <controlid>requestUnitTest</controlid>
            <uniqueid>false</uniqueid>
            <dtdversion>3.0</dtdversion>
      </control>
</response>";

            HttpResponseMessage mockResponse1 = new HttpResponseMessage()
            {
                StatusCode = System.Net.HttpStatusCode.OK,
                Content    = new StringContent(xml)
            };

            List <HttpResponseMessage> mockResponses = new List <HttpResponseMessage>
            {
                mockResponse1,
            };

            MockHandler mockHandler = new MockHandler(mockResponses);

            ClientConfig clientConfig = new ClientConfig()
            {
                SenderId       = "testsender",
                SenderPassword = "******",
                SessionId      = "testsession..",
                MockHandler    = mockHandler,
            };

            RequestConfig requestConfig = new RequestConfig()
            {
                PolicyId = "asyncPolicyId",
            };

            OfflineClient client = new OfflineClient(clientConfig);

            List <IFunction> contentBlock = new List <IFunction>
            {
                new ApiSessionCreate("func1UnitTest")
            };

            OfflineResponse response = await client.ExecuteBatch(contentBlock, requestConfig);

            Assert.Equal("requestUnitTest", response.Control.ControlId);
        }
Esempio n. 2
0
 //static object lookObj = new object();
 public void StartServer(string ip, int port)
 {
     if (hySever == null)
     {
         hySever = new TCPSyncSocketServer(port, ip, 1024 * 1024 * 6);
         try
         {
             hySever.OnReceviceByte += (o, a, c) =>
             {
                 try
                 {
                     ////if(c>0)
                     //try
                     //{
                     //    if (c > 0)
                     //    {
                     //        lock (lookObj)
                     //        {
                     //            datas.Add(new ZDPowerData.PowerData() { o = o, data = a, lenght = c });
                     //        }
                     //    }
                     //}
                     //catch (Exception) { }
                     DataHandle(o, a, c);
                     //SendData(((IPEndPoint)o.RemoteEndPoint).Address.ToString(), ((IPEndPoint)o.RemoteEndPoint).Port, "Zzzdgyjk000210Zzzdgyjk");
                 }
                 catch (Exception) { }
             };
             hySever.OnOfflineClient += (c) =>
             {
                 try
                 {
                     //clientInfo.RemoveAt(clientInfo.FindIndex(o => o.Ip == ((IPEndPoint)c.RemoteEndPoint).Address.ToString()));
                     OfflineClient?.Invoke(c);
                     ClientInfo pd = clientInfo.Find(a => a.Ip == ((IPEndPoint)c.RemoteEndPoint).Address.ToString());
                     if (pd != null)
                     {
                         pd.OnlineTime = DateTime.Now;
                         pd.Status     = "离线中";
                     }
                 }
                 catch (Exception) { }
             };
             hySever.OnOnlineClient += (o) =>
             {
                 OnlineClient?.Invoke(o);
                 //SendData(((IPEndPoint)o.RemoteEndPoint).Address.ToString(), ((IPEndPoint)o.RemoteEndPoint).Port, "stxzjzdstart1002");
                 //SendData(((IPEndPoint)o.RemoteEndPoint).Address.ToString(), ((IPEndPoint)o.RemoteEndPoint).Port, "zzzdgyjk000210Zzzzdgyjk" + Environment.NewLine);
                 ClientInfo pd = clientInfo.Find(a => a.Ip == ((IPEndPoint)o.RemoteEndPoint).Address.ToString());
                 if (pd != null)
                 {
                     pd.OnlineTime = DateTime.Now;
                     pd.Status     = "在线上";
                 }
             };
             hySever.OnStateInfo += (o, a) =>
             {
                 StateInfo?.Invoke(o, a);
             };
             //hySever.OnExceptionMsg += (o) =>
             //{
             //    //try
             //    //{
             //    //    txtFxMsg.Dispatcher.BeginInvoke(new Action(() =>
             //    //    {
             //    //        txtFxMsg.AppendText(Environment.NewLine + AppLogHelper.GetLogStr("----->>>" + string.Format("{0} {1}\r\n", o, DateTime.Now.ToString()), "错误消息"));
             //    //    }));
             //    //}
             //    //catch (Exception) { }
             //};
         }
         catch (InvalidOperationException) { }
         catch (Exception) { }
     }
     hySever.StartListen();
     (new Thread(SendHert)
     {
         IsBackground = true
     }).Start();
 }
        static void Main(string[] args)
        {
            Console.WriteLine(string.Format("connecting to: ws://{0}:{1}", ConfigurationManager.AppSettings["host"], ConfigurationManager.AppSettings["port"]));

            switch (ConfigurationManager.AppSettings["client_type"])
            {
            case "0":
                using (DataClient client = new DataClient(ConfigurationManager.AppSettings["host"], int.Parse(ConfigurationManager.AppSettings["port"]), ConfigurationManager.AppSettings["accesskey"], ConfigurationManager.AppSettings["accesssecret"]))
                {
                    try
                    {
                        client.subscribe(ConfigurationManager.AppSettings["subid"], ConfigurationManager.AppSettings["consumergroup"]);
                        foreach (var message in client.GetMessages())
                        {
                            Console.WriteLine(string.Format("got message on client, key: {0}, partition: {1}, offset: {2}, value: {3}", message.key, message.partition, message.offset, message.value));
                        }
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.Message);
                    }
                }
                break;

            case "1":
                using (AlertClient client = new AlertClient(ConfigurationManager.AppSettings["host"], int.Parse(ConfigurationManager.AppSettings["port"]), ConfigurationManager.AppSettings["accesskey"], ConfigurationManager.AppSettings["accesssecret"]))
                {
                    try
                    {
                        client.subscribe(ConfigurationManager.AppSettings["subid"], ConfigurationManager.AppSettings["consumergroup"]);
                        foreach (var message in client.GetMessages())
                        {
                            Console.WriteLine(string.Format("got message on client, key: {0}, partition: {1}, offset: {2}, value: {3}", message.key, message.partition, message.offset, message.value));
                        }
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.Message);
                    }
                }
                break;

            case "3":
                using (OfflineClient client = new OfflineClient(ConfigurationManager.AppSettings["host"], int.Parse(ConfigurationManager.AppSettings["port"]), ConfigurationManager.AppSettings["accesskey"], ConfigurationManager.AppSettings["accesssecret"]))
                {
                    try
                    {
                        client.subscribe(ConfigurationManager.AppSettings["subid"], ConfigurationManager.AppSettings["consumergroup"]);
                        foreach (var message in client.GetMessages())
                        {
                            Console.WriteLine(string.Format("got message on client, key: {0}, partition: {1}, offset: {2}, value: {3}", message.key, message.partition, message.offset, message.value));
                        }
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.Message);
                    }
                }
                break;

            default: break;
            }


            Console.WriteLine("Client exited....");

            Console.ReadLine();
        }