This commit is contained in:
2026-04-17 14:55:32 -04:00
commit bc3ac1d4c9
18017 changed files with 4371742 additions and 0 deletions

View File

@@ -0,0 +1,257 @@
/*
AttributeCoder.cs
* 12/18/2008 Relo'd from Dave to SVN-controlled utilities project.
$Log: AttributeCoder.cs,v $
Revision 1.1 2006/09/14 18:41:54 Paul Hrissikopoulos
Moved AttributeCoder files from Dave solution.
Revision 1.3 2006/09/07 20:43:08 Paul Hrissikopoulos
Expanded commentary.
Revision 1.2 2006/08/17 23:44:46 Paul Hrissikopoulos
Removed freeloading DCX XML prototype code.
Revision 1.1 2006/08/17 23:05:11 Paul Hrissikopoulos
Added generically-derived SelectionCriterion.ComparisonType enumeration attributes.
Copyright © 2006
Diversified Technical Systems
All Rights Reserved
*/
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
namespace DatabaseExport
{
/// <summary>
/// Object for manipulating object-attached attributes and attribute values.
/// </summary>
///
/// <typeparam name="TargetType">
/// The type of <see cref="object"/> the attributes we are concerned with are
/// are attached to.
/// </typeparam>
///
/// <typeparam name="AttributeType">
/// The type of attribute to be manipulated.
/// </typeparam>
///
/// <typeparam name="AttributeValueType">
/// The type of value contained by the attribute to be manipulated.
/// </typeparam>
///
/// <remarks>
/// This class was created to make it easier to "match" attributes and the data
/// types they're attached to in a somewhat generic manner. It is intended that
/// attribute coder classes that deal with specific attribute types be derived
/// from this one.
/// </remarks>
///
public class AttributeCoder<TargetType, AttributeType, AttributeValueType> : Exceptional
{
/// <summary>
/// Method that specifies how to access the value of a given "AttributeType".
/// </summary>
///
/// <param name="attribute">
/// The "AttributeType" attribute to have its value extracted.
/// </param>
///
/// <returns>
/// The "AttributeValueType" value of the specified attribute.
/// </returns>
///
public delegate AttributeValueType AttributeValueExtractionMethod(AttributeType attribute);
/// <summary>
/// Method for determining the equality of two "AttributeValueType" values.
/// </summary>
///
/// <param name="value1">
/// A "AttributeValueType" to be equality-compared.
/// </param>
///
/// <param name="value2">
/// A "AttributeValueType" to be equality-compared.
/// </param>
///
/// <returns>
/// True if the two values are equal; false otherwise.
/// </returns>
///
public delegate bool AttributeValueEqualityComparisonMethod(AttributeValueType value1, AttributeValueType value2);
private readonly AttributeValueExtractionMethod _extractAttributeValue;
private readonly AttributeValueEqualityComparisonMethod _areAttributeValuesEqual;
/// <summary>
/// Initializes an instance of the AttributeCoder class.
/// </summary>
///
/// <param name="attributeValueExtractionMethod">
/// A <see cref="AttributeValueExtractionMethod"/> that defines how "AttributeValueType"
/// values are to be extracted from "AttributeType" attributes.
/// </param>
///
/// <param name="attributeValueEqualityComparisonMethod">
/// Optional parameter for specifying a custom comparison method to override default
/// "AttributeValueType" equality determination. Pass null to use default
/// comparison.
/// </param>
///
public AttributeCoder(AttributeValueExtractionMethod attributeValueExtractionMethod,
AttributeValueEqualityComparisonMethod attributeValueEqualityComparisonMethod)
{
try
{
_extractAttributeValue = attributeValueExtractionMethod ?? throw new Exception("cannot use null attribute value extraction method reference");
if (null != attributeValueEqualityComparisonMethod)
_areAttributeValuesEqual = attributeValueEqualityComparisonMethod;
}
catch (Exception ex)
{
throw new Exception(
string.Format("encountered problem constructing {0}", /*fix this Resources.Generic_EncounteredProblemConstructingClassString,*/ GetType().FullName), ex);
}
}
/// <summary>
/// Return the "AttributeValueType" of the "AttributeType" attribute
/// attached to the specified "TargetType".
/// </summary>
///
/// <param name="target">
/// The "TargetType" object whose "AttributeType" attribute is to be
/// evaluated.
/// </param>
///
/// <returns>
/// The "AttributeValueType" of the "AttributeType" attribute attached
/// to the specified "TargetType".
/// </returns>
///
public AttributeValueType DecodeAttributeValue(TargetType target)
{
try
{
var attributes = DecodeAttributeValues(target);
Debug.Assert(1 == attributes.Count);
if (attributes.Count > 0) return attributes[0];
throw new Exception("no attributes of specified type found on designated target"); //fix this Resources.AttributeCoder_NoTypeAttributesFoundOnTargetString);
}
catch (Exception)
{
throw new Exception("encountered problem decoding attribute value"); //fix this Resources.AttributeCoder_DecodeAttributeExceptionString, ex);
}
}
/// <summary>
/// Return the <see cref="T:List"/> of "AttributeValueType"s of the
/// "AttributeType" attached to the specified "TargetType".
/// </summary>
///
/// <param name="target">
/// The "TargetType" object whose "AttributeType" attribute is to be
/// evaluated.
/// </param>
///
/// <returns>
/// The "AttributeValueType" of the "AttributeType" attribute attached
/// to the specified "TargetType".
/// </returns>
///
public List<AttributeValueType> DecodeAttributeValues(TargetType target)
{
try
{
var info = target.GetType().GetField(target.ToString());
var attributes = (info.GetCustomAttributes(typeof(AttributeType), false) as AttributeType[]);
var attributeList = new List<AttributeValueType>();
if (attributes != null)
{
attributeList.AddRange(attributes.Select(t => _extractAttributeValue(t)));
}
return attributeList;
}
catch (Exception ex)
{
throw new Exception($"encountered problem decoding attribute values {ex.Message}"); //fix this Resources.AttributeCoder_DecodeAttributesExceptionString, ex);
}
}
/// <summary>
/// Return the "TargetType" value that has the "AttributeType"
/// attribute with the specified "AttributeValueType" value attached
/// to it.
/// </summary>
///
/// <param name="attributeValue">
/// The value of the "AttributeType" attribute attached to the
/// "TargetType" target object we're looking for.
/// </param>
///
/// <returns>
/// The "TargetType" target object that has the "AttributeType"
/// attribute attached to it that has a "AttributeValueType" value of
/// attributeValue.
/// </returns>
///
public TargetType EncodeAttributeValue(AttributeValueType attributeValue)
{
try
{
var targets = DehashAttributeValue(attributeValue);
Debug.Assert(1 == targets.Count, "unable to find unique target type mapping for the specified attribute value"); //fix this Resources.AttributeCoder_UnableToFindTargetTypeMappingString);
if (1 != targets.Count)
throw new Exception("unable to find unique target type mapping for the specified attribute value"); //fix this Resources.AttributeCoder_UnableToFindTargetTypeMappingString);
return targets[0];
}
catch (System.Exception ex)
{
throw new Exception("encountered problem encoding attribute value", ex); //fix this Resources.AttributeCoder_EncodeAttributeExceptionString, ex);
}
}
/// <summary>
/// Return a list of "TargetType" values that have the
/// "AttributeType" attribute with the specified
/// "AttributeValueType" value attached to them.
/// </summary>
///
/// <param name="attributeValue">
/// The value of the "AttributeType" attribute attached to the
/// "TargetType" target object we're looking for.
/// </param>
///
/// <returns>
/// The <see cref="T:List"/> of "TargetType" target objects that has
/// the "AttributeType" attribute attached to it that has a
/// "AttributeValueType" value of attributeValue.
/// </returns>
///
public List<TargetType> DehashAttributeValue(AttributeValueType attributeValue)
{
try
{
var targets = Enum.GetValues(typeof(TargetType)).Cast<TargetType>()
.Where(target => (null != _areAttributeValuesEqual) ?
_areAttributeValuesEqual(DecodeAttributeValue(target), attributeValue) : DecodeAttributeValue(target).Equals(attributeValue)).ToList();
if (targets.Count <= 0)
throw new Exception("unable to match attribute value with an actual target type"); // fix this Resources.AttributeCoder_DehashAttributeValue_UnableToMatchAttributeValueWithTargetString);
return targets;
}
catch (System.Exception ex)
{
throw new Exception("encountered problem dehashing attribute value", ex); // fix this Resources.AttributeCoder_DehashAttributeValue_DehashAttributeValueExceptionString, ex);
}
}
}
}

