protected void Page_Load(object sender, EventArgs e) { if (this.User == null || this.User.Identity.IsAuthenticated == false) { Response.Redirect("~/Account/Login.aspx"); } else if (this.User.IsInRole("Administrator")) { currentUser = Administrator.Get(); } else { currentUser = DatabaseUtilities.GetUser(this.User.Identity.Name); } string otherStudentNumber = Request.QueryString["s"]; if (otherStudentNumber != null) { otherUser = DatabaseUtilities.GetUser(otherStudentNumber); //messages = DatabaseUtilities.GetMessagesBetweenUsers(currentUser.StudentNumber, otherUser.StudentNumber); chat = PrivateChatManager.GetChat(currentUser.StudentNumber, otherUser.StudentNumber); // tell the chat that we want to receive its messages chat.RegisterReceiver(this); PopulatePage(); } else { // no other user was supplied so return them to the inbox page Response.Redirect("~/Inbox.aspx"); } }
public static async void startTranmission() { if (dId == null) { dId = await createLinktoHub(); } privateChatManagerX = quickbloxClient.ChatXmppClient.GetPrivateChatManager(21010378, dId); privateChatManagerX.MessageReceived += ChatManager_MessageReceived; dynamic toSend = new JObject(); toSend.FriendlyName = user.FullName; toSend.Date = DateTime.Now; toSend.Type = "Init"; privateChatManagerX.SendMessage(JsonConvert.SerializeObject(toSend)); quickbloxClient.ChatXmppClient.MessageReceived += (object sender, MessageEventArgs messageEventArgs) => { var message = ((System.Xml.Linq.XElement)messageEventArgs.Message.ExtraParameters.NextNode).Value; var friendlyName = messageEventArgs.Message.SenderId; var dispatcher = CoreApplication.MainView.CoreWindow.Dispatcher; dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () => { } ); }; }
public static async void setGPIOstatus(int GPIOPin, bool bit) { if (dId == null) { dId = await createLinktoHub(); } privateChatManagerX = quickbloxClient.ChatXmppClient.GetPrivateChatManager(21010378, dId); dynamic toSend = new JObject(); toSend.FriendlyName = user.FullName; toSend.Date = DateTime.Now; toSend.Type = "setGPIOstatus"; toSend.GPIOPin = GPIOPin; toSend.bit = bit; privateChatManagerX.SendMessage(JsonConvert.SerializeObject(toSend)); }
public override void OnAppearing() { base.OnAppearing(); this.IsBusyIndicatorVisible = true; var dialog = Database.Instance().GetDialog(dialogId); var opponentId = dialog.OccupantIds.Split(',').Select(Int32.Parse).First(id => id != App.QbProvider.UserId); privateChatManager = App.QbProvider.GetXmppClient().GetPrivateChatManager(opponentId, dialogId); privateChatManager.MessageReceived += OnMessageReceived; DialogName = dialog.Name; ImageSource = Device.OnPlatform(iOS: ImageSource.FromFile("privateholder.png"), Android: ImageSource.FromFile("privateholder.png"), WinPhone: ImageSource.FromFile("privateholder.png")); Task.Factory.StartNew(async() => { var users = await App.QbProvider.GetUsersByIdsAsync(dialog.OccupantIds); var opponentUser = users.FirstOrDefault(u => u.Id != App.QbProvider.UserId); if (opponentUser != null && opponentUser.BlobId.HasValue) { await App.QbProvider.GetImageAsync(opponentUser.BlobId.Value).ContinueWith((task, result) => { var bytes = task.ConfigureAwait(true).GetAwaiter().GetResult(); if (bytes != null) { Device.BeginInvokeOnMainThread(() => ImageSource = ImageSource.FromStream(() => new MemoryStream(bytes))); } }, TaskScheduler.FromCurrentSynchronizationContext()); } this.opponentUsers = new List <User>() { opponentUser }; await this.LoadMessages(); Device.BeginInvokeOnMainThread(() => this.IsBusyIndicatorVisible = false ); }); }
public override async void OnAppearing() { base.OnAppearing(); this.IsBusy = true; var dialog = Database.Instance().GetDialog(dialogId); var opponentId = dialog.OccupantIds.Split(',').Select(Int32.Parse).First(id => id != App.QbProvider.UserId); privateChatManager = App.QbProvider.GetXmppClient().GetPrivateChatManager(opponentId, dialogId); privateChatManager.MessageReceived += OnMessageReceived; DialogName = dialog.Name; ImageSource = new BitmapImage(new Uri("ms-appx:///Assets/privateholder.png")); this.opponentUsers = new List <User>(); var users = await App.QbProvider.GetUsersByIdsAsync(dialog.OccupantIds); var opponentUser = users.FirstOrDefault(u => u.Id != App.QbProvider.UserId); if (opponentUser != null) { this.opponentUsers.Add(opponentUser); if (opponentUser.BlobId.HasValue) { var bytes = await App.QbProvider.GetImageAsync(opponentUser.BlobId.Value); BitmapImage image = new BitmapImage(); using (InMemoryRandomAccessStream stream = new InMemoryRandomAccessStream()) { await stream.WriteAsync(bytes.AsBuffer()); stream.Seek(0); await image.SetSourceAsync(stream); } } } await this.LoadMessages(); this.IsBusy = false; }
public override void OnAppearing() { base.OnAppearing(); this.IsBusyIndicatorVisible = true; var dialog = Database.Instance().GetDialog(dialogId); var opponentId = dialog.OccupantIds.Split(',').Select(Int32.Parse).First(id => id != App.QbProvider.UserId); privateChatManager = App.QbProvider.GetXmppClient().GetPrivateChatManager(opponentId, dialogId); privateChatManager.MessageReceived += OnMessageReceived; DialogName = dialog.Name; ImageSource = Device.OnPlatform(iOS: ImageSource.FromFile("privateholder.png"), Android: ImageSource.FromFile("privateholder.png"), WinPhone: ImageSource.FromFile("privateholder.png")); Task.Factory.StartNew(async () => { var users = await App.QbProvider.GetUsersByIdsAsync(dialog.OccupantIds); var opponentUser = users.FirstOrDefault(u => u.Id != App.QbProvider.UserId); if (opponentUser != null && opponentUser.BlobId.HasValue) { await App.QbProvider.GetImageAsync(opponentUser.BlobId.Value).ContinueWith((task, result) => { var bytes = task.ConfigureAwait(true).GetAwaiter().GetResult(); if (bytes != null) Device.BeginInvokeOnMainThread(() => ImageSource = ImageSource.FromStream(() => new MemoryStream(bytes))); }, TaskScheduler.FromCurrentSynchronizationContext()); } this.opponentUsers = new List<User>() { opponentUser }; await this.LoadMessages(); Device.BeginInvokeOnMainThread(() => this.IsBusyIndicatorVisible = false ); }); }
public override async void OnAppearing() { base.OnAppearing(); this.IsBusy = true; var dialog = Database.Instance().GetDialog(dialogId); var opponentId = dialog.OccupantIds.Split(',').Select(Int32.Parse).First(id => id != App.QbProvider.UserId); privateChatManager = App.QbProvider.GetXmppClient().GetPrivateChatManager(opponentId, dialogId); privateChatManager.MessageReceived += OnMessageReceived; DialogName = dialog.Name; ImageSource = new BitmapImage(new Uri("ms-appx:///Assets/privateholder.png")); this.opponentUsers = new List<User>(); var users = await App.QbProvider.GetUsersByIdsAsync(dialog.OccupantIds); var opponentUser = users.FirstOrDefault(u => u.Id != App.QbProvider.UserId); if (opponentUser != null) { this.opponentUsers.Add(opponentUser); if (opponentUser.BlobId.HasValue) { var bytes = await App.QbProvider.GetImageAsync(opponentUser.BlobId.Value); BitmapImage image = new BitmapImage(); using (InMemoryRandomAccessStream stream = new InMemoryRandomAccessStream()) { await stream.WriteAsync(bytes.AsBuffer()); stream.Seek(0); await image.SetSourceAsync(stream); } } } await this.LoadMessages(); this.IsBusy = false; }