Example #1
0
        public void UpdateOptionPanel()
        {
            int     availableTop = 0;
            Nuntias nuntias      = SyncAssets.NuntiasSortedList[this.nuntiasId];

            if (nuntias.SentTime != null)
            {
                copyNuntiasTextLabel.Text = "Copy";
                if (copyNuntiasTextLabel.Text.Length > 0)
                {
                    availableTop = copyNuntiasTextLabel.Bottom;
                    copyNuntiasTextLabel.Visible = true;
                }
            }

            deleteNuntiasLabel.Text = "Delete";
            deleteNuntiasLabel.Top  = availableTop - 2;
            if (deleteNuntiasLabel.Text.Length > 0)
            {
                availableTop = deleteNuntiasLabel.Bottom;
                deleteNuntiasLabel.Visible = true;
            }

            this.Size    = this.PreferredSize;
            this.Visible = false;
        }
Example #2
0
        new public Conversation Get(long conversationID)
        {
            string          sql      = "SELECT * FROM DuetConversations where Id = " + conversationID;
            DatabaseAccess  instance = DatabaseAccess.Instance;
            SqlCeDataReader data     = instance.ReadSqlCeData(sql);

            if (data == null)
            {
                return(null);
            }
            string conversation_ID = null, username_1 = null, username_2 = null, lastNuntiasId = null;

            while (data.Read())
            {
                conversation_ID = data["ID"].ToString();
                username_1      = data["username_1"].ToString();
                username_2      = data["username_2"].ToString();
                lastNuntiasId   = data["Last_Nuntias_id"].ToString();
                break;
            }
            instance.Dispose();
            if (conversation_ID == null)
            {
                return(null);
            }
            //Consumer user1 = ConsumerRepository.Instance.GetConsumerByUsername(username_1);
            //Consumer user2 = ConsumerRepository.Instance.GetConsumerByUsername(username_2);
            Nuntias lastNuntias = NuntiasRepository.Instance.Get(long.Parse(lastNuntiasId));

            return(null); //new DuetConversation(conversation_ID, user1, user2, lastNuntias);
        }
        public string InsertContentedNuntias(Nuntias newNuntias, string file_id)
        {
            string sql       = "INSERT INTO Nuntias (text,sender_username,sent_time,Content_file_id,conversation_id) OUTPUT Inserted.Id values ('" + newNuntias.Text + "','" + newNuntias.SenderId + "','" + newNuntias.SentTime.DbFormat + "','" + file_id + "','" + newNuntias.NativeConversationID + "')";
            string NuntiasID = this.ExecuteSqlScalar(sql).ToString();

            return(NuntiasID);
        }
        //conversation and nuntias requests methods
        internal void SendNuntiasToConsumers(Nuntias newNuntias, string requestingMacAddress)
        {
            Output.ShowLog("SendNuntiasToConsumers() => " + newNuntias.ToJson());
            BackgroundWorker bworker = new BackgroundWorker();

            bworker.DoWork += (s, e) =>
            {
                try
                {
                    List <long> nuntiasOwnerIdList = NuntiasRepository.Instance.NuntiasOwnerIdList(newNuntias.Id);
                    foreach (long userId in nuntiasOwnerIdList)
                    {
                        Output.ShowLog(userId);
                        List <string> connectionIdList = LoggedInConnectionIdList(userId);
                        foreach (string connectionId in connectionIdList)
                        {
                            if (MacConnectionIdMap[requestingMacAddress] == connectionId)
                            {
                                continue;
                            }
                            Output.ShowLog("cm: " + userId + " " + connectionId);
                            ServerHub.WorkingHubInstance.Clients.Client(connectionId).SendNuntias(newNuntias.ToJson());
                        }
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine("Exception in SendNuntiasToConsumers() => " + ex.Message);
                }
            };
            bworker.RunWorkerAsync();
            bworker.RunWorkerCompleted += (s, e) => { bworker.Dispose(); };
        }
        public long?StoreTmpNuntias(Nuntias nuntias)
        {
            string nuntiasText = "NULL", contentFileId = "NULL";

            if (nuntias.Text != null && nuntias.Text.Length > 0)
            {
                nuntiasText = "'" + nuntias.Text + "'";
            }
            if (nuntias.ContentFileId != null && nuntias.ContentFileId.Length > 0)
            {
                contentFileId = "'" + nuntias.ContentFileId + "'";
            }
            string sql    = "INSERT INTO Nuntii_to_be_sent (text,Sender_id,Sent_time,Conversation_id,Content_Id) values (" + nuntiasText + "," + nuntias.SenderId + ",'" + nuntias.SentTime.DbFormat + "'," + nuntias.NativeConversationID + "," + contentFileId + ");";
            int?   result = this.ExecuteSqlCeQuery(sql);

            if (result == null || result == 0)
            {
                return(null);
            }
            SqlCeDataReader data = this.ReadSqlCeData("SELECT MAX(Temp_Id) as id FROM Nuntii_to_be_sent;");
            long?           nuntiasLocalTmpId = null;

            //nuntias.Id is given negative value so that is can be identified as localId.
            if (data.Read())
            {
                nuntiasLocalTmpId = -(long.Parse(data["id"].ToString()));
            }
            return(nuntiasLocalTmpId);
        }
        public bool?Update(Nuntias item)
        {
            string deliveryTimeStr = "NULL", seenTimeStr = "NULL", contentFileId = "NULL";

            if (item.DeliveryTime != null)
            {
                deliveryTimeStr = "'" + item.DeliveryTime.DbFormat + "'";
            }
            if (item.SeenTime != null)
            {
                seenTimeStr = "'" + item.SeenTime.DbFormat + "'";
            }
            if (item.ContentFileId != null && item.ContentFileId.Length > 0)
            {
                contentFileId = "'" + item.ContentFileId + "'";
            }
            string query   = "UPDATE Nuntii SET Text = '" + item.Text + "', Delivery_time = " + deliveryTimeStr + ", Seen_time = " + seenTimeStr + ", Content_Id = " + contentFileId + " where Id = " + item.Id;
            int?   success = this.ExecuteSqlCeQuery(query);

            if (success == null)
            {
                return(null);
            }
            return(success != 0);
        }
Example #7
0
        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);
        }
