예제 #1
0
파일: SMSIM.cs 프로젝트: JMdeKlerk/SMSIM
 private void contacts_doubleClick(object sender, MouseEventArgs e)
 {
     Contact selected = (Contact)contacts.SelectedItem;
     if (selected == null) return;
     if (openConversations.ContainsKey(selected.name)) {
         Conversation conversation;
         if (openConversations.TryGetValue(selected.name, out conversation)) {
             if (conversation.InvokeRequired) conversation.Invoke(new MethodInvoker(delegate { conversation.Focus(); }));
             else conversation.Focus();
         }
     } else {
         String[] input = { "null", "null", selected.name, selected.number };
         Conversation conversation = new Conversation(this, input);
         openConversations.Add(selected.name, conversation);
         conversation.Show();
     }
 }
예제 #2
0
파일: SMSIM.cs 프로젝트: JMdeKlerk/SMSIM
 private void handleRequest(object sender, StringRequestReceivedEventArgs e)
 {
     ping = true;
     String[] input = e.RequestMessage.Split(':');
     if (input[0].Equals("Version")) {
         connectedDevice = e.ResponseReceiverId;
         sendMessage("Version:1.1");
         connectedDevice = null;
         return;
     }
     try {
         receiver.SendResponseMessage(e.ResponseReceiverId, "Ack:" + input[0]);
     } catch (InvalidOperationException) { input[1] = "DC"; }
     switch (input[1]) {
         case ("Mismatch"):
             var result = MessageBox.Show("An update is required. Would you like to download it now?",
                 "Update required", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
             if (result == DialogResult.Yes) System.Diagnostics.Process.Start("http://github.com/JMdeKlerk/SMSIM/releases");
             break;
         case ("Conn"):
             connectedDevice = e.ResponseReceiverId;
             deviceName.Invoke(new MethodInvoker(delegate { deviceName.Text = input[2]; }));
             contacts.Invoke(new MethodInvoker(delegate { contacts.Items.Clear(); }));
             sendMessage("Contacts");
             break;
         case ("Contact"):
             Contact contact = new Contact();
             contact.name = input[2];
             contact.number = input[3];
             foreach (Contact existingContact in contacts.Items) {
                 if (existingContact.name.Equals(contact.name) && existingContact.number.Equals(contact.number)) return;
             }
             System.Reflection.Assembly assembly = System.Reflection.Assembly.GetExecutingAssembly();
             Array lol = assembly.GetManifestResourceNames();
             Stream stream = assembly.GetManifestResourceStream("SMSIM.Contacts-50.png");
             contact.displayPic = new Bitmap(stream);
             contacts.Invoke(new MethodInvoker(delegate {
                 contacts.Items.Add(contact);
                 contacts.Sorted = false;
                 contacts.Sorted = true;
             }));
             break;
         case ("SMS"):
             SystemSounds.Beep.Play();
             if (openConversations.ContainsKey(input[2])) {
                 Conversation conversation;
                 if (openConversations.TryGetValue(input[2], out conversation)) {
                     if (conversation.InvokeRequired)
                         conversation.Invoke(new MethodInvoker(delegate {
                             conversation.ParseInput(input);
                         }));
                     else conversation.ParseInput(input);
                 }
             } else {
                 BackgroundWorker bw = new BackgroundWorker();
                 bw.DoWork += new DoWorkEventHandler(delegate (object o, DoWorkEventArgs args) {
                     Conversation conversation = new Conversation(this, input);
                     openConversations.Add(input[2], conversation);
                     Application.Run(conversation);
                 });
                 bw.RunWorkerAsync();
             }
             break;
         case ("Success"):
             foreach (KeyValuePair<string, Conversation> entry in openConversations) {
                 int id = Int32.Parse(input[2]);
                 entry.Value.messageSuccess(id);
             }
             break;
         case ("Fail"):
             foreach (KeyValuePair<string, Conversation> entry in openConversations) {
                 int id = Int32.Parse(input[2]);
                 entry.Value.messageFail(id);
             }
             break;
         case ("DC"):
             connectedDevice = null;
             deviceName.Invoke(new MethodInvoker(delegate { deviceName.Text = "-"; }));
             contacts.Invoke(new MethodInvoker(delegate { contacts.Items.Clear(); }));
             break;
     }
 }