public override CommandResult Execute(IEnumerable <string> inputParams)
        {
            if (!ExecuteCommon(inputParams))
            {
                return(new CommandResult(false, _outputMessages));
            }

            // deserialise 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 server is part of client's reference and remove it
            string          clientNewContent = string.Empty;
            IOpcuaServerApp serverReference  = null;

            if (opcuaClientServer != null && (serverReference = opcuaClientServer.ServerReferences.SingleOrDefault(x => x.Name == _serverName)) != null)
            {
                opcuaClientServer.ServerReferences.Remove(serverReference);
                clientNewContent = JsonConvert.SerializeObject(opcuaClientServer, Formatting.Indented);
            }
            else if (opcuaClient != null && (serverReference = opcuaClient.ServerReferences.SingleOrDefault(x => x.Name == _serverName)) != null)
            {
                opcuaClient.ServerReferences.Remove(serverReference);
                clientNewContent = JsonConvert.SerializeObject(opcuaClient, Formatting.Indented);
            }
            else
            {
                AppioLogger.Warn(LoggingText.ReferenceRemoveServerIsNotInClient);
                _outputMessages.Add(string.Format(OutputText.ReferenceRemoveServerIsNotInClient, _serverName, _clientName), string.Empty);
                return(new CommandResult(false, _outputMessages));
            }
            _fileSystem.WriteFile(_clientFullName, new List <string> {
                clientNewContent
            });

            // exit method with success
            AppioLogger.Info(LoggingText.ReferenceRemoveSuccess);
            _outputMessages.Add(string.Format(OutputText.ReferenceRemoveSuccess, _clientName, _serverName), string.Empty);
            return(new CommandResult(true, _outputMessages));
        }
        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));
        }