Example #8
0
        private bool ShowProfileImageIfNecessary(Nuntias nuntias, bool newTimeStampShowed)
        {
            if (this.lastShowedNuntias == null || this.lastShowedNuntias.SenderId != nuntias.SenderId)
            {
                Label profileImageLabel = new Label();
                profileImageLabel.Image = null;
                if (nuntias.SenderId == this.receiver.Id)
                {
                    profileImageLabel.Image = new Bitmap(this.receiver.ProfileImage, this.profileImageSize);
                }
                else if (nuntias.SenderId == Consumer.LoggedIn.Id)
                {
                    profileImageLabel.Image = new Bitmap(Consumer.LoggedIn.ProfileImage, this.profileImageSize);
                }
                profileImageLabel.Size = this.profileImageSize;
                if (nuntias.SenderId == Consumer.LoggedIn.Id)
                {
                    profileImageLabel.Left = this.selfProfileImageLocation.X;
                }
                else
                {
                    profileImageLabel.Left = this.othersProfileImageLocation.X;
                }
                if (newTimeStampShowed)
                {
                    profileImageLabel.Top = this.nuntiasBossPanel.PreferredSize.Height;
                }
                else
                {
                    profileImageLabel.Top = this.lastShowedLabel.Bottom + this.profileImageSize.Height;
                }

                Label keepSpaceAtBottom = new Label();
                keepSpaceAtBottom.Location = new Point(0, this.lastShowedLabel.Bottom + 25);
                keepSpaceAtBottom.Size     = new Size(0, 0);

                if (Universal.ParentForm.InvokeRequired)
                {
                    Universal.ParentForm.Invoke(new Action(() =>
                    {
                        this.nuntiasBossPanel.Controls.Add(profileImageLabel);
                        this.lastShowedLabel = profileImageLabel;
                        this.nuntiasBossPanel.Controls.Add(keepSpaceAtBottom);
                    }));
                }
                else
                {
                    this.nuntiasBossPanel.Controls.Add(profileImageLabel);
                    this.lastShowedLabel = profileImageLabel;
                    this.nuntiasBossPanel.Controls.Add(keepSpaceAtBottom);
                }

                return(true);
            }
            return(false);
        }
        public static void ConvertLocalNuntiasToGlobal(Nuntias updatedNuntias, long localNuntiasId)
        {
            try { SyncAssets.NuntiasSortedList.Remove(localNuntiasId); }
            catch { return; }
            SyncAssets.NuntiasSortedList[updatedNuntias.Id] = updatedNuntias;

            try
            {
                SyncAssets.ShowedNuntiasLabelSortedList[updatedNuntias.Id] = SyncAssets.ShowedNuntiasLabelSortedList[localNuntiasId];
                SyncAssets.ShowedNuntiasLabelSortedList[localNuntiasId]    = null;
                SyncAssets.ShowedNuntiasLabelSortedList.Remove(localNuntiasId);
            }
            catch { }

            try
            {
                NuntiasInfoPanel nuntiasInfoPanel = SyncAssets.NuntiasInfoPanelSortedList[updatedNuntias.Id] = SyncAssets.NuntiasInfoPanelSortedList[localNuntiasId];
                nuntiasInfoPanel.NuntiasId = updatedNuntias.Id;
                if (Universal.ParentForm.InvokeRequired)
                {
                    Universal.ParentForm.Invoke(new Action(() =>
                    {
                        nuntiasInfoPanel.UpdateInfoPanel();
                    }));
                }
                else
                {
                    nuntiasInfoPanel.UpdateInfoPanel();
                }
                SyncAssets.NuntiasInfoPanelSortedList[localNuntiasId] = null;
                SyncAssets.NuntiasInfoPanelSortedList.Remove(localNuntiasId);
            }
            catch { }

            try
            {
                NuntiasOptionsPanel nuntiasOptionPanel = SyncAssets.NuntiasOptionPanelSortedList[updatedNuntias.Id] = SyncAssets.NuntiasOptionPanelSortedList[localNuntiasId];
                nuntiasOptionPanel.NuntiasId = updatedNuntias.Id;
                if (Universal.ParentForm.InvokeRequired)
                {
                    Universal.ParentForm.Invoke(new Action(() =>
                    {
                        nuntiasOptionPanel.UpdateOptionPanel();
                    }));
                }
                else
                {
                    nuntiasOptionPanel.UpdateOptionPanel();
                }
                SyncAssets.NuntiasOptionPanelSortedList[localNuntiasId] = null;
                SyncAssets.NuntiasOptionPanelSortedList.Remove(localNuntiasId);
            }
            catch { }
        }
