Exemplo n.º 1
0
 /// <summary>
 /// Removes members from a group.
 /// </summary>
 /// <param name="groupId">Group id.</param>
 /// <param name="memberIds">Ids of members to remove from the group.</param>
 /// <param name="server">Target server.</param>
 public static async Task RemoveMembersAsync(int groupId, int[] memberIds, ServerContext server = null)
 {
     await RESTCaller.GetResponseStringAsync(groupId, "RemoveMembers", HttpMethod.Post, JsonHelper.GetJsonPostModel(new
     {
         contentIds = memberIds
     }),
                                             server);
 }
Exemplo n.º 2
0
        /// <summary>
        /// Gets a blob storage token that identifies a binary in the storage.
        /// </summary>
        /// <param name="path">Content path.</param>
        /// <param name="version">Content version (e.g. V2.3D). If not provided, the highest version
        /// accessible to the current user will be served.</param>
        /// <param name="propertyName">Binary field name. Default is Binary.</param>
        /// <param name="server">Target server.</param>
        /// <returns>A token that can be used with the Blob storage API.</returns>
        public static async Task <string> GetBlobToken(string path, string version = null, string propertyName = null, ServerContext server = null)
        {
            var responseText = await RESTCaller.GetResponseStringAsync(path, "GetBinaryToken", HttpMethod.Post,
                                                                       JsonHelper.Serialize(new { version, fieldName = propertyName }), server);

            var response = JsonHelper.Deserialize(responseText);

            return(response.token);
        }
Exemplo n.º 3
0
 /// <summary>
 /// Deletes one or more content by Id or Path.
 /// </summary>
 /// <param name="idsOrPaths">One or more id or path of the <see cref="Content"/> objects to delete.</param>
 /// <param name="permanent">Delete the content permanently or into the Trash.</param>
 /// <param name="cancellationToken">The token to monitor for cancellation requests.</param>
 /// <param name="server">Target server. If null, the first one will be used from the configuration.</param>
 /// <returns>A task that represents an asynchronous operation.</returns>
 public static async Task DeleteAsync(object[] idsOrPaths, bool permanent, CancellationToken cancellationToken,
                                      ServerContext server = null)
 {
     await RESTCaller.GetResponseStringAsync("/Root", "DeleteBatch", HttpMethod.Post,
                                             JsonHelper.GetJsonPostModel(new
     {
         permanent,
         paths = idsOrPaths
     }), server)
     .ConfigureAwait(false);
 }
Exemplo n.º 4
0
        /// <summary>
        /// Undo all modifications on the content since the last checkout operation.
        /// </summary>
        public async Task UndoCheckOutAsync()
        {
            var requestData = new ODataRequest(Server)
            {
                ContentId  = this.Id,
                Path       = this.Path,
                ActionName = "UndoCheckOut",
                Select     = new [] { "Id" }
            };

            await RESTCaller.GetResponseStringAsync(requestData.GetUri(), Server, HttpMethod.Post).ConfigureAwait(false);
        }
Exemplo n.º 5
0
        /// <summary>
        /// Check in the content.
        /// </summary>
        public async Task CheckInAsync()
        {
            var requestData = new ODataRequest()
            {
                SiteUrl    = Server.Url,
                ContentId  = this.Id,
                Path       = this.Path,
                ActionName = "CheckIn",
                Select     = new[] { "Id" }
            };

            await RESTCaller.GetResponseStringAsync(requestData.GetUri(), Server, HttpMethod.Post);
        }
Exemplo n.º 6
0
        /// <summary>
        /// Creates a copy of the content to the target location.
        /// </summary>
        /// <param name="targetPath">Target path.</param>
        public async Task CopyToAsync(string targetPath)
        {
            var requestData = new ODataRequest()
            {
                SiteUrl    = Server.Url,
                ContentId  = this.Id,
                Path       = this.Path,
                ActionName = "CopyTo"
            };

            await RESTCaller.GetResponseStringAsync(requestData.GetUri(), Server, HttpMethod.Post, JsonHelper.GetJsonPostModel(new
            {
                targetPath
            }));
        }
Exemplo n.º 7
0
        /// <summary>
        /// Deletes the content.
        /// </summary>
        /// <param name="permanent">Delete the content permanently or into the Trash.</param>
        public async Task DeleteAsync(bool permanent = true)
        {
            var requestData = new ODataRequest()
            {
                SiteUrl    = Server.Url,
                ContentId  = this.Id,
                Path       = this.Path,
                ActionName = "Delete"
            };

            await RESTCaller.GetResponseStringAsync(requestData.GetUri(), Server, HttpMethod.Post, JsonHelper.GetJsonPostModel(new
            {
                permanent
            }));
        }
Exemplo n.º 8
0
        /// <summary>
        /// Moves the content to the target location.
        /// </summary>
        /// <param name="targetPath">Target path.</param>
        public async Task MoveToAsync(string targetPath)
        {
            var requestData = new ODataRequest(Server)
            {
                ContentId  = this.Id,
                Path       = this.Path,
                ActionName = "MoveTo"
            };

            await RESTCaller.GetResponseStringAsync(requestData.GetUri(), Server, HttpMethod.Post, JsonHelper.GetJsonPostModel(new
            {
                targetPath
            }))
            .ConfigureAwait(false);
        }
Exemplo n.º 9
0
        private static async Task SaveAndFinalizeBlobInternalAsync(string initResponse, long fileSize,
                                                                   Func <int, int, string, Task> blobCallback, string fileName = null,
                                                                   string propertyName = null, ServerContext server = null)
        {
            // parse the response of the initial request
            var    response  = JsonHelper.Deserialize(initResponse);
            int    contentId = response.id;
            string token     = response.token;
            int    versionId = response.versionId;

            // save binary through the blob storage
            await blobCallback(contentId, versionId, token);

            // send final request
            await RESTCaller.GetResponseStringAsync(contentId, "FinalizeBlobUpload", HttpMethod.Post,
                                                    JsonHelper.Serialize(new
            {
                token,
                fullSize  = fileSize,
                fieldName = propertyName,
                fileName
            }),
                                                    server);
        }