diff --git a/build/build.proj b/build/build.proj index e721f20dc..71a774586 100644 --- a/build/build.proj +++ b/build/build.proj @@ -44,8 +44,8 @@ - - + + diff --git a/src/.vs/config/applicationhost.config b/src/.vs/config/applicationhost.config new file mode 100644 index 000000000..4b9bf4770 --- /dev/null +++ b/src/.vs/config/applicationhost.config @@ -0,0 +1,1031 @@ + + + + + + + +
+
+
+
+
+
+
+
+ + + +
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ +
+
+ +
+
+
+
+
+
+ +
+
+
+
+
+ +
+
+
+ +
+
+ +
+
+ +
+
+
+ + +
+
+
+
+
+
+ +
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/Samples/FSharpCodeSamples/FSharpCodeSamples.fsproj b/src/Samples/FSharpCodeSamples/FSharpCodeSamples.fsproj index 54dacc5c1..e249d33de 100644 --- a/src/Samples/FSharpCodeSamples/FSharpCodeSamples.fsproj +++ b/src/Samples/FSharpCodeSamples/FSharpCodeSamples.fsproj @@ -82,25 +82,25 @@ --> - + - ..\..\..\packages\Newtonsoft.Json\lib\net35\Newtonsoft.Json.dll + ..\..\..\packages\Newtonsoft.Json\lib\net20\Newtonsoft.Json.dll True True - + - ..\..\..\packages\Newtonsoft.Json\lib\net20\Newtonsoft.Json.dll + ..\..\..\packages\Newtonsoft.Json\lib\net35\Newtonsoft.Json.dll True True - + ..\..\..\packages\Newtonsoft.Json\lib\net40\Newtonsoft.Json.dll @@ -109,7 +109,7 @@ - + ..\..\..\packages\Newtonsoft.Json\lib\net45\Newtonsoft.Json.dll @@ -118,16 +118,16 @@ - + - ..\..\..\packages\Newtonsoft.Json\lib\portable-net45+wp80+win8+wpa81+dnxcore50\Newtonsoft.Json.dll + ..\..\..\packages\Newtonsoft.Json\lib\netcore45\Newtonsoft.Json.dll True True - + ..\..\..\packages\Newtonsoft.Json\lib\portable-net40+sl5+wp80+win8+wpa81\Newtonsoft.Json.dll @@ -136,18 +136,18 @@ - - - + - - ..\..\..\packages\SimpleRESTServices\lib\net35\SimpleRESTServices.dll + + ..\..\..\packages\Newtonsoft.Json\lib\portable-net45+wp80+win8+wpa81+aspnetcore50\Newtonsoft.Json.dll True True - + + + ..\..\..\packages\SimpleRESTServices\lib\net40\SimpleRESTServices.dll diff --git a/src/Samples/FSharpCodeSamples/app.config b/src/Samples/FSharpCodeSamples/app.config index 0ed82eae5..a38c807f2 100644 --- a/src/Samples/FSharpCodeSamples/app.config +++ b/src/Samples/FSharpCodeSamples/app.config @@ -5,6 +5,6 @@ True - + \ No newline at end of file diff --git a/src/corelib/Authentication/AuthenticatedMessageHandler.cs b/src/corelib/Authentication/AuthenticatedMessageHandler.cs index 3d75dc6bd..34ed9a0f0 100644 --- a/src/corelib/Authentication/AuthenticatedMessageHandler.cs +++ b/src/corelib/Authentication/AuthenticatedMessageHandler.cs @@ -29,7 +29,9 @@ protected async override Task SendAsync(HttpRequestMessage try { - return await base.SendAsync(request, cancellationToken).ConfigureAwait(false); + var response = await base.SendAsync(request, cancellationToken).ConfigureAwait(false); + // var contentStr = await response.Content.ReadAsStringAsync(); + return response; } catch (FlurlHttpException ex) { diff --git a/src/corelib/Authentication/ServiceType.cs b/src/corelib/Authentication/ServiceType.cs index 6862a822a..65251dbe8 100644 --- a/src/corelib/Authentication/ServiceType.cs +++ b/src/corelib/Authentication/ServiceType.cs @@ -84,6 +84,11 @@ public override int GetHashCode() /// The Networking service /// public static readonly ServiceType Networking = new ServiceType("network"); + + /// + /// The ObjectStorage service + /// + public static readonly ServiceType ObjectStorage = new ServiceType("object-store"); } /// diff --git a/src/corelib/Extensions/FlurlExtensions.cs b/src/corelib/Extensions/FlurlExtensions.cs index 6fec955fa..5ec625f8f 100644 --- a/src/corelib/Extensions/FlurlExtensions.cs +++ b/src/corelib/Extensions/FlurlExtensions.cs @@ -3,6 +3,7 @@ using System.Linq; using System.Net; using System.Net.Http; +using System.Net.Http.Headers; using System.Threading.Tasks; using Flurl.Http; using OpenStack; @@ -132,5 +133,15 @@ public static async Task SendAsync(this Task + /// Sends the . + /// + /// A task with returns the response + /// + public static async Task ReceiveHeaders(this Task responseTask) + { + return await Task.FromResult(responseTask.Result.Headers); + } } } diff --git a/src/corelib/Flurl/PreparedRequest.cs b/src/corelib/Flurl/PreparedRequest.cs index 1d96b204a..2575e8244 100644 --- a/src/corelib/Flurl/PreparedRequest.cs +++ b/src/corelib/Flurl/PreparedRequest.cs @@ -1,9 +1,19 @@ using System; +using System.Collections; +using System.Collections.Generic; +using System.Linq; using System.Net; using System.Net.Http; +using System.Net.Http.Headers; +using System.Text; using System.Threading; using System.Threading.Tasks; +using Flurl.Http.Configuration; using Flurl.Http.Content; +using net.openstack.Core; +using OpenStack.ObjectStorage.v1.Metadata; +using OpenStack.ObjectStorage.v1.Serialization; +using OpenStack.Serialization; // ReSharper disable once CheckNamespace namespace Flurl.Http @@ -69,6 +79,18 @@ public PreparedRequest(Url url, bool autoDispose) : base(url, autoDispose) /// The optional canellation token which will be used in the request, defaults to None. /// public CancellationToken CancellationToken { get; protected set; } + + /// + /// Apply default timeout to current Request + /// + /// The timeout to apply. + /// + public PreparedRequest SettingTimeout(TimeSpan defaultTimeout) + { + Settings.DefaultTimeout = defaultTimeout; + return this; + } + /// /// Prepares the client to send a DELETE request @@ -79,6 +101,15 @@ public PreparedRequest(Url url, bool autoDispose) : base(url, autoDispose) CancellationToken = cancellationToken; return this; } + /// + /// Prepares the client to send a DELETE request + /// + public PreparedRequest PrepareHead(CancellationToken cancellationToken = default(CancellationToken)) + { + Verb = HttpMethod.Head; + CancellationToken = cancellationToken; + return this; + } /// /// Prepares the client to send a GET request @@ -100,7 +131,7 @@ public PreparedRequest(Url url, bool autoDispose) : base(url, autoDispose) CancellationToken = cancellationToken; return this; } - + /// /// Prepares the client to send a POST request containing json /// @@ -112,6 +143,54 @@ public PreparedRequest(Url url, bool autoDispose) : base(url, autoDispose) return this; } + /// + /// Prepares the client to send a POST request containing data in content Header + /// + /// + /// + /// + public PreparedRequest PreparePostContentHeader(IEnumerable>> formData, CancellationToken cancellationToken = default(CancellationToken)) + { + Verb = HttpMethod.Post; + + Content = new System.Net.Http.StringContent(""); + Content.Headers.Remove("Content-Type"); + + foreach (var pair in formData) + { + System.Net.Http.Headers.HttpHeaders headerColl; + + switch (pair.Key.ToLowerInvariant()) + { + case "cache-control": + headerColl = this.HttpClient.DefaultRequestHeaders; + break; + default: + headerColl = this.Content.Headers; + break; + } + + headerColl.Add(pair.Key, pair.Value); + } + + CancellationToken = cancellationToken; + return this; + } + + /// + /// Prepares the client to send a POST request containing data in content Header + /// + /// + /// + /// + public PreparedRequest PreparePostContentTextPlain(string data, CancellationToken cancellationToken = default(CancellationToken)) + { + Verb = HttpMethod.Post; + Content = new System.Net.Http.StringContent(data); + CancellationToken = cancellationToken; + return this; + } + /// /// Prepares the client to send a PUT request containing json /// @@ -123,6 +202,17 @@ public PreparedRequest(Url url, bool autoDispose) : base(url, autoDispose) return this; } + /// + /// Prepares the client to send a PUT request containing data in stream + /// + public PreparedRequest PreparePutStream(System.IO.Stream dataStream, CancellationToken cancellationToken = default(CancellationToken)) + { + Verb = HttpMethod.Put; + Content = new CapturedStreamContent(dataStream); + CancellationToken = cancellationToken; + return this; + } + /// /// Executes the built request /// diff --git a/src/corelib/ObjectStorage/NamespaceDoc.cs b/src/corelib/ObjectStorage/NamespaceDoc.cs new file mode 100644 index 000000000..d6263aada --- /dev/null +++ b/src/corelib/ObjectStorage/NamespaceDoc.cs @@ -0,0 +1,13 @@ +namespace OpenStack.ObjectStorage +{ + using System.Runtime.CompilerServices; + + /// + /// The namespace defines provider-independent + /// interfaces and implementations for the OpenStack ObjectStorage API. + /// + [CompilerGenerated] + internal class NamespaceDoc + { + } +} diff --git a/src/corelib/ObjectStorage/v1/BulkDeleteResult.cs b/src/corelib/ObjectStorage/v1/BulkDeleteResult.cs new file mode 100644 index 000000000..720494e1d --- /dev/null +++ b/src/corelib/ObjectStorage/v1/BulkDeleteResult.cs @@ -0,0 +1,69 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Newtonsoft.Json; +using OpenStack.ObjectStorage.v1.Serialization; + +namespace OpenStack.ObjectStorage.v1 { + + /// + /// Result of BulkDelete operation. + /// See . + /// + public class BulkDeleteResult { + + /// + /// Items found + /// + [JsonProperty("Number Not Found")] + public int? NumberNotFound { get; set; } + + /// + /// Items deleted + /// + [JsonProperty("Number Deleted")] + public int? NumberDeleted { get; set; } + + /// + /// Response status + /// + [JsonProperty("Response Status")] + [JsonConverter(typeof(HttpStatusCodeConverter))] + public System.Net.HttpStatusCode ResponseStatus { get; set; } + + /// + /// Response body + /// + [JsonProperty("Response Body")] + public string ResponseBody { get; set; } + + /// + /// Errors + /// + [JsonProperty("Errors")] + public ErrorItem[] Errors { get; set; } + + + /// + /// Error item + /// + public class ErrorItem + { + + /// + /// Item fullname + /// + [JsonProperty("Name")] + public string Name { get; set; } + + /// + /// Error status + /// + [JsonProperty("Status")] + public string Status { get; set; } + } + + } +} diff --git a/src/corelib/ObjectStorage/v1/Container.cs b/src/corelib/ObjectStorage/v1/Container.cs new file mode 100644 index 000000000..3b66ddaa2 --- /dev/null +++ b/src/corelib/ObjectStorage/v1/Container.cs @@ -0,0 +1,34 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Newtonsoft.Json; + +namespace OpenStack.ObjectStorage.v1 { + + /// + /// Represents a Container + /// + public class Container { + + /// + /// Container name + /// + [JsonProperty("name")] + public string Name { get; set; } + + /// + /// Count of objects in container + /// + [JsonProperty("count")] + public long Count { get; set; } + + /// + /// Weight of container + /// + [JsonProperty("bytes")] + public long Bytes { get; set; } + + } +} diff --git a/src/corelib/ObjectStorage/v1/ContainerDirectory.cs b/src/corelib/ObjectStorage/v1/ContainerDirectory.cs new file mode 100644 index 000000000..f3af1e3c4 --- /dev/null +++ b/src/corelib/ObjectStorage/v1/ContainerDirectory.cs @@ -0,0 +1,24 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Newtonsoft.Json; + +namespace OpenStack.ObjectStorage.v1 { + + /// + /// Represent an Object of container + /// + public class ContainerDirectory : IContainerItem { + + /// + /// Directory fullname + /// + [JsonProperty("subdir")] + public string FullName { get; set; } + + /// + public ContainerItemType ItemType { get { return ContainerItemType.Directory; } } + } +} diff --git a/src/corelib/ObjectStorage/v1/ContainerItemType.cs b/src/corelib/ObjectStorage/v1/ContainerItemType.cs new file mode 100644 index 000000000..1961d9017 --- /dev/null +++ b/src/corelib/ObjectStorage/v1/ContainerItemType.cs @@ -0,0 +1,25 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace OpenStack.ObjectStorage.v1 { + + /// + /// List of ContainerItem types + /// + public enum ContainerItemType { + + /// + /// ContainerObject, like a file + /// + Object = 1, + + /// + /// ContainerDirectoty, like a folder + /// + Directory = 2 + + } +} diff --git a/src/corelib/ObjectStorage/v1/ContainerObject.cs b/src/corelib/ObjectStorage/v1/ContainerObject.cs new file mode 100644 index 000000000..78bd30ae2 --- /dev/null +++ b/src/corelib/ObjectStorage/v1/ContainerObject.cs @@ -0,0 +1,49 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Newtonsoft.Json; + +namespace OpenStack.ObjectStorage.v1 { + + /// + /// Represent an Object of container + /// + public class ContainerObject : IContainerItem { + + /// + /// Hash of Object + /// + [JsonProperty("hash")] + public string Hash { get; set; } + + /// + /// Date of last update + /// + [JsonProperty("last_modified")] + public DateTime LastModified { get; set; } + + /// + /// Weight of object + /// + [JsonProperty("bytes")] + public long Bytes { get; set; } + + /// + /// Object fullname + /// + [JsonProperty("name")] + public string FullName { get; set; } + + /// + /// Object content type + /// + [JsonProperty("content_type")] + public string ContentType { get; set; } + + /// + public ContainerItemType ItemType { get { return ContainerItemType.Object; } } + + } +} diff --git a/src/corelib/ObjectStorage/v1/ContentObjectFilters/ContentObjectFilterBase.cs b/src/corelib/ObjectStorage/v1/ContentObjectFilters/ContentObjectFilterBase.cs new file mode 100644 index 000000000..70c5bd8ad --- /dev/null +++ b/src/corelib/ObjectStorage/v1/ContentObjectFilters/ContentObjectFilterBase.cs @@ -0,0 +1,18 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace OpenStack.ObjectStorage.v1.ContentObjectFilters { + + /// + /// Base class for ContentObjectFilter classes + /// + public abstract class ContentObjectFilterBase : IContentObjectFilter { + + /// + public abstract IEnumerable> CompileQueryParams(); + + } +} diff --git a/src/corelib/ObjectStorage/v1/ContentObjectFilters/ContentObjectFilterCollection.cs b/src/corelib/ObjectStorage/v1/ContentObjectFilters/ContentObjectFilterCollection.cs new file mode 100644 index 000000000..152512bf5 --- /dev/null +++ b/src/corelib/ObjectStorage/v1/ContentObjectFilters/ContentObjectFilterCollection.cs @@ -0,0 +1,48 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace OpenStack.ObjectStorage.v1.ContentObjectFilters { + + /// + /// Collection of ContentObjectFilter + /// + public class ContentObjectFilterCollection : List { + + /// + /// Create new instance of ContentObjectFilter collection with preloaded items. + /// + public ContentObjectFilterCollection() + { + + } + + /// + /// Create new instance of ContentObjectFilter collection with preloaded items. + /// + /// + public ContentObjectFilterCollection(IEnumerable collection) : base(collection) + { + + } + + + /// + /// Create QueryParams to append to URL + /// + /// + public IEnumerable> CompileQueryParams() + { + foreach (var filter in this) + { + foreach (var compileQueryParam in filter.CompileQueryParams()) + { + yield return compileQueryParam; + } + } + } + + } +} diff --git a/src/corelib/ObjectStorage/v1/ContentObjectFilters/DelimiterContentObjectFilter.cs b/src/corelib/ObjectStorage/v1/ContentObjectFilters/DelimiterContentObjectFilter.cs new file mode 100644 index 000000000..f30ecf43f --- /dev/null +++ b/src/corelib/ObjectStorage/v1/ContentObjectFilters/DelimiterContentObjectFilter.cs @@ -0,0 +1,36 @@ +using System; +using System.Collections.Generic; +using System.Globalization; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace OpenStack.ObjectStorage.v1.ContentObjectFilters { + + /// + /// Define a filter that lock search inside folder when find string in item fullname. + /// When combined with it returns Subfolders. + /// + public class DelimiterContentObjectFilter : ContentObjectFilterBase { + + /// + /// Create new instance of filter and preload properties. + /// + public DelimiterContentObjectFilter() + { + this.Delimiter = "/"; + } + + /// + /// The delimiter string to find in item fullname. + /// + public string Delimiter { get; set; } + + + /// + public override IEnumerable> CompileQueryParams() + { + yield return new KeyValuePair("delimiter", this.Delimiter); + } + } +} diff --git a/src/corelib/ObjectStorage/v1/ContentObjectFilters/IContentObjectFilter.cs b/src/corelib/ObjectStorage/v1/ContentObjectFilters/IContentObjectFilter.cs new file mode 100644 index 000000000..072578115 --- /dev/null +++ b/src/corelib/ObjectStorage/v1/ContentObjectFilters/IContentObjectFilter.cs @@ -0,0 +1,22 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace OpenStack.ObjectStorage.v1.ContentObjectFilters { + + /// + /// Define a filter for Content Object search + /// + public interface IContentObjectFilter + { + + /// + /// Create query parameters to append to URL + /// + /// + IEnumerable> CompileQueryParams(); + + } +} diff --git a/src/corelib/ObjectStorage/v1/ContentObjectFilters/PathContentObjectFilter.cs b/src/corelib/ObjectStorage/v1/ContentObjectFilters/PathContentObjectFilter.cs new file mode 100644 index 000000000..eaf7fce27 --- /dev/null +++ b/src/corelib/ObjectStorage/v1/ContentObjectFilters/PathContentObjectFilter.cs @@ -0,0 +1,27 @@ +using System; +using System.Collections.Generic; +using System.Globalization; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace OpenStack.ObjectStorage.v1.ContentObjectFilters { + + /// + /// Define a filter to obtain items in specified container path. + /// + public class PathContentObjectFilter : ContentObjectFilterBase { + + /// + /// The path of container. + /// + public string Path { get; set; } + + + /// + public override IEnumerable> CompileQueryParams() + { + yield return new KeyValuePair("path", this.Path); + } + } +} diff --git a/src/corelib/ObjectStorage/v1/ContentObjectFilters/SearchPrefixContentObjectFilter.cs b/src/corelib/ObjectStorage/v1/ContentObjectFilters/SearchPrefixContentObjectFilter.cs new file mode 100644 index 000000000..e5ba2bdeb --- /dev/null +++ b/src/corelib/ObjectStorage/v1/ContentObjectFilters/SearchPrefixContentObjectFilter.cs @@ -0,0 +1,28 @@ +using System; +using System.Collections.Generic; +using System.Globalization; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace OpenStack.ObjectStorage.v1.ContentObjectFilters { + + /// + /// Define a filter to obtain items where fullname starts with prefix. + /// Alert: do not work when combined with . + /// + public class SearchPrefixContentObjectFilter : ContentObjectFilterBase { + + /// + /// The prefix of fullname items that will be return. + /// + public string PathPrefix { get; set; } + + + /// + public override IEnumerable> CompileQueryParams() + { + yield return new KeyValuePair("prefix", this.PathPrefix); + } + } +} diff --git a/src/corelib/ObjectStorage/v1/ContentObjectFilters/SearchRangeContentObjectFilter.cs b/src/corelib/ObjectStorage/v1/ContentObjectFilters/SearchRangeContentObjectFilter.cs new file mode 100644 index 000000000..792cd8fc9 --- /dev/null +++ b/src/corelib/ObjectStorage/v1/ContentObjectFilters/SearchRangeContentObjectFilter.cs @@ -0,0 +1,43 @@ +using System; +using System.Collections.Generic; +using System.Globalization; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace OpenStack.ObjectStorage.v1.ContentObjectFilters { + + /// + /// Define a filter to obtain items that are inside a specified range. + /// Items returned will be between and . + /// + public class SearchRangeContentObjectFilter : ContentObjectFilterBase { + + /// + /// The fullpath item to start search. If Null is considered as "not defined". + /// Note: selected item are fullpath greater than . + /// + public string StartMarker { get; set; } + + /// + /// The fullpath item to end search. If Null is considered as "not defined". + /// Note: selected item are fullpath lower than . + /// + public string EndMarker { get; set; } + + + /// + public override IEnumerable> CompileQueryParams() + { + if (this.StartMarker != null) + { + yield return new KeyValuePair("marker", this.StartMarker); + } + + if (this.EndMarker != null) + { + yield return new KeyValuePair("end_marker", this.EndMarker); + } + } + } +} diff --git a/src/corelib/ObjectStorage/v1/ContentObjectFilters/TakeContentObjectFilter.cs b/src/corelib/ObjectStorage/v1/ContentObjectFilters/TakeContentObjectFilter.cs new file mode 100644 index 000000000..3790f3b32 --- /dev/null +++ b/src/corelib/ObjectStorage/v1/ContentObjectFilters/TakeContentObjectFilter.cs @@ -0,0 +1,27 @@ +using System; +using System.Collections.Generic; +using System.Globalization; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace OpenStack.ObjectStorage.v1.ContentObjectFilters { + + /// + /// Define a filter to obtain first # items. + /// + public class TakeContentObjectFilter : ContentObjectFilterBase { + + /// + /// The limit of items to return. + /// + public int TakeLimit { get; set; } + + + /// + public override IEnumerable> CompileQueryParams() + { + yield return new KeyValuePair("limit", this.TakeLimit.ToString("0", CultureInfo.InvariantCulture)); + } + } +} diff --git a/src/corelib/ObjectStorage/v1/IContainerItem.cs b/src/corelib/ObjectStorage/v1/IContainerItem.cs new file mode 100644 index 000000000..d84e3d17b --- /dev/null +++ b/src/corelib/ObjectStorage/v1/IContainerItem.cs @@ -0,0 +1,28 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Newtonsoft.Json; +using OpenStack.ObjectStorage.v1.Serialization; + +namespace OpenStack.ObjectStorage.v1 { + + /// + /// Represents a item of container. + /// + [JsonConverter(typeof(ContainerItemConverter))] + public interface IContainerItem { + + /// + /// Fullname of item + /// + string FullName { get; set; } + + /// + /// Indicates the type of item + /// + ContainerItemType ItemType { get; } + + } +} diff --git a/src/corelib/ObjectStorage/v1/Metadata/ContainerMetadata/AccessControlAllowOriginContainerMetadata.cs b/src/corelib/ObjectStorage/v1/Metadata/ContainerMetadata/AccessControlAllowOriginContainerMetadata.cs new file mode 100644 index 000000000..c1a00ed13 --- /dev/null +++ b/src/corelib/ObjectStorage/v1/Metadata/ContainerMetadata/AccessControlAllowOriginContainerMetadata.cs @@ -0,0 +1,34 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Newtonsoft.Json.Serialization; + +namespace OpenStack.ObjectStorage.v1.Metadata.ContainerMetadata { + + /// + /// The `Access-Control-Allow-Origin` header metadata. + /// + public class AccessControlAllowOriginContainerMetadata : MetadataBase, IContainerMetadata + { + + /// + /// Create new instance + /// + public AccessControlAllowOriginContainerMetadata() : base("X-Container-Meta-Access-Control-Allow-Origin", true) + { + + } + + /// + /// Get or set list of allowed origins. Example: [ "http://web.com", "https://web.com" ] + /// + public string[] Origins + { + get { return MetadataConverter.ParseStringMultiValue(this.MetadataValue); } + set { this.MetadataValue = MetadataConverter.SerializeStringValue(value); } + } + + } +} diff --git a/src/corelib/ObjectStorage/v1/Metadata/ContainerMetadata/AccessControlMaxAgeContainerMetadata.cs b/src/corelib/ObjectStorage/v1/Metadata/ContainerMetadata/AccessControlMaxAgeContainerMetadata.cs new file mode 100644 index 000000000..2bc884da9 --- /dev/null +++ b/src/corelib/ObjectStorage/v1/Metadata/ContainerMetadata/AccessControlMaxAgeContainerMetadata.cs @@ -0,0 +1,32 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace OpenStack.ObjectStorage.v1.Metadata.ContainerMetadata { + + /// + /// The `Access-Control-Max-Age` header metadata. + /// + public class AccessControlMaxAgeContainerMetadata : MetadataBase, IContainerMetadata { + + /// + /// Create new instance + /// + public AccessControlMaxAgeContainerMetadata() : base("X-Container-Meta-Access-Control-Max-Age", false) + { + + } + + /// + /// Get or set the max age of container objects, in seconds. + /// + public long MaxAgeSeconds + { + get { return MetadataConverter.ParseLongSingleValue(this.MetadataValue); } + set { this.MetadataValue = MetadataConverter.SerializeLongValue(value); } + } + + } +} diff --git a/src/corelib/ObjectStorage/v1/Metadata/ContainerMetadata/IContainerMetadata.cs b/src/corelib/ObjectStorage/v1/Metadata/ContainerMetadata/IContainerMetadata.cs new file mode 100644 index 000000000..6455a8584 --- /dev/null +++ b/src/corelib/ObjectStorage/v1/Metadata/ContainerMetadata/IContainerMetadata.cs @@ -0,0 +1,10 @@ +namespace OpenStack.ObjectStorage.v1.Metadata.ContainerMetadata { + + /// + /// Represents a Container metadata + /// + public interface IContainerMetadata : IMetadata { + + } + +} diff --git a/src/corelib/ObjectStorage/v1/Metadata/ContainerObjectMetadata/CacheControlContainerObjectMetadata.cs b/src/corelib/ObjectStorage/v1/Metadata/ContainerObjectMetadata/CacheControlContainerObjectMetadata.cs new file mode 100644 index 000000000..4132b2ca4 --- /dev/null +++ b/src/corelib/ObjectStorage/v1/Metadata/ContainerObjectMetadata/CacheControlContainerObjectMetadata.cs @@ -0,0 +1,169 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Linq; +using System.Text; +using System.Text.RegularExpressions; +using System.Threading.Tasks; +using Newtonsoft.Json.Serialization; + +namespace OpenStack.ObjectStorage.v1.Metadata.ContainerObjectMetadata { + + /// + /// The `Cache-Control` header metadata. + /// + public class CacheControlContainerObjectMetadata : MetadataBase, IContainerObjectMetadata + { + + /// + /// Create new instance + /// + public CacheControlContainerObjectMetadata() : base("Cache-Control", false) + { + } + + /// + /// Get or set the Cacheability vale + /// + public CacheabilityEnum Cacheability + { + get + { + var metaValue = new CacheControlValue(this.MetadataValue); + return metaValue.Cacheability; + } + set + { + var metaValue = new CacheControlValue(this.MetadataValue); + metaValue.Cacheability = value; + this.MetadataValue = metaValue.ToMetadata(); + } + } + + /// + /// Get or set the max age of cached item + /// + public TimeSpan MaxAge + { + get + { + var metaValue = new CacheControlValue(this.MetadataValue); + return metaValue.MaxAge; + } + set + { + var metaValue = new CacheControlValue(this.MetadataValue); + metaValue.MaxAge = value; + this.MetadataValue = metaValue.ToMetadata(); + } + } + + private static bool tryGetCacheability(string metadataPart, out CacheabilityEnum value) + { + var part = metadataPart.Trim(); + + var enumValues = Enum.GetValues(typeof(CacheabilityEnum)).Cast(); + foreach (var enumValue in enumValues) + { + var enumValueAttr = MetadataEnumValueAttribute.GetAttribute(enumValue); + if (enumValueAttr.MetadataValue.Equals(part, StringComparison.InvariantCultureIgnoreCase)) + { + value = enumValue; + return true; + } + } + + value = CacheabilityEnum.NoCache; + return false; + } + + private static bool tryGetMaxAge(string metadataPart, out TimeSpan value) + { + var re = new Regex(@"\s*max-age=(?