예제 #1
0
 public void QueueWork(object sender, WorkQueue <Dictionary <string, Dictionary <string, Dictionary <string, string> > > > .EnqueueEventArgs e)
 {
     if (this.con == null || this.con.State != ConnectionState.Open)
     {
         if (this.con != null)
         {
             try
             {
                 this.con.Close();
             }
             catch (Exception)
             {
             }
         }
         try
         {
             if (DBUrl.SERVERMODE)
             {
                 this.con = this.getConnection();
             }
             else
             {
                 string connectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + DBUrl.DEFAULT_HOST_PATH + ";Jet OLEDB:Database Password="******"DBERROR~~~~~~~~~~~DBERROR : " + ex.Message + "\n" + ex.StackTrace);
         }
     }
     try
     {
         Dictionary <string, Dictionary <string, Dictionary <string, string> > > item = e.Item;
         foreach (KeyValuePair <string, Dictionary <string, Dictionary <string, string> > > current in item)
         {
             string key = current.Key;
             Dictionary <string, Dictionary <string, string> > value = current.Value;
             InSnergyGateway.RefreshGateWay(key, value, this.con);
             if (GateWayRefreshQueue.CBWork != null)
             {
                 GateWayRefreshQueue.CBWork(key);
             }
         }
     }
     catch (Exception ex2)
     {
         DebugCenter.GetInstance().appendToFile("DBERROR~~~~~~~~~~~DBERROR : " + ex2.Message + "\n" + ex2.StackTrace);
     }
 }
예제 #2
0
        public static void DeleteOverallRemainLastSomeHours(int hours, DateTime currentTime)
        {
            DateTime dateTime = currentTime.AddHours((double)(-(double)hours));

            Convert.ToDateTime(dateTime.ToString("yyyy-MM-dd HH:mm:ss"));
            string text = "delete from rack_effect where insert_time < #" + dateTime.ToString("yyyy-MM-dd HH:mm:ss") + "#";

            if (DBUrl.SERVERMODE || DBUrl.DB_CURRENT_TYPE.ToUpper().Equals("MYSQL"))
            {
                WorkQueue <string> .getInstance_rackeffect().WorkSequential = true;

                WorkQueue <string> .getInstance_rackeffect().EnqueueItem(text);

                return;
            }
            DBConn    dBConn    = null;
            DbCommand dbCommand = new OleDbCommand();

            try
            {
                dBConn = DBConnPool.getThermalConnection();
                if (dBConn != null && dBConn.con != null)
                {
                    dbCommand             = dBConn.con.CreateCommand();
                    dbCommand.CommandType = CommandType.Text;
                    dbCommand.CommandText = text;
                    dbCommand.ExecuteNonQuery();
                }
                dbCommand.Dispose();
                dBConn.Close();
            }
            catch (Exception ex)
            {
                try
                {
                    dbCommand.Dispose();
                }
                catch
                {
                }
                try
                {
                    dBConn.Close();
                }
                catch
                {
                }
                DebugCenter.GetInstance().appendToFile("Delete Rack effect: " + ex.Message + "\n" + ex.StackTrace);
            }
        }
예제 #3
0
        public static int Insertnewtask(Dictionary <string, Dictionary <string, Dictionary <string, string> > > dic_item)
        {
            int result;

            try
            {
                if (GateWayRefreshQueue.wq == null)
                {
                    GateWayRefreshQueue.wq = new WorkQueue <Dictionary <string, Dictionary <string, Dictionary <string, string> > > >(10000, "InsGateway");
                    GateWayRefreshQueue @object = new GateWayRefreshQueue();
                    GateWayRefreshQueue.wq.UserWork += new UserWorkEventHandler <Dictionary <string, Dictionary <string, Dictionary <string, string> > > >(@object.QueueWork);
                }
                GateWayRefreshQueue.wq.EnqueueItem(dic_item);
                result = 1;
            }
            catch (Exception ex)
            {
                DebugCenter.GetInstance().appendToFile("DBERROR~~~~~~~~~~~DBERROR : " + ex.Message + "\n" + ex.StackTrace);
                result = -1;
            }
            return(result);
        }
예제 #4
0
        public static int InsertDataTask(GatewayDataCell gdc_itm)
        {
            int result;

            try
            {
                if (GateWayRefreshQueue.wq_data == null)
                {
                    GateWayRefreshQueue.wq_data = new WorkQueue <GatewayDataCell>(10000, "GateWayData");
                    GateWayRefreshQueue @object = new GateWayRefreshQueue();
                    GateWayRefreshQueue.wq_data.UserWork += new UserWorkEventHandler <GatewayDataCell>(@object.QueueWork4Data);
                }
                GateWayRefreshQueue.wq_data.EnqueueItem(gdc_itm);
                result = 1;
            }
            catch (Exception ex)
            {
                DebugCenter.GetInstance().appendToFile("DBERROR~~~~~~~~~~~DBERROR : " + ex.Message + "\n" + ex.StackTrace);
                result = -1;
            }
            return(result);
        }
