Imported Upstream version 3.6.0

Former-commit-id: da6be194a6b1221998fc28233f2503bd61dd9d14
This commit is contained in:
Jo Shields
2014-08-13 10:39:27 +01:00
commit a575963da9
50588 changed files with 8155799 additions and 0 deletions

View File

@@ -0,0 +1,35 @@
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
// Copyright (c) 2008 Novell, Inc. (http://www.novell.com)
//
// Authors:
// Chris Toshok (toshok@ximian.com)
//
namespace System.IO.Packaging {
public enum CertificateEmbeddingOption {
InCertificatePart,
InSignaturePart,
NotEmbedded
}
}

View File

@@ -0,0 +1,183 @@
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
// Copyright (c) 2008 Novell, Inc. (http://www.novell.com)
//
// Authors:
// Alan McGovern (amcgovern@novell.com)
//
using System;
namespace System.IO.Packaging
{
internal static class Check
{
static void NotNull (object o, string name)
{
if (o == null)
throw new ArgumentNullException (name);
}
public static void ContentTypeIsValid (string contentType)
{
if (string.IsNullOrEmpty (contentType))
return;
// Must be in form of: type/subtype
int index = contentType.IndexOf ('/');
bool result = (index > 0) && contentType.Length > (index + 1) && contentType.IndexOf ('/', index + 1) == -1;
if(!result)
throw new ArgumentException ("contentType", "contentType must be in the form of 'type/subtype'");
}
public static void Id (object id)
{
NotNull (id, "id");
}
public static void IdIsValid (string id)
{
if (id == null)
return;
// If the ID is a zero string, need to throw a ArgNullEx
if (id.Length == 0)
throw new ArgumentNullException ("id", "Cannot be whitespace or empty");
// FIXME: I need to XSD parse this to make sure it's valid
// If it's not, throw an XmlException
}
private static bool EmptyOrBlank (string s)
{
return (s != null && (s == "" || s.Trim ().Length == 0));
}
private static void PartUriDoesntEndWithSlash(Uri uri)
{
var s = !uri.IsAbsoluteUri ? uri.OriginalString
: uri.GetComponents(UriComponents.Path, UriFormat.UriEscaped);
// We allow '/' at uri's beggining.
if ((s.Length > 1) && s.EndsWith("/"))
{
throw new ArgumentException("Part URI cannot end with a forward slash.");
}
}
public static void Package(object package)
{
if (package == null)
throw new ArgumentNullException ("package");
}
public static void PackageUri (object packageUri)
{
NotNull (packageUri, "packageUri");
}
public static void PackageUriIsValid (Uri packageUri)
{
if (!packageUri.IsAbsoluteUri)
throw new ArgumentException ("packageUri", "Uri must be absolute");
}
public static void PackUriIsValid (Uri packUri)
{
if (!packUri.IsAbsoluteUri)
throw new ArgumentException("packUri", "PackUris must be absolute");
if (packUri.Scheme != PackUriHelper.UriSchemePack)
throw new ArgumentException ("packUri", "Uri scheme is not a valid PackUri scheme");
}
public static void PartUri (object partUri)
{
if (partUri == null)
throw new ArgumentNullException ("partUri");
}
public static void PartUriIsValid (Uri partUri)
{
if (!partUri.OriginalString.StartsWith ("/"))
throw new UriFormatException ("PartUris must start with '/'");
if (partUri.IsAbsoluteUri)
throw new UriFormatException ("PartUris cannot be absolute");
}
public static void RelationshipTypeIsValid (string relationshipType)
{
if (relationshipType == null)
throw new ArgumentNullException ("relationshipType");
if (EmptyOrBlank (relationshipType))
throw new ArgumentException ("relationshipType", "Cannot be whitespace or empty");
}
public static void PartUri (Uri partUri)
{
if (partUri == null)
throw new ArgumentNullException ("partUri");
if (partUri.IsAbsoluteUri)
throw new ArgumentException ("partUri", "Absolute URIs are not supported");
if (string.IsNullOrEmpty (partUri.OriginalString))
throw new ArgumentException ("partUri", "Part uri cannot be an empty string");
}
public static void PackUri(Uri packUri)
{
NotNull(packUri, "packUri");
}
public static void SourcePartUri (Uri sourcePartUri)
{
NotNull(sourcePartUri, "sourcePartUri");
PartUriDoesntEndWithSlash(sourcePartUri);
}
public static void TargetPartUri (Uri targetPartUri)
{
NotNull(targetPartUri, "targetPartUri");
PartUriDoesntEndWithSlash(targetPartUri);
}
public static void SourceUri (Uri sourceUri)
{
if (sourceUri == null)
throw new ArgumentNullException ("sourceUri");
// if (sourceUri.IsAbsoluteUri)
// throw new ArgumentException ("sourceUri", "Absolute URIs are not supported");
if (string.IsNullOrEmpty (sourceUri.OriginalString))
throw new ArgumentException ("sourceUri", "Part uri cannot be an empty string");
}
public static void TargetUri (Uri targetUri)
{
if (targetUri == null)
throw new ArgumentNullException ("targetUri");
// if (targetUri.IsAbsoluteUri)
// throw new ArgumentException ("targetUri", "Absolute URIs are not supported");
if (string.IsNullOrEmpty (targetUri.OriginalString))
throw new ArgumentException ("targetUri", "Part uri cannot be an empty string");
}
}
}

View File

@@ -0,0 +1,37 @@
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
// Copyright (c) 2008 Novell, Inc. (http://www.novell.com)
//
// Authors:
// Chris Toshok (toshok@ximian.com)
//
namespace System.IO.Packaging {
public enum CompressionOption {
NotCompressed = -1,
Normal,
Maximum,
Fast,
SuperFast,
}
}

View File

@@ -0,0 +1,122 @@
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
// Copyright (c) 2007 Novell, Inc. (http://www.novell.com)
//
// Authors:
// Chris Toshok (toshok@ximian.com)
//
using System;
using System.IO;
using System.Security.RightsManagement;
namespace System.IO.Packaging {
public class EncryptedPackageEnvelope : IDisposable
{
internal EncryptedPackageEnvelope ()
{
}
protected virtual void Dispose (bool disposing)
{
throw new NotImplementedException ();
}
public FileAccess FileOpenAccess {
get { throw new NotImplementedException (); }
}
public PackageProperties PackageProperties {
get { throw new NotImplementedException (); }
}
public RightsManagementInformation RightsManagementInformation {
get { throw new NotImplementedException (); }
}
public StorageInfo StorageInfo {
get { throw new NotImplementedException (); }
}
public void Close ()
{
throw new NotImplementedException ();
}
public void Dispose ()
{
throw new NotImplementedException ();
}
public void Flush ()
{
throw new NotImplementedException ();
}
public Package GetPackage ()
{
throw new NotImplementedException ();
}
public static bool IsEncryptedPackageEnvelope (Stream stream)
{
throw new NotImplementedException ();
}
public static bool IsEncryptedPackageEnvelope (string fileName)
{
throw new NotImplementedException ();
}
public static EncryptedPackageEnvelope Create (Stream envelopeStream, PublishLicense publishLicense, CryptoProvider cryptoProvider)
{
throw new NotImplementedException ();
}
public static EncryptedPackageEnvelope Create (string envelopeFileName, PublishLicense publishLicense, CryptoProvider cryptoProvider)
{
throw new NotImplementedException ();
}
public static EncryptedPackageEnvelope CreateFromPackage (Stream envelopeStream, Stream packageStream, PublishLicense publishLicense, CryptoProvider cryptoProvider)
{
throw new NotImplementedException ();
}
public static EncryptedPackageEnvelope CreateFromPackage (string envelopeFileName, Stream packageStream, PublishLicense publishLicense, CryptoProvider cryptoProvider)
{
throw new NotImplementedException ();
}
public static EncryptedPackageEnvelope Open (Stream envelopeStream)
{
throw new NotImplementedException ();
}
public static EncryptedPackageEnvelope Open (string envelopeFileName)
{
throw new NotImplementedException ();
}
public static EncryptedPackageEnvelope Open (string envelopeFileName, FileAccess access)
{
throw new NotImplementedException ();
}
public static EncryptedPackageEnvelope Open (string envelopeFileName, FileAccess access, FileShare sharing)
{
throw new NotImplementedException ();
}
}
}

