2 using System
.Diagnostics
;
4 using System
.Runtime
.Serialization
;
5 using System
.Runtime
.Serialization
.Formatters
.Binary
;
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
17 /// Return next share to be indexed. Member of <see cref="IShareDiscoveryService"/>.
20 /// First (several) run(s) may return null as initialization may tame some time.
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
);
33 /// Save index for a share previousely served. Member of <see cref="IShareDiscoveryService"/>.
35 /// <param name="shareStream"></param>
36 public void SaveIndex( Stream shareStream
)
38 IFormatter formatter
= new BinaryFormatter();
39 TreeNode share
= formatter
.Deserialize( shareStream
) as TreeNode
;
43 EventLog
.WriteEntry( "lanspider", "Have got " + share
.Name
+ " to index." );
44 IndexManager
.Instance
.SaveShare( share
);
52 /// Stores information about path to be saved to the database.
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
;
64 /// Initializes an instance of <see cref="PathInfo"/>.
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
)
74 _accessTime
= accessTime
;
75 _modificationTime
= modificationTime
;
76 _creationTime
= creationTime
;
81 /// Initializes an instance of <see cref="PathInfo"/> based on an instance of
82 /// <see cref="TreeNode"/>.
84 /// <param name="path"></param>
85 /// <param name="node"></param>
86 public PathInfo( string path
, TreeNode node
)
89 _accessTime
= node
.AccessTime
;
90 _modificationTime
= node
.ModificationTime
;
91 _creationTime
= node
.CreationTime
;
96 /// Gets full file path.
107 /// Gets file size in bytes.
118 /// Gets file's time of creation.
120 public DateTime CreationTime
124 return _creationTime
;
129 /// Gets file's last time of modification.
131 public DateTime ModificationTime
135 return _modificationTime
;
140 /// Gets file's last access time.
142 public DateTime AccessTime