Beispiel #1
0
        private object dbImportPro(object param)
        {
            string str_file = (string)param;

            EcoGlobalVar.ECOAppRunStatus = 2;
            Program.StopService(EcoGlobalVar.gl_ServiceName, 30000);
            System.Threading.Thread.Sleep(3000);
            bool flag = false;

            try
            {
                flag = DBTools.ImportDatabase(str_file);
            }
            catch (System.Exception)
            {
            }
            InterProcessShared <System.Collections.Generic.Dictionary <string, string> > .setInterProcessKeyValue("ServiceStDBMaintain", "DBMaintainFinish");

            EcoGlobalVar.ECOAppRunStatus = 1;
            if (!flag)
            {
                return(-1);
            }
            return(1);
        }
Beispiel #2
0
        private object RestorecfgPro(object param)
        {
            string str_file = (string)param;

            EcoGlobalVar.ECOAppRunStatus = 2;
            Program.StopService(EcoGlobalVar.gl_ServiceName, 30000);
            System.Threading.Thread.Sleep(3000);
            int num = Backuptask.RestoreConfig(str_file);

            InterProcessShared <System.Collections.Generic.Dictionary <string, string> > .setInterProcessKeyValue("ServiceStDBMaintain", "DBMaintainFinish");

            Program.StartService(null);
            return(num);
        }
Beispiel #3
0
 public static void SetConvertOldDataStatus(bool b_status)
 {
     lock (DBMaintain._ConvertLock)
     {
         DBMaintain.b_convertfinish = b_status;
         if (b_status)
         {
             InterProcessShared <Dictionary <string, string> > .setInterProcessKeyValue("CONVERTDATATHREADSTATUS", "TRUE");
         }
         else
         {
             InterProcessShared <Dictionary <string, string> > .setInterProcessKeyValue("CONVERTDATATHREADSTATUS", "FALSE");
         }
     }
 }
Beispiel #4
0
        private void dbchangeDlg_FormClosing(object sender, FormClosingEventArgs e)
        {
            if (this.m_normalclose == 1)
            {
                if (this.butCancel.Enabled)
                {
                    this.b_cancel = true;
                    AccessDBUpdate.b_cancel_flag = true;
                    this.m_normalclose           = 3;
                    InterProcessShared <System.Collections.Generic.Dictionary <string, string> > .setInterProcessKeyValue("ServiceStDBMaintain", "DBMaintainFinish");

                    Program.StartService(null);
                    return;
                }
                e.Cancel = true;
            }
        }
Beispiel #5
0
        public static void StopService(string serviceName, int timeoutMilliseconds)
        {
            InterProcessShared <System.Collections.Generic.Dictionary <string, string> > .setInterProcessKeyValue("ServiceStDBMaintain", "DBMaintain");

            ServiceController serviceController = new ServiceController(serviceName);

            try
            {
                System.TimeSpan timeout = System.TimeSpan.FromMilliseconds((double)timeoutMilliseconds);
                ClientAPI.StopBroadcastChannel();
                serviceController.Stop();
                serviceController.WaitForStatus(ServiceControllerStatus.Stopped, timeout);
            }
            catch
            {
            }
        }
Beispiel #6
0
        private object dbImportPro(object param)
        {
            string          path            = (string)param;
            DbImportHandler dbImportHandler = new DbImportHandler(path);

            EcoGlobalVar.ECOAppRunStatus = 2;
            Program.StopService(EcoGlobalVar.gl_ServiceName, 30000);
            System.Threading.Thread.Sleep(3000);
            bool flag = dbImportHandler.HandleEvennt();

            InterProcessShared <System.Collections.Generic.Dictionary <string, string> > .setInterProcessKeyValue("ServiceStDBMaintain", "DBMaintainFinish");

            Program.StartService(null);
            if (!flag)
            {
                return(-1);
            }
            return(1);
        }
Beispiel #7
0
        private object dbExportPro(object obj)
        {
            DbExportHanler dbExportHanler = new DbExportHanler(this.tbExportPath.Text);

            EcoGlobalVar.ECOAppRunStatus = 2;
            Program.StopService(EcoGlobalVar.gl_ServiceName, 30000);
            this.syncThreshold();
            System.Threading.Thread.Sleep(3000);
            bool flag = dbExportHanler.HandleEvennt();

            InterProcessShared <System.Collections.Generic.Dictionary <string, string> > .setInterProcessKeyValue("ServiceStDBMaintain", "DBMaintainFinish");

            Program.StartService(null);
            if (flag)
            {
                return(1);
            }
            return(-1);
        }
Beispiel #8
0
        public static object StartService(object param)
        {
            System.Threading.Thread.Sleep(500);
            System.TimeSpan timeout = System.TimeSpan.FromMilliseconds(30000.0);
            try
            {
                ServiceController serviceController = new ServiceController(EcoGlobalVar.gl_ServiceName);
                if (serviceController.Status.Equals(ServiceControllerStatus.Running))
                {
                    object result = 0;
                    return(result);
                }
                InterProcessShared <System.Collections.Generic.Dictionary <string, string> > .setInterProcessKeyValue("ServiceStatus", "waiting");

                serviceController.Start();
                serviceController.WaitForStatus(ServiceControllerStatus.Running, timeout);
            }
            catch (System.Exception)
            {
                object result = -1;
                return(result);
            }
            return(Program.waitService_initfinish());
        }
