public CommandResult Execute(IEnumerable <string> inputParams) { var outputMessages = new MessageLines(); var(error, stringParams, _) = _resolver.ResolveParams(inputParams); if (error != null) { return(new CommandResult(false, new MessageLines { { error, string.Empty } })); } var solutionName = stringParams[ParamId.SolutionName]; if (_fileSystem.GetInvalidFileNameChars().Any(solutionName.Contains)) { AppioLogger.Warn(LoggingText.InvalidSolutionName); outputMessages.Add(string.Format(OutputText.NewSlnCommandFailure, solutionName), string.Empty); return(new CommandResult(false, outputMessages)); } var solutionFilePath = $"{solutionName}{Constants.FileExtension.Appiosln}"; _fileSystem.CreateFile(solutionFilePath, _fileSystem.LoadTemplateFile(Resources.Resources.AppioSlnTemplateFileName)); AppioLogger.Info(string.Format(LoggingText.NewSlnCommandSuccess, solutionFilePath)); outputMessages.Add(string.Format(OutputText.NewSlnCommandSuccess, solutionName), string.Empty); return(new CommandResult(true, outputMessages)); }
public CommandResult Execute(IEnumerable <string> inputParams) { var projectName = inputParams.ElementAtOrDefault(0); var outputMessages = new MessageLines(); // validate project name if (string.IsNullOrEmpty(projectName)) { AppioLogger.Warn(LoggingText.EmptyOpcuaappName); outputMessages.Add(OutputText.OpcuaappPublishFailure, string.Empty); return(new CommandResult(false, outputMessages)); } // build string with publish command source location var projectBuildDirectory = _fileSystem.CombinePaths(projectName, Constants.DirectoryName.MesonBuild); var appClientBuildLocation = _fileSystem.CombinePaths(projectBuildDirectory, Constants.ExecutableName.AppClient); var appServerBuildLocation = _fileSystem.CombinePaths(projectBuildDirectory, Constants.ExecutableName.AppServer); // build strings with publish command target location var projectPublishDirectory = _fileSystem.CombinePaths(projectName, Constants.DirectoryName.Publish); var appClientPublishLocation = _fileSystem.CombinePaths(projectPublishDirectory, Constants.ExecutableName.AppClient); var appServerPublishLocation = _fileSystem.CombinePaths(projectPublishDirectory, Constants.ExecutableName.AppServer); // check if any of client and server executables exist if ((string.IsNullOrEmpty(appClientBuildLocation) || !_fileSystem.FileExists(appClientBuildLocation)) && (string.IsNullOrEmpty(appServerBuildLocation) || !_fileSystem.FileExists(appServerBuildLocation))) { AppioLogger.Warn(LoggingText.MissingBuiltOpcuaAppFiles); outputMessages.Add(string.Format(OutputText.OpcuaappPublishFailureMissingExecutables, projectName), string.Empty); return(new CommandResult(false, outputMessages)); } // create publish directory _fileSystem.CreateDirectory(projectPublishDirectory); // publish client executable if (!string.IsNullOrEmpty(appClientBuildLocation) && _fileSystem.FileExists(appClientBuildLocation)) { _fileSystem.CopyFile(appClientBuildLocation, appClientPublishLocation); } // publish server executable if (!string.IsNullOrEmpty(appServerBuildLocation) && _fileSystem.FileExists(appServerBuildLocation)) { _fileSystem.CopyFile(appServerBuildLocation, appServerPublishLocation); } // return with success AppioLogger.Info(LoggingText.OpcuaappPublishedSuccess); outputMessages.Add(string.Format(OutputText.OpcuaappPublishSuccess, projectName), string.Empty); return(new CommandResult(true, outputMessages)); }
public CommandResult Execute(IEnumerable <string> inputParams) { var outputMessages = new MessageLines(); var validationMessages = new SlnUtility.ResultMessages(); var(error, stringParams, _) = _resolver.ResolveParams(inputParams); if (error != null) { return(new CommandResult(false, new MessageLines { { error, string.Empty } })); } var solutionName = stringParams[ParamId.SolutionName]; // validate solution name if (!SlnUtility.ValidateSolution(ref validationMessages, solutionName, _fileSystem)) { AppioLogger.Warn(validationMessages.LoggerMessage); outputMessages.Add(validationMessages.OutputMessage, string.Empty); return(new CommandResult(false, outputMessages)); } // deserialize *.appiosln file var solutionFullName = solutionName + Constants.FileExtension.Appiosln; Solution appioSolution = SlnUtility.DeserializeFile <Solution>(solutionFullName, _fileSystem); if (appioSolution == null) { AppioLogger.Warn(LoggingText.SlnCouldntDeserliazeSln); outputMessages.Add(string.Format(OutputText.SlnCouldntDeserliazeSln, solutionName), string.Empty); return(new CommandResult(false, outputMessages)); } // build projects that are part of solution foreach (var project in appioSolution.Projects) { var commandResult = _subcommand.Execute(new string[] { project.Name }); if (!commandResult.Success) { return(commandResult); } } // exit method with success AppioLogger.Info(SuccessLoggerMessage); outputMessages.Add(string.Format(SuccessOutputMessage, solutionName), string.Empty); return(new CommandResult(true, outputMessages)); }
public CommandResult Execute(IEnumerable <string> inputParams) { var outputMessages = new MessageLines(); outputMessages.Add(Constants.HelloString, string.Empty); return(new CommandResult(true, outputMessages)); }
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.Info(Resources.text.logging.LoggingText.CleanFailure); outputMessages.Add(Resources.text.output.OutputText.OpcuaappCleanFailure, string.Empty); return(new CommandResult(false, outputMessages)); } var buildDirectory = _fileSystem.CombinePaths(projectName, Constants.DirectoryName.MesonBuild); _fileSystem.DeleteDirectory(buildDirectory); AppioLogger.Info(Resources.text.logging.LoggingText.CleanSuccess); outputMessages.Add(string.Format(Resources.text.output.OutputText.OpcuaappCleanSuccess, projectName), string.Empty); return(new CommandResult(true, outputMessages)); }
public CommandResult Execute(IEnumerable <string> inputParams) { var outputMessages = new MessageLines(); foreach (var info in _reflection.GetAppioAssemblyInfos()) { outputMessages.Add(info.AssemblyName, string.Format(Resources.text.version.VersionText.AssemblyVersionInfo, info.AssemblyVersion.ToPrintableString())); } AppioLogger.Info(LoggingText.VersionCommandCalled); return(new CommandResult(true, outputMessages)); }
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)); }
protected bool ExecuteCommon(IEnumerable <string> inputParams) { var resolver = new ParameterResolver <ParamId>(Constants.CommandName.Reference + " " + Name, new [] { new StringParameterSpecification <ParamId> { Identifier = ParamId.ClientName, Short = Constants.ReferenceCommandOptions.Client, Verbose = Constants.ReferenceCommandOptions.VerboseClient }, new StringParameterSpecification <ParamId> { Identifier = ParamId.ServerName, Short = Constants.ReferenceCommandOptions.Server, Verbose = Constants.ReferenceCommandOptions.VerboseServer } }); var(error, stringParams, _) = resolver.ResolveParams(inputParams); if (error != null) { _outputMessages = new MessageLines { { error, string.Empty } }; return(false); } _serverName = stringParams[ParamId.ServerName]; _clientName = stringParams[ParamId.ClientName]; _outputMessages = new MessageLines(); // check if client appioproj file exists _clientFullName = _fileSystem.CombinePaths(_clientName, _clientName + Constants.FileExtension.Appioproject); if (!_fileSystem.FileExists(_clientFullName)) { AppioLogger.Warn(LoggingText.ReferenceClientAppioprojFileNotFound); _outputMessages.Add(string.Format(OutputText.ReferenceClientAppioprojFileNotFound, _clientFullName), string.Empty); return(false); } // exit with success return(true); }
public void ShouldTestAdd_OK() { // Arrange var msgKey = "key"; var msgValue = "value"; var messageLine = new MessageLines(); var countBeforeAdd = messageLine.Count(); // Act messageLine.Add(msgKey, msgValue); var countAfterAdd = messageLine.Count(); // Assert Assert.IsNotNull(messageLine); Assert.AreEqual(0, countBeforeAdd); Assert.AreEqual(1, countAfterAdd); Assert.IsTrue(messageLine.All(v => v.Key.Contains(msgKey))); Assert.IsTrue(messageLine.All(v => v.Value.Contains(msgValue))); }
public CommandResult Execute(IEnumerable <string> inputParams) { var(error, stringParams, _) = _resolver.ResolveParams(inputParams); if (error != null) { return(new CommandResult(false, new MessageLines { { error, string.Empty } })); } var projectName = stringParams[ParamId.AppName]; var outputMessages = new MessageLines(); // deserialize appioproj file var appioprojFilePath = _fileSystem.CombinePaths(projectName, projectName + Constants.FileExtension.Appioproject); var opcuaappData = Deserialize.Opcuaapp(appioprojFilePath, _fileSystem); if (opcuaappData == null) { AppioLogger.Warn(LoggingText.GenerateInformationModelFailureCouldntDeserliazeOpcuaapp); outputMessages.Add(string.Format(OutputText.GenerateInformationModelFailureCouldntDeserliazeOpcuaapp, projectName, appioprojFilePath), string.Empty); return(new CommandResult(false, outputMessages)); } if ((opcuaappData as IOpcuaClientApp)?.Type == Constants.ApplicationType.Client) { AppioLogger.Warn(LoggingText.GenerateInformationModelFailuteOpcuaappIsAClient); outputMessages.Add(string.Format(OutputText.GenerateInformationModelFailuteOpcuaappIsAClient, projectName), string.Empty); return(new CommandResult(false, outputMessages)); } var opcuaappModels = (opcuaappData as IOpcuaServerApp)?.Models; // check if models are valid if (!ValidateModels(opcuaappModels)) { AppioLogger.Warn(LoggingText.GenerateInformationModelInvalidModelsList); outputMessages.Add(string.Format(OutputText.GenerateInformationModelInvalidModelsList, projectName), string.Empty); return(new CommandResult(false, outputMessages)); } // check if there is any circular dependency between models if (SearchForCircularDependencies(opcuaappModels)) { AppioLogger.Warn(LoggingText.GenerateInformationModelCircularDependency); outputMessages.Add(string.Format(OutputText.GenerateInformationModelCircularDependency, projectName), string.Empty); return(new CommandResult(false, outputMessages)); } // sort models SortModels(opcuaappModels); // generate models foreach (var model in opcuaappModels) { var requiredModelData = GetListOfRequiredModels(opcuaappModels, model); if (!_nodesetGenerator.GenerateNodesetSourceCodeFiles(projectName, model, requiredModelData)) { outputMessages.Add(_nodesetGenerator.GetOutputMessage(), string.Empty); return(new CommandResult(false, outputMessages)); } } // add noodeset variables CreateNamespaceVariables(projectName, opcuaappModels); // exit method with positive result AppioLogger.Info(LoggingText.GenerateInformationModelSuccess); outputMessages.Add(string.Format(OutputText.GenerateInformationModelSuccess, projectName), string.Empty); return(new CommandResult(true, outputMessages)); }
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)); }
public CommandResult Execute(IEnumerable <string> inputParams) { var outputMessages = new MessageLines(); var(error, stringParams, _) = _resolver.ResolveParams(inputParams); if (error != null) { return(new CommandResult(false, new MessageLines { { error, string.Empty } })); } var solutionName = stringParams[ParamId.SolutionName]; var projectName = stringParams[ParamId.ProjectName]; // check if solution file is existing var solutionFullName = _fileSystem.CombinePaths(solutionName + Constants.FileExtension.Appiosln); if (string.IsNullOrEmpty(solutionName) || !_fileSystem.FileExists(solutionFullName)) { AppioLogger.Warn(LoggingText.SlnAppioslnFileNotFound); outputMessages.Add(string.Format(OutputText.SlnAppioslnNotFound, solutionFullName), string.Empty); return(new CommandResult(false, outputMessages)); } // deserialise solution file Solution appioSolution = SlnUtility.DeserializeFile <Solution>(solutionFullName, _fileSystem); if (appioSolution == null) { AppioLogger.Warn(LoggingText.SlnCouldntDeserliazeSln); outputMessages.Add(string.Format(OutputText.SlnCouldntDeserliazeSln, solutionName), string.Empty); return(new CommandResult(false, outputMessages)); } // check if the project to remove is part of the solution var appioproj = appioSolution.Projects.SingleOrDefault(x => x.Name == projectName); if (appioproj != null) { // remove opcuaapp from sln appioSolution.Projects.Remove(appioproj); // serialize and write sln var slnNewContent = JsonConvert.SerializeObject(appioSolution, Formatting.Indented); _fileSystem.WriteFile(solutionFullName, new List <string> { slnNewContent }); } else { AppioLogger.Warn(LoggingText.SlnRemoveOpcuaappIsNotInSln); outputMessages.Add(string.Format(OutputText.SlnRemoveOpcuaappIsNotInSln, projectName, solutionName), string.Empty); return(new CommandResult(false, outputMessages)); } // exit method with success AppioLogger.Info(LoggingText.SlnRemoveSuccess); outputMessages.Add(string.Format(OutputText.SlnRemoveSuccess, projectName, solutionName), string.Empty); return(new CommandResult(true, outputMessages)); }
public CommandResult Execute(IEnumerable <string> inputParams) { var outputMessages = new MessageLines(); var validationMessages = new SlnUtility.ResultMessages(); var(error, stringParams, _) = _resolver.ResolveParams(inputParams); if (error != null) { return(new CommandResult(false, new MessageLines { { error, string.Empty } })); } var solutionName = stringParams[ParamId.SolutionName]; var projectName = stringParams[ParamId.ProjectName]; // validate solution name if (!SlnUtility.ValidateSolution(ref validationMessages, solutionName, _fileSystem)) { AppioLogger.Warn(validationMessages.LoggerMessage); outputMessages.Add(validationMessages.OutputMessage, string.Empty); return(new CommandResult(false, outputMessages)); } // check if *.appioproj file exists var appioprojFilePath = _fileSystem.CombinePaths(projectName, projectName + Constants.FileExtension.Appioproject); if (string.IsNullOrEmpty(projectName) || !_fileSystem.FileExists(appioprojFilePath)) { AppioLogger.Warn(LoggingText.SlnAddAppioprojFileNotFound); outputMessages.Add(string.Format(OutputText.SlnAddOpcuaappNotFound, appioprojFilePath), string.Empty); return(new CommandResult(false, outputMessages)); } // deserialize *.appiosln file var solutionFullName = solutionName + Constants.FileExtension.Appiosln; Solution appioSolution = SlnUtility.DeserializeFile <Solution>(solutionFullName, _fileSystem); if (appioSolution == null) { AppioLogger.Warn(LoggingText.SlnCouldntDeserliazeSln); outputMessages.Add(string.Format(OutputText.SlnCouldntDeserliazeSln, solutionName), string.Empty); return(new CommandResult(false, outputMessages)); } // deserialize *.appioproj file OpcuaappReference appioproj = SlnUtility.DeserializeFile <OpcuaappReference>(appioprojFilePath, _fileSystem); if (appioproj == null) { AppioLogger.Warn(LoggingText.SlnAddCouldntDeserliazeOpcuaapp); outputMessages.Add(string.Format(OutputText.SlnAddCouldntDeserliazeOpcuaapp, projectName), string.Empty); return(new CommandResult(false, outputMessages)); } // check if sln does not contain opcuaapp yet if (!appioSolution.Projects.Any(x => x.Name == appioproj.Name)) { // add opcuaapp to sln appioproj.Path = appioprojFilePath; appioSolution.Projects.Add(appioproj); // serialize and write sln var slnNewContent = JsonConvert.SerializeObject(appioSolution, Formatting.Indented); _fileSystem.WriteFile(solutionFullName, new List <string> { slnNewContent }); } else { AppioLogger.Info(LoggingText.SlnAddContainsOpcuaapp); outputMessages.Add(string.Format(OutputText.SlnAddContainsOpcuaapp, solutionName, projectName), string.Empty); return(new CommandResult(false, outputMessages)); } // exit method with success AppioLogger.Info(LoggingText.SlnAddSuccess); outputMessages.Add(string.Format(OutputText.SlnAddSuccess, projectName, solutionName), string.Empty); return(new CommandResult(true, outputMessages)); }
public CommandResult Execute(IEnumerable <string> inputParams) { var(error, parameters, options) = _resolver.ResolveParams(inputParams); if (error != null) { return(new CommandResult(false, new MessageLines { { error, string.Empty } })); } var opcuaAppName = parameters[ParamId.AppName]; var modelPath = parameters[ParamId.ModelPath]; var typesPath = parameters[ParamId.TypesPath]; // opcuaapp name validation if (!ValidateOpcuaAppName(opcuaAppName)) { return(new CommandResult(false, _outputMessages)); } var appioprojFilePath = _fileSystem.CombinePaths(opcuaAppName, opcuaAppName + Constants.FileExtension.Appioproject); var modelData = new ModelData(); if (options[ParamId.Sample]) { var modelsDir = _fileSystem.CombinePaths(opcuaAppName, Constants.DirectoryName.Models); var nodesetContent = _fileSystem.LoadTemplateFile(Resources.Resources.SampleInformationModelFileName); var nodesetFilePath = _fileSystem.CombinePaths(modelsDir, Constants.FileName.SampleInformationModelFile); _fileSystem.CreateFile(nodesetFilePath, nodesetContent); var typesContent = _fileSystem.LoadTemplateFile(Resources.Resources.SampleInformationModelTypesFileName); var typesFilePath = _fileSystem.CombinePaths(modelsDir, Constants.FileName.SampleInformationModelTypesFile); _fileSystem.CreateFile(typesFilePath, typesContent); if (!UpdateAppioProjFile(appioprojFilePath, modelData, opcuaAppName, Constants.FileName.SampleInformationModelFile, nodesetFilePath, Constants.FileName.SampleInformationModelTypesFile)) { return(new CommandResult(false, _outputMessages)); } _outputMessages.Add(string.Format(OutputText.ImportSampleInformationModelSuccess, Constants.FileName.SampleInformationModelFile), string.Empty); AppioLogger.Info(string.Format(LoggingText.ImportInforamtionModelCommandSuccess, Constants.FileName.SampleInformationModelFile)); return(new CommandResult(true, _outputMessages)); } // nodeset validation if (!ValidateModel(modelPath)) { return(new CommandResult(false, _outputMessages)); } var modelFileName = _fileSystem.GetFileName(modelPath); // types validation var typesFileName = string.Empty; if (typesPath != string.Empty && !ValidateTypes(out typesFileName, typesPath)) { return(new CommandResult(false, _outputMessages)); } if (!UpdateAppioProjFile(appioprojFilePath, modelData, opcuaAppName, modelFileName, modelPath, typesFileName)) { return(new CommandResult(false, _outputMessages)); } // copy model file var modelsDirectory = _fileSystem.CombinePaths(opcuaAppName, Constants.DirectoryName.Models); var targetModelFilePath = _fileSystem.CombinePaths(modelsDirectory, modelFileName); _fileSystem.CopyFile(modelPath, targetModelFilePath); // copy types file if (typesPath != string.Empty) { var targetTypesFilePath = _fileSystem.CombinePaths(modelsDirectory, typesFileName); _fileSystem.CopyFile(typesPath, targetTypesFilePath); } // exit with success AppioLogger.Info(string.Format(LoggingText.ImportInforamtionModelCommandSuccess, modelPath)); _outputMessages.Add(string.Format(OutputText.ImportInformationModelCommandSuccess, modelPath), string.Empty); return(new CommandResult(true, _outputMessages)); }
public CommandResult Execute(IEnumerable <string> inputParams) { var outputMessages = new MessageLines(); var messages = new Messages(); var(error, stringParams, options) = _resolver.ResolveParams(inputParams); if (error != null) { return(new CommandResult(false, new MessageLines { { error, string.Empty } })); } var opcuaAppName = stringParams[ParamId.OpcuaAppName]; var applicationType = stringParams[ParamId.ApplicationType]; var url = stringParams[ParamId.Url]; var port = stringParams[ParamId.Port]; // validate opcuaapp name if (_fileSystem.GetInvalidFileNameChars().Any(opcuaAppName.Contains) || _fileSystem.GetInvalidPathChars().Any(opcuaAppName.Contains)) { AppioLogger.Warn(LoggingText.InvalidOpcuaappName); outputMessages.Add(string.Format(OutputText.NewOpcuaappCommandFailureInvalidProjectName, opcuaAppName), string.Empty); return(new CommandResult(false, outputMessages)); } // validate opcuaapp type if (!ValidateApplicationType(ref messages, applicationType, url, port)) { AppioLogger.Warn(messages.loggerMessage); outputMessages.Add(messages.outputMessage, string.Empty); return(new CommandResult(false, outputMessages)); } // combine project file paths var projectFilePath = _fileSystem.CombinePaths(opcuaAppName, $"{opcuaAppName}{Constants.FileExtension.Appioproject}"); var sourceDirectory = _fileSystem.CombinePaths(opcuaAppName, Constants.DirectoryName.SourceCode); var mesonFilePath = _fileSystem.CombinePaths(opcuaAppName, Constants.FileName.SourceCode_meson_build); // create project directories _fileSystem.CreateDirectory(opcuaAppName); _fileSystem.CreateDirectory(sourceDirectory); IOpcuaapp opcuaapp = null; // deploy files for opcuaapp Client if (applicationType == Constants.ApplicationType.Client) { opcuaapp = new OpcuaClientApp(opcuaAppName); _fileSystem.CreateFile(mesonFilePath, _fileSystem.LoadTemplateFile( Resources.Resources.AppioOpcuaAppTemplateFileName_meson_ClientType_build)); DeployTemplateOpcuaClientSourceFiles(sourceDirectory); } // deploy files for opcuaapp Server else if (applicationType == Constants.ApplicationType.Server) { opcuaapp = new OpcuaServerApp(opcuaAppName, url, port); _fileSystem.CreateFile(mesonFilePath, _fileSystem.LoadTemplateFile( Resources.Resources.AppioOpcuaAppTemplateFileName_meson_ServerType_build)); CreateModelsDirectory(opcuaAppName); DeployTemplateOpcuaServerSourceFiles(sourceDirectory); } // deploy files for opcuaapp ClientServer else if (applicationType == Constants.ApplicationType.ClientServer) { opcuaapp = new OpcuaClientServerApp(opcuaAppName, url, port); _fileSystem.CreateFile(mesonFilePath, _fileSystem.LoadTemplateFile(Resources.Resources .AppioOpcuaAppTemplateFileName_meson_ClientServerType_build)); CreateModelsDirectory(opcuaAppName); DeployTemplateOpcuaClientSourceFiles(sourceDirectory); DeployTemplateOpcuaServerSourceFiles(sourceDirectory); } if (!options[ParamId.NoCert]) { if (applicationType == Constants.ApplicationType.ClientServer) { _certificateGenerator.Generate(opcuaAppName, Constants.FileName.ClientCryptoPrefix); _certificateGenerator.Generate(opcuaAppName, Constants.FileName.ServerCryptoPrefix); } else { _certificateGenerator.Generate(opcuaAppName); } } // create *.appioproj file var opcuaappAsJson = JsonConvert.SerializeObject(opcuaapp, Formatting.Indented); _fileSystem.CreateFile(projectFilePath, opcuaappAsJson); AppioLogger.Info(string.Format(LoggingText.NewOpcuaappCommandSuccess, opcuaAppName)); outputMessages.Add(string.Format(OutputText.NewOpcuaappCommandSuccess, opcuaAppName), string.Empty); return(new CommandResult(true, outputMessages)); }