/////////////////////////////////////////////////////////////////////////// /// <summary> /// 处理服务器数据的协程 /// </summary> private IEnumerator OnHanleDataFiber() { while (true) { ServerDataItem item = null; // 数据是否接收到 if (m_ServerDataQueue.Count == 0) { yield return(0); continue; } // 取出数据 lock (m_ServerDataQueue) { item = m_ServerDataQueue.Dequeue(); Debug.Log("rr:" + item); } // 处理服务器的数据 if (item != null) { HandleServerData(item.nMainCmd, item.nSubCmd, item.byBody); } yield return(0); } }
public void Put(int id, [FromBody] ServerDataItem value) { var itemToUpdate = db.FirstOrDefault(x => x.Id == id); db.Remove(itemToUpdate); db.Add(value); }
public void Post([FromBody] ServerDataItem value) { var newId = db.Max(x => x.Id) + 1; value.Id = newId; db.Add(value); }
public async Task Delete(ServerDataItem o) { var stringResponse = await client.DeleteAsync(BASE_URL + "values/" + o.Id); if (!stringResponse.IsSuccessStatusCode) { throw new Exception(stringResponse.StatusCode.ToString()) { }; } }
public async Task Update(ServerDataItem o) { var serializedString = JsonConvert.SerializeObject(o); StringContent content = new StringContent(serializedString, UTF8Encoding.UTF8, "application/json"); var stringResponse = await client.PutAsync(BASE_URL + "values/" + o.Id, content); if (!stringResponse.IsSuccessStatusCode) { throw new Exception(stringResponse.StatusCode.ToString()) { }; } }
/////////////////////////////////////////////////////////////////////////// /// <summary> /// 处理服务器返回的信息 /// </summary> public bool OnServerDataEvent(ushort nMainCmd, ushort nSubCmd, byte[] byBody) { ServerDataItem item = new ServerDataItem(); item.nMainCmd = nMainCmd; item.nSubCmd = nSubCmd; item.byBody = byBody; // 将服务器的消息放进队列 lock (m_ServerDataQueue) { m_ServerDataQueue.Enqueue(item); } return(true); }
private async void Button_Clicked(object sender, EventArgs e) { try { var name = this.EntryName.Text; var desc = this.EntryDescription.Text; var dataOra = this.EntryDate.Date; if (_item != null) { ServerDataItem s = new ServerDataItem() { Id = _item.Id, Name = name, Description = desc, DataElemento = dataOra, }; await _webApiProxy.Update(s); await Navigation.PopAsync(); } else { // CREA NUOVO ServerDataItem s = new ServerDataItem() { // Id = _item.Id, Name = name, Description = desc, DataElemento = dataOra, }; await _webApiProxy.Create(s); await Navigation.PopAsync(); } } catch (Exception ex) { await DisplayAlert("ERRORE", ex.Message, "OK"); } }
internal void SetData(ServerDataItem item) { _item = item; }