Exemplo n.º 1
0
 public ScenarioInfo ReadInfo(string directory)
 {
     using (var content = new DirectoryContent(directory))
     {
         var description = ReadDescription(content);
         var contentInfo = new DirectoryContentInfo(directory);
         return(new ScenarioInfo(contentInfo, description));
     }
 }
Exemplo n.º 2
0
        /// <summary>
        /// Creates a directory if the following conditions are met:
        /// <list type="bullet">
        /// <item>
        /// <description>The full path does not exists</description>
        /// </item>
        /// <item>
        /// <description>The max allowed sub folders for the full path is not reached</description>
        /// </item>
        /// </list>
        /// </summary>
        /// <param name="folder">The form the user send</param>
        /// <param name="requestingUserUuid">The uuid of the requesting user</param>
        public async Task CreateFolder(FolderUpload folder, Guid requestingUserUuid)
        {
            if (!Directory.Exists($"{Environment.CurrentDirectory}/Media{folder.ParentPath}") ||
                !DirectoryHelper.CanCreateFolderInDirectory(folder.ParentPath))
            {
                throw new UnprocessableException();
            }

            string fullPath = $"{Environment.CurrentDirectory}/Media{folder.ParentPath}{folder.Name}";

            if (Directory.Exists(fullPath))
            {
                throw new DuplicateNameException();
            }

            FilePath filepathInfo = FilePathInfo.Find(folder.ParentPath);
            string   rootPath     = $"{Environment.CurrentDirectory}/Media{filepathInfo?.Path}";

            var rootDirectoryInfoFile = await DirectoryHelper.GetInfoFileFromDirectory(rootPath);

            DirectoryContentInfo directoryContentInfo = rootDirectoryInfoFile.DirectoryContentInfo
                                                        .Find(dci => dci.OwnerUuid == requestingUserUuid);

            if (directoryContentInfo == null || directoryContentInfo == new DirectoryContentInfo())
            {
                rootDirectoryInfoFile.DirectoryContentInfo.Add(new DirectoryContentInfo
                {
                    DirectoriesOwnedByUser = new List <string>
                    {
                        folder.Name
                    },
                    OwnerUuid = requestingUserUuid
                });
            }
            else
            {
                directoryContentInfo.DirectoriesOwnedByUser.Add(folder.Name);
            }

            Directory.CreateDirectory(fullPath);
            var directoryInfoFile = new DirectoryInfoFile
            {
                DirectoryOwnerUuid = requestingUserUuid
            };

            await DirectoryHelper.UpdateInfoFile(rootPath, rootDirectoryInfoFile);

            await DirectoryHelper.UpdateInfoFile(fullPath, directoryInfoFile);
        }