From ecb325c9030c27ddfad644b8e7197a43f008d11d Mon Sep 17 00:00:00 2001 From: zzandy Date: Wed, 5 Aug 2009 13:26:07 +0000 Subject: [PATCH] Streamed implementation. Limited input buffer. git-svn-id: https://abrams/svn/LanSpider-repo@35 16f2e333-51b0-4855-8c5a-a66b7be24171 --- src/Indexer/Indexer.csproj | 17 +- src/Indexer/Program.cs | 33 ++- .../ShareDiscoveryReference/Reference.cs | 6 +- .../ShareDiscoveryReference/Reference.svcmap | 9 +- .../ShareDiscoveryReference/ShareDiscovery.xsd | 20 -- .../ShareDiscoveryReference/configuration.svcinfo | 2 +- .../configuration91.svcinfo | 14 +- .../ShareDiscoveryReference/service.wsdl | 1 - .../ShareDiscoveryReference/service.xsd | 6 +- .../ShareDiscoveryReference/service1.xsd | 42 --- src/Indexer/app.config | 118 +++------ src/ShareDiscovery/IShareDiscoveryService.cs | 4 +- src/ShareDiscovery/IndexManager.cs | 294 +++++++++++++++++++++ src/ShareDiscovery/ShareDiscovery.csproj | 8 +- src/ShareDiscovery/ShareDiscoveryService.cs | 154 +---------- src/ShareDiscovery/app.config | 11 + 16 files changed, 402 insertions(+), 337 deletions(-) delete mode 100644 src/Indexer/Service References/ShareDiscoveryReference/ShareDiscovery.xsd delete mode 100644 src/Indexer/Service References/ShareDiscoveryReference/service1.xsd rewrite src/Indexer/app.config (76%) create mode 100644 src/ShareDiscovery/IndexManager.cs diff --git a/src/Indexer/Indexer.csproj b/src/Indexer/Indexer.csproj index bac27fb..c192bcd 100644 --- a/src/Indexer/Indexer.csproj +++ b/src/Indexer/Indexer.csproj @@ -3,7 +3,7 @@ Debug AnyCPU - 9.0.21022 + 9.0.30729 2.0 {284F3700-1020-44C9-BE34-50ADCF106DCB} Exe @@ -63,11 +63,7 @@ - - - - @@ -80,6 +76,13 @@ + + + + + + + @@ -89,14 +92,10 @@ - - WCF Proxy Generator Reference.cs - - + + + True + + \ No newline at end of file diff --git a/src/ShareDiscovery/ShareDiscoveryService.cs b/src/ShareDiscovery/ShareDiscoveryService.cs index ac2416a..24be087 100644 --- a/src/ShareDiscovery/ShareDiscoveryService.cs +++ b/src/ShareDiscovery/ShareDiscoveryService.cs @@ -1,43 +1,15 @@ using System; -using System.Collections.Generic; -using System.ComponentModel; +using System.Diagnostics; using System.IO; -using System.Linq; using System.Runtime.Serialization; using System.Runtime.Serialization.Formatters.Binary; -using System.ServiceModel.Channels; - -using AltSpider; - -using LanSpider; +using System.Text; namespace ShareDiscovery { // NOTE: If you change the class name "ShareDiscoveryService" here, you must also update the reference to "ShareDiscoveryService" in App.config. public class ShareDiscoveryService : IShareDiscoveryService { - private Queue _sharesQueue; - private readonly object _queueLock = new object(); - private bool _workerLaunched; - private AltModel _model; - private readonly object _modelLock = new object(); - - /// - /// Gets lazy initialized database model. - /// - private AltModel Model - { - get - { - if ( _model == null ) - { - _model = new AltModel(); - } - - return _model; - } - } - #region Implementation of IShareDiscoveryService /// @@ -49,66 +21,13 @@ namespace ShareDiscovery /// /// /// Next share to index or NULL if no shares know at a time. - public string GetShareToIndex() + public Stream GetShareToIndex() { - string rval = null; - - lock ( _queueLock ) - { - if ( _sharesQueue != null && _sharesQueue.Count > 0 ) - { - rval = _sharesQueue.Dequeue(); - } - } - - if ( ( _sharesQueue == null || rval == null ) && !_workerLaunched ) - { - BackgroundWorker worker = new BackgroundWorker(); - worker.DoWork += GetAllShares; - worker.RunWorkerAsync(); - - _workerLaunched = true; - } - - if (rval == null) rval = "d:\\music\\j\\Judas Priest"; - return rval; + string rval = IndexManager.Instance.GetNextShare(); + byte[] bytes = Encoding.UTF8.GetBytes( rval ); + return new MemoryStream( bytes ); } - /// - /// Load all network shares accessible to current computer. Method is run - /// on it's own thread on service initialization. Results are saved added - /// to . - /// - /// argument (not used) - /// argument (not used) - private void GetAllShares( object sender, DoWorkEventArgs e ) - { - IEnumerable known = Model.GetShares(); - - IEnumerable comps - = from comp in NetworkBrowser.Instance.GetNetworkComputers() - select comp; - - _sharesQueue = new Queue(); - - foreach ( string comp in comps ) - { - IEnumerable shares = NetworkBrowser.Instance.GetShares( comp ); - if ( shares != null ) - { - lock ( _queueLock ) - { - foreach ( string share in shares ) - { - if ( !known.Contains( share.Replace( '\\', '/' ) ) ) - { - _sharesQueue.Enqueue( share ); - } - } - } - } - } - } /// /// Save index for a share previousely served. Member of . @@ -119,66 +38,11 @@ namespace ShareDiscovery IFormatter formatter = new BinaryFormatter(); TreeNode share = formatter.Deserialize( shareStream ) as TreeNode; - BackgroundWorker worker = new BackgroundWorker(); - worker.DoWork += SaveIndexAssync; - worker.RunWorkerAsync( share ); - } - - /// - /// Assynchroneous index saving method. - /// - /// - /// - private void SaveIndexAssync( object sender, DoWorkEventArgs e ) - { - TreeNode share = e.Argument as TreeNode; - List paths = RectifyPaths( share, "" ).ToList(); - lock ( _modelLock ) - { - foreach ( PathInfo pathInfo in paths ) - { - int nodeId = Model.SavePath( pathInfo.Path ); - Model.SaveFileInfo( nodeId, pathInfo.Size, pathInfo.CreationTime, pathInfo.ModificationTime, - pathInfo.AccessTime ); - } - } - } - - /// - /// Convert tree objects into string paths. - /// - /// - /// - /// - /// Thrown if any of arguments is null. - private static IEnumerable RectifyPaths( TreeNode node, string parent ) - { - if ( node == null ) - { - throw new ArgumentNullException( "node" ); - } - - if ( parent == null ) + if ( share != null ) { - throw new ArgumentNullException( "parent" ); + EventLog.WriteEntry( "lanspider", "Have got " + share.Name + " to index." ); + IndexManager.Instance.SaveShare( share ); } - - IEnumerable nodes; - string path = Path.Combine( parent, node.Name ); - - if ( node.Children == null ) - { - nodes = new[] { new PathInfo( path, node ) }; - } - else - { - nodes = from child in node.Children - where child != null - from childpath in RectifyPaths( child, path ) - select childpath; - } - - return nodes; } #endregion diff --git a/src/ShareDiscovery/app.config b/src/ShareDiscovery/app.config index f7d881c..08880df 100644 --- a/src/ShareDiscovery/app.config +++ b/src/ShareDiscovery/app.config @@ -1,11 +1,22 @@ + + + + + + + + + +