CK.Core.FileUtil.FindUniqueTimedFile C# (CSharp) Method

FindUniqueTimedFile() static private method

static private FindUniqueTimedFile ( string pathPrefix, string fileSuffix, System.DateTime time, int maxTryBeforeGuid, bool>.Func tester ) : string
pathPrefix string
fileSuffix string
time System.DateTime
maxTryBeforeGuid int
tester bool>.Func
return string
        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;
        }