Exemplo n.º 1
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);
            }
        }
Exemplo n.º 2
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);
            }
        }