Esempio n. 1
0
        /// <summary>
        /// Validates the form fields.
        /// </summary>
        private bool ValidateFields()
        {
            // validate the name
            if (Mode == FormOperatingMode.New)
            {
                string name = InstanceName;

                if (name == "")
                {
                    ScadaUiUtils.ShowError(AppPhrases.InstanceNameEmpty);
                    return(false);
                }

                if (!AdminUtils.NameIsValid(name))
                {
                    ScadaUiUtils.ShowError(AppPhrases.InstanceNameInvalid);
                    return(false);
                }
            }

            // validate the applications
            if (!(ServerAppEnabled || CommAppEnabled || WebAppEnabled))
            {
                ScadaUiUtils.ShowError(AppPhrases.InstanceSelectApps);
                return(false);
            }

            return(true);
        }
Esempio n. 2
0
        /// <summary>
        /// Renames the instance.
        /// </summary>
        public bool Rename(string name, out string errMsg)
        {
            try
            {
                if (!AdminUtils.NameIsValid(name))
                {
                    throw new ArgumentException(AdminPhrases.IncorrectProjectName);
                }

                string        projectDir    = Path.GetDirectoryName(FileName);
                DirectoryInfo directoryInfo = new DirectoryInfo(projectDir);
                string        newProjectDir = Path.Combine(directoryInfo.Parent.FullName, name);

                if (Directory.Exists(newProjectDir))
                {
                    throw new ScadaException(AdminPhrases.ProjectDirectoryExists);
                }

                File.Move(FileName, GetProjectFileName(projectDir, name));
                Directory.Move(projectDir, newProjectDir);
                FileName = GetProjectFileName(newProjectDir, name);

                errMsg = "";
                return(true);
            }
            catch (Exception ex)
            {
                errMsg = AdminPhrases.RenameProjectError + ": " + ex.Message;
                return(false);
            }
        }
Esempio n. 3
0
        /// <summary>
        /// Renames the instance.
        /// </summary>
        public bool Rename(string newName, out string errMsg)
        {
            try
            {
                if (string.IsNullOrEmpty(newName))
                {
                    throw new ArgumentException(AdminPhrases.InstanceNameEmpty, nameof(newName));
                }

                if (!AdminUtils.NameIsValid(newName))
                {
                    throw new ArgumentException(AdminPhrases.InstanceNameInvalid, nameof(newName));
                }

                DirectoryInfo directoryInfo  = new(InstanceDir);
                string        newInstanceDir = Path.Combine(directoryInfo.Parent.FullName, newName);
                directoryInfo.MoveTo(newInstanceDir);
                InstanceDir = newInstanceDir;
                Name        = newName;

                errMsg = "";
                return(true);
            }
            catch (Exception ex)
            {
                errMsg = ex.BuildErrorMessage(AdminPhrases.RenameInstanceError);
                return(false);
            }
        }
Esempio n. 4
0
        /// <summary>
        /// Validates the form controls.
        /// </summary>
        private bool ValidateControls()
        {
            // validate the name when creating a new instance
            if (!EditMode)
            {
                string name = InstanceName;

                if (name == "")
                {
                    ScadaUiUtils.ShowError(AppPhrases.InstanceNameEmpty);
                    return(false);
                }

                if (!AdminUtils.NameIsValid(name))
                {
                    ScadaUiUtils.ShowError(AppPhrases.InstanceNameInvalid);
                    return(false);
                }
            }

            // validate the applications
            if (!(ServerAppEnabled || CommAppEnabled || WebAppEnabled))
            {
                ScadaUiUtils.ShowError(AppPhrases.InstanceSelectApps);
                return(false);
            }

            return(true);
        }
Esempio n. 5
0
        /// <summary>
        /// Creates a new project with the specified parameters.
        /// </summary>
        public static bool Create(string name, string location, string template,
                                  out ScadaProject project, out string errMsg)
        {
            try
            {
                // validate argumants
                if (!AdminUtils.NameIsValid(name))
                {
                    throw new ArgumentException(AdminPhrases.IncorrectProjectName);
                }

                string projectDir = Path.Combine(location, name);

                if (Directory.Exists(projectDir))
                {
                    throw new ScadaException(AdminPhrases.ProjectDirectoryExists);
                }

                // copy template
                FileInfo templateFileInfo = new FileInfo(template);
                string   projectFileName  = GetProjectFileName(projectDir, name);

                if (templateFileInfo.Exists)
                {
                    CopyDirectory(templateFileInfo.Directory, new DirectoryInfo(projectDir));
                    File.Move(Path.Combine(projectDir, templateFileInfo.Name), projectFileName);
                }

                // create project
                project = new ScadaProject {
                    Name = name
                };

                if (File.Exists(projectFileName))
                {
                    // load from template
                    project.Load(projectFileName);
                    project.Description = "";
                }

                project.Save(project.FileName);

                // create the necessary directories
                Directory.CreateDirectory(projectDir);
                Directory.CreateDirectory(project.ConfigBase.BaseDir);
                Directory.CreateDirectory(project.Interface.InterfaceDir);

                errMsg = "";
                return(true);
            }
            catch (Exception ex)
            {
                project = null;
                errMsg  = AdminPhrases.CreateProjectError + ": " + ex.Message;
                return(false);
            }
        }
