Added new function DateTimeFromString.

Correctly setting connection timeout for ODBC connection in ExecuteSqlNonQuery and ExecuteSqlScalar functions.
This commit is contained in:
NileshGhodekar 2017-07-16 12:40:44 -07:00
Родитель 8e62ec3ed0
Коммит 9953220f1c
3 изменённых файлов: 146 добавлений и 2 удалений

Просмотреть файл

@ -22,7 +22,7 @@ namespace MicrosoftServices.IdentityManagement.WorkflowActivityLibrary
/// Build Number (MMDD)
/// Revision (if any on the same day)
/// </summary>
internal const string Version = "2.17.0712.0";
internal const string Version = "2.17.0716.0";
/// <summary>
/// File Version information for the assembly consists of the following four values:
@ -31,6 +31,6 @@ namespace MicrosoftServices.IdentityManagement.WorkflowActivityLibrary
/// Build Number (MMDD)
/// Revision (if any on the same day)
/// </summary>
internal const string FileVersion = "2.17.0712.0";
internal const string FileVersion = "2.17.0716.0";
}
}

Просмотреть файл

@ -1233,6 +1233,11 @@ namespace MicrosoftServices.IdentityManagement.WorkflowActivityLibrary.Common
/// </summary>
public const int ExpressionFunctionValueByKey = 11681;
/// <summary>
/// The event identifier for ExpressionFunction DataTimeFromString events
/// </summary>
public const int ExpressionFunctionDateTimeFromString = 11682;
/// <summary>
/// The event identifier for LookupEvaluator Constructor events
/// </summary>
@ -3028,6 +3033,31 @@ namespace MicrosoftServices.IdentityManagement.WorkflowActivityLibrary.Common
/// </summary>
public const int ExpressionFunctionValueByKeyInvalidSecondFunctionParameterTypeError = 41681;
/// <summary>
/// The event identifier for ExpressionFunction DataTimeFromString events
/// </summary>
public const int ExpressionFunctionDateTimeFromStringInvalidFunctionParameterCountError = 41682;
/// <summary>
/// The event identifier for ExpressionFunction DataTimeFromString events
/// </summary>
public const int ExpressionFunctionDateTimeFromStringNullFunctionParameterError = 41682;
/// <summary>
/// The event identifier for ExpressionFunction DataTimeFromString events
/// </summary>
public const int ExpressionFunctionDateTimeFromStringInvalidFirstFunctionParameterTypeError = 41682;
/// <summary>
/// The event identifier for ExpressionFunction DataTimeFromString events
/// </summary>
public const int ExpressionFunctionDateTimeFromStringInvalidSecondFunctionParameterTypeError = 41682;
/// <summary>
/// The event identifier for ExpressionFunction DataTimeFromString events
/// </summary>
public const int ExpressionFunctionDateTimeFromStringInvalidFunctionParametersError = 41682;
/// <summary>
/// The event identifier for LookupEvaluator Constructor events
/// </summary>

Просмотреть файл

