public Save ( string filePath ) : void | ||
filePath | string | The file path. Uses the original source file path if not provided. |
Résultat | void |
/// <summary> /// Loads the applications from disk. /// </summary> public void LoadApplications() { ApplicationToManageCB.Items.Clear(); // add the recent files. foreach (string filePath in Utils.GetRecentFileList(m_groupName)) { AddApplicationToManage(new FileInfo(filePath)); } // load the config files for any OPC applications. string configDir = Utils.GetAbsoluteDirectoryPath("%LocalApplicationData%\\OPC Foundation\\Applications", false, false, true); if (configDir != null) { foreach (FileInfo fileInfo in new DirectoryInfo(configDir).GetFiles("*.xml")) { AddApplicationToManage(fileInfo); } } // add the standard applications. foreach (string fileName in s_StandardApplications) { string filePath = Utils.FindInstalledFile(fileName); if (!String.IsNullOrEmpty(filePath)) { ManagedApplication application = new ManagedApplication(); application.SetExecutableFile(filePath); bool found = false; foreach (ManagedApplication item in ApplicationToManageCB.Items) { if (item.ExecutablePath != null) { if (String.Compare(item.ExecutablePath, application.ExecutablePath, StringComparison.OrdinalIgnoreCase) == 0) { found = true; break; } } } if (!found) { application.Save(configDir + "\\" + application.DisplayName + ".xml"); AddApplicationToManage(application); } } } // select the first item. if (ApplicationToManageCB.Items.Count > 0) { ApplicationToManageCB.SelectedIndex = 0; } }
private void OkBTN_Click(object sender, EventArgs e) { try { if (String.IsNullOrEmpty(ApplicationNameTB.Text)) { MessageBox.Show("Application Name must be specified.", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Error); return; } // set source file. string filePath = null; if (m_application.SourceFile != null) { filePath = m_application.SourceFile.FullName; } else { filePath = Utils.GetAbsoluteDirectoryPath("%LocalApplicationData%\\OPC Foundation\\Applications\\", false, false, true); filePath += ApplicationNameTB.Text; filePath += ".xml"; } // check if exists. if (File.Exists(filePath)) { if (MessageBox.Show("File exists. Overwrite?", this.Text, MessageBoxButtons.YesNo, MessageBoxIcon.Question) != DialogResult.Yes) { return; } } // save the file. m_application.DisplayName = ApplicationNameTB.Text; m_application.ExecutablePath = ExecutableFileTB.Text; m_application.ConfigurationPath = ConfigurationFileTB.Text; m_application.Certificate = m_certificate; m_application.TrustList = m_trustList; m_application.Save(filePath); DialogResult = DialogResult.OK; } catch (Exception exception) { GuiUtils.HandleException(this.Text, System.Reflection.MethodBase.GetCurrentMethod(), exception); } }
/// <summary> /// Loads the applications from disk. /// </summary> public void LoadApplications() { ApplicationToManageCB.Items.Clear(); // add the recent files. foreach (string filePath in Utils.GetRecentFileList(m_groupName)) { AddApplicationToManage(new FileInfo(filePath)); } // load the config files for any OPC applications. string configDir = Utils.GetAbsoluteDirectoryPath("%LocalApplicationData%\\OPC Foundation\\Applications", false, false, true); if (configDir != null) { foreach (FileInfo fileInfo in new DirectoryInfo(configDir).GetFiles("*.xml")) { AddApplicationToManage(fileInfo); } } // add the standard applications. foreach (string fileName in s_StandardApplications) { string filePath = Utils.FindInstalledFile(fileName); if (!String.IsNullOrEmpty(filePath)) { ManagedApplication application = new ManagedApplication(); application.SetExecutableFile(filePath); bool found = false; foreach (ManagedApplication item in ApplicationToManageCB.Items) { if (item.ExecutablePath != null) { if (String.Compare(item.ExecutablePath, application.ExecutablePath, StringComparison.OrdinalIgnoreCase) == 0) { found = true; break; } } } if (!found) { application.Save(configDir + "\\" + application.DisplayName + ".xml"); AddApplicationToManage(application); } } } // select the first item. if (ApplicationToManageCB.Items.Count > 0) { ApplicationToManageCB.SelectedIndex = 0; } }