• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C# BoxRequest类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C#中BoxRequest的典型用法代码示例。如果您正苦于以下问题:C# BoxRequest类的具体用法?C# BoxRequest怎么用?C# BoxRequest使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



BoxRequest类属于命名空间,在下文中一共展示了BoxRequest类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。

示例1: QueueTask_MultipleThreads_OrderedResponse

        public async Task QueueTask_MultipleThreads_OrderedResponse()
        {
            /*** Arrange ***/
            int numTasks = 1000;

            int count = 0;

            // Increments the access token each time a call is made to the API
            _handler.Setup(h => h.ExecuteAsync<OAuthSession>(It.IsAny<IBoxRequest>()))
                .Returns(() => Task.FromResult<IBoxResponse<OAuthSession>>(new BoxResponse<OAuthSession>()
                {
                    Status = ResponseStatus.Success,
                    ContentString = "{\"access_token\": \"" + count + "\",\"expires_in\": 3600,\"token_type\": \"bearer\",\"refresh_token\": \"J7rxTiWOHMoSC1isKZKBZWizoRXjkQzig5C6jFgCVJ9bUnsUfGMinKBDLZWP9BgR\"}"
                })).Callback(() => System.Threading.Interlocked.Increment(ref count));

            /*** Act ***/
            IBoxRequest request = new BoxRequest(new Uri("http://box.com"), "folders");

            List<Task<IBoxResponse<OAuthSession>>> tasks = new List<Task<IBoxResponse<OAuthSession>>>();
            for (int i = 0; i < numTasks; i++)
                tasks.Add(_service.EnqueueAsync<OAuthSession>(request));

            await Task.WhenAll(tasks);

            /*** Assert ***/
            for (int i = 0; i < numTasks; i++)
            {
                OAuthSession session = _converter.Parse<OAuthSession>(tasks[i].Result.ContentString);
                Assert.AreEqual(session.AccessToken, i.ToString());
            }
        }
开发者ID:JeremyButts,项目名称:box-windows-sdk-v2,代码行数:31,代码来源:BoxServiceTest.cs


示例2: SearchAsync

        /// <summary>
        /// Returns a collection of search results that match the keyword, if there are are no matching search results
        /// an empty collection will be returned
        /// </summary>
        /// <param name="keyword"></param>
        /// <param name="limit"></param>
        /// <param name="offset"></param>
        /// <param name="extraParameters">additional search parameters, see https://developers.box.com/docs/#search-searching-for-content </param>
        /// <returns></returns>
        public async Task<BoxCollection<BoxItem>> SearchAsync(string keyword, int limit, int offset = 0, Dictionary<string,string> extraParameters = null)
        {
            keyword.ThrowIfNullOrWhiteSpace("keyword");

            BoxRequest request = new BoxRequest(_config.SearchEndpointUri)
                .Param("query", keyword)
                .Param("limit", limit.ToString())
                .Param("offset", offset.ToString());

            if (extraParameters != null)
            {
                if (extraParameters.ContainsKey("query"))
                {
                    throw new ArgumentException("ExtraParamters can not contain query paramter","extraParamters");
                }

                foreach (string key in extraParameters.Keys)
                {
                    request.Param(key, extraParameters[key]);
                }
            }

            IBoxResponse<BoxCollection<BoxItem>> response = await ToResponseAsync<BoxCollection<BoxItem>>(request).ConfigureAwait(false);
                    
            return response.ResponseObject;
        }
开发者ID:jaykay-design,项目名称:box-windows-sdk-v2,代码行数:35,代码来源:BoxSearchManager.cs


示例3: AuthenticateAsync

        public async Task<OAuthSession> AuthenticateAsync(string authCode)
        {
            if (string.IsNullOrWhiteSpace(authCode))
                throw new ArgumentException("Auth code cannot be null or empty", "authCode");

            BoxRequest boxRequest = new BoxRequest(_config.BoxApiHostUri, Constants.AuthTokenEndpointString)
                                            .Method(RequestMethod.Post)
                                            .Payload(Constants.RequestParameters.GrantType, Constants.RequestParameters.AuthorizationCode)
                                            .Payload(Constants.RequestParameters.Code, authCode)
                                            .Payload(Constants.RequestParameters.ClientId, _config.ClientId)
                                            .Payload(Constants.RequestParameters.ClientSecret, _config.ClientSecret)
                                            .Payload(Constants.RequestParameters.BoxDeviceId, _config.DeviceId)
                                            .Payload(Constants.RequestParameters.BoxDeviceName, _config.DeviceName);

            IBoxResponse<OAuthSession> boxResponse = await _service.ToResponseAsync<OAuthSession>(boxRequest).ConfigureAwait(false);
            boxResponse.ParseResults(_converter);

            using (await _mutex.LockAsync().ConfigureAwait(false))
            {
                Session = boxResponse.ResponseObject;
                
                var handler = SessionAuthenticated;
                if (handler != null)
                {
                    handler(this, new SessionAuthenticatedEventArgs(Session));
                }
            }

            return boxResponse.ResponseObject;
        }
