Exemplo n.º 1
0
        public override void Download()
        {
            #region Universal

            AffiliateNetwork Network = base.Network;

            try
            {
                DataTable dt = new DataTable();
                using (var bridge = ParserPool.Acquire(Database.Client))
                {
                    dt = bridge.Instance.ExecuteRawCommandToDataTable("SELECT * FROM CPAOffersOnHold WHERE NetworkName = '" + Network.Name + "' ORDER BY NetworkOfferIdInt ASC");
                }
                var OnHoldList = TableHelper.GetListFromDataTable <CPAOfferOnHold>(dt, 100, true);

                #endregion Universal

                JArray element    = GetElement(Network.PublisherPassword, ThrowExceptions);
                int    TotalCount = element.Count;

                //Lets process it in 1-1000 batches
                int BatchesCount = Convert.ToInt32(Math.Ceiling((double)TotalCount / (double)400.0));
                int MainIterator = 0;

                for (int i = 0; i < BatchesCount; ++i)
                {
                    var  Query = ConstructInsertQueryStart();
                    bool AreSomeRecordsInQuery = false;

                    for (int j = 0; j < 400 && MainIterator < TotalCount; j++)
                    {
                        try
                        {
                            var offer = element[MainIterator];

                            string id          = offer["offer_id"].ToString();
                            string name        = offer["offer_name"].ToString();
                            string description = offer["offer_requirements"].ToString();
                            string rate        = offer["offer_commission"].ToString();
                            string incent      = offer["offer_allows_incent"].ToString();

                            string url    = String.Empty;
                            string banner = String.Empty;

                            string countries = GetGeolocation(Network.PublisherPassword, id).Replace("UK", "GB");
                            var    creatives = GetCreatives(Network.PublisherPassword, id);

                            if (creatives["offer_creative_banners"].HasValues)
                            {
                                url    = creatives["offer_creative_banners"][0]["banner_tracking_link"].ToString().Replace("&subid=&", "&subid=%USERNAME%&");;
                                banner = creatives["offer_creative_banners"][0]["banner_creative_url"].ToString();
                            }
                            else if (creatives["offer_text_creatives"].HasValues)
                            {
                                url = creatives["offer_text_creatives"][0]["creative_link"].ToString().Replace("&subid=&", "&subid=%USERNAME%&");;
                            }

                            if (!string.IsNullOrWhiteSpace(url) && !url.ToUpper().Contains("NOT APPROVED"))
                            {
                                SyncedNetwork.HandleAddition(name, description, rate, banner, url, incent, countries, base.Network, id, OnHoldList, ref AreSomeRecordsInQuery, ref Query);
                            }

                            //Increase the iterator
                            MainIterator++;
                        }
                        catch (Exception ex) { ErrorLogger.Log(ex); }
                    }
                    //Now execute the batch;
                    if (AreSomeRecordsInQuery)
                    {
                        using (var bridge = ParserPool.Acquire(Database.Client))
                        {
                            if (Query[Query.Length - 1] == ',')
                            {
                                Query[Query.Length - 1] = ';';
                            }
                            bridge.Instance.ExecuteRawCommandNonQuery(Query.ToString());
                        }
                    }
                }

                //Now, remove the offers that shouldn't be on the list
                foreach (var elem in OnHoldList)
                {
                    if (elem.Status != AdvertStatus.WaitingForAcceptance)
                    {
                        elem.Delete();
                    }
                }

                Network.LastSyncDate = DateTime.Now;
                Network.Save();
            }
            catch (Exception ex)
            {
                ErrorLogger.Log(ex);
                if (base.ThrowExceptions)
                {
                    throw new MsgException("There was a problem with offers export/download " + Network.Name + ": "
                                           + ex.Message + ". Check your username/password and if the website is available");
                }
            }
        }
