Streamed implementation. Limited input buffer.
[LanSpider.git] / src / ShareDiscovery / ShareDiscoveryService.cs
blob24be087ce474b897841ad64d11514fceec30303c
1 using System;
2 using System.Diagnostics;
3 using System.IO;
4 using System.Runtime.Serialization;
5 using System.Runtime.Serialization.Formatters.Binary;
6 using System.Text;
8 namespace ShareDiscovery
10 // NOTE: If you change the class name "ShareDiscoveryService" here, you must also update the reference to "ShareDiscoveryService" in App.config.
11 public class ShareDiscoveryService : IShareDiscoveryService
13 #region Implementation of IShareDiscoveryService
15 /// <summary>
16 /// <para>
17 /// Return next share to be indexed. Member of <see cref="IShareDiscoveryService"/>.
18 /// </para>
19 /// <para>
20 /// First (several) run(s) may return null as initialization may tame some time.
21 /// </para>
22 /// </summary>
23 /// <returns>Next share to index or NULL if no shares know at a time.</returns>
24 public Stream GetShareToIndex()
26 string rval = IndexManager.Instance.GetNextShare();
27 byte[] bytes = Encoding.UTF8.GetBytes( rval );
28 return new MemoryStream( bytes );
32 /// <summary>
33 /// Save index for a share previousely served. Member of <see cref="IShareDiscoveryService"/>.
34 /// </summary>
35 /// <param name="shareStream"></param>
36 public void SaveIndex( Stream shareStream )
38 IFormatter formatter = new BinaryFormatter();
39 TreeNode share = formatter.Deserialize( shareStream ) as TreeNode;
41 if ( share != null )
43 EventLog.WriteEntry( "lanspider", "Have got " + share.Name + " to index." );
44 IndexManager.Instance.SaveShare( share );
48 #endregion
51 /// <summary>
52 /// Stores information about path to be saved to the database.
53 /// </summary>
54 internal class PathInfo
56 private readonly string _path;
57 private readonly long _size;
59 private readonly DateTime _creationTime;
60 private readonly DateTime _modificationTime;
61 private readonly DateTime _accessTime;
63 /// <summary>
64 /// Initializes an instance of <see cref="PathInfo"/>.
65 /// </summary>
66 /// <param name="path"></param>
67 /// <param name="size"></param>
68 /// <param name="creationTime"></param>
69 /// <param name="modificationTime"></param>
70 /// <param name="accessTime"></param>
71 public PathInfo( string path, long size, DateTime creationTime, DateTime modificationTime, DateTime accessTime )
73 _path = path;
74 _accessTime = accessTime;
75 _modificationTime = modificationTime;
76 _creationTime = creationTime;
77 _size = size;
80 /// <summary>
81 /// Initializes an instance of <see cref="PathInfo"/> based on an instance of
82 /// <see cref="TreeNode"/>.
83 /// </summary>
84 /// <param name="path"></param>
85 /// <param name="node"></param>
86 public PathInfo( string path, TreeNode node )
88 _path = path;
89 _accessTime = node.AccessTime;
90 _modificationTime = node.ModificationTime;
91 _creationTime = node.CreationTime;
92 _size = node.Size;
95 /// <summary>
96 /// Gets full file path.
97 /// </summary>
98 public string Path
102 return _path;
106 /// <summary>
107 /// Gets file size in bytes.
108 /// </summary>
109 public long Size
113 return _size;
117 /// <summary>
118 /// Gets file's time of creation.
119 /// </summary>
120 public DateTime CreationTime
124 return _creationTime;
128 /// <summary>
129 /// Gets file's last time of modification.
130 /// </summary>
131 public DateTime ModificationTime
135 return _modificationTime;
139 /// <summary>
140 /// Gets file's last access time.
141 /// </summary>
142 public DateTime AccessTime
146 return _accessTime;