Skip to content

Commit 2d6b193

Browse files
author
Alex Papadimoulis
committed
0 parents  commit 2d6b193

38 files changed

+2595
-0
lines changed

Shared/SubmitForm.Designer.cs

Lines changed: 299 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Shared/SubmitForm.cs

Lines changed: 191 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,191 @@
1+
using System;
2+
using System.ComponentModel;
3+
using System.Text.RegularExpressions;
4+
using System.Windows.Forms;
5+
6+
namespace SubmitToWTF
7+
{
8+
/// <summary>
9+
/// Submission modal dialog.
10+
/// </summary>
11+
public sealed partial class SubmitForm : Form
12+
{
13+
/// <summary>
14+
/// The regular expression used for basic email validation.
15+
/// </summary>
16+
private static readonly Regex EmailRegex = new Regex(@"^[^@]+@[^.]+\.[^@\s]+$", RegexOptions.Singleline | RegexOptions.Compiled);
17+
18+
/// <summary>
19+
/// Initializes a new instance of the <see cref="SubmitForm"/> class.
20+
/// </summary>
21+
public SubmitForm()
22+
{
23+
InitializeComponent();
24+
}
25+
26+
/// <summary>
27+
/// Gets or sets the code snippet to display.
28+
/// </summary>
29+
public string CodeSnippet
30+
{
31+
get { return this.txtCode.Text; }
32+
set { this.txtCode.Text = value; }
33+
}
34+
35+
/// <summary>
36+
/// Raises the <see cref="E:System.Windows.Forms.Form.Load"/> event.
37+
/// </summary>
38+
/// <param name="e">An <see cref="T:System.EventArgs"/> that contains the event data.</param>
39+
protected override void OnLoad(EventArgs e)
40+
{
41+
base.OnLoad(e);
42+
this.txtName.Text = Environment.UserName;
43+
}
44+
45+
/// <summary>
46+
/// Determines whether a string could be a valid email address.
47+
/// </summary>
48+
/// <param name="s">The string to test.</param>
49+
/// <returns>True if the string could be a valid email address. This is by no means exhaustive.</returns>
50+
private static bool IsPossiblyEmailAddress(string s)
51+
{
52+
if (Util.IsEmptyOrWhitespace(s))
53+
return false;
54+
55+
return EmailRegex.IsMatch(s);
56+
}
57+
58+
/// <summary>
59+
/// Enables or disables the controls during a submit.
60+
/// </summary>
61+
/// <param name="enabled">If set to <c>true</c> controls are enabled.</param>
62+
private void EnableControls(bool enabled)
63+
{
64+
this.btnSubmit.Enabled = enabled;
65+
this.txtName.Enabled = enabled;
66+
this.txtEmail.Enabled = enabled;
67+
this.txtSubject.Enabled = enabled;
68+
this.txtMessage.Enabled = enabled;
69+
this.txtCode.Enabled = enabled;
70+
this.chkDoNotPublish.Enabled = enabled;
71+
}
72+
73+
/// <summary>
74+
/// Handles the Click event of the btnSubmit control.
75+
/// </summary>
76+
/// <param name="sender">The source of the event.</param>
77+
/// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
78+
private void btnSubmit_Click(object sender, EventArgs e)
79+
{
80+
EnableControls(false);
81+
this.lblSubmitting.Visible = true;
82+
83+
this.bgwSubmit.RunWorkerAsync(new SubmitInfo(
84+
this.txtName.Text,
85+
this.txtEmail.Text,
86+
this.txtSubject.Text,
87+
this.txtMessage.Text,
88+
this.txtCode.Text,
89+
this.chkDoNotPublish.Checked));
90+
}
91+
/// <summary>
92+
/// Handles the DoWork event of the bgwSubmit control.
93+
/// </summary>
94+
/// <param name="sender">The source of the event.</param>
95+
/// <param name="e">The <see cref="System.ComponentModel.DoWorkEventArgs"/> instance containing the event data.</param>
96+
private void bgwSubmit_DoWork(object sender, DoWorkEventArgs e)
97+
{
98+
var info = (SubmitInfo)e.Argument;
99+
100+
try
101+
{
102+
var service = new WebSubmit.SubmitWTF();
103+
e.Result = service.Submit(info.Name, info.Email, info.Subject, info.Message, info.Code, info.DoNotPublish);
104+
}
105+
catch(Exception ex)
106+
{
107+
e.Result = ex;
108+
}
109+
}
110+
/// <summary>
111+
/// Handles the RunWorkerCompleted event of the bgwSubmit control.
112+
/// </summary>
113+
/// <param name="sender">The source of the event.</param>
114+
/// <param name="e">The <see cref="System.ComponentModel.RunWorkerCompletedEventArgs"/> instance containing the event data.</param>
115+
private void bgwSubmit_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
116+
{
117+
var ex = e.Result as Exception;
118+
if (ex != null)
119+
{
120+
this.lblSubmitting.Visible = false;
121+
MessageBox.Show(this, "TRWTF is this error message: " + ex.Message, "Submit CodeSOD", MessageBoxButtons.OK, MessageBoxIcon.Error);
122+
EnableControls(true);
123+
}
124+
else
125+
this.Close();
126+
}
127+
/// <summary>
128+
/// Handles the TextChanged event of any TextBox control.
129+
/// </summary>
130+
/// <param name="sender">The source of the event.</param>
131+
/// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
132+
private void TextBox_TextChanged(object sender, EventArgs e)
133+
{
134+
bool valid = !Util.IsEmptyOrWhitespace(this.txtName.Text)
135+
&& !Util.IsEmptyOrWhitespace(this.txtCode.Text)
136+
&& IsPossiblyEmailAddress(this.txtEmail.Text);
137+
138+
this.btnSubmit.Enabled = valid;
139+
}
140+
141+
/// <summary>
142+
/// Contains information about a code submission.
143+
/// </summary>
144+
private sealed class SubmitInfo
145+
{
146+
/// <summary>
147+
/// Initializes a new instance of the <see cref="SubmitInfo"/> class.
148+
/// </summary>
149+
/// <param name="name">The name.</param>
150+
/// <param name="email">The email address.</param>
151+
/// <param name="subject">The subject.</param>
152+
/// <param name="message">The message.</param>
153+
/// <param name="code">The code.</param>
154+
/// <param name="doNotPublish">If set to <c>true</c> do not publish.</param>
155+
public SubmitInfo(string name, string email, string subject, string message, string code, bool doNotPublish)
156+
{
157+
this.Name = name;
158+
this.Email = email;
159+
this.Subject = subject;
160+
this.Message = message;
161+
this.Code = code;
162+
this.DoNotPublish = doNotPublish;
163+
}
164+
165+
/// <summary>
166+
/// Gets the name.
167+
/// </summary>
168+
public string Name { get; private set; }
169+
/// <summary>
170+
/// Gets the email address.
171+
/// </summary>
172+
public string Email { get; private set; }
173+
/// <summary>
174+
/// Gets the subject.
175+
/// </summary>
176+
public string Subject { get; private set; }
177+
/// <summary>
178+
/// Gets the message.
179+
/// </summary>
180+
public string Message { get; private set; }
181+
/// <summary>
182+
/// Gets the code.
183+
/// </summary>
184+
public string Code { get; private set; }
185+
/// <summary>
186+
/// Gets a value indicating whether the snippet should be published.
187+
/// </summary>
188+
public bool DoNotPublish { get; private set; }
189+
}
190+
}
191+
}

