コード例 #1
0
ファイル: UtilPCL.cs プロジェクト: matteocoletta/windows_sdk
        private static ResponseData ProcessResponse(Dictionary <string, string> jsonResponse,
                                                    int?statusCode,
                                                    ActivityPackage activityPackage)
        {
            var responseData = ResponseData.BuildResponseData(activityPackage);

            responseData.JsonResponse = jsonResponse;
            responseData.StatusCode   = statusCode;
            responseData.Success      = false; // false by default, set to true later

            // for scenario: too frequent request for GDPR forget user
            if (statusCode == 429)
            {
                responseData.WillRetry = true;
                return(responseData);
            }

            if (jsonResponse == null)
            {
                responseData.WillRetry = true;
                return(responseData);
            }

            responseData.Message   = GetDictionaryString(jsonResponse, "message");
            responseData.Timestamp = GetDictionaryString(jsonResponse, "timestamp");
            responseData.Adid      = GetDictionaryString(jsonResponse, "adid");

            string trackingState = GetDictionaryString(jsonResponse, "tracking_state");

            if (!string.IsNullOrEmpty(trackingState) && trackingState == "opted_out")
            {
                responseData.TrackingState = TrackingState.OPTED_OUT;
            }

            string message = responseData.Message;

            if (message == null)
            {
                message = "No message found";
            }

            if (statusCode.HasValue && statusCode.Value == 200)
            {
                Logger.Info("{0}", message);
                responseData.Success = true;
            }
            else
            {
                Logger.Error("{0}", message);
                responseData.Success = false;
            }

            if (!statusCode.HasValue)
            {
                responseData.WillRetry = true;
            }

            return(responseData);
        }
コード例 #2
0
        private ResponseData ProcessException(Exception exception, ActivityPackage activityPackage)
        {
            var responseData = ResponseData.BuildResponseData(activityPackage);

            responseData.Success   = false;
            responseData.WillRetry = true;
            responseData.Exception = exception;

            return(responseData);
        }
コード例 #3
0
        private static ResponseData ProcessResponse(Dictionary <string, string> jsonResponse,
                                                    int?statusCode,
                                                    ActivityPackage activityPackage)
        {
            var responseData = ResponseData.BuildResponseData(activityPackage);

            responseData.JsonResponse = jsonResponse;
            responseData.StatusCode   = statusCode;
            responseData.Success      = false; // false by default, set to true later

            if (jsonResponse == null)
            {
                responseData.WillRetry = true;
                return(responseData);
            }

            responseData.Message   = GetDictionaryString(jsonResponse, "message");
            responseData.Timestamp = GetDictionaryString(jsonResponse, "timestamp");
            responseData.Adid      = GetDictionaryString(jsonResponse, "adid");

            string message = responseData.Message;

            if (message == null)
            {
                message = "No message found";
            }

            if (statusCode.HasValue && statusCode.Value == 200)
            {
                Logger.Info("{0}", message);
                responseData.Success = true;
            }
            else
            {
                Logger.Error("{0}", message);
                responseData.Success = false;
            }

            if (!statusCode.HasValue)
            {
                responseData.WillRetry = true;
            }
            else if (statusCode == 500 || statusCode == 501)
            {
                responseData.WillRetry = false;
            }
            else if (statusCode != 200)
            {
                responseData.WillRetry = true;
            }

            return(responseData);
        }