protected void UpdateTransactions <TDbTransactionModel>(IDalContext context,
                                                                List <GetTransactionResponse> transactions, string category,
                                                                Func <IDalContext, List <TDbTransactionModel> > funcGetDbTransactions,
                                                                Action <HotWalletModel, TransactionElement> actionAddTransactionInDb)
            where TDbTransactionModel : TransactionModel
        {
            long time;
            var  dictionaryRpcTransactions = new Dictionary <string, List <TransactionElement> >();

            transactions.ForEach(transaction =>
            {
                var detailTransaction = transaction.Details.First(d =>
                                                                  string.Compare(d.Category, category, StringComparison.OrdinalIgnoreCase) == 0);
                time       = GetTransactionTime(transaction, category);
                var result = new TransactionElement(transaction.TxId, transaction.Confirmations, time,
                                                    detailTransaction.Account, detailTransaction.Address, Convert.ToSingle(detailTransaction.Amount));
                if (!dictionaryRpcTransactions.ContainsKey(detailTransaction.Address))
                {
                    dictionaryRpcTransactions[result.Address] = new List <TransactionElement>();
                }
                dictionaryRpcTransactions[result.Address].Add(result);
            });
            var updateDbTransactionsIds =
                UpdateDbTransactions(context, dictionaryRpcTransactions, funcGetDbTransactions);

            AddTransactionsInDb(context, dictionaryRpcTransactions, updateDbTransactionsIds, actionAddTransactionInDb);
        }
 public LowFrequencySpatialFilter(IDalContext dalContext) : base(dalContext)
 {
     KernelConvolution = new double[, ] {
         { 1, 2, 1 }, { 2, 4, 2 }, { 1, 2, 1 }
     };
     PreCalculatedFilterValues = DalContext.GetLowFrequencySpatialDataMatrix();
 }
        protected List <string> UpdateDbTransactions <TDbTransactonModel>(IDalContext context,
                                                                          Dictionary <string, List <TransactionElement> > rpcTransactions,
                                                                          Func <IDalContext, List <TDbTransactonModel> > getDbTransactions) where TDbTransactonModel : TransactionModel
        {
            var dbTransactions        = getDbTransactions(context);
            var transactionsForUpdate = dbTransactions.Where(t => t.Confirmations < MaxGenerationForConfirmation).ToList();

            if (dbTransactions.Count == 0)
            {
                return(Enumerable.Empty <string>().ToList());
            }
            foreach (var dbTransaction in transactionsForUpdate)
            {
                if (!rpcTransactions.ContainsKey(dbTransaction.Address))
                {
                    continue;
                }
                var isExistTransactionElement = rpcTransactions[dbTransaction.Address].Any(te =>
                                                                                           string.Compare(te.TxId, dbTransaction.TxId, StringComparison.OrdinalIgnoreCase) == 0);
                if (!isExistTransactionElement)
                {
                    continue;
                }
                var rpcTransaction = rpcTransactions[dbTransaction.Address].First(te =>
                                                                                  string.Compare(te.TxId, dbTransaction.TxId, StringComparison.OrdinalIgnoreCase) == 0);
                dbTransaction.Confirmations = rpcTransaction.Confirmations;
            }
            context.SaveChangesAsync().Wait();
            return(dbTransactions.Select(transaction => transaction.TxId).ToList());
        }
        protected void AddTransactionsInDb(IDalContext context, Dictionary <string, List <TransactionElement> > rpcTransactions,
                                           List <string> updateDbTransactionsIds, Action <HotWalletModel, TransactionElement> actionAddTransactionInDb)
        {
            var localWallets      = new Dictionary <string, HotWalletModel>();
            var localTransactions = new Dictionary <string, TransactionElement>();
            var dbWallets         = context.HotWallets.ToList();

            dbWallets.ForEach(dbWallet => localWallets[dbWallet.Address] = dbWallet);
            var addRpcTransactionsIds = rpcTransactions.Keys
                                        .SelectMany(key => rpcTransactions[key].Select(te => te.TxId)).Except(updateDbTransactionsIds).ToList();

            if (addRpcTransactionsIds.Count == 0)
            {
                return;
            }
            rpcTransactions.Keys.SelectMany(key => rpcTransactions[key])
            .ForEach(te => localTransactions[te.TxId] = te);
            addRpcTransactionsIds.ForEach(id =>
            {
                var localTransaction = localTransactions[id];
                var localWallet      = localWallets[localTransaction.Address];
                if (localTransaction.Confirmations <= MaxGenerationForConfirmation)
                {
                    actionAddTransactionInDb(localWallet, localTransaction);
                }
            });
            context.SaveChangesAsync().Wait();
        }
 public HighFrequencySpatialFilter(IDalContext dalContext) : base(dalContext)
 {
     KernelConvolution = new double[, ] {
         { 1, -2, 1 }, { -2, 5, -2 }, { 1, -2, 1 }
     };;
     PreCalculatedFilterValues = DalContext.GetHighFrequencySpatialDataMatrix();
 }
 private RoundController(IDalContext context)
 {
     _tournaments = context.Tournaments;
     _members = context.Members;
     _rounds = context.Rounds;
     _tables = context.Tables;
 }
 public DataLoader(ISaContext saContext, IDalContext dalContext, ILogsContext logsContext, IWrapper <ILog> log, IIdentityRepository identityRepository)
 {
     SaContext          = saContext;
     DalContext         = dalContext;
     LogsContext        = logsContext;
     Log                = log;
     IdentityRepository = identityRepository;
 }
 public AccountsApiRepository(IWrapper <ILog> logger, IIdentityRepository identityRepository, IDalContext context) : base(logger)
 {
     IdentityRepository = identityRepository;
     Context            = context;
     if (!WebSecurity.Initialized)
     {
         IdentityRepository.Initialize();
     }
 }
 public DataLoader(ISaContext saContext, IDalContext dalContext, ILogsContext logsContext, IWrapper <ILog> log, IIdentityRepository identityRepository)
 {
     SaContext          = saContext;
     DalContext         = dalContext;
     LogsContext        = logsContext;
     Log                = log;
     IdentityRepository = identityRepository;
     Random             = new Random(DateTime.UtcNow.Second);
     NameBuilder        = new StringBuilder();
 }
        protected void UpdateWallets(IDalContext context, List <ListReceivedByAddressResponseElement> wallets)
        {
            var walletsAdresses   = wallets.Select(w => w.Address).ToList();
            var walletsDictionary = new Dictionary <string, ListReceivedByAddressResponseElement>(wallets.Count);

            wallets.ForEach(wallet => walletsDictionary[wallet.Address] = wallet);
            var dbWallets          = context.HotWallets.ToList();
            var dbWalletsAddresses = dbWallets.Select(dbWallet => dbWallet.Address).ToList();

            dbWallets.ForEach(dbWallet => dbWallet.Amount = walletsDictionary[dbWallet.Address].Amount);
            context.SaveChangesAsync().Wait();
            walletsAdresses.Except(dbWalletsAddresses).ForEach(address =>
            {
                var addWallet = walletsDictionary[address];
                context.HotWallets.Add(new HotWalletModel
                {
                    Account = addWallet.Account,
                    Address = addWallet.Address,
                    Amount  = addWallet.Amount
                });
            });
            context.SaveChangesAsync().Wait();
        }