开发者ID:jaykay-design,项目名称:box-windows-sdk-v2,代码行数:30,代码来源:AuthRepository.cs


示例4: UserEventsAsync

        /// <summary>
        /// Use this to get events for a given user.
        /// </summary>
        /// <param name="limit">Limits the number of events returned (defaults to 500).</param>
        /// <param name="streamType">Restricts the types of events returned: all returns all events; changes returns events that may cause file tree changes such as file updates or collaborations; sync returns events that may cause file tree changes only for synced folders.</param>
        /// <param name="streamPosition">The location in the event stream from which you want to start receiving events. You can specify the special value 'now' to get 0 events and the latest stream_position value. Defaults to 'now'.</param>
        /// <param name="dedupeEvents">Whether or not to automatically de-duplicate events as they are received. Defaults to true.</param>
        /// <returns></returns>
        public async Task<BoxEventCollection<BoxEnterpriseEvent>> UserEventsAsync(int limit = 500, 
                                                                                  UserEventsStreamType streamType = UserEventsStreamType.all,
                                                                                  string streamPosition = "now", 
                                                                                  bool dedupeEvents = true)
        {
            BoxRequest request = new BoxRequest(_config.EventsUri)
                .Param("stream_type", streamType.ToString())
                .Param("limit", limit.ToString())
                .Param("stream_position", streamPosition);

            IBoxResponse<BoxEventCollection<BoxEnterpriseEvent>> response = await ToResponseAsync<BoxEventCollection<BoxEnterpriseEvent>>(request).ConfigureAwait(false);

            if (dedupeEvents)
            {
                List<BoxEnterpriseEvent> filteredEvents = new List<BoxEnterpriseEvent>();
                foreach (var e in response.ResponseObject.Entries)
                {
                    bool notUsed = true;
                    if (!USER_EVENTS_DEDUPE_CACHE.TryGetValue(e.EventId, out notUsed))
                    {
                        USER_EVENTS_DEDUPE_CACHE.Add(e.EventId, true);
                        filteredEvents.Add(e);
                    }
                }

                response.ResponseObject.Entries = filteredEvents;
            }   

            return response.ResponseObject;
        }
开发者ID:box,项目名称:box-windows-sdk-v2,代码行数:38,代码来源:BoxEventsManager.cs


示例5: GetAllGroupsAsync

        /// <summary>
        /// Retrieves all of the groups for given enterprise. Must have permissions to see an enterprise's groups.
        /// </summary>
        /// <param name="limit">The number of results to return with this request. Refer to the Box API for defaults.</param>
        /// <param name="offset">The offset of the results. Refer to the Box API for more details.</param>
        /// <param name="fields">Attribute(s) to include in the response.</param>
        /// <param name="autoPaginate">Whether or not to auto-paginate to fetch all groups; defaults to false.</param>
        /// <returns>A collection of groups.</returns>
        public async Task<BoxCollection<BoxGroup>> GetAllGroupsAsync(int? limit = null, int? offset = null, List<string> fields = null, bool autoPaginate = false)
        {
            BoxRequest request = new BoxRequest(_config.GroupsEndpointUri)
                .Param(ParamFields, fields)
                .Param("limit", limit.ToString())
                .Param("offset", offset.ToString());

            if (autoPaginate)
            {
                if (!limit.HasValue)
                {
                    limit = 100;
                    request.Param("limit", limit.ToString());      
                }
                if (!offset.HasValue)
                    request.Param("offset", "0");

                return await AutoPaginateLimitOffset<BoxGroup>(request, limit.Value);
            }
            else
            {
                IBoxResponse<BoxCollection<BoxGroup>> response = await ToResponseAsync<BoxCollection<BoxGroup>>(request).ConfigureAwait(false);
                return response.ResponseObject;
            }
        }
开发者ID:box,项目名称:box-windows-sdk-v2,代码行数:33,代码来源:BoxGroupsManager.cs