Example #10
0
        public bool UpdateNuntiasStatusToOwners(JObject nuntiasJsonData)
        {
            Output.ShowLog("UpdateNuntiasStatusToOwners() => " + nuntiasJsonData);
            Nuntias newNuntias = new Nuntias(nuntiasJsonData);
            bool?   success    = NuntiasRepository.Instance.UpdateNuntiasStatusTimes(newNuntias, (long)nuntiasJsonData["user_id"]);

            ClientManager.Instance.SendNuntiasToConsumers(newNuntias, Context.Headers["mac_address"]);
            if (success == true)
            {
                return(true);
            }
            return(false);
        }
        public NuntiasInfoPanel(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";
            }

            sentTimeLabel      = new Label();
            deliveredTimeLabel = new Label();
            seenTimeLabel      = new Label();

            this.Controls.Add(sentTimeLabel);
            this.Controls.Add(deliveredTimeLabel);
            this.Controls.Add(seenTimeLabel);

            sentTimeLabel.Text       = "";
            sentTimeLabel.Image      = sentIcon;
            sentTimeLabel.ImageAlign = ContentAlignment.MiddleLeft;
            sentTimeLabel.TextAlign  = ContentAlignment.MiddleRight;
            sentTimeLabel.Font       = CustomFonts.Smallest;
            sentTimeLabel.Size       = labelSize;
            sentTimeLabel.Visible    = false;

            deliveredTimeLabel.Text       = "";
            deliveredTimeLabel.Image      = deliveredIcon;
            deliveredTimeLabel.ImageAlign = ContentAlignment.MiddleLeft;
            deliveredTimeLabel.TextAlign  = ContentAlignment.MiddleRight;
            deliveredTimeLabel.Font       = CustomFonts.Smallest;
            deliveredTimeLabel.Size       = labelSize;
            deliveredTimeLabel.Visible    = false;

            seenTimeLabel.Text       = "";
            seenTimeLabel.Image      = seenIcon;
            seenTimeLabel.ImageAlign = ContentAlignment.MiddleLeft;
            seenTimeLabel.TextAlign  = ContentAlignment.MiddleRight;
            seenTimeLabel.Font       = CustomFonts.Smallest;
            seenTimeLabel.Size       = labelSize;
            seenTimeLabel.Visible    = false;

            this.UpdateInfoPanel();
        }
