当前位置: 首页>>代码示例>>C#>>正文


C# BoxRequest类代码示例

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


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


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