init
This commit is contained in:
@@ -0,0 +1,140 @@
|
||||
/*
|
||||
PowerOfTwoIntProperty.cs
|
||||
|
||||
Copyright © 2008
|
||||
Diversified Technical Systems, Inc.
|
||||
All Rights Reserved
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Text;
|
||||
using DTS.Common.Utilities;
|
||||
|
||||
namespace DTS.Common.Utilities.DotNetProgrammingConstructs
|
||||
{
|
||||
/// <summary>
|
||||
/// A class to implement self-checking, on-error-auto-syntax-building
|
||||
/// power of 2 int properties.
|
||||
/// </summary>
|
||||
public class PowerOfTwoIntProperty : Property<int>
|
||||
{
|
||||
/// <summary>
|
||||
/// Determine whether or not the specified value is valid for this property.
|
||||
/// </summary>
|
||||
///
|
||||
/// <param name="value">
|
||||
/// The <see cref="int"/> value to be validity checked.
|
||||
/// </param>
|
||||
///
|
||||
/// <returns>
|
||||
/// <see cref="bool"/> true if the value is valid; false otherwise.
|
||||
/// </returns>
|
||||
///
|
||||
public override bool IsValidValue(int value)
|
||||
{
|
||||
try
|
||||
{
|
||||
return IsPowerOf2(value);
|
||||
}
|
||||
|
||||
catch (System.Exception ex)
|
||||
{
|
||||
throw new Exception(
|
||||
string.Format(Properties.Resources.PowerOfTwoProperty_IsValidValue_UnableToDetermineValidityString, value.ToString()),
|
||||
ex);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Determine whether or not the specified value is a power of two.
|
||||
/// </summary>
|
||||
///
|
||||
/// <param name="value">
|
||||
/// The <see cref="int"/> value to be power of 2-checked.
|
||||
/// </param>
|
||||
///
|
||||
/// <returns>
|
||||
/// <see cref="bool"/> true if the value is a power of 2, false otherwise.
|
||||
/// </returns>
|
||||
///
|
||||
private bool IsPowerOf2(int value)
|
||||
{
|
||||
try
|
||||
{
|
||||
for (var r = value; r > 0; r >>= 1)
|
||||
if (2 == r) return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
catch (System.Exception ex)
|
||||
{
|
||||
throw new Exception(
|
||||
string.Format(Properties.Resources.PowerOfTwoProperty_IsPowerOf2_UnableToDeterminePowerOf2nessString, value.ToString()),
|
||||
ex);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Generate a user-readable explanation as to why the specified value is
|
||||
/// not valid for this property.
|
||||
/// </summary>
|
||||
///
|
||||
/// <param name="value">
|
||||
/// The <see cref="int"/> value to be described.
|
||||
/// </param>
|
||||
///
|
||||
/// <returns>
|
||||
/// A <see cref="string"/> description explaining why the specified value
|
||||
/// is not valid for this property.
|
||||
/// </returns>
|
||||
///
|
||||
public override string GetInvalidValueDescription(int value)
|
||||
{
|
||||
try
|
||||
{
|
||||
return string.Format(Properties.Resources.PowerOfTwoProperty_GetInvalidValueDescription_ProposedValueIsNotPowerOf2String, value.ToString());
|
||||
}
|
||||
|
||||
catch (System.Exception ex)
|
||||
{
|
||||
throw new Exception(Properties.Resources.PowerOfTwoProperty_GetInvalidValueDescription_UnableToGetDescriptionString, ex);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initialize an instance of a power of two int property.
|
||||
/// </summary>
|
||||
///
|
||||
/// <param name="initialValue">
|
||||
/// The initialize <see cref="int"/> value of the int property.
|
||||
/// </param>
|
||||
///
|
||||
public PowerOfTwoIntProperty(int initialValue)
|
||||
: base(initialValue, true)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (!IsValidValue(initialValue))
|
||||
throw new InvalidValueException(GetInvalidValueDescription(initialValue));
|
||||
else return;
|
||||
}
|
||||
|
||||
catch (System.Exception ex)
|
||||
{
|
||||
throw new ConstructionException(
|
||||
string.Format(Properties.Resources.Generic_EncounteredProblemConstructingClassString, GetType().FullName)
|
||||
, ex);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initialize an instance of a power of two int property.
|
||||
/// </summary>
|
||||
public PowerOfTwoIntProperty()
|
||||
: base(0, false)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
/*
|
||||
* LargeArray.NameGeneratorLock.cs
|
||||
*
|
||||
* Copyright © 2009
|
||||
* Diversified Technical Systems, Inc.
|
||||
* All Rights Reserved
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Linq;
|
||||
using System.Runtime.ConstrainedExecution;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
using DTS.Common.Utilities;
|
||||
using DTS.Common.Utilities.DotNetProgrammingConstructs;
|
||||
|
||||
namespace DTS.Common.Utilities.IO.MemoryMap
|
||||
{
|
||||
// *** see LargeArray.cs ***
|
||||
public partial class LargeArray<T>
|
||||
{
|
||||
/// <summary>
|
||||
/// A class intended to serve as a locking object for all MegArrays, so they don't
|
||||
/// try to use the same seed number for generating their respective scratch files.
|
||||
/// </summary>
|
||||
protected class NameGeneratorLock
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace DTS.Common.Utilities
|
||||
{
|
||||
/// <summary>
|
||||
/// this is a class for doing natural string compares like in explorer (using the explorer function)
|
||||
/// http://msdn.microsoft.com/en-us/library/bb759947%28VS.85%29.aspx
|
||||
/// </summary>
|
||||
/// <remarks>requires XP or greater</remarks>
|
||||
public class NaturalStringComparer : IComparer<string>
|
||||
{
|
||||
[DllImport("shlwapi.dll", CharSet = CharSet.Unicode, ExactSpelling = true)]
|
||||
static extern int StrCmpLogicalW(String x, String y);
|
||||
|
||||
/// <summary>
|
||||
/// do a natural string compare between two strings
|
||||
/// </summary>
|
||||
/// <param name="x">left string to compare</param>
|
||||
/// <param name="y">right string to compare</param>
|
||||
/// <returns>-1 if natural order of x is less than y, +1 if x is after y, 0 if they are equal</returns>
|
||||
public int Compare(string x, string y)
|
||||
{
|
||||
if (null == x) { return -1; }
|
||||
if (null == y) { return 1; }
|
||||
return StrCmpLogicalW(x, y);
|
||||
}
|
||||
|
||||
public static int StaticCompare(string x, string y)
|
||||
{
|
||||
if (null == x) { return -1; }
|
||||
if (null == y) { return 1; }
|
||||
return StrCmpLogicalW(x, y);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user