/// <summary> /// Closes save as dialog /// </summary> /// <returns> /// true: if call worked fine /// false: if an error occurred /// </returns> public bool Close() { Button buttonClose = new SaveAsFileBrowserElements().ButtonClose; if (buttonClose == null) { Log.Error(LogInfo.Namespace(MethodBase.GetCurrentMethod()), "Close button is null"); return(false); } buttonClose.Click(DefaultValues.locDefaultLocation); return(true); }
/// <summary> /// save a file with given filename /// </summary> /// <param name="fileName"> /// filename under which file will be saved /// </param> /// <returns> /// true: if saving was successful /// false: if an error occurred /// </returns> public bool SaveAs(string fileName) { try { bool result = false; string directory = Path.GetDirectoryName(fileName); if (directory == null) { Log.Error(LogInfo.Namespace(MethodBase.GetCurrentMethod()), "System.IO.Path.GetDirectoryName returned null."); this.Close(); } else { if (Directory.Exists(directory) == false) { Log.Error(LogInfo.Namespace(MethodBase.GetCurrentMethod()), "The directory: \"" + directory + "\" does not exist."); this.Close(); } else { if ((new IsSaveAsDialogOpen()).Run()) { Log.Info(LogInfo.Namespace(MethodBase.GetCurrentMethod()), "Dialog is open"); } else { Log.Info(LogInfo.Namespace(MethodBase.GetCurrentMethod()), "Dialog is not open"); } Text text = new SaveAsFileBrowserElements().TextFileName; Button buttonSave = new SaveAsFileBrowserElements().ButtonSave; if (text == null || buttonSave == null) { Log.Error(LogInfo.Namespace(MethodBase.GetCurrentMethod()), "Text field or Save button is null"); this.Close(); } else { text.Click(DefaultValues.locDefaultLocation); text.TextValue = string.Empty; Keyboard.Press(fileName); Keyboard.Press(Keys.Tab); buttonSave.MoveTo(DefaultValues.locDefaultLocation); buttonSave.Click(DefaultValues.locDefaultLocation); // check if File already exists dialog appears, look for ok button Button buttonYes = new MessageElements().buttonYes; if (buttonYes == null) { // saving was successful Log.Info(LogInfo.Namespace(MethodBase.GetCurrentMethod()), "File " + "[" + fileName + "]" + "Saved successfully"); result = true; } else { // button yes available -> file with that filename already exists, replace file dialog appeared, replace file; buttonYes.Click(DefaultValues.locDefaultLocation); Log.Info(LogInfo.Namespace(MethodBase.GetCurrentMethod()), "File " + "[" + fileName + "]" + " already exists, overwriting..."); result = true; } } } } return(result); } catch (Exception exception) { Log.Error(LogInfo.Namespace(MethodBase.GetCurrentMethod()), exception.Message); this.Close(); return(false); } }