Пример #1
0
        public async Task <IDictionary <string, object> > Do(
            IDictionary <string, object> stepParameters,
            IDictionary <string, object> pluginParameters)
        {
            try
            {
                Log.Information($"Join groups...");

                // Get parameters
                stepParameters.TryGetTypedValue(SignalRConstants.Type,
                                                out _type, Convert.ToString);
                stepParameters.TryGetTypedValue(SignalRConstants.GroupCount,
                                                out _groupCount, Convert.ToInt32);
                stepParameters.TryGetTypedValue(SignalRConstants.ConnectionTotal,
                                                out _totalConnection, Convert.ToInt32);

                if (_totalConnection % _groupCount != 0)
                {
                    //throw new Exception("Not supported: Total connections cannot be divided by group count");
                    Log.Warning($"groups do not have equal members because total connections {_totalConnection} cannot be divided by group count {_groupCount}");
                }

                SignalRUtils.SaveGroupInfoToContext(pluginParameters, _type, _groupCount, _totalConnection);
                // Get context
                pluginParameters.TryGetTypedValue($"{SignalRConstants.ConnectionStore}.{_type}",
                                                  out _connections, (obj) => (IList <IHubConnectionAdapter>)obj);
                pluginParameters.TryGetTypedValue($"{SignalRConstants.StatisticsStore}.{_type}",
                                                  out _statisticsCollector, obj => (StatisticsCollector)obj);
                pluginParameters.TryGetTypedValue($"{SignalRConstants.ConnectionIndex}.{_type}",
                                                  out _connectionIndex, (obj) => (List <int>)obj);

                // Reset counters
                SignalRUtils.ResetCounters(_statisticsCollector);
                // Join group
                var connectionType = SignalRUtils.GetClientTypeFromContext(pluginParameters, _type);
                if (connectionType == SignalREnums.ClientType.DirectConnect)
                {
                    var connectionString = SignalRUtils.FetchConnectionStringFromContext(pluginParameters, _type);
                    await DirectConnectionJoinGroup(connectionString);
                }
                else
                {
                    await NormalConnectionJoinGroup();
                }
                return(null);
            }
            catch (Exception ex)
            {
                var message = $"Fail to join group: {ex}";
                Log.Error(message);
                throw;
            }
        }
Пример #2
0
        public async Task <IDictionary <string, object> > Do(
            IDictionary <string, object> stepParameters,
            IDictionary <string, object> pluginParameters)
        {
            try
            {
                Log.Information($"Leave groups...");

                // Get parameters
                stepParameters.TryGetTypedValue(SignalRConstants.Type, out _type, Convert.ToString);
                stepParameters.TryGetTypedValue(SignalRConstants.GroupCount, out _groupCount, Convert.ToInt32);
                stepParameters.TryGetTypedValue(SignalRConstants.ConnectionTotal, out int totalConnection, Convert.ToInt32);

                if (totalConnection % _groupCount != 0)
                {
                    throw new Exception("Not supported: Total connections cannot be divided by group count");
                }

                // Get context
                pluginParameters.TryGetTypedValue($"{SignalRConstants.ConnectionStore}.{_type}",
                                                  out _connections, (obj) => (IList <IHubConnectionAdapter>)obj);
                pluginParameters.TryGetTypedValue($"{SignalRConstants.StatisticsStore}.{_type}",
                                                  out _statisticsCollector, obj => (StatisticsCollector)obj);
                pluginParameters.TryGetTypedValue($"{SignalRConstants.ConnectionIndex}.{_type}",
                                                  out _connectionIndex, (obj) => (List <int>)obj);

                // Not reset counters because typically this step is followed the last sending step.
                // We do not want to clear the last sending step's sending statistics
                // Leave group
                var connectionType = SignalRUtils.GetClientTypeFromContext(pluginParameters, _type);
                if (connectionType == SignalREnums.ClientType.DirectConnect)
                {
                    var connectionString = SignalRUtils.FetchConnectionStringFromContext(pluginParameters, _type);
                    await DirectConnectionLeaveGroup(connectionString);
                }
                else
                {
                    await NormalConnectionLeaveGroup();
                }
                return(null);
            }
            catch (Exception ex)
            {
                var message = $"Fail to leave group: {ex}";
                Log.Error(message);
                throw;
            }
        }