Beispiel #9
0
        public void Execute(DateTime tDataTime, Hashtable data2DB, Hashtable existed)
        {
            if (data2DB == null || data2DB.Count <= 0)
            {
                DataWareHouse._tLastDataTime = tDataTime;
                return;
            }
            if (DBUrl.DB_CURRENT_TYPE.ToUpper().Equals("ACCESS"))
            {
                this.ht_All = data2DB;
            }
            if (data2DB.ContainsKey("PD"))
            {
                this.ht_powerPD = (Hashtable)data2DB["PD"];
                if (this.ht_powerPD != null && this.ht_powerPD.Count > 0)
                {
                    if (this.ht_powerPD.ContainsKey("DEVICE"))
                    {
                        this.ht_pdDev = (Hashtable)this.ht_powerPD["DEVICE"];
                        if (this.ht_pdDev.Count <= 0)
                        {
                            this.ht_pdDev = null;
                        }
                    }
                    if (this.ht_powerPD.ContainsKey("OUTLET"))
                    {
                        this.ht_pdPort = (Hashtable)this.ht_powerPD["OUTLET"];
                        if (this.ht_pdPort.Count <= 0)
                        {
                            this.ht_pdPort = null;
                        }
                    }
                }
            }
            if (data2DB.ContainsKey("POWER"))
            {
                this.ht_power = (Hashtable)data2DB["POWER"];
                if (this.ht_power != null && this.ht_power.Count > 0)
                {
                    if (this.ht_power.ContainsKey("DEVICE"))
                    {
                        this.ht_pwDev = (Hashtable)this.ht_power["DEVICE"];
                        if (this.ht_pwDev.Count <= 0)
                        {
                            this.ht_pwDev = null;
                        }
                    }
                    if (this.ht_power.ContainsKey("OUTLET"))
                    {
                        this.ht_pwPort = (Hashtable)this.ht_power["OUTLET"];
                        if (this.ht_pwPort.Count <= 0)
                        {
                            this.ht_pwPort = null;
                        }
                    }
                }
            }
            string tableSuffix         = tDataTime.ToString("yyyyMMdd");
            List <StorageContext> list = new List <StorageContext>();

            if (DBUrl.DB_CURRENT_TYPE.ToUpper().Equals("MYSQL"))
            {
                this.ht_All = null;
                if (this.ht_pwDev != null)
                {
                    list.Add(new StorageContext
                    {
                        _tDataTime   = tDataTime,
                        _sDataTime   = tDataTime.ToString("yyyy-MM-dd HH:mm:ss"),
                        _htData      = this.ht_pwDev,
                        _dataRatio   = 10000.0,
                        _htExisted   = null,
                        _tablePrefix = "dev_min_pw_pd_",
                        _tableSuffix = tableSuffix
                    });
                }
                if (this.ht_pwPort != null)
                {
                    list.Add(new StorageContext
                    {
                        _tDataTime   = tDataTime,
                        _sDataTime   = tDataTime.ToString("yyyy-MM-dd HH:mm:ss"),
                        _htData      = this.ht_pwPort,
                        _dataRatio   = 10000.0,
                        _htExisted   = null,
                        _tablePrefix = "port_min_pw_pd_",
                        _tableSuffix = tableSuffix
                    });
                }
            }
            else
            {
                if (this.ht_All != null)
                {
                    list.Add(new StorageContext
                    {
                        _tDataTime      = tDataTime,
                        _tablePrefix    = "UpdateForAccess",
                        _AllData4Access = this.ht_All
                    });
                }
            }
            if (this._deviceVoltageList != null)
            {
                list.Add(new StorageContext
                {
                    _tDataTime         = tDataTime,
                    _tablePrefix       = "Voltage",
                    _deviceVoltageList = this._deviceVoltageList
                });
            }
            if (this._lastSensorMaxValue != null)
            {
                list.Add(new StorageContext
                {
                    _tDataTime          = tDataTime,
                    _tablePrefix        = "SensorThermal",
                    _lastSensorMaxValue = this._lastSensorMaxValue
                });
            }
            DateTime now = DateTime.Now;

            InterProcessShared <Dictionary <string, string> > .setInterProcessKeyValue("MultiThreadUpdateStatus", "busy");

            this.ParallelUpdate(list.Count, list);
            InterProcessShared <Dictionary <string, string> > .setInterProcessKeyValue("MultiThreadUpdateStatus", "idle");

            DataWareHouse.WriteLog("########## Data2WareHouse, elapsed={0} ms", new string[]
            {
                (DateTime.Now - now).TotalMilliseconds.ToString()
            });
            DataWareHouse._tLastDataTime = tDataTime;
        }
