public override bool Equals(object other) { var mapField = other as MapField <TKey, TValue>; if (mapField != null) { return(_internal.Equals(mapField)); } var eventMap = other as EventMapField <TKey, TValue>; if (eventMap != null) { return(eventMap.Equals(_internal)); } return(false); }
// This method is called frequently from the KEDA runtime. It is supposed to create and prepare all the resources required // for the GetMetrics service method to be succesful. // Here we create the irc channel client, and we keep it for the lifetime of the scaler. // Ideally, there should be a separate client for every different metric, but we currently we support one. We will change this soon. public override Task <Empty> New(NewRequest request, ServerCallContext context) { _logger.LogInformation($"{DateTime.Now} New Is Called, the problem is between the screen and the chair!"); if (_metricMetadata != null && !_metricMetadata.Equals(request.Metadata)) { _logger.LogInformation($"the _metricMetadata: {_metricMetadata} is not equal to request.Metadata: {request.Metadata}"); } //If this is the first time New is called, or the metadata has changed if (_metricMetadata == null || !_metricMetadata.Equals(request.Metadata)) { var accessToken = request.Metadata["accessToken"]; var twitchUserName = request.Metadata["twitchUserName"]; var channelName = request.Metadata["channelName"]; _logger.LogInformation($"kaboom scaler new: twitchname:{twitchUserName}, channelName:{channelName}"); ConnectionCredentials credentials = new ConnectionCredentials(twitchUserName, accessToken); var clientOptions = new ClientOptions { MessagesAllowedInPeriod = 750, ThrottlingPeriod = TimeSpan.FromSeconds(30) }; WebSocketClient customClient = new WebSocketClient(clientOptions); _client = new TwitchClient(customClient); _client.Initialize(credentials, channelName); _client.OnMessageReceived += Client_OnMessageReceived; _client.OnLog += Client_OnLog; _client.Connect(); //Save the metadata so that we can compare it the the request next time to see if it changed. _metricMetadata = request.Metadata; } return(Task.FromResult(new Empty())); }