diff --git a/WebsitePanel/Sources/WebsitePanel.WebDav.Core/Config/Entities/OwaSupportedBrowsersCollection.cs b/WebsitePanel/Sources/WebsitePanel.WebDav.Core/Config/Entities/OwaSupportedBrowsersCollection.cs new file mode 100644 index 00000000..dd2c09f9 --- /dev/null +++ b/WebsitePanel/Sources/WebsitePanel.WebDav.Core/Config/Entities/OwaSupportedBrowsersCollection.cs @@ -0,0 +1,57 @@ +using System.Collections; +using System.Collections.Generic; +using System.Linq; +using WebsitePanel.WebDav.Core.Config.WebConfigSections; + +namespace WebsitePanel.WebDav.Core.Config.Entities +{ + public class OwaSupportedBrowsersCollection : AbstractConfigCollection, IReadOnlyDictionary + { + private readonly IDictionary _browsers; + + public OwaSupportedBrowsersCollection() + { + _browsers = ConfigSection.OwaSupportedBrowsers.Cast().ToDictionary(x => x.Browser, y => y.Version); + } + + public IEnumerator> GetEnumerator() + { + return _browsers.GetEnumerator(); + } + + IEnumerator IEnumerable.GetEnumerator() + { + return GetEnumerator(); + } + + public int Count + { + get { return _browsers.Count; } + } + + public bool ContainsKey(string browser) + { + return _browsers.ContainsKey(browser); + } + + public bool TryGetValue(string browser, out int version) + { + return _browsers.TryGetValue(browser, out version); + } + + public int this[string browser] + { + get { return ContainsKey(browser) ? _browsers[browser] : 0; } + } + + public IEnumerable Keys + { + get { return _browsers.Keys; } + } + + public IEnumerable Values + { + get { return _browsers.Values; } + } + } +} \ No newline at end of file diff --git a/WebsitePanel/Sources/WebsitePanel.WebDav.Core/Config/IWebDavAppConfig.cs b/WebsitePanel/Sources/WebsitePanel.WebDav.Core/Config/IWebDavAppConfig.cs index 9bb3b4d8..d46df2bd 100644 --- a/WebsitePanel/Sources/WebsitePanel.WebDav.Core/Config/IWebDavAppConfig.cs +++ b/WebsitePanel/Sources/WebsitePanel.WebDav.Core/Config/IWebDavAppConfig.cs @@ -12,5 +12,6 @@ namespace WebsitePanel.WebDav.Core.Config FileIconsDictionary FileIcons { get; } HttpErrorsCollection HttpErrors { get; } OfficeOnlineCollection OfficeOnline { get; } + OwaSupportedBrowsersCollection OwaSupportedBrowsers { get; } } } \ No newline at end of file diff --git a/WebsitePanel/Sources/WebsitePanel.WebDav.Core/Config/WebConfigSections/OwaSupportedBrowsersElement.cs b/WebsitePanel/Sources/WebsitePanel.WebDav.Core/Config/WebConfigSections/OwaSupportedBrowsersElement.cs new file mode 100644 index 00000000..3274af8b --- /dev/null +++ b/WebsitePanel/Sources/WebsitePanel.WebDav.Core/Config/WebConfigSections/OwaSupportedBrowsersElement.cs @@ -0,0 +1,24 @@ +using System.Configuration; + +namespace WebsitePanel.WebDav.Core.Config.WebConfigSections +{ + public class OwaSupportedBrowsersElement : ConfigurationElement + { + private const string BrowserKey = "browser"; + private const string VersionKey = "version"; + + [ConfigurationProperty(BrowserKey, IsKey = true, IsRequired = true)] + public string Browser + { + get { return (string)this[BrowserKey]; } + set { this[BrowserKey] = value; } + } + + [ConfigurationProperty(VersionKey, IsKey = true, IsRequired = true)] + public int Version + { + get { return (int)this[VersionKey]; } + set { this[VersionKey] = value; } + } + } +} \ No newline at end of file diff --git a/WebsitePanel/Sources/WebsitePanel.WebDav.Core/Config/WebConfigSections/OwaSupportedBrowsersElementCollection.cs b/WebsitePanel/Sources/WebsitePanel.WebDav.Core/Config/WebConfigSections/OwaSupportedBrowsersElementCollection.cs new file mode 100644 index 00000000..16bad9a7 --- /dev/null +++ b/WebsitePanel/Sources/WebsitePanel.WebDav.Core/Config/WebConfigSections/OwaSupportedBrowsersElementCollection.cs @@ -0,0 +1,18 @@ +using System.Configuration; + +namespace WebsitePanel.WebDav.Core.Config.WebConfigSections +{ + [ConfigurationCollection(typeof(OwaSupportedBrowsersElement))] + public class OwaSupportedBrowsersElementCollection : ConfigurationElementCollection + { + protected override ConfigurationElement CreateNewElement() + { + return new OwaSupportedBrowsersElement(); + } + + protected override object GetElementKey(ConfigurationElement element) + { + return ((OwaSupportedBrowsersElement)element).Browser; + } + } +} \ No newline at end of file diff --git a/WebsitePanel/Sources/WebsitePanel.WebDav.Core/Config/WebConfigSections/WebDavExplorerConfigurationSettingsSection.cs b/WebsitePanel/Sources/WebsitePanel.WebDav.Core/Config/WebConfigSections/WebDavExplorerConfigurationSettingsSection.cs index 1849b692..a51b9460 100644 --- a/WebsitePanel/Sources/WebsitePanel.WebDav.Core/Config/WebConfigSections/WebDavExplorerConfigurationSettingsSection.cs +++ b/WebsitePanel/Sources/WebsitePanel.WebDav.Core/Config/WebConfigSections/WebDavExplorerConfigurationSettingsSection.cs @@ -15,6 +15,7 @@ namespace WebsitePanel.WebDavPortal.WebConfigSections private const string ConnectionStringsKey = "appConnectionStrings"; private const string SessionKeysKey = "sessionKeys"; private const string FileIconsKey = "fileIcons"; + private const string OwaSupportedBrowsersKey = "owaSupportedBrowsers"; private const string OfficeOnlineKey = "officeOnline"; public const string SectionName = "webDavExplorerConfigurationSettings"; @@ -75,6 +76,13 @@ namespace WebsitePanel.WebDavPortal.WebConfigSections set { this[FileIconsKey] = value; } } + [ConfigurationProperty(OwaSupportedBrowsersKey, IsDefaultCollection = false)] + public OwaSupportedBrowsersElementCollection OwaSupportedBrowsers + { + get { return (OwaSupportedBrowsersElementCollection)this[OwaSupportedBrowsersKey]; } + set { this[OwaSupportedBrowsersKey] = value; } + } + [ConfigurationProperty(OfficeOnlineKey, IsDefaultCollection = false)] public OfficeOnlineElementCollection OfficeOnline { diff --git a/WebsitePanel/Sources/WebsitePanel.WebDav.Core/Config/WebDavAppConfigManager.cs b/WebsitePanel/Sources/WebsitePanel.WebDav.Core/Config/WebDavAppConfigManager.cs index 01eebf42..f6925e5b 100644 --- a/WebsitePanel/Sources/WebsitePanel.WebDav.Core/Config/WebDavAppConfigManager.cs +++ b/WebsitePanel/Sources/WebsitePanel.WebDav.Core/Config/WebDavAppConfigManager.cs @@ -18,6 +18,7 @@ namespace WebsitePanel.WebDav.Core.Config FileIcons = new FileIconsDictionary(); HttpErrors = new HttpErrorsCollection(); OfficeOnline = new OfficeOnlineCollection(); + OwaSupportedBrowsers = new OwaSupportedBrowsersCollection(); } public static WebDavAppConfigManager Instance @@ -51,5 +52,6 @@ namespace WebsitePanel.WebDav.Core.Config public FileIconsDictionary FileIcons { get; private set; } public HttpErrorsCollection HttpErrors { get; private set; } public OfficeOnlineCollection OfficeOnline { get; private set; } + public OwaSupportedBrowsersCollection OwaSupportedBrowsers { get; private set; } } } \ No newline at end of file diff --git a/WebsitePanel/Sources/WebsitePanel.WebDav.Core/Owa/CobaltManager.cs b/WebsitePanel/Sources/WebsitePanel.WebDav.Core/Owa/CobaltManager.cs index b33ae340..74e3af14 100644 --- a/WebsitePanel/Sources/WebsitePanel.WebDav.Core/Owa/CobaltManager.cs +++ b/WebsitePanel/Sources/WebsitePanel.WebDav.Core/Owa/CobaltManager.cs @@ -1,6 +1,8 @@ using System; using System.IO; +using System.Threading; using Cobalt; +using log4net; using WebsitePanel.WebDav.Core.Interfaces.Managers; using WebsitePanel.WebDav.Core.Interfaces.Owa; @@ -11,12 +13,16 @@ namespace WebsitePanel.WebDav.Core.Owa private readonly IWebDavManager _webDavManager; private readonly IWopiFileManager _fileManager; private readonly IAccessTokenManager _tokenManager; + private readonly ILog Log; - public CobaltManager(IWebDavManager webDavManager, IWopiFileManager fileManager, IAccessTokenManager tokenManager) + public CobaltManager(IWebDavManager webDavManager, IWopiFileManager fileManager, + IAccessTokenManager tokenManager) { _webDavManager = webDavManager; _fileManager = fileManager; _tokenManager = tokenManager; + + Log = LogManager.GetLogger(this.GetType()); } public Atom ProcessRequest(int accessTokenId, Stream requestStream) @@ -27,30 +33,69 @@ namespace WebsitePanel.WebDav.Core.Owa var requestBatch = new RequestBatch(); - var cobaltFile = _fileManager.Get(token.FilePath) ?? _fileManager.Create(accessTokenId); - - Object ctx; - ProtocolVersion protocolVersion; - - requestBatch.DeserializeInputFromProtocol(atomRequest, out ctx, out protocolVersion); - - cobaltFile.CobaltEndpoint.ExecuteRequestBatch(requestBatch); - - foreach (var request in requestBatch.Requests) + try { - if (request.GetType() == typeof(PutChangesRequest) && request.PartitionId == FilePartitionId.Content && request.CompletedSuccessfully) - { - using (var saveStream = new MemoryStream()) - { - GenericFdaStream myCobaltStream = new GenericFda(cobaltFile.CobaltEndpoint, null).GetContentStream(); - myCobaltStream.CopyTo(saveStream); + var cobaltFile = _fileManager.Get(token.FilePath) ?? _fileManager.Create(accessTokenId); - _webDavManager.UploadFile(token.FilePath, saveStream.ToArray()); + Object ctx; + ProtocolVersion protocolVersion; + + requestBatch.DeserializeInputFromProtocol(atomRequest, out ctx, out protocolVersion); + cobaltFile.CobaltEndpoint.ExecuteRequestBatch(requestBatch); + + + foreach (var request in requestBatch.Requests) + { + + if (request.GetType() == typeof (PutChangesRequest) && + request.PartitionId == FilePartitionId.Content && request.CompletedSuccessfully) + { + using (var saveStream = new MemoryStream()) + { + CopyStream(cobaltFile, saveStream); + _webDavManager.UploadFile(token.FilePath, saveStream.ToArray()); + } } } + + + return requestBatch.SerializeOutputToProtocol(protocolVersion); } - return requestBatch.SerializeOutputToProtocol(protocolVersion); + catch (Exception e) + { + Log.Error("Cobalt manager Process request", e); + + throw; + } + } + + private void CopyStream(CobaltFile file, Stream stream) + { + var tries = 3; + + for (int i = 0; i < tries; i++) + { + try + { + GenericFdaStream myCobaltStream = new GenericFda(file.CobaltEndpoint, null).GetContentStream(); + + myCobaltStream.CopyTo(stream); + + break; + } + catch (Exception) + { + //unable to read update - save failed + if (i == tries - 1) + { + throw; + } + + //waiting for cobalt completion + Thread.Sleep(50); + } + } } } } \ No newline at end of file diff --git a/WebsitePanel/Sources/WebsitePanel.WebDav.Core/WebsitePanel.WebDav.Core.csproj b/WebsitePanel/Sources/WebsitePanel.WebDav.Core/WebsitePanel.WebDav.Core.csproj index bf910311..f7aa574f 100644 --- a/WebsitePanel/Sources/WebsitePanel.WebDav.Core/WebsitePanel.WebDav.Core.csproj +++ b/WebsitePanel/Sources/WebsitePanel.WebDav.Core/WebsitePanel.WebDav.Core.csproj @@ -104,6 +104,7 @@ + @@ -114,6 +115,8 @@ + + diff --git a/WebsitePanel/Sources/WebsitePanel.WebDavPortal/App_Start/RouteConfig.cs b/WebsitePanel/Sources/WebsitePanel.WebDavPortal/App_Start/RouteConfig.cs index bf2fe2a4..f089cdbd 100644 --- a/WebsitePanel/Sources/WebsitePanel.WebDavPortal/App_Start/RouteConfig.cs +++ b/WebsitePanel/Sources/WebsitePanel.WebDavPortal/App_Start/RouteConfig.cs @@ -38,6 +38,12 @@ namespace WebsitePanel.WebDavPortal defaults: new { controller = "FileSystem", action = "UploadFile" } ); + routes.MapRoute( + name: FileSystemRouteNames.DownloadFile, + url: "download-file/{org}/{*pathPart}", + defaults: new { controller = "FileSystem", action = "DownloadFile" } + ); + routes.MapRoute( name: FileSystemRouteNames.ShowOfficeOnlinePath, url: "office365/{org}/{*pathPart}", diff --git a/WebsitePanel/Sources/WebsitePanel.WebDavPortal/Controllers/Api/OwaController.cs b/WebsitePanel/Sources/WebsitePanel.WebDavPortal/Controllers/Api/OwaController.cs index d2d84295..f557a237 100644 --- a/WebsitePanel/Sources/WebsitePanel.WebDavPortal/Controllers/Api/OwaController.cs +++ b/WebsitePanel/Sources/WebsitePanel.WebDavPortal/Controllers/Api/OwaController.cs @@ -105,6 +105,12 @@ namespace WebsitePanel.WebDavPortal.Controllers.Api return new HttpResponseMessage(HttpStatusCode.OK); } + [HttpPost] + public HttpResponseMessage Refresh_Lock(int accessTokenId) + { + return new HttpResponseMessage(HttpStatusCode.OK); + } + [HttpPost] public HttpResponseMessage UnLock(int accessTokenId) { diff --git a/WebsitePanel/Sources/WebsitePanel.WebDavPortal/Controllers/FileSystemController.cs b/WebsitePanel/Sources/WebsitePanel.WebDavPortal/Controllers/FileSystemController.cs index 28b6e19f..3f06482d 100644 --- a/WebsitePanel/Sources/WebsitePanel.WebDavPortal/Controllers/FileSystemController.cs +++ b/WebsitePanel/Sources/WebsitePanel.WebDavPortal/Controllers/FileSystemController.cs @@ -116,6 +116,26 @@ namespace WebsitePanel.WebDavPortal.Controllers return PartialView("_ResourseCollectionPartial", result); } + [HttpGet] + public ActionResult DownloadFile(string org, string pathPart) + { + if (org != WspContext.User.OrganizationId) + { + return new HttpStatusCodeResult(HttpStatusCode.NoContent); + } + + string fileName = pathPart.Split('/').Last(); + + if (_webdavManager.IsFile(pathPart) == false) + { + throw new Exception(Resources.NotAFile); + } + + var fileBytes = _webdavManager.GetFileBytes(pathPart); + + return File(fileBytes, MediaTypeNames.Application.Octet, fileName); + } + [HttpPost] public ActionResult UploadFile(string org, string pathPart) { diff --git a/WebsitePanel/Sources/WebsitePanel.WebDavPortal/FileOperations/FileOpenerManager.cs b/WebsitePanel/Sources/WebsitePanel.WebDavPortal/FileOperations/FileOpenerManager.cs index 1310e0ba..07ae4558 100644 --- a/WebsitePanel/Sources/WebsitePanel.WebDavPortal/FileOperations/FileOpenerManager.cs +++ b/WebsitePanel/Sources/WebsitePanel.WebDavPortal/FileOperations/FileOpenerManager.cs @@ -1,5 +1,7 @@ using System.Collections.Generic; using System.Linq; +using System.Net; +using System.Web; using WebsitePanel.WebDav.Core.Config; using WebsitePanel.WebDavPortal.Extensions; @@ -20,10 +22,23 @@ namespace WebsitePanel.WebDavPortal.FileOperations get { FileOpenerType result; - if (_operationTypes.TryGetValue(fileExtension, out result)) + if (_operationTypes.TryGetValue(fileExtension, out result) && CheckBrowserSupport()) return result; return FileOpenerType.Download; } } + + private bool CheckBrowserSupport() + { + var request = HttpContext.Current.Request; + int supportedVersion; + + if (WebDavAppConfigManager.Instance.OwaSupportedBrowsers.TryGetValue(request.Browser.Browser, out supportedVersion) == false) + { + return false; + } + + return supportedVersion <= request.Browser.MajorVersion; + } } } \ No newline at end of file diff --git a/WebsitePanel/Sources/WebsitePanel.WebDavPortal/UI/Resources.Designer.cs b/WebsitePanel/Sources/WebsitePanel.WebDavPortal/UI/Resources.Designer.cs index 8b375ced..0722b254 100644 --- a/WebsitePanel/Sources/WebsitePanel.WebDavPortal/UI/Resources.Designer.cs +++ b/WebsitePanel/Sources/WebsitePanel.WebDavPortal/UI/Resources.Designer.cs @@ -159,6 +159,15 @@ namespace WebsitePanel.WebDavPortal.UI { } } + /// + /// Looks up a localized string similar to Not a file.. + /// + public static string NotAFile { + get { + return ResourceManager.GetString("NotAFile", resourceCulture); + } + } + /// /// Looks up a localized string similar to Processing. /// diff --git a/WebsitePanel/Sources/WebsitePanel.WebDavPortal/UI/Resources.resx b/WebsitePanel/Sources/WebsitePanel.WebDavPortal/UI/Resources.resx index 00e0624f..edd8c739 100644 --- a/WebsitePanel/Sources/WebsitePanel.WebDavPortal/UI/Resources.resx +++ b/WebsitePanel/Sources/WebsitePanel.WebDavPortal/UI/Resources.resx @@ -150,6 +150,9 @@ No files are selected. + + Not a file. + Processing diff --git a/WebsitePanel/Sources/WebsitePanel.WebDavPortal/UI/Routes/FileSystemRouteNames.cs b/WebsitePanel/Sources/WebsitePanel.WebDavPortal/UI/Routes/FileSystemRouteNames.cs index 9732a57e..69e435ca 100644 --- a/WebsitePanel/Sources/WebsitePanel.WebDavPortal/UI/Routes/FileSystemRouteNames.cs +++ b/WebsitePanel/Sources/WebsitePanel.WebDavPortal/UI/Routes/FileSystemRouteNames.cs @@ -14,5 +14,7 @@ namespace WebsitePanel.WebDavPortal.UI.Routes public const string UploadFile = "UplaodFIleRoute"; public const string DeleteFiles = "DeleteFilesRoute"; + + public const string DownloadFile = "DownloadFileRoute"; } } \ No newline at end of file diff --git a/WebsitePanel/Sources/WebsitePanel.WebDavPortal/Web.config b/WebsitePanel/Sources/WebsitePanel.WebDavPortal/Web.config index 11c6991f..0ac3e949 100644 --- a/WebsitePanel/Sources/WebsitePanel.WebDavPortal/Web.config +++ b/WebsitePanel/Sources/WebsitePanel.WebDavPortal/Web.config @@ -22,6 +22,7 @@ + @@ -72,6 +73,12 @@ + + + + + +