public override T Using <T>(DirectoryContentHash cwd, Func <IFileSystemContext, T> action) { if (Root == null) { throw new InvalidOperationException("Unable to retrieve the root directory."); } DirectoryType rootDirectoryType; if (!EntityDirectoryTypes.TryGetValue(Root.LogicalName, out rootDirectoryType)) { throw new InvalidOperationException("Unable to retrieve the root directory."); } DirectoryType currentDirectoryType; if (!EntityDirectoryTypes.TryGetValue(cwd.LogicalName, out currentDirectoryType)) { throw new InvalidOperationException("Unable to retrieve the target directory"); } var current = new EntityDirectory(this, cwd.ToEntityReference(), currentDirectoryType); if (!current.Exists) { throw new InvalidOperationException("Unable to retrieve the target directory"); } return(action(new EntityFileSystemContext(this, Root, rootDirectoryType, current))); }
public CommandResponse GetResponse(ICommandContext commandContext) { var fileSystem = commandContext.CreateFileSystem(); var hash = commandContext.Parameters["current"]; DirectoryContentHash cwd; if (!DirectoryContentHash.TryParse(hash, out cwd)) { return(new ErrorCommandResponse { error = ResourceManager.GetString("Unable_To_Retrieve_Current_Directory_Error") }); } bool canWrite; try { canWrite = fileSystem.Using(cwd, fs => fs.Current.CanWrite); } catch (InvalidOperationException) { return(new ErrorCommandResponse { error = ResourceManager.GetString("Unable_To_Retrieve_Current_Directory_Error") }); } if (!canWrite) { return(new ErrorCommandResponse { error = ResourceManager.GetString("Delete_Permission_Denied_For_Current_Directory_Error") }); } var errors = RemoveFiles(commandContext); try { return(fileSystem.Using(cwd, fs => GetResponse(commandContext, fs, errors))); } catch (InvalidOperationException) { return(new ErrorCommandResponse { error = ResourceManager.GetString("Unable_To_Retrieve_Current_Directory_Error") }); } }
public CommandResponse GetResponse(ICommandContext commandContext) { var fileSystem = commandContext.CreateFileSystem(); // If no target directory is specified (as on first init), use a working directory, if // specified. var hash = string.IsNullOrEmpty(commandContext.Parameters["target"]) ? commandContext.Parameters["working"] : commandContext.Parameters["target"]; var response = new OpenCommandResponse { tmb = false, disabled = commandContext.DisabledCommands.ToArray(), parameters = new InitializationParameters { dotFiles = false, archives = new string[] {}, extract = new string[] {}, } }; DirectoryContentHash cwd; if (DirectoryContentHash.TryParse(hash, out cwd)) { try { return(fileSystem.Using(cwd, fs => GetResponse(commandContext, fs, response))); } catch (InvalidOperationException e) { response.error = e.Message; } } try { return(fileSystem.Using(fs => GetResponse(commandContext, fs, response))); } catch (InvalidOperationException e) { response.error = e.Message; return(response); } }
private T Using <T>(ContentMap contentMap, DirectoryContentHash cwd, Func <IFileSystemContext, T> action) { var root = GetRoot(contentMap); if (root == null) { throw new InvalidOperationException("Unable to retrieve the root directory."); } var current = GetDirectory(contentMap, cwd); if (current == null || !current.Exists) { throw new InvalidOperationException("Unable to retrieve the target directory"); } return(action(new ContentMapFileSystemContext(this, contentMap, root, current))); }
public static bool TryParse(string value, out DirectoryContentHash hash) { hash = null; try { if (string.IsNullOrEmpty(value)) { return(false); } var decoded = Base64Decode(value); var match = Regex.Match(decoded, "^(?<LogicalName>[^:]+):(?<Id>.+):(?<IsDirectory>.*)$", RegexOptions.CultureInvariant | RegexOptions.ExplicitCapture); if (!match.Success) { return(false); } var logicalName = match.Groups["LogicalName"].Value; Guid id; if (!Guid.TryParse(match.Groups["Id"].Value, out id)) { return(false); } bool isDirectoryValue; var isDirectory = bool.TryParse(match.Groups["IsDirectory"].Value, out isDirectoryValue) && isDirectoryValue; hash = new DirectoryContentHash(new EntityReference(logicalName, id), isDirectory); return(true); } catch { return(false); } }
private IDirectory GetDirectory(ContentMap contentMap, DirectoryContentHash hash) { var entityReference = hash.ToEntityReference(); WebPageNode node; if (contentMap.TryGetValue(entityReference, out node)) { return(new WebPageNodeDirectory(this, contentMap, node)); } DirectoryType entityDirectoryType; if (EntityDirectoryTypes.TryGetValue(entityReference.LogicalName, out entityDirectoryType)) { return(new EntityDirectory(this, entityReference, entityDirectoryType)); } return(null); }
private static bool TryGetTargetEntity(OrganizationServiceContext serviceContext, string hash, EntityReference website, out Entity target) { target = null; DirectoryContentHash hashInfo; if (!DirectoryContentHash.TryParse(hash, out hashInfo)) { return(false); } Tuple <string, string> targetSchema; if (!RmTargetSchemaLookup.TryGetValue(hashInfo.LogicalName, out targetSchema)) { return(false); } target = serviceContext.CreateQuery(hashInfo.LogicalName) .FirstOrDefault(e => e.GetAttributeValue <Guid>(targetSchema.Item1) == hashInfo.Id && e.GetAttributeValue <EntityReference>(targetSchema.Item2) == website); return(target != null); }
public override T Using <T>(DirectoryContentHash cwd, Func <IFileSystemContext, T> action) { return(ContentMapProvider.Using(map => Using(map, cwd, action))); }
public CommandResponse GetResponse(ICommandContext commandContext) { var fileSystem = commandContext.CreateFileSystem(); var hash = commandContext.Parameters["current"]; DirectoryContentHash cwd; if (!DirectoryContentHash.TryParse(hash, out cwd)) { return(new ErrorCommandResponse { error = ResourceManager.GetString("Unable_To_Retrieve_Current_Directory_For_Upload_Error") }); } DirectoryUploadInfo cwdInfo; try { cwdInfo = fileSystem.Using(cwd, fs => new DirectoryUploadInfo(fs.Current)); } catch (InvalidOperationException) { return(new ErrorCommandResponse { error = ResourceManager.GetString("Unable_To_Retrieve_Current_Directory_For_Upload_Error") }); } if (!(cwdInfo.SupportsUpload && cwdInfo.CanWrite)) { return(new ErrorCommandResponse { error = ResourceManager.GetString("Upload_Permission_Denied_For_Current_Directory_Error") }); } var files = GetUploadedFiles(commandContext.Files); if (!files.Any()) { return(new ErrorCommandResponse { error = "No valid files were uploaded" }); } var portal = commandContext.CreatePortalContext(); var publishingState = GetPublishingState(portal, cwdInfo.Entity); if (publishingState == null) { return(new ErrorCommandResponse { error = ResourceManager.GetString("Unable_To_Retrieve_Current_Directory_For_Upload_Error") }); } List <string> @select; List <Tuple <string, string> > errors; CreateFiles(commandContext, cwdInfo, files, publishingState, out @select, out errors); try { return(fileSystem.Using(cwd, fs => GetResponse(commandContext, fs, @select, errors))); } catch (InvalidOperationException) { return(new ErrorCommandResponse { error = ResourceManager.GetString("Unable_To_Retrieve_Current_Directory_For_Upload_Error") }); } }
public abstract T Using <T>(DirectoryContentHash cwd, Func <IFileSystemContext, T> action);