View File

@@ -0,0 +1,33 @@
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
// Copyright (c) 2008 Novell, Inc. (http://www.novell.com)
//
// Authors:
// Chris Toshok (toshok@ximian.com)
//
namespace System.IO.Packaging {
public enum EncryptionOption {
None,
RightsManagement
}
}

View File

@@ -0,0 +1,32 @@
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
// Copyright (c) 2008 Novell, Inc. (http://www.novell.com)
//
// Authors:
// Chris Toshok (toshok@ximian.com)
//
using System;
namespace System.IO.Packaging {
public delegate void InvalidSignatureEventHandler (object sender, SignatureVerificationEventArgs e);
}

View File

@@ -0,0 +1,202 @@
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
// Copyright (c) 2007 Novell, Inc. (http://www.novell.com)
//
// Authors:
// Chris Toshok (toshok@ximian.com)
//
using System;
namespace System.IO.Packaging {
public static class PackUriHelper
{
public static readonly string UriSchemePack = "pack";
static readonly Uri PackSchemeUri = new Uri("pack://", UriKind.Absolute);
static readonly char[] _escapedChars = new char[] { '%', ',', '?', '@' };
static PackUriHelper ()
{
if (!UriParser.IsKnownScheme (UriSchemePack))
UriParser.Register (new PackUriParser (), UriSchemePack, -1);
}
public static int ComparePackUri (Uri firstPackUri, Uri secondPackUri)
{
// FIXME: Do i need to do validation that it is a pack:// uri?
if (firstPackUri == null)
return secondPackUri == null ? 0 : -1;
if (secondPackUri == null)
return 1;
// FIXME: What exactly is compared. Lets assume originalstring
return firstPackUri.OriginalString.CompareTo (secondPackUri.OriginalString);
}
public static int ComparePartUri (Uri firstPartUri, Uri secondPartUri)
{
// FIXME: Do i need to do validation that it is a part URI?
if (firstPartUri == null)
return secondPartUri == null ? 0 : -1;
if (secondPartUri == null)
return 1;
return firstPartUri.OriginalString.CompareTo (secondPartUri.OriginalString);
}
public static Uri Create (Uri packageUri)
{
return Create (packageUri, null, null);
}
public static Uri Create (Uri packageUri, Uri partUri)
{
return Create (packageUri, partUri, null);
}
public static Uri Create (Uri packageUri, Uri partUri, string fragment)
{
Check.PackageUri (packageUri);
Check.PackageUriIsValid (packageUri);
if (partUri != null)
Check.PartUriIsValid (partUri);
if (fragment != null && (fragment.Length == 0 || fragment[0] != '#'))
throw new ArgumentException ("Fragment", "Fragment must not be empty and must start with '#'");
// FIXME: Validate that partUri is a valid one? Must be relative, must start with '/'
// First replace the slashes, then escape the special characters
//string orig = packageUri.GetComponents(UriComponents.AbsoluteUri, UriFormat.UriEscaped);
string orig = packageUri.OriginalString;
foreach (var ch in _escapedChars)
{
orig = !orig.Contains(ch.ToString()) ? orig : orig.Replace(ch.ToString(), Uri.HexEscape(ch));
}
orig = orig.Replace('/', ',');
if (partUri != null)
orig += partUri.OriginalString;
if ((fragment == null && partUri == null)&& orig[orig.Length - 1] != '/')
orig += '/';
if (fragment != null)
orig += fragment;
return new Uri ("pack://" + orig);
}
public static Uri CreatePartUri (Uri partUri)
{
Check.PartUri (partUri);
if (partUri.OriginalString[0] != '/')
partUri = new Uri("/" + partUri.ToString (), UriKind.Relative);
return partUri;
}
public static Uri GetNormalizedPartUri (Uri partUri)
{
Check.PartUri (partUri);
return new Uri (partUri.ToString ().ToUpperInvariant (), UriKind.Relative);
}
public static Uri GetPackageUri (Uri packUri)
{
Check.PackUri (packUri);
Check.PackUriIsValid (packUri);
string s = packUri.Host.Replace(',', '/');
return new Uri (Uri.UnescapeDataString(s), UriKind.RelativeOrAbsolute);
}
public static Uri GetPartUri (Uri packUri)
{
Check.PackUri(packUri);
Check.PackUriIsValid(packUri);
if (string.IsNullOrEmpty(packUri.AbsolutePath) || packUri.AbsolutePath == "/")
return null;
return new Uri(packUri.AbsolutePath, UriKind.Relative);
}
public static Uri GetRelationshipPartUri (Uri partUri)
{
Check.PartUri (partUri);
Check.PartUriIsValid (partUri);
int index = partUri.OriginalString.LastIndexOf ("/");
string s = partUri.OriginalString.Substring (0, index);
s += "/_rels" + partUri.OriginalString.Substring (index) + ".rels";
return new Uri (s, UriKind.Relative);
}
public static Uri GetRelativeUri (Uri sourcePartUri, Uri targetPartUri)
{
Check.SourcePartUri (sourcePartUri);
Check.TargetPartUri (targetPartUri);
Uri uri = new Uri ("http://fake.com");
Uri a = new Uri (uri, sourcePartUri.OriginalString);
Uri b = new Uri (uri, targetPartUri.OriginalString);
return a.MakeRelativeUri(b);
}
public static Uri GetSourcePartUriFromRelationshipPartUri (Uri relationshipPartUri)
{
//Check.RelationshipPartUri (relationshipPartUri);
if (!IsRelationshipPartUri (relationshipPartUri))
throw new Exception ("is not a relationship part!?");
return null;
}
public static bool IsRelationshipPartUri (Uri partUri)
{
Check.PartUri (partUri);
return partUri.OriginalString.StartsWith ("/_rels") && partUri.OriginalString.EndsWith (".rels");
}
public static Uri ResolvePartUri (Uri sourcePartUri, Uri targetUri)
{
Check.SourcePartUri (sourcePartUri);
Check.TargetUri (targetUri);
Check.PartUriIsValid (sourcePartUri);
if (targetUri.IsAbsoluteUri)
throw new ArgumentException ("targetUri", "Absolute URIs are not supported");
Uri uri = new Uri ("http://fake.com");
uri = new Uri (uri, sourcePartUri);
uri = new Uri (uri, targetUri);
// Trim out 'http://fake.com'
return new Uri (uri.OriginalString.Substring (15), UriKind.Relative);
}
}
}

View File