Beispiel #10
0
        private void startDBchange()
        {
            try
            {
                System.Threading.Thread.Sleep(500);
                EcoGlobalVar.ECOAppRunStatus = 2;
                Program.StopService(EcoGlobalVar.gl_ServiceName, 30000);
                System.Threading.Thread.Sleep(500);
                if (DBUrl.DB_CURRENT_TYPE.ToUpper().Equals("MYSQL") && this.m_usemysql)
                {
                    this.m_retv = DBUrl.updatesetting(this.m_port, this.m_usrnm, this.m_psw);
                }
                else
                {
                    this.m_retv = this.updatesetting(this.m_usemysql, this.m_dbIP, this.m_port, this.m_usrnm, this.m_psw);
                }
                string valuePair = ValuePairs.getValuePair("Username");
                if (!string.IsNullOrEmpty(valuePair))
                {
                    LogAPI.writeEventLog("0130020", new string[]
                    {
                        valuePair
                    });
                }
                else
                {
                    LogAPI.writeEventLog("0130020", new string[0]);
                }
                InterProcessShared <System.Collections.Generic.Dictionary <string, string> > .setInterProcessKeyValue("ServiceStDBMaintain", "DBMaintainFinish");

                if (!this.b_cancel)
                {
                    Program.StartService(null);
                }
                ControlAccess.ConfigControl config = delegate(Control control, object param)
                {
                    if (!this.b_cancel)
                    {
                        if (this.m_retv != DebugCenter.ST_Success)
                        {
                            EcoMessageBox.ShowError(this, EcoLanguage.getMsg(LangRes.OPfail, new string[0]));
                        }
                        else
                        {
                            EcoMessageBox.ShowInfo(this, EcoLanguage.getMsg(LangRes.OPsucc, new string[0]));
                        }
                        this.m_normalclose = 2;
                    }
                    base.Close();
                };
                ControlAccess controlAccess = new ControlAccess(this, config);
                controlAccess.Access(this, null);
            }
            catch (System.Exception)
            {
                if (this.m_normalclose == 1)
                {
                    ControlAccess.ConfigControl config2 = delegate(Control control, object param)
                    {
                        EcoMessageBox.ShowError(this, EcoLanguage.getMsg(LangRes.OPfail, new string[0]));
                        this.m_normalclose = 2;
                        base.Close();
                    };
                    ControlAccess controlAccess2 = new ControlAccess(this, config2);
                    controlAccess2.Access(this, null);
                }
            }
        }
Beispiel #11
0
        public static bool StartEcoService(bool ssl, int port, EcoHandler handle)
        {
            Common.WriteLine("StartEcoService... ssl=" + ssl.ToString() + ", port=" + port.ToString(), new string[0]);
            bool flag = false;

            try
            {
                ServerConfig serverConfig = new ServerConfig();
                serverConfig.ssl        = ssl;
                serverConfig.MaxListen  = 100;
                serverConfig.BufferSize = 4096;
                serverConfig.Protocol   = ecoServerProtocol.ServerTypes.TCP;
                serverConfig.serverName = "Eco Server";
                serverConfig.tokenList  = "";
                serverConfig.MaxConnect = 3000;
                serverConfig.port       = 7979;
                if (port != 0)
                {
                    serverConfig.port = port;
                }
                if (serverConfig.ssl)
                {
                    if (File.Exists(ServicesAPI._sCodebase + "MonitorServers.pfx"))
                    {
                        serverConfig.TlsCertificate = new X509Certificate2(ServicesAPI._sCodebase + "MonitorServers.pfx", "ecoserver");
                        ServicesAPI._ecoListener    = new ServerSSL <EcoContext, EcoHandler>(serverConfig);
                    }
                    else
                    {
                        Common.WriteLine("Server Certificate is lost: {0}", new string[]
                        {
                            ServicesAPI._sCodebase + "MonitorServers.pfx"
                        });
                    }
                }
                else
                {
                    ServicesAPI._ecoListener = new BaseTCPServer <EcoContext, EcoHandler>(serverConfig);
                }
                if (ServicesAPI._ecoListener != null)
                {
                    if (port == 0)
                    {
                        Random random = new Random();
                        for (int i = 128; i > 0; i++)
                        {
                            int usePort = 30000 + random.Next(35534);
                            flag = ServicesAPI._ecoListener.Start(handle, usePort);
                            if (flag)
                            {
                                InterProcessShared <Dictionary <string, string> > .setInterProcessKeyValue("Listen_Port", usePort.ToString());

                                ValuePairs.setValuePair("ServicePort", usePort.ToString());
                                ValuePairs.SaveValueKeyToRegistry(true);
                                break;
                            }
                        }
                    }
                    else
                    {
                        flag = ServicesAPI._ecoListener.Start(handle, -1);
                        if (flag)
                        {
                            ValuePairs.setValuePair("ServicePort", port.ToString());
                            ValuePairs.SaveValueKeyToRegistry(true);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Common.WriteLine("StartEcoService: {0}", new string[]
                {
                    ex.Message
                });
            }
            return(flag);
        }