/// <summary> /// Send any data with class T to Telemetry service. The data type must be serializable by implementing /// DataContract attribute. /// </summary> /// <param name="eventTag">Event tag</param> /// <param name="eventData">Event data</param> /// <param name="callback">Returns a Result via callback when completed.</param> /// <typeparam name="T">A class that implements DataContract and DataMember attribute</typeparam> public void SendEvent <T>(TelemetryEventTag eventTag, T eventData, ResultCallback callback) where T : class { Report.GetFunctionLog(this.GetType().Name); if (!this.session.IsValid()) { callback.TryError(ErrorCode.IsNotLoggedIn); return; } this.coroutineRunner.Run( this.api.SendEvent(this.@namespace, this.clientId, this.session.UserId, eventTag, eventData, callback)); }
/// <summary> /// Send any data with class T to Telemetry service. The data type must be serializable by implementing /// DataContract attribute. /// </summary> /// <param name="eventTag">Event tag</param> /// <param name="eventData">Event data</param> /// <param name="callback">Returns a Result via callback when completed.</param> /// <typeparam name="T">A class that implements DataContract and DataMember attribute</typeparam> public void SendEvent <T>(TelemetryEventTag eventTag, T eventData, ResultCallback callback) where T : class { if (!this.user.IsLoggedIn) { callback.TryError(ErrorCode.IsNotLoggedIn); return; } if (eventData is string) { callback.TryError(ErrorCode.InvalidRequest, "string is not allowed as event data"); return; } this.taskDispatcher.Start( Task.Retry( cb => this.api.SendEvent(this.user.Namespace, this.clientId, this.user.UserId, eventTag, eventData, result => cb(result)), result => this.coroutineRunner.Run(() => callback((Result)result)), this.user)); }
public IEnumerator <ITask> SendEvent <T>(string @namespace, string clientId, string userID, TelemetryEventTag eventTag, T eventData, ResultCallback callback) where T : class { Assert.IsTrue(typeof(T).IsSerializable, "Event data of type " + typeof(T) + " is not serializable. Try add [Serializable] attribute."); string nowTime = DateTime.UtcNow.ToString("O"); string strEventData; if (eventData is string) { strEventData = "\"" + eventData + "\""; } else { strEventData = SimpleJson.SimpleJson.SerializeObject(eventData); } string jsonString = string.Format( "{{" + "\"AgentType\": {0}," + "\"AppID\": {1}," + "\"ClientID\": \"{2}\"," + "\"Data\": {3}," + "\"DeviceID\": \"{4}\"," + "\"EventID\": {5}," + "\"EventLevel\": {6}," + "\"EventTime\": \"{7}\"," + "\"EventType\": {8}," + "\"UUID\": \"{9:N}\"," + "\"UX\": {10}," + "\"UserID\": \"{11}\"" + "}}", this.agentType, eventTag.AppId, clientId, strEventData, this.deviceId, eventTag.Id, eventTag.Level, nowTime, eventTag.Type, Guid.NewGuid(), eventTag.UX, userID); var request = HttpRequestBuilder .CreatePost(this.baseUrl + "/telemetry/public/namespaces/{namespace}/events/gameclient/{appID}/{eventType}/{eventLevel}/{eventID}") .WithPathParam("namespace", @namespace) .WithPathParam("appID", eventTag.AppId.ToString()) .WithPathParam("eventType", eventTag.Type.ToString()) .WithPathParam("eventLevel", eventTag.Level.ToString()) .WithPathParam("eventID", eventTag.Id.ToString()) .WithContentType(MediaType.ApplicationJson) .WithBody(jsonString) .ToRequest(); HttpWebResponse response = null; yield return(Task.Await(request, rsp => response = rsp)); if (response == null) { callback.Try(Result.CreateError(ErrorCode.NetworkError, "There is no response")); yield break; } response.Close(); Result result; switch (response.StatusCode) { case HttpStatusCode.NoContent: result = Result.CreateOk(); break; default: result = Result.CreateError((ErrorCode)response.StatusCode, "Sending telemetry event failed"); break; } callback.Try(result); }
public IEnumerator SendEvent <T>(string @namespace, string clientId, string userID, TelemetryEventTag eventTag, T eventData, ResultCallback callback) where T : class { Report.GetFunctionLog(this.GetType().Name); string nowTime = DateTime.UtcNow.ToString("O"); string strEventData; if (eventData is string) { strEventData = "\"" + eventData + "\""; } else { strEventData = eventData.ToJsonString(); } string jsonString = string.Format( "{{" + "\"AgentType\": {0}," + "\"AppID\": {1}," + "\"ClientID\": \"{2}\"," + "\"Data\": {3}," + "\"DeviceID\": \"{4}\"," + "\"EventID\": {5}," + "\"EventLevel\": {6}," + "\"EventTime\": \"{7}\"," + "\"EventType\": {8}," + "\"UUID\": \"{9:N}\"," + "\"UX\": {10}," + "\"UserID\": \"{11}\"" + "}}", this.agentType, eventTag.AppId, clientId, strEventData, this.deviceId, eventTag.Id, eventTag.Level, nowTime, eventTag.Type, Guid.NewGuid(), eventTag.UX, userID); var request = HttpRequestBuilder .CreatePost( this.baseUrl + "/public/namespaces/{namespace}/events/gameclient/{appID}/{eventType}/{eventLevel}/{eventID}") .WithPathParam("namespace", @namespace) .WithPathParam("appID", eventTag.AppId.ToString()) .WithPathParam("eventType", eventTag.Type.ToString()) .WithPathParam("eventLevel", eventTag.Level.ToString()) .WithPathParam("eventID", eventTag.Id.ToString()) .WithContentType(MediaType.ApplicationJson) .WithBody(jsonString) .GetResult(); IHttpResponse response = null; yield return(this.httpWorker.SendRequest(request, rsp => response = rsp)); var result = response.TryParse(); callback.Try(result); }