@ -177,6 +177,9 @@ namespace MicrosoftServices.IdentityManagement.WorkflowActivityLibrary.Common
case "DATETIMEFROMFILETIMEUTC":
return this.DateTimeFromFileTimeUtc();
case "DATETIMEFROMSTRING":
return this.DateTimeFromString();
case "DATETIMENOW":
return this.DateTimeNow();
@ -2230,6 +2233,81 @@ namespace MicrosoftServices.IdentityManagement.WorkflowActivityLibrary.Common
}
}
/// <summary>
/// This function is used to convert string representation of a date and time to its DateTime equivalent.
/// If the string does not contain time zone info, it's assumed to be UTC.
/// If the optional culture name parameter is not specified, it's assumed to be invariant culture.
/// Function Syntax: DateTimeFromString(string:dateTime [, culture:cultureName])
/// </summary>
/// <returns>A DateTime equivalent to specified string. If the string is null, a null is returned.</returns>
private object DateTimeFromString()
{
Logger.Instance.WriteMethodEntry(EventIdentifier.ExpressionFunctionDateTimeFromString, "Evaluation Mode: '{0}'.", this.mode);
try
{
if (this.parameters.Count < 1 && this.parameters.Count > 2)
{
throw Logger.Instance.ReportError(EventIdentifier.ExpressionFunctionDateTimeFromStringInvalidFunctionParameterCountError, new InvalidFunctionFormatException(Messages.ExpressionFunction_InvalidFunctionParameterCountError2, this.function, 1, 2, this.parameters.Count));
}
Type parameterType = typeof(string);
object parameter = this.parameters[0];
if (!this.VerifyType(parameter, parameterType))
{
throw Logger.Instance.ReportError(EventIdentifier.ExpressionFunctionDateTimeFromStringInvalidFirstFunctionParameterTypeError, new InvalidFunctionFormatException(Messages.ExpressionFunction_InvalidFirstFunctionParameterTypeError, this.function, parameterType.Name, parameter == null ? "null" : parameter.GetType().Name));
}
object result = null;
if (this.mode != EvaluationMode.Parse)
{
if (this.parameters[0] == null)
{
result = null;
}
else
{
var cultureInfo = CultureInfo.InvariantCulture;
if (this.parameters.Count == 2)
{
try
{
cultureInfo = new CultureInfo(this.parameters[1] as string);
}
catch (ArgumentException e)
{
throw Logger.Instance.ReportError(EventIdentifier.ExpressionFunctionDateTimeFromStringInvalidSecondFunctionParameterTypeError, e);
}
}
try
{
result = DateTime.Parse(this.parameters[0] as string, cultureInfo, DateTimeStyles.AdjustToUniversal | DateTimeStyles.AssumeUniversal);
}
catch (FormatException e)
{
throw Logger.Instance.ReportError(EventIdentifier.ExpressionFunctionDateTimeFromStringInvalidFunctionParametersError, e);
}
}
if (this.parameters.Count == 1)
{
Logger.Instance.WriteVerbose(EventIdentifier.ExpressionFunctionDateTimeFromString, "DateTimeFromString('{0}') returned '{1}'.", this.parameters[0], result);
}
else
{
Logger.Instance.WriteVerbose(EventIdentifier.ExpressionFunctionDateTimeFromString, "DateTimeFromString('{0}', '{1}') returned '{2}'.", this.parameters[0], this.parameters[1], result);
}
}
return result;
}
finally
{
Logger.Instance.WriteMethodExit(EventIdentifier.ExpressionFunctionDateTimeFromString, "Evaluation Mode: '{0}'.", this.mode);
}
}
/// <summary>
/// This function is used to get a DateTime object that is set to the current date and time on FIM server, expressed as the Coordinated Universal Time (UTC).
/// Function Syntax: DateTimeNow()
@ -5285,6 +5363,24 @@ namespace MicrosoftServices.IdentityManagement.WorkflowActivityLibrary.Common
using (var dbConnection = factory.CreateConnection())
{
dbConnection.ConnectionString = connectionString;
if (providerName.Equals("System.Data.Odbc", StringComparison.OrdinalIgnoreCase))
{
if (connectionString.IndexOf("CONNECTION TIMEOUT=", StringComparison.OrdinalIgnoreCase) != -1)
{
try
{
var connectionTimeout = Convert.ToInt32(connectionString.ToUpperInvariant().Split(new string[] { "CONNECTION TIMEOUT=" }, StringSplitOptions.RemoveEmptyEntries)[1].Split(';')[0], CultureInfo.InvariantCulture);
Logger.Instance.WriteVerbose(EventIdentifier.ExpressionFunctionExecuteSqlScalar, "Provider Name: '{0}'. Connection Timeout: '{1}'.", providerName, connectionTimeout);
((OdbcConnection)dbConnection).ConnectionTimeout = connectionTimeout;
}
catch (Exception e)
{
throw Logger.Instance.ReportError(EventIdentifier.ExpressionFunctionExecuteSqlNonQueryNullFunctionParameterError, new InvalidFunctionFormatException(Messages.ExpressionFunction_InvalidConfigKeyConfiguration, e, this.function, "Connection Timeout"));
}
}
}
using (var dbCommand = factory.CreateCommand())
{
dbCommand.Connection = dbConnection;
@ -5420,6 +5516,24 @@ namespace MicrosoftServices.IdentityManagement.WorkflowActivityLibrary.Common
using (var dbConnection = factory.CreateConnection())
{
dbConnection.ConnectionString = connectionString;
if (providerName.Equals("System.Data.Odbc", StringComparison.OrdinalIgnoreCase))
{
if (connectionString.IndexOf("CONNECTION TIMEOUT=", StringComparison.OrdinalIgnoreCase) != -1)
{
try
{
var connectionTimeout = Convert.ToInt32(connectionString.ToUpperInvariant().Split(new string[] { "CONNECTION TIMEOUT=" }, StringSplitOptions.RemoveEmptyEntries)[1].Split(';')[0], CultureInfo.InvariantCulture);
Logger.Instance.WriteVerbose(EventIdentifier.ExpressionFunctionExecuteSqlNonQuery, "Provider Name: '{0}'. Connection Timeout: '{1}'.", providerName, connectionTimeout);
((OdbcConnection)dbConnection).ConnectionTimeout = connectionTimeout;
}
catch (Exception e)
{
throw Logger.Instance.ReportError(EventIdentifier.ExpressionFunctionExecuteSqlNonQueryNullFunctionParameterError, new InvalidFunctionFormatException(Messages.ExpressionFunction_InvalidConfigKeyConfiguration, e, this.function, "Connection Timeout"));
}
}
}
using (var dbCommand = factory.CreateCommand())
{
dbCommand.Connection = dbConnection;