Ejemplo n.º 1
0
        public static DBConn getThermalConnection()
        {
            DBConn result;

            lock (DBConnPool._lockthermaldb)
            {
                string str = "";
                if (DBUrl.SERVERMODE)
                {
                    try
                    {
                        DBConn   dBConn         = new DBConn();
                        string   cONNECT_STRING = DBUrl.CONNECT_STRING;
                        string[] array          = cONNECT_STRING.Split(new string[]
                        {
                            ","
                        }, StringSplitOptions.RemoveEmptyEntries);
                        dBConn.con = new MySqlConnection(string.Concat(new string[]
                        {
                            "Database=eco",
                            DBUrl.SERVERID,
                            ";Data Source=",
                            array[0],
                            ";Port=",
                            array[1],
                            ";User Id=",
                            array[2],
                            ";Password="******";Pooling=true;Min Pool Size=0;Max Pool Size=150;Default Command Timeout=0;charset=utf8;"
                        }));
                        dBConn.con.Open();
                        dBConn.setInUse();
                        result = dBConn;
                        return(result);
                    }
                    catch (Exception ex)
                    {
                        DebugCenter.GetInstance().appendToFile("DBERROR~~~~~~~~~~~Get ThermalDB Connection Error : " + ex.Message + "\n" + ex.StackTrace);
                        result = null;
                        return(result);
                    }
                }
                if (DBUrl.DB_CURRENT_TYPE.ToUpperInvariant().Equals("MYSQL"))
                {
                    try
                    {
                        DBConn dBConn2 = new DBConn();
                        dBConn2.con = new MySqlConnection(string.Concat(new object[]
                        {
                            "Database=",
                            DBUrl.DB_CURRENT_NAME,
                            ";Data Source=",
                            DBUrl.CURRENT_HOST_PATH,
                            ";Port=",
                            DBUrl.CURRENT_PORT,
                            ";User Id=",
                            DBUrl.CURRENT_USER_NAME,
                            ";Password="******";Pooling=true;Min Pool Size=0;Max Pool Size=150;Default Command Timeout=0;charset=utf8;"
                        }));
                        dBConn2.con.Open();
                        dBConn2.setInUse();
                        DebugCenter.GetInstance().clearStatusCode(DebugCenter.ST_MYSQLCONNECT_LOST, true);
                        result = dBConn2;
                        return(result);
                    }
                    catch (Exception e)
                    {
                        DebugCenter.GetInstance().setLastStatusCode(DebugCenter.ST_MYSQLCONNECT_LOST, true);
                        DebugCenter.GetInstance().appendToFile("Could not create MySQL connection : \r\n" + CommonAPI.ReportException(0, e, false, "    "));
                        result = null;
                        return(result);
                    }
                }
                bool flag2 = false;
                try
                {
                    DBCache.PrintThermalDB();
                    string text = AppDomain.CurrentDomain.BaseDirectory + "datadb";
                    if (text[text.Length - 1] != Path.DirectorySeparatorChar)
                    {
                        text += Path.DirectorySeparatorChar;
                    }
                    if (!Directory.Exists(text))
                    {
                        Directory.CreateDirectory(text);
                    }
                    string text2 = text + "thermaldb.mdb";
                    if (!File.Exists(text2))
                    {
                        if (File.Exists(text + "compacted_thermaldb.mdb"))
                        {
                            try
                            {
                                File.Copy(text + "compacted_thermaldb.mdb", text2, true);
                                File.Delete(text + "compacted_thermaldb.mdb");
                                goto IL_31D;
                            }
                            catch
                            {
                                goto IL_31D;
                            }
                        }
                        string sourceFileName = text + "datadb.org";
                        File.Copy(sourceFileName, text2, true);
                    }
                    else
                    {
                        if (File.Exists(text + "compacted_thermaldb.mdb"))
                        {
                            try
                            {
                                File.Copy(text + "compacted_thermaldb.mdb", text2, true);
                                File.Delete(text + "compacted_thermaldb.mdb");
                            }
                            catch
                            {
                            }
                        }
                    }
IL_31D:
                    DBConn dBConn3 = new DBConn();
                    try
                    {
                        dBConn3.con = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + text + "thermaldb.mdb;Jet OLEDB:Database Password=root");
                        dBConn3.con.Open();
                        flag2 = true;
                    }
                    catch (Exception ex2)
                    {
                        str = ex2.Message + "\r\n" + ex2.StackTrace;
                        int i = 0;
                        while (i < 4)
                        {
                            Thread.Sleep(10);
                            i++;
                            try
                            {
                                dBConn3.con = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + text + "thermaldb.mdb;Jet OLEDB:Database Password=root");
                                dBConn3.con.Open();
                                flag2 = true;
                                break;
                            }
                            catch (Exception ex3)
                            {
                                str = ex3.Message + "\r\n" + ex3.StackTrace;
                            }
                        }
                    }
                    if (flag2)
                    {
                        dBConn3.setInUse();
                        dBConn3.DBSource_Type = 3;
                        try
                        {
                            StackTrace stackTrace = new StackTrace();
                            MethodBase method     = stackTrace.GetFrame(1).GetMethod();
                            DBCache.OpenThermalDB(dBConn3.GetHashCode(), method.Name);
                            DBCache.PrintThermalDB();
                        }
                        catch
                        {
                        }
                        result = dBConn3;
                    }
                    else
                    {
                        DebugCenter.GetInstance().appendToFile("DBERROR~~~~~~~~~~~Get ThermalDB Connection Error : " + str);
                        result = null;
                    }
                }
                catch (Exception ex4)
                {
                    DebugCenter.GetInstance().appendToFile("DBERROR~~~~~~~~~~~Get ThermalDB Connection Error : " + ex4.Message + "\n" + ex4.StackTrace);
                    result = null;
                }
            }
            return(result);
        }