Exemplo n.º 1
0
        public override void EnterParameterListParameterValue(TnsNamesParser.ParameterListParameterValueContext context)
        {
            var    parameterContext = (TnsNamesParser.ParameterContext)context.Parent;
            string keyword          = parameterContext.keyword().GetText();

            _levelStack.Push(keyword);


            bool isRootLevel = parameterContext.Parent is TnsNamesParser.Configuration_fileContext;

            // TNS name node
            if (isRootLevel && !string.Equals(keyword, "IFILE", StringComparison.OrdinalIgnoreCase))
            {
                _currentTnsNameInfo        = new TnsNameNode(keyword.ToUpperInvariant(), parameterContext);
                _currentTnsNameAddressList = new List <DatabaseAddressNode>();
            }
            // Address node
            else if (string.Equals(keyword, "ADDRESS", StringComparison.OrdinalIgnoreCase))
            {
                _currentDatabaseAddress = new DatabaseAddressNode(parameterContext);
                _currentTnsNameAddressList.Add(_currentDatabaseAddress);
            }

            base.EnterParameterListParameterValue(context);
        }
Exemplo n.º 2
0
        public override void ExitParameter(TnsNamesParser.ParameterContext context)
        {
            string keyword = context.keyword().GetText();

            bool isRootLevel = context.Parent is TnsNamesParser.Configuration_fileContext;

            // Verify and add TNS name
            if (isRootLevel && !string.Equals("IFILE", keyword, StringComparison.OrdinalIgnoreCase))
            {
                var nodeErrors = new List <TnsNamesListenerErrorNode>();

                // TNS name
                if (string.IsNullOrWhiteSpace(_currentTnsNameInfo.TnsName))
                {
                    nodeErrors.Add(new TnsNamesListenerErrorNode(context, TnsNamesParseError.MissingTnsName));
                }

                // Service name
                if (!string.IsNullOrWhiteSpace(_currentTnsNameServiceName))
                {
                    _currentTnsNameInfo.ServiceName = _currentTnsNameServiceName;
                }
                else if (!string.IsNullOrWhiteSpace(_currentTnsNameSid))
                {
                    _currentTnsNameInfo.ServiceName = _currentTnsNameSid;
                }
                else
                {
                    nodeErrors.Add(new TnsNamesListenerErrorNode(context, TnsNamesParseError.MissingServiceName));
                }

                // Verify database addresses, require at least on database address
                if (!_currentTnsNameAddressList.Any())
                {
                    nodeErrors.Add(new TnsNamesListenerErrorNode(context, TnsNamesParseError.NoDatabaseAddresses));
                }
                foreach (var databaseAddress in _currentTnsNameAddressList)
                {
                    // Protocol
                    if (string.IsNullOrWhiteSpace(databaseAddress.Protocol))
                    {
                        nodeErrors.Add(new TnsNamesListenerErrorNode(databaseAddress.ParameterContext, TnsNamesParseError.MissingProtocol));
                        continue;
                    }

                    if (string.Equals("TCP", databaseAddress.Protocol, StringComparison.OrdinalIgnoreCase) ||
                        string.Equals("TCPS", databaseAddress.Protocol, StringComparison.OrdinalIgnoreCase) ||
                        string.Equals("SDP", databaseAddress.Protocol, StringComparison.OrdinalIgnoreCase))
                    {
                        // Host
                        if (string.IsNullOrWhiteSpace(databaseAddress.Host))
                        {
                            nodeErrors.Add(new TnsNamesListenerErrorNode(databaseAddress.ParameterContext, TnsNamesParseError.MissingHost));
                        }

                        // Port
                        int port;
                        if (string.IsNullOrWhiteSpace(databaseAddress.PortStr))
                        {
                            nodeErrors.Add(new TnsNamesListenerErrorNode(databaseAddress.ParameterContext, TnsNamesParseError.MissingPort));
                        }
                        else if (!int.TryParse(databaseAddress.PortStr, NumberStyles.None, CultureInfo.InvariantCulture, out port))
                        {
                            nodeErrors.Add(new TnsNamesListenerErrorNode(databaseAddress.ParameterContext, TnsNamesParseError.InvalidPortString));
                        }
                        else if (port < 1 || port > 65535)
                        {
                            nodeErrors.Add(new TnsNamesListenerErrorNode(databaseAddress.ParameterContext, TnsNamesParseError.InvalidPortRange));
                        }
                        else
                        {
                            databaseAddress.PortNumber = port;
                        }
                    }
                    else if (string.Equals("IPC", databaseAddress.Protocol, StringComparison.OrdinalIgnoreCase))
                    {
                        // Key
                        if (string.IsNullOrWhiteSpace(databaseAddress.Key))
                        {
                            nodeErrors.Add(new TnsNamesListenerErrorNode(databaseAddress.ParameterContext, TnsNamesParseError.MissingKey));
                        }
                    }
                    else if (string.Equals("NMP", databaseAddress.Protocol, StringComparison.OrdinalIgnoreCase))
                    {
                        // Server
                        if (string.IsNullOrWhiteSpace(databaseAddress.Server))
                        {
                            nodeErrors.Add(new TnsNamesListenerErrorNode(databaseAddress.ParameterContext, TnsNamesParseError.MissingServer));
                        }

                        // Pipe
                        if (string.IsNullOrWhiteSpace(databaseAddress.Pipe))
                        {
                            nodeErrors.Add(new TnsNamesListenerErrorNode(databaseAddress.ParameterContext, TnsNamesParseError.MissingPipe));
                        }
                    }
                }

                // Add TNS name or alternativly error nodes
                if (!nodeErrors.Any())
                {
                    _currentTnsNameInfo.DatabaseAddresses = _currentTnsNameAddressList.ToArray();
                    TnsItems.Add(_currentTnsNameInfo);
                }
                else
                {
                    foreach (var nodeError in nodeErrors)
                    {
                        ErrorNodes.Add(nodeError);
                    }
                }

                // Release current resources
                _currentTnsNameSid         = null;
                _currentTnsNameServiceName = null;
                _currentTnsNameInfo        = null;
                _currentTnsNameAddressList = null;
                _currentDatabaseAddress    = null;
            }

            base.ExitParameter(context);
        }