forked from oazabir/codeuml
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathShare.ashx
53 lines (44 loc) · 1.92 KB
/
Share.ashx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
<%@ WebHandler Language="C#" Class="Share" %>
using System;
using System.Web;
public class Share : IHttpHandler {
public void ProcessRequest (HttpContext context) {
string uml = context.Request["uml"];
string url = context.Request["id"];
// Gist.com solution
//System.Xml.Linq.XDocument xml = GistHelper.CreateNewGist("Codeuml diagram", "codeuml.txt", uml);
//var enu = xml.Element("gist").Descendants("raw_url").GetEnumerator();
//if (enu.MoveNext())
//{
// var url = enu.Current.Value;
// context.Response.ContentType = "text/plain";
// context.Response.Write(url);
//}
// Tinyurl.com solution
//using (var client = new System.Net.WebClient())
//{
// var param = new System.Collections.Specialized.NameValueCollection();
// param.Add("is_private", "1");
// param.Add("title", "Codeuml.com Diagram");
// param.Add("paste", uml);
// var xmlDoc = System.Xml.Linq.XDocument.Load(
// new System.IO.StreamReader(
// new System.IO.MemoryStream(
// client.UploadValues("http://tny.cz/api/create.xml", param))));
// var id = xmlDoc.Element("result").Element("response").Value;
// context.Response.ContentType = "text/plain";
// context.Response.Write(id);
//}
// App_Data storage solution
var fileName = string.IsNullOrEmpty(url) ? DateTime.Now.Ticks.ToString() : url.Trim();
var filePath = context.Server.MapPath("~/App_Data/" + fileName);
System.IO.File.WriteAllText(filePath, uml);
context.Response.ContentType = "text/plain";
context.Response.Write(fileName);
}
public bool IsReusable {
get {
return false;
}
}
}