private static List <pixLandingPages_X_Mask> loadLandingPagesMask_X() { string cacheName = "landingPages_X_Mask"; log.Info("Settings - loadLandingPagesMask_X "); List <pixLandingPages_X_Mask> pages_X_Mask; if (!cacheManager.IsIncache(cacheName)) { var db = new PetaPoco.Database("myConnectionString"); string sQuery = "SELECT * FROM LandingPages_X_Mask"; try { var result = db.Fetch <pixLandingPages_X_Mask>(sQuery); db.CloseSharedConnection(); pages_X_Mask = result.ToList(); cacheManager.SaveTocache(cacheName, pages_X_Mask); } catch (Exception e) { log.Error("!! cannot load Settings of all Landing pages X Mask !!", e); } } return(cacheManager.GetFromCache <List <pixLandingPages_X_Mask> >(cacheName)); }
public static List <pixPaidGEO> loadPaidGEO() { string cacheName = "paidGEO"; log.Info("Settings - loadProviders "); List <pixPaidGEO> paidGEO; if (!cacheManager.IsIncache(cacheName)) { var db = new PetaPoco.Database("myConnectionString"); string sQuery = "SELECT * FROM paidGEO"; try { var result = db.Fetch <pixPaidGEO>(sQuery); db.CloseSharedConnection(); paidGEO = result.ToList(); cacheManager.SaveTocache(cacheName, paidGEO); } catch (Exception e) { log.Fatal("!! cannot load Settings of all providers !!", e); } } return(cacheManager.GetFromCache <List <pixPaidGEO> >(cacheName)); }
// Add error response to database private void insertErrorResponse(string fullUrl) { var db = new PetaPoco.Database("myConnectionString"); var responseError = new pixResponseError(); responseError.url = fullUrl; try { db.Insert(responseError); db.CloseSharedConnection(); } catch (Exception e) { db.CloseSharedConnection(); log.Fatal("Error inserting response error to DataBase", e); } }
private static List <pixLandingPagesByGEO> SomeHeavyAndExpensive_PagesByGeo_Calculation() { List <pixLandingPagesByGEO> tmp_LandingPagesByGeo = null; string sQuery = "SELECT * FROM LandingPagesByGEO"; var db = new PetaPoco.Database("myConnectionString"); try { var result = db.Fetch <pixLandingPagesByGEO>(sQuery); db.CloseSharedConnection(); tmp_LandingPagesByGeo = result.ToList(); } catch (Exception e) { log.Fatal("!! cannot load Settings of all Landing pages !!", e); } return(tmp_LandingPagesByGeo); }
// private static List<pixLandingPages> pages; // private static List<pixLandingPagesByGEO> pagesByGEO; private static List <pixProviders> SomeHeavyAndExpensive_Providers_Calculation() { List <pixProviders> tmp_providers = null; var db = new PetaPoco.Database("myConnectionString"); string sQuery = "SELECT * FROM providers"; try { var result = db.Fetch <pixProviders>(sQuery); db.CloseSharedConnection(); tmp_providers = result.ToList(); } catch (Exception e) { log.Fatal("!! cannot load Settings of all providers !!", e); } return(tmp_providers); }
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()); }
//[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); }
// 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); }