@@ -0,0 +1,113 @@
// PackUriParser.cs created with MonoDevelop
// User: alan at 14:50 31/10/2008
//
// To change standard headers go to Edit->Preferences->Coding->Standard Headers
//
using System;
using System.Collections.Generic;
using System.Text;
namespace System.IO.Packaging
{
class PackUriParser : System.GenericUriParser
{
const string SchemaName = "pack";
StringBuilder builder = new StringBuilder();
public PackUriParser ()
: base (GenericUriParserOptions.Default)
{
}
protected override string GetComponents(Uri uri, UriComponents components, UriFormat format)
{
string s = uri.OriginalString;
builder.Remove(0, builder.Length);
if ((components & UriComponents.Scheme) == UriComponents.Scheme)
{
int start = 0;
int end = s.IndexOf(':');
builder.Append(s, start, end - start);
}
if ((components & UriComponents.Host) == UriComponents.Host)
{
// Skip past pack://
int start = 7;
int end = s.IndexOf('/', start);
if (end == -1)
end = s.Length;
if (builder.Length > 0)
builder.Append("://");
builder.Append(s, start, end - start);
}
// Port is always -1, so i think i can ignore both Port and StrongPort
// Normally they'd get parsed here
if ((components & UriComponents.Path) == UriComponents.Path)
{
// Skip past pack://
int start = s.IndexOf('/', 7);
int end = s.IndexOf('?');
if (end == -1)
end = s.IndexOf('#');
if (end == -1)
end = s.Length;
if ((components & UriComponents.KeepDelimiter) != UriComponents.KeepDelimiter &&
builder.Length == 0)
start++;
if (start > 0) builder.Append(s, start, end - start);
}
if ((components & UriComponents.Query) == UriComponents.Query)
{
int index = s.IndexOf('?');
if (index != -1)
{
if ((components & UriComponents.KeepDelimiter) != UriComponents.KeepDelimiter &&
builder.Length == 0)
index++;
int fragIndex = s.IndexOf('#');
int end = fragIndex == -1 ? s.Length : fragIndex;
builder.Append(s, index, end - index);
}
}
if ((components & UriComponents.Fragment) == UriComponents.Fragment)
{
int index = s.IndexOf('#');
if (index != -1)
{
if ((components & UriComponents.KeepDelimiter) != UriComponents.KeepDelimiter &&
builder.Length == 0)
index++;
builder.Append(s, index, s.Length - index);
}
}
return builder.ToString();
}
protected override void InitializeAndValidate(Uri uri, out UriFormatException parsingError)
{
parsingError = null;
}
protected override UriParser OnNewUri()
{
return new PackUriParser();
}
}
}

View File