示例6: Exchange

        /// <summary>
        /// Get a down scoped token.
        /// </summary>
        /// <returns>The down scoped access token.</returns>
        public string Exchange()
        {
            BoxRequest boxRequest = new BoxRequest(new Uri(Constants.BoxApiHostUriString), Constants.AuthTokenEndpointString)
                .Method(RequestMethod.Post)
                .Payload(Constants.RequestParameters.SubjectToken, token)
                .Payload(Constants.RequestParameters.SubjectTokenType, Constants.RequestParameters.AccessTokenTypeValue)
                .Payload(Constants.RequestParameters.Scope, scope)
                .Payload(Constants.RequestParameters.Resource, resourceUrl)
                .Payload(Constants.RequestParameters.GrantType, Constants.RequestParameters.TokenExchangeGrantTypeValue);

            if (actorToken != null)
            {
                boxRequest = boxRequest.Payload(Constants.RequestParameters.ActorToken, actorToken)
                    .Payload(Constants.RequestParameters.ActorTokenType, Constants.RequestParameters.IdTokenTypeValue);
            }

            var handler = new HttpRequestHandler();
            var converter = new BoxJsonConverter();
            var service = new BoxService(handler);

            IBoxResponse<OAuthSession> boxResponse = service.ToResponseAsync<OAuthSession>(boxRequest).Result;
            boxResponse.ParseResults(converter);

            return boxResponse.ResponseObject.AccessToken;
        }
开发者ID:box,项目名称:box-windows-sdk-v2,代码行数:29,代码来源:TokenExchange.cs


示例7: GetDevicePin

        /// <summary>
        /// Gets information about an individual device pin.
        /// </summary>
        /// <param name="id">Device pin id.</param>
        /// <returns>Information about the device pin.</returns>
        public async Task<BoxDevicePin> GetDevicePin(string id)
        {
            BoxRequest request = new BoxRequest(_config.DevicePinUri, id);

            IBoxResponse<BoxDevicePin> response = await ToResponseAsync<BoxDevicePin>(request).ConfigureAwait(false);

            return response.ResponseObject;
        }
开发者ID:box,项目名称:box-windows-sdk-v2,代码行数:13,代码来源:BoxDevicePinManager.cs


示例8: SharedItemsAsync

 /// <summary>
 /// Shared items are any files or folders that are represented by a shared link. Shared items are different from other API resources in that a shared resource doesn’t necessarily have to be in the account of the user accessing it. The actual shared link itself is used along with a normal access token.
 /// </summary>
 /// <param name="sharedLink">The shared link for this item.</param>
 /// <param name="sharedLinkPassword">The password for the shared link (if required)</param>
 /// <returns>A full file or folder object is returned if the shared link is valid and the user has access to it. An error may be returned if the link is invalid, if a password is required, or if the user does not have access to the file.</returns>
 public async Task<BoxItem> SharedItemsAsync(string sharedLink, string sharedLinkPassword=null)
 {
     sharedLink.ThrowIfNullOrWhiteSpace("sharedLink");
     BoxRequest request = new BoxRequest(_config.SharedItemsUri, null)
         .Header("BoxApi", string.Format("shared_link={0}{1}", sharedLink, (string.IsNullOrEmpty(sharedLinkPassword) ? "" : ("&shared_link_password=" + sharedLinkPassword))));
     IBoxResponse<BoxItem> response = await ToResponseAsync<BoxItem>(request).ConfigureAwait(false);
     return response.ResponseObject;
 }
开发者ID:box,项目名称:box-windows-sdk-v2,代码行数:14,代码来源:BoxSharedItemsManager.cs


示例9: DeleteDevicePin

        /// <summary>
        /// Delete individual device pin.
        /// </summary>
        /// <param name="id">Device pin id.</param>
        /// <returns>True if successfully deleted.</returns>
        public async Task<bool> DeleteDevicePin(string id)
        {
            BoxRequest request = new BoxRequest(_config.DevicePinUri, id)
                .Method(RequestMethod.Delete);

            IBoxResponse<BoxDevicePin> response = await ToResponseAsync<BoxDevicePin>(request).ConfigureAwait(false);

            return response.Status == ResponseStatus.Success;
        }
开发者ID:box,项目名称:box-windows-sdk-v2,代码行数:14,代码来源:BoxDevicePinManager.cs


示例10: GetCurrentUserInformationAsync

        /// <summary>
        /// Retrieves information about the user who is currently logged in i.e. the user for whom this auth token was generated.
        /// </summary>
        /// <returns></returns>
        public async Task<BoxUser> GetCurrentUserInformationAsync(List<string> fields = null)
        {
            BoxRequest request = new BoxRequest(_config.UserEndpointUri, "me")
                .Param(ParamFields, fields);

            IBoxResponse<BoxUser> response = await ToResponseAsync<BoxUser>(request);

            return response.ResponseObject;
        }
