public Message PostMessage(MessageSubmit msg) { System.IO.Stream attachment = null; if (msg.Attachments != null) { attachment = msg.Attachments.Select(x => new NamedStream(x.Key, x.Value)).FirstOrDefault(); } System.Func <string, string, string, string, string, string, System.IO.Stream, V4Message> func = (string a, string b, string c, string d, string e, string f, System.IO.Stream g) => _messagesApi.V4StreamSidMessageCreatePost(a, b, c, d, e, f, g); V4Message response = _apiExecutor.Execute(func, msg.StreamId, _authTokens.SessionToken, msg.Body, _authTokens.KeyManagerToken, msg.Data, null, attachment); return(MessageFactory.Create(response)); }
public Message PostMessage(MessageSubmit msg) { FileParameter attachment = null; if (msg.Attachments != null) { attachment = msg.Attachments.Select(x => new FileParameter(new MemoryStream(x.Value), x.Key)).FirstOrDefault(); } try { System.Func <string, string, string, string, string, string, FileParameter, CancellationToken, Task <V4Message> > func = (string a, string b, string c, string d, string e, string f, FileParameter g, CancellationToken token) => _streamClient.V4MessageCreateAsync(a, b, c, d, e, f, g, token); V4Message response = _apiExecutor.Execute(func, msg.StreamId, _authTokens.SessionToken, msg.Body, _authTokens.KeyManagerToken, msg.Data, null, attachment); return(MessageFactory.Create(response)); } catch (Exception e) { var streamId = msg.StreamId; _log?.LogError(0, e, "An error has occured while trying to post a message to stream {streamId}", streamId); throw; } }
private System.Collections.ObjectModel.ObservableCollection <V4Event> CreateMessageList(int count, int startId = 1) { var result = new System.Collections.ObjectModel.ObservableCollection <V4Event>(); for (var i = 0; i < count; ++i) { var msg = new V4Message() { MessageId = "msg" + (startId + i), Timestamp = 1477297302, Stream = new V4Stream() { StreamId = "streamId" }, User = new V4User() { UserId = 1 } }; var evt = new V4Event() { Type = V4EventType.MESSAGESENT, Payload = new V4Payload() { MessageSent = new V4MessageSent() { Message = msg } } }; result.Add(evt); } ; return(result); }
protected void FireMessage(V4Message message) { var eventArgs = new MessageEventArgs(MessageFactory.Create(message)); InvokeEventHandlers(_onMessage, eventArgs); }
public static Message Create(V4Message v4Message) { var attachments = v4Message.Attachments?.Select(x => new Attachment(x.Id, x.Name, x.Size)).ToList(); return(new Message(v4Message.MessageId, Epoch.AddMilliseconds(v4Message.Timestamp.Value), v4Message.Stream.StreamType.ToString(), v4Message.Stream.StreamId, v4Message.Message, v4Message.User.UserId.Value, attachments, v4Message.Data)); }