示例#1
0
        public bool GenerateTypesSourceCodeFiles(string projectName, IModelData modelData)
        {
            // Verify if model has types
            if (string.IsNullOrEmpty(modelData.Types))
            {
                return(true);
            }

            // Verify types extension
            if (_fileSystem.GetExtension(modelData.Types) != Constants.FileExtension.ModelTypes)
            {
                AppioLogger.Warn(string.Format(LoggingText.NodesetCompilerExecutableFailsInvalidFile, modelData.Types));
                _outputMessage = string.Format(OutputText.GenerateInformationModelFailureInvalidFile, projectName, modelData.Name, modelData.Types);
                return(false);
            }

            // Verify if types file exists
            var typesPath = _fileSystem.CombinePaths(projectName, Constants.DirectoryName.Models, modelData.Types);

            if (!_fileSystem.FileExists(typesPath))
            {
                AppioLogger.Warn(string.Format(LoggingText.NodesetCompilerExecutableFailsMissingFile, typesPath));
                _outputMessage = string.Format(OutputText.GenerateInformationModelFailureMissingFile, projectName, modelData.Name, typesPath);
                return(false);
            }

            // Create a directory for generated C code
            var srcDirectory = _fileSystem.CombinePaths(projectName, Constants.DirectoryName.SourceCode, Constants.DirectoryName.ServerApp);

            CreateDirectoryForGeneratedModelsSourceCode(srcDirectory);

            // Build types source file and target files directories
            var modelName = _fileSystem.GetFileNameWithoutExtension(modelData.Name);
            var typesSourceRelativePath = @"../../" + _fileSystem.CombinePaths(Constants.DirectoryName.Models, modelData.Types);
            var typesTargetRelativePath = _fileSystem.CombinePaths(Constants.DirectoryName.InformationModels, modelName.ToLower());

            // Build types generation script arguments
            var generatedTypesArgs = Constants.ExecutableName.GenerateDatatypesScriptPath +
                                     string.Format(Constants.ExecutableName.GenerateDatatypesTypeBsd, typesSourceRelativePath) +
                                     " " +
                                     typesTargetRelativePath +
                                     Constants.InformationModelsName.Types;

            // Execute types generation script call
            var generatedTypesResult = _fileSystem.CallExecutable(Constants.ExecutableName.PythonScript, srcDirectory, generatedTypesArgs);

            if (!generatedTypesResult)
            {
                AppioLogger.Warn(LoggingText.GeneratedTypesExecutableFails);
                _outputMessage = string.Format(OutputText.GenerateInformationModelGenerateTypesFailure, projectName, modelData.Name, modelData.Types);
                return(false);
            }

            // Add generated types header file to server's meson build
            AdjustServerMesonBuildCFile(srcDirectory, modelName.ToLower() + Constants.InformationModelsName.TypesGenerated);

            return(true);
        }
示例#2
0
        public CommandResult Execute(IEnumerable <string> inputParams)
        {
            var inputParamsArray = inputParams.ToArray();
            var projectName      = inputParamsArray.ElementAtOrDefault(0);
            var outputMessages   = new MessageLines();

            if (string.IsNullOrEmpty(projectName) || !_fileSystem.DirectoryExists(projectName))
            {
                AppioLogger.Warn(LoggingText.BuildProjectDoesNotExist);
                outputMessages.Add(string.Format(OutputText.OpcuaappBuildFailureProjectDoesNotExist, projectName), string.Empty);
                return(new CommandResult(false, outputMessages));
            }

            SetServerHostnameAndPort(projectName);
            SetClientReferenceToServers(projectName);

            var buildDirectory = _fileSystem.CombinePaths(projectName, Constants.DirectoryName.MesonBuild);
            var mesonResult    = _fileSystem.CallExecutable(Constants.ExecutableName.Meson, projectName, Constants.DirectoryName.MesonBuild);

            if (!mesonResult)
            {
                AppioLogger.Warn(LoggingText.MesonExecutableFails);
                outputMessages.Add(OutputText.OpcuaappBuildFailure, string.Empty);

                return(new CommandResult(false, outputMessages));
            }
            var ninjaResult = _fileSystem.CallExecutable(Constants.ExecutableName.Ninja, buildDirectory, string.Empty);

            if (!ninjaResult)
            {
                AppioLogger.Warn(LoggingText.NinjaExecutableFails);
                outputMessages.Add(OutputText.OpcuaappBuildFailure, string.Empty);
                return(new CommandResult(false, outputMessages));
            }

            AppioLogger.Info(LoggingText.BuildSuccess);
            outputMessages.Add(string.Format(OutputText.OpcuaappBuildSuccess, projectName), string.Empty);
            return(new CommandResult(true, outputMessages));
        }