예제 #5
0
        public int Update(DBConn conn)
        {
            string text = this.insert_time.ToString("yyyyMMdd");

            try
            {
                long num = Convert.ToInt64(this.power_consumption * 10000.0);
                if (DBUrl.SERVERMODE)
                {
                    string item = string.Concat(new object[]
                    {
                        "update port_data_daily",
                        text,
                        " set power_consumption = power_consumption + ",
                        CultureTransfer.ToString((float)num),
                        " where port_id = ",
                        this.port_id,
                        " and insert_time = #",
                        this.insert_time.ToString("yyyy-MM-dd"),
                        "#"
                    });
                    string item2 = string.Concat(new object[]
                    {
                        "update port_data_hourly",
                        text,
                        " set power_consumption = power_consumption + ",
                        CultureTransfer.ToString((float)num),
                        " where port_id = ",
                        this.port_id,
                        " and insert_time = #",
                        new DateTime(this.insert_time.Year, this.insert_time.Month, this.insert_time.Day, DateTime.Now.Hour, 30, 0).ToString("yyyy-MM-dd HH:mm:ss"),
                        "#"
                    });
                    WorkQueue <string> .getInstance_pd().WorkSequential = true;

                    WorkQueue <string> .getInstance_pd().EnqueueItem(item);

                    WorkQueue <string> .getInstance_pd().EnqueueItem(item2);
                }
                else
                {
                    if (DBUrl.DB_CURRENT_TYPE.Equals("MYSQL"))
                    {
                        string item3 = string.Concat(new object[]
                        {
                            "update port_data_daily",
                            text,
                            " set power_consumption = power_consumption + ",
                            CultureTransfer.ToString((float)num),
                            " where port_id = ",
                            this.port_id,
                            " and insert_time = #",
                            this.insert_time.ToString("yyyy-MM-dd"),
                            "#"
                        });
                        string item4 = string.Concat(new object[]
                        {
                            "update port_data_hourly",
                            text,
                            " set power_consumption = power_consumption + ",
                            CultureTransfer.ToString((float)num),
                            " where port_id = ",
                            this.port_id,
                            " and insert_time = #",
                            new DateTime(this.insert_time.Year, this.insert_time.Month, this.insert_time.Day, DateTime.Now.Hour, 30, 0).ToString("yyyy-MM-dd HH:mm:ss"),
                            "#"
                        });
                        WorkQueue <string> .getInstance_pd().WorkSequential = true;

                        WorkQueue <string> .getInstance_pd().EnqueueItem(item3);

                        WorkQueue <string> .getInstance_pd().EnqueueItem(item4);
                    }
                    else
                    {
                        List <string> list = new List <string>();
                        list.Add(string.Concat(this.port_id));
                        list.Add(this.insert_time.ToString("yyyy-MM-dd HH:mm:ss"));
                        list.Add("port_data_daily");
                        list.Add(CultureTransfer.ToString((float)num));
                        MinuteDataProcess.GetInstance().PutItem(list);
                        List <string> list2 = new List <string>();
                        list2.Add(string.Concat(this.port_id));
                        list2.Add(this.insert_time.ToString("yyyy-MM-dd HH:mm:ss"));
                        list2.Add("port_data_hourly");
                        list2.Add(CultureTransfer.ToString((float)num));
                        MinuteDataProcess.GetInstance().PutItem(list2);
                    }
                }
            }
            catch (Exception ex)
            {
                DebugCenter.GetInstance().appendToFile("DBERROR~~~~~~~~~~~DBERROR : " + ex.Message + "\n" + ex.StackTrace);
            }
            return(0);
        }
