public void ChangeProfilePicture() { OpenFileDialog fileDialog = new OpenFileDialog(); fileDialog.Filter = "Image Files (JPG, JPEG, PNG)|*.jpg;*.jpeg;*.png"; fileDialog.InitialDirectory = FileResources.WindowsPicturePath; fileDialog.ShowDialog(); if (fileDialog.FileName.Length == 0) { return; } BackgroundWorker loaderWorker = new BackgroundWorker(); loaderWorker.DoWork += (s, e) => { Image gotImg = Image.FromFile(fileDialog.FileName); string profileImgId = ServerFileRequest.ChangeProfileImage(gotImg); if (profileImgId != null) { Universal.ParentForm.Invoke(new Action(() => { Consumer.LoggedIn.ProfileImage = LocalDataFileAccess.GetProfileImgFromLocalData(profileImgId); userProfilePictureLabel.Image = this.ResizedProfileImage; })); } gotImg.Dispose(); }; loaderWorker.RunWorkerCompleted += (s, e) => { VisualizingTools.HideWaitingAnimation(); loaderWorker.Dispose(); }; loaderWorker.RunWorkerAsync(); }
internal static void Logout() { SplashScreen sp = new SplashScreen(); sp.Show(); ServerHub.WorkingInstance.StopConnection(); if (Universal.ParentForm.InvokeRequired) { Universal.ParentForm.Invoke(new MethodInvoker(delegate { Logout(); return; })); } else { try { SlidebarPanel.MySidebarPanel.Dispose(); ConversationPanel.CurrentDisplayedConversationPanel.Dispose(); LocalDataFileAccess.EraseCurrentLoginCookie(); } catch { } Application.Restart(); } }
public static long?SendContentedNuntias(Nuntias newNuntias) { JObject nuntiasJsonData = newNuntias.ToJson(); nuntiasJsonData["sender_mac_address"] = Universal.SystemMACAddress; long? nuntiasId = null; string filePath = LocalDataFileAccess.GetFilePathInLocalData(newNuntias.ContentFileId); if (filePath == null) { return(null); } byte[] fileByte = Universal.FileToByteArray(filePath); KeyValuePair <JObject, byte[]> nuntiasData = new KeyValuePair <JObject, byte[]>(nuntiasJsonData, fileByte); ServerHub.WorkingInstance.ServerHubProxy.Invoke <long>("SendContentedNuntias", nuntiasData).ContinueWith(task => { if (!task.IsFaulted) { nuntiasId = task.Result; } else { Console.WriteLine(task.IsFaulted); } }).Wait(); return(nuntiasId); }
public static bool RefetchProfileImage(string profileImageId) { try { if (!LocalDataFileAccess.ProfileImgExistsInLocalData(profileImageId)) { if (profileImageId == null || profileImageId.Length == 0) { return(false); } string fileLink = "http://" + ConfigurationManager.AppSettings["serverIp"] + ":" + ConfigurationManager.AppSettings["xamppPort"] + "/ProfileImages/" + profileImageId; Console.WriteLine("ServerFileRequest.cs line 85: " + fileLink); string targetLocalPath = FileResources.ProfileImgFolderPath + profileImageId; using (WebClient webClient = new WebClient()) { webClient.DownloadFile(fileLink, targetLocalPath); } } return(true); } catch (Exception ex) { Console.WriteLine("ServerFileRequest:RefetchProfileImage() => Exception: " + ex.Message); return(false); } }
public static string ChangeProfileImage(Image gotImg) { using (Bitmap roundedBmp = new Bitmap(GraphicsStudio.ClipToCircle(gotImg), new Size(200, 200))) { JObject profileImgIdJson = null; byte[] imgByteArray = Universal.ImageToByteArray(roundedBmp, gotImg.RawFormat); ServerHub.WorkingInstance.ServerHubProxy.Invoke <JObject>("ChangeProfileImage", Consumer.LoggedIn.Id, imgByteArray).ContinueWith(task => { if (!task.IsFaulted) { profileImgIdJson = task.Result; } }).Wait(); if (profileImgIdJson == null) { return(null); } try { string oldProfileImgId = profileImgIdJson["old_image_id"].ToString(); if (oldProfileImgId != null && oldProfileImgId.Length > 5) { LocalDataFileAccess.EraseOldProfileImageFromLocalData(oldProfileImgId); } string newImgId = profileImgIdJson["new_image_id"].ToString(); LocalDataFileAccess.SaveProfileImageToLocal(roundedBmp, newImgId); return(newImgId); } catch (Exception e) { Console.WriteLine("Error occured in ChangeProfileImage() => " + e.Message); return(null); } } }
private void ResetUserData() { LocalDataFileAccess.ResetUserData(); string usersDbPassword = DatabaseAccess.LocalDbPassword; DatabaseAccess.LocalDbPassword = null; this.ChangeLocalDataBasePassword(usersDbPassword); }
public static void SaveLoginCookie() { JObject credentialsJson = new JObject(); credentialsJson["mac_address"] = Universal.SystemMACAddress; credentialsJson["password"] = BackendManager.Password; credentialsJson["last_login_time"] = Time.CurrentTime.TimeStampString; LocalDataFileAccess.CreateNewLoginCoockie(MathLaboratory.MatrixCryptography.Encrypt(credentialsJson.ToString())); }
public bool SetProfileImage(string profileImageId) { if (LocalDataFileAccess.ProfileImgExistsInLocalData(profileImageId)) { this.profileImageId = profileImageId; this.profileImage = LocalDataFileAccess.GetProfileImgFromLocalData(this.profileImageId); return(true); } return(false); }
public static JObject ValidLoginCookieData(string nativeMacAddress) { List <double> encryptedCredentials = LocalDataFileAccess.GetCredentialsFromLoginCookie(); if (encryptedCredentials != null) { JObject cookieDataJson = JObject.Parse(MathLaboratory.MatrixCryptography.Decrypt(encryptedCredentials)); string deviceMac = cookieDataJson["mac_address"].ToString(); string password = cookieDataJson["password"].ToString(); string lastActiveTimeStamp = cookieDataJson["last_login_time"].ToString(); if (deviceMac == nativeMacAddress) { return(cookieDataJson); } } return(null); }
public static void LoginProcessRun() //works as expected { bool?macExists = ServerRequest.MacAddressExists(Universal.SystemMACAddress); if (macExists == false) { if (Universal.ParentForm.InvokeRequired) { Universal.ParentForm.Invoke(new MethodInvoker(delegate { Universal.ParentForm.Controls.Add(new SignupPanel(Universal.ParentForm)); SplashScreen.Instance.Hide(); })); } else { Universal.ParentForm.Controls.Add(new SignupPanel(Universal.ParentForm)); SplashScreen.Instance.Hide(); } return; } else if (macExists == null) { if (Universal.ParentForm.InvokeRequired) { Universal.ParentForm.Invoke(new MethodInvoker(delegate { MessageBox.Show(Universal.ParentForm, "Server connection failed", "error", MessageBoxButtons.OK, MessageBoxIcon.Error); })); } else { MessageBox.Show(Universal.ParentForm, "Server connection failed", "error", MessageBoxButtons.OK, MessageBoxIcon.Error); } return; } JObject localCookieJson = Checker.ValidLoginCookieData(Universal.SystemMACAddress); if (localCookieJson != null && (Time.TimeDistanceInMinute(new Time(localCookieJson["last_login_time"].ToString()), Time.CurrentTime) > 4320 || localCookieJson["mac_address"].ToString() != Universal.SystemMACAddress)) { LocalDataFileAccess.EraseCurrentLoginCookie(); localCookieJson = null; } if (localCookieJson == null) { int?userVerifiedOrPasswordIsSet = ServerRequest.UserVerifiedOrPasswordIsSet(Universal.SystemMACAddress); if (userVerifiedOrPasswordIsSet == 0) //0 means user is not verified { if (Universal.ParentForm.InvokeRequired) { Universal.ParentForm.Invoke(new MethodInvoker(ShowEmailVerificationInputPanel)); } else { ShowEmailVerificationInputPanel(); } } else if (userVerifiedOrPasswordIsSet == 1) //1 means user verified but password is not set { if (Universal.ParentForm.InvokeRequired) { Universal.ParentForm.Invoke(new MethodInvoker(ShowPasswordSetupPanel)); } else { ShowPasswordSetupPanel(); } } else if (userVerifiedOrPasswordIsSet == 2) //2 means user is verified and password is set { if (Universal.ParentForm.InvokeRequired) { Universal.ParentForm.Invoke(new MethodInvoker(ShowPasswordEnterPanel)); } else { ShowPasswordEnterPanel(); } } else if (userVerifiedOrPasswordIsSet == null) { Universal.ShowErrorMessage("Server connection failed!"); } } else { bool?loginSuccess = ServerRequest.LoginWithCookie(localCookieJson); if (loginSuccess == true) { BackendManager.Password = localCookieJson["password"].ToString(); BackendManager.SaveLoginCookie(); BackendManager.LoginNow(User.LoggedIn); SplashScreen.Instance.Hide(); } else if (loginSuccess == false) { LocalDataFileAccess.EraseCurrentLoginCookie(); LoginProcessRun(); } else { MessageBox.Show("Server connection failed!"); } } }
private void SendChoosenFile(string choosenSafeFileName, string localPath, string extension) { if (File.ReadAllBytes(localPath).Length > 1024 * 1024 * 5) { Universal.ShowErrorMessage("Please choose a file below 5 MB."); return; } this.sendFileButton.Visible = false; this.cancelFileButton.Visible = false; int animationLeft = 0, animationPadding = 40; if (imgPreview != null) { animationLeft = imgPreview.Right + animationPadding; } else { animationLeft = Math.Max(animationLeft, fileNameLabel.Right + animationPadding); } VisualizingTools.ShowWaitingAnimation(new Point(animationLeft, (filePreviewPanel.Height - sendButton.Height / 2) / 2), new Size(this.filePreviewPanel.Right - animationLeft - animationPadding - 20, sendButton.Height / 2), filePreviewPanel); BackgroundWorker loaderWorker = new BackgroundWorker(); loaderWorker.DoWork += (s, e) => { try { using (FileStream gotFileStream = new FileStream(localPath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite)) { string fileIdName = this.theConversation.ConversationID + "_" + Universal.SystemMACAddress + "_" + Time.CurrentTime.TimeStampString + "-" + choosenSafeFileName; MemoryStream gotFileMemoryStream = new MemoryStream(); gotFileStream.CopyTo(gotFileMemoryStream); bool storeToLocalSucceed = LocalDataFileAccess.SaveNuntiasContentToLocal(gotFileMemoryStream, fileIdName); if (storeToLocalSucceed) { if (this.theConversation == null) { long?conversationId = ServerRequest.GetDuetConversationId(User.LoggedIn, this.receiver); if (conversationId == null) { MessageBox.Show("Server connection failed!\r\nPlease retry."); return; } this.TheConversation = new DuetConversation(Consumer.LoggedIn, this.receiver); this.TheConversation.ConversationID = (long)conversationId; } Nuntias newNuntias = new Nuntias("File: " + choosenSafeFileName, Consumer.LoggedIn.Id, Time.CurrentTime, this.theConversation.ConversationID); newNuntias.ContentFileId = fileIdName; if (extension == ".jpg" || extension == ".jpeg" || extension == ".png" || extension == ".gif" || extension == ".bmp") { newNuntias.Text = "Image : " + choosenSafeFileName; } long?nuntiasTmpID = NuntiasRepository.Instance.StoreTmpNuntias(newNuntias); if (nuntiasTmpID == null) { newNuntias = null; } else { newNuntias.Id = nuntiasTmpID ?? 0; } if (newNuntias == null) { return; } this.ShowNuntias(newNuntias, true); BackendManager.SendPendingNuntii(); string localStoredPath = LocalDataFileAccess.GetContentPathFromLocalData(fileIdName); Universal.ParentForm.Invoke(new Action(() => { VisualizingTools.HideWaitingAnimation(); if (localStoredPath != null) { this.FilePreviewPanelHeight(0); } else { Universal.ShowErrorMessage("Failed to send the file!"); } })); gotFileStream.Close(); gotFileMemoryStream.Dispose(); loaderWorker.Dispose(); this.DisposeUnmanaged(); } } } catch (Exception ex) { Console.WriteLine("Error occured while sending a file: " + ex.Message); }; }; loaderWorker.RunWorkerAsync(); loaderWorker.RunWorkerCompleted += (s, e) => { loaderWorker.Dispose(); }; if (ConversationListPanel.MyConversationListPanel != null) { ConversationListPanel.MyConversationListPanel.RefreshConversationList(); } }
public static void DownloadAndStoreContentFile(Nuntias nuntias) { if (nuntias.ContentFileId == null || nuntias.ContentFileId == "deleted" || nuntias.ContentFileId.Length == 0 || LocalDataFileAccess.ContentExistsInLocalData(nuntias.ContentFileId)) { return; } try { string fileLink = "http://" + ConfigurationManager.AppSettings["serverIp"] + ":" + ConfigurationManager.AppSettings["xamppPort"] + "/ContentFiles/" + nuntias.Id; Console.WriteLine("ServerFileRequest.cs line 107: " + fileLink); string targetLocalPath = FileResources.NuntiasContentFolderPath + nuntias.ContentFileId; using (WebClient webClient = new WebClient()) { webClient.DownloadFile(fileLink, targetLocalPath); } } catch (Exception ex) { Console.WriteLine("Exception in ServerFileRequest:DownloadAndStoreContentFile() => " + ex.Message); } }
private void ShowNuntiasTasks(Nuntias nuntias, bool playConversationInnerSound, string processesedText) { bool nuntiasIsImage = (nuntias.ContentFileId != null && nuntias.ContentFileId.Length > 0 && nuntias.Text.Length >= 5 && nuntias.Text.Substring(0, 5) == "Image"); //Nuntias.Text format for image file is 'Image: image_file_name' SyncAssets.NuntiasSortedList[nuntias.Id] = nuntias; if (playConversationInnerSound) { ConversationPanel.newMessageSound.Play(); } bool newTimeStampShowed = this.ShowTimeStampIfNecessary(nuntias); bool profileImageShowed = this.ShowProfileImageIfNecessary(nuntias, newTimeStampShowed); LinkLabel nuntiasLabel = SyncAssets.ShowedNuntiasLabelSortedList[nuntias.Id] = new LinkLabel(); nuntiasLabel.Name = nuntias.Id.ToString(); nuntiasLabel.LinkArea = new LinkArea(0, 0); if (nuntias.ContentFileId != null && nuntias.ContentFileId.Length > 0) { try { if (nuntias.ContentFileId == "deleted") { nuntiasLabel.Text = processesedText; nuntiasLabel.ForeColor = Color.FromArgb(95, 95, 95); nuntiasLabel.Padding = new Padding(7, 7, 7, 7); nuntiasLabel.Font = CustomFonts.New(CustomFonts.SmallerSize, 'i'); nuntiasLabel.Size = nuntiasLabel.PreferredSize; } else { string contentFilePath = LocalDataFileAccess.GetContentPathFromLocalData(nuntias.ContentFileId); if (nuntiasIsImage) { if (contentFilePath != null) { using (FileStream imgStream = new FileStream(contentFilePath, FileMode.Open)) { Image img = Image.FromStream(imgStream); nuntiasLabel.Image = new Bitmap(img, new Size((int)((150.0 / img.Height) * img.Width), 150)); img.Dispose(); imgStream.Close(); nuntiasLabel.Size = nuntiasLabel.Image.Size; } } nuntiasLabel.Padding = new Padding(7, 7, 7, 7); } else { nuntiasLabel.Text = processesedText; nuntiasLabel.LinkArea = new LinkArea(6, nuntiasLabel.Text.Length - 6); nuntiasLabel.LinkColor = Color.FromArgb(94, 92, 0); nuntiasLabel.LinkClicked += delegate(Object sender, LinkLabelLinkClickedEventArgs e) { try { Process.Start(contentFilePath); nuntiasLabel.LinkVisited = true; } catch { Universal.ShowErrorMessage("Failed to open the file!"); } }; nuntiasLabel.ForeColor = Color.FromArgb(95, 95, 95); nuntiasLabel.Padding = new Padding(7, 7, 7, 7); nuntiasLabel.Font = CustomFonts.New(CustomFonts.SmallerSize, 'i'); nuntiasLabel.Size = nuntiasLabel.PreferredSize; } } } catch (Exception e) { Console.WriteLine("Exception occured in conversation panel ShowNuntias() method due to: " + e.Message + " exception type " + e.GetType()); } } else { nuntiasLabel.Text = processesedText; Universal.SetLinkAreaIfLinkFound(nuntiasLabel); nuntiasLabel.LinkClicked += delegate(Object sender, LinkLabelLinkClickedEventArgs e) { try { Process.Start(e.Link.LinkData.ToString());; e.Link.Visited = true; } catch { Universal.ShowErrorMessage("Failed to open the link!"); } }; nuntiasLabel.Font = CustomFonts.Smaller; nuntiasLabel.Padding = new Padding(7, 7, 7, 7); nuntiasLabel.Size = nuntiasLabel.PreferredSize; } if (!nuntiasIsImage && nuntias.ContentFileId != "deleted") { if (nuntias.SenderId == Consumer.LoggedIn.Id) { nuntiasLabel.BackColor = Color.FromArgb(231, 255, 234); } else { nuntiasLabel.BackColor = Color.FromArgb(229, 231, 255); } } if (profileImageShowed) { nuntiasLabel.Top = this.lastShowedLabel.Bottom - this.profileImageSize.Height + 5; } else if (this.lastShowedNuntias == null || this.lastShowedNuntias.SenderId != nuntias.SenderId) { nuntiasLabel.Top = this.lastShowedLabel.Bottom + 25; } else { nuntiasLabel.Top = this.lastShowedLabel.Bottom + 5; } if (nuntias.SenderId == Consumer.LoggedIn.Id) { nuntiasLabel.Left = this.selfProfileImageLocation.X - nuntiasLabel.Width - this.profileImageSize.Width / 4; } else { nuntiasLabel.Left = this.othersProfileImageLocation.X + this.profileImageSize.Width + this.profileImageSize.Width / 4; } this.nuntiasBossPanel.Controls.Add(nuntiasLabel); this.lastShowedNuntias = nuntias; this.lastShowedLabel = nuntiasLabel; int x = 0; Timer makeXzeroTimer = new Timer() { Interval = 500 }; makeXzeroTimer.Tick += delegate(Object sender, EventArgs e) { x = 0; }; NuntiasInfoPanel respectiveInfoPanel = null; NuntiasOptionsPanel respectiveOptionPanel = null; if (nuntias.ContentFileId != "deleted") { respectiveInfoPanel = SyncAssets.NuntiasInfoPanelSortedList[nuntias.Id] = new NuntiasInfoPanel(nuntias.Id); this.nuntiasBossPanel.Controls.Add(respectiveInfoPanel); respectiveOptionPanel = SyncAssets.NuntiasOptionPanelSortedList[nuntias.Id] = new NuntiasOptionsPanel(nuntias.Id); this.nuntiasBossPanel.Controls.Add(respectiveOptionPanel); } nuntiasLabel.MouseEnter += (s, me) => { if (nuntiasIsImage) { return; } Color current = ((Label)s).BackColor; if (current == Color.Transparent) { return; } ((Label)s).BackColor = Color.FromArgb(current.R - 25, current.G - 25, current.B - 25); }; nuntiasLabel.MouseLeave += (s, me) => { if (nuntiasIsImage) { return; } Color current = ((Label)s).BackColor; if (current == Color.Transparent) { return; } ((Label)s).BackColor = Color.FromArgb(current.R + 25, current.G + 25, current.B + 25); }; nuntiasLabel.MouseClick += delegate(Object sender, MouseEventArgs e) { if (respectiveOptionPanel == null) { return; } if (respectiveInfoPanel == null) { return; } if (e.Button == MouseButtons.Left) { if (nuntias.ContentFileId != null && nuntias.ContentFileId.Length > 0) { makeXzeroTimer.Start(); x++; } if (x == 2) { if (nuntias.ContentFileId != null && nuntias.ContentFileId.Length > 0) { try { Process.Start(LocalDataFileAccess.GetFilePathInLocalData(nuntias.ContentFileId)); } catch { Universal.ShowErrorMessage("Failed to open the file!"); } } makeXzeroTimer.Stop(); x = 0; } if (respectiveOptionPanel.Visible) { respectiveOptionPanel.ChangeNuntiasOptionPanelState(); } respectiveInfoPanel.ChangeNuntiasInfoPanelState(); this.OnClick(sender, e); } else { if (respectiveInfoPanel.Visible) { respectiveInfoPanel.ChangeNuntiasInfoPanelState(); } respectiveOptionPanel.ChangeNuntiasOptionPanelState(); this.OnClick(sender, e); } }; Label keepSpaceAtBottom = new Label(); keepSpaceAtBottom.Location = new Point(0, this.lastShowedLabel.Bottom + 25); keepSpaceAtBottom.Size = new Size(0, 0); this.nuntiasBossPanel.Controls.Add(keepSpaceAtBottom); FilePreviewPanelHeight(0); this.nuntiasBossPanel.VerticalScroll.Value = this.nuntiasBossPanel.VerticalScroll.Maximum; }
private void ShowConversationsInPanel() { // here conversationDetailsPanel works only for duetConversations. fix it later. if (this.conversationHeaderJsonList.Count > 0) { try { this.Controls.Remove(emptyConversationWarnPanel); emptyConversationWarnPanel.Dispose(); } catch { }; } previousConversationBottom = 0; int allowedCharsOnNameLabel = 30, allowedCharsOnLastNuntiasLabel = 37; if (this.singleConversationPanelList == null) { this.singleConversationPanelList = new Dictionary <string, Panel>(); } if (this.conversationDetailsPanelList == null) { this.conversationDetailsPanelList = new Dictionary <string, Panel>(); } if (this.singleConversationIconLabelList == null) { this.singleConversationIconLabelList = new Dictionary <string, Label>(); } if (this.singleConversationNameLabelList == null) { this.singleConversationNameLabelList = new Dictionary <string, Label>(); } if (this.singleConversationLastNuntiasLabelList == null) { this.singleConversationLastNuntiasLabelList = new Dictionary <string, Label>(); } foreach (KeyValuePair <string, Panel> item in this.singleConversationPanelList) { item.Value.Name = "invalid"; } SortedList <string, JObject> validConversationHeaderJsonList = new SortedList <string, JObject>(); foreach (JObject chatJson in conversationHeaderJsonList) { Panel currentConversationTitlePanel; long conversationId = (long)chatJson["id"]; if (!this.singleConversationPanelList.ContainsKey(conversationId.ToString())) { this.singleConversationPanelList[chatJson["id"].ToString()] = new Panel(); currentConversationTitlePanel = this.singleConversationPanelList[conversationId.ToString()]; this.Controls.Add(currentConversationTitlePanel); currentConversationTitlePanel.Width = this.parent.Width; Consumer consumer = ServerRequest.GetConsumer((long)chatJson["other_member_id"]); Panel conversationDetailsPanel = this.conversationDetailsPanelList[conversationId.ToString()] = new UserProfilePanel(consumer, this); conversationDetailsPanel.Visible = false; this.Controls.Add(conversationDetailsPanel); Label conversationIconLabel = singleConversationIconLabelList[conversationId.ToString()] = new Label(); conversationIconLabel.Image = new Bitmap(LocalDataFileAccess.GetConversationImageFromLocalData(chatJson["icon_file_id"].ToString(), chatJson["type"].ToString()), 50, 50); conversationIconLabel.Size = conversationIconLabel.Image.Size; currentConversationTitlePanel.Height = conversationIconLabel.Height + 10; conversationIconLabel.Location = new Point(5, (currentConversationTitlePanel.Height - conversationIconLabel.Height) / 2); currentConversationTitlePanel.Controls.Add(conversationIconLabel); Label conversationNameLabel = singleConversationNameLabelList[conversationId.ToString()] = new Label(); conversationNameLabel.Text = chatJson["name"].ToString(); if (conversationNameLabel.Text.Length > allowedCharsOnNameLabel) { conversationNameLabel.Text = conversationNameLabel.Text.Substring(0, allowedCharsOnNameLabel) + "..."; } conversationNameLabel.Font = CustomFonts.Smaller; conversationNameLabel.Size = conversationNameLabel.PreferredSize; conversationNameLabel.Location = new Point(conversationIconLabel.Right + 5, 5); currentConversationTitlePanel.Controls.Add(conversationNameLabel); Label lastNuntiasLabel = singleConversationLastNuntiasLabelList[conversationId.ToString()] = new Label(); if (chatJson.ContainsKey("last_text")) { lastNuntiasLabel.Text = chatJson["last_text"].ToString(); if (lastNuntiasLabel.Text.Length > allowedCharsOnLastNuntiasLabel) { lastNuntiasLabel.Text = lastNuntiasLabel.Text.Substring(0, allowedCharsOnLastNuntiasLabel) + "..."; } } lastNuntiasLabel.Font = CustomFonts.Smallest; if (chatJson["last_text_has_content"].ToString() == "true") { lastNuntiasLabel.Font = CustomFonts.New(CustomFonts.SmallestSize, 'i'); lastNuntiasLabel.ForeColor = Color.FromArgb(95, 95, 95); } lastNuntiasLabel.Size = lastNuntiasLabel.PreferredSize; lastNuntiasLabel.Location = new Point(conversationIconLabel.Right + 5, conversationNameLabel.Bottom + 5); currentConversationTitlePanel.Controls.Add(lastNuntiasLabel); currentConversationTitlePanel.Height = Math.Max(currentConversationTitlePanel.PreferredSize.Height, conversationIconLabel.Height) + 10; currentConversationTitlePanel.BackColor = Colors.DragengerTileColor; conversationIconLabel.Click += (s, e) => { this.conversationDetailsPanelList[conversationId.ToString()].Visible = true; }; conversationIconLabel.MouseEnter += (s, e) => { currentConversationTitlePanel.BackColor = Color.FromArgb(currentConversationTitlePanel.BackColor.R - 25, currentConversationTitlePanel.BackColor.G - 25, currentConversationTitlePanel.BackColor.B - 25); }; conversationIconLabel.MouseLeave += (s, e) => { currentConversationTitlePanel.BackColor = Color.FromArgb(currentConversationTitlePanel.BackColor.R + 25, currentConversationTitlePanel.BackColor.G + 25, currentConversationTitlePanel.BackColor.B + 25); }; conversationNameLabel.Click += (s, e) => { this.OpenConversation(ConversationRepository.Instance.Get(conversationId)); }; conversationNameLabel.MouseEnter += (s, e) => { currentConversationTitlePanel.BackColor = Color.FromArgb(currentConversationTitlePanel.BackColor.R - 25, currentConversationTitlePanel.BackColor.G - 25, currentConversationTitlePanel.BackColor.B - 25); }; conversationNameLabel.MouseLeave += (s, e) => { currentConversationTitlePanel.BackColor = Color.FromArgb(currentConversationTitlePanel.BackColor.R + 25, currentConversationTitlePanel.BackColor.G + 25, currentConversationTitlePanel.BackColor.B + 25); }; lastNuntiasLabel.Click += (s, e) => { this.OpenConversation(ConversationRepository.Instance.Get(conversationId)); }; lastNuntiasLabel.MouseEnter += (s, e) => { currentConversationTitlePanel.BackColor = Color.FromArgb(currentConversationTitlePanel.BackColor.R - 25, currentConversationTitlePanel.BackColor.G - 25, currentConversationTitlePanel.BackColor.B - 25); }; lastNuntiasLabel.MouseLeave += (s, e) => { currentConversationTitlePanel.BackColor = Color.FromArgb(currentConversationTitlePanel.BackColor.R + 25, currentConversationTitlePanel.BackColor.G + 25, currentConversationTitlePanel.BackColor.B + 25); }; currentConversationTitlePanel.Click += (s, e) => { if (ConversationPanel.CurrentDisplayedConversationPanel.TheConversation != null && ((DuetConversation)(ConversationPanel.CurrentDisplayedConversationPanel.TheConversation)).ConversationID == conversationId) { SlidebarPanel.MySidebarPanel.ChangeState(); return; } this.OpenConversation(ConversationRepository.Instance.Get(conversationId)); }; currentConversationTitlePanel.MouseEnter += (s, e) => { ((Panel)s).BackColor = Color.FromArgb(((Panel)s).BackColor.R - 25, ((Panel)s).BackColor.G - 25, ((Panel)s).BackColor.B - 25); }; currentConversationTitlePanel.MouseLeave += (s, e) => { ((Panel)s).BackColor = Color.FromArgb(((Panel)s).BackColor.R + 25, ((Panel)s).BackColor.G + 25, ((Panel)s).BackColor.B + 25); }; } else { currentConversationTitlePanel = this.singleConversationPanelList[conversationId.ToString()]; } currentConversationTitlePanel.Name = "valid"; validConversationHeaderJsonList[conversationId.ToString()] = chatJson; } List <string> invalidKeyList = new List <string>(); foreach (KeyValuePair <string, Panel> item in this.singleConversationPanelList) { if (item.Value.Name == "invalid") { this.Controls.Remove(item.Value); item.Value.Dispose(); invalidKeyList.Add(item.Key); } } foreach (string key in invalidKeyList) { this.singleConversationPanelList.Remove(key); this.singleConversationIconLabelList.Remove(key); this.singleConversationNameLabelList.Remove(key); this.singleConversationLastNuntiasLabelList.Remove(key); } var singleConversationPanelListRev = singleConversationPanelList.Reverse(); foreach (KeyValuePair <string, Panel> item in singleConversationPanelListRev) { Panel singleConversationPanel = item.Value; singleConversationPanel.Top = previousConversationBottom + 2; previousConversationBottom = singleConversationPanel.Bottom; conversationDetailsPanelList[item.Key].Location = singleConversationPanel.Location; JObject chatJson = validConversationHeaderJsonList[item.Key]; singleConversationIconLabelList[item.Key].Image = new Bitmap(LocalDataFileAccess.GetConversationImageFromLocalData(chatJson["icon_file_id"].ToString(), chatJson["type"].ToString()), new Size(50, 50)); singleConversationNameLabelList[item.Key].Text = chatJson["name"].ToString(); if (singleConversationNameLabelList[item.Key].Text.Length > allowedCharsOnNameLabel) { singleConversationNameLabelList[item.Key].Text = singleConversationNameLabelList[item.Key].Text.Substring(0, allowedCharsOnNameLabel) + "..."; } singleConversationNameLabelList[item.Key].Width = singleConversationNameLabelList[item.Key].PreferredWidth; if (chatJson.ContainsKey("last_text")) { Label lastNuntiasLabel = singleConversationLastNuntiasLabelList[item.Key]; lastNuntiasLabel.Text = chatJson["last_text"].ToString(); if (lastNuntiasLabel.Text.Length > allowedCharsOnLastNuntiasLabel) { lastNuntiasLabel.Text = lastNuntiasLabel.Text.Substring(0, allowedCharsOnLastNuntiasLabel) + "..."; } } singleConversationLastNuntiasLabelList[item.Key].Width = singleConversationLastNuntiasLabelList[item.Key].PreferredWidth; } this.Size = this.PreferredSize; foreach (JObject chatJson in conversationHeaderJsonList) { BackgroundWorker bworker = new BackgroundWorker(); bworker.DoWork += (s, e) => { if (chatJson["type"].ToString() == "duet") { ServerRequest.SyncConsumer((long)chatJson["other_member_id"]); ServerFileRequest.RefetchProfileImage(chatJson["icon_file_id"].ToString()); try { this.Invoke(new MethodInvoker(delegate { singleConversationIconLabelList[chatJson["id"].ToString()].Image = new Bitmap(LocalDataFileAccess.GetConversationImageFromLocalData(chatJson["icon_file_id"].ToString(), chatJson["type"].ToString()), new Size(50, 50)); })); } catch { } } }; bworker.RunWorkerAsync(); bworker.RunWorkerCompleted += (s, e) => { bworker.Dispose(); }; } }
public static void DefineServerToClientMethods() { ServerHub.WorkingInstance.ServerHubProxy.On <JObject>("SendNuntias", (nuntiasJson) => { Nuntias newNuntias = new Nuntias(nuntiasJson); if (newNuntias != null) { Console.WriteLine("SendNuntias() Called by server => " + newNuntias.Id + " " + newNuntias.ContentFileId); bool updatedNuntias = false; if (newNuntias.SenderId != Consumer.LoggedIn.Id && newNuntias.DeliveryTime == null) { newNuntias.DeliveryTime = Time.CurrentTime; updatedNuntias = true; } if (newNuntias.ContentFileId != null && newNuntias.ContentFileId.Length > 0) { if (newNuntias.ContentFileId == "deleted") { try { LocalDataFileAccess.EraseContentFile(SyncAssets.NuntiasSortedList[newNuntias.Id].ContentFileId); } catch { } } else { ServerFileRequest.DownloadAndStoreContentFile(newNuntias); } } bool?updateResult = NuntiasRepository.Instance.Update(newNuntias); if (updateResult == false) { long?result = NuntiasRepository.Instance.Insert(newNuntias); if (result == null) { return; } try { if (ConversationListPanel.MyConversationListPanel != null) { ConversationListPanel.MyConversationListPanel.RefreshConversationList(); } if (ConversationPanel.CurrentDisplayedConversationPanel.TheConversation.ConversationID == newNuntias.NativeConversationID) { ConversationPanel.CurrentDisplayedConversationPanel.ShowNuntias(newNuntias, true); } } catch { } } else if (updateResult == true) { SyncAssets.UpdateNuntias(newNuntias); } if (updatedNuntias) { ServerRequest.UpdateNuntiasStatus(newNuntias); } } } ); ServerHub.WorkingInstance.ServerHubProxy.On("SendPendingNuntias", () => { Console.WriteLine("SendPendingNuntias() Called by server. "); BackendManager.SendPendingNuntii(); } ); ServerHub.WorkingInstance.ServerHubProxy.On <long, string>("UpdateUsersActivity", (userId, userActivity) => { try { if (ConversationPanel.CurrentDisplayedConversationPanel.TheConversation.Type == "duet" && ((DuetConversation)ConversationPanel.CurrentDisplayedConversationPanel.TheConversation).OtherMember.Id == userId) { ConversationPanel.CurrentDisplayedConversationPanel.UpdateUserActivity(userActivity); } } catch { } } ); ServerHub.WorkingInstance.ServerHubProxy.On <long, string>("SomethingBeingTypedForYou", (conversationId, messageText) => { try { if (ConversationPanel.CurrentDisplayedConversationPanel.TheConversation.ConversationID == conversationId) { if (Universal.ParentForm.InvokeRequired) { Universal.ParentForm.Invoke(new Action(() => { ConversationPanel.CurrentDisplayedConversationPanel.SomethingBeingTypedLabel.Text = messageText; ConversationPanel.CurrentDisplayedConversationPanel.AdjustTypingBarSize(); })); } else { ConversationPanel.CurrentDisplayedConversationPanel.SomethingBeingTypedLabel.Text = messageText; ConversationPanel.CurrentDisplayedConversationPanel.AdjustTypingBarSize(); } } } catch (Exception ex) { Console.WriteLine("Exception in SomethingBeingTypedForYou() => : " + ex.Message); } } ); }
public NuntiasOptionsPanel(long nuntiasId) { this.nuntiasId = nuntiasId; Nuntias nuntias = SyncAssets.NuntiasSortedList[this.nuntiasId]; this.parentNuntiasLabel = SyncAssets.ShowedNuntiasLabelSortedList[nuntias.Id]; this.BackColor = Color.FromArgb(51, 51, 51); this.ForeColor = Color.FromArgb(220, 220, 220); if (nuntias.SenderId == Consumer.LoggedIn.Id) { this.Name = "own"; } else { this.Name = "other"; } copyNuntiasTextLabel = new Label(); deleteNuntiasLabel = new Label(); this.Controls.Add(copyNuntiasTextLabel); this.Controls.Add(deleteNuntiasLabel); copyNuntiasTextLabel.Text = ""; copyNuntiasTextLabel.Image = copyIcon; copyNuntiasTextLabel.ImageAlign = ContentAlignment.MiddleLeft; copyNuntiasTextLabel.TextAlign = ContentAlignment.MiddleRight; copyNuntiasTextLabel.Font = CustomFonts.Smallest; copyNuntiasTextLabel.Size = labelSize; copyNuntiasTextLabel.MouseEnter += (s, e) => { copyNuntiasTextLabel.BackColor = Color.FromArgb(128, 128, 128); }; copyNuntiasTextLabel.MouseLeave += (s, e) => { copyNuntiasTextLabel.BackColor = Color.Transparent; }; copyNuntiasTextLabel.Click += (s, e) => { if (nuntias.ContentFileId == null || nuntias.ContentFileId.Length == 0) { Clipboard.SetText(nuntias.Text); } else if (nuntias.Text.Length >= 5 && nuntias.Text.Substring(0, 5) == "Image") { Clipboard.SetImage(Image.FromFile(LocalDataFileAccess.GetContentPathFromLocalData(nuntias.ContentFileId))); } else if (nuntias.Text.Length >= 4 && nuntias.Text.Substring(0, 4) == "File") { StringCollection paths = new StringCollection(); paths.Add(LocalDataFileAccess.GetContentPathFromLocalData(nuntias.ContentFileId)); Clipboard.SetFileDropList(paths); } this.ChangeNuntiasOptionPanelState(); }; copyNuntiasTextLabel.Visible = false; deleteNuntiasLabel.Text = ""; deleteNuntiasLabel.Image = deleteIcon; deleteNuntiasLabel.ImageAlign = ContentAlignment.MiddleLeft; deleteNuntiasLabel.TextAlign = ContentAlignment.MiddleRight; deleteNuntiasLabel.Font = CustomFonts.Smallest; deleteNuntiasLabel.Size = labelSize; deleteNuntiasLabel.MouseEnter += (s, e) => { deleteNuntiasLabel.BackColor = Color.FromArgb(128, 128, 128); }; deleteNuntiasLabel.MouseLeave += (s, e) => { deleteNuntiasLabel.BackColor = Color.Transparent; }; deleteNuntiasLabel.Click += (s, e) => { if (nuntias.SenderId == Consumer.LoggedIn.Id && Time.TimeDistanceInSecond(Time.CurrentTime, nuntias.SentTime) <= 300) { //server allows deletion of a message that was sent 5 minutes ago or later. DialogResult result = MessageBox.Show("Delete the message from both side?\r\nClick Yes. Else click No.", "Message Deletion", MessageBoxButtons.YesNoCancel); if (result == DialogResult.Yes || result == DialogResult.No) { BackgroundWorker bworker = new BackgroundWorker(); bworker.DoWork += (ss, ee) => { bool success = ServerRequest.DeleteNuntias(Consumer.LoggedIn.Id, this.NuntiasId, result == DialogResult.Yes); if (success && result == DialogResult.No) { SyncAssets.DeleteNuntiasAssets(this.NuntiasId); } }; bworker.RunWorkerAsync(); bworker.RunWorkerCompleted += (ss, ee) => { bworker.Dispose(); }; } else { return; } } else { DialogResult result = MessageBox.Show("Delete the message for you?", "Message Deletion", MessageBoxButtons.YesNo); if (result == DialogResult.Yes) { BackgroundWorker bworker = new BackgroundWorker(); bworker.DoWork += (ss, ee) => { bool success = ServerRequest.DeleteNuntias(Consumer.LoggedIn.Id, this.NuntiasId, false); if (success) { SyncAssets.DeleteNuntiasAssets(this.NuntiasId); } }; bworker.RunWorkerAsync(); bworker.RunWorkerCompleted += (ss, ee) => { bworker.Dispose(); }; } else { return; } } this.ChangeNuntiasOptionPanelState(); }; deleteNuntiasLabel.Visible = false; this.UpdateOptionPanel(); }