public HttpServer(char v_delimiter, string v_datafile, PgSqlDAL v_dao) { delimiter = v_delimiter; datafile = v_datafile; uriPrefix = ConfigurationManager.AppSettings["ReceiveMessageUri"].ToString(); dao = v_dao; listener = new HttpListener(); listener.Prefixes.Add(uriPrefix);//server url listener.Start(); //Start 20 servers for (int x = 0; x < 20; x++) { listener.BeginGetContext(new AsyncCallback(ListenerCallback), this.listener); } }
private void frmMain_Load(object sender, EventArgs e) { exitFlag = 0; string filedir = Application.StartupPath.ToString(); reportfile = filedir + "\\" + ConfigurationManager.AppSettings["ReportFile"].ToString(); //ReportFile.xml"; datafile = filedir + "\\" + ConfigurationManager.AppSettings["DataFile"].ToString(); //TimeSheet.txt"; CheckOutputFile(datafile); delimiter = '^'; // Set up the timer tmrDigitalClock = new System.Windows.Forms.Timer(); tmrDigitalClock.Enabled = true; tmrDigitalClock.Interval = 1000; tmrDigitalClock.Tick += new System.EventHandler(tmrDigitalClock_Tick); tmrSMSprocess = new System.Windows.Forms.Timer(); tmrSMSprocess.Enabled = true; tmrSMSprocess.Interval = 30000; tmrSMSprocess.Tick += new System.EventHandler(tmrSMSprocess_Tick); starttime = System.DateTime.MinValue; /*Begin: Same as btnStart_Click() function.*/ // Make UI read only for the duration. btnStart.Enabled = false; btnStop.Enabled = true; starttime = DateTime.Now; /*End: Same as btnStart_Click() function.*/ txtStartDate.Text = DateTime.Now.ToString("dd/MM/yyyy"); txtEndDate.Text = DateTime.Now.AddDays(1).ToString("dd/MM/yyyy"); //InitializeComponent(); mytable = CreateTable(); mysummarytable = CreateTable(); dao = new PgSqlDAL(ConfigurationManager.AppSettings["ConnectionString"].ToString()); /*Begin: kiểm tra và tạo ozekimessagein & ozekimessageout nếu chưa có.*/ try { DataSet ds = dao.ExecuteDataSet("SELECT * FROM " + ConfigurationManager.AppSettings["Schema"].ToString() + "ozekimessageout LIMIT 1"); } catch (Exception ex) { if (ex.Message.IndexOf("does not exist") != -1) { string sqlQuery = "CREATE TABLE " + ConfigurationManager.AppSettings["Schema"].ToString() + "ozekimessagein(id serial NOT NULL,sender character varying(30),receiver character varying(30),msg character varying(160),senttime character varying(100),receivedtime character varying(100),\"operator\" character varying(100),msgtype character varying(160),reference character varying(100),status character varying(20),CONSTRAINT ozekimessagein_id PRIMARY KEY (id) USING INDEX TABLESPACE medi_index) WITH (OIDS=FALSE);"; int result = dao.ExecuteQuery(sqlQuery); sqlQuery = "ALTER TABLE " + ConfigurationManager.AppSettings["Schema"].ToString() + "ozekimessagein OWNER TO medisoft;"; result = dao.ExecuteQuery(sqlQuery); sqlQuery = "CREATE TABLE " + ConfigurationManager.AppSettings["Schema"].ToString() + "ozekimessageout(id serial NOT NULL,sender character varying(30),receiver character varying(30),msg character varying(160),senttime character varying(100),receivedtime character varying(100),reference character varying(100),status character varying(20),\"operator\" character varying(100),msgtype character varying(160),CONSTRAINT ozekimessageout_id PRIMARY KEY (id) USING INDEX TABLESPACE medi_index) WITH (OIDS=FALSE);"; result = dao.ExecuteQuery(sqlQuery); sqlQuery = "ALTER TABLE " + ConfigurationManager.AppSettings["Schema"].ToString() + "ozekimessageout OWNER TO medisoft;"; result = dao.ExecuteQuery(sqlQuery); } } /*End: kiểm tra và tạo ozekimessagein & ozekimessageout nếu chưa có.*/ smsReceiver = new HttpServer(delimiter, datafile, dao); }