コード例 #1
0
 public ServiceFactory(IHttpAddress baseAddress, IHttpFacade httpFacade, IContentSerializer contentSerializer, HttpHeaders baseHeaders)
 {
     this.baseAddress = baseAddress;
     this.httpFacade = httpFacade;
     this.contentSerializer = contentSerializer;
     this.baseHeaders = baseHeaders;
 }
コード例 #2
0
ファイル: FilesApi.cs プロジェクト: gong0704/.net-sdk
 public FilesApi(IHttpAddress baseAddress, IHttpFacade httpFacade, IContentSerializer contentSerializer, IHttpHeaders baseHeaders, string serviceName)
 {
     this.baseAddress = baseAddress.WithResource(serviceName);
     this.httpFacade = httpFacade;
     this.contentSerializer = contentSerializer;
     this.baseHeaders = baseHeaders;
 }
コード例 #3
0
ファイル: UserApi.cs プロジェクト: gong0704/.net-sdk
 public UserApi(IHttpAddress baseAddress, IHttpFacade httpFacade, IContentSerializer contentSerializer, HttpHeaders baseHeaders)
 {
     this.baseAddress = baseAddress.WithResource("user");
     this.httpFacade = httpFacade;
     this.contentSerializer = contentSerializer;
     this.baseHeaders = baseHeaders;
 }
コード例 #4
0
ファイル: UserApi.cs プロジェクト: danielsteinkogler/.net-sdk
 public UserApi(
     IHttpAddress baseAddress, 
     IHttpFacade httpFacade, 
     IContentSerializer contentSerializer, 
     HttpHeaders baseHeaders)
     : base(baseAddress, httpFacade, contentSerializer, baseHeaders, "user")
 {
 }
コード例 #5
0
 public SystemApi(
     IHttpAddress baseAddress, 
     IHttpFacade httpFacade, 
     IContentSerializer contentSerializer, 
     HttpHeaders baseHeaders)
     : base(baseAddress, httpFacade, contentSerializer, baseHeaders, "system")
 {
 }
コード例 #6
0
 public EmailApi(
     IHttpAddress baseAddress, 
     IHttpFacade httpFacade, 
     IContentSerializer contentSerializer, 
     HttpHeaders baseHeaders, 
     string serviceName)
     : base(baseAddress, httpFacade, contentSerializer, baseHeaders, serviceName)
 {
 }
コード例 #7
0
ファイル: SystemApi.Get.cs プロジェクト: lomharshan/.net-sdk
        public async Task <EnvironmentResponse> GetEnvironmentAsync()
        {
            IHttpAddress address = baseAddress.WithResource("environment");
            IHttpRequest request = new HttpRequest(HttpMethod.Get, address.Build(), baseHeaders);

            IHttpResponse response = await httpFacade.RequestAsync(request);

            HttpUtils.ThrowOnBadStatus(response, contentSerializer);

            return(contentSerializer.Deserialize <EnvironmentResponse>(response.Body));
        }
コード例 #8
0
        public void ShouldChangeBaseAddress()
        {
            // Arrange
            IHttpAddress address = CreateTestHttpAddress();

            // Act
            address = address.WithBaseAddress("https://pinebit.ddns.net");

            // Assert
            address.Build().ShouldBe("https://pinebit.ddns.net/rest/user/session?one=1&two=true");
        }
コード例 #9
0
        public static IHttpAddress WithSqlQuery(this IHttpAddress httpAddress, SqlQuery query)
        {
            if (query == null)
            {
                throw new ArgumentNullException("query");
            }

            if (query.ids != null)
            {
                httpAddress = httpAddress.WithParameter("ids", query.ids);
            }

            if (query.filter != null)
            {
                httpAddress = httpAddress.WithParameter("filter", query.filter);
            }

            if (query.order != null)
            {
                httpAddress = httpAddress.WithParameter("order", query.order);
            }

            if (query.offset.HasValue)
            {
                httpAddress = httpAddress.WithParameter("offset", query.offset.Value);
            }

            if (query.limit.HasValue)
            {
                httpAddress = httpAddress.WithParameter("limit", query.limit.Value);
            }

            if (query.fields != null)
            {
                httpAddress = httpAddress.WithParameter("fields", query.fields);
            }

            if (query.related != null)
            {
                httpAddress = httpAddress.WithParameter("related", query.related);
            }

            if ([email protected])
            {
                httpAddress = httpAddress.WithParameter("continue", query.@continue);
            }

            if (query.rollback.HasValue)
            {
                httpAddress = httpAddress.WithParameter("rollback", query.rollback);
            }

            return(httpAddress);
        }
