static void Run(string[] args, bool verboseShow) { // Dependency Injection to reuse all stuff developed so far IKernel kernel = new StandardKernel(); DependencyInjection(kernel); // service initializatons var _albumInstanceDetailSvc = kernel.Get <IAlbumInstanceDetailService>(); var _albumInstanceSvc = kernel.Get <IAlbumInstanceService>(); var _memberSvc = kernel.Get <IMemberService>(); //class variable intializations string MatchFolderPath, MatchFile; IEnumerable <UserAlbumInstanceDetail> batchPhotos = _albumInstanceDetailSvc.GetPhotosForBatchProcssing(); Console.WriteLine("About to process {0} records", batchPhotos.Count().ToString()); if (batchPhotos.Count() > 0) { if (verboseShow) { Console.WriteLine("Total records retrieved for processing : {0}", batchPhotos.Count().ToString()); } foreach (UserAlbumInstanceDetail batchPhoto in batchPhotos) { long ticks = DateTime.Now.Ticks; if (verboseShow) { Console.WriteLine("Ticks-{0} : Processig record AlbumInstanceKey : {1}, MmeberKey : {2}, FaceToFind : {3}....", ticks.ToString(), batchPhoto.UserAlbumInstanceKey, batchPhoto.MemberKey, batchPhoto.FaceImage); } UserAlbumInstance photoImage = null; Member member = null; FindMatchResult findMatchResult = null; MatchFolderPath = MatchFile = ""; photoImage = _albumInstanceSvc.FindAlbumInstance(batchPhoto.UserAlbumInstanceKey); member = _memberSvc.FindMember(batchPhoto.MemberKey); MatchInput matchInput = new MatchInput(); matchInput.FindInFile = new FileInfo(photoImage.AbsolutePath); matchInput.MatchFile = new FileInfo(member.AbsoultePath + batchPhoto.FaceImage); matchInput.WebFolderPath = photoImage.FolderPath + "MatchFiles"; if (verboseShow) { Console.WriteLine(JsonConvert.SerializeObject(matchInput, Formatting.Indented)); } try { findMatchResult = BruteForceMatcher.FindMatchInSource(matchInput); } catch (Exception e) { Console.WriteLine("Error processing AlbumInstanceKey : {0}", batchPhoto.UserAlbumInstanceKey); Console.Error.WriteLine("Exception"); Console.Error.WriteLine(e.Message); Console.Error.WriteLine("Inner Exception"); Console.Error.WriteLine(e.InnerException.ToString()); } finally { if (findMatchResult != null) { if (findMatchResult.Matched) { batchPhoto.FaceMatchFile = findMatchResult.MatchedFaceFile; } batchPhoto.Inliers = findMatchResult.Inliers; batchPhoto.OpenCVMethod = findMatchResult.OpenCvMethod; batchPhoto.FaceFound = findMatchResult.Matched; batchPhoto.FolderPath = findMatchResult.FolderPath; batchPhoto.AbsolutePath = findMatchResult.AbsolutePath; batchPhoto.ProcessedOn = DateTime.Now; batchPhoto.Processed = true; _albumInstanceDetailSvc.Update(batchPhoto); if (verboseShow) { Console.WriteLine("Ticks-{0} : Processed successfully AlbumInstanceKey : {1}, MmeberKey : {2}, FaceToFind : {3}....", ticks.ToString(), batchPhoto.UserAlbumInstanceKey, batchPhoto.MemberKey, batchPhoto.FaceImage); } } } } } }
public async Task <AddAlbumAndPhotosResult> AddAlbumAndPhotos() { Album _albumRec = new Album(); //IEnumerable<FileInfoAddPhotos> fileInfos; IEnumerable <FileInfo> fileInfos; FaceDetection.FaceDetetctResult faceRes = new FaceDetection.FaceDetetctResult(); try { //--- insert record in to Member table and create a directory - before reading the file ------------- _albumRec.Name = "Name"; _albumRec.Description = "Description"; _albumRec.DisplayOrder = 0; _albumRec.IsAttached = false; _albumRec.UserKey = _userSvc.UserDetails(User.Identity.Name).Key; _albumRec.Created = DateTime.Now; _albumSvc.Insert(_albumRec); string subPath = _albumRec.Key.ToString(); // your code goes here bool exists = System.IO.Directory.Exists(ServerUploadFolderAlbum + subPath); if (!exists) { System.IO.Directory.CreateDirectory(ServerUploadFolderAlbum + subPath); } //------------------------------------------------------------------------------------------------------- var streamProvider = new CustomMultipartFormDataStreamProvider(ServerUploadFolderAlbum + subPath); await Request.Content.ReadAsMultipartAsync(streamProvider); fileInfos = streamProvider.FileData.Select(entry => { FileInfo fileInfo = new FileInfo(entry.LocalFileName); return(fileInfo); }); //---------------------------- open cv routine to do face detection ------------------------------- // done in a batch // ---------- insert into albuminstances table for teh photos added in a loop ----------------------- if (fileInfos.Count() > 0) { foreach (FileInfo fileInfo in fileInfos) { UserAlbumInstance _albumInstance = new UserAlbumInstance(); _albumInstance.AlbumKey = _albumRec.Key; _albumInstance.PhotoFile = fileInfo.Name; _albumInstance.PhotoId = Guid.Parse(fileInfo.Name.Substring(0, 36).ToString()); _albumInstance.FolderPath = "/UserContent/Album/" + _albumRec.Key + "/"; _albumInstance.AbsolutePath = fileInfo.FullName; _albumInstance.IsActive = true; _albumInstance.AnyFacesTagged = false; _albumInstance.PhotosSized = false; _albumInstance.FacesDetected = 0; _albumInstance.FileUploadStatus = "Success"; _albumInstance.IpAddress = HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"]; _albumInstance.OriginalFile = fileInfo.Name.Substring(37); _albumInstance.ImageType = fileInfo.Extension; _albumInstance.Created = DateTime.Now; _albumInstanceSvc.Insert(_albumInstance, _albumRec.UserKey); } } if (fileInfos.Count() > 0) { //-------------------Face detection successful and continue ---------------------------- _albumRec.Name = streamProvider.FormData["Name"]; _albumRec.Description = streamProvider.FormData["Description"]; _albumRec.DisplayOrder = string.IsNullOrEmpty(streamProvider.FormData["DisplayOrder"]) ? 0 : Convert.ToInt32(streamProvider.FormData["DisplayOrder"]); _albumRec.SetupEmail = User.Identity.Name; _albumRec.IsAttached = true; _albumRec.Remarks = "In Last session " + fileInfos.Count().ToString() + " uploaded on " + DateTime.UtcNow.ToString(); _albumRec.LastUpdated = DateTime.Now; _albumSvc.Update(_albumRec); } return(new AddAlbumAndPhotosResult { IsAddOk = true, FileNames = "Total of " + fileInfos.Count().ToString() + " has been added", ErrorMsg = "", UpdatedTimestamp = DateTime.UtcNow, MemberId = _albumRec.UserKey.ToString() }); } catch (Exception ex) { if (_albumRec.Key > 0) { _albumSvc.Delete(_albumRec); } return(new AddAlbumAndPhotosResult { IsAddOk = false, FileNames = string.Empty, ErrorMsg = ex.Message, UpdatedTimestamp = DateTime.UtcNow, MemberId = _albumRec.UserKey.ToString() }); } }