示例#1
0
        private static async Task DeleteFilesOwnedByUser(Guid userUuid, ConcurrentDictionary <string, DirectoryInfoFile> directoryInfoFileCollection)
        {
            var allFilesOwnedByUser = new ConcurrentBag <Guid>();
            var updateInfoFileTasks = directoryInfoFileCollection.Select(directoryInfoFileKeyValue => new Task(async() =>
            {
                string path = directoryInfoFileKeyValue.Key;
                DirectoryInfoFile directoryInfoFile = directoryInfoFileKeyValue.Value;
                FileContentInfo fileContentInfo     = directoryInfoFile.FileInfo.Find(fi => fi.FileOwnerUuid == userUuid);

                fileContentInfo.FilesOwnedByUser.ForEach(uuid => allFilesOwnedByUser.Add(uuid));

                directoryInfoFile.FileInfo.Remove(fileContentInfo);
                directoryInfoFile.DirectoryContentInfo.RemoveAll(dci => dci.OwnerUuid == userUuid);

                if (directoryInfoFile.DirectoryOwnerUuid == userUuid)
                {
                    directoryInfoFile.DirectoryOwnerUuid = Guid.Empty;
                }

                await UpdateInfoFile(path, directoryInfoFile);
            }))
                                      .ToList();

            await Task.WhenAll(updateInfoFileTasks);
        }
示例#2
0
        /// <summary>
        /// Updates the info file in the specified directory
        /// </summary>
        /// <param name="fullPath">The full path save the file</param>
        /// <param name="directoryInfoFile">The file to save</param>
        public static async Task UpdateInfoFile(string fullPath, DirectoryInfoFile directoryInfoFile)
        {
            if (string.IsNullOrEmpty(fullPath) || directoryInfoFile == null ||
                directoryInfoFile == new DirectoryInfoFile())
            {
                throw new UnprocessableException();
            }

            string newJson = await Task.Factory.StartNew(() => JsonConvert.SerializeObject(directoryInfoFile));

            await File.WriteAllTextAsync($"{fullPath}/info.json", newJson);
        }