public virtual T Post <T, T2>(string url, T2 t = default(T2))
        {
            var request = Equals(t, default(T2)) ? (object)new { } : JsonConvert.SerializeObject(AppendRootLevel(t));

            var logRequest = new LogEventRequest(_logger)
            {
                LogLevel  = LogLevel.Info,
                Method    = MethodBase.GetCurrentMethod(),
                Message   = "Post",
                ExtraData = new List <Tuple <string, object> >()
                {
                    new Tuple <string, object>("Url", url),
                    new Tuple <string, object>("Settings", Settings),
                    new Tuple <string, object>("Request", request),
                }
            };

            LogHelper.LogEvent(logRequest);

            var resp = Net.MakePost(url, request, Settings);

            logRequest.LogLevel = LogLevel.Trace;
            logRequest.ExtraData.Add(new Tuple <string, object>("Response", resp));

            LogHelper.LogEvent(logRequest);

            if (!string.IsNullOrEmpty(resp))
            {
                ContainsError(resp, JsonConvert.SerializeObject(request), url);
            }

            return(ParseResponse <T>(resp));
        }
Esempio n. 2
0
    public void Request(StringDelegate SuccessCallback = null, StringDelegate FailedCallback = null)
    {
        var req = new LogEventRequest();

        foreach (var item in dictionary)
        {
            req.SetEventAttribute(item.Key, item.Value.ToString());
        }
        req.SetEventKey(eventKey).Send((response) =>
        {
            if (response.HasErrors)
            {
                Debug.Log(eventKey + " request failed!\n" + response.Errors.JSON);
                if (FailedCallback != null)
                {
                    FailedCallback(response.JSONString);
                }
            }
            else
            {
                Debug.Log(eventKey + " request success!\n" + response.JSONString);
                if (SuccessCallback != null)
                {
                    SuccessCallback(response.JSONString);
                }
            }
        });
    }
Esempio n. 3
0
    public void SendEvent(string eventKey, Action <LogEventRequest> setAttributes, Action <LogEventResponse> onResponse = null)
    {
        var eventRequest = new LogEventRequest().SetEventKey(eventKey);

        setAttributes.Invoke(eventRequest);
        eventRequest.Send(onResponse);
    }
        /// <summary>
        /// Creates the specified t.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="t">The t.</param>
        /// <returns></returns>
        public virtual T Create <T>(T t, string url = null)
        {
            var request = JsonConvert.SerializeObject(AppendRootLevel(t));

            var logRequest = new LogEventRequest(_logger)
            {
                LogLevel  = LogLevel.Info,
                Method    = MethodBase.GetCurrentMethod(),
                Message   = "Create",
                ExtraData = new List <Tuple <string, object> >()
                {
                    new Tuple <string, object>("Url", url ?? Url),
                    new Tuple <string, object>("Settings", Settings),
                    new Tuple <string, object>("Request", request)
                }
            };

            LogHelper.LogEvent(logRequest);


            var resp = Net.MakePost(url ?? Url, request, Settings);

            logRequest.LogLevel = LogLevel.Trace;
            logRequest.ExtraData.Add(new Tuple <string, object>("Response", resp));

            LogHelper.LogEvent(logRequest);

            ContainsError(resp, request, url ?? Url);

            return(ParseResponse <T>(resp));
        }
        /// <summary>
        /// Updates the specified t.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="t">The t.</param>
        /// <param name="id">The identifier.</param>
        /// <returns></returns>
        public virtual T Update <T>(T t, long id, string url = null)
        {
            var resultUrl = url ?? $"{Url.Split('.')[0]}/{id}.json";

            var request = AppendRootLevel(t);

            var logRequest = new LogEventRequest(_logger)
            {
                LogLevel  = LogLevel.Info,
                Method    = MethodBase.GetCurrentMethod(),
                Message   = "Update",
                ExtraData = new List <Tuple <string, object> >()
                {
                    new Tuple <string, object>("Url", url ?? $"{Url.Split('.')[0]}/{id}.json"),
                    new Tuple <string, object>("Settings", Settings),
                    new Tuple <string, object>("ID", id),
                    new Tuple <string, object>("Request", request),
                }
            };

            LogHelper.LogEvent(logRequest);

            var resp = Net.MakePut(resultUrl, request,
                                   Settings);

            logRequest.LogLevel = LogLevel.Trace;
            logRequest.ExtraData.Add(new Tuple <string, object>("Request", request));

            LogHelper.LogEvent(logRequest);

            ContainsError(resp, JsonConvert.SerializeObject(request), url);

            return(ParseResponse <T>(resp));
        }
        /// <summary>
        /// Deletes by the specified identifier.
        /// </summary>
        /// <param name="id">The identifier.</param>
        /// <param name="url"></param>
        public virtual void Delete(long id, string url = null)
        {
            var logRequest = new LogEventRequest(_logger)
            {
                LogLevel  = LogLevel.Info,
                Method    = MethodBase.GetCurrentMethod(),
                Message   = "Delete",
                ExtraData = new List <Tuple <string, object> >()
                {
                    new Tuple <string, object>("Url", url ?? $"{Url.Split('.')[0]}/{id}.json"),
                    new Tuple <string, object>("Settings", Settings),
                    new Tuple <string, object>("ID", id),
                }
            };

            LogHelper.LogEvent(logRequest);

            var resp = Net.MakeDelete(url ?? $"{Url.Split('.')[0]}/{id}.json", Settings);

            logRequest.LogLevel = LogLevel.Trace;
            logRequest.ExtraData.Add(new Tuple <string, object>("Response", resp));

            LogHelper.LogEvent(logRequest);

            ContainsError(resp, "id: " + id.ToString(), url ?? Url);
        }
