|
using System;
using System.Linq;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Microsoft.WindowsMobile.PocketOutlook;
using MI = Microsoft.WindowsMobile.PocketOutlook.MessageInterception;
using MessageInterceptor.localhost;
namespace MessageInterceptor {
public partial class Form1 : Form {
public Form1() {
InitializeComponent();
this.CreateInterceptor();
}
private void button2_Click(object sender, EventArgs e) {
this.CloseInterceptor();
this.Close();
Application.Exit();
}
public StringBuilder Debug;
MI.MessageInterceptor intercept;
public void CreateInterceptor(){
Debug = new StringBuilder();
intercept = new MI.MessageInterceptor(MI.InterceptionAction.NotifyAndDelete);
intercept.MessageCondition = new MI.MessageCondition(MI.MessageProperty.Body, MI.MessagePropertyComparisonType.Contains, "#inf#");
intercept.MessageReceived += new MI.MessageInterceptorEventHandler(MessageReceived);
}
void MessageReceived(object sender, MI.MessageInterceptorEventArgs args) {
//Format du message recu : #inf#nom#prenom
SmsMessage receiveMsg = (SmsMessage)args.Message;
string data = receiveMsg.Body;
Debug.AppendLine(data);
string[] names = data.Split('#');
string firstname, lastname = "";
List<string> nameList = new List<string>();
if (names.Length > 2) {
lastname = names[2];
nameList.Add(lastname);
Debug.AppendLine("LastName : " + lastname);
}
if (names.Length > 3) {
firstname = names[3];
nameList.Add(firstname);
Debug.AppendLine("FirstName : " + firstname);
}
WebService ws = new WebService();
Employee[] employees = ws.ProcessEmployees(nameList.ToArray());
StringBuilder sb = new StringBuilder();
for (int i = 0; i < employees.Length; i++) {
Employee e = employees[i];
sb.AppendLine(e.Nom + " " + e.Prenom + " - " + e.TelBureau + " - " + e.TelMobile + " - " + e.Mail);
}
Debug.AppendLine(sb.ToString());
SmsMessage msgToSend = new SmsMessage();
msgToSend.To.Add(receiveMsg.From);
msgToSend.Body = sb.ToString();
msgToSend.Send();
this.label1.Text += this.Debug.ToString();
}
public void CloseInterceptor() {
intercept.MessageReceived -= MessageReceived;
intercept.Dispose();
}
}
} |