private void FrmDownloadConfig_Load(object sender, EventArgs e)
        {
            Translator.TranslateForm(this, "Scada.Admin.App.Controls.Deployment.CtrlProfileSelector");
            Translator.TranslateForm(this, "Scada.Admin.App.Controls.Deployment.CtrlTransferSettings");
            Translator.TranslateForm(this, "Scada.Admin.App.Forms.Deployment.FrmDownloadConfig");

            if (ScadaUtils.IsRunningOnMono)
            {
                int ctrlWidth = btnClose.Right - ctrlProfileSelector.Left;
                ctrlProfileSelector.Width  = ctrlWidth;
                ctrlTransferSettings.Width = ctrlWidth;
            }

            ProfileChanged       = false;
            ConnSettingsModified = false;
            BaseModified         = false;
            InterfaceModified    = false;
            InstanceModified     = false;

            ctrlTransferSettings.Disable();
            ctrlProfileSelector.Init(appData, project.DeploymentSettings, instance);

            initialProfile           = ctrlProfileSelector.SelectedProfile;
            initialConnSettings      = initialProfile?.ConnectionSettings.Clone();
            downloadSettingsModified = false;
        }
Exemple #2
0
        private void btnDeleteProfile_Click(object sender, EventArgs e)
        {
            // delete the selected profile
            if (MessageBox.Show(AppPhrases.ConfirmDeleteProfile, CommonPhrases.QuestionCaption,
                                MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question) == DialogResult.Yes)
            {
                // remove from the deployment settings
                DeploymentProfile selectedProfile = SelectedProfile;
                deploymentSettings.Profiles.Remove(selectedProfile.Name);

                // remove from the combo box
                try
                {
                    cbProfile.BeginUpdate();
                    int selectedIndex = cbProfile.SelectedIndex;
                    cbProfile.Items.RemoveAt(selectedIndex);

                    if (cbProfile.Items.Count > 0)
                    {
                        cbProfile.SelectedIndex = selectedIndex >= cbProfile.Items.Count ?
                                                  cbProfile.Items.Count - 1 : selectedIndex;
                    }
                }
                finally
                {
                    cbProfile.EndUpdate();
                }

                // save the deployment settings
                SaveDeploymentSettings();
            }
        }
Exemple #3
0
        /// <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);
            }
        }
Exemple #4
0
        private async void timer_Tick(object sender, EventArgs e)
        {
            timer.Stop();

            // initialize a client
            if (agentClient == null)
            {
                DeploymentProfile profile = ctrlProfileSelector.SelectedProfile;
                if (profile != null)
                {
                    ConnectionSettings connSettings = profile.ConnectionSettings.Clone();
                    connSettings.ScadaInstance = instance.Name;
                    agentClient = new AgentWcfClient(connSettings);
                }
            }

            // request status
            if (agentClient != null)
            {
                await GetServerStatusAsync();
                await GetCommStatusAsync();

                if (agentClient != null)
                {
                    timer.Start();
                }
            }
        }
Exemple #5
0
        private void btnEditProfile_Click(object sender, EventArgs e)
        {
            // edit the selected profile
            DeploymentProfile profile = SelectedProfile;
            string            oldName = profile.Name;

            FrmConnSettings frmConnSettings = new FrmConnSettings()
            {
                Profile = profile,
                ExistingProfileNames = deploymentSettings.GetExistingProfileNames(oldName)
            };

            if (frmConnSettings.ShowDialog() == DialogResult.OK)
            {
                // update the profile name if it changed
                if (oldName != profile.Name)
                {
                    deploymentSettings.Profiles.Remove(oldName);

                    try
                    {
                        cbProfile.BeginUpdate();
                        cbProfile.Items.RemoveAt(cbProfile.SelectedIndex);
                        AddProfileToLists(profile);
                    }
                    finally
                    {
                        cbProfile.EndUpdate();
                    }
                }

                // save the deployment settings
                SaveDeploymentSettings();
            }
        }
 public void VerifyNoProfileWithSameName(DeploymentProfile deploymentProfile)
 {
     if (Has(deploymentProfile.Name))
     {
         throw new DeploymentProfileException("Profile " + deploymentProfile.Name + " already exists");
     }
 }
