public SubRes Post([FromBody] SubReq value) { SubRes result = new SubRes(); try { SubReq numbers = value; if (String.IsNullOrEmpty(Request.Headers["X-Evi-Tracking-Id"])) { result.Difference = value.Minuend - value.Subtrahend; } else { result.Difference = value.Minuend - value.Subtrahend; Log log = new Log("journal_"); log.Add(Request.Headers["X-Evi-Tracking-Id"] + " operation subtraction numbers: " + value.Minuend + " - " + value.Subtrahend + " result: " + result.Difference); } } catch (Exception ex) { Log log = new Log(); log.Add("Error en SubController.cs " + ex.Message); } return(result); }
void sub() { SubReq sub_req = new SubReq(); sub_req.category = subType; sub_req.clientId = ((IPEndPoint)(clientSocket.Client.LocalEndPoint)).Address.ToString(); sub_req.subId = sub_id; sub_req.accessKey = accessKey; sub_req.consumerGroup = consumer_group; TransferPkg pkg = build_TransferPkg((int)CmdId.SubReq, ProtoBufEncoder.SerializeToBytes(sub_req)); TransferPkg sub_res = send_and_recv(pkg); //check if subscription is successful if (sub_res == null) { _logger.Error("Subscription failed, receive unexpected response, needed SubRsp, received nothing."); reconnect(); return; } if (sub_res.cmdId == (int)CmdId.SubRsp) { SubRsp rsp = ProtoBufDecoder.DeserializeToObj <SubRsp>(sub_res.data); if (rsp.ack == 0) { isConnected = true; //new thread to ping server to keep it alive next_ping_deadline = DateTime.Now.AddSeconds(ping_interval_in_sec); LifeKeeper lk = new LifeKeeper(); Thread life_keeper = new Thread(() => lk.Run(this)); life_keeper.Start(); //new thread to run fetching SubFetcher fetcher = new SubFetcher(); Thread fetchthread = new Thread(() => fetcher.Run(this)); fetchthread.Start(); } else { _logger.Error("Subscription failed, sub info:" + sub_req.ToString()); reconnect(); } } else { _logger.Error("Subscription failed, receive unexpected response, needed SubRsp, received:" + sub_res.cmdId); reconnect(); } }