webdav portal create new ability added
This commit is contained in:
parent
6b1c1660fe
commit
50e902b94d
26 changed files with 473 additions and 38 deletions
|
@ -13,12 +13,14 @@ namespace WebsitePanel.WebDav.Core.Config.Entities
|
|||
{
|
||||
IsEnabled = ConfigSection.OfficeOnline.IsEnabled;
|
||||
Url = ConfigSection.OfficeOnline.Url;
|
||||
NewFilePath = ConfigSection.OfficeOnline.CobaltNewFilePath;
|
||||
CobaltFileTtl = ConfigSection.OfficeOnline.CobaltFileTtl;
|
||||
_officeExtensions = ConfigSection.OfficeOnline.Cast<OfficeOnlineElement>().ToList();
|
||||
}
|
||||
|
||||
public bool IsEnabled { get; private set; }
|
||||
public string Url { get; private set; }
|
||||
public string NewFilePath { get; private set; }
|
||||
public int CobaltFileTtl { get; private set; }
|
||||
|
||||
public IEnumerator<OfficeOnlineElement> GetEnumerator()
|
||||
|
|
|
@ -8,6 +8,7 @@ namespace WebsitePanel.WebDavPortal.WebConfigSections
|
|||
private const string OwaViewKey = "OwaView";
|
||||
private const string OwaEditorKey = "OwaEditor";
|
||||
private const string OwaMobileViewKey = "OwaMobileView";
|
||||
private const string OwaNewFileViewKey = "OwaNewFileView";
|
||||
|
||||
[ConfigurationProperty(ExtensionKey, IsKey = true, IsRequired = true)]
|
||||
public string Extension
|
||||
|
@ -37,5 +38,12 @@ namespace WebsitePanel.WebDavPortal.WebConfigSections
|
|||
get { return this[OwaMobileViewKey].ToString(); }
|
||||
set { this[OwaMobileViewKey] = value; }
|
||||
}
|
||||
|
||||
[ConfigurationProperty(OwaNewFileViewKey, IsKey = true, IsRequired = true)]
|
||||
public string OwaNewFileView
|
||||
{
|
||||
get { return this[OwaNewFileViewKey].ToString(); }
|
||||
set { this[OwaNewFileViewKey] = value; }
|
||||
}
|
||||
}
|
||||
}
|
|
@ -9,6 +9,7 @@ namespace WebsitePanel.WebDavPortal.WebConfigSections
|
|||
private const string UrlKey = "url";
|
||||
private const string IsEnabledKey = "isEnabled";
|
||||
private const string CobaltFileTtlKey = "cobaltFileTtl";
|
||||
private const string CobaltNewFilePathKey = "cobaltNewFilePath";
|
||||
|
||||
[ConfigurationProperty(UrlKey, IsKey = true, IsRequired = true)]
|
||||
public string Url
|
||||
|
@ -24,6 +25,13 @@ namespace WebsitePanel.WebDavPortal.WebConfigSections
|
|||
set { this[IsEnabledKey] = value; }
|
||||
}
|
||||
|
||||
[ConfigurationProperty(CobaltNewFilePathKey, IsKey = true, IsRequired = true)]
|
||||
public string CobaltNewFilePath
|
||||
{
|
||||
get { return this[CobaltNewFilePathKey].ToString(); }
|
||||
set { this[CobaltNewFilePathKey] = value; }
|
||||
}
|
||||
|
||||
[ConfigurationProperty(CobaltFileTtlKey, IsKey = true, IsRequired = true)]
|
||||
public int CobaltFileTtl
|
||||
{
|
||||
|
|
|
@ -37,6 +37,10 @@ namespace WebsitePanel.WebDav.Core.Entities.Owa
|
|||
public bool RestrictedWebViewOnly { get; set; }
|
||||
[DataMember]
|
||||
public string ClientUrl { get; set; }
|
||||
[DataMember]
|
||||
public bool CloseButtonClosesWindow { get; set; }
|
||||
//[DataMember]
|
||||
//public string CloseUrl { get; set; }
|
||||
//[DataMember]
|
||||
//public bool UserCanNotWriteRelative { get; set; }
|
||||
|
||||
|
@ -59,8 +63,7 @@ namespace WebsitePanel.WebDav.Core.Entities.Owa
|
|||
//public string BreadcrumbFolderUrl { get; set; }
|
||||
//[DataMember]
|
||||
//public string ClientUrl { get; set; }
|
||||
//[DataMember]
|
||||
//public bool CloseButtonClosesWindow { get; set; }
|
||||
|
||||
//[DataMember]
|
||||
//public string CloseUrl { get; set; }
|
||||
//[DataMember]
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
using System.Web.Mvc;
|
||||
using WebsitePanel.EnterpriseServer.Base.HostedSolution;
|
||||
using WebsitePanel.WebDav.Core.Client;
|
||||
using WebsitePanel.WebDav.Core.Entities.Owa;
|
||||
|
||||
|
@ -6,7 +6,7 @@ namespace WebsitePanel.WebDav.Core.Interfaces.Owa
|
|||
{
|
||||
public interface IWopiServer
|
||||
{
|
||||
CheckFileInfo GetCheckFileInfo(string path);
|
||||
FileResult GetFile(string path);
|
||||
CheckFileInfo GetCheckFileInfo(WebDavAccessToken token);
|
||||
byte[] GetFileBytes(int accessTokenId);
|
||||
}
|
||||
}
|
|
@ -240,9 +240,9 @@ namespace WebsitePanel.WebDav.Core.Managers
|
|||
|
||||
return _currentFolder.GetResource(resourceName);
|
||||
}
|
||||
catch (InvalidOperationException exception)
|
||||
catch (Exception)
|
||||
{
|
||||
throw new ResourceNotFoundException("Resource not found", exception);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -2,8 +2,10 @@
|
|||
using System.Collections.Concurrent;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Runtime.Caching;
|
||||
using System.Web;
|
||||
using Cobalt;
|
||||
using WebsitePanel.WebDav.Core.Client;
|
||||
using WebsitePanel.WebDav.Core.Config;
|
||||
|
@ -72,9 +74,20 @@ namespace WebsitePanel.WebDav.Core.Owa
|
|||
|
||||
var token = _tokenManager.GetToken(accessTokenId);
|
||||
|
||||
var fileBytes = _webDavManager.GetFileBytes(token.FilePath);
|
||||
Atom atom;
|
||||
|
||||
var atom = new AtomFromByteArray(fileBytes);
|
||||
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);
|
||||
|
|
|
@ -6,6 +6,8 @@ using System.Runtime.Serialization.Json;
|
|||
using System.Text;
|
||||
using System.Web;
|
||||
using System.Web.Mvc;
|
||||
using Cobalt;
|
||||
using WebsitePanel.EnterpriseServer.Base.HostedSolution;
|
||||
using WebsitePanel.WebDav.Core.Client;
|
||||
using WebsitePanel.WebDav.Core.Config;
|
||||
using WebsitePanel.WebDav.Core.Entities.Owa;
|
||||
|
@ -22,27 +24,30 @@ namespace WebsitePanel.WebDav.Core.Owa
|
|||
private readonly IWebDavManager _webDavManager;
|
||||
private readonly IAccessTokenManager _tokenManager;
|
||||
private readonly IWebDavAuthorizationService _webDavAuthorizationService;
|
||||
private readonly IWopiFileManager _fileManager;
|
||||
|
||||
public WopiServer(IWebDavManager webDavManager, IAccessTokenManager tokenManager, IWebDavAuthorizationService webDavAuthorizationService)
|
||||
|
||||
public WopiServer(IWebDavManager webDavManager, IAccessTokenManager tokenManager, IWebDavAuthorizationService webDavAuthorizationService, IWopiFileManager fileManager)
|
||||
{
|
||||
_webDavManager = webDavManager;
|
||||
_tokenManager = tokenManager;
|
||||
_webDavAuthorizationService = webDavAuthorizationService;
|
||||
_fileManager = fileManager;
|
||||
}
|
||||
|
||||
public CheckFileInfo GetCheckFileInfo(string path)
|
||||
public CheckFileInfo GetCheckFileInfo(WebDavAccessToken token)
|
||||
{
|
||||
var resource = _webDavManager.GetResource(path);
|
||||
var resource = _webDavManager.GetResource(token.FilePath);
|
||||
|
||||
var permissions = _webDavAuthorizationService.GetPermissions(WspContext.User, path);
|
||||
var permissions = _webDavAuthorizationService.GetPermissions(WspContext.User, token.FilePath);
|
||||
|
||||
var readOnly = permissions.HasFlag(WebDavPermissions.Write) == false || permissions.HasFlag(WebDavPermissions.OwaEdit) == false;
|
||||
|
||||
var cFileInfo = new CheckFileInfo
|
||||
{
|
||||
BaseFileName = resource.DisplayName.Split(new []{'/'},StringSplitOptions.RemoveEmptyEntries).LastOrDefault(),
|
||||
BaseFileName = resource == null ? token.FilePath.Split('/').Last() : resource.DisplayName.Split(new[] { '/' }, StringSplitOptions.RemoveEmptyEntries).LastOrDefault(),
|
||||
OwnerId = WspContext.User.Login,
|
||||
Size = resource.ContentLength,
|
||||
Size = resource == null ? 0 : resource.ContentLength,
|
||||
Version = DateTime.Now.ToString("s"),
|
||||
SupportsCoauth = true,
|
||||
SupportsCobalt = true,
|
||||
|
@ -53,17 +58,34 @@ namespace WebsitePanel.WebDav.Core.Owa
|
|||
SupportsUpdate = true,
|
||||
UserCanWrite = !readOnly,
|
||||
ReadOnly = readOnly,
|
||||
RestrictedWebViewOnly = false
|
||||
RestrictedWebViewOnly = false,
|
||||
CloseButtonClosesWindow = true
|
||||
};
|
||||
|
||||
if (resource != null)
|
||||
{
|
||||
cFileInfo.ClientUrl = _webDavManager.GetFileUrl(token.FilePath);
|
||||
}
|
||||
|
||||
return cFileInfo;
|
||||
}
|
||||
|
||||
public FileResult GetFile(string path)
|
||||
public byte[] GetFileBytes(int accessTokenId)
|
||||
{
|
||||
var fileBytes = _webDavManager.GetFileBytes(path);
|
||||
var token = _tokenManager.GetToken(accessTokenId);
|
||||
|
||||
return new FileContentResult(fileBytes, MediaTypeNames.Application.Octet);
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue