Пример #1
0
        public void CallbackFunction(Int32 nComport)
        {
            try
            {
                int iRet = -1;

                if (Opticon.csp2.DataAvailable(nComport) > 0)
                {
                    iRet   = Opticon.csp2.ReadData(nComport);
                    Status = 1;
                }
                else if (Opticon.csp2.GetDSR(nComport) > 0)
                {
                    Status = 1;
                    iRet   = Status = Opticon.csp2.Interrogate(nComport);
                }
                else
                {
                    Status = -1;
                }

                if (iRet >= 0)
                {
                    if (Ports.Contains(nComport) == false)
                    {
                        Ports.Add(nComport);
                    }
                }
                else
                {
                    if (Ports.Contains(nComport) == true)
                    {
                        Ports.Remove(nComport);
                    }
                }

                BeginInvoke((Action) delegate()
                {
                    if (Ports.Count > 0)
                    {
                        tb_ScannerStatus.Text = "Connected";
                    }
                    else
                    {
                        tb_ScannerStatus.Text = "Not Connected";
                        tb_ScannedItems.Text  = "";
                    }
                });

                if (iRet >= 0L)
                {
                    Int32 iCount = iRet;

                    ScannedItems = iCount;

                    BeginInvoke((Action) delegate()
                    {
                        tb_ScannedItems.Text = ScannedItems.ToString();
                    });
                }
                else
                {
                    ScannedItems = 0;
                }

                Comport = nComport;
                Thread.Sleep(225);
            }
            catch (Exception error)
            {
                Error err = new Error();
                err.ReportError(error.ToString());
            }
        }
Пример #2
0
        private async Task UpdateRepository(RPCClient client, DerivationSchemeTrackedSource trackedSource, Repository repo, ScanTxoutOutput[] outputs, ScannedItems scannedItems, ScanUTXOProgress progressObj)
        {
            var clientBatch      = client.PrepareBatch();
            var blockIdsByHeight = new ConcurrentDictionary <int, uint256>();
            await Task.WhenAll(outputs.Select(async o =>
            {
                blockIdsByHeight.TryAdd(o.Height, await clientBatch.GetBlockHashAsync(o.Height));
            }).Concat(new[] { clientBatch.SendBatchAsync() }).ToArray());

            var data = outputs
                       .GroupBy(o => o.Coin.Outpoint.Hash)
                       .Select(o => (Coins: o.Select(c => c.Coin).ToList(),
                                     BlockId: blockIdsByHeight.TryGet(o.First().Height),
                                     TxId: o.Select(c => c.Coin.Outpoint.Hash).FirstOrDefault(),
                                     KeyPathInformations: o.Select(c => scannedItems.KeyPathInformations[c.Coin.ScriptPubKey]).ToList()))
                       .Where(o => o.BlockId != null)
                       .Select(o =>
            {
                foreach (var keyInfo in o.KeyPathInformations)
                {
                    var index   = keyInfo.KeyPath.Indexes.Last();
                    var highest = progressObj.HighestKeyIndexFound[keyInfo.Feature];
                    if (highest == null || index > highest.Value)
                    {
                        progressObj.HighestKeyIndexFound[keyInfo.Feature] = (int)index;
                    }
                }
                return(o);
            }).ToList();

            var blockHeadersByBlockId = new ConcurrentDictionary <uint256, BlockHeader>();

            clientBatch = client.PrepareBatch();
            var gettingBlockHeaders = Task.WhenAll(data.Select(async o =>
            {
                blockHeadersByBlockId.TryAdd(o.BlockId, await clientBatch.GetBlockHeaderAsync(o.BlockId));
            }).Concat(new[] { clientBatch.SendBatchAsync() }).ToArray());
            await repo.SaveKeyInformations(scannedItems.
                                           KeyPathInformations.
                                           Select(p => p.Value).
                                           Where(p =>
            {
                var highest = progressObj.HighestKeyIndexFound[p.Feature];
                if (highest == null)
                {
                    return(false);
                }
                return(p.KeyPath.Indexes.Last() <= highest.Value);
            }).ToArray());

            await repo.UpdateAddressPool(trackedSource, progressObj.HighestKeyIndexFound);

            await          gettingBlockHeaders;
            DateTimeOffset now = DateTimeOffset.UtcNow;
            await repo.SaveMatches(data.Select(o => new TrackedTransaction(new TrackedTransactionKey(o.TxId, o.BlockId, true), trackedSource, o.Coins, o.KeyPathInformations)
            {
                Inserted = now,
                FirstSeen = blockHeadersByBlockId.TryGetValue(o.BlockId, out var header) && header != null ? header.BlockTime : NBitcoin.Utils.UnixTimeToDateTime(0)
            }).ToArray());
Пример #3
0
 public void resetForm()
 {
     SelectedSales = null;
     ScannedItems.Clear();
     ShipmentNumber = "";
 }