private static string GetFileLocation(string fileName, WikiSection section, string rootFile) { string firstFolder = "0", secondFolder = "00"; var letter = (byte) fileName[0]; secondFolder = letter.ToString("x"); firstFolder = secondFolder.Substring(0, 1); var fileLocation = IO.Path.Combine(firstFolder, secondFolder); fileLocation = IO.Path.Combine(fileLocation, EncodeSafeName(fileName)); //TODO: encode nameprep here return fileLocation; }
private static void FileContentSave(string location, byte[] fileContent, WikiSection section, int tenantId) { var storage = StorageFactory.GetStorage(tenantId.ToString(), section.DataStorage.ModuleName); FileContentSave(storage, location, fileContent, section); }
private static void FileContentSave(IDataStore storage, string location, byte[] fileContent, WikiSection section) { using (var ms = new IO.MemoryStream(fileContent)) { storage.Save(section.DataStorage.DefaultDomain, location, ms); } }
private static void FileContentSave(string location, byte[] fileContent, WikiSection section, string configLocation, int tenantId, HttpContext context) { var storage = StorageFactory.GetStorage(configLocation, tenantId.ToString(), section.DataStorage.ModuleName, context); FileContentSave(storage, location, fileContent, section); }
public static SaveResult DirectFileSave(Guid UserId, FileUpload fuFile, string rootFile, WikiSection section, string configLocation, int tenantId, HttpContext context) { if (!fuFile.HasFile) return SaveResult.FileEmpty; //var fileName = fuFile.FileName; //var fileLocation = GetFileLocation(fileName, section, rootFile); //var file = new File // { // FileName = fileName, // UploadFileName = fileName, // UserID = UserId, // FileLocation = fileLocation, // FileSize = fuFile.FileBytes.Length, // }; var wikiEngine = new WikiEngine(); //wikiEngine.SaveFile(file); var file = wikiEngine.CreateOrUpdateFile(new File {FileName = fuFile.FileName, FileSize = fuFile.FileBytes.Length}); try { FileContentSave(file.FileLocation/*fileLocation*/, fuFile.FileBytes, section, configLocation, tenantId, context); } catch (TenantQuotaException) { wikiEngine.RemoveFile(file.FileName); return SaveResult.FileSizeExceeded; } return SaveResult.Ok; }
public static SaveResult MoveContentFromTemp(Guid UserId, string fromFileName, string toFileName, string configLocation, WikiSection section, int tenantId, HttpContext context, string rootFile, out string _fileName) { var storage = StorageFactory.GetStorage(configLocation, tenantId.ToString(), section.DataStorage.ModuleName, context); var fileName = toFileName; var fileLocation = GetFileLocation(fileName, section, rootFile); var file = new File { FileName = fileName, UploadFileName = fileName, UserID = UserId, FileLocation = fileLocation, FileSize = (int) storage.GetFileSize(section.DataStorage.TempDomain, fromFileName), }; var wiki = new WikiEngine(); wiki.SaveFile(file); storage.Move(section.DataStorage.TempDomain, fromFileName, section.DataStorage.DefaultDomain, fileLocation); _fileName = file.FileName; return SaveResult.Ok; }
public static void DeleteContent(string fileName, string configLocation, WikiSection section, int tenantId, HttpContext context) { var storage = StorageFactory.GetStorage(configLocation, tenantId.ToString(), section.DataStorage.ModuleName, context); storage.Delete(section.DataStorage.DefaultDomain, fileName); }
public static SaveResult DirectFileSave(Guid userId, FileUpload fuFile, string rootFile, WikiSection section, string configLocation, int tenantId, HttpContext context) { if (!fuFile.HasFile) return SaveResult.FileEmpty; var wikiEngine = new WikiEngine(); File file = null; try { file = wikiEngine.CreateOrUpdateFile(new File {FileName = fuFile.FileName, FileSize = fuFile.FileBytes.Length}); FileContentSave(file.FileLocation, fuFile.FileBytes, section, configLocation, tenantId, context); } catch (TenantQuotaException) { if (file != null) wikiEngine.RemoveFile(file.FileName); return SaveResult.FileSizeExceeded; } return SaveResult.Ok; }