예제 #1
0
        private static async Task <ServiceResultDto[]> GetResultsAsync(ServiceIdentifierDto[] identifiers)
        {
            using (var repository = new ServiceProviderRepository())
            {
                var tasks = identifiers
                            .Select(async item =>
                {
                    try
                    {
                        var serviceMapping = await repository.GetAsync(it => it.Service.Name == item.Name &&
                                                                       it.Group == item.Group).ConfigureAwait(false);

                        var addr = new ServiceInfoDto
                        {
                            Name    = item.Name,
                            Group   = item.Group,
                            Address = serviceMapping.Address,
                            Data    = serviceMapping.Data,
                        };

                        var result = new ServiceResultDto
                        {
                            Identifier   = item,
                            ServiceInfos = new[] { addr }
                        };

                        return(result);
                    }
                    catch (Exception ex)
                    {
                        LogHelper.Error(ex);
                    }
                    return(null);
                })
                            .ToArray();

                await Task.WhenAll(tasks).ConfigureAwait(false);

                var results = tasks
                              .Select(it => it.Result)
                              .Where(it => it != null)
                              .ToArray();
                return(results);
            }
        }
예제 #2
0
		private static async Task<ServiceResultDto[]> GetResultsAsync(ServiceIdentifierDto[] identifiers)
		{
			using (var repository = new ServiceProviderRepository())
			{
				var tasks = identifiers
					.Select(async item =>
					{
						try
						{
							var serviceMapping = await repository.GetAsync(it => it.Service.Name == item.Name
								&& it.Group == item.Group).ConfigureAwait(false);

							var addr = new ServiceInfoDto
							{
								Name = item.Name,
								Group = item.Group,
								Address = serviceMapping.Address,
								Data = serviceMapping.Data,
							};

							var result = new ServiceResultDto
							{
								Identifier = item,
								ServiceInfos = new[] { addr }
							};

							return result;
						}
						catch (Exception ex)
						{
							LogHelper.Error(ex);
						}
						return null;
					})
					.ToArray();

				await Task.WhenAll(tasks).ConfigureAwait(false);

				var results = tasks
						.Select(it => it.Result)
						.Where(it => it != null)
						.ToArray();
				return results;
			}
		}