X-Git-Url: https://code.grnet.gr/git/pithos-ms-client/blobdiff_plain/3c76f045adf73ec1dec5f87fd5dd454ff91dbb4f..dcca46c36c5767ce7f4ce1dac83f0b90600b3606:/trunk/Pithos.Interfaces/ObjectInfo.cs diff --git a/trunk/Pithos.Interfaces/ObjectInfo.cs b/trunk/Pithos.Interfaces/ObjectInfo.cs index fb48a95..fa97feb 100644 --- a/trunk/Pithos.Interfaces/ObjectInfo.cs +++ b/trunk/Pithos.Interfaces/ObjectInfo.cs @@ -1,3 +1,44 @@ +#region +/* ----------------------------------------------------------------------- + * + * + * Copyright 2011-2012 GRNET S.A. All rights reserved. + * + * Redistribution and use in source and binary forms, with or + * without modification, are permitted provided that the following + * conditions are met: + * + * 1. Redistributions of source code must retain the above + * copyright notice, this list of conditions and the following + * disclaimer. + * + * 2. Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * + * THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS + * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * The views and conclusions contained in the software and + * documentation are those of the authors and should not be + * interpreted as representing official policies, either expressed + * or implied, of GRNET S.A. + * + * ----------------------------------------------------------------------- + */ +#endregion using System; using System.Collections.Generic; using System.Diagnostics; @@ -12,7 +53,7 @@ using Newtonsoft.Json; namespace Pithos.Interfaces { [DebuggerDisplay("Name {Name}")] - public class ObjectInfo:DynamicObject + public class ObjectInfo//:DynamicObject { private readonly List _knownContainers= new List{"trash"}; public string Name { get; set; } @@ -86,10 +127,24 @@ namespace Pithos.Interfaces public Stream Stream { get; set; } + + public Uri StorageUri { get; set; } + public string Account { get; set; } public string Container { get; set; } + public Uri Uri + { + get + { + var relativeUrl=String.Format("{0}/{1}/{2}",Account, Container,Name); + return StorageUri==null + ? new Uri(relativeUrl,UriKind.Relative) + : new Uri(StorageUri, relativeUrl); + } + } + public string ContendDisposition { get; set; } public string ContentEncoding { get; set; } @@ -111,6 +166,8 @@ namespace Pithos.Interfaces [JsonProperty("X_Object_Public")] public string PublicUrl { get; set; } + public string PreviousHash { get; set; } + public ObjectInfo() {} @@ -179,9 +236,23 @@ namespace Pithos.Interfaces Hash = String.Empty, Bytes = 0, Content_Type = String.Empty, - Last_Modified = DateTime.MinValue + Last_Modified = DateTime.MinValue, + Exists=false }; + private bool _exists=true; + + public bool Exists + { + get { + return _exists; + } + set { + _exists = value; + } + } + + public string RelativeUrlToFilePath(string currentAccount) { if (Name==null) @@ -204,13 +275,14 @@ namespace Pithos.Interfaces if (Account != null) { pathParts.Push(Account); - pathParts.Push("others"); + pathParts.Push(FolderConstants.OthersFolder); } } var finalPath=Path.Combine(pathParts.ToArray()); return finalPath; } +/* public override bool TrySetMember(SetMemberBinder binder, object value) { if (binder.Name.StartsWith("x_object_meta")) @@ -219,6 +291,7 @@ namespace Pithos.Interfaces } return false; } +*/ public string GetPermissionString() { @@ -255,5 +328,32 @@ namespace Pithos.Interfaces } Permissions = permDict; } + + //The previous values that correspond to a NoModification object + //have the same account, container and possibly the same folder + public bool CorrespondsTo(ObjectInfo other) + { + return other.Account == this.Account + && other.Container == this.Container + && (this.Name == null || other.Name.StartsWith(this.Name)); + } + + + public ObjectInfo Previous { get; private set; } + + public bool IsDirectory + { + get + { + return String.Equals(Content_Type, @"application/directory",StringComparison.InvariantCultureIgnoreCase); + } + } + + public ObjectInfo SetPrevious(ObjectInfo previous) + { + Previous = previous; + PreviousHash = previous.Hash; + return this; + } } } \ No newline at end of file