Fixed ceiling calculation
[pithos-ms-client] / trunk / Pithos.Interfaces / ObjectInfo.cs
1 using System;
2 using System.Collections.Generic;
3 using System.Globalization;
4 using System.IO;
5
6 namespace Pithos.Interfaces
7 {
8     public class ObjectInfo
9     {
10         public string Name { get; set; }
11         public string Hash { get; set; }
12         public long Bytes { get; set; }
13         public string Content_Type { get; set; }
14         public DateTime Last_Modified { get; set; }
15
16         private Dictionary<string, string> _tags=new Dictionary<string, string>();
17         public Dictionary<string, string> Tags
18         {
19             get { return _tags; }
20             set { _tags = value; }
21         }
22
23         private Dictionary<string, string> _extensions=new Dictionary<string, string>();
24         public Dictionary<string, string> Extensions
25         {
26             get { return _extensions; }
27             set
28             {
29                 _extensions = value;
30                 ExtractKnownExtensions();
31             }
32         }
33
34         public long? Version { get; set; }
35         public DateTime? VersionTimeStamp { get; set; }
36
37         public Stream Stream { get; set; }
38
39
40         private void ExtractKnownExtensions()
41         {
42             Version=GetLong("X-Object-Version");
43             VersionTimeStamp = GetTimestamp("X-Object-Version-TimeStamp");
44         }
45
46         private long? GetLong(string name)
47         {
48             string version;
49             long value;
50             if (_extensions.TryGetValue(name, out version) && long.TryParse(version, out value))
51             {
52                 return value;
53             }
54             return null;
55         }
56
57         private DateTime? GetTimestamp(string name)
58         {
59             string version;
60             DateTime value;
61             if (_extensions.TryGetValue(name, out version) && 
62                 DateTime.TryParse(version,CultureInfo.InvariantCulture,DateTimeStyles.AdjustToUniversal, out value))
63             {
64                 return value;
65             }
66             return null;
67         }
68
69
70         public static ObjectInfo Empty = new ObjectInfo
71         {
72             Name = String.Empty,
73             Hash = String.Empty,
74             Bytes = 0,
75             Content_Type = String.Empty,
76             Last_Modified = DateTime.MinValue
77         };
78     }
79 }