Пример #1
0
        static void Main(string[] args)
        {
            UsbManager manager = UsbManager.getInstance(new Utilities());

            try {
                if (manager.connect()) {
                    while(true) {
                        Console.WriteLine("Ecrivez votre message :");
                        string msg = Console.ReadLine();

                        Contact c = new Contact("Adrien", "0647657049");
                        if (!string.IsNullOrEmpty(msg)) {
                            SMS sms = new SMS(msg, c);
                            manager.send(sms);
                        }
                        Console.WriteLine("Message envoyé !");
                    }
                }
                else {
                    Console.WriteLine("Aucun téléphone connecté !");
                }
            }
            catch (Exception e) {
                Console.WriteLine("Exception occured : {0}", e);
            }
        }
Пример #2
0
 public Conversation(Contact c)
 {
     receiver = c;
     messages = new List<SMS>();
 }
Пример #3
0
 public Conversation()
 {
     receiver = null;
     messages = new List<SMS>();
 }
Пример #4
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
        }
Пример #5
0
 public void removeContact(Contact con)
 {
     bdd.removeContact(con);
 }
Пример #6
0
 public void AddConversation(Contact con)
 {
     bdd.AddConversation(con);
 }
Пример #7
0
 public void addContact(Contact con)
 {
     bdd.addContact(con);
 }