@@ -0,0 +1,498 @@
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
// Copyright (c) 2007 Novell, Inc. (http://www.novell.com)
// Copyright (c) 2011 Xamarin Inc. (http://www.xamarin.com)
//
// Authors:
// Chris Toshok (toshok@ximian.com)
// Alan McGovern (amcgovern@novell.com)
// Rolf Bjarne Kvinge (rolf@xamarin.com)
//
using System;
using System.Collections.Generic;
using System.Xml;
namespace System.IO.Packaging {
public abstract class Package : IDisposable
{
internal const string RelationshipContentType = "application/vnd.openxmlformats-package.relationships+xml";
internal const string RelationshipNamespace = "http://schemas.openxmlformats.org/package/2006/relationships";
internal static readonly Uri RelationshipUri = new Uri ("/_rels/.rels", UriKind.Relative);
PackageProperties packageProperties;
PackagePartCollection partsCollection;
Dictionary<string, PackageRelationship> relationships;
PackageRelationshipCollection relationshipsCollection = new PackageRelationshipCollection ();
Uri Uri = new Uri ("/", UriKind.Relative);
bool Disposed {
get; set;
}
public FileAccess FileOpenAccess {
get; private set;
}
public PackageProperties PackageProperties {
get {
// PackageProperties are loaded when the relationships are loaded.
// Therefore ensure we've already loaded the relationships.
int count = Relationships.Count;
if (packageProperties == null) {
packageProperties = new PackagePropertiesPart ();
packageProperties.Package = this;
}
return packageProperties;
}
}
PackagePartCollection PartsCollection {
get {
if (partsCollection == null) {
partsCollection = new PackagePartCollection ();
partsCollection.Parts.AddRange (GetPartsCore ());
}
return partsCollection;
}
}
int RelationshipId {
get; set;
}
Dictionary<string, PackageRelationship> Relationships {
get {
if (relationships == null) {
LoadRelationships ();
}
return relationships;
}
}
bool Streaming {
get; set;
}
protected Package (FileAccess openFileAccess)
: this (openFileAccess, false)
{
}
protected Package (FileAccess openFileAccess, bool streaming)
{
FileOpenAccess = openFileAccess;
Streaming = streaming;
}
internal void CheckIsReadOnly ()
{
if (FileOpenAccess == FileAccess.Read)
throw new IOException ("Operation not valid when package is read-only");
}
public void Close ()
{
// FIXME: Ensure that Flush is actually called before dispose
((IDisposable) this).Dispose ();
}
public PackagePart CreatePart (Uri partUri, string contentType)
{
return CreatePart (partUri, contentType, CompressionOption.NotCompressed);
}
public PackagePart CreatePart (Uri partUri, string contentType, CompressionOption compressionOption)
{
CheckIsReadOnly ();
Check.PartUri (partUri);
Check.ContentTypeIsValid (contentType);
if (PartExists (partUri))
throw new InvalidOperationException ("This partUri is already contained in the package");
PackagePart part = CreatePartCore (partUri, contentType, compressionOption);
PartsCollection.Parts.Add (part);
return part;
}
protected abstract PackagePart CreatePartCore (Uri partUri, string contentType, CompressionOption compressionOption);
public PackageRelationship CreateRelationship (Uri targetUri, TargetMode targetMode, string relationshipType)
{
return CreateRelationship (targetUri, targetMode, relationshipType, null);
}
public PackageRelationship CreateRelationship (Uri targetUri, TargetMode targetMode, string relationshipType, string id)
{
return CreateRelationship (targetUri, targetMode, relationshipType, id, false);
}
internal PackageRelationship CreateRelationship (Uri targetUri, TargetMode targetMode, string relationshipType, string id, bool loading)
{
if (!loading)
CheckIsReadOnly ();
Check.TargetUri (targetUri);
if (targetUri.IsAbsoluteUri && targetMode == TargetMode.Internal)
throw new ArgumentException ("TargetUri cannot be absolute for an internal relationship");
Check.RelationshipTypeIsValid (relationshipType);
Check.IdIsValid (id);
if (id == null)
id = NextId ();
PackageRelationship r = new PackageRelationship (id, this, relationshipType, Uri, targetMode, targetUri);
if (!PartExists (RelationshipUri))
CreatePartCore (RelationshipUri, RelationshipContentType, CompressionOption.NotCompressed).IsRelationship = true;
Relationships.Add (r.Id, r);
relationshipsCollection.Relationships.Add (r);
if (!loading) {
using (Stream s = GetPart (RelationshipUri).GetStream ())
WriteRelationships (relationships, s);
}
return r;
}
public void DeletePart (Uri partUri)
{
CheckIsReadOnly ();
Check.PartUri (partUri);
PackagePart part = GetPart (partUri);
if (part != null)
{
if (part.Package == null)
throw new InvalidOperationException ("This part has already been removed");
// FIXME: MS.NET doesn't remove the relationship part
// Instead it throws an exception if you try to use it
if (PartExists (part.RelationshipsPartUri))
GetPart (part.RelationshipsPartUri).Package = null;
part.Package = null;
DeletePartCore (partUri);
PartsCollection.Parts.RemoveAll (p => p.Uri == partUri);
}
}
protected abstract void DeletePartCore (Uri partUri);
public void DeleteRelationship (string id)
{
Check.Id (id);
CheckIsReadOnly ();
Relationships.Remove (id);
relationshipsCollection.Relationships.RemoveAll (r => r.Id == id);
if (Relationships.Count > 0)
using (Stream s = GetPart (RelationshipUri).GetStream ())
WriteRelationships (relationships, s);
else
DeletePart (RelationshipUri);
}
void IDisposable.Dispose ()
{
if (!Disposed) {
Flush ();
Dispose (true);
Disposed = true;
}
}
protected virtual void Dispose (bool disposing)
{
// Nothing here needs to be disposed of
}
bool flushing = false;
public void Flush ()
{
if (FileOpenAccess == FileAccess.Read || flushing)
return;
flushing = true;
// Ensure we've loaded the relationships, parts and properties
int count = Relationships.Count;
if (packageProperties != null)
packageProperties.Flush ();
FlushCore ();
flushing = false;
}
protected abstract void FlushCore ();
public PackagePart GetPart (Uri partUri)
{
Check.PartUri (partUri);
return GetPartCore (partUri);
}
protected abstract PackagePart GetPartCore (Uri partUri);
public PackagePartCollection GetParts ()
{
PartsCollection.Parts.Clear ();
PartsCollection.Parts.AddRange (GetPartsCore());
return PartsCollection;
}
protected abstract PackagePart [] GetPartsCore ();
public PackageRelationship GetRelationship (string id)
{
return Relationships [id];
}
public PackageRelationshipCollection GetRelationships ()
{
// Ensure the Relationships dict is instantiated first.
ICollection <PackageRelationship> rels = Relationships.Values;
relationshipsCollection.Relationships.Clear ();
relationshipsCollection.Relationships.AddRange (rels);
return relationshipsCollection;
}
public PackageRelationshipCollection GetRelationshipsByType (string relationshipType)
{
PackageRelationshipCollection collection = new PackageRelationshipCollection ();
foreach (PackageRelationship r in Relationships.Values)
if (r.RelationshipType == relationshipType)
collection.Relationships.Add (r);
return collection;
}
void LoadRelationships ()
{
relationships = new Dictionary<string, PackageRelationship> ();
if (!PartExists (RelationshipUri))
return;
using (Stream stream = GetPart (RelationshipUri).GetStream ()) {
XmlDocument doc = new XmlDocument ();
doc.Load (stream);
XmlNamespaceManager manager = new XmlNamespaceManager (doc.NameTable);
manager.AddNamespace ("rel", RelationshipNamespace);
foreach (XmlNode node in doc.SelectNodes ("/rel:Relationships/*", manager))
{
TargetMode mode = TargetMode.Internal;
if (node.Attributes["TargetMode"] != null)
mode = (TargetMode) Enum.Parse (typeof(TargetMode), node.Attributes ["TargetMode"].Value);
Uri uri;
try {
uri = new Uri (node.Attributes ["Target"].Value.ToString(), UriKind.Relative);
} catch {
uri = new Uri (node.Attributes ["Target"].Value.ToString(), UriKind.Absolute);
}
CreateRelationship (uri,
mode,
node.Attributes["Type"].Value.ToString (),
node.Attributes["Id"].Value.ToString (),
true);
}
foreach (PackageRelationship r in relationships.Values) {
if (r.RelationshipType == System.IO.Packaging.PackageProperties.NSPackagePropertiesRelation) {
PackagePart part = GetPart (PackUriHelper.ResolvePartUri (Uri, r.TargetUri));
packageProperties = new PackagePropertiesPart ();
packageProperties.Package = this;
packageProperties.Part = part;
packageProperties.LoadFrom (part.GetStream ());
}
}
}
}
string NextId ()
{
while (true) {
string s = "Re" + RelationshipId.ToString ();
if (!Relationships.ContainsKey (s))
return s;
RelationshipId++;
}
}
public static Package Open (Stream stream)
{
return Open (stream, FileMode.Open);
}
public static Package Open (string path)
{
return Open (path, FileMode.OpenOrCreate);
}
public static Package Open (Stream stream, FileMode packageMode)
{
FileAccess access = packageMode == FileMode.Open ? FileAccess.Read : FileAccess.ReadWrite;
return Open (stream, packageMode, access);
}
public static Package Open (string path, FileMode packageMode)
{
return Open (path, packageMode, FileAccess.ReadWrite);
}
public static Package Open (Stream stream, FileMode packageMode, FileAccess packageAccess)
{
return Open (stream, packageMode, packageAccess, false);
}
static Package Open (Stream stream, FileMode packageMode, FileAccess packageAccess, bool ownsStream)
{
return OpenCore (stream, packageMode, packageAccess, ownsStream);
}
public static Package Open (string path, FileMode packageMode, FileAccess packageAccess)
{
return Open (path, packageMode, packageAccess, FileShare.None);
}
public static Package Open (string path, FileMode packageMode, FileAccess packageAccess, FileShare packageShare)
{
if (packageShare != FileShare.Read && packageShare != FileShare.None)
throw new NotSupportedException ("FileShare.Read and FileShare.None are the only supported options");
FileInfo info = new FileInfo (path);
// Bug - MS.NET appears to test for FileAccess.ReadWrite, not FileAccess.Write
if (packageAccess != FileAccess.ReadWrite && !info.Exists)
throw new ArgumentException ("packageAccess", "Cannot create stream with FileAccess.Read");
if (info.Exists && packageMode == FileMode.OpenOrCreate && info.Length == 0)
throw new FileFormatException ("Stream length cannot be zero with FileMode.Open");
Stream s = File.Open (path, packageMode, packageAccess, packageShare);
return Open (s, packageMode, packageAccess, true);
}
static Package OpenCore (Stream stream, FileMode packageMode, FileAccess packageAccess, bool ownsStream)
{
if ((packageAccess & FileAccess.Read) == FileAccess.Read && !stream.CanRead)
throw new IOException ("Stream does not support reading");
if ((packageAccess & FileAccess.Write) == FileAccess.Write && !stream.CanWrite)
throw new IOException ("Stream does not support reading");
if (!stream.CanSeek)
throw new ArgumentException ("stream", "Stream must support seeking");
if (packageMode == FileMode.Open && stream.Length == 0)
throw new FileFormatException("Stream length cannot be zero with FileMode.Open");
if (packageMode == FileMode.CreateNew && stream.Length > 0)
throw new IOException ("Cannot use CreateNew when stream contains data");
if (packageMode == FileMode.Append || packageMode == FileMode.Truncate)
{
if (stream.CanWrite)
throw new NotSupportedException (string.Format("PackageMode.{0} is not supported", packageMode));
else
throw new IOException (string.Format("PackageMode.{0} is not supported", packageMode));
}
// Test to see if archive is valid
if (stream.Length > 0 && packageAccess == FileAccess.Read) {
try {
using (zipsharp.UnzipArchive a = new zipsharp.UnzipArchive (stream)) {
}
} catch {
throw new FileFormatException ("The specified archive is invalid.");
}
}
return new ZipPackage (packageAccess, ownsStream, stream);
}
public virtual bool PartExists (Uri partUri)
{
return GetPart (partUri) != null;
}
public bool RelationshipExists (string id)
{
return Relationships.ContainsKey (id);
}
internal static void WriteRelationships (Dictionary <string, PackageRelationship> relationships, Stream stream)
{
XmlDocument doc = new XmlDocument ();
XmlNamespaceManager manager = new XmlNamespaceManager (doc.NameTable);
manager.AddNamespace ("rel", RelationshipNamespace);
doc.AppendChild (doc.CreateNode (XmlNodeType.XmlDeclaration, "", ""));
XmlNode root = doc.CreateNode (XmlNodeType.Element, "Relationships", RelationshipNamespace);
doc.AppendChild (root);
foreach (PackageRelationship relationship in relationships.Values)
{
XmlNode node = doc.CreateNode (XmlNodeType.Element, "Relationship", RelationshipNamespace);
XmlAttribute idAtt = doc.CreateAttribute ("Id");
idAtt.Value = relationship.Id;
node.Attributes.Append(idAtt);
XmlAttribute targetAtt = doc.CreateAttribute ("Target");
targetAtt.Value = relationship.TargetUri.ToString ();
node.Attributes.Append(targetAtt);
if (relationship.TargetMode != TargetMode.Internal) {
XmlAttribute modeAtt = doc.CreateAttribute ("TargetMode");
modeAtt.Value = relationship.TargetMode.ToString ();
node.Attributes.Append (modeAtt);
}
XmlAttribute typeAtt = doc.CreateAttribute ("Type");
typeAtt.Value = relationship.RelationshipType;
node.Attributes.Append(typeAtt);
root.AppendChild (node);
}
using (XmlTextWriter writer = new XmlTextWriter (stream, System.Text.Encoding.UTF8))
doc.WriteTo (writer);
}
}
}

