Exemple #1
0
        internal void saveAdvertisement(advertisement ad)
        {
            advertisement Old = new advertisement();

            Old = ad.SearchById(ad.Id);
            if (Old != null)
            {
                updateUI(new System.Action(() => grid("Captured", ad.Id+" : Already Exist..!", Color.Blue)));
                try
                {
                    ad.firstSceen = Old.firstSceen;
                    var CurrentHit = Old.Hits.Find(a => a.date == System.DateTime.Now.Date);
                    if (CurrentHit != null) CurrentHit.count++;
                    else
                    {
                        ad_hits hit = new ad_hits();
                        hit.date = System.DateTime.Now.Date;
                        hit.count = 1;
                        Old.Hits.Add(hit);
                    }
                    ad.Hits = Old.Hits;

                    var OldDetail = Old.ad_details.Find(a => a.advertiserUrl == ad.advertiserUrl[0]);
                    if (OldDetail != null)
                    {
                        OldDetail.lastSceen = System.DateTime.Now;
                        var imag = OldDetail.Images.Find(a => a.ImageUrl == ad.ad_details[0].Images[0].ImageUrl);
                        if (imag == null)
                        {
                            int index = Old.ad_details.FindIndex(a => a.advertiserUrl == ad.advertiserUrl[0]);
                            string ImagePath = Old.Id + "_" + index + "_" + OldDetail.Images.Count;
                            ImageDetails.Enqueue(ImagePath + "|" + ad.ad_details[0].Images[0].ImageUrl);
                            //if (NetworkFunctions.UploadImage(ImagePath, ad.ad_details[0].Images[0].ImageUrl))
                            {
                                ad.ad_details[0].Images[0].ServerUrl = ImagePath;
                                ad.ad_details[0].Images[0].IsServerUploaded = true;

                            }

                            OldDetail.Images.Add(ad.ad_details[0].Images[0]);
                        }
                        if (!OldDetail.publisherUrl.Contains(ad.ad_details[0].publisherUrl[0])) OldDetail.publisherUrl.Add(ad.ad_details[0].publisherUrl[0]);
                        var HitDetail = OldDetail.Hits.Find(a => a.date == System.DateTime.Now.Date);
                        if (HitDetail != null) HitDetail.count++;
                        else
                        {
                            ad_hits hit = new ad_hits();
                            hit.date = System.DateTime.Now.Date;
                            hit.count = 1;
                            OldDetail.Hits.Add(hit);
                        }

                    }
                    else
                    {
                        //int index = Old.ad_details.FindIndex(a => a.advertiserUrl == ad.advertiserUrl[0]);
                        string ImagePath = Old.Id + "_" + Old.ad_details.Count + "_" + 0;
                        ImageDetails.Enqueue(ImagePath + "|" + ad.ad_details[0].Images[0].ImageUrl);
                        //if (NetworkFunctions.UploadImage(ImagePath, ad.ad_details[0].Images[0].ImageUrl))
                        {
                            ad.ad_details[0].Images[0].ServerUrl = ImagePath;
                            ad.ad_details[0].Images[0].IsServerUploaded = true;

                        }
                        Old.ad_details.Add(ad.ad_details[0]);
                    }
                    ad.ad_details = Old.ad_details;
                    if (Old.publisherUrl.Contains(ad.publisherUrl[0])) ad.publisherUrl = Old.publisherUrl;
                    else
                    {
                        Old.publisherUrl.Add(ad.publisherUrl[0]);
                        ad.publisherUrl = Old.publisherUrl;
                    }
                    if (Old.advertiserUrl.Contains(ad.advertiserUrl[0])) ad.advertiserUrl = Old.advertiserUrl;
                    else
                    {
                        Old.advertiserUrl.Add(ad.advertiserUrl[0]);
                        ad.advertiserUrl = Old.advertiserUrl;
                    }

                    ad.Update(ad);
                    updateUI(new System.Action(() => grid("Update", ad.Id + " : successfully Updated..!", Color.Blue)));
                }
                catch { }

            }
            else
            {

                // ad.publisherUrl = new List<string> { publisherUrl };
                try
                {
                    //int index = Old.ad_details.FindIndex(a => a.advertiserUrl == ad.advertiserUrl[0]);
                    string ImagePath = ad.Id + "_" + 0 + "_" + 0 + ".jpg";//////////one
                    ImageDetails.Enqueue(ImagePath + "|" + ad.ad_details[0].Images[0].ImageUrl);
                   // if (NetworkFunctions.UploadImage(ImagePath, ad.ad_details[0].Images[0].ImageUrl))
                    {
                        ad.ad_details[0].Images[0].ServerUrl = ImagePath;
                        ad.ad_details[0].Images[0].IsServerUploaded = true;
                    }
                    ad.Insert(ad);
                    updateUI(new System.Action(() => grid("Insert", ad.Id + " : successfully Saved..!", Color.HotPink)));
                }
                catch { }

            }
        }
