public Task <IDictionary <string, object> > Do( IDictionary <string, object> stepParameters, IDictionary <string, object> pluginParameters) { stepParameters.TryGetTypedValue(SignalRConstants.Type, out string type, Convert.ToString); pluginParameters.TryGetTypedValue($"{SignalRConstants.ConnectionStore}.{type}", out IList <IHubConnectionAdapter> connections, (obj) => (IList <IHubConnectionAdapter>)obj); if (stepParameters.TryGetValue(SignalRConstants.ActionAfterConnect, out _)) { stepParameters.TryGetTypedValue(SignalRConstants.ActionAfterConnect, out string postAction, Convert.ToString); if (Enum.TryParse(postAction, out SignalREnums.ActionAfterConnection action)) { _action = action; } } _concurrentConnection = SignalRUtils.FetchConcurrentConnectionCountFromContext( pluginParameters, type, connections.Count); _type = type; // register the CTS to control the connector repairer. var cts = new CancellationTokenSource(); pluginParameters[$"{SignalRConstants.RepairConnectionCTS}.{type}"] = cts; _context = pluginParameters; _ = Task.Run(async() => { try { await Start(connections, cts); } catch (Exception e) { Log.Error($"Fail to repair the connection: {e.Message}"); } }); return(Task.FromResult <IDictionary <string, object> >(null));; }
public async Task <IDictionary <string, object> > Do( IDictionary <string, object> stepParameters, IDictionary <string, object> pluginParameters) { try { Log.Information($"Collect connection ID..."); // Get parameters stepParameters.TryGetTypedValue(SignalRConstants.Type, out string type, Convert.ToString); pluginParameters.TryGetTypedValue($"{SignalRConstants.ConnectionStore}.{type}", out IList <IHubConnectionAdapter> connections, (obj) => (IList <IHubConnectionAdapter>)obj); // Init the connection Id list var connectionIdList = new List <string>(); for (var m = 0; m < connections.Count; m++) { connectionIdList.Add(""); } var connIdStoreKey = $"{SignalRConstants.ConnectionIdStore}.{type}"; /* * if (pluginParameters.TryGetValue(connIdStoreKey, out object v)) * { * // check whether need re-get connection Ids * var allConnIds = (Dictionary<string, object>)v; * var existingConnIdList = (string[])allConnIds[SignalRConstants.ConnectionId]; * var hasMissingConnectionId = false; * foreach (var connId in existingConnIdList) * { * if (String.IsNullOrEmpty(connId)) * { * hasMissingConnectionId = true; * } * } * * if (!hasMissingConnectionId) * { * // all connection Ids are ready * Log.Information("No missing connection Ids, skip try-re-get connection Ids"); * return allConnIds; * } * else * { * // prepare re-get missing connection Ids * for (var m = 0; m < existingConnIdList.Length; m++) * { * connectionIdList[m] = existingConnIdList[m]; * } * } * } */ // get connection Ids int concurrentConnection = SignalRUtils.FetchConcurrentConnectionCountFromContext( pluginParameters, type, connections.Count); await SendRequestToGetConnectionIds(connections, concurrentConnection, connectionIdList); var connectionIdDic = new Dictionary <string, object> { { SignalRConstants.ConnectionId, connectionIdList.ToArray() } }; pluginParameters[connIdStoreKey] = connectionIdDic; return(connectionIdDic); } catch (Exception ex) { var message = $"Fail to collect connection ID: {ex}"; Log.Error(message); throw; } }