root / trunk / Pithos.Interfaces / ObjectInfo.cs @ a27aa447
History | View | Annotate | Download (4.1 kB)
1 | 3c43ec9b | Panagiotis Kanavos | using System; |
---|---|---|---|
2 | 3c43ec9b | Panagiotis Kanavos | using System.Collections.Generic; |
3 | 9c4346c9 | Panagiotis Kanavos | using System.Globalization; |
4 | 3c43ec9b | Panagiotis Kanavos | using System.IO; |
5 | 3c43ec9b | Panagiotis Kanavos | |
6 | 3c43ec9b | Panagiotis Kanavos | namespace Pithos.Interfaces |
7 | 3c43ec9b | Panagiotis Kanavos | { |
8 | 3c43ec9b | Panagiotis Kanavos | public class ObjectInfo |
9 | 3c43ec9b | Panagiotis Kanavos | { |
10 | 3c43ec9b | Panagiotis Kanavos | public string Name { get; set; } |
11 | 3c43ec9b | Panagiotis Kanavos | public string Hash { get; set; } |
12 | 3c43ec9b | Panagiotis Kanavos | public long Bytes { get; set; } |
13 | 3c43ec9b | Panagiotis Kanavos | public string Content_Type { get; set; } |
14 | 3c43ec9b | Panagiotis Kanavos | public DateTime Last_Modified { get; set; } |
15 | 3c43ec9b | Panagiotis Kanavos | |
16 | 3c43ec9b | Panagiotis Kanavos | private Dictionary<string, string> _tags=new Dictionary<string, string>(); |
17 | 3c43ec9b | Panagiotis Kanavos | public Dictionary<string, string> Tags |
18 | 3c43ec9b | Panagiotis Kanavos | { |
19 | 3c43ec9b | Panagiotis Kanavos | get { return _tags; } |
20 | 3c43ec9b | Panagiotis Kanavos | set { _tags = value; } |
21 | 3c43ec9b | Panagiotis Kanavos | } |
22 | 3c43ec9b | Panagiotis Kanavos | |
23 | 3c43ec9b | Panagiotis Kanavos | private Dictionary<string, string> _extensions=new Dictionary<string, string>(); |
24 | 3c43ec9b | Panagiotis Kanavos | public Dictionary<string, string> Extensions |
25 | 3c43ec9b | Panagiotis Kanavos | { |
26 | 3c43ec9b | Panagiotis Kanavos | get { return _extensions; } |
27 | 9c4346c9 | Panagiotis Kanavos | set |
28 | 9c4346c9 | Panagiotis Kanavos | { |
29 | 9c4346c9 | Panagiotis Kanavos | _extensions = value; |
30 | 9c4346c9 | Panagiotis Kanavos | ExtractKnownExtensions(); |
31 | 9c4346c9 | Panagiotis Kanavos | } |
32 | 3c43ec9b | Panagiotis Kanavos | } |
33 | 3c43ec9b | Panagiotis Kanavos | |
34 | bfc13ed8 | Panagiotis Kanavos | private long? _version; |
35 | bfc13ed8 | Panagiotis Kanavos | public long? Version |
36 | bfc13ed8 | Panagiotis Kanavos | { |
37 | bfc13ed8 | Panagiotis Kanavos | get { return _version; } |
38 | bfc13ed8 | Panagiotis Kanavos | set { _version = value; } |
39 | bfc13ed8 | Panagiotis Kanavos | } |
40 | bfc13ed8 | Panagiotis Kanavos | |
41 | bfc13ed8 | Panagiotis Kanavos | //Alias for version, for Json deserialization purposes |
42 | bfc13ed8 | Panagiotis Kanavos | public long? X_Object_Version |
43 | bfc13ed8 | Panagiotis Kanavos | { |
44 | bfc13ed8 | Panagiotis Kanavos | get { return _version; } |
45 | bfc13ed8 | Panagiotis Kanavos | set { _version = value; } |
46 | bfc13ed8 | Panagiotis Kanavos | } |
47 | bfc13ed8 | Panagiotis Kanavos | |
48 | a27aa447 | Panagiotis Kanavos | //Alias for VersionTimestamp, for Json deserialization purposes |
49 | a27aa447 | Panagiotis Kanavos | //The x_object_version_timestamp returned by GET on a container is |
50 | a27aa447 | Panagiotis Kanavos | //a float, probably due to a bug. |
51 | a27aa447 | Panagiotis Kanavos | public double? X_Object_Version_Timestamp |
52 | bfc13ed8 | Panagiotis Kanavos | { |
53 | a27aa447 | Panagiotis Kanavos | get |
54 | a27aa447 | Panagiotis Kanavos | { |
55 | a27aa447 | Panagiotis Kanavos | if (_versionTimestamp.HasValue) |
56 | a27aa447 | Panagiotis Kanavos | return (_versionTimestamp.Value-_epoch).TotalSeconds; |
57 | a27aa447 | Panagiotis Kanavos | return null; |
58 | a27aa447 | Panagiotis Kanavos | } |
59 | a27aa447 | Panagiotis Kanavos | set |
60 | a27aa447 | Panagiotis Kanavos | { |
61 | a27aa447 | Panagiotis Kanavos | if (value.HasValue) |
62 | a27aa447 | Panagiotis Kanavos | { |
63 | a27aa447 | Panagiotis Kanavos | _versionTimestamp = _epoch.AddSeconds(value.Value); |
64 | a27aa447 | Panagiotis Kanavos | } |
65 | a27aa447 | Panagiotis Kanavos | else |
66 | a27aa447 | Panagiotis Kanavos | { |
67 | a27aa447 | Panagiotis Kanavos | _versionTimestamp = null; |
68 | a27aa447 | Panagiotis Kanavos | } |
69 | a27aa447 | Panagiotis Kanavos | } |
70 | a27aa447 | Panagiotis Kanavos | } |
71 | bfc13ed8 | Panagiotis Kanavos | |
72 | bfc13ed8 | Panagiotis Kanavos | private DateTime? _versionTimestamp; |
73 | bfc13ed8 | Panagiotis Kanavos | public DateTime? VersionTimestamp |
74 | bfc13ed8 | Panagiotis Kanavos | { |
75 | bfc13ed8 | Panagiotis Kanavos | get { return _versionTimestamp; } |
76 | bfc13ed8 | Panagiotis Kanavos | set { _versionTimestamp = value; } |
77 | bfc13ed8 | Panagiotis Kanavos | } |
78 | bfc13ed8 | Panagiotis Kanavos | |
79 | bfc13ed8 | Panagiotis Kanavos | public string ModifiedBy |
80 | bfc13ed8 | Panagiotis Kanavos | { |
81 | bfc13ed8 | Panagiotis Kanavos | get{ return _modifiedBy; } |
82 | bfc13ed8 | Panagiotis Kanavos | set{ _modifiedBy = value; } |
83 | bfc13ed8 | Panagiotis Kanavos | } |
84 | bfc13ed8 | Panagiotis Kanavos | |
85 | bfc13ed8 | Panagiotis Kanavos | //Alias for ModifiedBy, for Json deserialization purposes |
86 | bfc13ed8 | Panagiotis Kanavos | public string X_Object_Modified_By |
87 | bfc13ed8 | Panagiotis Kanavos | { |
88 | bfc13ed8 | Panagiotis Kanavos | get{ return _modifiedBy; } |
89 | bfc13ed8 | Panagiotis Kanavos | set{ _modifiedBy = value; } |
90 | bfc13ed8 | Panagiotis Kanavos | } |
91 | 3c43ec9b | Panagiotis Kanavos | |
92 | 3c43ec9b | Panagiotis Kanavos | public Stream Stream { get; set; } |
93 | 3c43ec9b | Panagiotis Kanavos | |
94 | 9c4346c9 | Panagiotis Kanavos | |
95 | 9c4346c9 | Panagiotis Kanavos | private void ExtractKnownExtensions() |
96 | 9c4346c9 | Panagiotis Kanavos | { |
97 | bfc13ed8 | Panagiotis Kanavos | Version=GetLong(KnownExtensions.X_Object_Version); |
98 | bfc13ed8 | Panagiotis Kanavos | VersionTimestamp = GetTimestamp(KnownExtensions.X_Object_Version_Timestamp); |
99 | bfc13ed8 | Panagiotis Kanavos | ModifiedBy = GetString(KnownExtensions.X_Object_Modified_By); |
100 | bfc13ed8 | Panagiotis Kanavos | } |
101 | bfc13ed8 | Panagiotis Kanavos | |
102 | bfc13ed8 | Panagiotis Kanavos | private string GetString(string name) |
103 | bfc13ed8 | Panagiotis Kanavos | { |
104 | bfc13ed8 | Panagiotis Kanavos | var value=String.Empty; |
105 | bfc13ed8 | Panagiotis Kanavos | _extensions.TryGetValue(name, out value); |
106 | bfc13ed8 | Panagiotis Kanavos | return value ; |
107 | 9c4346c9 | Panagiotis Kanavos | } |
108 | 9c4346c9 | Panagiotis Kanavos | |
109 | 9c4346c9 | Panagiotis Kanavos | private long? GetLong(string name) |
110 | 9c4346c9 | Panagiotis Kanavos | { |
111 | 9c4346c9 | Panagiotis Kanavos | string version; |
112 | 9c4346c9 | Panagiotis Kanavos | long value; |
113 | bfc13ed8 | Panagiotis Kanavos | return _extensions.TryGetValue(name, out version) && long.TryParse(version, out value) |
114 | bfc13ed8 | Panagiotis Kanavos | ? (long?) value |
115 | bfc13ed8 | Panagiotis Kanavos | : null; |
116 | 9c4346c9 | Panagiotis Kanavos | } |
117 | 9c4346c9 | Panagiotis Kanavos | |
118 | 9c4346c9 | Panagiotis Kanavos | private DateTime? GetTimestamp(string name) |
119 | 9c4346c9 | Panagiotis Kanavos | { |
120 | 9c4346c9 | Panagiotis Kanavos | string version; |
121 | 9c4346c9 | Panagiotis Kanavos | DateTime value; |
122 | 9c4346c9 | Panagiotis Kanavos | if (_extensions.TryGetValue(name, out version) && |
123 | 9c4346c9 | Panagiotis Kanavos | DateTime.TryParse(version,CultureInfo.InvariantCulture,DateTimeStyles.AdjustToUniversal, out value)) |
124 | 9c4346c9 | Panagiotis Kanavos | { |
125 | 9c4346c9 | Panagiotis Kanavos | return value; |
126 | 9c4346c9 | Panagiotis Kanavos | } |
127 | 9c4346c9 | Panagiotis Kanavos | return null; |
128 | 9c4346c9 | Panagiotis Kanavos | } |
129 | 9c4346c9 | Panagiotis Kanavos | |
130 | 9c4346c9 | Panagiotis Kanavos | |
131 | 9c4346c9 | Panagiotis Kanavos | public static ObjectInfo Empty = new ObjectInfo |
132 | 9c4346c9 | Panagiotis Kanavos | { |
133 | 9c4346c9 | Panagiotis Kanavos | Name = String.Empty, |
134 | 9c4346c9 | Panagiotis Kanavos | Hash = String.Empty, |
135 | 9c4346c9 | Panagiotis Kanavos | Bytes = 0, |
136 | 9c4346c9 | Panagiotis Kanavos | Content_Type = String.Empty, |
137 | 9c4346c9 | Panagiotis Kanavos | Last_Modified = DateTime.MinValue |
138 | 9c4346c9 | Panagiotis Kanavos | }; |
139 | bfc13ed8 | Panagiotis Kanavos | |
140 | bfc13ed8 | Panagiotis Kanavos | private string _modifiedBy; |
141 | a27aa447 | Panagiotis Kanavos | private DateTime _epoch = new DateTime(1970, 1, 1); |
142 | 3c43ec9b | Panagiotis Kanavos | } |
143 | 3c43ec9b | Panagiotis Kanavos | } |