public JsonResult ItemExist(string org, string pathPart, string newItemName) { var exist = _webdavManager.FileExist(string.Format("{0}/{1}", pathPart.TrimEnd('/'), newItemName.Trim('/'))); return(new JsonResult() { Data = !exist }); }
public PutRelativeFile Put_Relative(int accessTokenId) { var result = new PutRelativeFile(); var token = _tokenManager.GetToken(accessTokenId); var newFilePath = string.Empty; var target = Request.Headers.Contains("X-WOPI-RelativeTarget") ? Request.Headers.GetValues("X-WOPI-RelativeTarget").First() : Request.Headers.GetValues("X-WOPI-SuggestedTarget").First(); bool overwrite = Request.Headers.Contains("X-WOPI-RelativeTarget") && Convert.ToBoolean(Request.Headers.GetValues("X-WOPI-OverwriteRelativeTarget").First()); if (string.IsNullOrEmpty(target)) { throw new HttpResponseException(HttpStatusCode.BadRequest); } if (target.Split(new[] { '.' }, StringSplitOptions.RemoveEmptyEntries).Count() > 1) { var fileName = Path.GetFileName(token.FilePath); newFilePath = token.FilePath.ReplaceLast(fileName, target); } else { newFilePath = Path.ChangeExtension(token.FilePath, target); } if (overwrite == false && _webDavManager.FileExist(newFilePath)) { throw new HttpResponseException(HttpStatusCode.Conflict); } var bytes = Request.Content.ReadAsByteArrayAsync().Result; _webDavManager.UploadFile(newFilePath, bytes); var newToken = _tokenManager.CreateToken(WspContext.User, newFilePath); var readUrlPart = Url.Route(FileSystemRouteNames.ViewOfficeOnline, new { org = WspContext.User.OrganizationId, pathPart = newFilePath }); var writeUrlPart = Url.Route(FileSystemRouteNames.EditOfficeOnline, new { org = WspContext.User.OrganizationId, pathPart = newFilePath }); result.HostEditUrl = new Uri(Request.RequestUri, writeUrlPart).ToString(); result.HostViewUrl = new Uri(Request.RequestUri, readUrlPart).ToString();; result.Name = Path.GetFileName(newFilePath); result.Url = Url.GenerateWopiUrl(newToken, newFilePath); return(result); }
public byte[] GetFileBytes(int accessTokenId) { var token = _tokenManager.GetToken(accessTokenId); if (_webDavManager.FileExist(token.FilePath)) { return(_webDavManager.GetFileBytes(token.FilePath)); } var cobaltFile = _fileManager.Get(token.FilePath) ?? _fileManager.Create(accessTokenId); var stream = new MemoryStream(); new GenericFda(cobaltFile.CobaltEndpoint, null).GetContentStream().CopyTo(stream); return(stream.ToArray()); }
public CobaltFile Create(int accessTokenId) { var disposal = new DisposalEscrow(accessTokenId.ToString(CultureInfo.InvariantCulture)); var content = new CobaltFilePartitionConfig { IsNewFile = true, HostBlobStore = new TemporaryHostBlobStore(new TemporaryHostBlobStore.Config(), disposal, accessTokenId + @".Content"), cellSchemaIsGenericFda = true, CellStorageConfig = new CellStorageConfig(), Schema = CobaltFilePartition.Schema.ShreddedCobalt, PartitionId = FilePartitionId.Content }; var coauth = new CobaltFilePartitionConfig { IsNewFile = true, HostBlobStore = new TemporaryHostBlobStore(new TemporaryHostBlobStore.Config(), disposal, accessTokenId + @".CoauthMetadata"), cellSchemaIsGenericFda = false, CellStorageConfig = new CellStorageConfig(), Schema = CobaltFilePartition.Schema.ShreddedCobalt, PartitionId = FilePartitionId.CoauthMetadata }; var wacupdate = new CobaltFilePartitionConfig { IsNewFile = true, HostBlobStore = new TemporaryHostBlobStore(new TemporaryHostBlobStore.Config(), disposal, accessTokenId + @".WordWacUpdate"), cellSchemaIsGenericFda = false, CellStorageConfig = new CellStorageConfig(), Schema = CobaltFilePartition.Schema.ShreddedCobalt, PartitionId = FilePartitionId.WordWacUpdate }; var partitionConfs = new Dictionary <FilePartitionId, CobaltFilePartitionConfig> { { FilePartitionId.Content, content }, { FilePartitionId.WordWacUpdate, wacupdate }, { FilePartitionId.CoauthMetadata, coauth } }; var cobaltFile = new CobaltFile(disposal, partitionConfs, new CobaltHostLockingStore(), null); var token = _tokenManager.GetToken(accessTokenId); Atom atom; if (_webDavManager.FileExist(token.FilePath)) { var fileBytes = _webDavManager.GetFileBytes(token.FilePath); atom = new AtomFromByteArray(fileBytes); } else { var filePath = HttpContext.Current.Server.MapPath(WebDavAppConfigManager.Instance.OfficeOnline.NewFilePath + Path.GetExtension(token.FilePath)); atom = new AtomFromByteArray(File.ReadAllBytes(filePath)); } Cobalt.Metrics o1; cobaltFile.GetCobaltFilePartition(FilePartitionId.Content).SetStream(RootId.Default.Value, atom, out o1); cobaltFile.GetCobaltFilePartition(FilePartitionId.Content).GetStream(RootId.Default.Value).Flush(); Add(token.FilePath, cobaltFile); return(cobaltFile); }