Ejemplo n.º 1
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="message"></param>
        /// <returns></returns>
        public async Task<bool> SendMessage(Message message)
        {
            var res = false;
            if (string.IsNullOrWhiteSpace(ConversationId))
            {
                Debug.WriteLine("You must call StartConversation() first");
                return res;
            }
            if (message == null) return res;

            try
            {
                if (await EnsureTokenIsValid())
                {
                    var postMessageResponse = await ConversationClient.Conversations.PostMessageWithOperationResponseAsync(ConversationId, message);
                    res = postMessageResponse?.Response?.StatusCode == HttpStatusCode.NoContent;
                }
                else
                {
                    //TODO: Handle situation when token is not valid
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex);
            }

            return res;
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Deserialize the object
 /// </summary>
 public virtual void DeserializeJson(JToken inputObject)
 {
     if (inputObject != null && inputObject.Type != JTokenType.Null)
     {
         JToken eTagValue = inputObject["eTag"];
         if (eTagValue != null && eTagValue.Type != JTokenType.Null)
         {
             this.ETag = ((string)eTagValue);
         }
         JToken messagesSequence = ((JToken)inputObject["messages"]);
         if (messagesSequence != null && messagesSequence.Type != JTokenType.Null)
         {
             foreach (JToken messagesValue in ((JArray)messagesSequence))
             {
                 Message message = new Message();
                 message.DeserializeJson(messagesValue);
                 this.Messages.Add(message);
             }
         }
         JToken watermarkValue = inputObject["watermark"];
         if (watermarkValue != null && watermarkValue.Type != JTokenType.Null)
         {
             this.Watermark = ((string)watermarkValue);
         }
     }
 }
Ejemplo n.º 3
0
 /// <param name='operations'>
 /// Reference to the DirectLinkApi.IConversations.
 /// </param>
 /// <param name='conversationId'>
 /// Required. Conversation ID
 /// </param>
 /// <param name='message'>
 /// Required. Message to send
 /// </param>
 public static object PostMessage(this IConversations operations, string conversationId, Message message)
 {
     return Task.Factory.StartNew((object s) => 
     {
         return ((IConversations)s).PostMessageAsync(conversationId, message);
     }
     , operations, CancellationToken.None, TaskCreationOptions.None, TaskScheduler.Default).Unwrap().GetAwaiter().GetResult();
 }
Ejemplo n.º 4
0
 /// <param name='operations'>
 /// Reference to the DirectLinkApi.IConversations.
 /// </param>
 /// <param name='conversationId'>
 /// Required. Conversation ID
 /// </param>
 /// <param name='message'>
 /// Required. Message to send
 /// </param>
 /// <param name='cancellationToken'>
 /// Cancellation token.
 /// </param>
 public static async Task<object> PostMessageAsync(this IConversations operations, string conversationId, Message message, CancellationToken cancellationToken = default(System.Threading.CancellationToken))
 {
     Microsoft.Rest.HttpOperationResponse<object> result = await operations.PostMessageWithOperationResponseAsync(conversationId, message, cancellationToken).ConfigureAwait(false);
     return result.Body;
 }