public WindowsViewModel() { ITcpEndPoint TcpEndPoint = Factory.CreateEndPoint(); IChatting chatting = Factory.CreateConnectingToServer(); IMessageContent messageContent = Factory.CreateMessageContent(); IPerson person = Factory.CreatePerson(); MessageList.Items = new System.Collections.ObjectModel.ObservableCollection <IMessageContent>(); IJsonContainer container = Factory.CreateJsonContainer(); IUserContent userContent = Factory.CreateUserContent(); IUserValidationData userValidationData = new UserValidationData(); ViewModels = new List <object> { new SignInViewModel(this, chatting, messageContent, person, TcpEndPoint, container, userContent), new LogInViewModel(this, chatting, messageContent, person, TcpEndPoint, container, userContent, userValidationData), new ChatViewModel(messageContent, this) }; currentView = ViewModels[1]; }
public EmailEnvelope(string subject, string to, string replyTo, IMessageContent content) { To = to; ReplyTo = replyTo; Subject = subject; Content = content; }
private static void GetAllMessages(IMessageContent messageContent, IJsonContainer container, SynchronizationContext uiContext) { foreach (var item in container.Messages) { uiContext.Send(x => MessageList.Items.Add(messageContent.NewInstance(item)), null); } }
////////////////////////////////////////////////////////////////////////////////////////////////////////////////// /// public void Receiving2(IWindowsViewModel windowsViewModel, IMessageContent messageContent, IJsonContainer container) { _windowsViewModel = windowsViewModel; FirstTime = true; IsConnected = true; var uiContext = SynchronizationContext.Current; Task.Run(() => { if (GetPermission(uiContext, container))///true then next { _windowsViewModel.ChangeView(2); //while (IsConnected) //{ Chat(uiContext, container, messageContent); //} } else { //FirstTimeLogin = false;//to isConnected class ? _windowsViewModel.ChangeView(1); // here some static error class witch binging to label under login panel to show message! } }); }
public LogInViewModel(IWindowsViewModel windowsViewModel, IChatting chatting, IMessageContent messageContent, IPerson person, ITcpEndPoint tcpEndPoint, IJsonContainer container, IUserContent userContent, IUserValidationData userValidationData) { _person = person; _windowsViewModel = windowsViewModel; _userValidationData = userValidationData; //firstTime = true; //////////////////Vecaic variant priekš sarkanās bultas //IsNameSet = false; //ArrowVisibility = "Hidden"; /////////////// //GetData = new RelayCommand(GetAppruval);//already is excecuted in LogInCommand SwitchToSignIn = new RelayCommand(ToSignIn); LogInCommand = new LogInRelayCommand(Login, _windowsViewModel, GetAppruval, chatting.Receiving2, this, messageContent, tcpEndPoint, container); //SetPicFamele = new RelayCommand(SetDefoultFamelePic); //SetPicMale = new RelayCommand(SetDefoultMalePic); //AddPic = new RelayCommand(AddPicture); }
public TargetedMessage(Client sender, Client target, IMessageContent content) : base(sender, content) { Sender = sender; Target = target; Content = content; }
/// <summary> /// Create a new message part request /// </summary> /// <param name="content"></param> /// <param name="callback"></param> /// <param name="dataReceived"></param> public MessagePartRequest(IMessageContent content, RequestCompletedCallback callback, BaseCommand.CommandDataReceivedCallback dataReceived) : base(callback) { PreCommand = new ExamineFolderCommand(content.Message.Folder, null); Command = new MessagePartCommand(content, dataReceived); ProcessorType = typeof(MessagePartProcessor); }
public Connect(int personId, IPerson person, IJsonContainer jsonContainer, IMessageContent messageContent, IUIViewModel uIViewModel) { _PersonId = personId; _person = person; _jsonContainer = jsonContainer; _uIViewModel = uIViewModel; }
/// <summary> /// Create a new message part request /// </summary> /// <param name="content"></param> /// <param name="callback"></param> /// <param name="dataReceived"></param> public MessagePartRequest(IMessageContent content, RequestCompletedCallback callback, BaseCommand.CommandDataReceivedCallback dataReceived) : base(callback) { PreCommand = new ExamineFolderCommand(content.Message.Folder, null); Command = new MessagePartCommand(content, dataReceived); ProcessorType = typeof (MessagePartProcessor); }
public static OutgoingMessage CreateFromContent(IMessageContent content) { return(new OutgoingMessage { Type = content.GetType().Name, FormatVersion = content.FormatVersion, Content = JsonConvert.SerializeObject(content) }); }
/// <summary> /// Create a new message part command /// </summary> /// <param name="content"></param> /// <param name="callback"></param> public MessagePartCommand(IMessageContent content, CommandDataReceivedCallback callback) : base(callback) { _parameters.Add(content.Message.UID.ToString()); _parameters.Add(content.PartID); _parameterObjs.Add(content); CommandString = String.Format("UID FETCH {0} BODY[{1}]", Parameters); }
private void attachmentList_MouseDoubleClick(object sender, MouseEventArgs e) { int idx = attachmentList.IndexFromPoint(e.Location); string name = attachmentList.GetItemText(attachmentList.Items[idx]); IMessageContent content = fileContent[name]; _client.MailboxManager.SaveAttachment(content, @"C:\"); MessageBox.Show(String.Format("{0} Saved.", name)); }
private List <IMessageContent> ParseBodyStructure(string input) { List <IMessageContent> msgContentList = new List <IMessageContent>(); int i = 0; int index = 1; int count = 0; do { int next = index; do { if (input[next] == '(') { i++; } else if (input[next] == ')') { i--; } next++; } while (i > 0 || input[next - 1] != ')'); if (i >= 0 && input[index] == '(') { count++; if (input.Substring(index, next - index).StartsWith("((")) { List <IMessageContent> temp = ParseBodyStructure(input.Substring(index, next - index)); for (int j = 0; j < temp.Count; j++) { //ParseContentPart(temp[j],); temp[j].PartID = count + "." + temp[j].PartID; msgContentList.Add(temp[j]); } } else { IMessageContent Part = _request.Client.MailboxManager.AddMessageContent(_msg.ID); ParseContentPart(Part, input.Substring(index, next - index)); Part.PartID = count.ToString(); msgContentList.Add(Part); } } else if (msgContentList.Count == 0) { IMessageContent Part = _request.Client.MailboxManager.AddMessageContent(_msg.ID); Part.TextData = null; Part.PartID = "1"; ParseContentPart(Part, input); msgContentList.Add(Part); } index = next; } while (i >= 0); return(msgContentList); }
/// <summary> /// Create message with specific buffer /// </summary> /// <param name="buf"></param> public Message(Reference source, Reference target, Reference proxy, IMessageContent content) : this() { Content = content ?? throw new ArgumentException("content was null"); TypeId = MessageContent.GetId(content); IsResponse = MessageContent.IsResponse(content); Source = source ?? new Reference(); Target = target ?? new Reference(); Proxy = proxy ?? new Reference(); }
public async Task SendPublicMessageAsync(Guid theConnectionUid, IMessageContent theMessageContent) { Client client = await ClientRepository.GetByUidAsync(theConnectionUid); ThrowsErrorWhenNicknameIsNullOrEmpty(client); ThrowsErrorWhenRoomIsNullOrEmpty(client); await SendTheMessageForEverbodyInTheRoom(client.Room, new Message(client, theMessageContent)); }
public async Task <MessageResponse> SendAsync(IMessageContent message, MessageType messageType = MessageType.Email) { switch (messageType) { case MessageType.Email: return(await _email.SendAsync(message as MailMessage)); } return(null); }
public ChatViewModel(IMessageContent messageContent, IWindowsViewModel windowsViewModel) { _windowsViewModel = windowsViewModel; _messageContent = messageContent; _SendCommand = new RelayCommand(Send); OnlineUsers.UserList = new ObservableCollection <IUserContent>(); }
public override async Task OnSetToManyRelationshipAsync(DomainGroup group, HasManyAttribute hasManyRelationship, ISet <IIdentifiable> rightResourceIds, OperationKind operationKind, CancellationToken cancellationToken) { _hitCounter.TrackInvocation <DomainGroup>(ResourceDefinitionHitCounter.ExtensibilityPoint.OnSetToManyRelationshipAsync); if (hasManyRelationship.Property.Name == nameof(DomainGroup.Users)) { HashSet <Guid> rightUserIds = rightResourceIds.Select(resource => (Guid)resource.GetTypedId()).ToHashSet(); List <DomainUser> beforeUsers = await _userSet.Include(user => user.Group).Where(user => rightUserIds.Contains(user.Id)) .ToListAsync(cancellationToken); foreach (DomainUser beforeUser in beforeUsers) { IMessageContent content = null; if (beforeUser.Group == null) { content = new UserAddedToGroupContent { UserId = beforeUser.Id, GroupId = group.Id }; } else if (beforeUser.Group != null && beforeUser.Group.Id != group.Id) { content = new UserMovedToGroupContent { UserId = beforeUser.Id, BeforeGroupId = beforeUser.Group.Id, AfterGroupId = group.Id }; } if (content != null) { _pendingMessages.Add(OutgoingMessage.CreateFromContent(content)); } } if (group.Users != null) { foreach (DomainUser userToRemoveFromGroup in group.Users.Where(user => !rightUserIds.Contains(user.Id))) { var message = OutgoingMessage.CreateFromContent(new UserRemovedFromGroupContent { UserId = userToRemoveFromGroup.Id, GroupId = group.Id }); _pendingMessages.Add(message); } } } }
public ChatModel.Util.ViewModel?getCompositorViewModel(IMessageContent content) { switch (content) { case TextContent textContent: return(new TextContentCompositorViewModel(textContent)); default: return(null); } }
public RequestReplyContext(string replyTo, string correlationId, IMessageContent sourceContent) { var properties = sourceContent.Properties.Clone(); properties.ReplyTo = replyTo; properties.CorrelationId = correlationId; SourceContent = sourceContent; RequestContent = new RequestMessageContentWrapper(sourceContent, properties); taskSource = new TaskCompletionSource <RabbitMQDelivery>(); }
public LogInRelayCommand(Action <object> login, IWindowsViewModel windowsViewModel, Action execute2, Action <IWindowsViewModel, /* ILogInViewModel, */ IMessageContent, /* ITcpEndPoint, */ IJsonContainer> execute3, ILogInViewModel userData, IMessageContent messageContent, ITcpEndPoint tcpEndPoint, IJsonContainer container) { _login = login; _execute2 = execute2; _execute3 = execute3; _userData = userData; _messageContent = messageContent; _tcpEndPoint = tcpEndPoint; _container = container;; _windowsViewModel = windowsViewModel; }
/// <summary> /// /// </summary> /// <param name="content"></param> /// <param name="path"></param> public void SaveAttachment(IMessageContent content, string path) { string fn = content.ContentFilename; fn = Regex.Replace(fn, "[\\/:*?\"<>|]+", "_"); string p = String.Format("{0}\\{1}", path.TrimEnd('\\'), fn); FileStream fstream = new FileStream(p, FileMode.Create); fstream.Write(content.BinaryData, 0, content.BinaryData.Length); fstream.Close(); }
public ParameterRelayCommand(IWindowsViewModel windowsViewModel, Action execute2, Action <IWindowsViewModel, ISignInViewModel, IMessageContent, ITcpEndPoint, IJsonContainer> execute3, SignInViewModel userData, IMessageContent messageContent, ITcpEndPoint tcpEndPoint, IJsonContainer container, Action noNameCheck) { _execute2 = execute2; _execute3 = execute3; _userData = userData; _messageContent = messageContent; _tcpEndPoint = tcpEndPoint; _container = container;; _windowsViewModel = windowsViewModel; _noNameCheck = noNameCheck; }
public async Task Should_Broadcast_A_Targeted_Message_When_User_Sents_A_Targeted_Public_Message() { // arrage string expectedRoom = "secret-room"; string theTargetedNickname = "Carlton"; Guid theConnectionUid = Guid.NewGuid(); IMessageContent theMessageContent = Mock.Of <IMessageContent>(); Client senderClient = new Client { Nickname = "Will", Room = expectedRoom }; Client targetedClient = new Client { Nickname = theTargetedNickname, Room = expectedRoom }; Client destinationClient = new Client(); ClientRepositoryMock.Setup(mock => mock.GetAllClientInTheRoomAsync(expectedRoom)).Returns(Task.FromResult(new List <Client> { destinationClient }.AsEnumerable())); ClientRepositoryMock.Setup(mock => mock.FindByNicknameAsync(theTargetedNickname)).Returns(Task.FromResult(targetedClient)); ClientRepositoryMock.Setup(mock => mock.GetByUidAsync(theConnectionUid)).Returns(Task.FromResult(senderClient)); Client actualDestinationClient = null; PropagateMessageCommand actualCommand = null; DomainEvents.OnCommand += (destination, command) => { actualDestinationClient = destination; actualCommand = command as PropagateMessageCommand; return(Task.CompletedTask); }; // act await ChatFacade.SendPublicTargetedMessageAsync(theConnectionUid, theTargetedNickname, theMessageContent); // assert Assert.AreEqual(destinationClient, actualDestinationClient); Assert.NotNull(actualCommand); Assert.AreEqual(theMessageContent, actualCommand.Content); Assert.AreEqual(senderClient, actualCommand.Sender); Assert.AreEqual(targetedClient, actualCommand.Target); }
/// <summary> /// Adds a message to conversation. /// </summary> /// <param name="user">Message's author</param> /// <param name="parentID">id of message to which the new one is replying. -1 indicates not replying to any other message</param> /// <param name="messageContent">Content of the message</param> /// <param name="datetime">Sent time of the message</param> /// <returns>Reference to added message, null if unsuccessful.</returns> public Message AddMessage(IUser user, Guid parentID, IMessageContent messageContent, DateTime datetime) { //can add only if the message isn't replying to anything or targeted message exists and the author exists in the system //and there is no other message with this id var message = new Message(user.ID, parentID, messageContent, datetime) { Conversation = this }; messages.Add(message.ID, message); return(message); }
public void Should_Return_Error_When_User_Has_Not_Set_Nickname() { // arrage Guid theConnectionUid = Guid.NewGuid(); IMessageContent theMessageContent = Mock.Of <IMessageContent>(); Client storedClient = new Client { Room = "" }; ClientRepositoryMock.Setup(mock => mock.GetByUidAsync(theConnectionUid)).Returns(Task.FromResult(storedClient)); // act & assert Assert.ThrowsAsync <UserHasNotsetTheNicknameException>(async() => await ChatFacade.SendPublicMessageAsync(theConnectionUid, theMessageContent)); }
public void SendMessage(MessageContentType type, int player, IMessageContent data) { lock (messageLock) { NetworkMessage msg; if (data != null) { msg = new NetworkMessage(data, type); SendBuffer(msg.Encode(), player); } else { SendBuffer(NetworkMessage.EmptyMessage(type), player); } } }
private Task Publish(IMessageContent content, string routingKey, string exchange) { var model = Model; var body = content.GetBody(); var properties = content.Properties.Build(model); model.BasicPublish( exchange, routingKey, properties, body ); return(Task.CompletedTask); }
/// <summary> /// Create message with specific buffer /// </summary> protected static Message Create(uint sequenceId, Reference source, Reference target, Reference proxy, IMessageContent content, string deviceId = null) { var message = Get(); message.Version = VersionEx.Assembly.ToUInt(); message.SequenceId = sequenceId; message.Content = content ?? throw new ArgumentException("content was null"); message.TypeId = MessageContent.GetId(content); message.IsResponse = MessageContent.IsResponse(content); message.Source = source ?? new Reference(); message.Target = target ?? new Reference(); message.Proxy = proxy ?? new Reference(); message.DeviceId = deviceId; return(message); }
public IMessageContent NewInstance(IMessageContent from) { MessageContent content = new MessageContent(); content.MessageAlignment = from.MessageAlignment; content.MessageColour = from.MessageColour; content.MessagePicture = from.MessagePicture; content.MessageText = from.MessageText; content.MessageTime = from.MessageTime; content.Name = from.Name; content.MessagePictureVisibility = from.MessagePictureVisibility; content.Pic = from.Pic; content.PictureChanged = from.PictureChanged; content.Id = from.Id; return(content); }
private void ParseContentPart(IMessageContent part, string s) { const string non_attach = "^\\((?<type>(\"[^\"]*\"|NIL))\\s(?<subtype>(\"[^\"]*\"|NIL))\\s(?<attr>(\\(.*\\)|NIL))\\s(?<id>(\"[^\"]*\"|NIL))\\s(?<desc>(\"[^\"]*\"|NIL))\\s(?<encoding>(\"[^\"]*\"|NIL))\\s(?<size>(\\d+|NIL))\\s(?<lines>(\\d+|NIL))\\s(?<md5>(\"[^\"]*\"|NIL))\\s(?<disposition>(\\([^\\)]*\\)|NIL))\\s(?<lang>(\"[^\"]*\"|NIL))\\)$"; const string attachment = "^\\((?<type>(\"[^\"]*\"|NIL))\\s(?<subtype>(\"[^\"]*\"|NIL))\\s(?<attr>(\\(.*\\)|NIL))\\s(?<id>(\"[^\"]*\"|NIL))\\s(?<desc>(\"[^\"]*\"|NIL))\\s(?<encoding>(\"[^\"]*\"|NIL))\\s(?<size>(\\d+|NIL))\\s((?<data>(.*))\\s|)(?<lines>(\"[^\"]*\"|NIL))\\s(?<disposition>((?>\\((?<LEVEL>)|\\)(?<-LEVEL>)|(?!\\(|\\)).)+(?(LEVEL)(?!))|NIL))\\s(?<lang>(\"[^\"]*\"|NIL))\\)$"; const string alt_attach = "^\\([\"]*(?<type>([\\w]*))[\"\\s]*(?<subtype>(\\w*))[\"\\s]*\\([\"*]\\w*[\"\\s\"]*(?<filename>([^\"]*))[\")\\s]*NIL\\sNIL\\s\"(?<encoding>(\\w*))[\"]\\s(?<size>(\\d*))"; Match match; if ((match = Regex.Match(s, non_attach, RegexOptions.ExplicitCapture)).Success) { //this.Attachment = false; part.ContentType = string.Format("{0}/{1}", match.Groups["type"].Value.Replace("\"", ""), match.Groups["subtype"].Value.Replace("\"", "")); part.Charset = ParseCharacterSet(ParseNIL(match.Groups["attr"].Value)); part.ContentId = ParseNIL(match.Groups["id"].Value); part.ContentDescription = ParseNIL(match.Groups["desc"].Value); part.ContentTransferEncoding = ParseNIL(match.Groups["encoding"].Value); part.ContentSize = Convert.ToInt64(ParseNIL(match.Groups["size"].Value)); part.Lines = Convert.ToInt64(ParseNIL(match.Groups["lines"].Value)); part.MD5 = ParseNIL(match.Groups["md5"].Value); part.ContentDisposition = ParseNIL(match.Groups["disposition"].Value); part.Language = ParseNIL(match.Groups["lang"].Value); } else if ((match = Regex.Match(s, attachment, RegexOptions.ExplicitCapture)).Success) { //this.Attachment = true; part.ContentType = string.Format("{0}/{1}", match.Groups["type"].Value.Replace("\"", ""), match.Groups["subtype"].Value.Replace("\"", "")); part.ContentFilename = ParseFileName(ParseNIL(match.Groups["attr"].Value)); part.ContentId = ParseNIL(match.Groups["id"].Value); part.ContentDescription = ParseNIL(match.Groups["desc"].Value); part.ContentTransferEncoding = ParseNIL(match.Groups["encoding"].Value.Replace("\"", "")); part.ContentSize = Convert.ToInt64(ParseNIL(match.Groups["size"].Value)); part.Lines = Convert.ToInt64(ParseNIL(match.Groups["lines"].Value)); part.ContentDisposition = ParseNIL(match.Groups["disposition"].Value); part.Language = ParseNIL(match.Groups["lang"].Value); } else if ((match = Regex.Match(s, alt_attach, RegexOptions.ExplicitCapture)).Success) { part.ContentType = string.Format("{0}/{1}", match.Groups["type"].Value, match.Groups["subtype"].Value); part.ContentFilename = match.Groups["filename"].Value; part.ContentTransferEncoding = match.Groups["encoding"].Value; part.ContentSize = Convert.ToInt64(match.Groups["size"].Value); } else { throw new Exception("Invalid format could not parse body part headers."); } }
public IMessageEnvelope GetEnvelope(string subject, string to, IMessageContent message) { return new EmailEnvelope(subject, to, null, message); }
private void ParseContentPart(IMessageContent part, string s) { const string non_attach = "^\\((?<type>(\"[^\"]*\"|NIL))\\s(?<subtype>(\"[^\"]*\"|NIL))\\s(?<attr>(\\([^\\)]*\\)|NIL))\\s(?<id>(\"[^\"]*\"|NIL))\\s(?<desc>(\"[^\"]*\"|NIL))\\s(?<encoding>(\"[^\"]*\"|NIL))\\s(?<size>(\\d+|NIL))\\s(?<lines>(\\d+|NIL))\\s(?<md5>(\"[^\"]*\"|NIL))\\s(?<disposition>(\\([^\\)]*\\)|NIL))\\s(?<lang>(\"[^\"]*\"|NIL))\\)$"; const string attachment = "^\\((?<type>(\"[^\"]*\"|NIL))\\s(?<subtype>(\"[^\"]*\"|NIL))\\s(?<attr>(\\([^\\)]*\\)|NIL))\\s(?<id>(\"[^\"]*\"|NIL))\\s(?<desc>(\"[^\"]*\"|NIL))\\s(?<encoding>(\"[^\"]*\"|NIL))\\s(?<size>(\\d+|NIL))\\s((?<data>(.*))\\s|)(?<lines>(\"[^\"]*\"|NIL))\\s(?<disposition>((?>\\((?<LEVEL>)|\\)(?<-LEVEL>)|(?!\\(|\\)).)+(?(LEVEL)(?!))|NIL))\\s(?<lang>(\"[^\"]*\"|NIL))\\)$"; const string alt_attach = "^\\([\"]*(?<type>([\\w]*))[\"\\s]*(?<subtype>(\\w*))[\"\\s]*\\([\"*]\\w*[\"\\s\"]*(?<filename>([^\"]*))[\")\\s]*NIL\\sNIL\\s\"(?<encoding>(\\w*))[\"]\\s(?<size>(\\d*))"; Match match; if ((match = Regex.Match(s, non_attach, RegexOptions.ExplicitCapture)).Success) { //this.Attachment = false; part.ContentType = string.Format("{0}/{1}", match.Groups["type"].Value.Replace("\"", ""), match.Groups["subtype"].Value.Replace("\"", "")); part.Charset = ParseCharacterSet(ParseNIL(match.Groups["attr"].Value)); part.ContentId = ParseNIL(match.Groups["id"].Value); part.ContentDescription = ParseNIL(match.Groups["desc"].Value); part.ContentTransferEncoding = ParseNIL(match.Groups["encoding"].Value); part.ContentSize = Convert.ToInt64(ParseNIL(match.Groups["size"].Value)); part.Lines = Convert.ToInt64(ParseNIL(match.Groups["lines"].Value)); part.MD5 = ParseNIL(match.Groups["md5"].Value); part.ContentDisposition = ParseNIL(match.Groups["disposition"].Value); part.Language = ParseNIL(match.Groups["lang"].Value); } else if ((match = Regex.Match(s, attachment, RegexOptions.ExplicitCapture)).Success) { //this.Attachment = true; part.ContentType = string.Format("{0}/{1}", match.Groups["type"].Value.Replace("\"", ""), match.Groups["subtype"].Value.Replace("\"", "")); part.ContentFilename = ParseFileName(ParseNIL(match.Groups["attr"].Value)); part.ContentId = ParseNIL(match.Groups["id"].Value); part.ContentDescription = ParseNIL(match.Groups["desc"].Value); part.ContentTransferEncoding = ParseNIL(match.Groups["encoding"].Value.Replace("\"","")); part.ContentSize = Convert.ToInt64(ParseNIL(match.Groups["size"].Value)); part.Lines = Convert.ToInt64(ParseNIL(match.Groups["lines"].Value)); part.ContentDisposition = ParseNIL(match.Groups["disposition"].Value); part.Language = ParseNIL(match.Groups["lang"].Value); } else if ((match = Regex.Match(s, alt_attach, RegexOptions.ExplicitCapture)).Success) { part.ContentType = string.Format("{0}/{1}", match.Groups["type"].Value, match.Groups["subtype"].Value); part.ContentFilename = match.Groups["filename"].Value; part.ContentTransferEncoding = match.Groups["encoding"].Value; part.ContentSize = Convert.ToInt64(match.Groups["size"].Value); } else throw new Exception("Invalid format could not parse body part headers."); }