Ejemplo n.º 1
0
            public Task SendAsync(IEnumerable <EventData> eventDataBatch, string partitionKey, CancellationToken cancellationToken)
            {
                if (_client == null)
                {
                    throw new InvalidOperationException("EventHubClient has not been initialized");
                }

                Azure.Messaging.EventHubs.Producer.SendEventOptions sendEventOptions = null;
                if (!string.IsNullOrEmpty(partitionKey))
                {
                    if (!_partitionKeys.TryGetValue(partitionKey, out sendEventOptions))
                    {
                        sendEventOptions = new Azure.Messaging.EventHubs.Producer.SendEventOptions()
                        {
                            PartitionKey = partitionKey
                        };
                        _partitionKeys.TryAdd(partitionKey, sendEventOptions);
                    }
                }

                if (sendEventOptions != null)
                {
                    return(_client.SendAsync(eventDataBatch, sendEventOptions, cancellationToken));
                }
                else
                {
                    return(_client.SendAsync(eventDataBatch, cancellationToken));
                }
            }
Ejemplo n.º 2
0
    /// <summary>
    /// Subscribe to a WAMP topic.
    /// </summary>
    /// <param name="topic">The topic to which subscribe.</param>
    /// <param name="options">The options the subscription.</param>
    /// <param name="publishEvent">The delegate function to call when the topic is published.</param>
    /// <param name="timeout">The maximum timeout in milliseconds for the function to execute. Will raise Waapi.TimeoutException when timeout is reached.</param>
    /// <returns>Subscription id, that you can use to unsubscribe.</returns>
    internal async System.Threading.Tasks.Task <uint> Subscribe(string topic, string options, PublishHandler publishEvent, int timeout)
    {
        int requestId = ++currentRequestId;

        // [SUBSCRIBE, Request|id, Options|dict, Topic|uri]
        await Send($"[{(int)Messages.SUBSCRIBE},{requestId},{options},\"{topic}\"]", timeout);

        // Should receive the SUBSCRIBED or ERROR
        Response response = await ReceiveExpect(Messages.SUBSCRIBED, requestId, timeout);

        subscriptions.TryAdd(response.SubscriptionId, publishEvent);
        return(response.SubscriptionId);
    }
Ejemplo n.º 3
0
    void TestConcurrentSpeed()
    {
        var a = new object[100];

        for (int i = 0; i < a.Length; i++)
        {
            a[i] = new object();
        }

        perf.cpu();
        for (int i1 = 0; i1 < 7; i1++)
        {
            int n2 = a.Length;
            perf.first();
            for (int i2 = 0; i2 < n2; i2++)
            {
                hs.Add(a[i2]);
            }
            for (int i2 = 0; i2 < n2; i2++)
            {
                hs.Remove(a[i2]);
            }
            perf.next();
            for (int i2 = 0; i2 < n2; i2++)
            {
                lock (hs2) hs2.Add(a[i2]);
            }                                                                          //20% slower
            for (int i2 = 0; i2 < n2; i2++)
            {
                lock (hs2) hs2.Remove(a[i2]);
            }
            perf.next();
            for (int i2 = 0; i2 < n2; i2++)
            {
                cd.TryAdd(a[i2], default);
            }                                                                          //50% slower
            for (int i2 = 0; i2 < n2; i2++)
            {
                cd.TryRemove(a[i2], out _);
            }
            perf.next();
            for (int i2 = 0; i2 < n2; i2++)
            {
                var gc = GCHandle.Alloc(a[i2]); gc.Free();
            }                                                                                          //50% faster
            perf.nw();
            Thread.Sleep(100);
        }
    }
Ejemplo n.º 4
0
 static Symbol.Collections.Generic.NameValueCollection <string> GetValues(ICustomAttributeProvider provider)
 {
     Symbol.Collections.Generic.NameValueCollection <string> list;
     if (!_list.TryGetValue(provider, out list))
     {
         ThreadHelper.Block(_list, () => {
             if (!_list.TryGetValue(provider, out list))
             {
                 list = new Symbol.Collections.Generic.NameValueCollection <string>(StringComparer.OrdinalIgnoreCase);
                 GetValues(provider, list, true);
                 _list.TryAdd(provider, list);
             }
         });
     }
     return(list);
 }