Exemplo n.º 2
0
        public override void Download()
        {
            #region Universal

            AffiliateNetwork Network = base.Network;

            try
            {
                DataTable dt = new DataTable();
                using (var bridge = ParserPool.Acquire(Database.Client))
                {
                    dt = bridge.Instance.ExecuteRawCommandToDataTable("SELECT * FROM CPAOffersOnHold WHERE NetworkName = '" + Network.Name + "' ORDER BY NetworkOfferIdInt ASC");
                }
                var OnHoldList = TableHelper.GetListFromDataTable <CPAOfferOnHold>(dt, 100, true);

                #endregion Universal

                JObject element    = GetElement(Network.PerformaUsername, ThrowExceptions);
                int     TotalCount = Convert.ToInt32(element["number_offers"]);

                #region Universal

                //Lets process it in 1-1000 batches
                int BatchesCount = Convert.ToInt32(Math.Ceiling((double)TotalCount / (double)1000.0));
                int MainIterator = 0;

                for (int i = 0; i < BatchesCount; ++i)
                {
                    var  Query = ConstructInsertQueryStart();
                    bool AreSomeRecordsInQuery = false;

                    for (int j = 0; j < 1000 && MainIterator < TotalCount; j++)
                    {
                        try
                        {
                            #endregion Universal

                            var offer = element["offers"][MainIterator];

                            string id          = offer["campid"].ToString();
                            string name        = offer["title"].ToString();
                            string url         = offer["link"].ToString();
                            string description = offer["description"].ToString();
                            string rate        = offer["amount"].ToString(); // e.g. 0.24

                            string countries = "";
                            try
                            {
                                countries = offer["country"].ToString(); // 'PL' 'US'
                            }
                            catch (Exception ex) { }

                            string incent = "Yes"; // offer["incent"].ToString(); //'Yes' 'No'
                            string banner = "";    // offer["banner"].ToString();

                            try
                            {
                                banner = offer["creatives"][0]["url"].ToString();
                            }
                            catch (Exception ex) { }

                            #region Universal

                            SyncedNetwork.HandleAddition(name, description, rate, banner, url, incent, countries, base.Network, id, OnHoldList, ref AreSomeRecordsInQuery, ref Query);

                            //Increase the iterator
                            MainIterator++;
                        }
                        catch (Exception ex) { }
                    }
                    //Now execute the batch;
                    if (AreSomeRecordsInQuery)
                    {
                        using (var bridge = ParserPool.Acquire(Database.Client))
                        {
                            if (Query[Query.Length - 1] == ',')
                            {
                                Query[Query.Length - 1] = ';';
                            }


                            bridge.Instance.ExecuteRawCommandNonQuery(Query.ToString());
                        }
                    }
                }

                //Now, remove the offers that shouldn't be on the list
                foreach (var elem in OnHoldList)
                {
                    if (elem.Status != AdvertStatus.WaitingForAcceptance)
                    {
                        elem.Delete();
                    }
                }

                Network.LastSyncDate = DateTime.Now;
                Network.Save();
            }
            catch (Exception ex)
            {
                ErrorLogger.Log(ex);
                if (base.ThrowExceptions)
                {
                    throw new MsgException("There was a problem with offers export/download " + Network.Name + ": "
                                           + ex.Message + ". Check your username/password and if the website is available");
                }
            }
            #endregion Universal
        }
        public override void Download()
        {
            #region Universal

            AffiliateNetwork Network = base.Network;

            try
            {
                DataTable dt = new DataTable();
                using (var bridge = ParserPool.Acquire(Database.Client))
                {
                    dt = bridge.Instance.ExecuteRawCommandToDataTable("SELECT * FROM CPAOffersOnHold WHERE NetworkName = '" + Network.Name + "' ORDER BY NetworkOfferIdInt ASC");
                }
                var OnHoldList = TableHelper.GetListFromDataTable <CPAOfferOnHold>(dt, 100, true);

                #endregion Universal

                XmlDocument doc        = GetElement(Network.PublisherPassword, Network.PublisherUsername, ThrowExceptions);
                XmlElement  root       = doc.DocumentElement;
                XmlNodeList elemList   = root.ChildNodes;
                int         TotalCount = elemList.Count;

                XmlNodeList ids          = root.SelectNodes("/offers/offer/offer_id");
                XmlNodeList names        = root.SelectNodes("/offers/offer/offer_name");
                XmlNodeList descriptions = root.SelectNodes("/offers/offer/requirements");
                XmlNodeList commissions  = root.SelectNodes("/offers/offer/rate");
                XmlNodeList countries    = root.SelectNodes("/offers/offer/allowed_countries");
                XmlNodeList incentives   = root.SelectNodes("/offers/offer/cash_incentive_allowed");
                XmlNodeList banners      = root.SelectNodes("/offers/offer/creatives/image_url");
                XmlNodeList urls         = root.SelectNodes("/offers/offer/creatives/publisher_url");


                //Lets process it in 1-1000 batches
                int BatchesCount = Convert.ToInt32(Math.Ceiling((double)TotalCount / (double)400.0));
                int MainIterator = 0;

                for (int i = 0; i < BatchesCount; ++i)
                {
                    var  Query = ConstructInsertQueryStart();
                    bool AreSomeRecordsInQuery = false;

                    for (int j = 0; j < 400 && MainIterator < TotalCount; j++)
                    {
                        try
                        {
                            var offer = elemList[MainIterator];

                            string id              = ids[MainIterator].InnerText;
                            string name            = names[MainIterator].InnerText;
                            string description     = descriptions[MainIterator].InnerText;
                            string incent          = incentives[MainIterator].InnerText;
                            string url             = urls[MainIterator].InnerText.Replace("sid1/", "sid1/%USERNAME%");
                            string banner          = banners[MainIterator].InnerText;
                            string rate            = commissions[MainIterator].InnerText;
                            var    countriesList   = countries[MainIterator].SelectNodes("country");
                            string countriesString = "";
                            if (countriesList.Count == 1 && countriesList[0].InnerText.ToUpper() == "ALL")
                            {
                                countriesString = "";
                            }
                            else
                            {
                                foreach (XmlElement country in countriesList)
                                {
                                    countriesString += country.InnerText.Trim() + ", ";
                                }
                                if (countriesString.EndsWith(", "))
                                {
                                    countriesString = countriesString.Remove(countriesString.Length - 2);
                                }
                            }

                            if (!string.IsNullOrWhiteSpace(url))
                            {
                                SyncedNetwork.HandleAddition(name, description, rate, banner, url, incent, countriesString, base.Network, id, OnHoldList, ref AreSomeRecordsInQuery, ref Query);
                            }

                            //Increase the iterator
                            MainIterator++;
                        }
                        catch (Exception ex) { ErrorLogger.Log(ex); }
                    }
                    //Now execute the batch;
                    if (AreSomeRecordsInQuery)
                    {
                        using (var bridge = ParserPool.Acquire(Database.Client))
                        {
                            if (Query[Query.Length - 1] == ',')
                            {
                                Query[Query.Length - 1] = ';';
                            }
                            bridge.Instance.ExecuteRawCommandNonQuery(Query.ToString());
                        }
                    }
                }

                //Now, remove the offers that shouldn't be on the list
                foreach (var elem in OnHoldList)
                {
                    if (elem.Status != AdvertStatus.WaitingForAcceptance)
                    {
                        elem.Delete();
                    }
                }

                Network.LastSyncDate = DateTime.Now;
                Network.Save();
            }
            catch (Exception ex)
            {
                ErrorLogger.Log(ex);
                if (base.ThrowExceptions)
                {
                    throw new MsgException("There was a problem with offers export/download " + Network.Name + ": "
                                           + ex.Message + ". Check your username/password and if the website is available");
                }
            }
        }