Esempio n. 7
0
        public void GSPostLeaderboardScore(c2s_Leaderboard_Score packet)
        {
            Log.Info("GSPostLeaderboardScore");

            LogEventRequest logEventRequest = new LogEventRequest();

            logEventRequest.SetEventKey(packet.eventKey);
            logEventRequest.SetEventAttribute("SCORE", packet.SCORE);

            Log.InfoFormat("Data send to server: {0}", packet.ToString());

            logEventRequest.Send(response =>
            {
                if (response.HasErrors)
                {
                    Debug.LogWarning("Error in GSPostLeaderboardScore()");
                    Debug.Log("Error: " + response.Errors.JSON);
                }
                else
                {
                    Debug.Log("GSPostLeaderboardScore() succeed");
                    Debug.Log(response.JSONString);
                }
            });
        }
Esempio n. 8
0
    public void Request(string eventKey, Dictionary <string, object> dictionary, StringDelegate SuccessCallback, StringDelegate FailedCallback = null)
    {
        var req = new LogEventRequest();

        req.SetEventKey(eventKey);
        foreach (var item in dictionary)
        {
            if (item.Value != null)
            {
                req.SetEventAttribute(item.Key, item.Value.ToString());
            }
            else
            {
                Debug.Log(item.Key + " has null value!");
            }
        }
        req.Send((response) =>
        {
            if (response.HasErrors)
            {
                if (FailedCallback != null)
                {
                    FailedCallback(response.JSONString);
                }
            }
            else
            {
                SuccessCallback(response.JSONString);
            }
        });
    }
        public virtual string Delete(string url)
        {
            var logRequest = new LogEventRequest(_logger)
            {
                LogLevel  = LogLevel.Info,
                Method    = MethodBase.GetCurrentMethod(),
                Message   = "Delete",
                ExtraData = new List <Tuple <string, object> >()
                {
                    new Tuple <string, object>("Url", url),
                    new Tuple <string, object>("Settings", Settings)
                }
            };

            LogHelper.LogEvent(logRequest);

            var resp = Net.MakeDelete(url, Settings);

            logRequest.LogLevel = LogLevel.Trace;
            logRequest.ExtraData.Add(new Tuple <string, object>("Response", resp));

            LogHelper.LogEvent(logRequest);

            ContainsError(resp, "", url);

            return(ParseResponse <string>(resp));
        }
