static void Main() { if (!VerifyConfiguration()) { Console.ReadLine(); return; } // Init. CloudStorageAccount storageAccount = CloudStorageAccount.Parse(ConfigurationManager.ConnectionStrings["AzureWebJobsStorage"].ConnectionString); Storage.Init(storageAccount); InputImageModel.Init(storageAccount); ImageProcessJobModel.Init(storageAccount); // App Serviceでは必要なくできる。d:\home参照 // Utils.Storage.DownLoadContents(storageAccount); // example.. // System.IO.Stream stream = Storage.DownloadFileToStream("hoge.jpg"); // ImageProcessor.execute(stream); // // Console.WriteLine("Init queue"); // Init(storageAccount); Console.WriteLine("Waiting queue. run and block.."); JobHostConfiguration config = new JobHostConfiguration(); config.Queues.MaxPollingInterval = TimeSpan.FromMilliseconds(500); JobHost host = new JobHost(config); host.RunAndBlock(); }
// POST api/file public async Task <IEnumerable <InputImageDTO> > Post() { var tempPath = Path.GetTempPath(); var provider = new MultipartFormDataStreamProvider(tempPath); await this.Request.Content.ReadAsMultipartAsync(provider); var list = new List <InputImageDTO>(); foreach (var file in provider.FileData) { // アップロードファイル名の取得 // var fileName = file.Headers.ContentDisposition.FileName; // fileName = fileName.StartsWith("\"") || fileName.StartsWith("'") ? fileName.Substring(1, fileName.Length - 1) : fileName; // fileName = fileName.EndsWith("\"") || fileName.EndsWith("'") ? fileName.Substring(0, fileName.Length - 1) : fileName; // fileName = Path.GetFileName(fileName); // ファイル名は乱数を入れておく Guid g = System.Guid.NewGuid(); string imageId = g.ToString("N").Substring(0, 15); // ファイルの移動 // File.Move(file.LocalFileName, Path.Combine("C:\\temp\\", fileName)); BlobModel.Upload(imageId, file.LocalFileName); InputImageModel.Create(imageId); list.Add(new InputImageDTO() { ImageId = imageId }); } return(list); }
public static void Register(HttpConfiguration config) { // Web API configuration and services // Model init CloudStorageAccount storageAccount = CreateStorageAccountFromConnectionString(CloudConfigurationManager.GetSetting("StorageConnectionString")); BlobModel.Init(storageAccount); QueueModel.Init(storageAccount); ImageProcessJobModel.Init(storageAccount); InputImageModel.Init(storageAccount); // Web API routes config.MapHttpAttributeRoutes(); config.Routes.MapHttpRoute( name: "DefaultApi", routeTemplate: "api/{controller}/{id}", defaults: new { id = RouteParameter.Optional } ); }
// GET api/file/{id} public HttpResponseMessage Get(string id) { HttpResponseMessage response = Request.CreateResponse(); InputImageEntity imageEntry = InputImageModel.Get(id); if (imageEntry == null) { return(this.Request.CreateResponse(HttpStatusCode.NotFound)); } MemoryStream ms = new MemoryStream(); BlobModel.Download(id, ms); response.Content = new ByteArrayContent(ms.ToArray()); // only jpeg response.Content.Headers.TryAddWithoutValidation("Content-Type", "image/jpeg"); return(response); }
// POST api/processing public async Task <JobOrderDTO> Post([FromBody] ProcessOrderDTO processOrderDTO) { InputImageEntity imageEntity = InputImageModel.Get(processOrderDTO.ImageId); if (imageEntity == null) { // return this.Request.CreateResponse(HttpStatusCode.NotFound); return(null); } Guid g = System.Guid.NewGuid(); string orderId = g.ToString("N").Substring(0, 15); ImageProcessJobModel.Crate(orderId, imageEntity.RowKey); // send job QueueModel.SendMessage(orderId, processOrderDTO.ImageId, "default"); return(new JobOrderDTO() { OrderId = orderId }); }