Ejemplo n.º 5
0
        /// <summary>
        /// Gets the Inserts into tables if selectSqlCondition(such as 'select 1 from student where name=@name') has no record SQL.
        /// </summary>
        public static SqlBatch GetInsertIfNotExistSql <T>(this IDataHelper dh, T model, string selectSqlCondition, params Params[] paramKeyAndValue)
        {
            var type                = typeof(T);
            var tableName           = AttributeHelper.GetTableName(type, true, dh.Driver.SafeName);
            var columnNameDic       = AttributeHelper.GetProp2ColumnNameDics(dh.Driver.DirverType, type);
            var insertColumnsValues = ReflectHelper.GetPropertyValues(type, model, false, true, true);

            Collections.Concurrent.ConcurrentDictionary <string, object> columnValueDic = new Collections.Concurrent.ConcurrentDictionary <string, object>();
            foreach (var item in insertColumnsValues)
            {
                if (columnNameDic.ContainsKey(item.Key))
                {
                    columnValueDic.TryAdd(columnNameDic[item.Key], item.Value);
                }
            }
            var insertColumns = columnValueDic.Keys.ToList();

            return(dh.Driver.GetInsertIfNotExistSql(tableName, insertColumns, columnValueDic, selectSqlCondition, paramKeyAndValue));
        }
Ejemplo n.º 6
0
    void UpdateUIPanel()
    {
        while (ShallRun)
        {
            ulong newBlockNumber = GetCurrentBlockNumber();
            UpdateBalances();
            if (StartBlockNumber == 0)
            {
                StartBlockNumber         = newBlockNumber;
                LastBlockNumberProcessed = newBlockNumber;
            }

            //Web3.Eth.Blocks.GetBlockNumber();
            if (newBlockNumber > LastBlockNumber)
            {
                var blockNumber = new Nethereum.Hex.HexTypes.HexBigInteger(new BigInteger(newBlockNumber));

                var blockTask = Web3.Eth.Blocks.GetBlockWithTransactionsByNumber.SendRequestAsync(blockNumber);
                blockTask.Wait();
                var block = blockTask.Result;

                BlockDetails blockDetails = new BlockDetails();
                blockDetails.BlockInfo = block;

                StringBuilder txInfos = new StringBuilder();
                txInfos.AppendLine(newBlockNumber.ToString());
                txInfos.AppendLine(block.BlockHash);

                List <Task <TransactionReceipt> > transactionReceiptTasks = new List <Task <TransactionReceipt> >();
                foreach (var tx in block.Transactions)
                {
                    //TODO: maybe just pick up transaction that point to one of our contracts ? see mapping ContractMappingAddressToName

                    txInfos.AppendLine(" - " + tx.TransactionHash);
                    //tx.TransactionHash;
                    //tx.
                    //tx.

                    Task <TransactionReceipt> receiptTask = Web3.Eth.TransactionManager.TransactionReceiptService.PollForReceiptAsync(tx.TransactionHash);
                    //receiptTask.Start();
                    transactionReceiptTasks.Add(receiptTask);
                }

                TimeSpan timeout = TimeSpan.FromSeconds(10);
                foreach (var task in transactionReceiptTasks)
                {
                    task.Wait(timeout);
                    TransactionDetails details = new TransactionDetails();
                    if (task.IsCompleted)
                    {
                        details.TransactionReceipt = task.Result;

                        if (!string.IsNullOrEmpty(details.TransactionReceipt.ContractAddress) && ContractMappingAddressToName.ContainsKey(details.TransactionReceipt.ContractAddress))
                        {
                            details.ContractName = ContractMappingAddressToName[details.TransactionReceipt.ContractAddress];
                        }

                        AddEventsFromReceipt(details.TransactionReceipt, details.FishEvents, details.AllEvents);
                        AddEventsFromReceipt(details.TransactionReceipt, details.LandEvents, details.AllEvents);
                        AddEventsFromReceipt(details.TransactionReceipt, details.LandOwner, details.AllEvents);
                        AddEventsFromReceipt(details.TransactionReceipt, details.DoggerWasBuild, details.AllEvents);
                        // AddEventsFromReceipt(details.TransactionReceipt, details.TimberMintEvents, details.AllEvents);
                        // AddEventsFromReceipt(details.TransactionReceipt, details.CopperMintEvents , details.AllEvents);



                        LatestTransactionInformations.TryAdd(details.TransactionReceipt.TransactionHash, details);
                        blockDetails.TransactionDetails.Add(details);
                    }
                    else
                    {
                        if (task.IsCanceled)
                        {
                            Debug.LogWarning("Receiving Transaction details was cancelled");
                        }

                        if (task.IsFaulted)
                        {
                            Debug.LogWarning("Receiving Transaction details Rand into an Error.");
                        }
                    }

                    //var fishEvents = details.TransactionReceipt.DecodeAllEvents<Galleass3D.Contracts.Bay.ContractDefinition.FishEventDTO>();
                    //details.
                    //task.Result
                }

                LatestBlockInformation = txInfos.ToString();

                if (!LatestBlockDetails.TryAdd(newBlockNumber, blockDetails))
                {
                    Debug.LogError("Could not add Block #" + newBlockNumber);
                }

                LastBlockNumber = newBlockNumber;
                //block.Result.Transactions
            }

            System.Threading.Thread.Sleep(BlockTimeMs);
        }
    }