예제 #6
0
        private void CompactThread()
        {
            Interlocked.Exchange(ref this._threadDone, 0);
            int arg_12_0 = Environment.TickCount;

            try
            {
                File.Delete(this._dstDatabasePath);
                this._result = this.CompactDB(this._srcDatabasePath, this._dstDatabasePath, this._password);
                string text = "";
                if (this._result)
                {
                    text = this._dstDatabasePath;
                }
                else
                {
                    text = this._srcDatabasePath;
                }
                int num = DBTools.ShudownAccess();
                if (num > 0)
                {
                    try
                    {
                        if (File.Exists(AppDomain.CurrentDomain.BaseDirectory + "datadb.mdb") && File.Exists(text))
                        {
                            string text2 = AppDomain.CurrentDomain.BaseDirectory + DateTime.Now.ToString("yyyyMMddHHmmss") + "_tmpdatadb.mdb";
                            bool   flag  = true;
                            int    num2  = 0;
                            while (flag && num2 < 5)
                            {
                                try
                                {
                                    FileInfo fileInfo = new FileInfo(AppDomain.CurrentDomain.BaseDirectory + "datadb.mdb");
                                    fileInfo.MoveTo(text2);
                                    FileInfo fileInfo2 = new FileInfo(text);
                                    fileInfo2.MoveTo(AppDomain.CurrentDomain.BaseDirectory + "datadb.mdb");
                                    flag = false;
                                    TaskStatus.TMPDB_path = text2;
                                    try
                                    {
                                        File.Delete(TaskStatus.DB_compact_tmp);
                                        TaskStatus.DB_compact_tmp = "";
                                    }
                                    catch
                                    {
                                    }
                                    TaskStatus.SetDBStatus(1);
                                }
                                catch (Exception)
                                {
                                }
                                num2++;
                            }
                            if (flag)
                            {
                                TaskStatus.SetDBStatus(1);
                            }
                            else
                            {
                                OleDbConnection oleDbConnection = null;
                                OleDbCommand    oleDbCommand    = new OleDbCommand();
                                try
                                {
                                    string connectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + TaskStatus.TMPDB_path + ";Jet OLEDB:Database Password=root";
                                    oleDbConnection = new OleDbConnection(connectionString);
                                    oleDbConnection.Open();
                                    oleDbCommand = oleDbConnection.CreateCommand();
                                    try
                                    {
                                        oleDbCommand.CommandText = "select device_id,power_consumption,insert_time from device_data_daily ";
                                        OleDbDataReader oleDbDataReader = oleDbCommand.ExecuteReader();
                                        while (oleDbDataReader.Read())
                                        {
                                            string item = string.Concat(new string[]
                                            {
                                                "update device_data_daily set power_consumption = power_consumption + ",
                                                Convert.ToString(oleDbDataReader.GetValue(1)),
                                                " where device_id = ",
                                                Convert.ToString(oleDbDataReader.GetValue(0)),
                                                " and insert_time = #",
                                                Convert.ToDateTime(oleDbDataReader.GetValue(2)).ToString("yyyy-MM-dd"),
                                                "#"
                                            });
                                            WorkQueue <string> .getInstance_pd().WorkSequential = true;

                                            WorkQueue <string> .getInstance_pd().EnqueueItem(item);
                                        }
                                        oleDbDataReader.Close();
                                    }
                                    catch
                                    {
                                    }
                                    try
                                    {
                                        oleDbCommand.CommandText = "select device_id,power_consumption,insert_time from device_data_hourly ";
                                        OleDbDataReader oleDbDataReader = oleDbCommand.ExecuteReader();
                                        while (oleDbDataReader.Read())
                                        {
                                            string item2 = string.Concat(new string[]
                                            {
                                                "update device_data_hourly set power_consumption = power_consumption + ",
                                                Convert.ToString(oleDbDataReader.GetValue(1)),
                                                " where device_id = ",
                                                Convert.ToString(oleDbDataReader.GetValue(0)),
                                                " and insert_time = #",
                                                Convert.ToDateTime(oleDbDataReader.GetValue(2)).ToString("yyyy-MM-dd HH:mm:ss"),
                                                "#"
                                            });
                                            WorkQueue <string> .getInstance_pd().WorkSequential = true;

                                            WorkQueue <string> .getInstance_pd().EnqueueItem(item2);
                                        }
                                        oleDbDataReader.Close();
                                    }
                                    catch
                                    {
                                    }
                                    try
                                    {
                                        oleDbCommand.CommandText = "select bank_id,power_consumption,insert_time from bank_data_hourly ";
                                        OleDbDataReader oleDbDataReader = oleDbCommand.ExecuteReader();
                                        while (oleDbDataReader.Read())
                                        {
                                            string item3 = string.Concat(new string[]
                                            {
                                                "update bank_data_hourly set power_consumption = power_consumption + ",
                                                Convert.ToString(oleDbDataReader.GetValue(1)),
                                                " where bank_id = ",
                                                Convert.ToString(oleDbDataReader.GetValue(0)),
                                                " and insert_time = #",
                                                Convert.ToDateTime(oleDbDataReader.GetValue(2)).ToString("yyyy-MM-dd HH:mm:ss"),
                                                "#"
                                            });
                                            WorkQueue <string> .getInstance_pd().WorkSequential = true;

                                            WorkQueue <string> .getInstance_pd().EnqueueItem(item3);
                                        }
                                        oleDbDataReader.Close();
                                    }
                                    catch
                                    {
                                    }
                                    try
                                    {
                                        oleDbCommand.CommandText = "select bank_id,power_consumption,insert_time from bank_data_daily ";
                                        OleDbDataReader oleDbDataReader = oleDbCommand.ExecuteReader();
                                        while (oleDbDataReader.Read())
                                        {
                                            string item4 = string.Concat(new string[]
                                            {
                                                "update bank_data_daily set power_consumption = power_consumption + ",
                                                Convert.ToString(oleDbDataReader.GetValue(1)),
                                                " where bank_id = ",
                                                Convert.ToString(oleDbDataReader.GetValue(0)),
                                                " and insert_time = #",
                                                Convert.ToDateTime(oleDbDataReader.GetValue(2)).ToString("yyyy-MM-dd"),
                                                "#"
                                            });
                                            WorkQueue <string> .getInstance_pd().WorkSequential = true;

                                            WorkQueue <string> .getInstance_pd().EnqueueItem(item4);
                                        }
                                        oleDbDataReader.Close();
                                    }
                                    catch
                                    {
                                    }
                                    try
                                    {
                                        oleDbCommand.CommandText = "select port_id,power_consumption,insert_time from port_data_daily ";
                                        OleDbDataReader oleDbDataReader = oleDbCommand.ExecuteReader();
                                        while (oleDbDataReader.Read())
                                        {
                                            string item5 = string.Concat(new string[]
                                            {
                                                "update port_data_daily set power_consumption = power_consumption + ",
                                                Convert.ToString(oleDbDataReader.GetValue(1)),
                                                " where port_id = ",
                                                Convert.ToString(oleDbDataReader.GetValue(0)),
                                                " and insert_time = #",
                                                Convert.ToDateTime(oleDbDataReader.GetValue(2)).ToString("yyyy-MM-dd"),
                                                "#"
                                            });
                                            WorkQueue <string> .getInstance_pd().WorkSequential = true;

                                            WorkQueue <string> .getInstance_pd().EnqueueItem(item5);
                                        }
                                        oleDbDataReader.Close();
                                    }
                                    catch
                                    {
                                    }
                                    try
                                    {
                                        oleDbCommand.CommandText = "select port_id,power_consumption,insert_time from port_data_hourly ";
                                        OleDbDataReader oleDbDataReader = oleDbCommand.ExecuteReader();
                                        while (oleDbDataReader.Read())
                                        {
                                            string item6 = string.Concat(new string[]
                                            {
                                                "update port_data_hourly set power_consumption = power_consumption + ",
                                                Convert.ToString(oleDbDataReader.GetValue(1)),
                                                " where port_id = ",
                                                Convert.ToString(oleDbDataReader.GetValue(0)),
                                                " and insert_time = #",
                                                Convert.ToDateTime(oleDbDataReader.GetValue(2)).ToString("yyyy-MM-dd HH:mm:ss"),
                                                "#"
                                            });
                                            WorkQueue <string> .getInstance_pd().WorkSequential = true;

                                            WorkQueue <string> .getInstance_pd().EnqueueItem(item6);
                                        }
                                        oleDbDataReader.Close();
                                    }
                                    catch
                                    {
                                    }
                                    try
                                    {
                                        oleDbCommand.CommandText = "select device_id,power,insert_time from device_auto_info ";
                                        OleDbDataReader oleDbDataReader = oleDbCommand.ExecuteReader();
                                        while (oleDbDataReader.Read())
                                        {
                                            string item7 = string.Concat(new string[]
                                            {
                                                "insert into device_auto_info (device_id,power,insert_time ) values(",
                                                Convert.ToString(oleDbDataReader.GetValue(0)),
                                                ",",
                                                Convert.ToString(oleDbDataReader.GetValue(1)),
                                                ",#",
                                                Convert.ToDateTime(oleDbDataReader.GetValue(2)).ToString("yyyy-MM-dd HH:mm:ss"),
                                                "#)"
                                            });
                                            WorkQueue <string> .getInstance().WorkSequential = true;

                                            WorkQueue <string> .getInstance().EnqueueItem(item7);
                                        }
                                        oleDbDataReader.Close();
                                    }
                                    catch
                                    {
                                    }
                                    try
                                    {
                                        oleDbCommand.CommandText = "select bank_id,power,insert_time from bank_auto_info ";
                                        OleDbDataReader oleDbDataReader = oleDbCommand.ExecuteReader();
                                        while (oleDbDataReader.Read())
                                        {
                                            string item8 = string.Concat(new string[]
                                            {
                                                "insert into bank_auto_info (bank_id,power,insert_time ) values(",
                                                Convert.ToString(oleDbDataReader.GetValue(0)),
                                                ",",
                                                Convert.ToString(oleDbDataReader.GetValue(1)),
                                                ",#",
                                                Convert.ToDateTime(oleDbDataReader.GetValue(2)).ToString("yyyy-MM-dd HH:mm:ss"),
                                                "#)"
                                            });
                                            WorkQueue <string> .getInstance().WorkSequential = true;

                                            WorkQueue <string> .getInstance().EnqueueItem(item8);
                                        }
                                        oleDbDataReader.Close();
                                    }
                                    catch
                                    {
                                    }
                                    try
                                    {
                                        oleDbCommand.CommandText = "select port_id,power,insert_time from port_auto_info ";
                                        OleDbDataReader oleDbDataReader = oleDbCommand.ExecuteReader();
                                        while (oleDbDataReader.Read())
                                        {
                                            string item9 = string.Concat(new string[]
                                            {
                                                "insert into port_auto_info (port_id,power,insert_time ) values(",
                                                Convert.ToString(oleDbDataReader.GetValue(0)),
                                                ",",
                                                Convert.ToString(oleDbDataReader.GetValue(1)),
                                                ",#",
                                                Convert.ToDateTime(oleDbDataReader.GetValue(2)).ToString("yyyy-MM-dd HH:mm:ss"),
                                                "#)"
                                            });
                                            WorkQueue <string> .getInstance().WorkSequential = true;

                                            WorkQueue <string> .getInstance().EnqueueItem(item9);
                                        }
                                        oleDbDataReader.Close();
                                    }
                                    catch
                                    {
                                    }
                                    oleDbCommand.Dispose();
                                    oleDbConnection.Close();
                                    try
                                    {
                                        TaskStatus.DB_compact_final = "";
                                        File.Delete(TaskStatus.TMPDB_path);
                                    }
                                    catch
                                    {
                                    }
                                    DebugCenter.GetInstance().appendToFile("Finish compact Access Database ");
                                }
                                catch (Exception)
                                {
                                    oleDbCommand.Dispose();
                                    if (oleDbConnection != null)
                                    {
                                        oleDbConnection.Close();
                                    }
                                }
                            }
                        }
                    }
                    catch (Exception)
                    {
                    }
                }
            }
            catch (Exception)
            {
            }
            Interlocked.Exchange(ref this._threadDone, 1);
        }
