Ejemplo n.º 1
0
        /// <summary>
        /// Return current banner that should be displayed, NULL otherwise
        /// </summary>
        /// <param name="type"></param>
        /// <param name="position">if you want to get different position than 1st banner (e.g. you have multiple banner controls)</param>
        /// <returns></returns>
        public static BannerAdvert GetCurrentBanner(BannerAdvertDimensions dimensions, int position = 1)
        {
            using (var bridge = ParserPool.Acquire(Database.Client))
            {
                var currentSql  = bridge.Instance.ExecuteRawCommandToDataTable(BannerAuctionSQLManager.GetCurrentSQL(dimensions));
                var currentList = TableHelper.GetListFromDataTable <BannerAuction>(currentSql, 1);

                if (currentList.Count > 0)
                {
                    BannerAuction auction = currentList[0];
                    BannerBid     bid     = auction.GetHighestBid(position);
                    if (bid != null)
                    {
                        if (!bid.RefAndPoolsCredited)
                        {
                            BannerCrediter crediter          = new BannerCrediter(new Member(bid.Username));
                            Money          moneyLeftForPools = crediter.CreditReferer(bid.BidValue);
                            PoolDistributionManager.AddProfit(ProfitSource.Banners, moneyLeftForPools);

                            bid.RefAndPoolsCredited = true;
                            bid.Save();
                        }
                        return(new BannerAdvert(bid.BannerAdvertId));
                    }
                }
                return(null);
            }
        }
Ejemplo n.º 2
0
 private static void HandleEarningStats(BannerBid bid, BannerAuction auction, BannerBid refundBid)
 {
     EarningsStatsManager.Add(EarningsStatsType.Banner, bid.BidValue);
     if (refundBid != null)
     {
         EarningsStatsManager.Subtract(EarningsStatsType.Banner, refundBid.BidValue);
     }
 }
Ejemplo n.º 3
0
        protected static void ConstructInsertQuery(ref StringBuilder sb, BannerAuction Auction)
        {
            sb.Append(" ('")
            .Append(Auction.DateStart.ToDBString())
            .Append("', ")
            .Append(Auction.BannerType.Id)
            .Append(")");

            sb.Append(",");
        }
Ejemplo n.º 4
0
        public static void AddBid(BannerBid bid, BannerAuction auction, Member user)
        {
            //Add new bid
            bid.Save();

            //Make history
            History.AddBidPlaced(user.Name, bid.BidValue.ToString());

            //Refund previous bid (if needed)
            BannerBid bidToRefund = null;

            bidToRefund = auction.GetHighestBid(DisplayedNormalBannerNumber + 1);

            if (bidToRefund != null)
            {
                RefundBid(bidToRefund);

                //Earning statistics
                HandleEarningStats(bid, auction, bidToRefund);
            }
        }
Ejemplo n.º 5
0
        public static void ExecuteCRONSQL()
        {
            using (var bridge = ParserPool.Acquire(Database.Client))
            {
                //Delete old records
                bridge.Instance.ExecuteRawCommandNonQuery(
                    String.Format(@"DELETE FROM BannerBids WHERE BannerAuctionId IN (SELECT Id FROM BannerAuctions WHERE DateStart < '{0}')",
                                  DateTime.Now.Add(-Titan.Advertising.BannerAuction.DeleteOldAfter).ToDBString()));

                bridge.Instance.ExecuteRawCommandNonQuery(
                    String.Format(@"DELETE FROM BannerAuctions WHERE DateStart < '{0}'",
                                  DateTime.Now.Add(-Titan.Advertising.BannerAuction.DeleteOldAfter).ToDBString()));

                //Add new records
                //Executing in 800 batches for good performance

                var latestAuctionSql = bridge.Instance.ExecuteRawCommandToDataTable(
                    String.Format(@"SELECT TOP 1 * FROM BannerAuctions ORDER BY DateStart DESC"));
                var latestAuctionList = TableHelper.GetListFromDataTable <BannerAuction>(latestAuctionSql, 1);

                var now = DateTime.Now;
                now = new DateTime(now.Year, now.Month, now.Day, now.Hour, 0, 0);
                DateTime StartingDate = latestAuctionList.Count > 0 ? latestAuctionList[0].DateStart.Add(AppSettings.BannerAdverts.AuctionTime) : now;

                bool Active = true;

                while (Active)
                {
                    bool AreRecordsInQuery = false;

                    //Batch start
                    var Query = ConstructInsertQueryStart();
                    int i     = 0;
                    while (StartingDate < now.AddDays(BannerAuctionManager.AuctionsGeneratedUpfrontDays) && i < 400)
                    {
                        AreRecordsInQuery = true;

                        var dimenstions = TableHelper.SelectAllRows <BannerAdvertDimensions>();
                        foreach (var dimension in dimenstions)
                        {
                            BannerAuction auction1 = new BannerAuction();
                            auction1.DateStart  = StartingDate;
                            auction1.BannerType = dimension;
                            ConstructInsertQuery(ref Query, auction1);
                            i++;
                        }

                        StartingDate = StartingDate.Add(AppSettings.BannerAdverts.AuctionTime);
                    }

                    if (AreRecordsInQuery)
                    {
                        if (Query[Query.Length - 1] == ',')
                        {
                            Query[Query.Length - 1] = ';';
                        }

                        bridge.Instance.ExecuteRawCommandNonQuery(Query.ToString());
                    }
                    else
                    {
                        Active = false;
                    }
                }
            }
        }