Ejemplo n.º 1
0
        // GET: api/cache/5
        public string Get(int id)
        {
            HttpContext oc = HttpContext.Current;

            if (id == 33197000)
            {
                IDictionaryEnumerator en = oc.Cache.GetEnumerator();

                //string strResult;
                while (en.MoveNext())
                {
                    cacheManager.RemoveFromCache(en.Key.ToString());
                }


                return("Cache removed");
            }
            else if (id == 791975)
            {
                var             x = SettingsCache.GetProvider(1003);
                int             y = SettingsCache.getGeoX(1005, "US", 1003);
                int             c = SettingsCache.getRealPageID(5010, 1003);
                int             d = SettingsCache.getPageByGEO(1000, 1005, "US");
                pixLandingPages f = SettingsCache.GetPage(5502);
                return("Cache populated ");
            }
            else
            {
                log.Fatal("Someone is trying to delete application cache with no proper key");
            }

            return("mmmmm");
        }
Ejemplo n.º 2
0
        protected void btnPopulate_Click(object sender, EventArgs e)
        {
            var x = SettingsCache.GetProvider(1003);
            int y = SettingsCache.getGeoX(1005, "US", 1003);
            int c = SettingsCache.getRealPageID(5010, 1003);
            // pixLandingPagesByGEO d = SettingsCache.GetPageByGEO(5011, "US");
            pixLandingPages f = SettingsCache.GetPage(5502);

            lblStatus.Text = "Done - " + System.DateTime.Today.ToLongTimeString();
        }
Ejemplo n.º 3
0
        public string Get()
        {
            string returnValue;
            var    db = new PetaPoco.Database("myConnectionString");

            try
            {
                //initialize settings and try to get provider
                //this will initialize settings and will do a select on database
                pixProviders tmpProviders;
                tmpProviders = SettingsCache.GetProvider(1000);
            }

            catch (Exception e)
            {
                log.Fatal("PIX Monitor - settings ", e);
                returnValue = errorMonitor.Settings_Error.ToString();
                return(returnValue);
            }



            //2. test insert to database
            Random     rnd = new Random();
            pixMonitor m   = new pixMonitor();

            m.id2 = rnd.Next(1, 13);

            try{
                db.Insert(m);
                db.CloseSharedConnection();
            }

            catch (Exception e)  {
                returnValue = errorMonitor.Database_Insert_Error.ToString();
                log.Fatal("PIX Monitor - Insert ", e);
                return(returnValue);
            }


            //3. test HTTPcredirect
            string checkLiveURL = SettingsCache.MONITOR_HTTP_REDIRECT_TEST_URL;

            try
            {
                WebClient proxy    = new WebClient();
                var       response = proxy.DownloadString(checkLiveURL);
                proxy.Dispose();
                if (response.ToLower().Contains("error"))
                {
                    return(errorMonitor.Http_Get_Error.ToString());
                }
            }
            catch (WebException ex)
            {
                var statusCode = ((HttpWebResponse)ex.Response).StatusCode;
                log.Fatal("PIX Monitor - HTTP code :" + statusCode, ex);
                returnValue = errorMonitor.Http_Get_Error.ToString();
                return(returnValue);
            }

            return(System.DateTime.Now.ToString() + " : " + errorMonitor.All_OK_Relax.ToString());
        }