コード例 #10
0
        public void ShouldAddParameters()
        {
            // Arrange
            IHttpAddress address = CreateTestHttpAddress();

            // Act
            address = address.WithParameter("new", "value");

            // Assert
            address.Build().ShouldBe("http://base_address/rest/user/session?one=1&two=true&new=value");
        }
コード例 #11
0
        public void ShouldAddResources()
        {
            // Arrange
            IHttpAddress address = CreateTestHttpAddress();

            // Act
            address = address.WithResource("add");

            // Assert
            address.Build().ShouldBe("http://base_address/rest/user/session/add?one=1&two=true");
        }
コード例 #12
0
        public void ShouldChangeVersion()
        {
            // Arrange
            IHttpAddress address = CreateTestHttpAddress();

            // Act
            address = address.WithVersion(RestApiVersion.V2);

            // Assert
            address.Build().ShouldBe("http://base_address/api/v2/user/session?one=1&two=true");
        }
コード例 #13
0
 public CustomSettingsApi(
     IHttpAddress baseAddress,
     IHttpFacade httpFacade,
     IContentSerializer contentSerializer,
     IHttpHeaders baseHeaders,
     string serviceName)
 {
     this.baseAddress       = baseAddress.WithResource(serviceName);
     this.httpFacade        = httpFacade;
     this.contentSerializer = contentSerializer;
     this.baseHeaders       = baseHeaders;
 }
コード例 #14
0
ファイル: SystemApi.cs プロジェクト: lomharshan/.net-sdk
        public async Task <ConfigResponse> SetConfigAsync(ConfigRequest config)
        {
            IHttpAddress address = baseAddress.WithResource("config");
            string       body    = contentSerializer.Serialize(config);
            IHttpRequest request = new HttpRequest(HttpMethod.Get, address.Build(), baseHeaders, body);

            IHttpResponse response = await httpFacade.RequestAsync(request);

            HttpUtils.ThrowOnBadStatus(response, contentSerializer);

            return(contentSerializer.Deserialize <ConfigResponse>(response.Body));
        }
コード例 #15
0
        public async Task <IEnumerable <ContainerInfo> > GetAccessComponentsAsync()
        {
            IHttpAddress address = baseAddress.WithParameter("include_properties", true);
            IHttpRequest request = new HttpRequest(HttpMethod.Get, address.Build(), baseHeaders);

            IHttpResponse response = await httpFacade.RequestAsync(request);

            HttpUtils.ThrowOnBadStatus(response, contentSerializer);

            var data = new { container = new List <ContainerInfo>() };

            return(contentSerializer.Deserialize(response.Body, data).container);
        }
コード例 #16
0
ファイル: SystemApi.Get.cs プロジェクト: lomharshan/.net-sdk
        public async Task <IEnumerable <string> > GetConstantsAsync()
        {
            IHttpAddress address = baseAddress.WithResource("constant");
            IHttpRequest request = new HttpRequest(HttpMethod.Get, address.Build(), baseHeaders);

            IHttpResponse response = await httpFacade.RequestAsync(request);

            HttpUtils.ThrowOnBadStatus(response, contentSerializer);

            Dictionary <string, object> types = contentSerializer.Deserialize <Dictionary <string, object> >(response.Body);

            return(types.Keys);
        }
コード例 #17
0
ファイル: SystemApi.cs プロジェクト: lomharshan/.net-sdk
        public async Task <byte[]> DownloadApplicationSdkAsync(int applicationId)
        {
            IHttpAddress address = baseAddress
                                   .WithResource("app", applicationId.ToString(CultureInfo.InvariantCulture))
                                   .WithParameter("sdk", true);

            IHttpRequest request = new HttpRequest(HttpMethod.Get, address.Build(), baseHeaders);

            IHttpResponse response = await httpFacade.RequestAsync(request);

            HttpUtils.ThrowOnBadStatus(response, contentSerializer);

            return(response.RawBody);
        }