Shared/SubmitForm.resx

Lines changed: 172 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,172 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<root>
3+
<!--
4+
Microsoft ResX Schema
5+
6+
Version 2.0
7+
8+
The primary goals of this format is to allow a simple XML format
9+
that is mostly human readable. The generation and parsing of the
10+
various data types are done through the TypeConverter classes
11+
associated with the data types.
12+
13+
Example:
14+
15+
... ado.net/XML headers & schema ...
16+
<resheader name="resmimetype">text/microsoft-resx</resheader>
17+
<resheader name="version">2.0</resheader>
18+
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
19+
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
20+
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
21+
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
22+
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
23+
<value>[base64 mime encoded serialized .NET Framework object]</value>
24+
</data>
25+
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
26+
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
27+
<comment>This is a comment</comment>
28+
</data>
29+
30+
There are any number of "resheader" rows that contain simple
31+
name/value pairs.
32+
33+
Each data row contains a name, and value. The row also contains a
34+
type or mimetype. Type corresponds to a .NET class that support
35+
text/value conversion through the TypeConverter architecture.
36+
Classes that don't support this are serialized and stored with the
37+
mimetype set.
38+
39+
The mimetype is used for serialized objects, and tells the
40+
ResXResourceReader how to depersist the object. This is currently not
41+
extensible. For a given mimetype the value must be set accordingly:
42+
43+
Note - application/x-microsoft.net.object.binary.base64 is the format
44+
that the ResXResourceWriter will generate, however the reader can
45+
read any of the formats listed below.
46+
47+
mimetype: application/x-microsoft.net.object.binary.base64
48+
value : The object must be serialized with
49+
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
50+
: and then encoded with base64 encoding.
51+
52+
mimetype: application/x-microsoft.net.object.soap.base64
53+
value : The object must be serialized with
54+
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
55+
: and then encoded with base64 encoding.
56+
57+
mimetype: application/x-microsoft.net.object.bytearray.base64
58+
value : The object must be serialized into a byte array
59+
: using a System.ComponentModel.TypeConverter
60+
: and then encoded with base64 encoding.
61+
-->
62+
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
63+
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
64+
<xsd:element name="root" msdata:IsDataSet="true">
65+
<xsd:complexType>
66+
<xsd:choice maxOccurs="unbounded">
67+
<xsd:element name="metadata">
68+
<xsd:complexType>
69+
<xsd:sequence>
70+
<xsd:element name="value" type="xsd:string" minOccurs="0" />
71+
</xsd:sequence>
72+
<xsd:attribute name="name" use="required" type="xsd:string" />
73+
<xsd:attribute name="type" type="xsd:string" />
74+
<xsd:attribute name="mimetype" type="xsd:string" />
75+
<xsd:attribute ref="xml:space" />
76+
</xsd:complexType>
77+
</xsd:element>
78+
<xsd:element name="assembly">
79+
<xsd:complexType>
80+
<xsd:attribute name="alias" type="xsd:string" />
81+
<xsd:attribute name="name" type="xsd:string" />
82+
</xsd:complexType>
83+
</xsd:element>
84+
<xsd:element name="data">
85+
<xsd:complexType>
86+
<xsd:sequence>
87+
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
88+
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
89+
</xsd:sequence>
90+
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
91+
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
92+
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
93+
<xsd:attribute ref="xml:space" />
94+
</xsd:complexType>
95+
</xsd:element>
96+
<xsd:element name="resheader">
97+
<xsd:complexType>
98+
<xsd:sequence>
99+
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
100+
</xsd:sequence>
101+
<xsd:attribute name="name" type="xsd:string" use="required" />
102+
</xsd:complexType>
103+
</xsd:element>
104+
</xsd:choice>
105+
</xsd:complexType>
106+
</xsd:element>
107+
</xsd:schema>
108+
<resheader name="resmimetype">
109+
<value>text/microsoft-resx</value>
110+
</resheader>
111+
<resheader name="version">
112+
<value>2.0</value>
113+
</resheader>
114+
<resheader name="reader">
115+
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
116+
</resheader>
117+
<resheader name="writer">
118+
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
119+
</resheader>
120+
<metadata name="lblName.GenerateMember" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
121+
<value>False</value>
122+
</metadata>
123+
<metadata name="lblEmail.GenerateMember" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
124+
<value>False</value>
125+
</metadata>
126+
<metadata name="lblSubject.GenerateMember" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
127+
<value>False</value>
128+
</metadata>
129+
<metadata name="lblMessage.GenerateMember" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
130+
<value>False</value>
131+
</metadata>
132+
<metadata name="lblCode.GenerateMember" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
133+
<value>False</value>
134+
</metadata>
135+
<metadata name="splitContainer1.GenerateMember" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
136+
<value>False</value>
137+
</metadata>
138+
<metadata name="bgwSubmit.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
139+
<value>17, 17</value>
140+
</metadata>
141+
<metadata name="lblDoNotPublish.GenerateMember" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
142+
<value>False</value>
143+
</metadata>
144+
<data name="lblDoNotPublish.Text" xml:space="preserve">
145+
<value>Even though I’m sure you’d do a fine job of anonymizing, I just wanted to be able to say that I sent code to The Daily WTF. Yes, I realize this hardly counts, but it’s better than wallowing in my own misery.</value>
146+
</data>
147+
<assembly alias="System.Drawing" name="System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
148+
<data name="$this.Icon" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
149+
<value>
150+
AAABAAEAEBAAAAEAIABoBAAAFgAAACgAAAAQAAAAIAAAAAEAIAAAAAAAAAAAABMLAAATCwAAAAAAAAAA
151+
AAAAAAAACAjOMAgIzjMICM5kCAjPcgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
152+
AAAAAAAAAAAAAAgIzmAICM6ICAjOsggIzqMCAeABAAAAAAAAAADS09gB+Pj+AQgIzlYICM6PCAjO1ggI
153+
zv8ICM4yAAAAAAAAAAAICM9pCAjO+wgIzv8ICM7uCAjQdQAAAAAAAAAAAAAAAAAAAAAICM7KCAjO/wgI
154+
ztgICM7/CAjObAAAAAAAAAAACAjNggkIzvAICM7aCAjO0ggIznUAAAAAAAAAAAAAAAAAAAAACAjOYwgI
155+
zvYICM7CCAjO/wgIzsYICM4LAAAAAAEByiEICM9nCAjOdQgIzn4ICM47AAAAAAAAAAA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AADgYwAA8CEAAIggAAAAIAAAgGAAAMDw
169+
///B/////////w==
170+
</value>
171+
</data>
172+
</root>

0 commit comments

Comments
 (0)