Esempio n. 6
0
        /// <summary>
        /// Validates the form field.
        /// </summary>
        private bool ValidateFields()
        {
            string fileName = FileName;

            if (fileName == "")
            {
                ScadaUiUtils.ShowError(AppPhrases.FileNameEmpty);
                return(false);
            }

            if (!AdminUtils.NameIsValid(fileName))
            {
                ScadaUiUtils.ShowError(AppPhrases.FileNameInvalid);
                return(false);
            }

            return(true);
        }
Esempio n. 7
0
        /// <summary>
        /// Renames the instance.
        /// </summary>
        public bool Rename(string name, out string errMsg)
        {
            try {
                if (!AdminUtils.NameIsValid(name))
                {
                    throw new ArgumentException("The specified name is incorrect.");
                }

                DirectoryInfo directoryInfo  = new DirectoryInfo(InstanceDir);
                string        newInstanceDir = Path.Combine(directoryInfo.Parent.FullName, name);
                directoryInfo.MoveTo(newInstanceDir);
                InstanceDir = newInstanceDir;
                Name        = name;

                errMsg = "";
                return(true);
            } catch (Exception ex) {
                errMsg = AdminPhrases.RenameInstanceError + ": " + ex.Message;
                return(false);
            }
        }
Esempio n. 8
0
        /// <summary>
        /// Renames the project.
        /// </summary>
        public bool Rename(string newName, out string errMsg)
        {
            try
            {
                if (string.IsNullOrEmpty(newName))
                {
                    throw new ArgumentException(AdminPhrases.ProjectNameEmpty, nameof(newName));
                }

                if (!AdminUtils.NameIsValid(newName))
                {
                    throw new ArgumentException(AdminPhrases.ProjectNameInvalid, nameof(newName));
                }

                string        projectDir    = ProjectDir;
                DirectoryInfo directoryInfo = new(projectDir);
                string        newProjectDir = Path.Combine(directoryInfo.Parent.FullName, newName);

                if (Directory.Exists(newProjectDir))
                {
                    throw new ScadaException(AdminPhrases.ProjectDirectoryExists);
                }

                File.Move(FileName, GetProjectFileName(projectDir, newName));
                Directory.Move(projectDir, newProjectDir);
                FileName = GetProjectFileName(newProjectDir, newName);

                errMsg = "";
                return(true);
            }
            catch (Exception ex)
            {
                errMsg = ScadaUtils.BuildErrorMessage(ex, AdminPhrases.RenameProjectError);
                return(false);
            }
        }
Esempio n. 9
0
        /// <summary>
        /// Validates the form field.
        /// </summary>
        private bool ValidateField()
        {
            string name = ItemName;

            if (name == "")
            {
                ScadaUiUtils.ShowError(AppPhrases.ItemNameEmpty);
                return(false);
            }

            if (!AdminUtils.NameIsValid(name))
            {
                ScadaUiUtils.ShowError(AppPhrases.ItemNameInvalid);
                return(false);
            }

            if (ExistingNames != null && ExistingNames.Contains(name.ToLowerInvariant()))
            {
                ScadaUiUtils.ShowError(AppPhrases.ItemNameDuplicated);
                return(false);
            }

            return(true);
        }
Esempio n. 10
0
        /// <summary>
        /// Creates a new project with the specified parameters.
        /// </summary>
        public static bool Create(string name, string location, string template,
                                  out ScadaProject project, out string errMsg)
        {
            try
            {
                // validate arguments
                if (string.IsNullOrEmpty(name))
                {
                    throw new ArgumentException(AdminPhrases.ProjectNameEmpty, nameof(name));
                }

                if (!AdminUtils.NameIsValid(name))
                {
                    throw new ArgumentException(AdminPhrases.ProjectNameInvalid, nameof(name));
                }

                // define project directory and file
                string projectDir      = Path.Combine(location, name);
                string projectFileName = GetProjectFileName(projectDir, name);

                if (Directory.Exists(projectDir))
                {
                    throw new ScadaException(AdminPhrases.ProjectDirectoryExists);
                }

                // copy template
                if (File.Exists(template))
                {
                    FileInfo templateFileInfo = new(template);
                    CopyDirectory(templateFileInfo.Directory, new DirectoryInfo(projectDir));
                    File.Move(Path.Combine(projectDir, templateFileInfo.Name), projectFileName);
                }

                // create project
                project = new ScadaProject {
                    Name = name
                };

                if (File.Exists(projectFileName))
                {
                    // load from template
                    project.Load(projectFileName);
                    project.Description = "";
                }
                else
                {
                    Directory.CreateDirectory(projectDir);
                    project.FileName = projectFileName;
                }

                project.Save(project.FileName);

                // create necessary directories
                Directory.CreateDirectory(project.ConfigBase.BaseDir);
                Directory.CreateDirectory(project.Views.ViewDir);

                errMsg = "";
                return(true);
            }
            catch (Exception ex)
            {
                project = null;
                errMsg  = ScadaUtils.BuildErrorMessage(ex, AdminPhrases.CreateProjectError);
                return(false);
            }
        }