Exemplo n.º 1
0
        public async Task <IDictionary <string, object> > Do(IDictionary <string, object> stepParameters, IDictionary <string, object> pluginParameters)
        {
            try
            {
                Log.Information($"Send {GetType().Name}...");

                LoadParametersAndContext(stepParameters, pluginParameters);
                // Get parameters
                stepParameters.TryGetTypedValue(SignalRConstants.ConnectionIdStore, out string[] connectionIds,
                                                obj => Convert.ToString(obj).Split(' '));

                // Generate necessary data
                var messageBlob = SignalRUtils.GenerateRandomData(MessageSize);

                // Reset counters
                UpdateStatistics(StatisticsCollector, RemainderEnd);

                // Send messages
                await Task.WhenAll(from i in Enumerable.Range(0, Connections.Count)
                                   let data = new Dictionary <string, object>
                {
                    { SignalRConstants.MessageBlob, messageBlob },                    // message payload
                    { SignalRConstants.ConnectionId, connectionIds[i] }
                }
                                   where ConnectionIndex[i] % Modulo >= RemainderBegin && ConnectionIndex[i] % Modulo < RemainderEnd
                                   select ContinuousSend((Connection: Connections[i],
                                                          LocalIndex: i,
                                                          CallbackMethod: SignalRConstants.SendToClientCallbackName),
                                                         data,
                                                         BaseSendAsync,
                                                         TimeSpan.FromMilliseconds(Duration),
                                                         TimeSpan.FromMilliseconds(Interval),
                                                         TimeSpan.FromMilliseconds(1),
                                                         TimeSpan.FromMilliseconds(Interval)));

                Log.Information($"Finish {GetType().Name} {RemainderEnd}");
                return(null);
            }
            catch (Exception ex)
            {
                var message = $"Fail to send to client: {ex}";
                Log.Error(message);
                throw;
            }
        }
Exemplo n.º 2
0
        protected override async Task <IDictionary <string, object> > SimpleScenarioSend(
            IDictionary <string, object> stepParameters,
            IDictionary <string, object> pluginParameters,
            string callbackMethod)
        {
            try
            {
                Log.Information($"Start {GetType().Name}...");

                LoadParametersAndContext(stepParameters, pluginParameters);

                // Generate necessary data
                var data = new Dictionary <string, object>
                {
                    { SignalRConstants.MessageBlob, SignalRUtils.GenerateRandomData(MessageSize) } // message payload
                };

                // Reset counters
                UpdateStatistics(StatisticsCollector, RemainderEnd);

                // Send messages
                await Task.WhenAll(from i in Enumerable.Range(0, Connections.Count)
                                   where ConnectionIndex[i] % Modulo >= RemainderBegin && ConnectionIndex[i] % Modulo < RemainderEnd
                                   select ContinuousSend((Connection: Connections[i],
                                                          LocalIndex: i,
                                                          CallbackMethod: callbackMethod,
                                                          StreamItemsCount,
                                                          StreamItemInterval),
                                                         data,
                                                         StreamingBaseSendAsync,
                                                         TimeSpan.FromMilliseconds(Duration),
                                                         TimeSpan.FromMilliseconds(Interval),
                                                         TimeSpan.FromMilliseconds(1),
                                                         TimeSpan.FromMilliseconds(Interval)));

                Log.Information($"Finish {GetType().Name} {RemainderEnd}");
                return(null);
            }
            catch (Exception ex)
            {
                var message = $"Fail to {GetType().Name}: {ex}";
                Log.Error(message);
                throw;
            }
        }
Exemplo n.º 3
0
        protected virtual IEnumerable <Package> GenerateData()
        {
            // Generate necessary data
            var messageBlob = SignalRUtils.GenerateRandomData(MessageSize);
            // TODO: for group count is larger than connections, we need to tune groupName parameters
            var packages = from i in Enumerable.Range(0, Connections.Count)
                           let groupName = SignalRUtils.GroupName(Type, ConnectionIndex[i] % GroupCount)
                                           select
                                           new Package
            {
                LocalIndex = i,
                Connection = Connections[i],
                GroupName  = groupName,
                Data       = new Dictionary <string, object>
                {
                    { SignalRConstants.MessageBlob, messageBlob },
                    { SignalRConstants.GroupName, groupName }
                }
            };

            return(packages);
        }
Exemplo n.º 4
0
        protected override IEnumerable <Package> GenerateData()
        {
            // Generate necessary data
            var messageBlob = SignalRUtils.GenerateRandomData(MessageSize);

            var packages = from i in Enumerable.Range(0, Connections.Count)
                           let groupName = SignalRUtils.GroupName(Type, ConnectionIndex[i] % GroupCount)
                                           select
                                           new Package
            {
                LocalIndex = i,
                Connection = Connections[i],
                GroupName  = groupName,
                Data       = new Dictionary <string, object>
                {
                    { SignalRConstants.MessageBlob, messageBlob },                    // message payload
                    { SignalRConstants.GroupName, groupName },
                    { _isIngroup, false }
                }
            };

            return(packages);
        }