예제 #1
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);
        }
예제 #2
0
 public TnsNamesListenerErrorNode(TnsNamesParser.ParameterContext parameterContext, TnsNamesParseError parseError)
 {
     ParameterContext = parameterContext;
     ParseError       = parseError;
 }
예제 #3
0
 /// <summary>
 /// Exit a parse tree produced by <see cref="TnsNamesParser.parameter"/>.
 /// <para>The default implementation does nothing.</para>
 /// </summary>
 /// <param name="context">The parse tree.</param>
 public virtual void ExitParameter([NotNull] TnsNamesParser.ParameterContext context)
 {
 }
예제 #4
0
 public DatabaseAddressNode(TnsNamesParser.ParameterContext parameterContext)
 {
     ParameterContext = parameterContext;
 }
예제 #5
0
 internal TnsNameNode([NotNull] string tnsName, [NotNull] TnsNamesParser.ParameterContext parameterContext)
 {
     TnsName          = tnsName ?? throw new ArgumentNullException(nameof(tnsName));
     ParameterContext = parameterContext ?? throw new ArgumentNullException(nameof(parameterContext));
 }