public void SetupTest() { _defaultopcuaApp = new OpcuaappReference(); _opcuaapp = new OpcuaappReference(_name, _path); }
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)); }