コード例 #18
0
        public void ShouldNotModifyOriginal()
        {
            // Arrange
            IHttpAddress address = CreateTestHttpAddress();
            string       result  = address.Build();

            // Act
            address
            .WithVersion(RestApiVersion.V2).WithResource("system", "config")
            .WithBaseAddress("https://pinebit.ddns.net")
            .WithParameter("new", "value");

            // Assert
            address.Build().ShouldBe(result);
        }
コード例 #19
0
        /// <summary>
        /// Builds IHttpAddress from given resourceParts and query.
        /// </summary>
        /// <param name="resourceParts">Array of resource parts. Usually consists of resource and resource identifier.</param>
        /// <param name="query">Query parameters.</param>
        internal IHttpAddress BuildAddress(string[] resourceParts, SqlQuery query)
        {
            IHttpAddress address = BaseAddress;

            if (resourceParts != null)
            {
                address = address.WithResource(resourceParts);
            }

            if (query != null)
            {
                address = address.WithSqlQuery(query);
            }
            return(address);
        }
コード例 #20
0
        public async Task <byte[]> GetBinaryFileAsync(string filepath)
        {
            if (filepath == null)
            {
                throw new ArgumentNullException("filepath");
            }

            IHttpAddress  address  = base.BaseAddress.WithResource(filepath);
            IHttpRequest  request  = new HttpRequest(HttpMethod.Get, address.Build(), base.BaseHeaders.Include(HttpHeaders.AcceptHeader, OctetStream));
            IHttpResponse response = await base.HttpFacade.RequestAsync(request);

            HttpUtils.ThrowOnBadStatus(response, base.ContentSerializer);

            return(response.RawBody);
        }
コード例 #21
0
        public async Task <IEnumerable <ScriptResponse> > GetScriptsAsync(bool includeUserScripts)
        {
            IHttpAddress address = baseAddress.WithResource("script")
                                   .WithParameter("include_script_body", true)
                                   .WithParameter("include_user_scripts", includeUserScripts);

            IHttpRequest  request  = new HttpRequest(HttpMethod.Get, address.Build(), baseHeaders);
            IHttpResponse response = await httpFacade.RequestAsync(request);

            HttpUtils.ThrowOnBadStatus(response, contentSerializer);

            var scripts = new { resource = new List <ScriptResponse>() };

            return(contentSerializer.Deserialize(response.Body, scripts).resource);
        }
コード例 #22
0
        public async Task DeleteContainerAsync(string container, bool force = false)
        {
            if (container == null)
            {
                throw new ArgumentNullException("container");
            }

            IHttpAddress address = baseAddress.WithResource(container, string.Empty)
                                   .WithParameter("force", force);

            IHttpRequest request = new HttpRequest(HttpMethod.Delete, address.Build(), baseHeaders);

            IHttpResponse response = await httpFacade.RequestAsync(request);

            HttpUtils.ThrowOnBadStatus(response, contentSerializer);
        }
コード例 #23
0
        public async Task UnregisterEventsAsync(params EventRequest[] requests)
        {
            if (requests == null || requests.Length < 1)
            {
                throw new ArgumentException("At least one parameter must be specificed", "requests");
            }

            IHttpAddress address = baseAddress.WithResource("event");
            var          records = new { record = new List <EventRequest>(requests) };
            string       body    = contentSerializer.Serialize(records);
            IHttpRequest request = new HttpRequest(HttpMethod.Delete, address.Build(), baseHeaders, body);

            IHttpResponse response = await httpFacade.RequestAsync(request);

            HttpUtils.ThrowOnBadStatus(response, contentSerializer);
        }
コード例 #24
0
        public async Task DeleteScriptAsync(string scriptId)
        {
            if (scriptId == null)
            {
                throw new ArgumentNullException("scriptId");
            }

            IHttpAddress address = baseAddress
                                   .WithResource("script", scriptId)
                                   .WithParameter("is_user_script", true);

            IHttpRequest  request  = new HttpRequest(HttpMethod.Delete, address.Build(), baseHeaders);
            IHttpResponse response = await httpFacade.RequestAsync(request);

            HttpUtils.ThrowOnBadStatus(response, contentSerializer);
        }
コード例 #25
0
        /// <summary>
        /// Builds IHttpRequest from given arguments.
        /// </summary>
        /// <param name="method">HttpMethod used in request.</param>
        /// <param name="body">Body used in request.</param>
        /// <param name="resourceParts">Array of resource parts. Usually consists of resource and resource identifier.</param>
        /// <param name="query">Query parameters.</param>
        internal IHttpRequest BuildRequest(HttpMethod method, string body, string[] resourceParts, SqlQuery query)
        {
            IHttpAddress address = BuildAddress(resourceParts, query);

            IHttpRequest request;

            if (body == null)
            {
                request = new HttpRequest(method, address.Build(), BaseHeaders);
            }
            else
            {
                request = new HttpRequest(method, address.Build(), BaseHeaders, body);
            }
            return(request);
        }
