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();
        }
示例#2
0
        public static void SendPendingNuntii()
        {
            while (SendPendingNuntiiTaskGoing)
            {
                Thread.Sleep(500);
                continue;
            }
            SendPendingNuntiiTaskGoing = true;
            List <Nuntias> pendingNuntiiList = NuntiasRepository.Instance.GetAllPendingPendingNuntiiList();

            if (pendingNuntiiList == null)
            {
                Universal.ShowErrorMessage("Error in accessing user data!");
                return;
            }
            Dictionary <long, long?> universalIdMapAgainstTmpId = new Dictionary <long, long?>();
            List <long> toBeDeleted = new List <long>();

            foreach (Nuntias tmpNuntias in pendingNuntiiList)
            {
                if (tmpNuntias.Id == 0)
                {
                    continue;
                }
                long localNuntiasId     = (long)tmpNuntias.Id;
                long?universalNuntiasId = null;
                if (tmpNuntias.ContentFileId == null || tmpNuntias.ContentFileId.Length == 0)
                {
                    universalNuntiasId = ServerRequest.SendNewNuntias(tmpNuntias);
                }
                else
                {
                    universalNuntiasId = ServerFileRequest.SendContentedNuntias(tmpNuntias);
                }
                if (universalNuntiasId == null || universalNuntiasId == 0)
                {
                    continue;
                }
                tmpNuntias.Id = (long)universalNuntiasId;
                NuntiasRepository.Instance.Insert(tmpNuntias);
                SyncAssets.ConvertLocalNuntiasToGlobal(tmpNuntias, localNuntiasId);
                toBeDeleted.Add(localNuntiasId);
            }
            NuntiasRepository.Instance.DeleteTmpNuntii(toBeDeleted);
            SendPendingNuntiiTaskGoing = false;
        }
        private void LoadPerviousNuntiasList()
        {
            VisualizingTools.ShowWaitingAnimation(new Point(this.Width / 4, this.conversationTitleBar.Bottom + 30), new Size(this.Width / 2, 10), this);
            BackgroundWorker loaderWorker = new BackgroundWorker();

            loaderWorker.DoWork += (s, e) =>
            {
                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;
                }

                List <Nuntias> previousNuntii        = ConversationRepository.Instance.GetLastNuntias(this.theConversation);
                List <Nuntias> previousPendingNuntii = ConversationRepository.Instance.GetPendingNuntii(this.theConversation);
                previousNuntii.AddRange(previousPendingNuntii);

                if (previousNuntii != null && previousNuntii.Count > 0)
                {
                    foreach (Nuntias item in previousNuntii)
                    {
                        SyncAssets.NuntiasSortedList[item.Id] = item;
                        if (item.Id > 0)
                        {
                            ServerFileRequest.DownloadAndStoreContentFile(item);
                        }
                        this.ShowNuntias(item, false);
                    }
                }
                this.ConversationPanelLoadingOk = true;
            };
            loaderWorker.RunWorkerCompleted += (s, e) => { VisualizingTools.HideWaitingAnimation(); loaderWorker.Dispose(); };
            loaderWorker.RunWorkerAsync();
        }
        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);
                }
            }
                                                                       );
        }