public ServiceCallback <byte[]> SendAppMsg(AppInfo app, byte[] data, AppMsgRecipient recipient) { return(new ServiceCallback <byte[]>(() => { MainMessage mainMsg = new MainMessage(); mainMsg.AppMsg = new AppMsg(); mainMsg.AppMsg.AppId = app.ID; mainMsg.AppMsg.Data = ByteString.CopyFrom(data); MainMessage response = null; switch (recipient) { case AppMsgRecipient.FORWARDER: response = _api.OpenAPI.Networking.Send(mainMsg, _api.Services.Room.ForwarderAddress); break; case AppMsgRecipient.PROVIDER: response = _api.OpenAPI.Networking.Send(mainMsg, _api.OpenAPI.Config.MainServer); break; } if (response == null) { throw new AppServiceException("Unknown response."); } if (SystemServiceClient.IsErrorMsg(response)) { throw new AppServiceException(response.SystemMsg.ErrorMsg.ErrorMsg_); } AppMsg appMsg = response.AppMsg; if (appMsg == null) { throw new AppServiceException("Unknown response."); } return appMsg.Data.ToByteArray(); })); }