开发者ID:rhullah,项目名称:box-windows-sdk-v2,代码行数:13,代码来源:BoxUsersManager.cs


示例11: GetCollectionsAsync

        /// <summary>
        /// Retrieves the collections for the given user. Currently, only the favorites collection is supported.
        /// </summary>
        /// <returns>An array of collection instances</returns>
        public async Task<BoxCollection<BoxCollectionItem>> GetCollectionsAsync()
        {
            BoxRequest request = new BoxRequest(_config.CollectionsEndpointUri, null)
                .Method(RequestMethod.Get);

            IBoxResponse<BoxCollection<BoxCollectionItem>> response = await ToResponseAsync<BoxCollection<BoxCollectionItem>>(request).ConfigureAwait(false);

            return response.ResponseObject;
        }
开发者ID:box,项目名称:box-windows-sdk-v2,代码行数:13,代码来源:BoxCollectionsManager.cs


示例12: DownloadStreamAsync

 /// <summary>
 /// Returns the stream of the requested file
 /// </summary>
 /// <param name="id">Id of the file to download</param>
 /// <param name="versionId">The ID specific version of this file to download.</param>
 /// <param name="timeout">Optional timeout for response</param>
 /// <returns>MemoryStream of the requested file</returns>
 public async Task<Stream> DownloadStreamAsync(string id, string versionId = null, TimeSpan? timeout = null)
 {
     var uri = await GetDownloadUriAsync(id, versionId);
     BoxRequest request = new BoxRequest(uri)
     {
         Timeout = timeout
     };
     IBoxResponse<Stream> response = await ToResponseAsync<Stream>(request).ConfigureAwait(false);
     return response.ResponseObject;
 }
开发者ID:zeus82,项目名称:box-windows-sdk-v2,代码行数:17,代码来源:BoxFilesManager.cs


示例13: GetMetadata

        /// <summary>
        /// Retrieves the metadata for the given file id
        /// </summary>
        /// <param name="id">ID of the file to retrieve metadata from</param>
        /// <param name="typeInstance">Name of the metadata type instance</param>
        /// <returns>A BoxMetadata object that includes key:value pairs defined by a user or application. 
        /// If there is no type instance present, a 404 HTTP status code of not_found will be returned.</returns>
        public async Task<BoxMetadata> GetMetadata(string id, string typeInstance = DefaultTypeInstance)
        {
            id.ThrowIfNullOrWhiteSpace("id");

            BoxRequest request = new BoxRequest(new Uri(Constants.BoxApiUriString + string.Format(CultureInfo.InvariantCulture, MetadataEndpointPath, id, typeInstance)));

            IBoxResponse<BoxMetadata> response = await ToResponseAsync<BoxMetadata>(request).ConfigureAwait(false);

            return response.ResponseObject;
        }
开发者ID:tio4226,项目名称:box-windows-metadata-sdk-v2,代码行数:17,代码来源:BoxMetadataManager.cs


示例14: ValidParameters_ValidRequest

        public void ValidParameters_ValidRequest()
        {
            Uri baseUri = new Uri("http://api.box.com/v2");
            IBoxRequest request = new BoxRequest(baseUri, "auth/oauth2");
            request.Parameters.Add("test", "test2");

            Assert.AreEqual(request.Method, RequestMethod.Get);
            Assert.AreEqual(baseUri, request.Host);
            Assert.IsNotNull(request.Parameters);
        }
开发者ID:JeremyButts,项目名称:box-windows-sdk-v2,代码行数:10,代码来源:BoxRequestTest.cs


示例15: UpdateUserInformationAsync

        /// <summary>
        /// Used to edit the settings and information about a user. This method only works for enterprise admins. To roll a user out 
        /// of the enterprise (and convert them to a standalone free user), update the special enterprise attribute to be null
        /// </summary>
        /// <param name="id"></param>
        /// <param name="userRequest"></param>
        /// <returns></returns>
        public async Task<BoxUser> UpdateUserInformationAsync(BoxUserRequest userRequest, List<string> fields = null)
        {
            BoxRequest request = new BoxRequest(_config.UserEndpointUri, userRequest.Id)
                .Param(ParamFields, fields)
                .Payload(_converter.Serialize(userRequest));

            IBoxResponse<BoxUser> response = await ToResponseAsync<BoxUser>(request);

            return response.ResponseObject;
        }
