Ali cloud Things .NET Core Client | CZGL.AliIoTClient:. 9 custom delegate event method

Documents directory:


 

CZGL.AliIoTClient has commissioned seven events, setting the default method. You can use the default by the following methods bound to the delegate event.

public void UseDefaultEventHandler() 

1) The default method

Under the server send property to receive:

public void Default_PubPropertyEventHandler(object sender, MqttMsgPublishEventArgs e) 

Upon receipt of server calls the service command:

public void Default_PubServiceEventHandler(object sender, MqttMsgPublishEventArgs e) 

Other general cases received Topic, upload data, etc. in response to:

public void Default_PubCommonEventHandler(object sender, MqttMsgPublishEventArgs e) 

QOS server to receive push 1

public void Default_PubedEventHandler(object sender, MqttMsgPublishedEventArgs e) 

When the message is successfully sent to the server:

public void Default_SubedEventHandler(object sender, MqttMsgSubscribedEventArgs e) 

Message failed to push the server:

public void Default_UnSubedEventHandler(object sender, MqttMsgUnsubscribedEventArgs e) 

When disconnecting

public void Default_ConnectionClosedEventHandler(object sender, 
                                                 System.EventArgs e)

Writing 2) Method

Different delegate different parameters, there are several types, methods, refer to the author's arguments.

     /// 一般的推送
        /// </summary> /// <param name="sender"></param> /// <param name="e"></param> public void Default_PubCommonEventHandler(object sender, MqttMsgPublishEventArgs e) { // handle message received string topic = e.Topic; string message = Encoding.ASCII.GetString(e.Message); Console.WriteLine("- - - - - - - - - - "); Console.WriteLine("get topic message,Date: " + DateTime.Now.ToLongTimeString()); Console.WriteLine("topic: " + topic); Console.WriteLine("get messgae :\n" + message); } /// <summary> /// 收到属性设置 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> public void Default_PubPropertyEventHandler(object sender, MqttMsgPublishEventArgs e) { // handle message received string topic = e.Topic; string message = Encoding.ASCII.GetString(e.Message); Console.WriteLine("- - - - - - - - - - "); Console.WriteLine("get topic message,Date: " + DateTime.Now.ToLongTimeString()); Console.WriteLine("topic: " + topic); Console.WriteLine("get messgae :\n" + message); } /// <summary> /// 收到服务调用 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> public void Default_PubServiceEventHandler(object sender, MqttMsgPublishEventArgs e) { // handle message received string topic = e.Topic; string message = Encoding.ASCII.GetString(e.Message); Console.WriteLine("- - - - - - - - - - "); Console.WriteLine("get topic message,Date: " + DateTime.Now.ToLongTimeString()); Console.WriteLine("topic: " + topic); Console.WriteLine("get messgae :\n" + message); } /// <summary> /// 收到服务器QOS为1的推送 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> public void Default_PubedEventHandler(object sender, MqttMsgPublishedEventArgs e) { Console.WriteLine("- - - - - - - - - - "); Console.WriteLine("published,Date: " + DateTime.Now.ToLongTimeString()); Console.WriteLine("MessageId: " + e.MessageId + " Is Published: " + e.IsPublished); } /// <summary> /// 向服务器推送成功 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> public void Default_SubedEventHandler(object sender, MqttMsgSubscribedEventArgs e) { Console.WriteLine("- - - - - - - - - - "); Console.WriteLine("Sub topic,Date: " + DateTime.Now.ToLongTimeString()); Console.WriteLine("MessageId: " + e.MessageId); Console.WriteLine("List of granted QOS Levels: " + Encoding.UTF8.GetString(e.GrantedQoSLevels)); } /// <summary> /// 推送失败 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> public void Default_UnSubedEventHandler(object sender, MqttMsgUnsubscribedEventArgs e) { Console.WriteLine("- - - - - - - - - - "); Console.WriteLine("Sub topic error,Date: " + DateTime.Now.ToLongTimeString()); Console.WriteLine("MessageId: " + e.MessageId); } /// <summary> /// 连接发生异常,断网等 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> public void Default_ConnectionClosedEventHandler(object sender, EventArgs e) { Console.WriteLine("- - - - - - - - - - "); Console.WriteLine("Connect Closed error,Date: " + DateTime.Now.ToLongTimeString()); }

Guess you like

Origin www.cnblogs.com/whuanle/p/10994720.html