Exemplo n.º 1
0
        /// <summary>
        /// Standard constructor
        /// </summary>
        /// <param name="name"></param>
        /// <param name="parent"></param>
        public TnsNames(string name, TnsNames parent)
        {
            Name   = name;
            Parent = parent;

            if (parent != null)
            {
                parent.m_Items.Add(this);
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Standard Constructor
        /// </summary>
        /// <param name="directoryName"></param>
        public OracleHome(string directoryName)
        {
            ClientPath = directoryName ?? throw new ArgumentNullException(nameof(directoryName));

            string netWork = Path.Combine(ClientPath, "network", "admin");

            m_TnsNames = new Lazy <TnsNames>(() => TnsNames.Load(Path.Combine(netWork, "tnsnames.ora")));

            m_Ldap   = new Lazy <IReadOnlyDictionary <string, string> >(() => ReadAsDictionary(Path.Combine(netWork, "ldap.ora")));
            m_SqlNet = new Lazy <IReadOnlyDictionary <string, string> >(() => ReadAsDictionary(Path.Combine(netWork, "sqlnet.ora")));
        }
Exemplo n.º 3
0
        /// <summary>
        /// Load
        /// </summary>
        public static TnsNames Load(IEnumerable <string> lines)
        {
            if (null == lines)
            {
                throw new ArgumentNullException(nameof(lines));
            }

            TnsNames root = new TnsNames("", null);

            Stack <TnsNames> current = new Stack <TnsNames>();

            current.Push(root);

            StringBuilder sb = new StringBuilder();

            int  bracketCount = 0;
            bool inQuot       = false;
            bool inValue      = false;
            bool inName       = false;

            foreach (string line in lines)
            {
                foreach (char c in line)
                {
                    if (inQuot)
                    {
                        sb.Append(c);

                        if (c == '"')
                        {
                            inQuot = !inQuot;
                        }
                    }
                    else if (c == '#')
                    {
                        break;
                    }
                    else if (c == '"')
                    {
                        sb.Append(c);

                        inQuot = true;
                    }
                    else if (c == '(')
                    {
                        bracketCount += 1;

                        inValue = false;
                        inName  = true;

                        TnsNames child = new TnsNames("", current.Peek());

                        current.Push(child);
                    }
                    else if (c == '=')
                    {
                        if (inName)
                        {
                            current.Peek().Name = sb.ToString().Trim();
                        }
                        else
                        {
                            if (bracketCount <= 0)
                            {
                                bracketCount = 0;

                                if (current.Count > 1)
                                {
                                    current.Pop();
                                }
                            }

                            TnsNames child = new TnsNames(sb.ToString(), current.Peek());
                            current.Push(child);
                        }

                        sb.Clear();

                        inName  = false;
                        inValue = true;
                    }
                    else if (c == ')')
                    {
                        if (inValue)
                        {
                            new TnsNames(sb.ToString(), current.Peek());
                        }

                        bracketCount -= 1;

                        sb.Clear();

                        inValue = false;
                        inName  = false;

                        current.Pop();
                    }
                    else
                    {
                        sb.Append(c);
                    }
                }
            }

            return(root);
        }