Beispiel #1
0
        public async Task <IActionResult> Post([FromBody] AdRequest request)
        {
            List <Bidder>     bidders = _repo.GetBidders();
            List <AdResponse> result  = await GetBids(bidders, request);

            AdResponse temp = new AdResponse();

            temp = result.OrderBy(res => res.Bid.Price).FirstOrDefault();
            return(Ok(temp));
        }
        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();
                }
            }
        }
Beispiel #3
0
        //

        private static Mock <IAdService> Register(App app, Criteria criteria, decimal amount, out string html)
        {
            var service = new Mock <IAdService>();

            html = AutoFaker.Generate <string>();
            var response = new AdResponse {
                Amount = amount, Html = html
            };

            service.Setup(it => it.GetOffer(criteria)).ReturnsAsync(response).Verifiable();
            app.Register(service.Object);
            return(service);
        }
Beispiel #4
0
        private async Task <List <AdResponse> > GetBids(List <Bidder> bidders, AdRequest request)
        {
            List <AdResponse> returnList = new List <AdResponse>();
            var downloads = bidders.Select(bidder => TryDownloadAsync(bidder.Uri, request));

            Task <HttpResponseMessage>[] downloadTasks = downloads.Where(d => d.IsCompletedSuccessfully).ToArray();
            HttpResponseMessage[]        responses     = await Task.WhenAll(downloadTasks);

            foreach (HttpResponseMessage r in responses)
            {
                string     stringData = r.Content.ReadAsStringAsync().Result;
                AdResponse response   = JsonConvert.DeserializeObject <AdResponse>(stringData);
                returnList.Add(response);
            }
            return(returnList);
        }
Beispiel #5
0
    /// <summary>
    /// Get Ads based on user input.
    /// This methods performs the following functions:
    /// 1. If clientCredential of RequestFactory instance is null
    ///         a. Reads access token from file
    ///         b. Set the ClientCredential of requestFactory instance with the access token read from file.
    /// 2. Build AdRequest object.
    /// 3. Call GetAdvertisement() of requestFactory by passing AdRequest object.
    /// 4. Display the AdResponse.
    /// 5. Save the access token information to file.
    /// </summary>
    private void GetAds()
    {
        try
        {
            OAuthToken clientToken = null;
            if (this.requestFactory.ClientCredential == null)
            {
                clientToken = this.ReadAccessTokenFile();
                this.requestFactory.ClientCredential = clientToken;
            }

            AdRequest  adsRequest  = this.BuildAdRequestObject();
            AdResponse adsResponse = this.requestFactory.GetAdvertisement(adsRequest, this.udid);

            if (null == clientToken || (null != clientToken && clientToken.AccessToken != this.requestFactory.ClientCredential.AccessToken))
            {
                this.WriteToAccessTokenFile(this.requestFactory.ClientCredential);
            }

            if (null != adsResponse && null != adsResponse.AdsResponse && null != adsResponse.AdsResponse.Ads)
            {
                this.DrawAdResponse(adsResponse.AdsResponse.Ads);
            }

            if (null == adsResponse || adsResponse.AdsResponse == null)
            {
                this.DrawPanelForFailure(statusPanel, "No content received");
            }
        }
        catch (ArgumentNullException ae)
        {
            this.DrawPanelForFailure(statusPanel, ae.Message);
        }
        catch (InvalidResponseException ire)
        {
            this.DrawPanelForFailure(statusPanel, ire.Body);
        }
        catch (ArgumentException ae)
        {
            this.DrawPanelForFailure(statusPanel, ae.Message);
        }
        catch (Exception ex)
        {
            this.DrawPanelForFailure(statusPanel, ex.Message);
        }
    }
Beispiel #6
0
        /// <summary>
        /// Method called to request an the ad.
        /// </summary>
        private void printCoupon(bool is_test, string receiptContent, AdRequest new_request)
        {
            //Get the selected OPOS printer from list.
            var selectedPrinter = from d in printerList
                                  where d.ServiceObjectName == OPOSListcomboBox.SelectedItem.ToString()
                                  select d;
            PosPrinter actualPrinter = (PosPrinter)posExplorer.CreateInstance(selectedPrinter.ElementAt(0));
            string test = actualPrinter.ToString();
            AddLog("Printer found",false);

            try
            {
                if (actualPrinter != null)
                {
                actualPrinter.Open();

                AddLog("Printer opened",false);

                actualPrinter.Claim(5000);
                actualPrinter.DeviceEnabled = true;
                actualPrinter.RecLetterQuality = true;

                    AdProvider provider = new AdProvider();
                    AdResponse new_response = new AdResponse();

                    provider.Url = WebServiceTextBox.Text;

                    //Call web service
                    if (is_test)
                    {
                         new_response = provider.TestConnection(new_request);
                    }
                    else
                    {
                    new_response = provider.RequestAd(new_request);
                    }

                    if (new_response.is_error)
                    {
                    AddLog(new_response.status,false);
                         RewardsHelper.SaveLastDocket(new_request.currentDocket);
                         PrintLocalDefaultImage(actualPrinter);
                    }
                    else
                    {

                    if (new_response.adList.Count() == 0)
                    {
                        PrintLocalDefaultImage(actualPrinter);
                    }
                    else
                    {
                        int placedad_id = 0;

                        if (!is_test)
                        {
                            placedad_id = new_response.placedad_id;
                        }

                        actualPrinter.PrintNormal(PrinterStation.Receipt, new_response.header);

                        foreach (AdImage item in new_response.adList)
                        {
                            actualPrinter.PrintNormal(PrinterStation.Receipt, "\r\n");
                            Bitmap ADimg = Helpers.ConvertPNGDataToBitmap(item.imageData);
                                   string directory = Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData);
                                   string fileName = directory + @"/temp.bmp";
                            ADimg.Save( fileName, ImageFormat.Bmp);

                            actualPrinter.PrintBitmap(PrinterStation.Receipt, fileName, PosPrinter.PrinterBitmapAsIs, PosPrinter.PrinterBitmapCenter);
                            actualPrinter.PrintNormal(PrinterStation.Receipt, "\r\n");
                            actualPrinter.PrintNormal(PrinterStation.Receipt, item.footer);
                        }

                        actualPrinter.PrintNormal(PrinterStation.Receipt, "\r\n\r\nPowered by www.docketplace.com.au");
                        actualPrinter.PrintNormal(PrinterStation.Receipt, "\r\n\r\n\r\n\r\n\r\n\r\n");
                        actualPrinter.CutPaper(10);
                              actualPrinter.DeviceEnabled = false;
                        AddLog("Internet Image printed\t" + placedad_id + "\r\n",false);
                        }
                    }
                }
            }
            catch (System.Net.WebException ex)
            {
                //If its a test print  failure display a message otherwise print out the default coupon.
                if (is_test)
                {
                    TestStoreConnectionErrorLabel.Text = "No internet connection";
                }
                else
                {
                throw ex;
                }
            }
            catch(Exception ex)
            {
                TestStoreConnectionErrorLabel.Text = "Error with printer , check to see if switched on";
                AddLog(ex.ToString(),true);
            }
            finally
            {
                if (actualPrinter.Claimed)
                {
                    actualPrinter.Release();
                }
                actualPrinter.Close();
            }
        }