/// <summary>
        /// Provides a method to get a tasks subTasks without the need to call get function for the superTask
        /// </summary>
        public static async Task <List <WrikeTask> > GetSubTasksBySuperTaskIdAsync(this IWrikeTasksClient wrikeTasksClient, WrikeClientIdParameter superTaskId)
        {
            var superTask = await GetTaskByIdAsync(wrikeTasksClient, superTaskId).ConfigureAwait(false);

            if (superTask.SubTaskIds.Count == 0)
            {
                return(new List <WrikeTask>());
            }

            return(await wrikeTasksClient.GetAsync(taskIds : superTask.SubTaskIds).ConfigureAwait(false));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Uploads the attachment to given folder
        /// </summary>
        /// <param name="wrikeAttachmentsClient"></param>
        /// <param name="folderId">Folder ID</param>
        /// <param name="filePath">Full path of the file</param>
        /// <param name="fileName">If not given gets the name from filePath</param>
        public static async Task <WrikeFolderAttachment> CreateAttachmentInFolder(this IWrikeAttachmentsClient wrikeAttachmentsClient, WrikeClientIdParameter folderId, string filePath, string fileName = null)
        {
            var fileBytes = File.ReadAllBytes(filePath);

            if (string.IsNullOrWhiteSpace(fileName))
            {
                fileName = Path.GetFileName(filePath);
            }

            return(await wrikeAttachmentsClient.CreateInFolderAsync(folderId, fileName, fileBytes).ConfigureAwait(false));
        }
        /// <summary>
        /// Provides a method to get task with single taskId rather than List
        /// </summary>
        public static async Task <WrikeTask> GetTaskByIdAsync(this IWrikeTasksClient wrikeTasksClient, WrikeClientIdParameter taskId)
        {
            var tasks = await wrikeTasksClient.GetAsync(taskIds : new List <string> {
                taskId
            }).ConfigureAwait(false);

            return(tasks.FirstOrDefault());
        }
Ejemplo n.º 4
0
 /// <summary>
 /// Downloads the attachment and saves it to the given path
 /// </summary>
 /// <param name="wrikeAttachmentsClient"></param>
 /// <param name="attachmentId">Attachment ID</param>
 /// <param name="savingPath">Path to save file</param>
 public static async Task DownloadAndSaveAttachment(this IWrikeAttachmentsClient wrikeAttachmentsClient, WrikeClientIdParameter attachmentId, string savingPath)
 {
     using (var downloadedStream = await wrikeAttachmentsClient.DownloadAsync(attachmentId).ConfigureAwait(false))
     {
         using (FileStream fs = new FileStream(savingPath, FileMode.Create, FileAccess.Write))
         {
             byte[] buffer = new byte[8 * 1024];
             int    len;
             while ((len = downloadedStream.Read(buffer, 0, buffer.Length)) > 0)
             {
                 fs.Write(buffer, 0, len);
             }
         }
     }
 }