Example #12
0
        public long SendNewNuntias(JObject nuntiasJsonData)
        {
            Output.ShowLog("SendNewNuntias() => " + nuntiasJsonData);
            Nuntias newNuntias = new Nuntias(nuntiasJsonData);
            long?   nuntiasId  = NuntiasRepository.Instance.Insert(newNuntias);

            newNuntias.Id = nuntiasId ?? 0;
            if (newNuntias.Id > 0)
            {
                Output.ShowLog("Called " + newNuntias.Id);
                ClientManager.Instance.SendNuntiasToConsumers(newNuntias, Context.Headers["mac_address"]);
            }
            return(newNuntias.Id);
        }
        private void SendTypedNuntias()
        {
            string           rawText      = this.nuntiasTextBox.Text;
            BackgroundWorker loaderWorker = new BackgroundWorker();
            Nuntias          newNuntias   = null;

            loaderWorker.DoWork += (s, e) =>
            {
                try
                {
                    string processedText = Universal.ProcessValidMessageText(rawText);
                    if (processedText == null)
                    {
                        return;
                    }
                    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;
                    }
                    newNuntias = new Nuntias(processedText, User.LoggedIn.Id, Time.CurrentTime, this.theConversation.ConversationID);
                    long?nuntiasTmpID = NuntiasRepository.Instance.StoreTmpNuntias(newNuntias);
                    if (nuntiasTmpID == null)
                    {
                        return;
                    }
                    newNuntias.Id = nuntiasTmpID ?? 0;
                    SyncAssets.NuntiasSortedList[(long)nuntiasTmpID] = newNuntias;
                    this.Invoke(new Action(() =>
                    {
                        this.nuntiasTextBox.Clear();
                    }));
                    this.ShowNuntias(newNuntias, true);
                    BackendManager.SendPendingNuntii();
                }
                catch (Exception ex) { Console.WriteLine("Exception in SendTypedNuntias() => " + ex.Message); }
            };
            loaderWorker.RunWorkerAsync();
            loaderWorker.RunWorkerCompleted += (s, e) => { loaderWorker.Dispose(); };
            if (ConversationListPanel.MyConversationListPanel != null)
            {
                ConversationListPanel.MyConversationListPanel.RefreshConversationList();
            }
        }
 private static void NuntiasLocalUpdateWorks(Nuntias nuntias)
 {
     if (nuntias.ContentFileId == null || nuntias.ContentFileId.Length == 0 || nuntias.ContentFileId == "deleted")
     {
         SyncAssets.ShowedNuntiasLabelSortedList[nuntias.Id].Text = nuntias.Text;
         if (nuntias.ContentFileId == "deleted")
         {
             NuntiasLocalDeletionWorks(nuntias.Id);
             return;
         }
     }
     SyncAssets.NuntiasInfoPanelSortedList[nuntias.Id].UpdateInfoPanel();
     SyncAssets.NuntiasOptionPanelSortedList[nuntias.Id].UpdateOptionPanel();
 }
        internal List <Nuntias> GetNuntiasListByQuery(string query)
        {
            SqlCeDataReader reader = this.ReadSqlCeData(query);

            if (reader == null)
            {
                return(null);
            }
            List <Nuntias> nuntiasList = new List <Nuntias>();

            while (reader.Read())
            {
                try
                {
                    long?   id = null, senderId = null, conversationId = null;
                    string  text = null, contentPath = null;
                    Time    sentTime = null, deliveryTime = null, seenTime = null;
                    Nuntias nuntias = null;
                    id             = long.Parse(reader["id"].ToString());
                    text           = reader["Text"].ToString();
                    senderId       = long.Parse(reader["Sender_id"].ToString());
                    conversationId = long.Parse(reader["Conversation_id"].ToString());
                    if (reader["Sent_time"].ToString().Length > 0)
                    {
                        sentTime = new Time(DateTime.Parse(reader["Sent_time"].ToString()));
                    }
                    if (reader["delivery_time"].ToString().Length > 0)
                    {
                        deliveryTime = new Time(DateTime.Parse(reader["delivery_time"].ToString()));
                    }
                    if (reader["seen_time"].ToString().Length > 0)
                    {
                        seenTime = new Time(DateTime.Parse(reader["seen_time"].ToString()));
                    }
                    nuntias = new Nuntias((long)id, text, (long)senderId, sentTime, deliveryTime, seenTime, contentPath, (long)conversationId);
                    if (reader["Content_Id"].ToString().Length > 0)
                    {
                        nuntias.ContentFileId = reader["Content_Id"].ToString();
                    }
                    nuntiasList.Add(nuntias);
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                }
            }
            this.CloseConnection();
            return(nuntiasList);
        }
