public void CloseSketch() { if (apexSketch != null) { AxExchange2XControl1.AxExchange2X existingApex = (AxExchange2XControl1.AxExchange2X)apexSketch.Controls["apexExchange"]; //apexSketch.SketchState = "12"; if (existingApex != null)// && existingApex.InterruptCode != 2729) { bool isExisted = false; foreach (Process processList in Process.GetProcesses()) { //if (processList.ProcessName.Contains("apexwin5p")) //{ // if (existingApex.Tag != null && processList.MainWindowTitle.ToUpper().Contains(existingApex.Tag.ToString().Trim().ToUpper())) // { // isExisted = true; // break; // } //} if (processList.ProcessName.Contains("apexwin5p")) { //if (existingApex.Tag != null && processList.MainWindowTitle.ToUpper().Contains(existingApex.Tag.ToString().Trim().ToUpper())) if (existingApex.Tag != null && processList.Id.Equals(existingApex.Tag)) { isExisted = true; break; } } } if (isExisted) { existingApex.Focus(); existingApex.Select(); // existingApex.SaveFile(); //existingApex.CloseSketch(); existingApex.CloseApex(); this.ApexPanel.Controls.Remove(apexSketch); if (apexSketch != null) { apexSketch = null; } } else { this.ApexPanel.Controls.Remove(apexSketch); apexSketch = null; this.Close(); } } else { this.ApexPanel.Controls.Remove(apexSketch); apexSketch = null; this.Close(); } } }
private void F3205_Load(object sender, EventArgs e) { try { if (this.FormPermissionFields.openPermission) { flagLoadOnProcess = true; if (apexSketch != null) { AxExchange2XControl1.AxExchange2X existingApex = (AxExchange2XControl1.AxExchange2X)apexSketch.Controls["apexExchange"]; existingApex.CloseApex(); } if (!TerraScanCommon.IsFieldUser) { this.ApexSketchData = this.form3205Controll.WorkItem.F3205pcgetSketchFilePath(this.keyId, TerraScanCommon.UserId); if (this.ApexSketchData.F3205pcgetSketchFilePath.Rows.Count > 0) { string ApexFilePath = this.ApexSketchData.F3205pcgetSketchFilePath.Rows[0][0].ToString(); Uri uriAddress2 = new Uri(ApexFilePath); //FileInfo f = new FileInfo(ApexFilePath); //if (!uriAddress2.IsLoopback) //{ // string[] path = ApexFilePath.Split('\\'); // int length = path.Length; // int param = path[length - 1].Length; // int FileLength = ApexFilePath.Length; // if (length < 5) // { // MessageBox.Show("There was Error in Creating Apex File UNC File Path.", "TerraScan", MessageBoxButtons.OK, MessageBoxIcon.Information); // } // else // { // this.ApexPathFolder = ApexFilePath.Remove(FileLength - (param), param); // FileIOPermission f2 = new FileIOPermission(FileIOPermissionAccess.Write, this.ApexPathFolder); // f2.AllFiles = FileIOPermissionAccess.Write; // string Permission = f2.AllFiles.ToString(); // if (Permission.Equals("NoAccess")) // { // MessageBox.Show("There was Error in Creating Apex File.", "TerraScan", MessageBoxButtons.OK, MessageBoxIcon.Information); // } // else // { // this.ApexPanel.Controls.Add(apexSketch); // apexSketch = new ApexSketch(); // apexSketch.FilePath = this.ApexSketchData.F3205pcgetSketchFilePath.Rows[0][0].ToString(); // sketchCount = 1; // apexSketch.ApexSaveImage += new ApexSketch.SaveImageHandler(apexSketch_ApexSaveImage); // apexSketch.ApexFormClosed += new ApexSketch.CloseEventHandler(apexSketch_ApexFormClosed); // flagLoadOnProcess = false; // } // } //} //else //{ if (!uriAddress2.IsLoopback) { string[] path = ApexFilePath.Split('\\'); int length = path.Length; int param = path[length - 1].Length; int FileLength = ApexFilePath.Length; if (length < 5) { MessageBox.Show("There was Error in Creating Apex File UNC File Path.", "TerraScan T2", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { this.ApexPathFolder = ApexFilePath; this.ApexPathFolder = ApexFilePath.Remove(FileLength - (param + 1), param + 1); bool permission = HasWritePermissionOnDir(this.ApexPathFolder); if (permission) { this.ApexPanel.Controls.Add(apexSketch); apexSketch = new ApexSketch(); apexSketch.FilePath = this.ApexSketchData.F3205pcgetSketchFilePath.Rows[0][0].ToString(); sketchCount = 1; apexSketch.ApexSaveImage += new ApexSketch.SaveImageHandler(apexSketch_ApexSaveImage); apexSketch.ApexFormClosed += new ApexSketch.CloseEventHandler(apexSketch_ApexFormClosed); apexSketch.InterLogEvent += new ApexSketch.InterruptEventLogging(apexSketch_InterLogEvent); flagLoadOnProcess = false; // Code added to dispose object to avoid exception on immediate close on apex load // while trying to close apex without its initialization completes if (((AxExchange2XControl1.AxExchange2X)apexSketch.Controls["apexExchange"]).ApplicationStatus != null && ((AxExchange2XControl1.AxExchange2X)apexSketch.Controls["apexExchange"]).ApplicationStatus.ToUpper().Equals("CLOSED")) { AxExchange2XControl1.AxExchange2X existingApex = (AxExchange2XControl1.AxExchange2X)apexSketch.Controls["apexExchange"]; this.ApexPanel.Controls.Remove(apexSketch); apexSketch = null; this.Close(); } } } } } } else { this.ApexSketchData = this.form3205Controll.WorkItem.F3205pcgetSketchFilePath(this.keyId, TerraScanCommon.UserId); if (this.ApexSketchData.F3205pcgetSketchFilePath.Rows.Count > 0) { string ApexFilePath = this.ApexSketchData.F3205pcgetSketchFilePath.Rows[0][0].ToString(); string SpecialPath = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData); string tempPath1 = SpecialPath + @"\Terrascan Attachment\Apex Path\" + ApexFilePath; this.ApexPathFolder = SpecialPath + @"\Terrascan Attachment\Apex Path"; this.ApexPanel.Controls.Add(apexSketch); apexSketch = new ApexSketch(); apexSketch.FilePath = tempPath1; sketchCount = 1; apexSketch.ApexSaveImage += new ApexSketch.SaveImageHandler(apexSketch_ApexSaveImage); apexSketch.ApexFormClosed += new ApexSketch.CloseEventHandler(apexSketch_ApexFormClosed); apexSketch.InterLogEvent += new ApexSketch.InterruptEventLogging(apexSketch_InterLogEvent); flagLoadOnProcess = false; // Code added to dispose object to avoid exception on immediate close on apex load // while trying to close apex without its initialization completes if (((AxExchange2XControl1.AxExchange2X)apexSketch.Controls["apexExchange"]).ApplicationStatus != null && ((AxExchange2XControl1.AxExchange2X)apexSketch.Controls["apexExchange"]).ApplicationStatus.ToUpper().Equals("CLOSED")) { AxExchange2XControl1.AxExchange2X existingApex = (AxExchange2XControl1.AxExchange2X)apexSketch.Controls["apexExchange"]; this.ApexPanel.Controls.Remove(apexSketch); apexSketch = null; this.Close(); } } } } } catch (Exception ex) { if (ex.Message.Equals("Method failed with unexpected error code 53.")) { MessageBox.Show("Please provide the specific Network path to create apex file", "Terrascan T2", MessageBoxButtons.OK, MessageBoxIcon.Warning); } else if (ex.Message.Equals("Attempted to perform an unauthorized operation.")) { MessageBox.Show("Please provide the folder permission to create apex file", "Terrascan T2", MessageBoxButtons.OK, MessageBoxIcon.Warning); } else { ExceptionManager.ManageException(ex, ExceptionManager.ActionType.JustLog, this); MessageBox.Show("There was an error launching the Apex Sketch module. It may not have been installed properly. Please contact T2 Support for further assistance.", "TerraScan – Error opening Apex", MessageBoxButtons.OK, MessageBoxIcon.Warning); this.Close(); } } }