Exemple #7
0
        private void btnOK_Click(object sender, EventArgs e)
        {
            // set the instance profile
            DeploymentProfile profile = ctrlProfileSelector.SelectedProfile;

            instance.DeploymentProfile = profile?.Name ?? "";
            ProfileChanged             = initialProfile != profile;
            DialogResult = DialogResult.OK;
        }
Exemple #8
0
        private void btnConnect_Click(object sender, EventArgs e)
        {
            DeploymentProfile profile = ctrlProfileSelector.SelectedProfile;

            if (profile != null)
            {
                instance.DeploymentProfile = profile.Name;
                Connect();
            }
        }
        private void btnConnect_Click(object sender, EventArgs e)
        {
            DeploymentProfile profile = ctrlProfileSelector.SelectedProfile;

            if (profile != null && profile.AgentEnabled)
            {
                instance.DeploymentProfile = profile.Name;
                ProfileChanged             = IDeploymentForm.ProfilesDifferent(initialProfile, profile);
                Connect();
            }
        }
Exemple #10
0
        /// <summary>
        /// Initializes a new instance of the class.
        /// </summary>
        public FrmInstanceProfile(AppData appData, ScadaProject project, ProjectInstance instance)
            : this()
        {
            this.appData   = appData ?? throw new ArgumentNullException(nameof(appData));
            this.project   = project ?? throw new ArgumentNullException(nameof(project));
            this.instance  = instance ?? throw new ArgumentNullException(nameof(instance));
            initialProfile = null;

            ProfileChanged     = false;
            ConnectionModified = false;
        }
Exemple #11
0
        private void FrmInstanceProfile_Load(object sender, EventArgs e)
        {
            FormTranslator.Translate(this, GetType().FullName);
            FormTranslator.Translate(ctrlProfileSelector, ctrlProfileSelector.GetType().FullName);

            ctrlProfileSelector.Init(appData, project.DeploymentConfig, instance);

            if (ctrlProfileSelector.SelectedProfile != null)
            {
                initialProfile = ctrlProfileSelector.SelectedProfile.DeepClone();
            }
        }
Exemple #12
0
        /// <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 { }
            }
        }
Exemple #13
0
        /// <summary>
        /// Adds the profile to the deployment settings and combo box.
        /// </summary>
        private void AddProfileToLists(DeploymentProfile profile)
        {
            // add to the deployment settings
            deploymentSettings.Profiles.Add(profile.Name, profile);

            // add to the combo box
            int index = deploymentSettings.Profiles.IndexOfKey(profile.Name);

            if (index >= 0)
            {
                cbProfile.Items.Insert(index, profile);
                cbProfile.SelectedIndex = index;
            }
        }
Exemple #14
0
 /// <summary>
 /// Initializes a new instance of the class.
 /// </summary>
 public Uploader(ScadaProject project, ProjectInstance instance, DeploymentProfile profile,
                 ITransferControl transferControl)
 {
     this.project         = project ?? throw new ArgumentNullException(nameof(project));
     this.instance        = instance ?? throw new ArgumentNullException(nameof(instance));
     this.profile         = profile ?? throw new ArgumentNullException(nameof(profile));
     this.transferControl = transferControl ?? throw new ArgumentNullException(nameof(transferControl));
     uploadOptions        = profile.UploadOptions;
     progressTracker      = new ProgressTracker(transferControl)
     {
         TaskCount = TaskCount
     };
     conn = null;
 }
        /// <summary>
        /// Initializes a new instance of the class.
        /// </summary>
        public FrmDownloadConfig(AppData appData, ScadaProject project, ProjectInstance instance)
            : this()
        {
            this.appData            = appData ?? throw new ArgumentNullException(nameof(appData));
            this.project            = project ?? throw new ArgumentNullException(nameof(project));
            this.instance           = instance ?? throw new ArgumentNullException(nameof(instance));
            initialProfile          = null;
            transferOptionsModified = false;

            ProfileChanged     = false;
            ConnectionModified = false;
            BaseModified       = false;
            ViewModified       = false;
            InstanceModified   = false;
        }
Exemple #16
0
        private void FrmInstanceProfile_Load(object sender, EventArgs e)
        {
            Translator.TranslateForm(this, ctrlProfileSelector.GetType().FullName);
            Translator.TranslateForm(this, GetType().FullName);

            if (ScadaUtils.IsRunningOnMono)
            {
                ctrlProfileSelector.Width = btnClose.Right - ctrlProfileSelector.Left;
            }

            ProfileChanged       = false;
            ConnSettingsModified = false;

            ctrlProfileSelector.Init(appData, project.DeploymentSettings, instance);
            initialProfile      = ctrlProfileSelector.SelectedProfile;
            initialConnSettings = initialProfile?.ConnectionSettings.Clone();
        }
        /// <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 { }
            }
        }
