Remodef form, added state class to save and load previous execution state.
[LanSpider.git] / LanSpider / LanSpider.cs
bloba002d3842cb4d4b13a28cfbfa9ae34abf1dd0593
1 using System;
2 using System.Collections.Generic;
4 namespace LanSpider
6 /// <summary>
7 /// Gathers information on open shares in local area network.
8 /// </summary>
9 internal class LanSpider
11 private static readonly string IndexFileName = "index";
12 private static readonly string StateFileName = "state";
14 private State _state;
15 private List<string> _machines;
17 public State State
19 get
21 if ( _state == null )
23 _state = new State( StateFileName );
26 return _state;
30 public void StartIndexing( )
32 DiscoverMachines( );
34 DiscoverShares( );
36 IndexShares( );
39 private void DiscoverMachines( )
41 Console.Write( "Loading list of computers in network ... " );
43 IEnumerable<string> machines = NetworkBrowser.GetNetworkComputers( );
44 _machines = new List<string>( new[] {"EPUAKYIV01"} );
46 Console.WriteLine( "done." );
49 private void DiscoverShares( )
51 Queue<string> shareQueue = null;
53 Console.Write( "Loading saved shares ... " );
54 if ( _machines.Count != State.MachinesCount )
56 shareQueue = new Queue<string>( State.GetMissingMachines( _machines ) );
59 Console.WriteLine( "done." );
61 if ( shareQueue != null )
63 Console.Write( "Loading {0} new shares ... ", shareQueue.Count );
64 foreach ( string machine in shareQueue )
66 IEnumerable<string> shares = NetworkBrowser.GetShares( machine );
67 foreach ( string share in shares )
69 State.AddShare( String.Format( @"\\{0}\{1}", machine, share ) );
73 Console.WriteLine( "done." );
77 private void IndexShares( )