Imported Upstream version 5.2.0.179

Former-commit-id: a536d4f20e27294d8bbc2184d75f3a22364f7ba1
This commit is contained in:
Xamarin Public Jenkins (auto-signing)
2017-06-16 11:04:32 +00:00
parent 966bba02bb
commit fad71374d0
18265 changed files with 3842164 additions and 16 deletions

View File

@ -0,0 +1,63 @@
using System;
using System.IO;
using System.Xml;
using System.Linq;
using System.Collections.Generic;
namespace Monodoc.Storage
{
// A storage that doesn't store
public class NullStorage : IDocStorage
{
public NullStorage ()
{
}
public bool SupportRevision {
get {
return false;
}
}
public IDocRevisionManager RevisionManager {
get {
return null;
}
}
public bool SupportChange {
get {
return true;
}
}
public string Store (string id, string text)
{
return id;
}
public string Store (string id, byte[] data)
{
return id;
}
public string Store (string id, Stream stream)
{
return id;
}
public Stream Retrieve (string id)
{
return null;
}
public IEnumerable<string> GetAvailableIds ()
{
return Enumerable.Empty<string> ();
}
public void Dispose ()
{
}
}
}

View File

@ -0,0 +1,69 @@
using System;
using System.IO;
using System.Linq;
using System.Collections.Generic;
namespace Monodoc.Storage
{
// A read-only storage to access ecma XML document based on a standard directory layout
// id are relative path inside the base doc directory
public class UncompiledDocStorage : IDocStorage
{
readonly string basePath;
public UncompiledDocStorage (string basePath)
{
this.basePath = basePath;
}
public bool SupportRevision {
get {
return false;
}
}
public IDocRevisionManager RevisionManager {
get {
return null;
}
}
public bool SupportChange {
get {
return false;
}
}
public string Store (string id, string text)
{
throw new NotSupportedException ();
}
public string Store (string id, byte[] data)
{
throw new NotSupportedException ();
}
public string Store (string id, Stream stream)
{
throw new NotSupportedException ();
}
public Stream Retrieve (string id)
{
var path = id;
if ('/' != Path.DirectorySeparatorChar)
path = path.Replace ('/', Path.DirectorySeparatorChar);
return File.OpenRead (Path.Combine (basePath, path));
}
public IEnumerable<string> GetAvailableIds ()
{
return Directory.EnumerateFiles (basePath, "*.xml", SearchOption.AllDirectories);
}
public void Dispose ()
{
}
}
}

View File

@ -0,0 +1,131 @@
using System;
using System.IO;
using System.Xml;
using System.Linq;
using System.Text;
using System.Collections.Generic;
using ICSharpCode.SharpZipLib.Zip;
namespace Monodoc.Storage
{
public class ZipStorage : IDocStorage
{
string zipFileName;
int code;
ZipOutputStream zipOutput;
ZipFile zipFile;
// SharpZipLib use linear search to map name to index, correct that a bit
Dictionary<string, int> entries = new Dictionary<string, int> ();
public ZipStorage (string zipFileName)
{
this.zipFileName = zipFileName;
}
public bool SupportRevision {
get {
return false;
}
}
public IDocRevisionManager RevisionManager {
get {
return null;
}
}
public bool SupportChange {
get {
return true;
}
}
public string Store (string id, string text)
{
EnsureOutput ();
SetupEntry (zipOutput, ref id);
var writer = new StreamWriter (zipOutput);
writer.Write (text);
writer.Flush ();
return id;
}
public string Store (string id, byte[] data)
{
EnsureOutput ();
SetupEntry (zipOutput, ref id);
zipOutput.Write (data, 0, data.Length);
return id;
}
public string Store (string id, Stream stream)
{
EnsureOutput ();
SetupEntry (zipOutput, ref id);
stream.CopyTo (zipOutput);
return id;
}
void SetupEntry (ZipOutputStream zipOutput, ref string id)
{
if (string.IsNullOrEmpty (id))
id = GetNewCode ();
ZipEntry entry = new ZipEntry (id);
zipOutput.PutNextEntry (entry);
}
public Stream Retrieve (string id)
{
EnsureInput ();
int index;
ZipEntry entry;
if (!entries.TryGetValue (id, out index) || (entry = zipFile[index]) == null)
entry = zipFile.GetEntry (id);
if (entry != null)
return zipFile.GetInputStream (entry);
else
throw new ArgumentException ("id", string.Format ("'{0}' isn't a valid id for this storage", id));
}
public IEnumerable<string> GetAvailableIds ()
{
EnsureInput ();
return zipFile.Cast<ZipEntry> ().Select (ze => ze.Name);
}
void EnsureOutput ()
{
if (zipFile != null)
throw new InvalidOperationException ("This ZipStorage instance is already used in read-mode");
if (zipOutput != null)
return;
zipOutput = new ZipOutputStream (File.Create (zipFileName));
}
void EnsureInput ()
{
if (zipOutput != null)
throw new InvalidOperationException ("This ZipStorage instance is already used in write-mode");
if (zipFile != null)
return;
zipFile = new ZipFile (zipFileName);
entries = Enumerable.Range (0, zipFile.Size).ToDictionary (i => zipFile[i].Name, i => i);
}
public void Dispose ()
{
if (zipOutput != null)
zipOutput.Dispose ();
if (zipFile != null)
zipFile.Close ();
}
string GetNewCode ()
{
return String.Format ("{0}", code++);
}
}
}