2 using System
.Collections
.Generic
;
9 /// Fake network browser which takes information from file.
11 internal class TextNetworkBrowser
: INetworkBrowser
13 private readonly string _filename
;
15 public TextNetworkBrowser( string filename
)
20 public IEnumerable
<string> GetNetworkComputers()
22 return ReadItems( 2 );
25 public IEnumerable
<string> GetShares( string serverName
)
27 return ReadItems( serverName
, 3, true );
30 public IEnumerable
<FileInfo
> GetSharedFiles( string shareName
)
32 return from filename
in ReadItems( shareName
, true )
33 select new FileInfo( filename
);
38 private IEnumerable
<string> ReadItems( string mask
, int clipDepth
)
40 return ReadItems( mask
, clipDepth
, false );
43 private IEnumerable
<string> ReadItems( int clipDepth
)
45 return ReadItems( clipDepth
, false );
48 private IEnumerable
<string> ReadItems( int clipDepth
, bool entriesGroupped
)
50 return ReadItems( null, clipDepth
, entriesGroupped
);
53 private IEnumerable
<string> ReadItems( string mask
, bool entriesGroupped
)
55 return ReadItems( mask
, 0, entriesGroupped
);
60 private IEnumerable
<string> ReadItems( string mask
, int clipDepth
, bool entriesGroupped
)
62 List
<string> items
= new List
<string>();
64 using ( StreamReader reader
= File
.OpenText( _filename
) )
68 while ( !( String
.IsNullOrEmpty( line
= reader
.ReadLine() ) ) )
70 string path
= line
.Trim( new[] { '[', ']', ' ', '\t' }
);
71 if ( String
.IsNullOrEmpty( mask
) || path
.StartsWith( mask
) )
78 for ( int i
= 0; i
< clipDepth
; ++i
)
80 lastIndex
= path
.IndexOf( '\\', lastIndex
+ 1 );
83 item
= path
.Substring( 0, lastIndex
);
90 if ( !items
.Contains( item
) )
95 else if ( entriesGroupped
&& items
.Count
> 0 )