示例#3
0
        public override void Generate(string appName, string filePrefix, uint keySize, uint days, string organization)
        {
            var openSSLConfigBuilder =
                new StringBuilder(_fileSystem.LoadTemplateFile(Resources.Resources.OpenSSLConfigTemplateFileName));

            openSSLConfigBuilder.Replace("$KEY_SIZE", keySize.ToString());
            openSSLConfigBuilder.Replace("$ORG_NAME", organization);
            openSSLConfigBuilder.Replace("$COMMON_NAME", appName);

            var certificateFolder     = _fileSystem.CombinePaths(appName, Constants.DirectoryName.Certificates);
            var certificateConfigPath = _fileSystem.CombinePaths(certificateFolder, Constants.FileName.CertificateConfig);

            try
            {
                _fileSystem.CreateDirectory(certificateFolder);
                _fileSystem.CreateFile(certificateConfigPath, openSSLConfigBuilder.ToString());
            }
            catch (Exception)
            {
                AppioLogger.Warn(string.Format(LoggingText.CertificateGeneratorFailureNonexistentDirectory, appName));
                return;
            }

            var separator = filePrefix == string.Empty ? "" : "_";

            try
            {
                _fileSystem.CallExecutable(Constants.ExecutableName.OpenSSL, certificateFolder, string.Format(Constants.ExternalExecutableArguments.OpenSSL, filePrefix + separator, days));
                _fileSystem.CallExecutable(Constants.ExecutableName.OpenSSL, certificateFolder, string.Format(Constants.ExternalExecutableArguments.OpenSSLConvertKeyFromPEM, filePrefix + separator + Constants.FileName.PrivateKeyPEM, filePrefix + separator + Constants.FileName.PrivateKeyDER));
            }
            catch (Exception)
            {
                AppioLogger.Warn(LoggingText.CertificateGeneratorFailureOpenSSLError);
            }

            _fileSystem.DeleteFile(_fileSystem.CombinePaths(certificateFolder, filePrefix + separator + Constants.FileName.PrivateKeyPEM));
            AppioLogger.Info(string.Format(LoggingText.CertificateGeneratorSuccess, filePrefix == string.Empty ? appName : appName + "/" + filePrefix));
        }
示例#4
0
        private void Import(string directory, bool isPEM, string openSSLArgsFmt, string source, string targetFileName)
        {
            var targetPath = _fileSystem.CombinePaths(directory, targetFileName);

            if (isPEM)
            {
                var openSSLArgs = string.Format(openSSLArgsFmt, source, targetPath);
                _fileSystem.CallExecutable(Constants.ExecutableName.OpenSSL, null, openSSLArgs);
            }
            else
            {
                _fileSystem.CopyFile(source, targetPath);
            }
        }
        public CommandResult Execute(IEnumerable <string> inputParams)
        {
            var projectName = inputParams.ElementAtOrDefault(0);

            var outputMessages = new MessageLines();

            if (string.IsNullOrEmpty(projectName))
            {
                AppioLogger.Warn(LoggingText.EmptyOpcuaappName);
                outputMessages.Add(OutputText.OpcuaappDeployFailure, string.Empty);
                return(new CommandResult(false, outputMessages));
            }

            var projectPublishDirectory  = _fileSystem.CombinePaths(projectName, Constants.DirectoryName.Publish);
            var appClientPublishLocation = _fileSystem.CombinePaths(projectPublishDirectory, Constants.ExecutableName.AppClient);
            var appServerPublishLocation = _fileSystem.CombinePaths(projectPublishDirectory, Constants.ExecutableName.AppServer);

            var projectDeployDirectory = _fileSystem.CombinePaths(projectName, Constants.DirectoryName.Deploy);

            if (!_fileSystem.FileExists(appClientPublishLocation) && !_fileSystem.FileExists(appServerPublishLocation))
            {
                AppioLogger.Warn(LoggingText.MissingPublishedOpcuaAppFiles);
                outputMessages.Add(string.Format(OutputText.OpcuaappDeployWithNameFailure, projectName), string.Empty);
                return(new CommandResult(false, outputMessages));
            }

            // steps
            // create deploy dir
            _fileSystem.CreateDirectory(projectDeployDirectory);

            // create temp dir
            var tempDirectory = _fileSystem.CombinePaths(projectDeployDirectory, Constants.DirectoryName.Temp);

            _fileSystem.CreateDirectory(tempDirectory);

            // create needed installer structure
            var zipSourceLocation = _fileSystem.CombinePaths(projectDeployDirectory, Constants.DirectoryName.Temp, Constants.DirectoryName.OpcuaappInstaller + Constants.FileExtension.ZipFile);

            _fileSystem.ExtractFromZip(zipSourceLocation, tempDirectory, Resources.Resources.InstallerZipResourceName);

            // copy all needed files to temp dir installer source
            if (_fileSystem.FileExists(appClientPublishLocation))
            {
                var appClientDeployTempLocation = _fileSystem.CombinePaths(tempDirectory, Constants.DirectoryName.OpcuaappInstaller, Constants.DirectoryName.Usr, Constants.DirectoryName.Bin, Constants.ExecutableName.AppClient);
                _fileSystem.CopyFile(appClientPublishLocation, appClientDeployTempLocation);
            }
            if (_fileSystem.FileExists(appServerPublishLocation))
            {
                var appServerDeployTempLocation = _fileSystem.CombinePaths(tempDirectory, Constants.DirectoryName.OpcuaappInstaller, Constants.DirectoryName.Usr, Constants.DirectoryName.Bin, Constants.ExecutableName.AppServer);
                _fileSystem.CopyFile(appServerPublishLocation, appServerDeployTempLocation);
            }

            // create installer
            var debianInstallerResult = _fileSystem.CallExecutable(Constants.ExecutableName.CreateDebianInstaller, tempDirectory, Constants.ExecutableName.CreateDebianInstallerArguments);

            if (!debianInstallerResult)
            {
                AppioLogger.Warn(LoggingText.CreateDebianInstallerFails);
                outputMessages.Add(string.Format(OutputText.OpcuaappDeployWithNameFailure, projectName), string.Empty);
                return(new CommandResult(false, outputMessages));
            }

            // move installer to deploy dir
            var installerName        = Constants.DirectoryName.OpcuaappInstaller + Constants.FileExtension.DebianInstaller;
            var createdInstallerPath = _fileSystem.CombinePaths(tempDirectory, installerName);
            var installerTargetPath  = _fileSystem.CombinePaths(projectDeployDirectory, installerName);

            _fileSystem.CopyFile(createdInstallerPath, installerTargetPath);

            // remove temp dir
            _fileSystem.DeleteDirectory(tempDirectory);

            // exit with success result
            AppioLogger.Info(LoggingText.OpcuaappDeploySuccess);
            outputMessages.Add(string.Format(OutputText.OpcuaappDeploySuccess, projectName), string.Empty);
            return(new CommandResult(true, outputMessages));
        }
