add webtestversion
This commit is contained in:
		
							
								
								
									
										156
									
								
								Project/Web/Controller/ResourceController.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										156
									
								
								Project/Web/Controller/ResourceController.cs
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,156 @@ | ||||
| using System; | ||||
| using System.Collections.Generic; | ||||
| using System.Linq; | ||||
| using System.Net; | ||||
| using System.Net.Http; | ||||
| using System.Text; | ||||
| using System.Threading.Tasks; | ||||
| using System.Web.Http; | ||||
|  | ||||
| namespace Project.Web.Controllers | ||||
| { | ||||
|     public class ResourceController : BaseController | ||||
|     { | ||||
|         //[HttpGet] | ||||
|         //public HttpResponseMessage Index() | ||||
|         //{ | ||||
|         //    //로그인이 되어있지않다면 로그인을 가져온다 | ||||
|         //    MethodResult result; | ||||
|         //    result = View(true); | ||||
|  | ||||
|         //    var model = GetGlobalModel(); | ||||
|         //    var getParams = Request.GetQueryNameValuePairs();// GetParameters(data); | ||||
|  | ||||
|         //    //기본값을 찾아서 없애줘야한다 | ||||
|         //    var contents = result.Content; | ||||
|  | ||||
|         //    //공용값 적용 | ||||
|         //    ApplyCommonValue(ref contents); | ||||
|  | ||||
|         //    //최종문자 적용 | ||||
|         //    result.Content = contents; | ||||
|  | ||||
|         //    var resp = new HttpResponseMessage() | ||||
|         //    { | ||||
|         //        Content = new StringContent( | ||||
|         //      result.Content, | ||||
|         //      System.Text.Encoding.UTF8, | ||||
|         //      "text/html") | ||||
|         //    }; | ||||
|  | ||||
|         //    return resp; | ||||
|         //} | ||||
|  | ||||
|         [HttpGet] | ||||
|         public HttpResponseMessage file() | ||||
|         { | ||||
|             var config = RequestContext.Configuration; | ||||
|             var routeData = config.Routes.GetRouteData(Request).Values.ToList(); | ||||
|  | ||||
|             var p_resource = routeData.Where(t => t.Key == "resource").FirstOrDefault(); | ||||
|             var p_path = routeData.Where(t => t.Key == "path").FirstOrDefault(); | ||||
|             var p_ext = routeData.Where(t => t.Key == "ext").FirstOrDefault(); | ||||
|             var p_subdir = routeData.Where(t => t.Key == "subdir").FirstOrDefault(); | ||||
|  | ||||
|             var v_resource = string.Empty; | ||||
|             var v_path = string.Empty; | ||||
|             var v_ext = string.Empty; | ||||
|             var v_subdir = string.Empty; | ||||
|  | ||||
|             if (p_resource.Key == "resource") v_resource = p_resource.Value.ToString(); | ||||
|             if (p_path.Key == "path") v_path = p_path.Value.ToString(); | ||||
|             if (p_ext.Key == "ext") v_ext = p_ext.Value.ToString(); | ||||
|             if (p_subdir.Key == "subdir") v_subdir = p_subdir.Value.ToString(); | ||||
|  | ||||
|             //var file_ext = routeData[0].Value.ToString(); | ||||
|             //var name_resource = routeData[1].Value.ToString() + "." + file_ext; | ||||
|             //var name_action = routeData[3].Value.ToString(); | ||||
|  | ||||
|             Boolean isBinary = true; | ||||
|  | ||||
|  | ||||
|             string content_type = "text/plain"; | ||||
|  | ||||
|             if (v_ext == "json") | ||||
|             { | ||||
|                 isBinary = false; | ||||
|                 content_type = "application/json"; | ||||
|             } | ||||
|             else if(v_ext == "vue") | ||||
|             { | ||||
|                 isBinary = false; | ||||
|                 content_type = "application/js"; | ||||
|             } | ||||
|             else if (v_ext == "js") | ||||
|             { | ||||
|                 isBinary = false; | ||||
|                 content_type = "application/js"; | ||||
|             } | ||||
|             else if (v_ext == "css") | ||||
|             { | ||||
|                 isBinary = false; | ||||
|                 content_type = "text/css"; | ||||
|             } | ||||
|             else if (v_ext == "csv") | ||||
|             { | ||||
|                 isBinary = false; | ||||
|                 content_type = "text/csv"; | ||||
|             } | ||||
|             else if (v_ext == "ico") | ||||
|             { | ||||
|                 isBinary = true; | ||||
|                 content_type = "image/x-icon"; | ||||
|             } | ||||
|             else if(v_ext == "ttf" || v_ext == "otf") | ||||
|             { | ||||
|                 isBinary = true; | ||||
|                 content_type = "application/octet-stream"; | ||||
|             } | ||||
|  | ||||
|             HttpContent resultContent = null; | ||||
|  | ||||
|             if (v_resource.isEmpty() && v_ext.isEmpty()) | ||||
|             { | ||||
|                 v_resource = "index"; | ||||
|                 v_ext = "html"; | ||||
|                 isBinary = false; | ||||
|                 content_type = "text/html"; | ||||
|             } | ||||
|              | ||||
|              | ||||
|  | ||||
|             var file = System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "View", v_path, v_subdir, v_resource + "." + v_ext); | ||||
|  | ||||
|             if (isBinary) | ||||
|             { | ||||
|  | ||||
|                 if (System.IO.File.Exists(file)) | ||||
|                 { | ||||
|                     var buffer = System.IO.File.ReadAllBytes(file); | ||||
|                     resultContent = new ByteArrayContent(buffer); | ||||
|                     Console.WriteLine(">>File(B) : " + file); | ||||
|                 } | ||||
|                 else Console.WriteLine("no resouoir file  " + file); | ||||
|  | ||||
|             } | ||||
|             else | ||||
|             { | ||||
|                 if (System.IO.File.Exists(file)) | ||||
|                 { | ||||
|  | ||||
|                     var buffer = System.IO.File.ReadAllText(file, System.Text.Encoding.UTF8); | ||||
|                     resultContent = new StringContent(buffer, System.Text.Encoding.UTF8, content_type); | ||||
|                     Console.WriteLine(">>File(S) : " + file); | ||||
|                 } | ||||
|                 else Console.WriteLine("no resouoir file  " + file); | ||||
|             } | ||||
|  | ||||
|  | ||||
|             return new HttpResponseMessage() | ||||
|             { | ||||
|                 Content = resultContent | ||||
|             }; | ||||
|  | ||||
|         } | ||||
|     } | ||||
| } | ||||
		Reference in New Issue
	
	Block a user
	 backuppc
					backuppc