View File

@@ -0,0 +1,37 @@
/*
* DiskUtility.cs
*
* Copyright © 2009
* Diversified Technical Systems, Inc.
* All Rights Reserved
*/
using System.IO;
using System.Linq;
namespace DatabaseExport
{
/// <summary>
/// A collection of handy disk-related methods.
/// </summary>
public class DiskUtility : Exceptional
{
/// <summary>
/// checks to see if a string contains illegal characters for file and/or path names
/// </summary>
/// <param name="nameToValidate"></param>
/// <returns></returns>
public static bool ValidateFileAndPathNameChars(string nameToValidate)
{
var bValid = true;
var name = nameToValidate;
if (name.Trim().Length < 1) { bValid = false; }
foreach (var invalidChar in Path.GetInvalidFileNameChars())
if (name.Contains(invalidChar)) { bValid = false; }
foreach (var invalidChar in Path.GetInvalidPathChars())
if (name.Contains(invalidChar)) { bValid = false; }
if (name.Contains('.')) { bValid = false; }
return bValid;
}
}
}

View File

@@ -0,0 +1,49 @@
/*
Exceptional.cs
Copyright © 2008
Diversified Technical Systems, Inc.
All Rights Reserved
*/
using System;
namespace DatabaseExport
{
/// <summary>
/// "Ultimate" base class for all DTS classes that expect to throw exceptions.
/// Deriving classes from this class allows exceptions to be trapped based on
/// the class type that threw them.
/// </summary>
///
/// <remarks>
/// Sample usage:
/// public class A : Exceptional
/// {
/// public void ScrewItUp( )
/// {
/// private bool error = true;
/// if ( error ) throw new A.Exception( "Class A-specific screwup." );
/// }
/// }
///
/// ...
///
/// try
/// {
/// A.ScrewItUp( );
/// B.ScrewItUp( );
/// C.ScrewItUp( );
/// }
/// catch ( A.Exception ex )
/// {
/// // Can pick A's exceptions out of a crowd, or not and just treat it
/// // polymorphically as a System.Exception.
/// }
/// </remarks>
///
[Serializable]
public abstract class Exceptional
{
}
}

View File

@@ -0,0 +1,51 @@
/*
* ExceptionalList.cs
*
* Copyright © 2009
* Diversified Technical Systems, Inc.
* All Rights Reserved
*/
using System.Collections.Generic;
namespace DatabaseExport
{
/// <summary>
/// A version of <see cref="T:List"/> that provides its own exception type.
/// </summary>
///
/// <typeparam name="T">
/// The type of object contained by this list.
/// </typeparam>
///
/// <remarks>
/// Sample usage:
/// public class A : ExceptionalList &lt;int&gt;
/// {
/// public void ScrewItUp( )
/// {
/// private bool error = true;
/// if ( error ) throw new A.Exception( "Class A-specific screwup." );
/// }
/// }
///
/// ...
///
/// try
/// {
/// A.ScrewItUp( );
/// B.ScrewItUp( );
/// C.ScrewItUp( );
/// }
/// catch ( A.Exception ex )
/// {
/// // Can pick A's exceptions out of a crowd, or not and just treat it
/// // polymorphically as a System.Exception.
/// }
/// </remarks>
///
[global::System.Serializable]
public class ExceptionalList<T> : List<T>
{
}
}