Exemplo n.º 1
0
        public void Handle(BasicReturn basicReturn)
        {
            var toRemove = callbacks.Where(pair => pair.Value(basicReturn)).Select(p => p.Key).ToArray();

            log.DebugFormat("Removing {0} return callbacks from internal storage", toRemove.Length);

            foreach (var id in toRemove)
            {
                Func<BasicReturn, bool> _;
                callbacks.TryRemove(id, out _);
            }
        }
Exemplo n.º 2
0
        public ActionResult <BasicReturn> ChangeActive(Question data)
        {
            BasicReturn _return = new BasicReturn();

            Question _question = new Question(
                data.Guid,
                _user,
                data.Active
                );

            try
            {
                _return = _questions.ChangeActive(_question);
                return(_return);
            }
            catch (System.Exception ex)
            {
                _return.Success = false;
                _return.Message = ex.Message;
                return(_return);
            }
        }
Exemplo n.º 3
0
        public ActionResult <BasicReturn> LogoEdit(Image data)
        {
            BasicReturn _return = new BasicReturn();

            try
            {
                data.CreatedBy = _user;
                _return        = _myImages.LogoEdit(data);
                data.Name      = _return.Code + ".png";
                _blob.SaveBase64(data);
                return(_return);
            }
            catch (System.Exception ex)
            {
                _return.Success = false;
                _return.Message = ex.Message;
                _return.Code    = data.Src;
                _return.Details = ex.StackTrace;

                return(_return);
            }
        }
Exemplo n.º 4
0
        public BasicReturn ValidateLastChanged(string user, string lastChanged, string url)
        {
            BasicReturn _return = new BasicReturn();

            int _user = Convert.ToInt32(user);

            using (SqlConnection Con = new SqlConnection(_connStr.Value.SqlServer))
            {
                using (SqlCommand Cmd = new SqlCommand())
                {
                    Cmd.CommandType = CommandType.StoredProcedure;
                    Cmd.Connection  = Con;
                    Cmd.CommandText = "[sp_VALIDATE_LAST_CHANGED]";

                    Cmd.Parameters.AddWithValue("@USER", user);
                    Cmd.Parameters.AddWithValue("@LAST_CHANGED", Convert.ToDateTime(lastChanged));
                    Cmd.Parameters.AddWithValue("@URL", url);

                    Con.Open();

                    using (SqlDataReader MyDR = Cmd.ExecuteReader())
                    {
                        if (MyDR.HasRows)
                        {
                            MyDR.Read();

                            _return.Success = MyDR.GetBoolean(0);
                        }
                        else
                        {
                            _return.Success = false;
                        }
                    }
                }
            }

            return(_return);
        }
Exemplo n.º 5
0
        public async Task <ActionResult <BasicReturn> > SignOut()
        {
            BasicReturn _return = new BasicReturn();

            try
            {
                int _userID = Convert.ToInt32(User.FindFirst(claim => claim.Type == "UserID")?.Value);
                await HttpContext.SignOutAsync(CookieAuthenticationDefaults.AuthenticationScheme);

                _myIdentity.SignOut(_userID);

                _return.Success = true;

                return(_return);
            }
            catch (System.Exception ex)
            {
                _return.Success = false;
                _return.Message = ex.Message;

                return(_return);
            }
        }
Exemplo n.º 6
0
        private async void BtnCloseShutter_Clicked(object sender, EventArgs e)
        {
            StopFlag = true;

            //var r1 = bluetooth.Check();
            //BasicReturn r1Obj = JsonConvert.DeserializeObject<BasicReturn>(r1);
            //Log.Debug("PPX", r1Obj.Message);

            //string address = "98:D3:C1:FD:41:51";
            //string uuid = "00001101-0000-1000-8000-00805F9B34FB";
            //var r2 = bluetooth.Connect(address, uuid);
            //BasicReturn r2Obj = JsonConvert.DeserializeObject<BasicReturn>(r2);
            //Log.Debug("PPX", r2Obj.Message);

            var         rInfo    = bluetooth.BlinkOff();
            BasicReturn rInfoObj = JsonConvert.DeserializeObject <BasicReturn>(rInfo);

            Log.Debug("PPX", rInfoObj.Message);

            //var rDis = bluetooth.Disconnect();
            //BasicReturn rDisObj = JsonConvert.DeserializeObject<BasicReturn>(rDis);
            //Log.Debug("PPX", rDisObj.Message);
        }
Exemplo n.º 7
0
        void BtConnect()
        {
            var         r1    = bluetooth.Check();
            BasicReturn r1Obj = JsonConvert.DeserializeObject <BasicReturn>(r1);

            Log.Debug("PPX", r1Obj.Message);

            string      address = "98:D3:C1:FD:41:51";
            string      uuid    = "00001101-0000-1000-8000-00805F9B34FB";
            var         r2      = bluetooth.Connect(address, uuid);
            BasicReturn r2Obj   = JsonConvert.DeserializeObject <BasicReturn>(r2);

            Log.Debug("PPX", r2Obj.Message);

            var         rInfo    = bluetooth.ReadInfo();
            BasicReturn rInfoObj = JsonConvert.DeserializeObject <BasicReturn>(rInfo);

            Log.Debug("PPX", rInfoObj.Message);

            //var rDis = bluetooth.Disconnect();
            //BasicReturn rDisObj = JsonConvert.DeserializeObject<BasicReturn>(rDis);
            //Log.Debug("PPX", rDisObj.Message);
        }