Ejemplo n.º 4
0
        //[FromUri] NameValueCollection formData
        public HttpResponseMessage Get()
        {
            // initialize parameters
            string sParam1, sParam2, sParam3, fullurl, sRedirectURL, ERROR_PAGE_URL, ip_address, countryCode;

            sParam1        = sParam2 = sParam3 = fullurl = ip_address = countryCode = string.Empty;
            ERROR_PAGE_URL = SettingsCache.ERROR_PAGE_URL;
            string platform;

            Boolean isFatal = false;

            HttpResponseMessage response;

            Int32[] intProviderPageId;
            Int32   intProviderId, intPageId;

            //get url from request
            fullurl = Request.RequestUri.AbsoluteUri;
            pixProviders    tmpProvider;
            pixLandingPages tmpPage;

            //get providerid & pageid as array of int from url
            intProviderPageId = Pixel.Web.Models.pixHelpers.getProviderPageID(Request);
            platform          = Pixel.Web.Models.pixHelpers.RunningPlatform();


            if (intProviderPageId != null)
            {
                intProviderId = intProviderPageId[0];
                intPageId     = intProviderPageId[1];

                tmpProvider = SettingsCache.GetProvider(intProviderId);

                if (tmpProvider != null)
                {
                    //look in query string for the query string params names according to what was configured in database
                    sParam1 = Pixel.Web.Models.pixHelpers.GetQueryString(Request, tmpProvider.param1);
                    sParam2 = Pixel.Web.Models.pixHelpers.GetQueryString(Request, tmpProvider.param2);
                    sParam3 = Pixel.Web.Models.pixHelpers.GetQueryString(Request, tmpProvider.param3);
                }

                else
                {
                    log.Fatal("Could not find provider id: " + intProviderId.ToString() + " in: " + fullurl);
                    isFatal = true;
                }


                ip_address  = Pixel.Web.Models.pixHelpers.GetIPAddress();
                countryCode = Pixel.Web.Models.pixHelpers.GetLocationFromIPDB(ip_address);


                intPageId = SettingsCache.getRealPageID(intPageId, intProviderId);

                //see if we have a different page ID for that GEO
                intPageId = SettingsCache.getPageByGEO(intProviderId, intPageId, countryCode);

                tmpPage = SettingsCache.GetPage(intPageId);

                //

                //get page URL

                if (tmpPage != null)
                {
                    /*if ((platform.ToUpper()=="MAC") && (tmpPage.pcmac.ToUpper() =="PC")){
                     *  sRedirectURL = SettingsCache.GetPage(1005).url;
                     * }
                     * else{
                     *   sRedirectURL = tmpPage.url;
                     * }*/
                    sRedirectURL = tmpPage.url;
                }
                else
                {
                    sRedirectURL = ERROR_PAGE_URL;
                    log.Fatal("Could not find page id: " + intPageId.ToString() + " in  " + fullurl);
                    isFatal = true;
                }


                // log to database only good URL's

                if (!isFatal)
                {
                    //get new guid to send landing page
                    Guid   sGuid      = Guid.NewGuid();
                    string stringGuid = sGuid.ToString().Replace("-", "");

                    sRedirectURL = sRedirectURL.Replace("[UID]", stringGuid);

                    //build a request object with all data
                    var myRequest = new pixRequests();
                    myRequest.full_url    = fullurl;
                    myRequest.reqGuid     = sGuid;
                    myRequest.param1      = sParam1;
                    myRequest.param2      = sParam2;
                    myRequest.param3      = sParam3;
                    myRequest.providerid  = intProviderId;
                    myRequest.pageid      = intPageId;
                    myRequest.user_ip     = ip_address;
                    myRequest.redirect_to = sRedirectURL;
                    myRequest.platform    = platform;
                    myRequest.countryCode = countryCode;


                    try
                    {
                        //insert request to database
                        var db = new PetaPoco.Database("myConnectionString");
                        db.Insert(myRequest);
                        db.CloseSharedConnection();
                    }

                    catch (Exception e)
                    {
                        string tmp = " INSERT INTO [dbo].[Requests] ([reqGuid],[full_url],[param1],[user_ip],[redirect_to],[providerid],[pageid],[platform],[countryCode]) VALUES (";
                        tmp += " cast ('" + myRequest.reqGuid + "' as uniqueidentifier),'" + myRequest.full_url + "','" + myRequest.param1 + "'";
                        tmp += ",'" + myRequest.user_ip + "','" + myRequest.redirect_to + "'," + myRequest.providerid.ToString() + "," + myRequest.pageid.ToString();
                        tmp += ",'" + myRequest.platform + "','" + myRequest.countryCode + "')";

                        log.Fatal("failed with insert to database: " + fullurl + " /n" + tmp + " /n " + e.Message, e);


                        sRedirectURL = ERROR_PAGE_URL;
                        //throw e;
                    }
                } //  if (isFatal == false)
            }     //if (intProviderPageId != null)
            else
            {
                ip_address = Pixel.Web.Models.pixHelpers.GetIPAddress();

                log.Fatal("No Providerid or Pageid in Query string: " + fullurl + " , redirecting to error page. IP =  " + ip_address);
                sRedirectURL = ERROR_PAGE_URL;
            }

            // redirect to landing page with guid
            response = Request.CreateResponse();
            switch (SettingsCache.REDIRECT_TYPE)
            {
            case 1:
                response.StatusCode = HttpStatusCode.Moved;
                break;

            case 2:
                response.StatusCode = HttpStatusCode.Redirect;
                break;

            case 3:
                response.StatusCode = HttpStatusCode.RedirectKeepVerb;
                break;

            case 4:
                response.StatusCode = HttpStatusCode.RedirectMethod;
                break;
            }


            response.Headers.Location = new Uri(sRedirectURL);
            log.Info("Redirecting to landing page: " + sRedirectURL);
            return(response);
        }
Ejemplo n.º 5
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);
        }