///<summary>Writes or uploads the bytes to the specified file name. Sychronous for cloud storage.</summary> public static void WriteAllBytes(string fileName, byte[] byteArray) { if (CloudStorage.IsCloudStorage) { OpenDentalCloud.Core.TaskStateUpload state = CloudStorage.Upload(Path.GetDirectoryName(fileName), Path.GetFileName(fileName), byteArray); } else //Not cloud { File.WriteAllBytes(fileName, byteArray); } }
///<summary>Writes or uploads the text to the specified file name. Sychronous for cloud storage.</summary> public static void WriteAllText(string fileName, string textForFile) { if (CloudStorage.IsCloudStorage) { OpenDentalCloud.Core.TaskStateUpload state = CloudStorage.Upload(Path.GetDirectoryName(fileName), Path.GetFileName(fileName), Encoding.UTF8.GetBytes(textForFile)); } else //Not cloud { File.WriteAllText(fileName, textForFile); } }
///<summary>Writes or uploads the text to the specified file name.</summary> public static void WriteAllText(string fileName, string textForFile, string uploadMessage = "Uploading file") { if (CloudStorage.IsCloudStorage) { FormProgress FormP = CreateFormProgress(uploadMessage); OpenDentalCloud.Core.TaskStateUpload state = CloudStorage.UploadAsync(Path.GetDirectoryName(fileName), Path.GetFileName(fileName), Encoding.UTF8.GetBytes(textForFile), new OpenDentalCloud.ProgressHandler(FormP.OnProgress)); FormP.ShowDialog(); if (FormP.DialogResult == DialogResult.Cancel) { state.DoCancel = true; return; } } else //Not cloud { File.WriteAllText(fileName, textForFile); } }
private void SaveAttachment() { Patient PatCur = Patients.GetPat(PatNum); //if(PatCur.ImageFolder=="") { // MsgBox.Show(this,"Invalid patient image folder."); // return; //} if (PrefC.AtoZfolderUsed == DataStorageType.InDatabase) { MsgBox.Show(this, "Error. Not using AtoZ images folder."); return; } string patfolder = ImageStore.GetPatientFolder(PatCur, ImageStore.GetPreferredAtoZpath()); //ODFileUtils.CombinePaths( //FormPath.GetPreferredImagePath(),PatCur.ImageFolder.Substring(0,1).ToUpper(),PatCur.ImageFolder); //if(!Directory.Exists(patfolder)) { // MsgBox.Show(this,"Patient folder not found in AtoZ folder."); // return; //} Document doc = Docs[gridMain.GetSelectedIndex()]; if (!ImageHelper.HasImageExtension(doc.FileName)) { MsgBox.Show(this, "Invalid file. Only images may be attached, no other file format."); return; } string oldPath = ODFileUtils.CombinePaths(patfolder, doc.FileName); Random rnd = new Random(); string newName = DateTime.Now.ToString("yyyyMMdd") + "_" + DateTime.Now.TimeOfDay.Ticks.ToString() + rnd.Next(1000).ToString() + Path.GetExtension(oldPath); string attachPath = EmailAttaches.GetAttachPath(); string newPath = ODFileUtils.CombinePaths(attachPath, newName); if (CloudStorage.IsCloudStorage) { oldPath = oldPath.Replace("\\", "/"); newPath = newPath.Replace("\\", "/"); } try { if (ImageHelper.HasImageExtension(oldPath)) { if (doc.CropH != 0 || doc.CropW != 0 || doc.CropX != 0 || doc.CropY != 0 || doc.DegreesRotated != 0 || doc.IsFlipped || doc.WindowingMax != 0 || doc.WindowingMin != 0 || CloudStorage.IsCloudStorage) { //this does result in a significantly larger images size if jpg. A later optimization would recompress it. Bitmap bitmapold = null; if (PrefC.AtoZfolderUsed == DataStorageType.LocalAtoZ) { bitmapold = (Bitmap)Bitmap.FromFile(oldPath); Bitmap bitmapnew = ImageHelper.ApplyDocumentSettingsToImage(doc, bitmapold, ImageSettingFlags.ALL); bitmapnew.Save(newPath); } else if (CloudStorage.IsCloudStorage) { //First, download the file. FormProgress FormP = new FormProgress(); FormP.DisplayText = "Downloading Image..."; FormP.NumberFormat = "F"; FormP.NumberMultiplication = 1; FormP.MaxVal = 100; //Doesn't matter what this value is as long as it is greater than 0 FormP.TickMS = 1000; OpenDentalCloud.Core.TaskStateDownload state = CloudStorage.DownloadAsync(patfolder , doc.FileName , new OpenDentalCloud.ProgressHandler(FormP.OnProgress)); FormP.ShowDialog(); if (FormP.DialogResult == DialogResult.Cancel) { state.DoCancel = true; return; } //Successfully downloaded, now do stuff with state.FileContent FormP = new FormProgress(); FormP.DisplayText = "Uploading Image for Claim Attach..."; FormP.NumberFormat = "F"; FormP.NumberMultiplication = 1; FormP.MaxVal = 100; //Doesn't matter what this value is as long as it is greater than 0 FormP.TickMS = 1000; OpenDentalCloud.Core.TaskStateUpload state2 = CloudStorage.UploadAsync(attachPath , newName , state.FileContent , new OpenDentalCloud.ProgressHandler(FormP.OnProgress)); FormP.ShowDialog(); if (FormP.DialogResult == DialogResult.Cancel) { state2.DoCancel = true; return; } //Upload was successful } } else { File.Copy(oldPath, newPath); } } else { File.Copy(oldPath, newPath); } ClaimAttachNew = new ClaimAttach(); ClaimAttachNew.DisplayedFileName = Docs[gridMain.GetSelectedIndex()].FileName; ClaimAttachNew.ActualFileName = newName; DialogResult = DialogResult.OK; } catch (FileNotFoundException ex) { MessageBox.Show(Lan.g(this, "File not found: ") + ex.Message); return; } catch (Exception ex) { MessageBox.Show(ex.Message); } }
private void butImport_Click(object sender, EventArgs e) { OpenFileDialog dlg = new OpenFileDialog(); dlg.Multiselect = false; if (dlg.ShowDialog() != DialogResult.OK) { return; } if (!File.Exists(dlg.FileName)) { MsgBox.Show(this, "File does not exist."); return; } if (!ImageHelper.HasImageExtension(dlg.FileName)) { MsgBox.Show(this, "Only allowed to import an image."); return; } string newName = dlg.FileName; if (PrefC.AtoZfolderUsed == DataStorageType.LocalAtoZ) { newName = ODFileUtils.CombinePaths(SheetUtil.GetImagePath(), Path.GetFileName(dlg.FileName)); if (File.Exists(newName)) { MsgBox.Show(this, "A file of that name already exists in SheetImages. Please rename the file before importing."); return; } File.Copy(dlg.FileName, newName); } else if (CloudStorage.IsCloudStorage) { if (CloudStorage.FileExists(ODFileUtils.CombinePaths(SheetUtil.GetImagePath(), Path.GetFileName(dlg.FileName)))) { MsgBox.Show(this, "A file of that name already exists in SheetImages. Please rename the file before importing."); return; } FormProgress FormP = new FormProgress(); FormP.DisplayText = Lan.g(CloudStorage.LanThis, "Uploading..."); FormP.NumberFormat = "F"; FormP.NumberMultiplication = 1; FormP.MaxVal = 100; //Doesn't matter what this value is as long as it is greater than 0 FormP.TickMS = 1000; OpenDentalCloud.Core.TaskStateUpload state = CloudStorage.UploadAsync(SheetUtil.GetImagePath(), Path.GetFileName(dlg.FileName) , File.ReadAllBytes(dlg.FileName) , new OpenDentalCloud.ProgressHandler(FormP.OnProgress)); if (FormP.ShowDialog() == DialogResult.Cancel) { state.DoCancel = true; return; } newName = Path.GetFileName(dlg.FileName); //It would be nice to save the image somewhere so that we don't have to download it again. } FillCombo(); for (int i = 0; i < comboFieldName.Items.Count; i++) { if (comboFieldName.Items[i].ToString() == Path.GetFileName(newName)) { comboFieldName.SelectedIndex = i; comboFieldName.Text = Path.GetFileName(newName); FillImage(); ShrinkToFit(); } } }