コード例 #1
0
        private IEnumerable <Task <ServiceResponse> > GetServiceTasks(IEnumerable <ServiceInfo> services,
                                                                      string cacheRegion, CancellationToken cancellationToken,
                                                                      IEnumerable <KeyValuePair <string, string> > additionalParameters)
        {
            var taskList = new List <Task <ServiceResponse> >();

            foreach (ServiceInfo service in services)
            {
                Task <ServiceResponse> task = null;

                // ReSharper disable once PossibleMultipleEnumeration
                IEnumerable <KeyValuePair <string, string> > additionalParams = additionalParameters as KeyValuePair <string, string>[];
                if (additionalParams == null)
                {
                    if (additionalParameters != null)
                    {
                        // ReSharper disable once PossibleMultipleEnumeration
                        additionalParams = additionalParameters.ToArray();
                    }
                }

                switch (service)
                {
                case DynamicServiceInfo dynamicServiceInfo:
                {
                    task = _dynamicService.CallService(dynamicServiceInfo, cacheRegion, cancellationToken, additionalParams);
                    break;
                }

                case CachedServiceInfo cachedServiceInfo:
                    task = _cachedService.CallService(cachedServiceInfo, cacheRegion, cancellationToken, additionalParams);
                    break;

                case StaticServiceInfo staticServiceInfo:
                    task = _staticService.CallService(staticServiceInfo, cacheRegion, cancellationToken, additionalParams);
                    break;
                }

                if (task != null)
                {
                    taskList.Add(task);
                }
            }

            return(taskList);
        }