private void OnAdResponseReceived(System.Object sender, UploadStringCompletedEventArgs e)
        {
            Logger.Log(this, "OnAdResponseReceived: Entered");

            /**
             * Error Handling for Ad Response
             **/
            if (e.Cancelled)
            {
                String           errorMesage = "Request Cancelled.";
                AdUnitFailedArgs args        = new AdUnitFailedArgs(AdUnitFailedArgs.ErrorCode.NO_AD_LOADED, errorMesage, this.adUnitId);
                adUnitListener.OnAdUnitLoadFailed(args);
                //AnalyticsWebManager.Push(new AdEventDTO(this.adUnitId, AdEventDTO.EventType.AdMetadataLoadFailed, errorMesage), AnalyticsWebWrapperDTO.Action.AdEvent, AnalyticsWebManager.PRIORITY.HIGH);
                return;
            }
            if (e.Error != null)
            {
                String           errorMessage = e.Error.Message;
                AdUnitFailedArgs args         = new AdUnitFailedArgs(AdUnitFailedArgs.ErrorCode.NO_AD_LOADED, errorMessage, this.adUnitId);
                adUnitListener.OnAdUnitLoadFailed(args);
                //AnalyticsWebManager.Push(new AdEventDTO(this.adUnitId, AdEventDTO.EventType.AdMetadataLoadFailed, errorMessage), AnalyticsWebWrapperDTO.Action.AdEvent, AnalyticsWebManager.PRIORITY.HIGH);
                return;
            }
            AdResponse adResponse = JsonConvert.DeserializeObject <AdResponse>(e.Result);

            if (adResponse.errorCode != 0)
            {
                String           errorMessage = adResponse.errorMsg;
                AdUnitFailedArgs args         = new AdUnitFailedArgs(AdUnitFailedArgs.ErrorCode.NO_AD_LOADED, errorMessage, this.adUnitId);
                adUnitListener.OnAdUnitLoadFailed(args);
                //AnalyticsWebManager.Push(new AdEventDTO(this.adUnitId, AdEventDTO.EventType.AdMetadataLoadFailed, errorMessage), AnalyticsWebWrapperDTO.Action.AdEvent, AnalyticsWebManager.PRIORITY.HIGH);
                return;
            }
            //AnalyticsWebManager.Push(new AdEventDTO(this.adUnitId, AdEventDTO.EventType.AdMetadataLoadSuccess, ""), AnalyticsWebWrapperDTO.Action.AdEvent, AnalyticsWebManager.PRIORITY.HIGH);

            /**
             * Analyzing individual ads in the response
             */
            ads = new List <ImageTextureAd>();
            for (int i = 0; i < adResponse.adResources.Count; i++)
            {
                AdResourceMetadata adMetadata = adResponse.adResources[i];
                if (adMetadata.errorCode != 0) //Some error occured in this particualr ad
                {
                    adsMutex.WaitOne();
                    adErrors.Add(new AdErrorData(adMetadata.errorCode, adMetadata.errorMsg));
                    adsMutex.ReleaseMutex();
                }
                else if (adMetadata.errorCode == 0) //No error for this ad
                {
                    ImageTextureAd ad = new ImageTextureAd(adMetadata.adServingId, this.adUnitId, adMetadata.diffuseTextureImageUrl, this);
                    ad.DownloadAd();
                }
            }
        }
        public void OnAdLoaded(Object context)
        {
            ImageTextureAd ad = (ImageTextureAd)context;

            adsMutex.WaitOne();
            ads.Add(ad);
            int total = adErrors.Count + ads.Count;

            adsMutex.ReleaseMutex();
            if (total == nDistinctAds)
            {
                AllAdsResponded();
            }
        }
 public ImageTextureAdInstance(String instanceId, ImageTextureAd ad, IAdObject adObject) : base(instanceId, ad.adUnitId, ad.adServingId, adObject)
 {
     this.ad = ad;
 }