Beispiel #11
0
 public BaseManager()
 {
     Ioc.RegisterServices();
     _context = Ioc.Instance.GetService(typeof(IDalContext)) as IDalContext;
     _logger = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
 }
 private MemberController(IDalContext context)
 {
     _users = context.Users;
     _members = context.Members;
 }
Beispiel #13
0
 public SobelFilter(IDalContext dalContext)
 {
     DalContext = dalContext;
     PreCalculatedFilterValues = DalContext.GetSobelDataMatrix();
 }
Beispiel #14
0
 public BaseManager()
 {
     Ioc.RegisterServices();
     _context = Ioc.Instance.GetService(typeof(IDalContext)) as IDalContext;
     _logger  = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
 }
Beispiel #15
0
 public static void Init(IDalContext context)
 {
     Current = context;
 }
 protected List <OutgoingTransactionModel> GetOutgoingDbTransactions(IDalContext context)
 {
     return(context.HotWallets.SelectMany(wallet => wallet.OutgoingTransactions)
            .Where(transaction => transaction.Confirmations <= MaxGenerationForConfirmation).ToList());
 }
 public IdentityRepository(IDalContext context, IWrapper <ILog> logger) : base(logger)
 {
     Context = context;
 }
 public HomeController(IHomeRepository homeRepository, IDalContext context) : base(homeRepository)
 {
     Context = context;
 }
 public MessagesApiRepository(IWrapper <ILog> logger, IDalContext context) : base(logger)
 {
     Context = context;
 }
Beispiel #20
0
 public static void Init(IDalContext context)
 {
     Current = context;
 }
Beispiel #21
0
 public IdentityRepository(IDalContext context, ISystemMessagesRepository systemMessagesRepository, IWrapper <ILog> logger) : base(logger)
 {
     Context = context;
     SystemMessagesRepository = systemMessagesRepository;
 }
 protected BaseFrequencySpatialFilter(IDalContext dalContext)
 {
     DalContext = dalContext;
 }