public HttpResponseMessage Post([FromBody] DatedValue value) //Insert Value { try { //Simple types are harder to post than complex types! //http://weblog.west-wind.com/posts/2012/Mar/21/ASPNET-Web-API-and-Simple-Value-Parameters-from-POSTed-data if (value == null) { throw new InvalidOperationException("Expected value in body, got " + Request.Content.ReadAsStringAsync().Result); } int id = (from int key in values.Keys select key).Max() + 1; DatedValue justCreated = new DatedValue { Id = values.Count, Value = value.Value, LastModified = DateTime.Now }; values.Add(values.Count, justCreated); //Return address to resource just created. return(DefaultPostResponse(id, justCreated)); } catch (Exception ex) { Tracing.Err.TraceEvent(TraceEventType.Error, 0, ex.ToString()); throw; } }
private static DatedValue Insert(DatedValue value) { DatedValue justCreated; int id = (from int key in values.Keys select key).Max() + 1; justCreated = new DatedValue { Id = values.Count, Value = value.Value, LastModified = DateTime.Now }; values.Add(values.Count, justCreated); return(justCreated); }
public HttpResponseMessage Put([FromBody] DatedValue value) { try { //Update existing value.LastModified = DateTime.Now; values[value.Id] = value; //Tricky... this will *only* be called by jquery xhr! return(DefaultPutResponse(value.Id, value)); } catch (Exception ex) { Tracing.Err.TraceEvent(TraceEventType.Error, 0, ex.ToString()); throw; } }
public Task <HttpResponseMessage> Post(bool asynch, [FromBody] DatedValue value) //Insert Value { try { //Simple types are harder to post than complex types! //http://weblog.west-wind.com/posts/2012/Mar/21/ASPNET-Web-API-and-Simple-Value-Parameters-from-POSTed-data if (value == null) { throw new InvalidOperationException("Expected value in body, got " + Request.Content.ReadAsStringAsync().Result); } //Throw message on Queue Guid key = GuidUtils.NewSequential(); //Want this to run to completion, even if response associated with parent thread is done. Task toWait = Task.Factory.StartNew(() => { queue.Add(key, 0); DatedValue justCreated = Insert(value); queue[key] = justCreated.Id; }); //Return address to resource just created. Task <HttpResponseMessage> sender = Task.Factory.StartNew(() => { HttpResponseMessage message = Request.CreateResponse(HttpStatusCode.Accepted); message.Headers.Location = new Uri("/ValueQueue/" + key); return(message); }); Task.WaitAll((new[] { toWait, sender })); return(sender); } catch (Exception ex) { Tracing.Err.TraceEvent(TraceEventType.Error, 0, ex.ToString()); throw; } }
private new void Capture(object state) { m_arrRpmValues = new ArrayList(); m_arrKphValues = new ArrayList(); bool flag = false; if (m_bCapture) { do { OBDParameterValue obdParameterValue1 = m_obdInterface.getValue("SAE.RPM", true); if (!obdParameterValue1.ErrorDetected) { DatedValue datedValue1 = new DatedValue(obdParameterValue1.DoubleValue); DateTime now1 = DateTime.Now; datedValue1.Date = now1; Decimal num1 = numFromRPM.Value; Decimal num2 = new Decimal(); num2 = new Decimal(datedValue1.Value); if (num2 >= num1) { Decimal num3 = numToRPM.Value; Decimal num4 = new Decimal(); num4 = new Decimal(datedValue1.Value); if (num4 <= num3) { m_arrRpmValues.Add((object)datedValue1); OBDParameterValue obdParameterValue2 = m_obdInterface.getValue("SAE.VSS", false); if (!obdParameterValue2.ErrorDetected) { float num5 = m_obdInterface.GetActiveProfile().SpeedCalibrationFactor; DatedValue datedValue2 = new DatedValue(obdParameterValue2.DoubleValue * (double)num5); DateTime now2 = DateTime.Now; datedValue2.Date = now2; m_arrKphValues.Add((object)datedValue2); } flag = true; goto label_9; } } if (flag) m_bCapture = false; } label_9: ; } while (m_bCapture); } Calculate(); btnOpen.Enabled = true; }
static internal DatedValue ReadValue(int id) { DatedValue value = values[id]; return(value); }