コード例 #26
0
        public async Task <byte[]> DownloadContainerAsync(string container)
        {
            if (container == null)
            {
                throw new ArgumentNullException("container");
            }

            IHttpAddress address = baseAddress.WithResource(container, string.Empty)
                                   .WithParameter("zip", true);
            IHttpRequest request = new HttpRequest(HttpMethod.Get, address.Build(), baseHeaders);

            IHttpResponse response = await httpFacade.RequestAsync(request);

            HttpUtils.ThrowOnBadStatus(response, contentSerializer);

            return(response.RawBody);
        }
コード例 #27
0
ファイル: SystemApi.cs プロジェクト: lomharshan/.net-sdk
        public async Task <byte[]> DownloadApplicationPackageAsync(int applicationId, bool includeFiles, bool includeServices, bool includeSchema)
        {
            IHttpAddress address = baseAddress
                                   .WithResource("app", applicationId.ToString(CultureInfo.InvariantCulture))
                                   .WithParameter("pkg", true)
                                   .WithParameter("include_files", includeFiles)
                                   .WithParameter("include_services", includeServices)
                                   .WithParameter("include_schema", includeSchema);

            IHttpRequest request = new HttpRequest(HttpMethod.Get, address.Build(), baseHeaders);

            IHttpResponse response = await httpFacade.RequestAsync(request);

            HttpUtils.ThrowOnBadStatus(response, contentSerializer);

            return(response.RawBody);
        }
コード例 #28
0
        public Task <FileResponse> ReplaceFileContentsAsync(string filepath, string contents)
        {
            if (filepath == null)
            {
                throw new ArgumentNullException("filepath");
            }

            if (contents == null)
            {
                throw new ArgumentNullException("contents");
            }

            IHttpAddress address = base.BaseAddress.WithResource(filepath);
            IHttpRequest request = new HttpRequest(HttpMethod.Put, address.Build(), base.BaseHeaders.Exclude(HttpHeaders.ContentTypeHeader), contents);

            return(base.ExecuteRequest <FileResponse>(request));
        }
コード例 #29
0
        public async Task <IEnumerable <EventCacheResponse> > GetEventsAsync(bool allEvents)
        {
            IHttpAddress address = baseAddress.WithResource("event").WithParameter("as_cached", false);

            if (allEvents)
            {
                address = address.WithParameter("all_events", true);
            }

            IHttpRequest  request  = new HttpRequest(HttpMethod.Get, address.Build(), baseHeaders);
            IHttpResponse response = await httpFacade.RequestAsync(request);

            HttpUtils.ThrowOnBadStatus(response, contentSerializer);

            var records = new { record = new List <EventCacheResponse>() };

            return(contentSerializer.Deserialize(response.Body, records).record);
        }
コード例 #30
0
        public async Task <ContainerResponse> GetContainerAsync(string container, ListingFlags flags)
        {
            if (container == null)
            {
                throw new ArgumentNullException("container");
            }

            IHttpAddress address = baseAddress.WithResource(container, string.Empty);

            address = AddListingParameters(address, flags);
            IHttpRequest request = new HttpRequest(HttpMethod.Get, address.Build(), baseHeaders);

            IHttpResponse response = await httpFacade.RequestAsync(request);

            HttpUtils.ThrowOnBadStatus(response, contentSerializer);

            return(contentSerializer.Deserialize <ContainerResponse>(response.Body));
        }
コード例 #31
0
        private async Task <IEnumerable <string> > GetNamesOnlyAsync(string resource, bool refresh)
        {
            IHttpAddress address = baseAddress.WithResource(resource).WithParameter("names_only", true);

            if (refresh)
            {
                address = address.WithParameter("refresh", true);
            }

            IHttpRequest request = new HttpRequest(HttpMethod.Get, address.Build(), baseHeaders);

            IHttpResponse response = await httpFacade.RequestAsync(request);

            HttpUtils.ThrowOnBadStatus(response, contentSerializer);

            var result = new { resource = new List <string>() };

            return(contentSerializer.Deserialize(response.Body, result).resource);
        }
