예제 #1
0
        private async void BiostarTest_btn(object sender, EventArgs e)
        {
            BiostarModule bs        = new BiostarModule();
            var           groupDict = await bs.BSGetGroups();

            foreach (int key in groupDict.Keys)
            {
                //MessageBox.Show(String.Format("{0} : {1}", key, groupDict[key]));
            }
            for (int i = 0; i < userDataDGV.Rows.Count - 1; i++)
            {
                var    targetRow = userDataDGV.Rows[i].Cells;
                string userID    = targetRow[1].Value.ToString();
                int    groupID;
                if (targetRow[2].Value.ToString() == "M")
                {
                    groupID = 1;
                }
                else
                {
                    groupID = 2;
                }
                bs.BSUpdateUser(userID, groupID, 202008);
            }
        }
예제 #2
0
        static async void ResponseThread() // 웹 제어용 Response Thread
        {
            while (threadControl)
            {
                try
                {
                    HttpListenerContext context = _httpListener.GetContext();
                    context.Response.Headers.Add("Access-Control-Allow-Origin", "*");
                    context.Response.Headers.Add("Access-Control-Allow-Methods", "POST, GET");
                    byte[] _responseArray = Encoding.UTF8.GetBytes("");

                    if (context.Request.HttpMethod == "POST")   // POST 신호를 받았을 때 (POST)
                    {
                        var     body     = new StreamReader(context.Request.InputStream).ReadToEnd();
                        JObject jsonBody = (JObject)JsonConvert.DeserializeObject(body);

                        if (jsonBody.SelectToken("pw").ToString() == "seven7757")   // pw가 일치할 때
                        {
                            var command = context.Request.RawUrl.ToString().Split('/');
                            if (command[1] == "api")    // api request 일 때
                            {
                                BiostarModule bs = new BiostarModule();
                                if (command[2] == "users") // users request 일 때
                                {
                                    string userID    = jsonBody.SelectToken("user_id").ToString();
                                    string startTime = jsonBody.SelectToken("s_time").ToString();
                                    string endTime   = jsonBody.SelectToken("e_time").ToString();
                                    await bs.BSRegisterUser(userID, startTime, endTime);

                                    _responseArray = Encoding.UTF8.GetBytes("ok");
                                    context.Response.OutputStream.Write(_responseArray, 0, _responseArray.Length);
                                    context.Response.KeepAlive = false;
                                    context.Response.Close();
                                }
                            }
                        }
                        _responseArray = Encoding.UTF8.GetBytes("ok");
                        context.Response.OutputStream.Write(_responseArray, 0, _responseArray.Length);
                        context.Response.KeepAlive = false;
                        context.Response.Close();
                    }
                    else if (context.Request.HttpMethod == "GET")   // GET 요청을 받았을 때
                    {
                        JObject jsonBody = (JObject)JsonConvert.DeserializeObject(new StreamReader(context.Request.InputStream).ReadToEnd());
                        var     command  = context.Request.RawUrl.ToString().Split('/');
                        if (command[1] == "api")       // api request 일 때
                        {
                            if (command[2] == "doors") // doors request 일 때
                            {
                                if (entrance)
                                {
                                    _responseArray = Encoding.UTF8.GetBytes("T");
                                }
                                else
                                {
                                    _responseArray = Encoding.UTF8.GetBytes("F");
                                }
                                context.Response.OutputStream.Write(_responseArray, 0, _responseArray.Length);
                                context.Response.KeepAlive = false;
                                context.Response.Close();
                            }
                        }
                    }
                }
                catch { }
            }
        }