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