internal static WopiDiscovery FromXmlDocument(XmlDocument discoveryXml) { if (discoveryXml?.DocumentElement == null) { return(new WopiDiscovery()); } var wd = new WopiDiscovery(); wd.Zones.AddRange(discoveryXml.DocumentElement?.SelectNodes("net-zone")?.Cast <XmlNode>().Where(zn => zn != null) .Select(WopiZone.FromXmlNode) ?? new WopiZone[0]); return(wd); }
public static object GetWopiData(Content content, string action) { if (!(content.ContentHandler is File)) { throw new SnNotSupportedException("Office Online is not supported for this type of content."); } var officeOnlineUrl = Settings.GetValue("OfficeOnline", "OfficeOnlineUrl", content.Path, string.Empty); if (string.IsNullOrEmpty(officeOnlineUrl)) { throw new SnNotSupportedException("Office Online Server setting not found."); } var wd = WopiDiscovery.GetInstance(officeOnlineUrl); if (wd == null || !wd.Zones.Any()) { throw new SnNotSupportedException("Office Online Server not found."); } //TODO: handle internal or external zone urls var wopiApp = wd.Zones["internal-https"]?.GetApp(content.Name, action); var wopiAction = wopiApp?.Actions.GetAction(action, content.Name); if (wopiAction == null) { throw new SnNotSupportedException($"Office Online action '{action}' is not supported on this content."); } // load an existing token or create a new one var token = AccessTokenVault.GetOrAddToken(User.Current.Id, DefaultTokenTimeout, content.Id, WopiHandler.AccessTokenFeatureName); var expiration = Math.Truncate((token.ExpirationDate - new DateTime(1970, 1, 1).ToUniversalTime()).TotalMilliseconds); return(new Dictionary <string, object> { { "accesstoken", token.Value }, { "expiration", expiration }, { "actionUrl", TransformUrl(wopiAction.UrlSrc, content.Id) }, { "faviconUrl", wopiApp.FaviconUrl } }); }
internal static (bool?Forbidden, bool?Visible) InitializeInternal(Content context, string actionType, string officeOnlineUrl) { if (!(context.ContentHandler is File)) { return(true, false); } if (string.IsNullOrEmpty(officeOnlineUrl)) { return(true, false); } var wd = WopiDiscovery.GetInstance(officeOnlineUrl); if (wd == null || !wd.Zones.Any()) { return(true, false); } var extension = System.IO.Path.GetExtension(context.Name)?.Trim('.') ?? string.Empty; if (string.IsNullOrEmpty(extension)) { return(true, false); } var actions = wd.Zones.SelectMany(z => z.Apps).SelectMany(app => app.Actions); if (!actions.Any(act => string.Equals(act.Extension, extension, StringComparison.InvariantCultureIgnoreCase) && string.Equals(act.Name, actionType, StringComparison.InvariantCultureIgnoreCase))) { return(true, false); } return(null, null); }
/// <summary> /// For tests. /// </summary> internal static void AddInstance(string url, WopiDiscovery discovery) { Instances.AddOrUpdate(url.TrimEnd('/'), oosUrl => new Lazy <WopiDiscovery>(() => discovery), (oosUrl, current) => new Lazy <WopiDiscovery>(() => discovery)); }