Exemplo n.º 8
0
 private void Model_BasicReturn(object sender, BasicReturnEventArgs e)
 {
     BasicReturn?.Invoke(sender, e);
 }
    public string BlinkOn(int time)
    {
        System.IO.Stream outStream;
        try
        {
            outStream = btSocket.OutputStream;
        }
        catch (System.Exception ex1)
        {
            Log.Debug("PPX", ex1.Message);
            BasicReturn rEx1 = new BasicReturn()
            {
                Flag = false, Code = "OE1", Message = "Socket สร้างไม่สำเร็จ"
            };
            return(JsonConvert.SerializeObject(rEx1, Formatting.Indented));
        }
        //System.IO.Stream inStream;
        //try
        //{
        //    inStream = btSocket.InputStream;
        //}
        //catch (System.Exception ex2)
        //{
        //    Log.Debug("PPX", ex2.Message);
        //    BasicReturn rEx2 = new BasicReturn() { Flag = false, Code = "OE1", Message = ex2.Message };
        //    return JsonConvert.SerializeObject(rEx2, Formatting.Indented);
        //}

        byte[] msgBuffer2 = System.Text.Encoding.ASCII.GetBytes(time.ToString());

        try
        {
            outStream.WriteByte(0xfd);
            outStream.WriteByte((byte)'B');
            outStream.Write(msgBuffer2, 0, msgBuffer2.Length);
            outStream.WriteByte(0xca);
        }
        catch (System.Exception ex2)
        {
            BasicReturn rEx1 = new BasicReturn()
            {
                Flag = false, Code = "OE2", Message = ex2.Message
            };
            return(JsonConvert.SerializeObject(rEx1, Formatting.Indented));
        }

        //Stopwatch sw1 = new Stopwatch();
        //bool isTimeout = false;
        //int waitTtime = 1000;
        //sw1.Start();
        //string s = string.Empty;
        //while (sw1.ElapsedMilliseconds <= waitTtime)
        //{
        //    System.Threading.Thread.Sleep(10);
        //    byte[] buffer = new byte[1024];
        //    int bytes;
        //    bytes = inStream.Read(buffer, 0, buffer.Length);

        //    if (4 < bytes)
        //    {
        //        s = System.Text.Encoding.ASCII.GetString(buffer);
        //        break;
        //    }

        //    if (waitTtime <= sw1.ElapsedMilliseconds)
        //    {
        //        isTimeout = true;
        //        break;
        //    }
        //}
        //sw1.Stop();

        //if (isTimeout)
        //{
        //    BasicReturn rTO = new BasicReturn() { Flag = false, Code = "TO1", Message = "Read timeout!" };
        //    return JsonConvert.SerializeObject(rTO, Formatting.Indented);
        //}

        BasicReturn r1 = new BasicReturn()
        {
            Flag = true, Code = "00", Message = $"Blink ON of {time} sec"
        };

        return(JsonConvert.SerializeObject(r1, Formatting.Indented));
    }
    public string ReadInfo()
    {
        System.IO.Stream outStream;
        try
        {
            outStream = btSocket.OutputStream;
        }
        catch (System.Exception ex1)
        {
            Log.Debug("PPX", ex1.Message);
            BasicReturn rEx1 = new BasicReturn()
            {
                Flag = false, Code = "OE1", Message = "Socket สร้างไม่สำเร็จ"
            };
            return(JsonConvert.SerializeObject(rEx1, Formatting.Indented));
        }
        System.IO.Stream inStream;
        try
        {
            inStream = btSocket.InputStream;
        }
        catch (System.Exception ex2)
        {
            Log.Debug("PPX", ex2.Message);
            BasicReturn rEx2 = new BasicReturn()
            {
                Flag = false, Code = "OE1", Message = "Socket สร้างไม่สำเร็จ"
            };
            return(JsonConvert.SerializeObject(rEx2, Formatting.Indented));
        }

        byte[] msgBuffer = new byte[] { 0xfe, 0x3f, 0xca };

        try
        {
            outStream.Write(msgBuffer, 0, msgBuffer.Length);
        }
        catch (System.Exception ex2)
        {
            BasicReturn rEx1 = new BasicReturn()
            {
                Flag = false, Code = "OE2", Message = "ไม่สามารถส่งได้สำเร็จ"
            };
            return(JsonConvert.SerializeObject(rEx1, Formatting.Indented));
        }

        Stopwatch sw1       = new Stopwatch();
        bool      isTimeout = false;
        int       waitTtime = 1000;

        sw1.Start();
        string s = string.Empty;

        while (sw1.ElapsedMilliseconds <= waitTtime)
        {
            System.Threading.Thread.Sleep(150);
            byte[] buffer = new byte[1024];
            int    bytes;
            bytes = inStream.Read(buffer, 0, buffer.Length);

            if (4 < bytes)
            {
                s = System.Text.Encoding.ASCII.GetString(buffer);
                break;
            }

            if (waitTtime <= sw1.ElapsedMilliseconds)
            {
                isTimeout = true;
                break;
            }
        }
        sw1.Stop();

        if (isTimeout)
        {
            BasicReturn rTO = new BasicReturn()
            {
                Flag = false, Code = "TO1", Message = "Read timeout!"
            };
            return(JsonConvert.SerializeObject(rTO, Formatting.Indented));
        }

        BasicReturn r1 = new BasicReturn()
        {
            Flag = true, Code = "00", Message = s
        };

        return(JsonConvert.SerializeObject(r1, Formatting.Indented));
    }