Example #16
0
        public long SendContentedNuntias(KeyValuePair <JObject, byte[]> nuntiasData)     //key contains the JsonObject, Value contains the file bytes
        {
            Output.ShowLog("SendContentedNuntias() => " + nuntiasData.Key + nuntiasData.Value.Length);
            Nuntias newNuntias = new Nuntias(nuntiasData.Key);
            long?   nuntiasId  = NuntiasRepository.Instance.Insert(newNuntias);

            newNuntias.Id = nuntiasId ?? 0;
            if (newNuntias.Id > 0)
            {
                Output.ShowLog("Called " + newNuntias.Id);
                ContentFileAccess.StoreNuntiasContentFile(nuntiasData.Value, newNuntias.Id);
                ClientManager.Instance.SendNuntiasToConsumers(newNuntias, Context.Headers["mac_address"]);
            }
            return(newNuntias.Id);
        }
        public bool?UpdateLastNuntias(Conversation conversation, Nuntias lastNuntias)
        {
            string sql     = "UPDATE DuetConversations set Last_Nuntias_id = " + lastNuntias.Id + " where Id = " + conversation.ConversationID;
            int?   success = this.ExecuteSqlCeQuery(sql);

            if (success == null)
            {
                return(null);
            }
            if (success > 0)
            {
                return(true);
            }
            return(false);
        }
        public static void UpdateNuntiasStatus(Nuntias newNuntias)
        {
            JObject nuntiasJsonData = newNuntias.ToJson();

            nuntiasJsonData["user_id"] = Consumer.LoggedIn.Id;
            bool?success = null;

            ServerHub.WorkingInstance.ServerHubProxy.Invoke <bool>("UpdateNuntiasStatusToOwners", nuntiasJsonData).ContinueWith(task =>
            {
                if (!task.IsFaulted)
                {
                    success = task.Result;
                }
            }).Wait();
        }
        public static long?SendNewNuntias(Nuntias newNuntias)
        {
            JObject nuntiasJsonData = newNuntias.ToJson();

            nuntiasJsonData["sender_mac_address"] = Universal.SystemMACAddress;
            long?nuntiasId = null;

            ServerHub.WorkingInstance.ServerHubProxy.Invoke <long>("SendNewNuntias", nuntiasJsonData).ContinueWith(task =>
            {
                if (!task.IsFaulted)
                {
                    nuntiasId = task.Result;
                }
            }).Wait();
            return(nuntiasId);
        }
