protected void GenerateContentForGetLast() { List <GetLastResponseDataElement> data; var container = UnityConfig.GetConfiguredContainer(); using (var context = container.Resolve <IDalContext>()) { var jointIds = new Dictionary <string, bool>(); var allTransactions = context.IncomingTransactions.ToList(); allTransactions.Where(transaction => !transaction.IsInterrogation) .Select(transaction => transaction.TxId).ForEach( txid => { if (!jointIds.ContainsKey(txid)) { jointIds[txid] = true; } }); allTransactions.Where(t => t.Confirmations < MinCoutConfirmations) .Select(transaction => transaction.TxId).ForEach( txid => { if (!jointIds.ContainsKey(txid)) { jointIds[txid] = true; } }); var jointTransactions = allTransactions.Join(jointIds.Keys, transaction => transaction.TxId, key => key, (transaction, key) => transaction).ToList(); data = jointTransactions.Select(transaction => new GetLastResponseDataElement(transaction.TimeTransaction, transaction.Address, transaction.Amount, transaction.Confirmations)).ToList(); jointTransactions.ForEach(transaction => transaction.IsInterrogation = true); context.SaveChangesAsync().Wait(); } var result = new GetLastResponse(data); lock (LockObject) { CaсheGetLastResponse = JsonConvert.SerializeObject(result); } }
public CoreServiceRepository(IWrapper <ILog> logger, IExecutor excecutor) : base(logger) { var ipAddressCoreBitcoinService = ConfigurationManager.AppSettings["IpAddressCoreBitcoinService"]; var maxCountConnectionsForTcpListeners = Convert.ToInt32(ConfigurationManager.AppSettings["MaxCountConnectionsForTcpListeners"]); var portForSendBtc = Convert.ToInt32(ConfigurationManager.AppSettings["PortForSendBtc"]); var portForGetLast = Convert.ToInt32(ConfigurationManager.AppSettings["PortForGetLast"]); var portForGetAddressForAccount = Convert.ToInt32(ConfigurationManager.AppSettings["PortForGetAddressForAccount"]); MaxGenerationForConfirmation = Convert.ToInt32(ConfigurationManager.AppSettings["MaxGenerationForConfirmation"]); MinCoutConfirmations = Convert.ToInt32(ConfigurationManager.AppSettings["MinCoutConfirmations"]); UriBitcoinRpcServer = ConfigurationManager.AppSettings["UriBitcoinRpcServer"]; LoginBitcoinRpcServer = ConfigurationManager.AppSettings["LoginBitcoinRpcServer"]; PasswordBitcoinRpcServer = ConfigurationManager.AppSettings["PasswordBitcoinRpcServer"]; var emptySendBtcResponse = BaseResponse.Ok(); var emptyGetLastResponse = new GetLastResponse(Enumerable.Empty <GetLastResponseDataElement>().ToList()); CaсheSendBtcResponse = JsonConvert.SerializeObject(emptySendBtcResponse); CaсheGetLastResponse = JsonConvert.SerializeObject(emptyGetLastResponse); var ipAddressForTcpListener = IPAddress.Parse(ipAddressCoreBitcoinService); Executor = excecutor; Servers = new Dictionary <string, TcpListener> { { "SendBtc", new TcpListener(ipAddressForTcpListener, portForSendBtc) }, { "GetLast", new TcpListener(ipAddressForTcpListener, portForGetLast) }, { "GetAddressForAccount", new TcpListener(ipAddressForTcpListener, portForGetAddressForAccount) }, }; OnDataProcessingActions = new Dictionary <string, Func <string, string> > { { "SendBtc", SendBtcOnDataProcessingAction }, { "GetLast", GetLastOnDataProcessingAction }, { "GetAddressForAccount", GetAddressForAccountOnDataProcessingAction }, }; Servers.Keys.ForEach(key => { Servers[key].Start(maxCountConnectionsForTcpListeners); Servers[key].BeginAcceptTcpClient(ServerBeginAcceptTcpClient, key); }); }