View File

@@ -0,0 +1,101 @@
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
// Copyright (c) 2008 Novell, Inc. (http://www.novell.com)
//
// Authors:
// Chris Toshok (toshok@ximian.com)
//
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Security;
using System.Security.Cryptography.X509Certificates;
namespace System.IO.Packaging {
public class PackageDigitalSignature
{
internal PackageDigitalSignature ()
{
}
public CertificateEmbeddingOption CertificateEmbeddingOption {
get { throw new NotImplementedException (); }
}
#if notyet
public System.Security.Cryptography.Xml.Signature Signature {
get { throw new NotImplementedException (); }
set { throw new NotImplementedException (); }
}
#endif
public PackagePart SignaturePart {
get { throw new NotImplementedException (); }
}
public string SignatureType {
get { throw new NotImplementedException (); }
}
public byte[] SignatureValue {
get { throw new NotImplementedException (); }
}
public ReadOnlyCollection<Uri> SignedParts {
get { throw new NotImplementedException (); }
}
public ReadOnlyCollection<PackageRelationshipSelector> SignedRelationshipSelectors {
get { throw new NotImplementedException (); }
}
public X509Certificate Signer {
get { throw new NotImplementedException (); }
}
public DateTime SigningTime {
get { throw new NotImplementedException (); }
}
public string TimeFormat {
get { throw new NotImplementedException (); }
}
public List<string> GetPartTransformList(Uri partName)
{
throw new NotImplementedException ();
}
public VerifyResult Verify()
{
throw new NotImplementedException ();
}
[SecurityCritical]
[SecurityTreatAsSafe]
public VerifyResult Verify(X509Certificate signingCertificate)
{
throw new NotImplementedException ();
}
}
}

View File

@@ -0,0 +1,168 @@
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
// Copyright (c) 2008 Novell, Inc. (http://www.novell.com)
//
// Authors:
// Chris Toshok (toshok@ximian.com)
//
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Security;
using System.Security.Cryptography.X509Certificates;
#if notyet
using System.Security.Cryptography.Xml;
#endif
namespace System.IO.Packaging {
public sealed class PackageDigitalSignatureManager
{
public static string DefaultHashAlgorithm {
get { throw new NotImplementedException (); }
}
public static string SignatureOriginRelationshipType {
get { throw new NotImplementedException (); }
}
public PackageDigitalSignatureManager (Package package)
{
throw new NotImplementedException ();
}
public CertificateEmbeddingOption CertificateOption {
get { throw new NotImplementedException (); }
set { throw new NotImplementedException (); }
}
public string HashAlgorithm {
get { throw new NotImplementedException (); }
set { throw new NotImplementedException (); }
}
public bool IsSigned {
get { throw new NotImplementedException (); }
}
public IntPtr ParentWindow {
get { throw new NotImplementedException (); }
set { throw new NotImplementedException (); }
}
public Uri SignatureOrigin {
get { throw new NotImplementedException (); }
}
public ReadOnlyCollection<PackageDigitalSignature> Signatures {
get { throw new NotImplementedException (); }
}
public string TimeFormat {
get { throw new NotImplementedException (); }
set { throw new NotImplementedException (); }
}
public Dictionary<string, string> TransformMapping {
get { throw new NotImplementedException (); }
}
public event InvalidSignatureEventHandler InvalidSignatureEvent;
public PackageDigitalSignature Countersign()
{
throw new NotImplementedException ();
}
public PackageDigitalSignature Countersign(X509Certificate certificate)
{
throw new NotImplementedException ();
}
public PackageDigitalSignature Countersign(X509Certificate certificate, IEnumerable<Uri> signatures)
{
throw new NotImplementedException ();
}
public PackageDigitalSignature GetSignature (Uri signatureUri)
{
throw new NotImplementedException ();
}
public void RemoveSignature (Uri signatureUri)
{
throw new NotImplementedException ();
}
public void RemoveAllSignatures ()
{
throw new NotImplementedException ();
}
public PackageDigitalSignature Sign (IEnumerable<Uri> parts)
{
throw new NotImplementedException ();
}
public PackageDigitalSignature Sign (IEnumerable<Uri> parts, X509Certificate certificate)
{
throw new NotImplementedException ();
}
public PackageDigitalSignature Sign (IEnumerable<Uri> parts, X509Certificate certificate, IEnumerable<PackageRelationshipSelector> relationshipSelectors)
{
throw new NotImplementedException ();
}
public PackageDigitalSignature Sign (IEnumerable<Uri> parts, X509Certificate certificate, IEnumerable<PackageRelationshipSelector> relationshipSelectors,
string signatureId)
{
throw new NotImplementedException ();
}
#if notyet
public PackageDigitalSignature Sign (IEnumerable<Uri> parts, X509Certificate certificate, IEnumerable<PackageRelationshipSelector> relationshipSelectors,
string signatureId,
IEnumerable<DataObject> signatureObjects,
IEnumerable<Reference> objectReferences)
{
throw new NotImplementedException ();
}
#endif
[SecurityCritical]
public static X509ChainStatusFlags VerifyCertificate (X509Certificate certificate)
{
throw new NotImplementedException ();
}
public VerifyResult VerifySignatures (bool exitOnFailure)
{
throw new NotImplementedException ();
}
}
}

View File

