Skip to content

Commit dea8c46

Browse files
authored
Merge pull request #19 from MadeiraData/v2.3
convert to .NET Framework 3.5 for backward-compatibility with SQL2008
2 parents 113f3f9 + 431db60 commit dea8c46

File tree

4 files changed

+46
-11
lines changed

4 files changed

+46
-11
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ exec sp_send_calendar_event
4444
[ , [ @subject = ] 'subject' ]
4545
[ , [ @body = ] 'body' ]
4646
[ , [ @body_format = ] 'TEXT | HTML' ]
47-
[ , [ @importance = ] 'LOW | NORMAL | HIGH' ]
47+
[ , [ @importance = ] 'Low | Normal | High' ]
4848
[ , [ @sensitivity = ] 'PUBLIC | PRIVATE | CONFIDENTIAL' ]
4949
[ , [ @file_attachments = ] 'file_attachments [ ; ...n ]' ]
5050
[ , [ @location = ] 'location' ]

sql_clr_ics/clr_send_ics_invite.cs

Lines changed: 40 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ INNER JOIN [msdb].[dbo].[sysmail_server] AS s
193193

194194
#region validations
195195

196-
currentPhase = "Parameter validations";
196+
currentPhase = "Validating parameters";
197197

198198
StringBuilder sb_Errors = new StringBuilder();
199199

@@ -205,10 +205,10 @@ INNER JOIN [msdb].[dbo].[sysmail_server] AS s
205205
)
206206
sb_Errors.AppendLine("Missing recipients: Please specify either @recipients, @copy_recipients or @blind_copy_recipients");
207207

208-
if (body_format.Value != "HTML" && body_format.Value != "TEXT") sb_Errors.AppendLine(string.Format("@body_format {0} is invalid. Valid values: TEXT, HTML", body_format.Value));
209-
if (!Enum.TryParse(method.Value, true, out iCalMethods method_enumvalue)) sb_Errors.AppendLine(string.Format("@method {0} is invalid. Valid values: {1}", method.Value, Enum.GetNames(typeof(iCalMethods)).ToString().ToUpper()));
210-
if (!Enum.TryParse(sensitivity.Value, true, out iCalClass sensitivity_enumvalue)) sb_Errors.AppendLine(string.Format("sensitivity {0} is invalid. Valid values: {1}", sensitivity.Value, Enum.GetNames(typeof(iCalClass)).ToString().ToUpper()));
211-
if (!Enum.TryParse(importance.Value, true, out mailPriority)) sb_Errors.AppendLine(string.Format("@importance {0} is invalid. Valid values: {1}", importance.Value, Enum.GetNames(typeof(MailPriority)).ToString().ToUpper()));
208+
if (body_format.Value != "HTML" && body_format.Value != "TEXT") sb_Errors.AppendLine(string.Format("@body_format {0} is invalid. Valid values: TEXT | HTML", body_format.Value));
209+
if (!TryParseEnum(typeof(iCalMethods), method.Value.ToUpper())) sb_Errors.AppendLine(string.Format("@method {0} is invalid. Valid values: {1}", method.Value, String.Join(" | ", Enum.GetNames(typeof(iCalMethods)))));
210+
if (!TryParseEnum(typeof(iCalClass), sensitivity.Value.ToUpper())) sb_Errors.AppendLine(string.Format("sensitivity {0} is invalid. Valid values: {1}", sensitivity.Value, String.Join(" | ", Enum.GetNames(typeof(iCalClass)))));
211+
if (!TryParseEnum(typeof(MailPriority), importance.Value, out mailPriority)) sb_Errors.AppendLine(string.Format("@importance {0} is invalid. Valid values: {1}", importance.Value, String.Join(" | ", Enum.GetNames(typeof(MailPriority)))));
212212

213213
bool recipient_role_found = false;
214214
bool copy_recipient_role_found = false;
@@ -276,7 +276,7 @@ INNER JOIN [msdb].[dbo].[sysmail_server] AS s
276276

277277
try
278278
{
279-
if (!reply_to.IsNull && !string.IsNullOrEmpty(reply_to.Value)) msg.ReplyToList.Add(reply_to.Value.Replace(';', ','));
279+
if (!reply_to.IsNull && !string.IsNullOrEmpty(reply_to.Value)) msg.ReplyTo = new MailAddress(reply_to.Value);
280280
}
281281
catch (Exception e)
282282
{
@@ -468,6 +468,40 @@ INNER JOIN [msdb].[dbo].[sysmail_server] AS s
468468
}
469469
}
470470

471+
/// <summary>
472+
/// This is a .NET 3.5 compatible replacement for Enum.TryParse functionality.
473+
/// Check whether a given enum value is valid, and return an output object.
474+
/// </summary>
475+
/// <param name="type">typeof(enumClassName)</param>
476+
/// <param name="value">String value to check</param>
477+
/// <param name="returnObject">If enum is valid, outputs a corresponding parsed object, otherwise outputs null</param>
478+
/// <returns>true = valid, false = invalid</returns>
479+
private static bool TryParseEnum<TEnum>(Type type, string value, out TEnum returnObject)
480+
{
481+
try
482+
{
483+
returnObject = (TEnum)Enum.Parse(type, value);
484+
return (returnObject == null) ? false : true;
485+
}
486+
catch
487+
{
488+
returnObject = default(TEnum);
489+
return false;
490+
}
491+
}
492+
493+
/// <summary>
494+
/// This is a .NET 3.5 compatible replacement for Enum.TryParse functionality.
495+
/// Check whether a given enum value is valid.
496+
/// </summary>
497+
/// <param name="type">typeof(enumClassName)</param>
498+
/// <param name="value">String value to check</param>
499+
/// <returns>true = valid, false = invalid</returns>
500+
private static bool TryParseEnum(Type type, string value)
501+
{
502+
return (TryParseEnum(type, value, out object enumcheck));
503+
}
504+
471505
private static void Smtpclient_SendCompleted(object sender, System.ComponentModel.AsyncCompletedEventArgs e)
472506
{
473507
if (e.Cancelled || e.Error != null)

sql_clr_ics/sql_clr_ics.sqlproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
<SchemaVersion>2.0</SchemaVersion>
99
<ProjectVersion>4.1</ProjectVersion>
1010
<ProjectGuid>{25d32670-f382-4174-a91d-8fb1885f4353}</ProjectGuid>
11-
<DSP>Microsoft.Data.Tools.Schema.Sql.Sql120DatabaseSchemaProvider</DSP>
11+
<DSP>Microsoft.Data.Tools.Schema.Sql.Sql100DatabaseSchemaProvider</DSP>
1212
<OutputType>Database</OutputType>
1313
<RootPath>
1414
</RootPath>
@@ -17,7 +17,7 @@
1717
<ModelCollation>1033, CI</ModelCollation>
1818
<DefaultFileStructure>BySchemaAndSchemaType</DefaultFileStructure>
1919
<DeployToDatabase>True</DeployToDatabase>
20-
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
20+
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
2121
<TargetLanguage>CS</TargetLanguage>
2222
<AppDesignerFolder>Properties</AppDesignerFolder>
2323
<SqlServerVerification>False</SqlServerVerification>

sql_clr_ics/sql_clr_ics_install.sql

Lines changed: 3 additions & 2 deletions
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)