Пример #1
0
        public void GetValueTest()
        {
            WowRegistryKey key =
                WowRegistry.LocalMachine.OpenSubKey(@"SOFTWARE\ORACLE\KEY_OraDb11g_home1");

            Assert.IsNotNull(key);

            string value = (string)key.GetValue("ORACLE_HOME");

            Console.WriteLine(String.Format("GetValueTest value=[{0}]", value));
            Assert.IsNotNull(value);
        }
Пример #2
0
        private static string GetKeyValue(WowRegistryKey key, string name)
        {
            string value = String.Empty;

            if (key != null)
            {
                try
                {
                    if ((value = (string)key.GetValue(name)) == null)
                    {
                        value = String.Empty;
                    }
                }
                catch { }
            }

            return(value);
        }
Пример #3
0
        private static string GetHomeKey(WowRegistryKey key)
        {
            string homeKey = (string)key.GetValue("ORACLE_HOME_KEY");

            if ((homeKey == null) && (key != null))
            {
                string[] keys = key.GetSubKeyNames();
                int      i    = 0;

                while ((i < keys.Length) && (homeKey == null))
                {
                    var subkey = key.OpenSubKey(keys[i]);
                    if ((homeKey = GetHomeKey(subkey)) == null)
                    {
                        i++;
                    }
                }
            }

            return(homeKey);
        }
Пример #4
0
        //========================================================================================
        // ReadTnsNames()
        //		Parse the tnsnames.ora file.  This routine essentially filters out all
        //		comments and anything between paranthesis, leaving only the TNS names.
        //========================================================================================

        private static void ReadTnsNames(SortedList list, SortedList all)
        {
            string home = String.Empty;

            WowRegistryKey key =
                WowRegistry.ClassesRoot.OpenSubKey("OracleDatabase.OracleDatabase\\CurVer");

            if (key == null)
            {
                home = DatabaseSetup.OracleHome;
            }
            else
            {
                key = WowRegistry.ClassesRoot.OpenSubKey((string)key.GetValue(null) + "\\CLSID");
                if (key != null)
                {
                    string clsid = (string)key.GetValue(null);

                    key = WowRegistry.ClassesRoot.OpenSubKey("CLSID\\" + clsid + "\\LocalServer32");
                    if (key != null)
                    {
                        string oracon = (string)key.GetValue(null);
                        if (!String.IsNullOrEmpty(oracon))
                        {
                            home = oracon.Substring(0, oracon.ToLower().IndexOf("\\oracon"));

                            if (home.StartsWith("\""))
                            {
                                home = home.Substring(1);
                            }
                        }
                    }
                }
            }

            var content = new StringBuilder();

            tnsNamesOraPath = Path.Combine(home, @"network\admin\tnsnames.ora");

            try
            {
                using (var reader = new StreamReader(
                           (Stream)File.OpenRead(tnsNamesOraPath),
                           System.Text.Encoding.ASCII))
                {
                    char ch;
                    int  depth     = 0;
                    bool inComment = false;

                    while (reader.Peek() >= 0)
                    {
                        ch = (char)reader.Read();

                        if (inComment)
                        {
                            if (ch == 10)
                            {
                                inComment = false;
                            }
                        }
                        else
                        {
                            if (ch == '#')
                            {
                                inComment = true;
                            }
                            else if (ch == '(')
                            {
                                depth++;
                            }
                            else if (ch == ')')
                            {
                                depth--;
                            }
                            else if ((depth == 0) && !Char.IsWhiteSpace(ch))
                            {
                                content.Append(ch);
                            }
                        }
                    }

                    reader.Close();
                }
            }
            catch (Exception)
            {
                return;
            }

            if (content.Length > 0)
            {
                string[] names = content.ToString().Split('=');
                string   name;
                TnsName  tname;

                for (int i = 0; i < names.Length; i++)
                {
                    name = names[i].Trim().ToLower();

                    if ((name.Length > 0) &&
                        (name.IndexOf("http") < 0) &&
                        (name.IndexOf("extproc") < 0))
                    {
                        tname = new TnsName(name, Location.TnsNames, null);

                        if (!list.Contains(name))
                        {
                            list.Add(name, tname);
                        }

                        all.Add(name + Location.TnsNames.ToString(), tname);
                    }
                }
            }
        }