@@ -0,0 +1,265 @@
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
// Copyright (c) 2007 Novell, Inc. (http://www.novell.com)
//
// Authors:
// Chris Toshok (toshok@ximian.com)
// Alan McGovern (amcgovern@novell.com)
//
using System;
using System.Collections.Generic;
using System.IO;
using System.Xml;
namespace System.IO.Packaging {
public abstract class PackagePart
{
string contentType;
internal bool IsRelationship { get; set; }
int relationshipId;
Dictionary<string, PackageRelationship> relationships;
PackageRelationshipCollection relationshipsCollection = new PackageRelationshipCollection ();
Dictionary<string, PackageRelationship> Relationships {
get {
if (relationships == null) {
relationships = new Dictionary<string, PackageRelationship> (StringComparer.OrdinalIgnoreCase);
if (Package.PartExists (RelationshipsPartUri))
using (Stream s = Package.GetPart (RelationshipsPartUri).GetStream ())
LoadRelationships (relationships, s);
}
return relationships;
}
}
Stream PartStream { get; set; }
internal Uri RelationshipsPartUri {
get; set;
}
protected PackagePart (Package package, Uri partUri)
: this(package, partUri, null)
{
}
protected internal PackagePart (Package package, Uri partUri, string contentType)
: this (package, partUri, contentType, CompressionOption.Normal)
{
}
protected internal PackagePart (Package package, Uri partUri, string contentType, CompressionOption compressionOption)
{
Check.Package (package);
Check.PartUri (partUri);
Check.ContentTypeIsValid (contentType);
Package = package;
Uri = partUri;
ContentType = contentType;
CompressionOption = compressionOption;
RelationshipsPartUri = PackUriHelper.GetRelationshipPartUri(Uri);
}
public CompressionOption CompressionOption {
get; private set;
}
public string ContentType {
get {
if (contentType == null && (contentType = GetContentTypeCore()) == null)
throw new NotSupportedException ("If contentType is not supplied in the constructor, GetContentTypeCore must be overridden");
return contentType;
}
private set {
contentType = value;
}
}
public Package Package {
get; internal set;
}
public Uri Uri {
get; private set;
}
private void CheckIsRelationship ()
{
if (IsRelationship)
throw new InvalidOperationException ("A relationship cannot have relationships to other parts");
}
public PackageRelationship CreateRelationship (Uri targetUri, TargetMode targetMode, string relationshipType)
{
return CreateRelationship (targetUri, targetMode, relationshipType, null);
}
public PackageRelationship CreateRelationship (Uri targetUri, TargetMode targetMode, string relationshipType, string id)
{
return CreateRelationship (targetUri, targetMode, relationshipType, id, false);
}
private PackageRelationship CreateRelationship (Uri targetUri, TargetMode targetMode, string relationshipType, string id, bool loading)
{
Package.CheckIsReadOnly ();
Check.TargetUri (targetUri);
Check.RelationshipTypeIsValid (relationshipType);
Check.IdIsValid (id);
if (id == null)
id = NextId ();
if (Relationships.ContainsKey (id))
throw new XmlException ("A relationship with this ID already exists");
PackageRelationship r = new PackageRelationship (id, Package, relationshipType, Uri, targetMode, targetUri);
Relationships.Add (r.Id, r);
if (!loading)
WriteRelationships ();
return r;
}
public void DeleteRelationship (string id)
{
Package.CheckIsReadOnly ();
CheckIsRelationship ();
Relationships.Remove (id);
WriteRelationships ();
}
void LoadRelationships (Dictionary<string, PackageRelationship> relationships, Stream stream)
{
XmlDocument doc = new XmlDocument ();
doc.Load (stream);
XmlNamespaceManager manager = new XmlNamespaceManager (doc.NameTable);
manager.AddNamespace ("rel", Package.RelationshipNamespace);
foreach (XmlNode node in doc.SelectNodes ("/rel:Relationships/*", manager))
{
TargetMode mode = TargetMode.Internal;
if (node.Attributes["TargetMode"] != null)
mode = (TargetMode) Enum.Parse (typeof(TargetMode), node.Attributes ["TargetMode"].Value);
CreateRelationship (new Uri (node.Attributes["Target"].Value.ToString(), UriKind.Relative),
mode,
node.Attributes["Type"].Value.ToString (),
node.Attributes["Id"].Value.ToString (),
true);
}
}
public bool RelationshipExists (string id)
{
CheckIsRelationship ();
return Relationships.ContainsKey (id);
}
public PackageRelationship GetRelationship (string id)
{
CheckIsRelationship ();
return Relationships [id];
}
public PackageRelationshipCollection GetRelationships ()
{
CheckIsRelationship ();
relationshipsCollection.Relationships.Clear ();
relationshipsCollection.Relationships.AddRange (Relationships.Values);
return relationshipsCollection;
}
public PackageRelationshipCollection GetRelationshipsByType (string relationshipType)
{
CheckIsRelationship ();
PackageRelationshipCollection collection = new PackageRelationshipCollection ();
foreach (PackageRelationship r in Relationships.Values)
if (r.RelationshipType == relationshipType)
collection.Relationships.Add (r);
return collection;
}
public Stream GetStream ()
{
return GetStream (Package.FileOpenAccess == FileAccess.Read && !IsRelationship ? FileMode.Open : FileMode.OpenOrCreate);
}
public Stream GetStream (FileMode mode)
{
return GetStream (mode, IsRelationship ? FileAccess.ReadWrite : Package.FileOpenAccess);
}
public Stream GetStream (FileMode mode, FileAccess access)
{
bool notAllowed = mode == FileMode.Append || mode == FileMode.CreateNew || mode == FileMode.Truncate;
if (access != FileAccess.Read && notAllowed)
throw new ArgumentException (string.Format (string.Format ("FileMode '{0}' not supported", mode)));
if (access == FileAccess.Read && (notAllowed || mode == FileMode.Create))
throw new IOException (string.Format ("FileMode '{0}' not allowed on a readonly stream", mode));
return GetStreamCore (mode, access);
}
protected abstract Stream GetStreamCore (FileMode mode, FileAccess access);
protected virtual string GetContentTypeCore ()
{
return null;
}
private string NextId ()
{
while (true)
{
string s = "Re" + relationshipId.ToString ();
if (!RelationshipExists (s))
return s;
relationshipId ++;
}
}
void WriteRelationships ()
{
bool exists = Package.PartExists (RelationshipsPartUri);
if (exists && Relationships.Count == 0)
{
Package.DeletePart (RelationshipsPartUri);
return;
}
if (!exists)
{
PackagePart part = Package.CreatePart (RelationshipsPartUri, Package.RelationshipContentType);
part.IsRelationship = true;
}
using (Stream s = Package.GetPart (RelationshipsPartUri).GetStream ())
Package.WriteRelationships (Relationships, s);
}
}
}

View File

@@ -0,0 +1,52 @@
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
// Copyright (c) 2007 Novell, Inc. (http://www.novell.com)
//
// Authors:
// Chris Toshok (toshok@ximian.com)
// Alan McGovern (amcgovern@novell.com)
//
using System;
using System.Collections;
using System.Collections.Generic;
namespace System.IO.Packaging {
public class PackagePartCollection : IEnumerable<PackagePart>, IEnumerable
{
internal List<PackagePart> Parts { get; private set; }
internal PackagePartCollection ()
{
Parts = new List<PackagePart> ();
}
public IEnumerator<PackagePart> GetEnumerator ()
{
return Parts.GetEnumerator ();
}
IEnumerator IEnumerable.GetEnumerator ()
{
return Parts.GetEnumerator ();
}
}
}

View File

@@ -0,0 +1,110 @@
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
// Copyright (c) 2007 Novell, Inc. (http://www.novell.com)
//
// Authors:
// Chris Toshok (toshok@ximian.com)
// Alan McGovern (amcgovern@novell.com)
//
using System;
using System.Xml;
namespace System.IO.Packaging {
public abstract class PackageProperties : IDisposable
{
internal const string NSPackageProperties = "http://schemas.openxmlformats.org/package/2006/metadata/core-properties";
internal const string NSPackagePropertiesRelation = "http://schemas.openxmlformats.org/package/2006/relationships/metadata/core-properties";
internal const string PackagePropertiesContentType = "application/vnd.openxmlformats-package.core-properties+xml";
static int uuid;
protected PackageProperties ()
{
}
public abstract string Category { get; set; }
public abstract string ContentStatus { get; set; }
public abstract string ContentType { get; set; }
public abstract DateTime? Created { get; set; }
public abstract string Creator { get; set; }
public abstract string Description { get; set; }
public abstract string Identifier { get; set; }
public abstract string Keywords { get; set; }
public abstract string Language { get; set; }
public abstract string LastModifiedBy { get; set; }
public abstract DateTime? LastPrinted { get; set; }
public abstract DateTime? Modified { get; set; }
internal Package Package { get; set; }
internal PackagePart Part { get; set; }
public abstract string Revision { get; set; }
public abstract string Subject { get; set; }
public abstract string Title { get; set; }
public abstract string Version { get; set; }
public void Dispose ()
{
Dispose (true);
}
protected virtual void Dispose (bool disposing)
{
// Nothing
}
internal void Flush ()
{
using (MemoryStream temp = new MemoryStream ()) {
using (XmlTextWriter writer = new XmlTextWriter (temp, System.Text.Encoding.UTF8)) {
WriteTo (writer);
writer.Flush ();
if (temp.Length == 0)
return;
}
}
if (Part == null)
{
int id = System.Threading.Interlocked.Increment (ref uuid);
Uri uri = new Uri (string.Format ("/package/services/metadata/core-properties/{0}.psmdcp", id), UriKind.Relative);
Part = Package.CreatePart (uri, PackagePropertiesContentType);
PackageRelationship rel = Package.CreateRelationship (uri, TargetMode.Internal, NSPackagePropertiesRelation);
}
using (Stream s = Part.GetStream (FileMode.Create))
using (XmlTextWriter writer = new XmlTextWriter (s, System.Text.Encoding.UTF8))
WriteTo (writer);
}
internal virtual void LoadFrom (Stream stream)
{
}
internal virtual void WriteTo (XmlTextWriter writer)
{
}
}
}

