예제 #1
0
        public ResolvedParameters <TIdent> ResolveParams(IEnumerable <string> parameters)
        {
            var resolvedStringParams = new string[_numStringParams];
            var resolvedBoolParams   = new bool[_numBoolParams];

            Array.Fill(resolvedBoolParams, false);

            var handledFlags = new List <Tuple <TIdent, string> >();

            var parameterArray = parameters as string[] ?? parameters.ToArray();

            for (var providedFlagNameIndex = 0; providedFlagNameIndex < parameterArray.Length; providedFlagNameIndex++)
            {
                var providedFlagName = parameterArray[providedFlagNameIndex];
                var flagIndex        = _flags.FindIndex(pair => pair.Name == providedFlagName);
                if (flagIndex == -1)
                {
                    AppioLogger.Warn(string.Format(LoggingText.UnknownParameterProvided, _commandName));
                    return(new ResolvedParameters <TIdent> {
                        ErrorMessage =
                            string.Format(OutputText.UnknownParameterProvided, providedFlagName, JoinFlagString())
                    });
                }

                switch (_flags[flagIndex].Type)
                {
                case IdentifierNames.DataType.String:
                    ++providedFlagNameIndex;
                    if (providedFlagNameIndex >= parameterArray.Length ||
                        parameterArray[providedFlagNameIndex] == string.Empty)
                    {
                        AppioLogger.Warn(string.Format(LoggingText.ParameterValueMissing, _commandName));
                        return(new ResolvedParameters <TIdent> {
                            ErrorMessage = string.Format(OutputText.ParameterValueMissing, _flags[flagIndex].Name)
                        });
                    }
                    resolvedStringParams[(int)(object)_flags[flagIndex].Identifier] = parameterArray[providedFlagNameIndex];
                    break;

                case IdentifierNames.DataType.Bool:
                    resolvedBoolParams[(int)(object)_flags[flagIndex].Identifier - _boolOffset] = true;
                    break;
                }

                handledFlags.Add(new Tuple <TIdent, string>(_flags[flagIndex].Identifier, providedFlagName));
            }

            if (ContainsDuplicateParameters(handledFlags, out var affectedFlag))
            {
                AppioLogger.Warn(string.Format(LoggingText.DuplicateParameterProvided, _commandName));
                return(new ResolvedParameters <TIdent> {
                    ErrorMessage =
                        string.Format(OutputText.DuplicateParameterProvided, affectedFlag)
                });
            }

            if (!FillDefaultValues(resolvedStringParams, out var missingParamString))
            {
                AppioLogger.Warn(string.Format(LoggingText.MissingRequiredParameter, _commandName));
                return(new ResolvedParameters <TIdent> {
                    ErrorMessage =
                        string.Format(OutputText.MissingRequiredParameter, missingParamString)
                });
            }

            return(new ResolvedParameters <TIdent>
            {
                StringParameters = new ParameterList <string, TIdent>(0, resolvedStringParams),
                BoolParameters = new ParameterList <bool, TIdent>(_boolOffset, resolvedBoolParams)
            });
        }
예제 #2
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);
        }