public static ActionResult SendConfig(this HttpListenerResponse response, ConfigResponse r) { //buffer 100kb byte[] buffer = new byte[r.BufferSize]; //content type response.ContentType = "text/xml"; StringBuilder sb = new StringBuilder(); sb.AppendLine(@"<?xml version=""1.0"" encoding=""UTF-8""?>"); sb.AppendLine(@"<video>"); sb.AppendLine(@" <result>suee</result>"); //framecount string framecount = ""; //src string src = "400"; //time length string timelength = ""; //calculate totallength int total = 0; foreach (Video v in r.Videos) { total += v.Length; } timelength = total.ToString(); //get config from file if (!string.IsNullOrEmpty(r.TimeLength)) timelength = r.TimeLength; if (!string.IsNullOrEmpty(r.FrameCount)) framecount = r.FrameCount; if (!string.IsNullOrEmpty(r.Src)) src = r.Src; //generate XML file sb.AppendLine(@" <timelength>" + timelength + "</timelength>"); sb.AppendLine(@" <framecount>" + framecount + "</framecount>"); sb.AppendLine(@" <vname><![CDATA[]]></vname>"); sb.AppendLine(@" <src>" + src + "</src>"); //append every video foreach (Video v in r.Videos) { sb.AppendLine(@" <durl>"); sb.AppendLine(@" <order>" + v.Order.ToString() + "</order>"); sb.AppendLine(@" <length>" + v.Length.ToString() + "</length>"); //generate filename if (v.FileName.StartsWith("http://", StringComparison.CurrentCultureIgnoreCase)) { sb.AppendLine(@" <url><![CDATA[" + v.FileName + "]]></url>"); } else { string p = Path.IsPathRooted(v.FileName) ? v.FileName : Path.Combine(r.StartupPath, v.FileName); p = r.ServerUrl + (r.ServerUrl.EndsWith("/") ? "" : "/") + "?local=true&file=" + Tools.ToBase64StringForUrl(p); sb.AppendLine(@" <url><![CDATA[" + p + "]]></url>"); } sb.AppendLine(@" </durl>"); } sb.AppendLine(@" <vtags><![CDATA[..]]></vtags>"); sb.AppendLine(@" <ad><![CDATA[]]></ad>"); sb.AppendLine(@" <vstr><![CDATA[]]></vstr>"); sb.AppendLine(@" <vip><![CDATA[]]></vip>"); sb.AppendLine(@" <vround></vround>"); sb.AppendLine(@" <pd></pd>"); sb.AppendLine(@"</video>"); string doc = sb.ToString(); //open output stream using (var net = response.OutputStream) { using (Stream st = new MemoryStream(r.Encode.GetBytes(doc))) { while (true) { int count = st.Read(buffer, 0, buffer.Length); if (count <= 0) break; net.Write(buffer, 0, count); } } }//end write return ActionResult.Handled; }
public static ActionResult SendConfig(this HttpListenerResponse response, ConfigResponse r) { //buffer 100kb byte[] buffer = new byte[r.BufferSize]; //content type response.ContentType = "text/xml"; StringBuilder sb = new StringBuilder(); sb.AppendLine(@"<?xml version=""1.0"" encoding=""UTF-8""?>"); sb.AppendLine(@"<video>"); sb.AppendLine(@" <result>suee</result>"); //framecount string framecount = ""; //src string src = "400"; //time length string timelength = ""; //calculate totallength int total = 0; foreach (Video v in r.Videos) { total += v.Length; } timelength = total.ToString(); //get config from file if (!string.IsNullOrEmpty(r.TimeLength)) { timelength = r.TimeLength; } if (!string.IsNullOrEmpty(r.FrameCount)) { framecount = r.FrameCount; } if (!string.IsNullOrEmpty(r.Src)) { src = r.Src; } //generate XML file sb.AppendLine(@" <timelength>"+ timelength + "</timelength>"); sb.AppendLine(@" <framecount>"+ framecount + "</framecount>"); sb.AppendLine(@" <vname><![CDATA[]]></vname>"); sb.AppendLine(@" <src>"+ src + "</src>"); //append every video foreach (Video v in r.Videos) { sb.AppendLine(@" <durl>"); sb.AppendLine(@" <order>"+ v.Order.ToString() + "</order>"); sb.AppendLine(@" <length>"+ v.Length.ToString() + "</length>"); //generate filename if (v.FileName.StartsWith("http://", StringComparison.CurrentCultureIgnoreCase)) { sb.AppendLine(@" <url><![CDATA["+ v.FileName + "]]></url>"); } else { string p = Path.IsPathRooted(v.FileName) ? v.FileName : Path.Combine(r.StartupPath, v.FileName); p = r.ServerUrl + (r.ServerUrl.EndsWith("/") ? "" : "/") + "?local=true&file=" + Tools.ToBase64StringForUrl(p); sb.AppendLine(@" <url><![CDATA["+ p + "]]></url>"); } sb.AppendLine(@" </durl>"); } sb.AppendLine(@" <vtags><![CDATA[..]]></vtags>"); sb.AppendLine(@" <ad><![CDATA[]]></ad>"); sb.AppendLine(@" <vstr><![CDATA[]]></vstr>"); sb.AppendLine(@" <vip><![CDATA[]]></vip>"); sb.AppendLine(@" <vround></vround>"); sb.AppendLine(@" <pd></pd>"); sb.AppendLine(@"</video>"); string doc = sb.ToString(); //open output stream using (var net = response.OutputStream) { using (Stream st = new MemoryStream(r.Encode.GetBytes(doc))) { while (true) { int count = st.Read(buffer, 0, buffer.Length); if (count <= 0) { break; } net.Write(buffer, 0, count); } } } //end write return(ActionResult.Handled); }