Beispiel #1
0
        /// <summary>
        /// GET: WopiFrame
        /// </summary>
        /// <param name="id">File name</param>
        /// <returns>A ViewResult object</returns>
        public ActionResult Index(string id)
        {
            string sourceDoc = id.ToLower();
            string uid       = ConfigurationManager.AppSettings["BrowserUserName"].ToLower();

            string access_token = AccessTokenUtil.WriteToken(AccessTokenUtil.GenerateToken(uid, sourceDoc));

            List <WopiAction> actions   = DiscoveryUtil.GetDiscoveryInfo();
            string            extention = sourceDoc.Split('.')[sourceDoc.Split('.').Length - 1];
            WopiAction        action    = actions.FirstOrDefault(i => i.ext == extention && i.name == "view");
            string            urlSrc    = action.urlsrc;

            urlSrc = string.Format("{0}WOPISrc={1}",
                                   urlSrc.Substring(0, urlSrc.IndexOf('<')),
                                   HttpUtility.UrlEncode(string.Format("http://{0}/wopi/files/{1}",
                                                                       ConfigurationManager.AppSettings["WOPIServerName"],
                                                                       HttpUtility.UrlEncode(sourceDoc))));

            urlSrc = urlSrc.ToLower().Replace(ConfigurationManager.AppSettings["OfficeServerName"].ToLower().Trim(), ConfigurationManager.AppSettings["OfficeServerIP"]);

            urlSrc = string.Format("{0}&access_token={1}", urlSrc, HttpUtility.UrlEncode(access_token));

            ViewData["URL"] = urlSrc;

            return(View());
        }
Beispiel #2
0
        /// <summary>
        /// Forms the correct action url for the file and host
        /// </summary>
        public string GetActionUrl(WopiAction action, string fileId, string authority)
        {
            // Initialize the urlsrc
            var urlsrc = action.urlsrc;

            // Look through the action placeholders
            var placeholderCount = 0;

            foreach (var placeholder in WopiUrlPlaceholders.Placeholders)
            {
                if (urlsrc.Contains(placeholder))
                {
                    // Replace the placeholder value accordingly
                    var ph = WopiUrlPlaceholders.GetPlaceholderValue(placeholder);

                    if (!string.IsNullOrEmpty(ph))
                    {
                        urlsrc = urlsrc.Replace(placeholder, ph + "&");
                        placeholderCount++;
                    }
                    else
                    {
                        urlsrc = urlsrc.Replace(placeholder, ph);
                    }
                }
            }

            // Add the WOPISrc to the end of the request
            urlsrc += ((placeholderCount > 0) ? "" : "?") + string.Format("WOPISrc=https://{0}/wopi/files/{1}", authority, fileId);
            return(urlsrc);
        }
Beispiel #3
0
        /// <summary>
        /// Get action URL of a file
        /// </summary>
        /// <param name="action">The action</param>
        /// <param name="fileName">File name</param>
        /// <returns>The URL</returns>
        public static string GetActionUrl(WopiAction action, string fileName)
        {
            string urlSrc = action.urlsrc;

            string access_token = AccessTokenUtil.WriteToken(AccessTokenUtil.GenerateToken(Environment.UserName, fileName.ToLower()));

            urlSrc = string.Format("{0}WOPISrc={1}",
                                   urlSrc.Substring(0, urlSrc.IndexOf('<')),
                                   HttpUtility.UrlEncode(string.Format("http://{0}/wopi/files/{1}", ConfigurationManager.AppSettings["WOPIServerName"], HttpUtility.UrlEncode(fileName))));

            urlSrc = urlSrc.ToLower().Replace(ConfigurationManager.AppSettings["OfficeServerName"].ToLower().Trim(), ConfigurationManager.AppSettings["OfficeServerIP"]);

            urlSrc = string.Format("{0}&access_token={1}", urlSrc, HttpUtility.UrlEncode(access_token));
            return(urlSrc);
        }