Ejemplo n.º 1
0
    async Task PostConsent(int actionType, int environment, PostConsentRequest body, Action <string> onSuccessAction, Action <Exception> onErrorAction)
    {
        try
        {
            client.DefaultRequestHeaders.Accept.Clear();
            client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
            var options = new JsonSerializerOptions {
                IgnoreNullValues = true
            };
            string json = null;
            switch (CmpCampaignPopupQueue.CurrentCampaignToShow())
            {
            case 0:
                json = JsonSerializer.Serialize(body as PostConsentGdprRequest, options);
                break;

            case 2:
                json = JsonSerializer.Serialize(body as PostConsentCcpaRequest, options);
                break;
            }
            var    data = new StringContent(json, Encoding.UTF8, "application/json");
            string link = GetConsentGdprQueryParams(actionType, environment);
            HttpResponseMessage response = await client.PostAsync(link, data);

            response.EnsureSuccessStatusCode();
            string responseBody = await response.Content.ReadAsStringAsync();

            dispatcher.Enqueue(delegate { onSuccessAction?.Invoke(responseBody); });
        }
        catch (Exception ex)
        {
            dispatcher.Enqueue(delegate { onErrorAction?.Invoke(ex); });
        }
    }
Ejemplo n.º 2
0
    public void Consent(/*CONSENT_ACTION_TYPE == */ int actionType,
                        int environment,
                        string language,
                        string privacyManagerId,
                        Action <string> onSuccessAction,
                        Action <Exception> onErrorAction,
                        ConsentSaveAndExitVariables pmSaveAndExitVariables = null)
    {
        var dict = new Dictionary <string, string> {
            { "type", "RecordString" }
        };
        var includeData = new IncludeDataPostGetMessagesRequest()
        {
            localState = dict,
            TCData     = dict
                         // messageMetaData = dict,
        };
        ConsentSaveAndExitVariables concretePmSaveAndExitVariables;
        PostConsentRequest          body = null;

        switch (CmpCampaignPopupQueue.CurrentCampaignToShow())
        {
        case 0:
            if (pmSaveAndExitVariables != null)
            {
                concretePmSaveAndExitVariables = pmSaveAndExitVariables as ConsentGdprSaveAndExitVariables;
            }
            else
            {
                concretePmSaveAndExitVariables = new ConsentGdprSaveAndExitVariables(
                    language: language,
                    privacyManagerId: privacyManagerId,
                    categories: new ConsentGdprSaveAndExitVariablesCategory[] { },
                    vendors: new ConsentGdprSaveAndExitVariablesVendor[] { },
                    specialFeatures: new ConsentGdprSaveAndExitVariablesSpecialFeature[] { }
                    );
            }
            body = new PostConsentGdprRequest(
                requestUUID: GUID.Value,
                idfaStatus: "accepted",
                localState: SaveContext.GetLocalState(),
                includeData: includeData,
                pmSaveAndExitVariables: (ConsentGdprSaveAndExitVariables)concretePmSaveAndExitVariables
                );
            break;

        case 2:
            if (pmSaveAndExitVariables != null)
            {
                //remove if vendor._id == null
                concretePmSaveAndExitVariables = pmSaveAndExitVariables as ConsentCcpaSaveAndExitVariables;
                List <ConsentGdprSaveAndExitVariablesVendor> rej = new List <ConsentGdprSaveAndExitVariablesVendor>();
                foreach (var rejected in (pmSaveAndExitVariables as ConsentCcpaSaveAndExitVariables).rejectedVendors)
                {
                    if (!string.IsNullOrEmpty(rejected._id))
                    {
                        rej.Add(rejected);
                    }
                }
                (concretePmSaveAndExitVariables as ConsentCcpaSaveAndExitVariables).rejectedVendors = rej.ToArray();
            }
            else
            {
                concretePmSaveAndExitVariables = new ConsentCcpaSaveAndExitVariables(
                    language: language,
                    privacyManagerId: privacyManagerId,
                    rejectedCategories: new ConsentGdprSaveAndExitVariablesCategory[] { },
                    rejectedVendors: new ConsentGdprSaveAndExitVariablesVendor[] { },
                    specialFeatures: new ConsentGdprSaveAndExitVariablesSpecialFeature[] { }
                    );
            }
            body = new PostConsentCcpaRequest(
                requestUUID: GUID.Value,
                idfaStatus: "accepted",
                localState: SaveContext.GetLocalState(),
                includeData: includeData,
                pmSaveAndExitVariables: (ConsentCcpaSaveAndExitVariables)concretePmSaveAndExitVariables
                );
            break;
        }

        if (body == null)
        {
            onErrorAction?.Invoke(new Exception("Message body is null!!!"));
        }
        else
        {
            Task.Factory.StartNew(async delegate { await PostConsent(actionType, environment, body, onSuccessAction, onErrorAction); });
        }
    }