Esempio n. 10
0
        public virtual List <T> Get <T>(string url)
        {
            var logRequest = new LogEventRequest(_logger)
            {
                LogLevel  = LogLevel.Info,
                Method    = MethodBase.GetCurrentMethod(),
                Message   = "Get from",
                ExtraData = new List <Tuple <string, object> >()
                {
                    new Tuple <string, object>("Url", url),
                    new Tuple <string, object>("Settings", Settings)
                }
            };

            LogHelper.LogEvent(logRequest);

            var resp = Net.MakeGet(url, Settings);

            logRequest.LogLevel = LogLevel.Trace;
            logRequest.ExtraData.Add(new Tuple <string, object>("Response", resp));

            LogHelper.LogEvent(logRequest);

            if (!string.IsNullOrEmpty(resp))
            {
                ContainsError(resp, "", url);
            }


            return(ParseResponse <List <T> >(resp));
        }
Esempio n. 11
0
 public void LogCustomEvent(string eventName, Dictionary <string, object> body)
 {
     PlayFab.ClientModels.LogEventRequest request = new LogEventRequest();
     request.EventName = eventName;
     request.Body      = body;
     if (PlayFabData.AuthKey != null)
     {
         PlayFabClientAPI.LogEvent(request, EventLogged, OnPlayFabError);
     }
 }
        public async ValueTask <LogEventResponse> RegisterAsync(LogEventRequest request)
        {
            foreach (var log in request.Events)
            {
                Console.WriteLine($"{log.DateTime:s} {log.LogLevel}: {log.Component};{log.Process};{log.Message}");
            }

            return(new LogEventResponse()
            {
                Component = request.Component
            });
        }
Esempio n. 13
0
    public void PlayAgain()
    {
        //AsyncPlayAgain();
        //if (messageQueue.IsQueueEmpty(MessageQueue.QueueNameEnum.MATCHMAKINGGROUPNUMBER))
        //{
        Debug.Log("Sending playAgain event to GS");
        LogEventRequest request = new LogEventRequest();

        request.SetEventAttribute("challengeID", ChallengeID);
        request.SetEventKey("PlayAgain");
        request.Send(OnPlayAgainSuccess, OnPlayAgainError);
        //}
    }
Esempio n. 14
0
 public IEnumerable AsyncPlayAgain()
 {
     if (messageQueue.IsQueueEmpty(MessageQueue.QueueNameEnum.MATCHMAKINGGROUPNUMBER))
     {
         Debug.Log("Sending playAgain event to GS");
         LogEventRequest request = new LogEventRequest();
         request.SetEventAttribute("challengeID", ChallengeID);
         request.SetEventKey("PlayAgain");
         request.Send(OnPlayAgainSuccess, OnPlayAgainError);
     }
     else
     {
         yield return(new WaitForSeconds(0.1f));
     }
 }
Esempio n. 15
0
        internal virtual List <T> GetAll <T>(long id, string url = null) where T : IShopifyBaseObject
        {
            var      result = new List <T>();
            List <T> response;

            do
            {
                var logRequest = new LogEventRequest(_logger)
                {
                    LogLevel  = LogLevel.Info,
                    Method    = MethodBase.GetCurrentMethod(),
                    Message   = "Get all",
                    ExtraData = new List <Tuple <string, object> >()
                    {
                        new Tuple <string, object>("Url", url ?? $"{Url}?limit=250&since_id={id}"),
                        new Tuple <string, object>("Settings", Settings),
                        new Tuple <string, object>("ID", id),
                    }
                };

                LogHelper.LogEvent(logRequest);

                var jsonResp = Net.MakeGet(url ?? $"{Url}?limit=250&since_id={id}", Settings);

                ContainsError(jsonResp, "id:" + id.ToString(), url ?? Url);

                response = ParseResponse <List <T> >(jsonResp);

                logRequest.LogLevel = LogLevel.Trace;
                logRequest.ExtraData.Add(new Tuple <string, object>("Response", response));

                LogHelper.LogEvent(logRequest);

                if (response == null)
                {
                    break;
                }

                result.AddRange(response);

                if (response.Count == 250)
                {
                    id = (long)response.Last().Id;
                }
            } while (response.Count == 250);

            return(result);
        }
