//when user press the save button, it will automatically call the S3Uploader class. //In that class, we are storing the file into the aws bucket protected void save_Click(object sender, EventArgs e) { SaveText(); S3Uploader s3 = new S3Uploader(); s3.UploadFile(); }
private static Button CreateUploadToS3Button(S3Uploader s3Uploader, Func <Control> parent, ObservableCollection <S3File> s3Files) { var uploadFileToS3 = new Button { Text = "Upload" }; uploadFileToS3.Click += (sender, args) => { using (var ofd = new OpenFileDialog() { CheckFileExists = true }) { var result = ofd.ShowDialog(parent()); if (result == DialogResult.Ok) { if (File.Exists(ofd.FileName)) { var s3 = s3Uploader.GetS3Client(); using (var fs = File.OpenRead(ofd.FileName)) { var uploadPath = S3Uploader.StoreForLaterAccess(s3, fs, Path.GetFileName(ofd.FileName)); s3Files.Add(uploadPath); } } } } }; return(uploadFileToS3); }
public EventController(ApplicationDbContext db, UserManager <ApplicationUser> userManager, IHostingEnvironment enviroment) { uploader = new S3Uploader(); this.enviroment = enviroment; this.dB = db; this.userManager = userManager; }
public S3FileGridPresenter(S3Uploader s3Uploader) { S3Files = new ObservableCollection <S3File>(); Grid = new Lazy <GridView>(() => CreateS3FilesGrid(s3Uploader, S3Files)); UploadToS3 = new Lazy <Func <Func <Control>, Button> >(() => (control => CreateUploadToS3Button(s3Uploader, control, S3Files))); RefreshS3Files = new Lazy <Button>(() => CreateRefreshS3FilesButton(Grid, s3Uploader, S3Files)); DeleteS3Files = new Lazy <Button>(() => CreateDeleteS3FilesButton(Grid, s3Uploader, S3Files)); }
//----- params ----- //----- field ----- //----- property ----- //----- method ----- public static async Task <bool> Upload(S3Uploader uploader) { var exportPath = MasterGenerator.GetExportDirectory(); if (string.IsNullOrEmpty(exportPath)) { Debug.LogError("Export path is empty."); return(false); } // バージョンファイルから作成時のコミットハッシュを取得. var versionFilePath = PathUtility.Combine(exportPath, MasterGenerator.VersionFileName); if (!File.Exists(versionFilePath)) { Debug.LogErrorFormat("VersionFile not found.\n{0}", versionFilePath); return(false); } var commitHash = string.Empty; using (var streamReader = new StreamReader(versionFilePath, Encoding.UTF8, false)) { commitHash = await streamReader.ReadLineAsync(); } if (string.IsNullOrEmpty(commitHash)) { Debug.LogError("CommitHash not found."); return(false); } // アップロード. var sw = System.Diagnostics.Stopwatch.StartNew(); var result = await uploader.Execute(exportPath, commitHash); sw.Stop(); using (new DisableStackTraceScope()) { if (result) { Debug.LogFormat("Upload Complete. ({0:F2}sec)\n\nVersion: {1}", sw.Elapsed.TotalSeconds, commitHash); } else { Debug.LogError("Upload Failed."); } } return(result); }
private static Button CreateRefreshS3FilesButton(Lazy <GridView> uploader, S3Uploader s3Uploader, ObservableCollection <S3File> s3Files) { var refreshS3Files = new Button { Text = "Refresh" }; refreshS3Files.Click += (sender, args) => { var gv = uploader.Value; var s = gv.SelectedItems.ToList(); s3Uploader.RefreshFiles(s3Files); }; return(refreshS3Files); }
private static Button CreateDeleteS3FilesButton(Lazy <GridView> uploader, S3Uploader s3Uploader, ObservableCollection <S3File> s3Files) { var deleteS3Files = new Button { Text = "Delete" }; deleteS3Files.Click += (sender, args) => { var gv = uploader.Value; var selectedItems = gv.SelectedItems.Cast <S3File>().ToList(); s3Uploader.DeleteFiles(selectedItems); s3Uploader.RefreshFiles(s3Files); }; return(deleteS3Files); }
private static GridView CreateS3FilesGrid(S3Uploader s3Uploader, ObservableCollection <S3File> s3Files) { var s3FilesGrid = new GridView { DataStore = s3Files, AllowColumnReordering = true }; s3FilesGrid.Columns.Add(new GridColumn { DataCell = new TextBoxCell { Binding = Binding.Property <S3File, string>(r => r.Key) }, HeaderText = "Key" }); s3FilesGrid.Columns.Add(new GridColumn { DataCell = new TextBoxCell { Binding = Binding.Property <S3File, String>(r => r.AgeInDaysString) }, HeaderText = "Age" }); s3FilesGrid.Columns.Add(new GridColumn { DataCell = new CheckBoxCell { Binding = Binding.Property <S3File, bool?>(r => r.Check) }, HeaderText = "Check" }); s3FilesGrid.CellClick += (sender, args) => { if (args.Column == 2) { ((S3File)args.Item).Check = !((S3File)args.Item).Check; } else { using (Clipboard clipboard = new Clipboard()) { clipboard.Text = s3Uploader.GetPublicUri(((S3File)args.Item).Key).ToString(); } } }; return(s3FilesGrid); }
static void Main(string[] args) { S3Uploader s3 = new S3Uploader(); s3.UploadFile(); }
async void Analyze_Clicked(System.Object sender, System.EventArgs e) { CognitoAWSCredentials credentials = new CognitoAWSCredentials( AWS.IdentityPoolId, RegionEndpoint.USEast1 ); S3Uploader uploader = new S3Uploader(credentials); string bucketName = "babytech-images"; string keyName = patient.PatientID + ".jpg"; await uploader.UploadFileAsync(bucketName, keyName, PhotoPath); AmazonRekognitionClient rekognitionClient = new AmazonRekognitionClient(credentials, Amazon.RegionEndpoint.USEast1); DetectFacesRequest detectFacesRequest = new DetectFacesRequest() { Image = new Amazon.Rekognition.Model.Image() { S3Object = new S3Object { Bucket = bucketName, Name = keyName } }, Attributes = new List <String>() { "ALL" } }; try { DetectFacesResponse detectFacesResponse = await rekognitionClient.DetectFacesAsync(detectFacesRequest); foreach (FaceDetail face in detectFacesResponse.FaceDetails) { // check if mouth is open if ((face.MouthOpen != null) && (face.MouthOpen.Value)) { FacialAnalysisData += "\n❌ Baby's mouth should be closed"; } if ((face.MouthOpen != null) && (!face.MouthOpen.Value) && (face.EyesOpen.Confidence > 0.88F)) { FacialAnalysisData += "\n✔ Baby's mouth should be closed"; } // check if eyes are open if ((face.EyesOpen != null) && (face.EyesOpen.Value)) { FacialAnalysisData += "\n✔ Baby's eyes should be open"; } if ((face.EyesOpen != null) && (!face.EyesOpen.Value) && (face.EyesOpen.Confidence > 0.93F)) { FacialAnalysisData += "\n❌ Baby's eyes should be open"; } // check for eyeglasses if ((face.Eyeglasses != null) && (face.Eyeglasses.Value)) { FacialAnalysisData += "\n❌ Baby should not be wearing eyeglasses"; } if ((face.Eyeglasses != null) && (!face.Eyeglasses.Value)) { FacialAnalysisData += "\n✔ Baby should not be wearing eyeglasses"; } //check brightness if ((face.Quality.Brightness != null) && (face.Quality.Brightness > 0.61F) && (face.Quality.Brightness < 0.97F)) { FacialAnalysisData += "\n✔ Picture is acceptable brightness"; } else { FacialAnalysisData += "\n❌ Picture is acceptable brightness"; } //check sharpness if ((face.Quality.Sharpness != null) && (face.Quality.Sharpness > 0.67F)) { FacialAnalysisData += "\n✔ Picture is acceptable sharpness"; } else { FacialAnalysisData += "\n❌ Picture is acceptable sharpness"; } // check for smile if ((face.Smile != null) && (face.Smile.Value) && (face.Smile.Confidence < 0.83F)) { FacialAnalysisData += "\n❌ Baby should not be smiling"; } if ((face.Eyeglasses != null) && (!face.Eyeglasses.Value)) { FacialAnalysisData += "\n✔ Baby should not be smiling"; } // check for calm expression Emotion calmEmotion = face.Emotions.Find(emotion => emotion.Type == "CALM"); if (calmEmotion.Confidence > 0.93F) { FacialAnalysisData += "\n ✔ Baby should have a neutral facial expression"; } else { FacialAnalysisData += "\n ❌ BBaby should have a neutral facial expression"; } //check sharpness if ((face.Quality.Sharpness != null) && (face.Quality.Sharpness > 0.67F)) { FacialAnalysisData += "\n✔ Picture is acceptable sharpness"; } else { FacialAnalysisData += "\n❌ Picture is acceptable sharpness"; } //check brightness if ((face.Quality.Brightness != null) && (face.Quality.Brightness > 0.61F) && (face.Quality.Brightness < 0.97F)) { FacialAnalysisData += "\n✔ Picture is acceptable brightness"; } else { FacialAnalysisData += "\n❌ Picture is acceptable brightness"; } } await DisplayAlert("Analysis Results", FacialAnalysisData, "OK"); } catch (Exception exception) { Console.WriteLine(exception.Message); } }
public AccountController(UserManager <ApplicationUser> userManager, ApplicationDbContext context) { this.userManager = userManager; applicationDbContext = context; s3uploader = new S3Uploader(); }