Exemplo n.º 1
0
        //[System.Web.Http.HttpPost]
        /// <summary>
        /// Register a passage event
        /// </summary>
        /// <param name="payload"></param>
        /// <param name="hash"></param>
        /// <returns></returns>
        public IHttpActionResult Post(string payload, string hash)
        {
            // Validate hash
            // TODO use nonce
            const String SALT        = "%8vvpAwg48cvlcRwfAiY%A4gEj"; // not very secure
            var          hashCompare = Crypto.GetHashString(SALT + payload);
            var          response    = string.Format("payload: [{0}], hash: [{1}], hashCompare: [{2}]", payload, hash, hashCompare);

            if (hashCompare.Equals(hash, StringComparison.CurrentCultureIgnoreCase))
            {
                // Map parameters to properties
                var passage = new Passage();
                switch (payload.ToUpper())
                {
                case "IN":
                    passage.Direction = Passage.DirectionType.IN;
                    break;

                case "OUT":
                    passage.Direction = Passage.DirectionType.OUT;
                    break;

                default:
                    break;
                }
                passage.Message = DateTime.Now.ToString();
                CatFlapData.Save(passage);
            }
            else
            {
                return(Unauthorized());
            }
            return(Ok("OK"));
        }
Exemplo n.º 2
0
 public void Add_Dummy_Data()
 {
     for (int i = 0; i < 10; i++)
     {
         var passage = new Passage(Passage.DirectionType.IN);
         //passage.
         CatFlapData.Save(passage);
     }
 }
Exemplo n.º 3
0
        public void GetAll()
        {
            var passage = new Passage(Passage.DirectionType.IN);
            var x       = CatFlapData.GetAll();

            //CatFlap.Models.Flap.test();

            foreach (var item in x)
            {
                Trace.WriteLine(item.ID);
                Trace.WriteLine(item.Direction);
            }
        }
Exemplo n.º 4
0
 /// <summary>
 /// Get all log entries
 /// </summary>
 /// <returns></returns>
 public List <Passage> Get()
 {
     Log("Reading log 2");
     return(CatFlapData.GetAll().ToList());
 }