Esempio n. 16
0
        /// <summary>
        /// Filters this instance.
        /// </summary>
        /// <returns></returns>
        /// <exception cref="System.NotImplementedException"></exception>
        public virtual T Filter <T, TReturn>(TReturn filter, string url = null)
        {
            var logRequest = new LogEventRequest(_logger)
            {
                LogLevel  = LogLevel.Info,
                Method    = MethodBase.GetCurrentMethod(),
                Message   = "Filter",
                ExtraData = new List <Tuple <string, object> >()
                {
                    new Tuple <string, object>("Url", url ?? Url),
                    new Tuple <string, object>("Settings", Settings),
                    new Tuple <string, object>("Filter", filter)
                }
            };

            LogHelper.LogEvent(logRequest);

            var dict      = ExtractParams(filter);
            var filterUrl = "?";

            foreach (var x in dict.Select((entry, i) => new { entry, i }))
            {
                if (x.entry.Value.Any())
                {
                    if (x.i != 0)
                    {
                        filterUrl += "&";
                    }

                    filterUrl += x.entry.Key + "=" + x.entry.Value[0];
                    for (var i = 1; i < x.entry.Value.Count; i++)
                    {
                        filterUrl += "," + x.entry.Value[i];
                    }
                }
            }

            var resp = Net.MakeGet((url ?? Url) + filterUrl, Settings);

            logRequest.LogLevel = LogLevel.Trace;
            logRequest.ExtraData.Add(new Tuple <string, object>("Response", resp));

            LogHelper.LogEvent(logRequest);

            ContainsError(resp, url + filterUrl, url);

            return(ParseResponse <T>(resp));
        }
Esempio n. 17
0
        /// <summary>
        /// Gets the by ids.
        /// </summary>
        /// <param name="ids">The ids.</param>
        /// <param name="url"></param>
        /// <returns></returns>
        public virtual List <T> GetByIDs <T>(List <long> ids, string url = null)
        {
            var idsToGet = ids.ChunkBy(250);

            var result = new List <T>();

            foreach (var idToget in idsToGet)
            {
                var logRequest = new LogEventRequest(_logger)
                {
                    LogLevel  = LogLevel.Info,
                    Method    = MethodBase.GetCurrentMethod(),
                    Message   = "Get by Ids",
                    ExtraData = new List <Tuple <string, object> >()
                    {
                        new Tuple <string, object>("Url", url ?? $"{Url}?ids={string.Join(",", ids)}"),
                        new Tuple <string, object>("Settings", Settings),
                        new Tuple <string, object>("IDs", ids)
                    }
                };

                LogHelper.LogEvent(logRequest);

                var resp = Net.MakeGet(url ?? $"{Url}?limit=250&ids={string.Join(",", idToget)}", Settings);

                ContainsError(resp, "ids: " + string.Join(",", idToget), url ?? Url);

                var response = ParseResponse <List <T> >(resp);

                logRequest.LogLevel = LogLevel.Trace;
                logRequest.ExtraData.Add(new Tuple <string, object>("Response", resp));

                LogHelper.LogEvent(logRequest);

                if (response != null)
                {
                    result.AddRange(response);
                }
            }

            return(result);
        }
        public override void Inject(string targetId)
        {
            var data = _sendAction?.Invoke();

            if (data == null)
            {
                throw new Exception("Inejected data cannot be null!");
            }
            var jsonData = JsonConvert.SerializeObject(data);

            var request = new LogEventRequest().SetEventKey(ExtCode);

            request.SetEventAttribute("targetId", targetId);
            request.SetEventAttribute("data", jsonData);
            request.Send(x =>
            {
                if (x.HasErrors)
                {
                    Debug.Log(x.Errors.JSON);
                }
            });
        }
Esempio n. 19
0
        /// <summary>
        /// Begin a new asynchronous LogEventRequest
        /// </summary>
        /// <param name="requestData"></param>
        /// <returns></returns>
        public async Task <EventsResponse> LogEventRequestAsync(LogEventRequest requestData)
        {
            var res = await Requestor.PostStringAsync(Urls.LogEventRequest, JsonHelper.SerializeData(requestData));

            return(JsonConvert.DeserializeObject <EventsResponse>(res.ResponseJson));
        }