View File

@@ -0,0 +1,297 @@
// PackagePropertiesPart.cs created with MonoDevelop
// User: alan at 11:07 04/11/2008
//
// To change standard headers go to Edit->Preferences->Coding->Standard Headers
//
using System;
using System.Xml;
namespace System.IO.Packaging
{
class PackagePropertiesPart : PackageProperties
{
const string NSDc = "http://purl.org/dc/elements/1.1/";
const string NSDcTerms = "http://purl.org/dc/terms/";
const string NSXsi = "http://www.w3.org/2001/XMLSchema-instance";
string category;
string contentStatus;
string contentType;
DateTime? created;
string creator;
string description;
string identifier;
string keywords;
string language;
string lastModifiedBy;
DateTime? lastPrinted;
DateTime? modified;
string revision;
string subject;
string title;
string version;
public PackagePropertiesPart ()
{
}
public override string Category {
get {
return category;
}
set {
Package.CheckIsReadOnly ();
category = value;
}
}
public override string ContentStatus {
get {
return contentStatus;
}
set {
Package.CheckIsReadOnly ();
contentStatus = value;
}
}
public override string ContentType {
get {
return contentType;
}
set {
Package.CheckIsReadOnly ();
contentType = value;
}
}
public override DateTime? Created {
get {
return created;
}
set {
Package.CheckIsReadOnly ();
created = value;
}
}
public override string Creator {
get {
return creator;
}
set {
Package.CheckIsReadOnly ();
creator = value;
}
}
public override string Description {
get {
return description;
}
set {
Package.CheckIsReadOnly ();
description = value;
}
}
public override string Identifier {
get {
return identifier;
}
set {
Package.CheckIsReadOnly ();
identifier = value;
}
}
public override string Keywords {
get {
return keywords;
}
set {
Package.CheckIsReadOnly ();
keywords = value;
}
}
public override string Language {
get {
return language;
}
set {
Package.CheckIsReadOnly ();
language = value;
}
}
public override string LastModifiedBy {
get {
return lastModifiedBy;
}
set {
Package.CheckIsReadOnly ();
lastModifiedBy = value;
}
}
public override DateTime? LastPrinted {
get {
return lastPrinted;
}
set {
Package.CheckIsReadOnly ();
lastPrinted = value;
}
}
public override DateTime? Modified {
get {
return modified;
}
set {
Package.CheckIsReadOnly ();
modified = value;
}
}
public override string Revision {
get {
return revision;
}
set {
Package.CheckIsReadOnly ();
revision = value;
}
}
public override string Subject {
get {
return subject;
}
set {
Package.CheckIsReadOnly ();
subject = value;
}
}
public override string Title {
get {
return title;
}
set {
Package.CheckIsReadOnly ();
title = value;
}
}
public override string Version {
get {
return version;
}
set {
Package.CheckIsReadOnly ();
version = value;
}
}
internal override void LoadFrom (Stream stream)
{
if (stream.Length == 0)
return;
XmlDocument doc = new XmlDocument ();
doc.Load (stream);
XmlNamespaceManager manager = new XmlNamespaceManager (doc.NameTable);
manager.AddNamespace ("prop", NSPackageProperties);
manager.AddNamespace ("dc", NSDc);
manager.AddNamespace ("dcterms", NSDcTerms);
manager.AddNamespace ("xsi", NSXsi);
XmlNode node;
if ((node = doc.SelectSingleNode ("prop:coreProperties/prop:category", manager)) != null)
category = node.InnerXml;
if ((node = doc.SelectSingleNode ("prop:coreProperties/prop:contentStatus", manager)) != null)
contentStatus = node.InnerXml;
if ((node = doc.SelectSingleNode ("prop:coreProperties/prop:contentType", manager)) != null)
contentType = node.InnerXml;
if ((node = doc.SelectSingleNode ("prop:coreProperties/dcterms:created", manager)) != null)
created = DateTime.Parse (node.InnerXml);
if ((node = doc.SelectSingleNode ("prop:coreProperties/dc:creator", manager)) != null)
creator = node.InnerXml;
if ((node = doc.SelectSingleNode ("prop:coreProperties/dc:description", manager)) != null)
description = node.InnerXml;
if ((node = doc.SelectSingleNode ("prop:coreProperties/dc:identifier", manager)) != null)
identifier = node.InnerXml;
if ((node = doc.SelectSingleNode ("prop:coreProperties/prop:keywords", manager)) != null)
keywords = node.InnerXml;
if ((node = doc.SelectSingleNode ("prop:coreProperties/dc:language", manager)) != null)
language = node.InnerXml;
if ((node = doc.SelectSingleNode ("prop:coreProperties/prop:lastModifiedBy", manager)) != null)
lastModifiedBy = node.InnerXml;
if ((node = doc.SelectSingleNode ("prop:coreProperties/prop:lastPrinted", manager)) != null)
lastPrinted = DateTime.Parse (node.InnerXml);
if ((node = doc.SelectSingleNode ("prop:coreProperties/dcterms:modified", manager)) != null)
modified = DateTime.Parse (node.InnerXml);
if ((node = doc.SelectSingleNode ("prop:coreProperties/prop:revision", manager)) != null)
revision = node.InnerXml;
if ((node = doc.SelectSingleNode ("prop:coreProperties/dc:subject", manager)) != null)
subject = node.InnerXml;
if ((node = doc.SelectSingleNode ("prop:coreProperties/dc:title", manager)) != null)
title = node.InnerXml;
if ((node = doc.SelectSingleNode ("prop:coreProperties/prop:version", manager)) != null)
version = node.InnerXml;
}
internal override void WriteTo(XmlTextWriter writer)
{
XmlDocument doc = new XmlDocument ();
XmlNamespaceManager manager = new XmlNamespaceManager (doc.NameTable);
manager.AddNamespace ("prop", NSPackageProperties);
manager.AddNamespace ("dc", NSDc);
manager.AddNamespace ("dcterms", NSDcTerms);
manager.AddNamespace ("xsi", NSXsi);
// Create XML declaration
doc.AppendChild (doc.CreateXmlDeclaration ("1.0", "UTF-8", null));
// Create root node with required namespace declarations
XmlNode coreProperties = doc.AppendChild (doc.CreateNode (XmlNodeType.Element, "coreProperties", NSPackageProperties));
coreProperties.Attributes.Append (doc.CreateAttribute ("xmlns:dc")).Value = NSDc;
coreProperties.Attributes.Append (doc.CreateAttribute ("xmlns:dcterms")).Value = NSDcTerms;
coreProperties.Attributes.Append (doc.CreateAttribute ("xmlns:xsi")).Value = NSXsi;
// Create the children
if (Category != null)
coreProperties.AppendChild (doc.CreateNode (XmlNodeType.Element, "category", NSPackageProperties)).InnerXml = Category;
if (ContentStatus != null)
coreProperties.AppendChild (doc.CreateNode (XmlNodeType.Element, "contentStatus", NSPackageProperties)).InnerXml = ContentStatus;
if (ContentType != null)
coreProperties.AppendChild (doc.CreateNode (XmlNodeType.Element, "contentType", NSPackageProperties)).InnerXml = ContentType;
if (Created.HasValue)
coreProperties.AppendChild (doc.CreateNode (XmlNodeType.Element, "dcterms", "created", NSDcTerms)).InnerXml = Created.Value.ToString ();
if (Creator != null)
coreProperties.AppendChild (doc.CreateNode (XmlNodeType.Element, "dc", "creator", NSDc)).InnerXml = Creator;
if (Description != null)
coreProperties.AppendChild (doc.CreateNode (XmlNodeType.Element, "dc", "description", NSDc)).InnerXml = Description;
if (Identifier != null)
coreProperties.AppendChild (doc.CreateNode (XmlNodeType.Element, "dc", "identifier", NSDc)).InnerXml = Identifier;
if (Keywords != null)
coreProperties.AppendChild (doc.CreateNode (XmlNodeType.Element, "keywords", NSPackageProperties)).InnerXml = Keywords;
if (Language != null)
coreProperties.AppendChild (doc.CreateNode (XmlNodeType.Element, "dc", "language", NSDc)).InnerXml = Language;
if (LastModifiedBy != null)
coreProperties.AppendChild (doc.CreateNode (XmlNodeType.Element, "lastModifiedBy", NSPackageProperties)).InnerXml = LastModifiedBy;
if (LastPrinted.HasValue)
coreProperties.AppendChild (doc.CreateNode (XmlNodeType.Element, "lastPrinted", NSPackageProperties)).InnerXml = LastPrinted.Value.ToString ();
if (Revision != null)
coreProperties.AppendChild (doc.CreateNode (XmlNodeType.Element, "revision", NSPackageProperties)).InnerXml = Revision;
if (Subject != null)
coreProperties.AppendChild (doc.CreateNode (XmlNodeType.Element, "dc", "subject", NSDc)).InnerXml = Subject;
if (Title != null)
coreProperties.AppendChild (doc.CreateNode (XmlNodeType.Element, "dc", "title", NSDc)).InnerXml = Title;
if (Version != null)
coreProperties.AppendChild (doc.CreateNode (XmlNodeType.Element, "version", NSPackageProperties)).InnerXml = Version;
if (Modified.HasValue)
{
XmlAttribute att = doc.CreateAttribute("xsi", "type", NSXsi);
att.Value = "dcterms:W3CDTF";
XmlNode modified = coreProperties.AppendChild (doc.CreateNode (XmlNodeType.Element, "dcterms", "modified", NSDcTerms));
modified.Attributes.Append (att);
modified.InnerXml = Modified.Value.ToString ();
}
doc.WriteContentTo (writer);
}
}
}

