예제 #1
0
    //called on configure server button click
    public string configureServer(ConsoliAds CAInstance, JSONClass allAdNetworks)
    {
        //creating App JSON
        var    strJson         = new JSONClass();
        string contentEncoding = "";

        strJson.Add(CAConstants.PACKAGE_KEY, CAInstance.bundleIdentifier.ToString());
        strJson.Add(CAConstants.TITLE_KEY, CAInstance.appName.ToString());
        strJson.Add(CAConstants.SDK_VERSION_KEY, CAConstants.ConsoliAdsVersion);
        strJson.Add(CAConstants.SDK_VERSION_ID_KEY, CAConstants.sdkVersionID);
        strJson.Add(CAConstants.SDK_VERSION, CAConstants.sdkVersionID);
        strJson.Add(CAConstants.USER_SIGNATURE_KEY, CAInstance.userSignature.ToString());
        strJson.Add(CAConstants.TOTAL_SEQUENCES_KEY, CAInstance.scenesArray.Length.ToString());

        if (CAInstance.getShowAdMechanism() == ConsoliAdsShowAdMechanism.Priority)
        {
            strJson.Add(CAConstants.AD_SHOWN_MECHANISM_KEY, "priority");
        }
        else
        {
            strJson.Add(CAConstants.AD_SHOWN_MECHANISM_KEY, "round_robin");
        }

        if (CAInstance.platform == Platform.Google)
        {
            if (CAInstance.rateUsURL == "https://play.google.com/store/apps/details?id=")
            {
                strJson.Add(CAConstants.GP_RATEUS_URL_KEY, CAInstance.rateUsURL + CAInstance.bundleIdentifier);
            }
            else
            {
                strJson.Add(CAConstants.GP_RATEUS_URL_KEY, CAInstance.rateUsURL);
            }
        }
        else
        {
            strJson.Add(CAConstants.AS_RATEUS_URL_KEY, CAInstance.rateUsURL);
        }

        if (CAInstance.isHideAds)
        {
            strJson[CAConstants.IS_HIDEAD_KEY].AsInt = 1;
        }
        else
        {
            strJson[CAConstants.IS_HIDEAD_KEY].AsInt = 0;
        }

        if (CAInstance.ShowLog)
        {
            strJson[CAConstants.MEDIATION_LOG_KEY].AsInt = 1;
        }

        if (CAInstance.ChildDirected)
        {
            strJson[CAConstants.CHILED_DIRECTED_KEY].AsInt = 1;
        }
        else
        {
            strJson[CAConstants.CHILED_DIRECTED_KEY].AsInt = 0;
        }

        strJson[CAConstants.STORE_KEY].AsInt = (int)CAInstance.platform;

        for (int sequenceCounter = 0; sequenceCounter < CAInstance.scenesArray.Length; sequenceCounter++)
        {
            strJson[CAConstants.SEQUENCES_KEY][sequenceCounter][CAConstants.SEQUENCE_TITLE_ID_KEY].AsInt = (int)CAInstance.scenesArray[sequenceCounter].placeholderName;
            strJson[CAConstants.SEQUENCES_KEY][sequenceCounter][CAConstants.SKIPFIRST_KEY]           = CAInstance.scenesArray[sequenceCounter].interstitialAndVideoDetails.skipFirst.ToString();
            strJson[CAConstants.SEQUENCES_KEY][sequenceCounter][CAConstants.FAILOVERAD_ID_KEY].AsInt = (int)(AdNetworkName)CAInstance.scenesArray[sequenceCounter].interstitialAndVideoDetails.failOver;
            strJson[CAConstants.SEQUENCES_KEY][sequenceCounter][CAConstants.REWARDED_SKIPFIRST_KEY]  = CAInstance.scenesArray[sequenceCounter].rewardedVideoDetails.skipFirst.ToString();

            strJson[CAConstants.SEQUENCES_KEY][sequenceCounter][CAConstants.BANNER_ENABLED_KEY].AsBool = CAInstance.scenesArray[sequenceCounter].bannerDetails.enabled;
            strJson[CAConstants.SEQUENCES_KEY][sequenceCounter][CAConstants.BANNER_SIZE_KEY].AsInt     = (int)CAInstance.scenesArray[sequenceCounter].bannerDetails.size;
            strJson[CAConstants.SEQUENCES_KEY][sequenceCounter][CAConstants.BANNER_POSITION_KEY].AsInt = (int)CAInstance.scenesArray[sequenceCounter].bannerDetails.position;

            int bannerFailoverID = (int)(AdNetworkName)CAInstance.scenesArray[sequenceCounter].bannerDetails.failOver;
            if (bannerFailoverID != 0)
            {
                strJson[CAConstants.SEQUENCES_KEY][sequenceCounter][CAConstants.BANNER_FAILOVERAD_ID_KEY].AsInt = (int)(AdNetworkName)CAInstance.scenesArray[sequenceCounter].bannerDetails.failOver;
            }
            else
            {
                strJson[CAConstants.SEQUENCES_KEY][sequenceCounter][CAConstants.BANNER_FAILOVERAD_ID_KEY].AsInt = -1;
            }

            int nativeFailoverID = (int)(AdNetworkName)CAInstance.scenesArray[sequenceCounter].nativeDetails.failOver;
            if (nativeFailoverID != 0)
            {
                strJson[CAConstants.SEQUENCES_KEY][sequenceCounter][CAConstants.NATIVE_FAILOVERAD_ID_KEY].AsInt = (int)(AdNetworkName)CAInstance.scenesArray[sequenceCounter].nativeDetails.failOver;
            }
            else
            {
                strJson[CAConstants.SEQUENCES_KEY][sequenceCounter][CAConstants.NATIVE_FAILOVERAD_ID_KEY].AsInt = -1;
            }

            int rewardedFiloverID = (int)(AdNetworkName)CAInstance.scenesArray[sequenceCounter].rewardedVideoDetails.failOver;
            if (rewardedFiloverID != 0)
            {
                strJson[CAConstants.SEQUENCES_KEY][sequenceCounter][CAConstants.REWARDED_FAILOVERAD_ID_KEY].AsInt = (int)(AdNetworkName)CAInstance.scenesArray[sequenceCounter].rewardedVideoDetails.failOver;
            }
            else
            {
                strJson[CAConstants.SEQUENCES_KEY][sequenceCounter][CAConstants.REWARDED_FAILOVERAD_ID_KEY].AsInt = -1;
            }

            strJson[CAConstants.SEQUENCES_KEY][sequenceCounter][CAConstants.NATIVE_ENABLED_KEY].AsBool = CAInstance.scenesArray[sequenceCounter].nativeDetails.enabled;
            strJson[CAConstants.SEQUENCES_KEY][sequenceCounter][CAConstants.NATIVE_WIDTH_KEY].AsInt    = CAInstance.scenesArray[sequenceCounter].nativeDetails.width;
            strJson[CAConstants.SEQUENCES_KEY][sequenceCounter][CAConstants.NATIVE_HEIGHT_KEY].AsInt   = CAInstance.scenesArray[sequenceCounter].nativeDetails.height;



            for (int adCounter = 0; adCounter < CAInstance.scenesArray[sequenceCounter].interstitialAndVideoDetails.networkList.Length; adCounter++)
            {
                AdNetworkNameInterstitial ad = CAInstance.scenesArray[sequenceCounter].interstitialAndVideoDetails.networkList[adCounter];
                strJson[CAConstants.SEQUENCES_KEY][sequenceCounter][CAConstants.INTERSTITIAL_VIDEO_KEY][adCounter][CAConstants.AD_ID_KEY].AsInt    = (int)ad;
                strJson[CAConstants.SEQUENCES_KEY][sequenceCounter][CAConstants.INTERSTITIAL_VIDEO_KEY][adCounter][CAConstants.AD_ORDER_KEY].AsInt = (adCounter + 1);
            }

            for (int adCounter = 0; adCounter < CAInstance.scenesArray[sequenceCounter].rewardedVideoDetails.networkList.Length; adCounter++)
            {
                AdNetworkNameRewardedVideo ad = CAInstance.scenesArray[sequenceCounter].rewardedVideoDetails.networkList[adCounter];

                if ((int)ad == 0)
                {
                    strJson[CAConstants.SEQUENCES_KEY][sequenceCounter][CAConstants.REWARDEDVIDEO_KEY][adCounter][CAConstants.AD_ID_KEY].AsInt = -1;
                }
                else
                {
                    strJson[CAConstants.SEQUENCES_KEY][sequenceCounter][CAConstants.REWARDEDVIDEO_KEY][adCounter][CAConstants.AD_ID_KEY].AsInt = (int)ad;
                }

                strJson[CAConstants.SEQUENCES_KEY][sequenceCounter][CAConstants.REWARDEDVIDEO_KEY][adCounter][CAConstants.AD_ORDER_KEY].AsInt = (adCounter + 1);
            }

            /*
             *          for (int adCounter = 0; adCounter < CAInstance.scenesArray[sequenceCounter].interactiveDetails.networkList.Length; adCounter++)
             *          {
             *                  AdNetworkNameInteractive ad = CAInstance.scenesArray[sequenceCounter].interactiveDetails.networkList[adCounter];
             *
             *                  if ((int)ad == 0)
             *                          strJson[CAConstants.SEQUENCES_KEY][sequenceCounter][CAConstants.INTERACTIVE_KEY][adCounter][CAConstants.AD_ID_KEY].AsInt = -1;
             *                  else
             *                          strJson[CAConstants.SEQUENCES_KEY][sequenceCounter][CAConstants.INTERACTIVE_KEY][adCounter][CAConstants.AD_ID_KEY].AsInt = (int)ad;
             *
             *                  strJson[CAConstants.SEQUENCES_KEY][sequenceCounter][CAConstants.INTERACTIVE_KEY][adCounter][CAConstants.AD_ORDER_KEY].AsInt = (adCounter + 1);
             *          }
             */

            for (int adCounter = 0; adCounter < CAInstance.scenesArray[sequenceCounter].nativeDetails.networkList.Length; adCounter++)
            {
                AdNetworkNameNative ad = CAInstance.scenesArray[sequenceCounter].nativeDetails.networkList[adCounter];

                if ((int)ad == 0)
                {
                    strJson[CAConstants.SEQUENCES_KEY][sequenceCounter][CAConstants.NATIVEAD_KEY][adCounter][CAConstants.AD_ID_KEY].AsInt = -1;
                }
                else
                {
                    strJson[CAConstants.SEQUENCES_KEY][sequenceCounter][CAConstants.NATIVEAD_KEY][adCounter][CAConstants.AD_ID_KEY].AsInt = (int)ad;
                }

                strJson[CAConstants.SEQUENCES_KEY][sequenceCounter][CAConstants.NATIVEAD_KEY][adCounter][CAConstants.AD_ORDER_KEY].AsInt = (adCounter + 1);
            }

            for (int adCounter = 0; adCounter < CAInstance.scenesArray[sequenceCounter].bannerDetails.networkList.Length; adCounter++)
            {
                AdNetworkNameBanner ad = CAInstance.scenesArray[sequenceCounter].bannerDetails.networkList[adCounter];

                if ((int)ad == 0)
                {
                    strJson[CAConstants.SEQUENCES_KEY][sequenceCounter][CAConstants.BANNERAD_KEY][adCounter][CAConstants.AD_ID_KEY].AsInt = -1;
                }
                else
                {
                    strJson[CAConstants.SEQUENCES_KEY][sequenceCounter][CAConstants.BANNERAD_KEY][adCounter][CAConstants.AD_ID_KEY].AsInt = (int)ad;
                }

                strJson[CAConstants.SEQUENCES_KEY][sequenceCounter][CAConstants.BANNERAD_KEY][adCounter][CAConstants.AD_ORDER_KEY].AsInt = (adCounter + 1);
            }

            strJson[CAConstants.SEQUENCES_KEY][sequenceCounter][CAConstants.ICONAD_KEY][CAConstants.ICON_ENABLED_KEY].AsBool = CAInstance.scenesArray[sequenceCounter].iconDetails.enabled;
            strJson[CAConstants.SEQUENCES_KEY][sequenceCounter][CAConstants.ICONAD_KEY][CAConstants.AD_ID_KEY].AsInt         = (int)CAInstance.scenesArray[sequenceCounter].iconDetails.adType;
            strJson[CAConstants.SEQUENCES_KEY][sequenceCounter][CAConstants.ICONAD_KEY][CAConstants.ICON_SIZE_KEY].AsInt     = (int)CAInstance.scenesArray[sequenceCounter].iconDetails.size;
        }

        strJson[CAConstants.APP_INTEGRATED_ADNETWORKS_KEY] = allAdNetworks[CAConstants.APP_INTEGRATED_ADNETWORKS_KEY];


        var compressedJson = CAAdnetworkUtils.CompressJson(strJson.ToString());

        WWW result = CAInstance.postAppJson(networkCall(0, compressedJson));


        if (!string.IsNullOrEmpty(result.error))
        {
            Debug.Log("Error: configureServer" + result.error.ToString());
        }
        else
        {
            Dictionary <string, string> headers = result.responseHeaders;

            if (headers.ContainsKey("Content-Encoding"))
            {
                contentEncoding = headers["Content-Encoding"];
            }
            else if (headers.ContainsKey("CONTENT-ENCODING"))
            {
                contentEncoding = headers["CONTENT-ENCODING"];
            }

            contentEncoding = contentEncoding.ToLower();
            string resultResponse = "";

            if (contentEncoding.Equals("gzip") || contentEncoding.Equals("binary/octet stream"))
            {
                try
                {
                    resultResponse = CAAdnetworkUtils.UnZip(result.text);
                }
                catch (Exception exp)
                {
                    resultResponse = "";
                }
            }
            else
            {
                resultResponse = result.text;
            }

            var responseArray = JSONNode.Parse(resultResponse);
            if (responseArray != null)
            {
                populateConsoliAdsParamsFromResponse(responseArray, CAInstance);
                if (responseArray[CAConstants.MESSAGE_KEY] != null)
                {
                    return(responseArray[CAConstants.MESSAGE_KEY]);
                }
            }
        }
        return(null);
    }
