public ITransfersSubscription addSubscription(AccountSubscription subscription) { if (subscription.keys.viewSecretKey != m_viewSecret) { throw new System.Exception("TransfersConsumer: view secret key mismatch"); } auto res = m_subscriptions[subscription.keys.address.spendPublicKey]; if (res.get() == null) { res.reset(new TransfersSubscription(m_currency, m_logger.GetLogger(), subscription)); m_spendKeys.Add(subscription.keys.address.spendPublicKey); if (m_subscriptions.Count == 1) { m_syncStart = res.getSyncStart(); } else { var subStart = res.getSyncStart(); m_syncStart.height = Math.Min(m_syncStart.height, subStart.height); m_syncStart.timestamp = Math.Min(m_syncStart.timestamp, subStart.timestamp); } } return(*res); }
public async Task <IActionResult> Edit(int id, [Bind("AccountSubscritionId,IsActive,IsSuspended,AccountStartDate,AccountEndDate,SuspensionStartDate,SuspensionEndDate")] AccountSubscription accountSubscription) { if (id != accountSubscription.AccountSubscritionId) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(accountSubscription); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!AccountSubscriptionExists(accountSubscription.AccountSubscritionId)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } ViewData["AccountSubscritionId"] = new SelectList(_context.Accounts, "AccountID", "AccountID", accountSubscription.AccountSubscritionId); return(View(accountSubscription)); }
public async Task <IActionResult> Create([Bind("AccountSubscritionId,IsActive,IsSuspended,AccountStartDate,AccountEndDate,SuspensionStartDate,SuspensionEndDate")] AccountSubscription accountSubscription) { if (ModelState.IsValid) { _context.Add(accountSubscription); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["AccountSubscritionId"] = new SelectList(_context.Accounts, "AccountID", "AccountID", accountSubscription.AccountSubscritionId); return(View(accountSubscription)); }
// ITransfersSynchronizer public override ITransfersSubscription addSubscription(AccountSubscription acc) { var it = m_consumers.find(acc.keys.address.viewPublicKey); if (it == m_consumers.end()) { std::unique_ptr <TransfersConsumer> consumer = new std::unique_ptr <TransfersConsumer>(new TransfersConsumer(m_currency, m_node, m_logger.GetLogger(), acc.keys.viewSecretKey)); m_sync.addConsumer(consumer.get()); consumer.addObserver(this); it = m_consumers.Add(acc.keys.address.viewPublicKey, std::move(consumer)).first; } //C++ TO C# CONVERTER TODO TASK: Iterators are only converted within the context of 'while' and 'for' loops: return(it.second.addSubscription(acc)); }
public override async Task <bool> Execute(PerformContext context) { var tokens = await _tokenRepository .GetAll() .ToListAsync(); foreach (var token in tokens) { try { var user = await _userManager.FindByIdAsync(token.AppUserId); if (user is null) { LogError($"Unable to find user for token: {token.Id}"); continue; } using var client = _httpClientFactory.CreateClient("patreon"); client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.AccessToken); var response = await client.GetAsync( "/api/oauth2/v2/identity?include=memberships,memberships.currently_entitled_tiers" ); response.EnsureSuccessStatusCode(); var data = await response.Content.ReadAsStringAsync(); var ds = JsonSerializer.Deserialize <PatreonResponse>(data); if (ds.Subscriptions is null) { continue; } // check if the user has subscribed to any of our active campaigns foreach (var userTiers in ds.Subscriptions .Where(t => t.Id.Equals(_patreonSettings.CampaignId)) .Select(t => t.RelationShips?.CurrentlyEntitledTiers)) { foreach (var t in userTiers?.Tiers) { Log($"Found active tier: {t.Id} - {t.Type}"); var subType = _patreonSettings.Tiers? .FirstOrDefault(patreonTier => patreonTier.Id.Equals((t.Id))); if (subType == null) { continue; } var sub = new AccountSubscription { Type = AccountSubscriptionType.Patreon, Tier = subType.Level, EndDate = DateTime.Today.AddDays(1), WasSuccessful = true }; var existingSubs = _subscriptionRepository .GetAll() .Where(r => r.Type.Equals(AccountSubscriptionType.Patreon)); _subscriptionRepository.GetContext().RemoveRange( existingSubs ); user.AccountSubscriptions.Add(sub); await _unitOfWork.CompleteAsync(); } } } catch (Exception e) { LogError($"Error updating patreon info: {e.Message}"); } } return(true); }
public TransfersSubscription(CryptoNote.Currency currency, Logging.ILogger logger, AccountSubscription sub) { this.subscription = new CryptoNote.AccountSubscription(sub); this.logger = new Logging.LoggerRef(logger, "TransfersSubscription"); this.transfers = new CryptoNote.TransfersContainer(currency, logger, sub.transactionSpendableAge); this.m_address = currency.accountAddressAsString(sub.keys.address); }