Exemple #18
0
        private void btnCreateProfile_Click(object sender, EventArgs e)
        {
            // create a new profile
            DeploymentProfile profile = new DeploymentProfile();

            FrmConnSettings frmConnSettings = new FrmConnSettings()
            {
                Profile = profile,
                ExistingProfileNames = deploymentSettings.GetExistingProfileNames()
            };

            if (frmConnSettings.ShowDialog() == DialogResult.OK)
            {
                AddProfileToLists(profile);
                SaveDeploymentSettings();
            }
        }
Exemple #19
0
        /// <summary>
        /// Initializes a new instance of the class.
        /// </summary>
        public FrmTransfer(AppData appData, ScadaProject project, ProjectInstance instance, DeploymentProfile profile)
            : this()
        {
            this.appData  = appData ?? throw new ArgumentNullException(nameof(appData));
            this.project  = project ?? throw new ArgumentNullException(nameof(project));
            this.instance = instance ?? throw new ArgumentNullException(nameof(instance));
            this.profile  = profile ?? throw new ArgumentNullException(nameof(profile));

            setCancelEnabledAction = b => SetCancelEnabled(b);
            setProgressAction      = d => SetProgress(d);
            setResultAction        = (b, d) => SetResult(b, d);
            logHelper = new RichTextBoxHelper(txtLog);

            extensionLogic  = null;
            uploadMode      = false;
            operationResult = false;
            tokenSource     = null;
        }
Exemple #20
0
        /// <summary>
        /// Initializes a new instance of the class.
        /// </summary>
        public Downloader(AdminDirs appDirs, ScadaProject project, ProjectInstance instance,
                          DeploymentProfile profile, ITransferControl transferControl)
        {
            this.appDirs         = appDirs ?? throw new ArgumentNullException(nameof(appDirs));
            this.project         = project ?? throw new ArgumentNullException(nameof(project));
            this.instance        = instance ?? throw new ArgumentNullException(nameof(instance));
            this.profile         = profile ?? throw new ArgumentNullException(nameof(profile));
            this.transferControl = transferControl ?? throw new ArgumentNullException(nameof(transferControl));
            downloadOptions      = profile.DownloadOptions;
            progressTracker      = new ProgressTracker(transferControl)
            {
                TaskCount = TaskCount
            };

            agentClient   = null;
            tempFileNames = null;
            extractDirs   = null;
        }
Exemple #21
0
        private void ctrlProfileSelector_SelectedProfileChanged(object sender, EventArgs e)
        {
            // display upload settings of the selected profile
            DeploymentProfile profile = ctrlProfileSelector.SelectedProfile;

            if (profile == null)
            {
                ctrlTransferSettings.Disable();
                btnUpload.Enabled = false;
            }
            else
            {
                ctrlTransferSettings.SettingsToControls(profile.UploadSettings);
                btnUpload.Enabled = true;
            }

            uploadSettingsModified = false;
        }
Exemple #22
0
        /// <summary>
        /// Adds the profile to the deployment configuration and combo box.
        /// </summary>
        private void AddProfileToLists(DeploymentProfile profile)
        {
            // add to deployment configuration
            deploymentConfig.Profiles.Add(profile.Name, profile);

            // add to combo box
            int indexToInsert = cbProfile.Items.Count;

            for (int i = 1, cnt = cbProfile.Items.Count; i < cnt; i++)
            {
                if (string.Compare(cbProfile.Items[i].ToString(), profile.Name) > 0)
                {
                    indexToInsert = i;
                    break;
                }
            }

            cbProfile.Items.Insert(indexToInsert, profile);
            cbProfile.SelectedIndex = indexToInsert;
        }
Exemple #23
0
        private void btnUpload_Click(object sender, EventArgs e)
        {
            // validate settings and upload
            DeploymentProfile profile = ctrlProfileSelector.SelectedProfile;

            if (profile != null && ValidateUploadSettings())
            {
                // save the settings changes
                if (uploadSettingsModified)
                {
                    ctrlTransferSettings.ControlsToSettings(profile.UploadSettings);
                    SaveDeploymentSettings();
                }

                // upload
                instance.DeploymentProfile = profile.Name;
                if (UploadConfig(profile))
                {
                    DialogResult = DialogResult.OK;
                }
            }
        }
