blob: 9fddecb3afbff176c971c20112652229073e4fd2 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
|
using System;
using System.IO;
using System.Collections.Generic;
namespace Monodoc
{
// Define a storage mechanism for a help source
public interface IDocStorage : IDisposable
{
// Tell if the storage can store successive change to the doc as revision
bool SupportRevision { get; }
IDocRevisionManager RevisionManager { get; }
// Tell if the storage support modifying an existing data
bool SupportChange { get; }
/* Store data inside the storage backend
* if SupportChange is false and user try to store something with an existing id
* an exception will be thrown
* if id is null or empty, the storage will try to create an automatic id. In all
* case the id that has been used to store the content is returned by the method
*/
string Store (string id, string text);
string Store (string id, byte[] data);
string Store (string id, Stream stream);
Stream Retrieve (string id);
IEnumerable<string> GetAvailableIds ();
}
public interface IDocRevisionManager
{
Stream RetrieveWithRevision (string id, string revision);
// This should be ordered by most recent first
IEnumerable<string> AvailableRevisionsForId (string id);
// This can simply be implemented with above property but it can also be
// a revision storage symbolic value like "HEAD"
string LatestRevisionForId (string id);
// A commit message for instance
string GetRevisionDescription (string revision);
}
public static class DocRevisionManagerExtensions
{
public static Stream RetrieveLatestRevision (this IDocRevisionManager revManager, string id)
{
return revManager.RetrieveWithRevision (id, revManager.LatestRevisionForId (id));
}
}
public static class DocStorageExtensions
{
public static bool TryRetrieve (this IDocStorage storage, string id, out Stream stream)
{
stream = null;
try {
stream = storage.Retrieve (id);
return true;
} catch {
return false;
}
}
}
}
|