예제 #2
0
    public JSONClass validateAllScenesAdNetwork(ConsoliAds CAInstance)
    {
        List <int> userSelectedAdNetworks = new List <int>();

        for (int sequenceCounter = 0; sequenceCounter < CAInstance.scenesArray.Length; sequenceCounter++)
        {
            for (int adCounter = 0; adCounter < CAInstance.scenesArray[sequenceCounter].interstitialAndVideoDetails.networkList.Length; adCounter++)
            {
                AdNetworkNameInterstitial ad = CAInstance.scenesArray[sequenceCounter].interstitialAndVideoDetails.networkList[adCounter];
                if (ad != AdNetworkNameInterstitial.EMPTY)
                {
                    userSelectedAdNetworks.Add((int)ad);
                }
            }

            for (int adCounter = 0; adCounter < CAInstance.scenesArray[sequenceCounter].rewardedVideoDetails.networkList.Length; adCounter++)
            {
                AdNetworkNameRewardedVideo ad = CAInstance.scenesArray[sequenceCounter].rewardedVideoDetails.networkList[adCounter];
                if (ad != AdNetworkNameRewardedVideo.EMPTY && (int)ad != 0)
                {
                    userSelectedAdNetworks.Add((int)ad);
                }
            }

            AdNetworkName failOverInterstitial = (AdNetworkName)CAInstance.scenesArray[sequenceCounter].interstitialAndVideoDetails.failOver;


            if (failOverInterstitial != AdNetworkName.EMPTY)
            {
                userSelectedAdNetworks.Add((int)failOverInterstitial);
            }

            AdNetworkName failOverRewarded = (AdNetworkName)CAInstance.scenesArray[sequenceCounter].rewardedVideoDetails.failOver;
            if (failOverRewarded != AdNetworkName.EMPTY && (int)failOverRewarded != 0)
            {
                userSelectedAdNetworks.Add((int)failOverRewarded);
            }

            for (int adCounter = 0; adCounter < CAInstance.scenesArray[sequenceCounter].nativeDetails.networkList.Length; adCounter++)
            {
                AdNetworkNameNative ad = CAInstance.scenesArray[sequenceCounter].nativeDetails.networkList[adCounter];
                if (ad != AdNetworkNameNative.EMPTY && (int)ad != 0)
                {
                    userSelectedAdNetworks.Add((int)ad);
                }
            }

            for (int adCounter = 0; adCounter < CAInstance.scenesArray[sequenceCounter].bannerDetails.networkList.Length; adCounter++)
            {
                AdNetworkNameBanner ad = CAInstance.scenesArray[sequenceCounter].bannerDetails.networkList[adCounter];
                if (ad != AdNetworkNameBanner.NONE && (int)ad != 0)
                {
                    userSelectedAdNetworks.Add((int)ad);
                }
            }

            AdNetworkNameNative failOverNative = CAInstance.scenesArray[sequenceCounter].nativeDetails.failOver;
            if (failOverNative != AdNetworkNameNative.EMPTY && (int)failOverRewarded != 0)
            {
                userSelectedAdNetworks.Add((int)failOverNative);
            }

            AdNetworkNameBanner failOverBanner = CAInstance.scenesArray[sequenceCounter].bannerDetails.failOver;
            if (failOverBanner != AdNetworkNameBanner.NONE && (int)failOverBanner != 0)
            {
                userSelectedAdNetworks.Add((int)failOverBanner);
            }
        }

        ArrayList  arraylist           = CAAdnetworkUtils.GetIntegratedAdNetworksList(CAInstance, userSelectedAdNetworks);
        List <int> mismatchedAdnetwork = (List <int>)arraylist[0];

        missMatchStr = "";
        foreach (int element in mismatchedAdnetwork)
        {
            missMatchStr = missMatchStr + "\n" + (AdNetworkName)element;
        }
        JSONClass allAdNetworks = (JSONClass)arraylist[1];

        return(allAdNetworks);
    }