static string FindUniqueTimedFile( string pathPrefix, string fileSuffix, DateTime time, int maxTryBeforeGuid, Func<string, bool> tester )
{
if( pathPrefix == null ) throw new ArgumentNullException( "pathPrefix" );
if( fileSuffix == null ) throw new ArgumentNullException( "fileSuffix" );
if( maxTryBeforeGuid < 0 ) throw new ArgumentOutOfRangeException( "maxTryBeforeGuid" );
DateTimeStamp timeStamp = new DateTimeStamp( time );
int counter = 0;
string result = pathPrefix + timeStamp.ToString() + fileSuffix;
for( ; ; )
{
if( tester( result ) ) break;
if( counter < maxTryBeforeGuid )
{
timeStamp = new DateTimeStamp( timeStamp, timeStamp );
result = pathPrefix + timeStamp.ToString() + fileSuffix;
}
else
{
if( counter == maxTryBeforeGuid + 1 ) throw new CKException( Impl.CoreResources.FileUtilUnableToCreateUniqueTimedFile );
if( counter == maxTryBeforeGuid )
{
result = pathPrefix + FormatTimedUniqueFilePart( time ) + fileSuffix;
}
}
++counter;
}
return result;
}