public void Send(string userId, string receiverUsername, string ids) { var repos = new ApplicationUserRepository(_context); var clientId = repos.GetUserByUsername(receiverUsername).Id; MessengerHub.Receive(repos.GetUserById(userId).UserName, clientId, ids); }
protected override void OnExit() { screen.AnimateOut(screen.Dispose); RubiksCube.AnimateOut(RubiksCube.Dispose); MessengerHub.Publish(new DisableCameraControlMessage(this)); MessengerHub.Publish(new ResetCameraMessage(this)); }
public IHttpActionResult MarkAsSeen(string username) { var clientId = Repository.ApplicationUserRepository.GetUserByUsername(username).Id; var list = new List <string>(); var output = Put(userId => { list = Repository.MessengerRepository.MarkAsRead(userId, clientId); }); MessengerHub.ChangeSeen(clientId, list.ToArray()); return(output); }
protected override void OnEnter() { MessengerHub.Publish(new CameraOrbitRequestMessage(this, times: 3, onComplete: () => { screen.Build(); screen.AnimateIn(); })); }
private void EnableInput() { if (dragEndSubscriptionToken != null) { return; } dragEndSubscriptionToken = MessengerHub.Subscribe <DragEndMessage>(OnDragEnd); inGameScreen.SetEnabled(true); }
private void OnDragEnd(DragEndMessage message) { if (!RubiksCube.AcceptDragInput(message, out var command)) { return; } DisableInput(); MessengerHub.Publish(new EnqueueCommandMessage(this, command)); }
public ActionResult Send(SentMessageModel model) { if (ModelState.IsValid) { var groupMembers = dbProvider.GetUsersInGroup(new Group { Id = (int)model.GroupId }); if (groupMembers.All(x => x.Id != SessionData.User.Id)) { return(HttpNotFound()); } var materials = JsonConvert.DeserializeObject <Dictionary <int, string> >(model.Materials); var message = new Message { GroupId = (int)model.GroupId, SenderId = SessionData.User.Id, TimeStamp = DateTime.Now, Text = model.Ciphertext }; dbProvider.StoreMessage(message); foreach (var material in materials) { if (groupMembers.Any(x => x.Id == material.Key)) { dbProvider.StoreCryptographicMaterial(new MessageCryptoMaterial { Material = material.Value, MessageId = message.Id, UserId = material.Key }); } } if (model.Attachment != null && model.AttachmentName != null && model.AttachmentType != null) { dbProvider.StoreAttachment(new Attachment { Content = Encoding.UTF8.GetBytes(model.Attachment), FileExtension = model.AttachmentType, FileName = model.AttachmentName, MessageId = message.Id }); } foreach (var member in groupMembers) { MessengerHub.CallNewMessagesForGroup(member.RtID, (int)model.GroupId); } return(Content("OK")); } else { return(HttpNotFound()); } }
public void MessengerTest() { var hub = new MessengerHub(); for (int i = 0; i < count; i++) { hub.Subscribe<TestMessage>(_ => { //do nothing }); } for (int i = 0; i < count; i++) { hub.Publish (new TestMessage(this)); } }
private void RotateRandomSlice() { var position = Random.rotationUniform * Vector3.right * Random.Range(-randomPointVariance, randomPointVariance); var axis = Random.Range(0, sliceFinders.Count - 1); var slice = sliceFinders[axis](position); var command = new RotateSliceCommand(slice, Random.value > 0.5f); MessengerHub.Publish(new EnqueueCommandMessage(this, command, transient: true)); }
private void CloseOptionsScreen() { optionsScreen.AnimateOut(() => { MessengerHub.Publish(new EnableCameraControlMessage(this)); EnableInput(); timer.Start(); optionsScreen.Dispose(); }); }
protected override void OnEnter() { cmdCompleteSubscriptionToken = MessengerHub.Subscribe <CommandCompleteMessage>(OnCommandCompleted); optionsRequestedSubscriptionToken = MessengerHub.Subscribe <OptionsRequestedMessage>(OnOptionsRequested); MessengerHub.Publish(new EnableCameraControlMessage(this)); EnableInput(); timer.Start(); inGameScreen.AnimateIn(); }
private void OnOptionsRequested(OptionsRequestedMessage message) { DisableInput(); MessengerHub.Publish(new DisableCameraControlMessage(this)); timer.Stop(); optionsScreen = new OptionsScreen(this, inGameScreen.TimerIsVisible); optionsScreen.Build(); optionsScreen.AnimateIn(); }
protected override void OnExit() { cmdCompleteSubscriptionToken.Dispose(); optionsRequestedSubscriptionToken.Dispose(); MessengerHub.Publish(new DisableCameraControlMessage(this)); MessengerHub.Publish(new ResetCameraMessage(this)); timer.Stop(); DisableInput(); inGameScreen.AnimateOut(inGameScreen.Dispose); }
public void OnStayRequested() { screen.AnimateOut(() => { screen.Dispose(); MessengerHub.Publish(new EnableCameraControlMessage(this)); screen = new FreeViewScreen(this); screen.Build(); screen.AnimateIn(); }); }
protected override void OnEnter() { remainingRandomMoveCount = Random.Range(RandomMoveCountMin, RandomMoveCountMax); commandFinishedSubscriptionToken = MessengerHub.Subscribe <CommandCompleteMessage>(OnCommandFinished); MessengerHub.Publish(new EnableCameraControlMessage(this)); RubiksCube.AnimateIn(() => { lightLevelController.TurnOff(delay: 1f); RotateRandomSlice(); }); }
public ActionResult DeleteFriendship(int id) { var otherUser = dbProvider.GetUserByID(id, false); if (otherUser == null) { return(HttpNotFound()); } dbProvider.DeleteFriendship(SessionData.User, new DB.Entities.User { Id = id }); dbProvider.DeleteFriendship(new DB.Entities.User { Id = id }, SessionData.User); MessengerHub.CallRefresh(otherUser.RtID); return(Content("OK")); }
public void SubscribeAndPublishAllowsMessageToBeReceived() { var messenger = new MessengerHub(); var message = new TestMessage(this); var messageReceived = false; messenger.Subscribe<TestMessage>(m => { Assert.That(m, Is.EqualTo(message)); Assert.That(m.Sender, Is.EqualTo(this)); messageReceived = true; }); messenger.Publish(message); Assert.IsTrue(messageReceived); }
public ActionResult Accept(int?otherId) { if (otherId == null) { return(HttpNotFound()); } var request = dbProvider.GetRequestBetween(new DB.Entities.User { Id = (int)otherId }, SessionData.User); if (request == null) { return(HttpNotFound()); } request.Resolved = true; var group = dbProvider.CreateGroup(new DB.Entities.Group { Binary = true, IsAdmin = false, Name = null, Picture = null, PictureType = null, Timestamp = DateTime.Now }); dbProvider.AddUsersToGroup(new List <DB.Entities.User>() { SessionData.User, new DB.Entities.User { Id = (int)otherId } }, group, false); dbProvider.AddFriendship(SessionData.User, new DB.Entities.User { Id = (int)otherId }); dbProvider.DeleteFriendRequest(request); var other = dbProvider.GetUserByID((int)otherId, false); MessengerHub.CallRefresh(other.RtID); return(Content("OK")); }
public void MultipleSubscribeAndPublishAllowsMessageToBeReceived() { var messenger = new MessengerHub(); var message = new TestMessage(this); var otherMessage = new OtherTestMessage(this); var messageReceived = 0; messenger.Subscribe<TestMessage>(m => { Assert.That(m, Is.EqualTo(message)); Assert.That(m.Sender, Is.EqualTo(this)); messageReceived++; }); var otherMessageReceived = 0; messenger.Subscribe<OtherTestMessage>(m => { Assert.That(m, Is.EqualTo(otherMessage)); Assert.That(m.Sender, Is.EqualTo(this)); otherMessageReceived++; }); messenger.Publish(otherMessage); Assert.AreEqual(0, messageReceived); Assert.AreEqual(1, otherMessageReceived); messenger.Publish(message); Assert.AreEqual(1, messageReceived); Assert.AreEqual(1, otherMessageReceived); messenger.Publish(message); Assert.AreEqual(2, messageReceived); Assert.AreEqual(1, otherMessageReceived); messenger.Publish(message); Assert.AreEqual(3, messageReceived); Assert.AreEqual(1, otherMessageReceived); messenger.Publish(otherMessage); Assert.AreEqual(3, messageReceived); Assert.AreEqual(2, otherMessageReceived); }
public ActionResult SendRequest(int?id) { if (id == null) { return(HttpNotFound()); } if (id == SessionData.User.Id) { return(HttpNotFound()); } var other = dbProvider.GetUserByID((int)id, false); if (other == null) { return(HttpNotFound()); } if (dbProvider.GetSentFriendRequests(SessionData.User).Any(x => x.ReceiverId == id) || dbProvider.GetUnresolvedFriendRequests(SessionData.User).Any(x => x.SenderId == id)) { return(HttpNotFound()); } if (dbProvider.GetFriends(SessionData.User).Any(x => x.Id == id)) { return(HttpNotFound()); } dbProvider.CreateFriendRequest(new DB.Entities.FriendRequest { ReceiverId = (int)id, Resolved = false, Seen = false, SenderId = SessionData.User.Id, Timestamp = DateTime.Now }); MessengerHub.CallRefresh(other.RtID); return(Content("OK")); }
public void UnknownUnsubscribeDoesNotCauseException() { var messenger = new MessengerHub(); messenger.Unsubscribe<TestMessage>(Guid.NewGuid()); messenger.Subscribe<TestMessage>(m => { // stuff }); messenger.Unsubscribe<TestMessage>(Guid.NewGuid()); messenger.Unsubscribe<TestMessage>(Guid.Empty); }
public void UnsubscribePreventsMessagesBeingReceived() { var messenger = new MessengerHub(); Action<TestMessage> action = _ => Assert.That(false, "This event should not fire!"); var id = messenger.Subscribe(action); messenger.Unsubscribe<TestMessage>(id); messenger.Publish(new TestMessage(this)); }
protected override void OnEnter() { subscriptionToken = MessengerHub.Subscribe <MouseDownMessage>(OnMouseDown); }
public void NullPublishCausesException() { var messenger = new MessengerHub(); messenger.Publish<TestMessage>(null); }
public void NullSubscribeCausesException() { var messenger = new MessengerHub(); messenger.Subscribe<TestMessage>(null); }
protected override void OnEnter() { dragProgressSubscriptionToken = MessengerHub.Subscribe <DragProgressMessage>(OnDragProgress); dragEndSubscriptionToken = MessengerHub.Subscribe <DragEndMessage>(OnDragEnd); }
public ActionResult Edit(GroupModel model) { if (ModelState.IsValid) { if (model.Id == null) { if (model.Picture == null) { return(Content("FAIL:Niste poslali sliku")); } var image = ImageManipulation.LoadImage(model.Picture.InputStream); if (image == null) { return(Content("FAIL:Niste poslali sliku")); } image = ImageManipulation.ResizeImage(image, 160, 160); var group = dbProvider.CreateGroup(new DB.Entities.Group { Binary = false, Name = model.Name, Timestamp = DateTime.Now, Picture = ImageManipulation.StoreImage(image), PictureType = ImageManipulation.OutputImageFormat, }); var users = model.GetMembers(); var friends = dbProvider.GetFriends(SessionData.User).Union(dbProvider.GetUsersInGroup(group)); foreach (var user in users) { if (user.Id == SessionData.User.Id || friends.All(x => x.Id != user.Id)) { return(HttpNotFound()); } } dbProvider.AddUsersToGroup(users, group, false); dbProvider.AddUsersToGroup(new List <DB.Entities.User> { SessionData.User }, group, true); dbProvider.CommitIfNecessary(); foreach (var user in users) { MessengerHub.CallRefresh(friends.First(x => x.Id == user.Id).RtID); } return(Content("OK")); } else { Image picture = null; if (model.Picture != null) { picture = ImageManipulation.LoadImage(model.Picture.InputStream); if (picture == null) { return(Content("FAIL:Niste poslali sliku")); } picture = ImageManipulation.ResizeImage(picture, 160, 160); } var group = dbProvider.GetGroupsForUser(SessionData.User).FirstOrDefault(x => x.Id == model.Id); if (group == null || !(bool)group.IsAdmin) { return(HttpNotFound()); } var oldMembers = dbProvider.GetUsersInGroup(group); var newMembers = model.GetMembers(); var friends = dbProvider.GetFriends(SessionData.User).Union(dbProvider.GetUsersInGroup(group)); foreach (var user in newMembers) { if (user.Id == SessionData.User.Id || friends.All(x => x.Id != user.Id)) { return(HttpNotFound()); } } newMembers.Add(SessionData.User); List <User> deletedMembers = new List <User>(); List <User> addedMembers = new List <User>(); foreach (var member in oldMembers) { if (!newMembers.Any(x => x.Id == member.Id)) { deletedMembers.Add(member); } } foreach (var member in newMembers) { if (!oldMembers.Any(x => x.Id == member.Id)) { addedMembers.Add(member); } } dbProvider.RemoveUsersFromGroup(deletedMembers, group); dbProvider.AddUsersToGroup(addedMembers, group, false); if (model.Name != group.Name || model.Picture != null) { if (model.Name != group.Name) { group.Name = model.Name; } if (picture != null) { group.Picture = ImageManipulation.StoreImage(picture); } dbProvider.UpdateGroup(group, picture != null); } dbProvider.CommitIfNecessary(); foreach (var member in deletedMembers) { MessengerHub.CallRefresh(member.RtID); } foreach (var member in addedMembers) { MessengerHub.CallRefresh(friends.First(x => x.Id == member.Id).RtID); } return(Content("OK")); } } else { var x = ModelValidationErrors; return(Content("FAIL:" + string.Join(", ", ModelValidationErrors))); } }