예제 #7
0
        public void QueueWork4Data(object sender, WorkQueue <GatewayDataCell> .EnqueueEventArgs e)
        {
            DbCommand    dbCommand    = null;
            DbDataReader dbDataReader = null;

            if (this.con == null || this.con.State != ConnectionState.Open)
            {
                if (this.con != null)
                {
                    try
                    {
                        this.con.Close();
                    }
                    catch (Exception)
                    {
                    }
                }
                try
                {
                    if (DBUrl.SERVERMODE)
                    {
                        this.con = this.getConnection();
                    }
                    else
                    {
                        string connectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + DBUrl.DEFAULT_HOST_PATH + ";Jet OLEDB:Database Password="******"DBERROR~~~~~~~~~~~DBERROR : " + ex.Message + "\n" + ex.StackTrace);
                }
            }
            try
            {
                GatewayDataCell item = e.Item;
                dbCommand             = this.con.CreateCommand();
                dbCommand.CommandText = string.Concat(new string[]
                {
                    "select eleflag from gatewaytable where gid='",
                    item.GatewayID,
                    "' and bid='",
                    item.BranchID,
                    "' and sid='",
                    item.SubmeterID,
                    "' "
                });
                object obj = dbCommand.ExecuteScalar();
                if (obj == null || obj is DBNull || Convert.ToInt32(obj) < 1)
                {
                    dbCommand.Dispose();
                }
                else
                {
                    dbCommand.Dispose();
                    int num = Convert.ToInt32(obj);
                    dbCommand             = this.con.CreateCommand();
                    dbCommand.CommandText = string.Concat(new string[]
                    {
                        "select * from gatewaylastpd where bid='",
                        item.BranchID,
                        "' and sid='",
                        item.SubmeterID,
                        "' "
                    });
                    dbDataReader = dbCommand.ExecuteReader();
                    if (dbDataReader.HasRows)
                    {
                        dbDataReader.Read();
                        int      num2     = MyConvert.ToInt32(dbDataReader.GetValue(2));
                        double   @double  = dbDataReader.GetDouble(3);
                        DateTime dateTime = dbDataReader.GetDateTime(4);
                        dbDataReader.Close();
                        dbDataReader.Dispose();
                        dbCommand.Dispose();
                        if (num == num2)
                        {
                            double num3  = item.PD - @double;
                            double num4  = 0.0;
                            double num5  = 0.0;
                            double num6  = 0.0;
                            bool   flag  = this.checkweek(dateTime);
                            bool   flag2 = this.checkday(dateTime);
                            bool   flag3 = this.checkhour(dateTime);
                            if (flag)
                            {
                                num4 = num3;
                            }
                            if (flag2)
                            {
                                num5 = num3;
                            }
                            if (flag3)
                            {
                                num6 = num3;
                            }
                            dbCommand             = this.con.CreateCommand();
                            dbCommand.CommandText = "select lasttime from currentpue ";
                            obj = dbCommand.ExecuteScalar();
                            string text  = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, DateTime.Now.Hour, 0, 0).ToString("yyyy-MM-dd HH:mm:ss");
                            string text2 = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, 0, 0, 0).ToString("yyyy-MM-dd HH:mm:ss");
                            string text3 = this.getweek().ToString("yyyy-MM-dd HH:mm:ss");
                            if (obj == null || obj is DBNull)
                            {
                                if (num == 1)
                                {
                                    dbCommand.CommandText = string.Concat(new object[]
                                    {
                                        "insert into currentpue (curhour,curday,curweek,ithourpue,nonithourpue,itdaypue,nonitdaypue,itweekpue,nonitweekpue,lasttime) values(#",
                                        text,
                                        "#,#",
                                        text2,
                                        "#,#",
                                        text3,
                                        "#,",
                                        num6,
                                        ",0,",
                                        num5,
                                        ",0,",
                                        num4,
                                        ",0,#",
                                        DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"),
                                        "# ) "
                                    });
                                }
                                else
                                {
                                    if (num == 2)
                                    {
                                        dbCommand.CommandText = string.Concat(new object[]
                                        {
                                            "insert into currentpue (curhour,curday,curweek,ithourpue,nonithourpue,itdaypue,nonitdaypue,itweekpue,nonitweekpue,lasttime) values(#",
                                            text,
                                            "#,#",
                                            text2,
                                            "#,#",
                                            text3,
                                            "#,0,",
                                            num6,
                                            ",0,",
                                            num5,
                                            ",0,",
                                            num4,
                                            ",#",
                                            DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"),
                                            "# ) "
                                        });
                                    }
                                }
                                if (DBUrl.SERVERMODE)
                                {
                                    dbCommand.CommandText = dbCommand.CommandText.Replace("#", "'");
                                }
                            }
                            else
                            {
                                DateTime dt_time = Convert.ToDateTime(obj);
                                string   text4   = "";
                                if (this.checkweek(dt_time))
                                {
                                    if (this.checkday(dt_time))
                                    {
                                        if (this.checkhour(dt_time))
                                        {
                                            if (num == 1)
                                            {
                                                text4 = string.Concat(new object[]
                                                {
                                                    "update currentpue set curhour=#",
                                                    text,
                                                    "#,curday=#",
                                                    text2,
                                                    "#,curweek=#",
                                                    text3,
                                                    "#,ithourpue=ithourpue+",
                                                    num6,
                                                    ",itdaypue=itdaypue+",
                                                    num5,
                                                    ",itweekpue=itweekpue+",
                                                    num4,
                                                    ",lasttime=#",
                                                    DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"),
                                                    "# "
                                                });
                                            }
                                            else
                                            {
                                                if (num == 2)
                                                {
                                                    text4 = string.Concat(new object[]
                                                    {
                                                        "update currentpue set curhour=#",
                                                        text,
                                                        "#,curday=#",
                                                        text2,
                                                        "#,curweek=#",
                                                        text3,
                                                        "#,nonithourpue=nonithourpue+",
                                                        num6,
                                                        ",nonitdaypue=nonitdaypue+",
                                                        num5,
                                                        ",nonitweekpue=nonitweekpue+",
                                                        num4,
                                                        ",lasttime=#",
                                                        DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"),
                                                        "# "
                                                    });
                                                }
                                            }
                                        }
                                        else
                                        {
                                            if (num == 1)
                                            {
                                                text4 = string.Concat(new object[]
                                                {
                                                    "update currentpue set curhour=#",
                                                    text,
                                                    "#,curday=#",
                                                    text2,
                                                    "#,curweek=#",
                                                    text3,
                                                    "#,nonithourpue=0,ithourpue=",
                                                    num6,
                                                    ",itdaypue=itdaypue+",
                                                    num5,
                                                    ",itweekpue=itweekpue+",
                                                    num4,
                                                    ",lasttime=#",
                                                    DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"),
                                                    "# "
                                                });
                                            }
                                            else
                                            {
                                                if (num == 2)
                                                {
                                                    text4 = string.Concat(new object[]
                                                    {
                                                        "update currentpue set curhour=#",
                                                        text,
                                                        "#,curday=#",
                                                        text2,
                                                        "#,curweek=#",
                                                        text3,
                                                        "#,ithourpue=0,nonithourpue=",
                                                        num6,
                                                        ",nonitdaypue=nonitdaypue+",
                                                        num5,
                                                        ",nonitweekpue=nonitweekpue+",
                                                        num4,
                                                        ",lasttime=#",
                                                        DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"),
                                                        "# "
                                                    });
                                                }
                                            }
                                        }
                                    }
                                    else
                                    {
                                        if (num == 1)
                                        {
                                            text4 = string.Concat(new object[]
                                            {
                                                "update currentpue set curhour=#",
                                                text,
                                                "#,curday=#",
                                                text2,
                                                "#,curweek=#",
                                                text3,
                                                "#,ithourpue=",
                                                num6,
                                                ",nonithourpue=0,itdaypue=",
                                                num5,
                                                ",nonitdaypue=0,itweekpue=itweekpue+",
                                                num4,
                                                ",lasttime=#",
                                                DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"),
                                                "# "
                                            });
                                        }
                                        else
                                        {
                                            if (num == 2)
                                            {
                                                text4 = string.Concat(new object[]
                                                {
                                                    "update currentpue set curhour=#",
                                                    text,
                                                    "#,curday=#",
                                                    text2,
                                                    "#,curweek=#",
                                                    text3,
                                                    "#,nonithourpue=",
                                                    num6,
                                                    ",ithourpue=0,nonitdaypue=",
                                                    num5,
                                                    ",itdaypue=0,nonitweekpue=nonitweekpue+",
                                                    num4,
                                                    ",lasttime=#",
                                                    DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"),
                                                    "# "
                                                });
                                            }
                                        }
                                    }
                                }
                                else
                                {
                                    text4 = string.Concat(new string[]
                                    {
                                        "update currentpue set curhour=#",
                                        text,
                                        "#,curday=#",
                                        text2,
                                        "#,curweek=#",
                                        text3,
                                        "#,ithourpue=0,nonithourpue=0,itdaypue=0,nonitdaypue=0,itweekpue=0,nonitweekpue=0,lasttime=#",
                                        DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"),
                                        "# "
                                    });
                                }
                                if (DBUrl.SERVERMODE)
                                {
                                    text4 = text4.Replace("#", "'");
                                }
                                dbCommand.CommandText = text4;
                            }
                            DbTransaction dbTransaction = this.con.BeginTransaction();
                            dbCommand.Transaction = dbTransaction;
                            dbCommand.ExecuteNonQuery();
                            dbCommand.Transaction.Commit();
                            dbTransaction.Dispose();
                            dbCommand.Dispose();
                        }
                        this.ModifyLastPD(this.con, item.BranchID, item.SubmeterID, num, item.PD, item.RecordTime, "UPDATE");
                    }
                    else
                    {
                        dbDataReader.Close();
                        dbDataReader.Dispose();
                        dbCommand.Dispose();
                        this.ModifyLastPD(this.con, item.BranchID, item.SubmeterID, num, item.PD, item.RecordTime, "INSERT");
                    }
                }
            }
            catch (Exception ex2)
            {
                DebugCenter.GetInstance().appendToFile("DBERROR~~~~~~~~~~~DBERROR : " + ex2.Message + "\n" + ex2.StackTrace);
                if (dbDataReader != null)
                {
                    try
                    {
                        dbDataReader.Close();
                        dbDataReader.Dispose();
                    }
                    catch (Exception)
                    {
                    }
                }
                if (dbCommand != null)
                {
                    try
                    {
                        dbCommand.Transaction.Rollback();
                        dbCommand.Dispose();
                    }
                    catch (Exception)
                    {
                    }
                }
            }
        }