Exemple #2
0
        internal void combineAdd(string url, List<string> adIds, List<string> adUrls, List<string> adImages, List<string> adTitle, List<string> imgwidth, List<string> imgheight, ad_network adN,string agent,string time)
        {
            updateUI(new System.Action(() => grid("Combining Add", "Total: "+adIds.Count+" From "+url, Color.Green)));
            for (int i = 0; i < adUrls.Count; i++)
            {

                //file.Write(adUrls[i] +"|" + adIds + "|" + adImages[i] + "|" + adTitle + "|" + FirstSeen[i] + "|" + LastSeen[i]);
                advertisement ad = new advertisement();
                ad.Id = adIds[i] + "_" + adN.name + "_" + Form1.country + "_" + Form1.device;
                ad.ad_networkId = adN.id;
                ad.ad_networkName = adN.name;
                ad.AddId = adIds[i];
                ad.Time = time;
                ad.title = adTitle[i];// "19 Things That Probably Only Happen in Dubai";
                                      //ad.image = adImages[i];// "http://d3dytsf4vrjn5x.cloudfront.net/2724/300x250/6afe33ad3159d67dd9b77b210a1a4335.jpg";
                                      //ad.imageheight = 120;
                                      //ad.imageWidth = 150;

                ad.firstSceen = System.DateTime.Now;
                ad.lastSceen = System.DateTime.Now;
                ad.advertiserUrl = new List<string> { url }; //url;
                                                             // ad.publisherUrl[0] = adUrls[i];
                ad.publisherUrl = new List<string> { adUrls[i] };

                //ad.publisherUrl = new List<string> { "http://firsttoknow.com/only-in-dubai/?utm_source=contentad_backfill&utm_campaign=only-in-dubai-102596&pp=1", "http://firsttoknow.com/make-a-ring-out-of-a-quarter/?utm_source=contentad_backfill&utm_campaign=make-a-ring-out-of-a-qua-108675&pp=1" };
                ad.Country = Form1.country;
                ad.deviceName = Form1.device;

                ad.Useragent = agent;//"Opera/9.80 (Android; Opera Mini/5.1.22460/23.334; U; en) Presto/2.5.25 Version/10.54";//"Mozilla/5.0 (compatible; MSIE 9.0; Windows Phone OS 7.5; Trident/5.0; IEMobile/9.0)";//"Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/46.0.2490.86 Safari/537.36";
                ad.Hits = new List<ad_hits>();
                ad_hits hit = new ad_hits();
                hit.date = System.DateTime.Now.Date;
                hit.count = 1;
                ad.Hits.Add(hit);
                ad.ad_details = new List<ad_Detail>();
                ad_Detail adeatail = new ad_Detail();
                adeatail.advertiserUrl = url;
                adeatail.publisherUrl = new List<string> { adUrls[i] };
                adeatail.firstSceen = System.DateTime.Now;
                adeatail.lastSceen = System.DateTime.Now;
                adeatail.Hits = new List<ad_hits> { hit };
                //adeatail.Hits.Add(hit);
                ad_Images aImage = new ad_Images();
                aImage.ImageUrl = adImages[i];
                try
                {
                    aImage.imageheight = imgheight[i];
                    aImage.imageWidth = imgwidth[i];
                }
                catch
                {
                    aImage.imageheight = "300";
                    aImage.imageWidth = "250";
                }
                aImage.IsServerUploaded = false;
                aImage.IsAmazonUploaded = false;
                aImage.ServerUrl = "";
                aImage.AmazonUrl = "";

                adeatail.Images = new List<ad_Images> { aImage };
                ad.ad_details.Add(adeatail);
                saveAdvertisement(ad);
            }
            adIds = new List<string>();
            adUrls = new List<string>();
            adImages = new List<string>();
            adTitle = new List<string>();
        }