예제 #1
0
        // POST: odata/Heartbeats
        public async Task <IHttpActionResult> Post(Heartbeat heartbeat)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            // each heartbeat must be unique
            if (heartbeat.Id == Guid.Empty)
            {
                heartbeat.Id = Guid.NewGuid();
            }
            //generate event args for delegate
            HeartbeatEventArgs e = RxStreamHelper.GetHeartbeatEventArgs(heartbeat);

            //propagate the heartbeat
            heartbeatDelegate(this, e);
            //insert into db
            db.Heartbeats.Add(heartbeat);

            try
            {
                await db.SaveChangesAsync();
            }
            catch (DbUpdateException)
            {
                if (HeartbeatExists(heartbeat.Id))
                {
                    return(Conflict());
                }
                else
                {
                    throw;
                }
            }

            return(Created(heartbeat));
        }
예제 #2
0
 static WebRole()
 {
     //initialize Rx streams
     RxHelper = new RxStreamHelper();
 }