コード例 #1
0
        /// <summary>
        /// Manage what was received
        /// </summary>
        private void handle()
        {
            int index = 0;
            int nbComs = 0;
            SMS sms = null;
            string toHandle;

            ConversationManager business = new ConversationManager();

            while (!m_stop) {
                try {
                    toHandle = m_manager.getLastReceived();
                    if (!string.IsNullOrEmpty(toHandle)) {
                        if (toHandle.StartsWith("ACK")) {
                            m_manager.popSending();
                        }
                        else {
                            m_manager.send("ACK");                          // Acquittal
                            #region Connexion
                            if (toHandle.StartsWith("OK")) {
                                m_manager.hasBeenConnected();
                            }
                            #endregion
                            #region SMS HEADER
                            if (toHandle.StartsWith("SMSHEADER")) {         // SMS Header
                                string[] args = toHandle.Split(':');        // Get arguments

                                if (checkHeader(args)) {                    // Check
                                    // Get contact
                                    Contact c = business.getContactFromString(args[1]);         // Get contact

                                    // Get a phone number which begin by 0
                                    if (c != null) {
                                        if (args[1].StartsWith("+33")) {
                                            args[1] = "0" + args[1].Substring(3);
                                        }
                                        c = new Contact(args[1]);
                                    }

                                    // Get the date
                                    string pattern = "dd-MM-yyyy HH.mm.ss";
                                    DateTime date = DateTime.ParseExact(args[2], pattern,
                                        CultureInfo.InvariantCulture);

                                    sms = new SMS(c, date, true);
                                    nbComs = int.Parse(args[3]);
                                    index = 1;
                                }
                                else {                                      // If problem
                                    throw new Exception("Incorrect Header !");
                                }
                            }
                            #endregion
                            #region SMS BODY
                            else if (toHandle.StartsWith("SMSBODY")) {      // SMS Body
                                if (index != 0 && nbComs != 0) {

                                    toHandle = toHandle.Substring(8);       // Delete "SMSBODY:"

                                    // Get the number of the part of the message
                                    int i = int.Parse(toHandle.Split(':')[0]);
                                    toHandle = toHandle.Substring(2);       // Delete number

                                    // Get a part
                                    if (i == index && index <= nbComs) {
                                        sms.appendBody(toHandle);
                                    }
                                    else if (nbComs > 0 && i != index) {
                                        throw new Exception("Incorrect part of the message received !");
                                    }

                                    // Is the message complete ?
                                    if (index == nbComs) {                   // Yes
                                        // Add the message in the conversation
                                        Conversation c = business.getConversationsFromContact(sms.Contact.Num);
                                        business.AddMessageToConv(sms, c);

                                        m_manager.smsReceived(sms);         // Notify the interface
                                        nbComs = 0;
                                        index = 0;
                                    }
                                    else {                                  // No
                                        index++;
                                    }
                                }
                                else {
                                    throw new Exception("Body unexpected !");
                                }
                            }
                            #endregion
                            #region CONTACT
                            else if (toHandle.StartsWith("CONTACT")) {
                                // TODO : to implement
                            }
                            #endregion
                        }

                    }   // End if
                }
                catch (Exception e) {
                    LogManager.WriteToFile(e.Message, "ReceiveHandler");
                }

                Thread.Sleep(50);                                       // For scheduling
            }   // End while
        }
コード例 #2
0
 private void Import_Conv_Click(object sender, RoutedEventArgs e)
 {
     BusinessLayer.ConversationManager cm = new BusinessLayer.ConversationManager();
     cm.loadHistorique("Conversations.xml");
 }
コード例 #3
0
        private void AppWindow_Loaded(object sender, RoutedEventArgs e)
        {
            BusinessLayer.ConversationManager cm = new BusinessLayer.ConversationManager();

            Import_Conv_Click(this, null);
            Import_Cont_Click(this, null);

            IList<EntityLayer.Conversation> convs = cm.getConversations();
            ViewModel.Conversation.ConversationsModelView cmv = new ViewModel.Conversation.ConversationsModelView(convs);
            ListConversations.DataContext = cmv;
        }
コード例 #4
0
 private void Export_Conv_Click(object sender, RoutedEventArgs e)
 {
     BusinessLayer.ConversationManager cm = new BusinessLayer.ConversationManager();
     cm.saveConversations("Conversations.xml");
 }