2012-10-12 4 views
2

업로드 된 이미지 파일을 세 가지 크기로 변환하는 컨트롤러 업로드 방법이 있습니다. 파일이 업로드되고 그리고 당신은에 필드를 추가해야합니다 변환이 정지 방법의 끝이 하나가 내가이ASP.Net MVC에서 메서드의 시작 시간과 종료 시간을 얻는 방법은 무엇입니까?

 this is my controller 


      public ActionResult Upload() 
    { 
     //ViewBag.ProcessingTime = DateTime.Now; 
     return View(); 
    } 

     [HttpPost] 
     public ActionResult Uploading(ImageModel model) 
     { 
      if (ModelState.IsValid) 
      { 

       Console.WriteLine("time is"+System.DateTime.Now); 

       string fileName = Guid.NewGuid().ToString() + System.DateTime.Now.ToString("yyyy/MM/dd/hh/mm/ss/fff"); 
       string serverPath = Server.MapPath("~"); 
       string imagesPath = serverPath + "Content\\Images\\"; 
       string thumsise = Path.Combine(imagesPath, "Thumb" + fileName); 
       string thumbPath = Path.Combine(imagesPath, "Thu" + fileName); 
       //string thumbPath = imagesPath + "Thumb\\"; 
       string fullPath = Path.Combine(imagesPath, "Full" + fileName); 
       //string fullPath = imagesPath + "Full\\"; 
       // string Bigpath = imagesPath + "big\\"; 
       string Bigpath = Path.Combine(imagesPath, "big" + fileName); 
       string Bigpatha = Path.Combine(imagesPath, "biga" + fileName); 
       string Bigpathb = Path.Combine(imagesPath, "bigb" + fileName); 
       //string Bigpatha = imagesPath + "biga\\"; 
       //string Bigpathb = imagesPath + "bigb\\"; 
       string Bigpathc = Path.Combine(imagesPath, "bigc" + fileName); 
       //string Bigpathc = imagesPath + "bigc\\"; 
       //var firstSize = Path.Combine(uploadFolder, "bigsize-" + Path.GetFileName(uploadedFile)); 
       ImageModel.ResizeAndSave(thumsise, fileName, model.ImageUploaded.InputStream, 80, true); 
       ImageModel.ResizeAndSave(thumbPath, fileName, model.ImageUploaded.InputStream, 100, true); 
       ImageModel.ResizeAndSave(fullPath, fileName, model.ImageUploaded.InputStream, 500, true); 
       ImageModel.ResizeAndSave(Bigpath, fileName, model.ImageUploaded.InputStream, 200, true); 
       ImageModel.ResizeAndSave(Bigpatha, fileName, model.ImageUploaded.InputStream, 250, true); 
       ImageModel.ResizeAndSave(Bigpathb, fileName, model.ImageUploaded.InputStream, 150, true); 
       ImageModel.ResizeAndSave(Bigpathc, fileName, model.ImageUploaded.InputStream, 50, true); 
       Console.WriteLine("Time is " + System.DateTime.Now); 
      } 
      Console.WriteLine("Time is "+System.DateTime.Now); 

      Console.ReadLine(); 
      return View(); 
     } 

답변

0

을 할 수있는 방법을 말해 줄 수있을 때 나는에서 소요되는 시간을 DISPALY하려는 Model :

public DateTime StartTime { get; set; } 
public DateTime OperatingTime { get; set; } 
public DateTime EndTime { get; set; } 

그런 다음 적절하게 각을 할당, 즉에서 다음 StartTime = DateTime.Now;

당신의 View :

추가

나는 개인적으로 바람직하게는 당신의 ImageModel 클래스, 새로운 방법으로 업로드 이미지 기능을 래핑합니다. 당신은 할 수 : model.UploadImage(fileName, imagePath);

0

은 다음 스톱워치를 재설정 할 수있는 여러 타이밍의 스톱워치

var stopwatch = new Stopwatch(); 
    stopwatch.Start();  
    //whatever you want to time 
    stopwatch.Stop(); 
    var result1 = string.Format("{0} to run whatever ", 
           stopwatch.Elapsed.ToString()); 
    Console.WriteLine(result1); 

를 사용하여 첫 번째와 비슷한 더 타이밍을한다.

+0

"무엇이든지 실행하려면 {0}"해야합니까? – SoftwareNerd

+0

{0}은 (는) stopwatch.Elapsed.ToString()으로 바뀝니다. 원한다면 당신의 콘솔을 사용하도록 업데이트하겠습니다. – dove

관련 문제