Exemplo n.º 1
0
 static public void DeserializeClient(ref OpcuaClientApp opcuaClient, ref OpcuaClientServerApp opcuaClientServer, string clientFullName, IFileSystem fileSystem)
 {
     opcuaClient = SlnUtility.DeserializeFile <OpcuaClientApp>(clientFullName, fileSystem);
     if (opcuaClient != null && opcuaClient.Type == Constants.ApplicationType.ClientServer)
     {
         opcuaClientServer = SlnUtility.DeserializeFile <OpcuaClientServerApp>(clientFullName, fileSystem);
     }
 }
Exemplo n.º 2
0
        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));
        }
Exemplo n.º 3
0
        private void SetServerHostnameAndPort(string projectName)
        {
            var appioprojFilePath = _fileSystem.CombinePaths(projectName, projectName + Constants.FileExtension.Appioproject);

            var appioprojOpcuaapp = SlnUtility.DeserializeFile <OpcuaServerApp>(appioprojFilePath, _fileSystem);

            if (appioprojOpcuaapp != null && (appioprojOpcuaapp.Type == Constants.ApplicationType.Server || appioprojOpcuaapp.Type == Constants.ApplicationType.ClientServer))
            {
                var serverConstantsFilePath = _fileSystem.CombinePaths(projectName, Constants.DirectoryName.SourceCode, Constants.DirectoryName.ServerApp, Constants.FileName.SourceCode_constants_h);

                var constantsFileContent = new List <string>();
                using (var constantsFileStream = _fileSystem.ReadFile(serverConstantsFilePath))
                {
                    var reader = new StreamReader(constantsFileStream);
                    while (!reader.EndOfStream)
                    {
                        constantsFileContent.Add(reader.ReadLine());
                    }
                    reader.Dispose();

                    var hostnameLineIndex = constantsFileContent.FindIndex(x => x.Contains(Constants.ServerConstants.ServerAppHostname));
                    if (hostnameLineIndex != -1)
                    {
                        constantsFileContent.RemoveAt(hostnameLineIndex);
                    }

                    var portLineIndex = constantsFileContent.FindIndex(x => x.Contains(Constants.ServerConstants.ServerAppPort));
                    if (portLineIndex != -1)
                    {
                        constantsFileContent.RemoveAt(portLineIndex);
                    }

                    var hostName = new StringBuilder(Constants.ServerConstants.ServerAppHostname).Append(" = \"").Append(appioprojOpcuaapp.Url).Append("\";").ToString();
                    constantsFileContent.Add(hostName);

                    var portNumber = new StringBuilder(Constants.ServerConstants.ServerAppPort).Append(" = ").Append(appioprojOpcuaapp.Port).Append(";").ToString();
                    constantsFileContent.Add(portNumber);
                }
                _fileSystem.WriteFile(serverConstantsFilePath, constantsFileContent);
            }
        }
Exemplo n.º 4
0
        private void SetClientReferenceToServers(string projectName)
        {
            var appioprojFilePath = _fileSystem.CombinePaths(projectName, projectName + Constants.FileExtension.Appioproject);

            var appioprojOpcuaapp = SlnUtility.DeserializeFile <OpcuaClientApp>(appioprojFilePath, _fileSystem);

            if (appioprojOpcuaapp != null && (appioprojOpcuaapp.Type == Constants.ApplicationType.Client || appioprojOpcuaapp.Type == Constants.ApplicationType.ClientServer))
            {
                var clientGlobalVariablesFilePath = _fileSystem.CombinePaths(projectName, Constants.DirectoryName.SourceCode, Constants.DirectoryName.ClientApp, Constants.FileName.SourceCode_globalVariables_h);

                var globalVariablesFileContent = new StringBuilder(string.Format(Constants.ClientGlobalVariables.FirstLines, appioprojOpcuaapp.ServerReferences.Count));
                foreach (var project in appioprojOpcuaapp.ServerReferences)
                {
                    globalVariablesFileContent.Append(string.Format(Constants.ClientGlobalVariables.Hostname, project.Url, project.Port));
                }
                globalVariablesFileContent.Append(Constants.ClientGlobalVariables.LastLines);

                _fileSystem.WriteFile(clientGlobalVariablesFilePath, new List <string> {
                    globalVariablesFileContent.ToString()
                });
            }
        }
        public override CommandResult Execute(IEnumerable <string> inputParams)
        {
            if (!ExecuteCommon(inputParams))
            {
                return(new CommandResult(false, _outputMessages));
            }

            // validate server
            var serverFullName = _fileSystem.CombinePaths(_serverName, _serverName + Constants.FileExtension.Appioproject);

            if (!ValidateServer(_serverName, serverFullName))
            {
                return(new CommandResult(false, _outputMessages));
            }

            // deserialize server file
            OpcuaServerApp opcuaServer = SlnUtility.DeserializeFile <OpcuaServerApp>(serverFullName, _fileSystem);

            if (opcuaServer == null)
            {
                AppioLogger.Warn(LoggingText.ReferenceAddCouldntDeserliazeServer);
                _outputMessages.Add(string.Format(OutputText.ReferenceAddCouldntDeserliazeServer, serverFullName), string.Empty);
                return(new CommandResult(false, _outputMessages));
            }

            // check if deserialized server is not a client
            if (opcuaServer.Type == Constants.ApplicationType.Client)
            {
                AppioLogger.Warn(LoggingText.ReferenceAddClientCannotBeReferred);
                _outputMessages.Add(string.Format(OutputText.ReferenceAddClientCannotBeReferred, _serverName), string.Empty);
                return(new CommandResult(false, _outputMessages));
            }

            // deserialize client file
            OpcuaClientApp       opcuaClient       = null;
            OpcuaClientServerApp opcuaClientServer = null;

            RefUtility.DeserializeClient(ref opcuaClient, ref opcuaClientServer, _clientFullName, _fileSystem);
            if (opcuaClient == null && opcuaClientServer == null)
            {
                AppioLogger.Warn(LoggingText.ReferenceCouldntDeserliazeClient);
                _outputMessages.Add(string.Format(OutputText.ReferenceCouldntDeserliazeClient, _clientFullName), string.Empty);
                return(new CommandResult(false, _outputMessages));
            }

            // check if deserialized client is not a server
            if (!ClientIsNotAServer(ref opcuaClient, ref opcuaClientServer, _clientName))
            {
                return(new CommandResult(false, _outputMessages));
            }

            // check if server is not already a part of client's references
            if (!ServerIsNotYetClientsReference(ref opcuaClient, ref opcuaClientServer, _clientName, opcuaServer.Name))
            {
                return(new CommandResult(false, _outputMessages));
            }

            // overwrite client appioproj file with new server reference
            string clientNewContent = string.Empty;

            if (opcuaClientServer != null)
            {
                opcuaClientServer.ServerReferences.Add(opcuaServer);
                clientNewContent = JsonConvert.SerializeObject(opcuaClientServer, Formatting.Indented);
            }
            else
            {
                opcuaClient.ServerReferences.Add(opcuaServer);
                clientNewContent = JsonConvert.SerializeObject(opcuaClient, Formatting.Indented);
            }
            _fileSystem.WriteFile(_clientFullName, new List <string> {
                clientNewContent
            });

            // exit with success
            AppioLogger.Info(LoggingText.ReferenceAddSuccess);
            _outputMessages.Add(string.Format(OutputText.RefereneceAddSuccess, _serverName, _clientName), 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));
        }
Exemplo n.º 7
0
        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));
        }