开发者ID:rhullah,项目名称:box-windows-sdk-v2,代码行数:17,代码来源:BoxUsersManager.cs


示例16: GetWebhookAsync

        /// <summary>
        /// Get a webhook.
        /// </summary>
        /// <param name="id">Webhook id.</param>
        /// <returns>Returns a webhook object.</returns>
        public async Task<BoxWebhook> GetWebhookAsync(string id)
        {
            id.ThrowIfNullOrWhiteSpace("id");

            BoxRequest request = new BoxRequest(_config.WebhooksUri, id);

            IBoxResponse<BoxWebhook> response = await ToResponseAsync<BoxWebhook>(request).ConfigureAwait(false);

            return response.ResponseObject;
        }
开发者ID:box,项目名称:box-windows-sdk-v2,代码行数:15,代码来源:BoxWebhooksManager.cs


示例17: CreateRetentionPolicyAsync

        /// <summary>
        /// Used to create a new retention policy.
        /// </summary>
        /// <param name="retentionPolicyRequest">BoxRetentionPolicyRequest object.</param>
        /// <returns>A new retention policy object will be returned upon success.</returns>
        public async Task<BoxRetentionPolicy> CreateRetentionPolicyAsync(BoxRetentionPolicyRequest retentionPolicyRequest)
        {
            BoxRequest request = new BoxRequest(_config.RetentionPoliciesEndpointUri)
                .Method(RequestMethod.Post)
                .Payload(_converter.Serialize(retentionPolicyRequest));

            IBoxResponse<BoxRetentionPolicy> response = await ToResponseAsync<BoxRetentionPolicy>(request).ConfigureAwait(false);

            return response.ResponseObject;
        }
开发者ID:box,项目名称:box-windows-sdk-v2,代码行数:15,代码来源:BoxRetentionPoliciesManager.cs


示例18: CreateWebhookAsync

        /// <summary>
        /// Create a new webhook.
        /// </summary>
        /// <param name="webhookRequest">BoxWebhookRequest object.</param>
        /// <returns>Returns a webhook object if creation succeeds.</returns>
        public async Task<BoxWebhook> CreateWebhookAsync(BoxWebhookRequest webhookRequest)
        {
            BoxRequest request = new BoxRequest(_config.WebhooksUri)
                .Method(RequestMethod.Post)
                .Payload(_converter.Serialize<BoxWebhookRequest>(webhookRequest));

            IBoxResponse<BoxWebhook> response = await ToResponseAsync<BoxWebhook>(request).ConfigureAwait(false);

            return response.ResponseObject;
        }
开发者ID:box,项目名称:box-windows-sdk-v2,代码行数:15,代码来源:BoxWebhooksManager.cs


示例19: DownloadStreamAsync

        /// <summary>
        /// Returns the stream of the requested file.
        /// </summary>
        /// <param name="id">Id of the file to download.</param>
        /// <param name="versionId">The ID specific version of this file to download.</param>
        /// <param name="timeout">Optional timeout for response.</param>
        /// <returns>Stream of the requested file.</returns>
        public async Task<Stream> DownloadStreamAsync(string id, string versionId = null, TimeSpan? timeout = null)
        {
            id.ThrowIfNullOrWhiteSpace("id");

            BoxRequest request = new BoxRequest(_config.FilesEndpointUri, string.Format(Constants.ContentPathString, id)) { Timeout = timeout }
                .Param("version", versionId);

            IBoxResponse<Stream> response = await ToResponseAsync<Stream>(request).ConfigureAwait(false);
            return response.ResponseObject;
        }
开发者ID:box,项目名称:box-windows-sdk-v2,代码行数:17,代码来源:BoxFilesManager.cs


示例20: RemoveCollaborationAsync

        /// <summary>
        /// Used to delete a single collaboration.
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public async Task<bool> RemoveCollaborationAsync(string id)
        {
            id.ThrowIfNullOrWhiteSpace("id");

            BoxRequest request = new BoxRequest(_config.CollaborationsEndpointUri, id)
                .Method(RequestMethod.Delete);

            IBoxResponse<BoxCollaboration> response = await ToResponseAsync<BoxCollaboration>(request).ConfigureAwait(false);

            return response.Status == ResponseStatus.Success;
        }
开发者ID:JeremyButts,项目名称:box-windows-sdk-v2,代码行数:16,代码来源:BoxCollaborationsManager.cs



注:本文中的BoxRequest类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# BoxedValue类代码示例发布时间:2022-05-24
下一篇:
C# BoxModuleI类代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap