//*****************************************************************************
// This code file is part of the Universal Provider Framework for SharePoint.
// This file was written by Adam Buenz [WSS MVP] of ARB Security Solutions, LLC
// http://www.sharepointsecurity.com
//
// This file and its parts is free for re-distribution, for use in both free
// and commercial applications, however this header must remain intact for legal
// use. The Universal Provider Framework is distributed in the hope that it will
// be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
//*****************************************************************************
//**************************************
// Current Version: 1.0.0.0 (Beta)
//**************************************
// namespace references
using System;
using System.Collections.Specialized;
using System.Configuration.Provider;
using System.Globalization;
namespace Universal.SharePointProvider.Framework
{
internal class GeneralUtilities
{
///
/// Determine valid boolean values
///
///
///
///
///
internal static bool GetBooleanValue(NameValueCollection config, string valueName, bool defaultValue)
{
bool flagValid;
//We have the valueName 'string' and need to inspect if it is on NameValuecollection or not
string textConfig = config[valueName];
if (textConfig == null)
{
//return the value sent by the function
return defaultValue;
}
if (!bool.TryParse(textConfig, out flagValid))
{
throw new ProviderException("The value needs to be boolean for " + valueName);
}
//Returns a vaildation flag
return flagValid;
}
///
/// Determine valid integer values
///
///
///
///
///
///
///
internal static int GetIntValue(NameValueCollection config, string valueName, int defaultValue, bool zeroAllowed, int maxValueAllowed)
{
int numValidation;
//same as first function
string textConfig = config[valueName];
if (textConfig == null)
{
return defaultValue;
}
//textconig contains numbers
if (!int.TryParse(textConfig, out numValidation))
{
if (zeroAllowed)
{
throw new ProviderException("The SharePoint provider requires the value must be a non-negative integer for " + valueName);
}
throw new ProviderException("The SharePoint provider requires the value must be a positive integer for " + valueName);
}
if (zeroAllowed && (numValidation < 0))
{
throw new ProviderException("The SharePoint provider requires the value must be a non-negative integer for " + valueName);
}
if (!zeroAllowed && (numValidation <= 0))
{
throw new ProviderException("The SharePoint provider requires the value must be a positive integer for " + valueName);
}
if ((maxValueAllowed > 0) && (numValidation > maxValueAllowed))
{
throw new ProviderException(valueName + "value is greater than " + maxValueAllowed.ToString(CultureInfo.InvariantCulture));
}
return numValidation;
}
}
}