/// <summary> /// Tests the connection of the selected profile. /// </summary> private void TestConnection() { try { Cursor = Cursors.WaitCursor; DeploymentProfile profile = ctrlProfileSelector.SelectedProfile; if (profile != null) { ConnectionSettings connSettings = profile.ConnectionSettings.Clone(); connSettings.ScadaInstance = instance.Name; IAgentClient agentClient = new AgentWcfClient(connSettings); bool testResult = agentClient.TestConnection(out string errMsg); Cursor = Cursors.Default; if (testResult) { ScadaUiUtils.ShowInfo(AppPhrases.ConnectionOK); } else { ScadaUiUtils.ShowError(errMsg); } } } catch (Exception ex) { Cursor = Cursors.Default; appData.ProcError(ex, AppPhrases.TestConnectionError); } }
/// <summary> /// Uploads the configuration. /// </summary> private bool UploadConfig(DeploymentProfile profile) { string configFileName = GetTempFileName(); try { Cursor = Cursors.WaitCursor; DateTime t0 = DateTime.UtcNow; // prepare an archive ImportExport importExport = new ImportExport(); importExport.ExportToArchive(configFileName, project, instance, profile.UploadSettings); FileInfo configFileInfo = new FileInfo(configFileName); long configFileSize = configFileInfo.Length; // upload the configuration ConnectionSettings connSettings = profile.ConnectionSettings.Clone(); connSettings.ScadaInstance = instance.Name; IAgentClient agentClient = new AgentWcfClient(connSettings); agentClient.UploadConfig(configFileName, profile.UploadSettings.ToConfigOpions()); // restart the services if (profile.UploadSettings.RestartServer && (profile.UploadSettings.IncludeBase || profile.UploadSettings.IncludeServer)) { agentClient.ControlService(ServiceApp.Server, ServiceCommand.Restart); } if (profile.UploadSettings.RestartComm && (profile.UploadSettings.IncludeBase || profile.UploadSettings.IncludeComm)) { agentClient.ControlService(ServiceApp.Comm, ServiceCommand.Restart); } // show result Cursor = Cursors.Default; ScadaUiUtils.ShowInfo(string.Format(AppPhrases.UploadConfigComplete, Math.Round((DateTime.UtcNow - t0).TotalSeconds), configFileSize)); return(true); } catch (Exception ex) { Cursor = Cursors.Default; appData.ProcError(ex, AppPhrases.UploadConfigError); return(false); } finally { // delete temporary file try { File.Delete(configFileName); } catch { } } }
/// <summary> /// Downloads the configuration. /// </summary> private bool DownloadConfig(DeploymentProfile profile) { string configFileName = GetTempFileName(); try { Cursor = Cursors.WaitCursor; DateTime t0 = DateTime.UtcNow; // download the configuration ConnectionSettings connSettings = profile.ConnectionSettings.Clone(); connSettings.ScadaInstance = instance.Name; IAgentClient agentClient = new AgentWcfClient(connSettings); agentClient.DownloadConfig(configFileName, profile.DownloadSettings.ToConfigOpions()); // import the configuration ImportExport importExport = new ImportExport(); importExport.ImportArchive(configFileName, project, instance, out ConfigParts foundConfigParts); FileInfo configFileInfo = new FileInfo(configFileName); long configFileSize = configFileInfo.Length; // set the modification flags BaseModified = foundConfigParts.HasFlag(ConfigParts.Base); InterfaceModified = foundConfigParts.HasFlag(ConfigParts.Interface); InstanceModified = foundConfigParts.HasFlag(ConfigParts.Server) || foundConfigParts.HasFlag(ConfigParts.Comm) || foundConfigParts.HasFlag(ConfigParts.Web); // show result Cursor = Cursors.Default; ScadaUiUtils.ShowInfo(string.Format(AppPhrases.DownloadConfigComplete, Math.Round((DateTime.UtcNow - t0).TotalSeconds), configFileSize)); return(true); } catch (Exception ex) { Cursor = Cursors.Default; appData.ProcError(ex, AppPhrases.DownloadConfigError); return(false); } finally { // delete temporary file try { File.Delete(configFileName); } catch { } } }