Skip to content

Commit

Permalink
Merge pull request #22 from cincuranet/resources
Browse files Browse the repository at this point in the history
DNET-570
  • Loading branch information
cincuranet committed Jan 23, 2015
2 parents 4ebc2ba + 4a2a21b commit 1859a50
Show file tree
Hide file tree
Showing 6 changed files with 2,040 additions and 6,093 deletions.

Large diffs are not rendered by default.

109 changes: 50 additions & 59 deletions NETProvider/src/FirebirdSql.Data.FirebirdClient/Common/IscException.cs
Expand Up @@ -194,86 +194,71 @@ private void BuildSqlState()
// step #2, see if we can find a mapping.
else
{
using (var rs = CreateResourceSet("FirebirdSql.Data.Resources.sqlstate_mapping"))
{
this.SQLSTATE = rs.GetString(this.ErrorCode.ToString());
}
this.SQLSTATE = GetValueOrDefault(SqlStateMapping.Values, this.ErrorCode, _ => string.Empty);
}
}

private void BuildExceptionMessage()
{
StringBuilder builder = new StringBuilder();

using (var rs = CreateResourceSet("FirebirdSql.Data.Resources.isc_error_msg"))
for (int i = 0; i < this.Errors.Count; i++)
{
for (int i = 0; i < this.Errors.Count; i++)
if (this.Errors[i].Type == IscCodes.isc_arg_gds ||
this.Errors[i].Type == IscCodes.isc_arg_warning)
{
if (this.Errors[i].Type == IscCodes.isc_arg_gds ||
this.Errors[i].Type == IscCodes.isc_arg_warning)
{
int code = this.Errors[i].ErrorCode;
string message = null;
int code = this.Errors[i].ErrorCode;
string message = GetValueOrDefault(IscErrorMessages.Values, code, BuildDefaultErrorMessage);

try
{
message = rs.GetString(code.ToString());
}
catch
{
message = BuildDefaultErrorMessage(code);
}
ArrayList param = new ArrayList();

ArrayList param = new ArrayList();
int index = i + 1;

int index = i + 1;
while (index < this.Errors.Count && this.Errors[index].IsArgument)
{
param.Add(this.Errors[index++].StrParam);
i++;
}

object[] args = (object[])param.ToArray(typeof(object));

while (index < this.Errors.Count && this.Errors[index].IsArgument)
try
{
if (code == IscCodes.isc_except)
{
param.Add(this.Errors[index++].StrParam);
i++;
// Custom exception add the first argument as error code
this.ErrorCode = Convert.ToInt32(args[0], CultureInfo.InvariantCulture);
}

object[] args = (object[])param.ToArray(typeof(object));

try
else if (code == IscCodes.isc_except2)
{
if (code == IscCodes.isc_except)
{
// Custom exception add the first argument as error code
this.ErrorCode = Convert.ToInt32(args[0], CultureInfo.InvariantCulture);
}
else if (code == IscCodes.isc_except2)
{
// Custom exception. Next Error should be the exception name.
// And the next one the Exception message
}
else if (code == IscCodes.isc_stack_trace)
{
// The next error contains the PSQL Stack Trace
if (builder.Length > 0)
{
builder.Append(Environment.NewLine);
}
builder.AppendFormat(CultureInfo.CurrentCulture, "{0}", args);
}
else
// Custom exception. Next Error should be the exception name.
// And the next one the Exception message
}
else if (code == IscCodes.isc_stack_trace)
{
// The next error contains the PSQL Stack Trace
if (builder.Length > 0)
{
if (builder.Length > 0)
{
builder.Append(Environment.NewLine);
}

builder.AppendFormat(CultureInfo.CurrentCulture, message, args);
builder.Append(Environment.NewLine);
}
builder.AppendFormat(CultureInfo.CurrentCulture, "{0}", args);
}
catch
else
{
message = BuildDefaultErrorMessage(code);
if (builder.Length > 0)
{
builder.Append(Environment.NewLine);
}

builder.AppendFormat(CultureInfo.CurrentCulture, message, args);
}
}
catch
{
message = BuildDefaultErrorMessage(code);

builder.AppendFormat(CultureInfo.CurrentCulture, message, args);
}
}
}

Expand All @@ -292,12 +277,18 @@ private string BuildDefaultErrorMessage(int code)
return string.Format(CultureInfo.CurrentCulture, "No message for error code {0} found.", code);
}

private ResourceSet CreateResourceSet(string resourceName)
#endregion

#region · Static Methods ·

private static string GetValueOrDefault(IDictionary<int, string> dictionary, int key, Func<int, string> defaultValueFactory)
{
using (var resourceStream = Assembly.GetExecutingAssembly().GetManifestResourceStream(resourceName + ".resources"))
string result;
if (!dictionary.TryGetValue(key, out result))
{
return new ResourceSet(resourceStream);
result = defaultValueFactory(key);
}
return result;
}

#endregion
Expand Down

0 comments on commit 1859a50

Please sign in to comment.