Example #20
0
        public void ShowNuntias(Nuntias nuntias, bool playConversationInnerSound)
        {
            string processesedText = Universal.ProcessStringToShow(nuntias.Text, this.maxCharactersPerLine);

            if (Universal.ParentForm.InvokeRequired)
            {
                Universal.ParentForm.Invoke(new Action(() =>
                {
                    ShowNuntiasTasks(nuntias, playConversationInnerSound, processesedText);
                }));
            }
            else
            {
                ShowNuntiasTasks(nuntias, playConversationInnerSound, processesedText);
            }
        }
        internal Nuntias GetNuntiasByQyery(string query)
        {
            SqlCeDataReader reader = this.ReadSqlCeData(query);

            if (reader == null)
            {
                return(null);
            }
            long?   id = null, senderId = null, conversationId = null;
            string  text = null, contentPath = null;
            Time    sentTime = null, deliveryTime = null, seenTime = null;
            Nuntias nuntias = null;

            while (reader.Read())
            {
                try
                {
                    id             = long.Parse(reader["id"].ToString());
                    text           = reader["Text"].ToString();
                    senderId       = long.Parse(reader["Sender_id"].ToString());
                    conversationId = long.Parse(reader["Conversation_id"].ToString());
                    if (reader["Sent_time"].ToString().Length > 0)
                    {
                        sentTime = new Time(DateTime.Parse(reader["Sent_time"].ToString()));
                    }
                    if (reader["delivery_time"].ToString().Length > 0)
                    {
                        deliveryTime = new Time(DateTime.Parse(reader["delivery_time"].ToString()));
                    }
                    if (reader["seen_time"].ToString().Length > 0)
                    {
                        seenTime = new Time(DateTime.Parse(reader["seen_time"].ToString()));
                    }
                    nuntias = new Nuntias((long)id, text, (long)senderId, sentTime, deliveryTime, seenTime, contentPath, (long)conversationId);
                    if (reader["Content_Id"].ToString().Length > 0)
                    {
                        nuntias.ContentFileId = reader["Content_Id"].ToString();
                    }
                }
                catch { }
                this.CloseConnection();
                return(nuntias);
            }
            return(null);
        }
        public void UpdateInfoPanel()
        {
            int     availableTop = 0;
            Nuntias nuntias      = SyncAssets.NuntiasSortedList[this.nuntiasId];

            if (nuntias.SentTime != null)
            {
                sentTimeLabel.Text = nuntias.SentTime.Time12;
                if (nuntias.Id < 0)
                {
                    sentTimeLabel.Text = "sending...";
                }
                if (sentTimeLabel.Text.Length > 0)
                {
                    availableTop          = sentTimeLabel.Bottom;
                    sentTimeLabel.Visible = true;
                }
            }

            if (nuntias.SeenTime != null)
            {
                seenTimeLabel.Text = nuntias.SeenTime.Time12;
                seenTimeLabel.Top  = availableTop - 2;
                if (seenTimeLabel.Text.Length > 0)
                {
                    availableTop          = seenTimeLabel.Bottom;
                    seenTimeLabel.Visible = true;
                }
            }
            else if (nuntias.DeliveryTime != null)
            {
                deliveredTimeLabel.Text = nuntias.DeliveryTime.Time12;
                deliveredTimeLabel.Top  = availableTop - 2;
                if (deliveredTimeLabel.Text.Length > 0)
                {
                    availableTop = deliveredTimeLabel.Bottom;
                    deliveredTimeLabel.Visible = true;
                }
            }

            this.Size    = this.PreferredSize;
            this.Visible = false;
        }
