2 using System.Collections.Generic;
5 using System.Windows.Controls;
6 using System.Windows.Documents;
7 using System.Windows.Media.Animation;
10 using System.Text.RegularExpressions;
13 namespace SeciControls
22 InitializeComponent();
27 txtNameError.Visibility = System.Windows.Visibility.Collapsed;
28 txtDescError.Visibility = System.Windows.Visibility.Collapsed;
36 txtNameError.Visibility = System.Windows.Visibility.Collapsed;
37 txtDescError.Visibility = System.Windows.Visibility.Collapsed;
39 if (String.IsNullOrEmpty(txtDesc.Text.Trim()))
41 txtDescError.Visibility = System.Windows.Visibility.Visible;
45 if (String.IsNullOrEmpty(txtName.Text.Trim()))
47 txtNameError.Visibility = System.Windows.Visibility.Visible;
53 String toAddress =
"FBUITservicedesk@rl.ac.uk";
54 String fromAddress =
"ISISsupport@rl.ac.uk";
57 String machine = Environment.MachineName.ToUpper();
58 String instrument = machine;
60 if (instrument.StartsWith(
"NDX"))
62 instrument = instrument.Substring(3);
66 String header =
"IT Query Type=SIT" + Environment.NewLine;
67 header +=
"Primary Assignee=ISIS Science Support Team" + Environment.NewLine;
69 if (!String.IsNullOrEmpty(assignees))
71 header +=
"Assignees=" + assignees + Environment.NewLine;
73 header +=
"Status=New Instrument Request" + Environment.NewLine;
74 header +=
"Full Name=" + instrument + Environment.NewLine;
75 header +=
"Telephone Number=0000" + Environment.NewLine;
76 header +=
"Email Address=" +
"ISISinstrument@sparrowhawk.nd.rl.ac.uk" + Environment.NewLine;
77 header +=
"Company=STFC" + Environment.NewLine;
78 header +=
"Office=" + instrument + Environment.NewLine;
79 header +=
"Department=Isis" + Environment.NewLine;
80 header +=
"Site=RAL" + Environment.NewLine;
81 header +=
"Internal Notes (Agents only)=The Contact email address of ISISInstrument@sparrowhawk is a dummy one;"
82 +
" the relevant instrument scientists have been added to the CC list of the query" + Environment.NewLine;
83 header +=
"Machine Name=" + machine;
85 String comment =
"ISIS Instrument: " + instrument + Environment.NewLine;
86 comment = comment +
"Name of computer problem was submitted from: " + machine + Environment.NewLine;
87 comment = comment +
"Scientist Contact Information: http://www.isis.stfc.ac.uk/people/instrument-scientists-4398.html" + Environment.NewLine;
88 comment = comment +
"Instrument Contact List (i.e. who gets these sorts of emails): http://sparrowhawk.nd.rl.ac.uk/footprints/contacts.html";
90 String message = header + Environment.NewLine + Environment.NewLine
91 + txtDesc.Text + Environment.NewLine + Environment.NewLine + txtName.Text + Environment.NewLine + Environment.NewLine + comment;
96 System.Net.Mail.MailMessage msg =
new System.Net.Mail.MailMessage();
97 msg.To.Add(toAddress);
99 if (txtDesc.Text.Length > 30)
101 msg.Subject =
"INSTRUMENT (" + instrument +
"): " + txtDesc.Text.Substring(0, 30);
105 msg.Subject =
"INSTRUMENT (" + instrument +
"): " + txtDesc.Text;
107 msg.From =
new System.Net.Mail.MailAddress(fromAddress);
109 System.Net.Mail.SmtpClient smtp =
new System.Net.Mail.SmtpClient(
"exchsmtp.stfc.ac.uk");
113 txtMsgSent.Text =
"Message Submitted";
114 ((Storyboard)FindResource(
"FadeOut")).Begin(txtMsgSent);
115 ((Storyboard)FindResource(
"FadeIn")).Begin(btnSubmit);
122 txtMsgSent.Text =
"Sorry - could not send message at this time";
123 ((Storyboard)FindResource(
"FadeOut")).Begin(txtMsgSent);
124 ((Storyboard)FindResource(
"FadeIn")).Begin(btnSubmit);
131 String url =
"http://sparrowhawk.nd.rl.ac.uk/footprints/contacts.html";
135 if (String.IsNullOrEmpty(url))
return "";
138 WebRequest wr = WebRequest.Create(url);
140 using (WebResponse res = wr.GetResponse())
141 using (Stream s = res.GetResponseStream())
142 using (StreamReader sr =
new StreamReader(s))
143 data = sr.ReadToEnd();
145 data = data.Substring(data.IndexOf(instrument));
146 data = data.Substring(0, data.IndexOf(
"</TR>"));
148 List<String> lines =
new List<string>(data.Split(
'\n'));
151 Regex emailRegex =
new Regex(
@"\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*", RegexOptions.IgnoreCase);
152 MatchCollection emailMatches = emailRegex.Matches(data);
154 StringBuilder sb =
new StringBuilder();
157 foreach (Match emailMatch
in emailMatches)
159 if (last != emailMatch.Value)
161 last = emailMatch.Value;
162 sb.Append(
"CC:" + emailMatch.Value.Trim() +
" ");
166 return sb.ToString().Trim();