DocumentServer/OnlineEditorsExample/DocEditor.aspx.cs
2015-04-29 19:10:50 +03:00

109 lines
3.4 KiB
C#

using System;
using System.IO;
using System.Web;
using System.Web.Configuration;
using System.Web.UI;
using ASC.Api.DocumentConverter;
namespace OnlineEditorsExample
{
public partial class DocEditor : Page
{
public static string FileName;
public static string FileUri
{
get { return _Default.FileUri(FileName); }
}
protected string Key
{
get { return ServiceConverter.GenerateRevisionId(_Default.CurUserHostAddress(null) + "/" + Path.GetFileName(FileUri)); }
}
protected string ValidateKey
{
get { return ServiceConverter.GenerateValidateKey(Key); }
}
protected string DocServiceApiUri
{
get { return WebConfigurationManager.AppSettings["files.docservice.url.api"] ?? string.Empty; }
}
public static string CallbackUrl
{
get
{
var callbackUrl = new UriBuilder(HttpContext.Current.Request.Url)
{
Path =
HttpRuntime.AppDomainAppVirtualPath
+ (HttpRuntime.AppDomainAppVirtualPath.EndsWith("/") ? "" : "/")
+ "webeditor.ashx",
Query = "type=track"
+ "&userAddress=" + HttpUtility.UrlEncode(HttpContext.Current.Request.UserHostAddress)
+ "&fileName=" + HttpUtility.UrlEncode(FileName)
};
return callbackUrl.ToString();
}
}
protected string DocumentType
{
get
{
var ext = Path.GetExtension(FileName).ToLower();
if (FileType.ExtsDocument.Contains(ext)) return "text";
if (FileType.ExtsSpreadsheet.Contains(ext)) return "spreadsheet";
if (FileType.ExtsPresentation.Contains(ext)) return "presentation";
return string.Empty;
}
}
protected void Page_Load(object sender, EventArgs e)
{
var externalUrl = Request["fileUrl"];
if (!string.IsNullOrEmpty(externalUrl))
{
FileName = _Default.DoUpload(externalUrl);
}
else
{
FileName = Request["fileID"];
}
var type = Request["type"];
if (!string.IsNullOrEmpty(type))
{
Try(type);
Response.Redirect("doceditor.aspx?fileID=" + HttpUtility.UrlEncode(FileName));
}
}
private static void Try(string type)
{
string ext;
switch (type)
{
case "document":
ext = ".docx";
break;
case "spreadsheet":
ext = ".xlsx";
break;
case "presentation":
ext = ".pptx";
break;
default:
return;
}
var demoName = "demo" + ext;
FileName = _Default.GetCorrectName(demoName);
File.Copy(HttpRuntime.AppDomainAppPath + "app_data/" + demoName, _Default.StoragePath(FileName, null));
}
}
}