Example #23
0
 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);
     }
 }
        public long?Insert(Nuntias nuntias)
        {
            string sentTimeStr = "NULL", deliveryTimeStr = "NULL", seenTimeStr = "NULL", nuntiasText = "NULL", contentFileId = "NULL";;

            if (nuntias.SentTime != null)
            {
                sentTimeStr = "'" + nuntias.SentTime.DbFormat + "'";
            }
            if (nuntias.DeliveryTime != null)
            {
                deliveryTimeStr = "'" + nuntias.DeliveryTime.DbFormat + "'";
            }
            if (nuntias.SeenTime != null)
            {
                seenTimeStr = "'" + nuntias.SeenTime.DbFormat + "'";
            }
            if (nuntias.Text != null && nuntias.Text.Length > 0)
            {
                nuntiasText = "'" + nuntias.Text + "'";
            }
            if (nuntias.ContentFileId != null && nuntias.ContentFileId.Length > 0)
            {
                contentFileId = "'" + nuntias.ContentFileId + "'";
            }
            string sql    = "INSERT INTO Nuntii (Id, text,Sender_id,Sent_time,Delivery_time,Seen_time,Conversation_id,Content_Id) values (" + nuntias.Id + "," + nuntiasText + "," + nuntias.SenderId + "," + sentTimeStr + "," + deliveryTimeStr + "," + seenTimeStr + "," + nuntias.NativeConversationID + "," + contentFileId + ");";
            int?   result = this.ExecuteSqlCeQuery(sql);

            if (result == null)
            {
                return(null);
            }
            sql    = "UPDATE Conversations SET Last_nuntias_id = " + nuntias.Id + " where Id = " + nuntias.NativeConversationID + ";";
            result = this.ExecuteSqlCeQuery(sql);
            if (result == null)
            {
                return(null);
            }
            return(nuntias.Id);
        }
        public bool?UpdateNuntiasStatusTimes(Nuntias item, long userId)
        {
            string deliveryTimeStr = "NULL", seenTimeStr = "NULL";

            if (item.DeliveryTime != null)
            {
                deliveryTimeStr = "'" + item.DeliveryTime.DbFormat + "'";
            }
            if (item.SeenTime != null)
            {
                seenTimeStr = "'" + item.SeenTime.DbFormat + "'";
            }
            string query = "UPDATE Nuntii SET Delivery_time = " + deliveryTimeStr + ", Seen_time = " + seenTimeStr + " where Id = " + item.Id + ";";

            query += "UPDATE Nuntius_Owner_map SET Delivery_Status = 1 where Delivery_Status = 0 and Owner_Id = " + userId + " and Nuntias_Id = " + item.Id + ";";
            string success = this.ExecuteSqlScalar(query);

            if (success == null)
            {
                return(false);
            }
            return(true);
        }
Example #26
0
        private bool ShowTimeStampIfNecessary(Nuntias nuntias)
        {
            if (this.lastShowedNuntias == null || Time.TimeDistanceInMinute(this.lastShowedNuntias.SentTime, nuntias.SentTime) > 5)
            {
                Label timeLabel = new Label();
                timeLabel.Text = nuntias.SentTime.DateTimeLong;
                timeLabel.Size = timeLabel.PreferredSize;
                if (this.lastShowedNuntias == null)
                {
                    timeLabel.Top = 20;
                }
                else if (this.lastShowedNuntias.SenderId != nuntias.SenderId)
                {
                    timeLabel.Top = this.lastShowedLabel.Bottom + 20;
                }
                else
                {
                    timeLabel.Top = this.lastShowedLabel.Bottom + 10;
                }
                timeLabel.Left = (this.nuntiasBossPanel.Width - timeLabel.Width) / 2;
                if (Universal.ParentForm.InvokeRequired)
                {
                    Universal.ParentForm.Invoke(new MethodInvoker(delegate
                    {
                        this.nuntiasBossPanel.Controls.Add(timeLabel);
                    }));
                }
                else
                {
                    this.nuntiasBossPanel.Controls.Add(timeLabel);
                }
                this.lastShowedLabel = timeLabel;

                return(true);
            }
            return(false);
        }
        public static void UpdateNuntias(Nuntias nuntias)
        {
            SyncAssets.NuntiasSortedList[nuntias.Id] = nuntias;

            if (Universal.ParentForm.InvokeRequired)
            {
                Universal.ParentForm.Invoke(new Action(() =>
                {
                    try
                    {
                        NuntiasLocalUpdateWorks(nuntias);
                    }
                    catch { }
                }));
            }
            else
            {
                try
                {
                    NuntiasLocalUpdateWorks(nuntias);
                }
                catch { }
            }
        }
        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);
                }
            }
                                                                       );
        }
Example #29
0
        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 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();
            }
        }