public Money Credit(PtcAdvert ad) { Money calculated = ad.MoneyToClaimAsCashLink; user.AddToMainBalance(calculated, "CashLink", BalanceLogType.CashLinkClick); user.IncreaseEarnings(calculated); //OK mark as watched and credit List <int> av = user.AdsViewed; av.Add(ad.Id); user.AdsViewed = av; user.LastActive = DateTime.Now; Money NewTotalEarned = (user.TotalEarned + calculated); user.TryToAddAchievements( Prem.PTC.Achievements.Achievement.GetProperAchievements( Prem.PTC.Achievements.AchievementType.AfterEarning, NewTotalEarned.GetRealTotals())); user.IncreaseUserStatClicks(1); user.IncreaseStatClicks(1); user.IncreaseCashLinksEarnings(calculated); user.Save(); DailyPoolManager.AddToPool(PoolsHelper.GetBuiltInProfitPoolId(Pools.AdPackRevenueReturn), DateTime.Now, calculated); AdPackProfitDistributionHistory.Add(calculated); return(calculated); }
public static void AddProfit(ProfitSource source, Money amount, ProfitPoolDistribution targetPool) { if (targetPool.Pool == PoolsHelper.GetBuiltInProfitPoolId(Pools.AdPackRevenueReturn)) { //Daily pool DailyPoolManager.AddToPool(targetPool.Pool, DateTime.Now, amount); AdPackProfitDistributionHistory.Add(amount); } else { //Global pool GlobalPoolManager.AddToPool(targetPool.Pool, amount); } }
/// <summary> /// Distributes the money from the Profit Source properly /// </summary> /// <param name="source"></param> /// <param name="amount"></param> public static bool AddProfit(ProfitSource source, Money amount) { if (amount != Money.Zero) { var where = TableHelper.MakeDictionary(ProfitPoolDistribution.Columns.ProfitSource, (int)source); var targetPools = TableHelper.SelectRows <ProfitPoolDistribution>(where); Money distributed = new Money(0); for (int i = 0; i < targetPools.Count; i++) { var poolRule = targetPools[i]; Money toDistribute = new Money(0); //Last pool rule if (i == (targetPools.Count - 1)) { toDistribute = (amount - distributed); } else { toDistribute = Money.MultiplyPercent(amount, poolRule.ProfitPoolPercent); distributed += toDistribute; } if (poolRule.Pool == PoolsHelper.GetBuiltInProfitPoolId(Pools.AdPackRevenueReturn)) { //Daily pool DailyPoolManager.AddToPool(poolRule.Pool, AppSettings.ServerTime, toDistribute); AdPackProfitDistributionHistory.Add(toDistribute); } else { //Global pool GlobalPoolManager.AddToPool(poolRule.Pool, toDistribute); } } return(distributed != Money.Zero); } return(false); }
public static void CRON() { int poolId = PoolsHelper.GetBuiltInProfitPoolId(Pools.AdPackRevenueReturn); //Delete pools older then 2 days and move their money to current pools List <DailyPool> oldPools = TableHelper.GetListFromRawQuery <DailyPool>(String.Format( "SELECT * FROM DailyPools WHERE DateDay <= '{0}' AND DailyPoolType = {1}", AppSettings.ServerTime.AddDays(-2).ToDBString(), poolId)); Money left = Money.Zero; foreach (var oldPool in oldPools) { left += oldPool.SumAmount; } if (left > Money.Zero) { DailyPoolManager.AddToPool(poolId, AppSettings.ServerTime, left); } TableHelper.ExecuteRawCommandNonQuery(String.Format( "DELETE FROM DailyPools WHERE DateDay <= '{0}' AND DailyPoolType = {1}", AppSettings.ServerTime.AddDays(-2).ToDBString(), poolId)); }
public static void ProceedDailyTasks() { log = new StringBuilder(); var Entry = new CronEntry(); Entry.Date = DateTime.Now; try { Log("Starting CRON procedure"); //Make sure it runs only once if (CanRun()) { AppSettings.IsOffline = true; AppSettings.Misc.LastCRONRun = DateTime.Now; AppSettings.Misc.Save(); stime = DateTime.Now; AntiCheatSystem.CRON(); Log("OK [1] AntiCheatSystem. Elapsed time: " + GetTimeString(stime)); RentReferralsSystem.CRON(); Log("OK [2] RentedReferralsSystem. Elapsed time: " + GetTimeString(stime)); StatisticsManager.CRON(); Log("OK [3a] StatisticsManager. Elapsed time: " + GetTimeString(stime)); //MUST BE RUN BEFORE MEMBERMANAGER.CRON() !!! CustomFeaturesManager.CRON(); Log("OK [3b] CustomFeaturesManager. Elapsed time: " + GetTimeString(stime)); MemberManager.CRON(); Log("OK [4] Member. Elapsed time: " + GetTimeString(stime)); SyncedNetworkFactory.SynchronizeAll(); Log("OK [5] CPA Offers. Elapsed time: " + GetTimeString(stime)); AppSettings.Payments.CRON(); Log("OK [6] Payments. Elapsed time: " + GetTimeString(stime)); ShoutboxManager.CRON(); Log("OK [7] Shoutbox. Elapsed time: " + GetTimeString(stime)); CLPManager.CRON(); Log("OK [8] CLPManager. Elapsed time: " + GetTimeString(stime)); BannerAuctionManager.CRON(); Log("OK [10] BannerAuctionManager. Elapsed time: " + GetTimeString(stime)); PointsLockingManager.CRON(); Log("OK [11] PointsLockingManager. Elapsed time: " + GetTimeString(stime)); DBArchiver.CRON(); Log("OK [12] DBArchiver. Elapsed time: " + GetTimeString(stime)); RevenueSharesDistributionManager.CRON(); Log("OK [13] RevenueSharesDistributionManager. Elapsed time: " + GetTimeString(stime)); CreditLineManager.CRON(); Log("OK [14] CreditLineManager. Elapsed time: " + GetTimeString(stime)); PoolRotatorManager.CRON(); Log("OK [15] PoolRotatorManager. Elapsed time: " + GetTimeString(stime)); JackpotManager.CRON(); Log("OK [16] JackpotManager. Elapsed time: " + GetTimeString(stime)); TrafficExchangeManager.CRON(); Log("OK [17] TrafficExchangeManager. Elapsed time: " + GetTimeString(stime)); DailyPoolManager.CRON(); Log("OK [18] DailyPoolManager. Elapsed time: " + GetTimeString(stime)); //Matrix MatrixBase matrix = MatrixFactory.GetMatrix(); if (matrix != null) { matrix.CRON(); } Log("OK [19] MatrixBase. Elapsed time: " + GetTimeString(stime)); ApiAccessToken.CRON(); Log("OK [20] ApiAccessToken. Elapsed time: " + GetTimeString(stime)); InvestmentPlatformManager.CRON(); Log("OK [21] InvestmentPlatformManager. Elapsed time: " + GetTimeString(stime)); MarketplaceBalanceLogManager.CRON(); Log("OK [22] MarketplaceBalanceLogManager. Elapsed time: " + GetTimeString(stime)); MiniVideoManager.CRON(); Log("OK [23] MiniVideoManager. Elapsed time: " + GetTimeString(stime)); PaidToPromoteManager.CRON(); Log("OK [24] PaidToPromoteManager. Elapsed time: " + GetTimeString(stime)); RollDiceLotteryManager.CRON(); Log("OK [25] RollDiceLotteryManager. Elapsed time: " + GetTimeString(stime)); WalletManager.CRON(); Log("OK [26] WalletManager. Elapsed time: " + GetTimeString(stime)); NewsManager.CRON(); Log("OK [27] NewsManager. Elapsed time: " + GetTimeString(stime)); Entry.Type = 1; Entry.Text = "Procedure completed successfully (27/27 100%) after " + GetTimeString(stime); } else { Entry.Type = 2; Entry.Text = "Procedure prevented from multiple run"; } } catch (Exception ex) { ErrorLogger.Log(ex); Log("Fatal error (exception thrown).."); Entry.Type = 3; Entry.Text = "Fatal error during procedure execution. Check logs for more information"; Mailer.SendCRONFailureMessage(); } finally { ErrorLogger.Log(log.ToString(), LogType.CRON); AppSettings.IsOffline = false; Entry.Save(); HttpContext.Current.Response.Write(Entry.Text); } }