示例#6
0
        public bool GenerateNodesetSourceCodeFiles(string projectName, IModelData modelData, List <RequiredModelsData> requiredModelsData)
        {
            // Verify if nodeset file name is not empty
            if (string.IsNullOrEmpty(modelData.Name))
            {
                AppioLogger.Warn(LoggingText.GenerateInformationModelFailureEmptyModelName);
                _outputMessage = string.Format(OutputText.GenerateInformationModelFailureEmptyModelName, projectName);
                return(false);
            }

            // Verify nodeset extension
            if (_fileSystem.GetExtension(modelData.Name) != Constants.FileExtension.InformationModel)
            {
                AppioLogger.Warn(string.Format(LoggingText.NodesetCompilerExecutableFailsInvalidModelFile, modelData.Name));
                _outputMessage = string.Format(OutputText.GenerateInformationModelFailureInvalidModel, projectName, modelData.Name);
                return(false);
            }

            // Verify if nodeset file exists
            var modelPath = _fileSystem.CombinePaths(projectName, Constants.DirectoryName.Models, modelData.Name);

            if (!_fileSystem.FileExists(modelPath))
            {
                AppioLogger.Warn(string.Format(LoggingText.NodesetCompilerExecutableFailsMissingModelFile, modelData.Name));
                _outputMessage = string.Format(OutputText.GenerateInformationModelFailureMissingModel, projectName, modelData.Name, modelPath);
                return(false);
            }

            // Validate nodeset
            if (!_modelValidator.Validate(modelPath, Resources.Resources.UANodeSetXsdFileName))
            {
                AppioLogger.Warn(string.Format(LoggingText.NodesetValidationFailure, modelData.Name));
                _outputMessage = string.Format(OutputText.NodesetValidationFailure, modelData.Name);
                return(false);
            }

            // Create a directory for generated C code
            var srcDirectory = _fileSystem.CombinePaths(projectName, Constants.DirectoryName.SourceCode, Constants.DirectoryName.ServerApp);

            CreateDirectoryForGeneratedModelsSourceCode(srcDirectory);

            // Build nodeset compiler script arguments
            var modelName           = _fileSystem.GetFileNameWithoutExtension(modelData.Name);
            var nodesetCompilerArgs = BuildNodesetCompilerArgs(modelName, modelData, requiredModelsData);

            // Execute nodeset compiler call
            var nodesetResult = _fileSystem.CallExecutable(Constants.ExecutableName.PythonScript, srcDirectory, nodesetCompilerArgs);

            if (!nodesetResult)
            {
                AppioLogger.Warn(LoggingText.NodesetCompilerExecutableFails);
                _outputMessage = string.Format(OutputText.GenerateInformationModelFailure, projectName, modelData.Name);
                return(false);
            }

            // Add nodeset header file to server's meson build
            AdjustServerMesonBuildCFile(srcDirectory, modelName);

            // Add nodeset function call to server code
            AdjustLoadInformationModelsCFile(srcDirectory, modelName);

            // Add method callback functioncs to server code
            AdjustMainCallbacksCFile(srcDirectory, modelPath, modelData);

            return(true);
        }