예제 #8
0
        public void workQueue_DBWork(object sender, WorkQueue <string> .EnqueueEventArgs e)
        {
            try
            {
                if (!DBWorkThread.STOP_THREAD)
                {
                    string text = "";
                    if (TaskStatus.GetDBStatus() == -1)
                    {
                        try
                        {
                            this.con.Close();
                            this.con.Dispose();
                            this.con = null;
                        }
                        catch
                        {
                        }
                    }
                    if (this.con == null)
                    {
                        if (DBUrl.SERVERMODE)
                        {
                            string   cONNECT_STRING = DBUrl.CONNECT_STRING;
                            string[] array          = cONNECT_STRING.Split(new string[]
                            {
                                ","
                            }, StringSplitOptions.RemoveEmptyEntries);
                            this.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=50;Default Command Timeout=0;charset=utf8;"
                            }));
                            this.con.Open();
                        }
                        else
                        {
                            if (DBWorkThread.STOP_THREAD)
                            {
                                return;
                            }
                            switch (this.DBTYPE)
                            {
                            case 0:
                                break;

                            case 1:
                                try
                                {
                                    this.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;"
                                    }));
                                    this.con.Open();
                                    DebugCenter.GetInstance().clearStatusCode(DebugCenter.ST_MYSQLCONNECT_LOST, true);
                                    goto IL_2A6;
                                }
                                catch (Exception e2)
                                {
                                    DebugCenter.GetInstance().setLastStatusCode(DebugCenter.ST_MYSQLCONNECT_LOST, true);
                                    DebugCenter.GetInstance().appendToFile("Could not create MySQL connection : \r\n" + CommonAPI.ReportException(0, e2, false, "    "));
                                    goto IL_2A6;
                                }
                                break;

                            default:
                                goto IL_2A6;
                            }
                            try
                            {
                                "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + DBUrl.CURRENT_HOST_PATH + ";Jet OLEDB:Database Password="******"Waiting DBConnection : " + num);
                                    num++;
                                }
                                DBConn dynaConnection = DBConnPool.getDynaConnection();
                                if (dynaConnection != null)
                                {
                                    this.con = dynaConnection.con;
                                }
                                else
                                {
                                    this.con = null;
                                }
                            }
                            catch (Exception ex)
                            {
                                DebugCenter.GetInstance().appendToFile("DBERROR~~~~~~~~~~~DBERROR : " + ex.Message + "\n" + ex.StackTrace);
                            }
                        }
                    }
                    try
                    {
IL_2A6:
                        if (this.con.State != ConnectionState.Open)
                        {
                            try
                            {
                                this.con.Close();
                                this.con.Open();
                            }
                            catch (Exception e3)
                            {
                                this.con = null;
                                DebugCenter.GetInstance().setLastStatusCode(DebugCenter.ST_MYSQLCONNECT_LOST, true);
                                DebugCenter.GetInstance().appendToFile("Could not create MySQL connection : \r\n" + CommonAPI.ReportException(0, e3, false, "    "));
                            }
                        }
                    }
                    catch
                    {
                    }
                    try
                    {
                        if (this.cmd != null)
                        {
                            this.cmd.Dispose();
                        }
                    }
                    catch (Exception ex2)
                    {
                        DebugCenter.GetInstance().appendToFile("DBERROR~~~~~~~~~~~DBERROR : " + ex2.Message + "\n" + ex2.StackTrace);
                    }
                    try
                    {
                        string item = e.Item;
                        if (item.StartsWith("PDEND"))
                        {
                            InSnergyGateway.Need_Calculate_PUE = true;
                            DBWorkThread.NEEDLOG = true;
                        }
                        else
                        {
                            if (item.IndexOf("END") > -1)
                            {
                                DBCacheStatus.LastInsertTime = DateTime.Now;
                                DBWorkThread.NEEDLOG         = true;
                            }
                            else
                            {
                                this.cmd = this.con.CreateCommand();
                                int num2 = this.NeedU2I(item);
                                if (this.DBTYPE == 1 || DBUrl.SERVERMODE)
                                {
                                    string commandText = item.Replace("#", "'");
                                    this.cmd.CommandText = commandText;
                                }
                                else
                                {
                                    this.cmd.CommandText = item;
                                }
                                text = this.cmd.CommandText;
                                if (!DBWorkThread.STOP_THREAD)
                                {
                                    int num3 = this.cmd.ExecuteNonQuery();
                                    if (num3 < 1 && num2 > 0)
                                    {
                                        if (this.DBTYPE == 1 || DBUrl.SERVERMODE)
                                        {
                                            string text2 = this.ChgU2I(item, num2);
                                            text2 = text2.Replace("#", "'");
                                            this.cmd.CommandText = text2;
                                        }
                                        else
                                        {
                                            this.cmd.CommandText = this.ChgU2I(item, num2);
                                        }
                                        text = this.cmd.CommandText;
                                        if (DBWorkThread.STOP_THREAD)
                                        {
                                            return;
                                        }
                                        this.cmd.ExecuteNonQuery();
                                    }
                                    this.cmd.Dispose();
                                    if (TaskStatus.GetDBStatus() == -1)
                                    {
                                        try
                                        {
                                            this.con.Close();
                                        }
                                        catch
                                        {
                                        }
                                        try
                                        {
                                            this.con.Dispose();
                                        }
                                        catch
                                        {
                                        }
                                        this.con = null;
                                    }
                                }
                            }
                        }
                    }
                    catch (Exception ex3)
                    {
                        if (ex3.GetType().FullName.Equals("MySql.Data.MySqlClient.MySqlException"))
                        {
                            string tableName = DBUtil.GetTableName(text);
                            if (tableName != null && tableName.Length > 0)
                            {
                                DBUtil.SetMySQLInfo(tableName);
                                DebugCenter.GetInstance().appendToFile("MySQL database is marked as crashed, EcoSensor Monitor Service will be shutdown ");
                                DBUtil.StopService();
                            }
                        }
                        if (ex3.Message.ToLower().IndexOf("fatal error encountered during command execution") < 0)
                        {
                            if (text.IndexOf("rack_effect") > 0)
                            {
                                try
                                {
                                    DBTools.Write_DBERROR_Log();
                                    goto IL_56F;
                                }
                                catch
                                {
                                    goto IL_56F;
                                }
                            }
                            if (DBWorkThread.NEEDLOG)
                            {
                                try
                                {
                                    DBTools.Write_DBERROR_Log();
                                }
                                catch
                                {
                                }
                                DBWorkThread.NEEDLOG = false;
                            }
IL_56F:
                            DebugCenter.GetInstance().appendToFile("DBERROR~~~~~~~~~~~DBERROR : " + ex3.Message + "\n" + ex3.StackTrace);
                        }
                        try
                        {
                            this.cmd.Dispose();
                            this.con.Close();
                        }
                        catch (Exception)
                        {
                        }
                        this.con = null;
                    }
                }
            }
            finally
            {
                try
                {
                    if (this.con != null)
                    {
                        this.con.Close();
                    }
                    this.con = null;
                }
                catch
                {
                }
            }
        }