Esempio n. 1
0
        protected void rfrCache_Click(object sender, EventArgs e)
        {
            cacheManager.RemoveFromCache("providers");

            pixProviders p = Models.SettingsCache.GetProvider(Convert.ToInt16(txtIP.Text));

            var    db     = new PetaPoco.Database("myConnectionString");
            string sQuery = "SELECT * FROM LandingPagesByGEO";

            var result = db.Fetch <object>(sQuery);


            if (p == null)
            {
                label1.Text = "NULL";
            }
            else
            {
                label1.Text = p.name;
            }
        }
Esempio n. 2
0
        // will check if the country the request came from is one that has a landing page
        // if not we should not send response pixel

        /*  private Boolean sendResponseByCountry(int intPageId, string countryCode)
         * {
         *
         *    Boolean retVal = true;
         *    if (SettingsCache.checkLandingPageByGeo(intPageId))
         *    {
         *        pixLandingPagesByGEO tmpPage = SettingsCache.GetPageByGEO(intPageId, countryCode);
         *        if (tmpPage == null) {
         *            retVal = false;
         *        }
         *    }
         *
         *    log.Info("sendResponseByCountry = " + retVal.ToString());
         *    return retVal;
         *
         *
         * }
         */
        private string buildS2SURL(pixProviders provider, pixRequests req)
        {
            //split string to replace vro mprovider
            // for each one
            //take paramX from request and replace in pixel URL from provider
            List <string> paramsToReplace;

            paramsToReplace = provider.pixel_url_Text2Replace.Split(',').ToList();
            string pixelURL = provider.pixel_url;
            int    i        = 1;



            try
            {
                foreach (string value in paramsToReplace)
                {
                    if (value.Contains("#CC#"))  //replacing countyrcode and any other system variables we want :-) just make sure to put in ## and implement code
                    {
                        pixelURL = pixelURL.Replace(value, req.countryCode);
                    }
                    else if (value.Contains("#UID#"))
                    {
                        pixelURL = pixelURL.Replace(value, req.reqGuid.ToString());
                    }

                    else
                    {
                        pixelURL = pixelURL.Replace(value, Convert.ToString(req.GetType().GetProperty("param" + i.ToString()).GetValue(req, null)));
                        i       += 1;
                    }
                }
            }
            catch (Exception e) {
                log.Fatal("Faild to build pixel URL from request ID: " + req.id.ToString(), e);
            }


            return(pixelURL);
        }
Esempio n. 3
0
        // GET: api/s
        //this function will be called when installaiton is finished and we are getting a call from th DLM


        public string  Get()
        {
            string sUID, fullUrl, pixelURL, retValue, requestCountryCode;
            string ip_address, res_countryCode;

            ip_address = res_countryCode = requestCountryCode = string.Empty;
            Guid  tmpGuid;
            Int32 intProviderId;

            retValue = "OK";

            fullUrl = Request.RequestUri.AbsoluteUri;

            //Get uid from request
            sUID = Pixel.Web.Models.pixHelpers.GetQueryString(Request, "uid");

            log.Info("Got request from DLM: " + fullUrl);

            // if sUID cannot be converted to GUID - no point in moving forward
            if (Guid.TryParse(sUID, out tmpGuid))
            {
                //get requet with equivilant sUID
                var db = new PetaPoco.Database("myConnectionString");
                tmpRequest = db.SingleOrDefault <pixRequests>("SELECT * FROM requests WHERE reqGuid=@0", tmpGuid.ToString());

                if (tmpRequest != null)
                {
                    //get providerID from request
                    intProviderId      = tmpRequest.providerid;
                    intRequestPageId   = tmpRequest.pageid;
                    requestCountryCode = tmpRequest.countryCode;

                    //Get full provider record from cache according to provifderID
                    tmpProvider = SettingsCache.GetProvider(intProviderId);

                    if (tmpProvider != null)
                    {
                        log.Info("Found provider: " + tmpProvider.id.ToString() + " ,building response URL");

                        //getting server to server url and changing return param value
                        if (intProviderId == 1008)
                        {
                            string countryCode = tmpRequest.countryCode.ToUpper();
                            tmpProvider.pixel_url = getMondoS2SURL(countryCode);
                        }


                        pixelURL = buildS2SURL(tmpProvider, tmpRequest);



                        //set up parameters for responses handel
                        var myResponse = new pixResponses();
                        myResponse.sentToProvider = false;

                        // check if we need to send response to provider
                        // if (blnSendPixel() && sendResponseByCountry(intRequestPageId, requestCountryCode))

                        if (blnSendPixel())
                        {
                            //R_FACTOR: get R_Factor for provider/ page-provider etc.
                            //if R_Factroe > 1 we need to send several pixels

                            //1. need to add curent response with sent to provider = 0
                            //2. extract R responses that need to be sent
                            // for each one run loop of
                            // - build request from GUID
                            // - build URL
                            // - send pixel
                            // - update record that provide sent
                            try
                            {
                                //send actual response only in production environment
                                if (Pixel.Web.Models.SettingsCache.SEND_RESPONSE)
                                {
                                    //send response to provider
                                    WebClient proxy = new WebClient();
                                    log.Info("Sending pixel response to Provider: " + pixelURL);
                                    var response = proxy.DownloadString(pixelURL);
                                    proxy.Dispose();
                                    myResponse.sentToProvider = true;
                                }
                            }
                            catch (Exception e)
                            {
                                log.Fatal("Error in sending response to provider: " + pixelURL, e);
                                retValue = "ERROR 2";
                            }
                        }


                        // save all good response to database

                        myResponse.full_url     = fullUrl;
                        myResponse.response_url = pixelURL;
                        myResponse.resGuid      = tmpRequest.reqGuid;
                        myResponse.providerid   = tmpRequest.providerid;
                        myResponse.pageid       = tmpRequest.pageid;
                        myResponse.countryCode  = tmpRequest.countryCode;


                        try
                        {
                            db.Insert(myResponse);
                            db.CloseSharedConnection();
                        }
                        catch (Exception e)
                        {
                            log.Fatal("Could not insert Response to database with url: " + fullUrl, e);
                            retValue = "ERROR 1";
                        }

//****************************************************************************************************************************
                    }

                    else
                    {
                        log.Fatal("Counld not find provider id in: " + fullUrl + ", notification will not be sent");
                        retValue = "ERROR 3";
                    }
                }

                else //a is null
                {
                    log.Fatal("could not find a request in the database with the following GUID: " + sUID);
                    retValue = "ERROR 4";
                }
            }

            else
            {
                log.Fatal("The uid we got from DLM is empty or cannot be converted to guid : " + fullUrl);
                insertErrorResponse(fullUrl);
                retValue = "ERROR 5";
            }
            return(retValue);
        }