コード例 #32
0
        private async Task CreateOrUpdateTableAsync(HttpMethod httpMethod, TableSchema tableSchema)
        {
            if (tableSchema == null)
            {
                throw new ArgumentNullException("tableSchema");
            }

            IHttpAddress address = baseAddress.WithResource("_schema");

            var tableSchemas = new { table = new List <TableSchema> {
                                         tableSchema
                                     } };
            string       body    = contentSerializer.Serialize(tableSchemas);
            IHttpRequest request = new HttpRequest(httpMethod, address.Build(), baseHeaders, body);

            IHttpResponse response = await httpFacade.RequestAsync(request);

            HttpUtils.ThrowOnBadStatus(response, contentSerializer);
        }
コード例 #33
0
        public async Task <bool> DeleteTableAsync(string tableName)
        {
            if (tableName == null)
            {
                throw new ArgumentNullException("tableName");
            }

            IHttpAddress address = baseAddress.WithResource("_schema", tableName);
            IHttpRequest request = new HttpRequest(HttpMethod.Delete, address.Build(), baseHeaders);

            IHttpResponse response = await httpFacade.RequestAsync(request);

            HttpUtils.ThrowOnBadStatus(response, contentSerializer);

            var success = new { success = false };

            success = contentSerializer.Deserialize(response.Body, success);

            return(success.success);
        }
コード例 #34
0
        private async Task DeleteRecordsAsync(string resource, bool setDeleteStorage, params int[] ids)
        {
            if (ids == null || ids.Length < 1)
            {
                throw new ArgumentException("At least one application ID must be specificed", "ids");
            }

            string       list    = string.Join(",", ids);
            IHttpAddress address = baseAddress.WithResource(resource).WithParameter("ids", list);

            if (setDeleteStorage)
            {
                address = address.WithParameter("delete_storage", true);
            }

            IHttpRequest request = new HttpRequest(HttpMethod.Delete, address.Build(), baseHeaders);

            IHttpResponse response = await httpFacade.RequestAsync(request);

            HttpUtils.ThrowOnBadStatus(response, contentSerializer);
        }
コード例 #35
0
        public async Task <string> GetTextFileAsync(string container, string filepath)
        {
            if (container == null)
            {
                throw new ArgumentNullException("container");
            }

            if (filepath == null)
            {
                throw new ArgumentNullException("filepath");
            }

            IHttpAddress address = baseAddress.WithResource(container, filepath);
            IHttpRequest request = new HttpRequest(HttpMethod.Get, address.Build(), baseHeaders);

            IHttpResponse response = await httpFacade.RequestAsync(request);

            HttpUtils.ThrowOnBadStatus(response, contentSerializer);

            return(response.Body);
        }
コード例 #36
0
        public async Task DeleteRecordsAsync <TRecord>(string tableName, IEnumerable <TRecord> records)
        {
            if (tableName == null)
            {
                throw new ArgumentNullException("tableName");
            }

            if (records == null)
            {
                throw new ArgumentNullException("records");
            }

            IHttpAddress address = baseAddress.WithResource(tableName);

            var          recordsRequest = new { record = records.ToList() };
            string       data           = contentSerializer.Serialize(recordsRequest);
            IHttpRequest request        = new HttpRequest(HttpMethod.Delete, address.Build(), baseHeaders, data);

            IHttpResponse response = await httpFacade.RequestAsync(request);

            HttpUtils.ThrowOnBadStatus(response, contentSerializer);
        }
コード例 #37
0
ファイル: FilesApi.cs プロジェクト: gong0704/.net-sdk
        private static IHttpAddress AddListingParameters(IHttpAddress source, ListingFlags mode)
        {
            int modeInt = (int)mode;

            if ((modeInt & (int)ListingFlags.IncludeFiles) != 0)
            {
                source = source.WithParameter("include_files", true);
            }

            if ((modeInt & (int)ListingFlags.IncludeFolders) != 0)
            {
                source = source.WithParameter("include_folders", true);
            }

            if ((modeInt & (int)ListingFlags.IncludeProperties) != 0)
            {
                source = source.WithParameter("include_properties", true);
            }

            if ((modeInt & (int)ListingFlags.IncludeSubFolders) != 0)
            {
                source = source.WithParameter("full_tree", true);
            }

            return source;
        }