View File

@@ -0,0 +1,68 @@
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
// Copyright (c) 2007 Novell, Inc. (http://www.novell.com)
//
// Authors:
// Chris Toshok (toshok@ximian.com)
//
using System;
namespace System.IO.Packaging {
public class PackageRelationship
{
internal PackageRelationship (string id, Package package, string relationshipType,
Uri sourceUri, TargetMode targetMode, Uri targetUri)
{
Check.IdIsValid (id);
Check.Package (package);
Check.RelationshipTypeIsValid (relationshipType);
Check.SourceUri (sourceUri);
Check.TargetUri (targetUri);
Id = id;
Package = package;
RelationshipType = relationshipType;
SourceUri = sourceUri;
TargetMode = targetMode;
TargetUri = targetUri;
}
public string Id {
get; private set;
}
public Package Package {
get; private set;
}
public string RelationshipType {
get; private set;
}
public Uri SourceUri {
get; private set;
}
public TargetMode TargetMode {
get; private set;
}
public Uri TargetUri {
get; private set;
}
}
}

View File

@@ -0,0 +1,52 @@
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
// Copyright (c) 2007 Novell, Inc. (http://www.novell.com)
//
// Authors:
// Chris Toshok (toshok@ximian.com)
// Alan McGovern (amcgovern@novell.com)
//
using System;
using System.Collections;
using System.Collections.Generic;
namespace System.IO.Packaging {
public class PackageRelationshipCollection : IEnumerable<PackageRelationship>, IEnumerable
{
internal List<PackageRelationship> Relationships { get; private set; }
internal PackageRelationshipCollection ()
{
Relationships = new List<PackageRelationship> ();
}
public IEnumerator<PackageRelationship> GetEnumerator ()
{
return Relationships.GetEnumerator ();
}
IEnumerator IEnumerable.GetEnumerator ()
{
return GetEnumerator();
}
}
}

View File

@@ -0,0 +1,55 @@
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
// Copyright (c) 2008 Novell, Inc. (http://www.novell.com)
//
// Authors:
// Chris Toshok (toshok@ximian.com)
//
using System;
using System.Collections.Generic;
namespace System.IO.Packaging {
public sealed class PackageRelationshipSelector {
public PackageRelationshipSelector (Uri sourceUri, PackageRelationshipSelectorType selectorType, string selectionCriteria)
{
throw new NotImplementedException ();
}
public string SelectionCriteria {
get { throw new NotImplementedException (); }
}
public PackageRelationshipSelectorType SelectorType {
get { throw new NotImplementedException (); }
}
public Uri SourceUri {
get { throw new NotImplementedException (); }
}
public List<PackageRelationship> Select(Package package)
{
throw new NotImplementedException ();
}
}
}

View File

@@ -0,0 +1,33 @@
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
// Copyright (c) 2008 Novell, Inc. (http://www.novell.com)
//
// Authors:
// Chris Toshok (toshok@ximian.com)
//
namespace System.IO.Packaging {
public enum PackageRelationshipSelectorType {
Id,
Type
}
}

View File

@@ -0,0 +1,74 @@
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
// Copyright (c) 2007 Novell, Inc. (http://www.novell.com)
//
// Authors:
// Chris Toshok (toshok@ximian.com)
//
using System;
using System.Collections.Generic;
using System.Security.RightsManagement;
namespace System.IO.Packaging {
public class RightsManagementInformation
{
internal RightsManagementInformation ()
{
}
public CryptoProvider CryptoProvider {
get { throw new NotImplementedException (); }
set { throw new NotImplementedException (); }
}
public void DeleteUseLicense (ContentUser userKey)
{
throw new NotImplementedException ();
}
public IDictionary<ContentUser, UseLicense> GetEmbeddedUseLicenses()
{
throw new NotImplementedException ();
}
public PublishLicense LoadPublishLicense ()
{
throw new NotImplementedException ();
}
public UseLicense LoadUseLicense (ContentUser userKey)
{
throw new NotImplementedException ();
}
public void SavePublishLicense (PublishLicense publishLicense)
{
throw new NotImplementedException ();
}
public void SaveUseLicense (ContentUser userKey, UseLicense useLicense)
{
throw new NotImplementedException ();
}
}
}

Some files were not shown because too many files have changed in this diff Show More