Exemple #24
0
        private void FrmInstanceStatus_Load(object sender, EventArgs e)
        {
            Translator.TranslateForm(this, ctrlProfileSelector.GetType().FullName);
            Translator.TranslateForm(this, GetType().FullName);

            if (ScadaUtils.IsRunningOnMono)
            {
                ctrlProfileSelector.Width = gbStatus.Width;
            }

            ProfileChanged       = false;
            ConnSettingsModified = false;

            ctrlProfileSelector.Init(appData, deploymentSettings, instance);
            initialProfile      = ctrlProfileSelector.SelectedProfile;
            initialConnSettings = initialProfile?.ConnectionSettings.Clone();
            agentClient         = null;

            if (ctrlProfileSelector.SelectedProfile != null)
            {
                Connect();
            }
        }
        private void btnDownload_Click(object sender, EventArgs e)
        {
            // validate settings and download
            DeploymentProfile profile = ctrlProfileSelector.SelectedProfile;

            if (profile != null && ctrlTransferSettings.ValidateFields())
            {
                // save the settings changes
                if (downloadSettingsModified)
                {
                    ctrlTransferSettings.ControlsToSettings(profile.DownloadSettings);
                    SaveDeploymentSettings();
                }

                // download
                instance.DeploymentProfile = profile.Name;
                if (DownloadConfig(profile))
                {
                    ProfileChanged = initialProfile != profile;
                    DialogResult   = DialogResult.OK;
                }
            }
        }
        public void Save(DeploymentProfile deploymentProfile)
        {
            var profileDirectory = new DirectoryInfo(DeploymentConfiguration.ProfileFolder);

            if (!profileDirectory.Exists)
            {
                profileDirectory.Create();
            }
            var profileFilename = Path.Combine(profileDirectory.FullName, deploymentProfile.Name + ".xml");
            var serializer      = new XmlSerializer(typeof(DeploymentProfile));

            try
            {
                using (var stream = File.Create(profileFilename, 4096, FileOptions.None))
                {
                    serializer.Serialize(stream, deploymentProfile);
                }
            }
            catch (InvalidOperationException e)
            {
                throw new DeploymentProfileException("Could not save " + deploymentProfile.Name, e);
            }
        }
        private void btnCreateProfile_Click(object sender, EventArgs e)
        {
            // create a new profile
            HashSet <string> existingNames      = deploymentSettings.GetExistingProfileNames();
            string           defaultProfileName = string.Format(ProfileNameFormat, instance.Name);

            DeploymentProfile profile = new DeploymentProfile
            {
                InstanceID = instance.ID,
                Name       = existingNames.Contains(defaultProfileName) ? "" : defaultProfileName
            };

            FrmProfileEdit frmProfileEdit = new FrmProfileEdit
            {
                Profile = profile,
                ExistingProfileNames = existingNames
            };

            if (frmProfileEdit.ShowDialog() == DialogResult.OK)
            {
                AddProfileToLists(profile);
                SaveDeploymentSettings();
            }
        }
 /// <summary>
 /// Uploads the configuration.
 /// </summary>
 public override void UploadConfig(ScadaProject project, ProjectInstance instance, DeploymentProfile profile,
                                   ITransferControl transferControl)
 {
     new Uploader(project, instance, profile, transferControl).Upload();
 }
 /// <summary>
 /// Downloads the configuration.
 /// </summary>
 public override void DownloadConfig(ScadaProject project, ProjectInstance instance, DeploymentProfile profile,
                                     ITransferControl transferControl)
 {
     new Downloader(AdminContext.AppDirs, project, instance, profile, transferControl).Download();
 }
Exemple #30
0
 /// <summary>
 /// Initializes a new instance of the class.
 /// </summary>
 public FrmProfileEdit(AppData appData, DeploymentProfile deploymentProfile)
     : this()
 {
     this.appData           = appData ?? throw new ArgumentNullException(nameof(appData));
     this.deploymentProfile = deploymentProfile ?? throw new ArgumentNullException(nameof(deploymentProfile));
 }