/// <summary> /// Метод для получения экземпляра одного из классов для отправки сообщений в зависимости от подписки. /// </summary> /// <param name="subscription">Подписка, тип которой определяет класс для отправки. Кроме этого, из подписки берется клиент.</param> /// <returns>Экземпляр класса для отправки сообщений.</returns> private static IMessageSender GetMessageSender(Subscription subscription, ILogger logger) { IMessageSender result; switch (subscription.TransportType) { case TransportType.HTTP: result = new HttpMessageSender(subscription.Client, logger); break; case TransportType.MAIL: result = new MailMessageSender(subscription.Client, logger); break; case TransportType.WCF: result = new WcfMessageSender(subscription.Client, logger); break; case TransportType.WEB: result = new WebMessageSender(subscription.Client, logger); break; default: throw new ArgumentException("Неизвестный способ отправки сообщения."); } return(result); }
public async Task <HttpResponseMessage> AddDir(string path) { var newFolder = new Common.NewFolder() { Path = path, Name = "New Folder" }; return(await HttpMessageSender.AddFolder(newFolder, _endpoint)); }
public static void AddMessageQueue(this IServiceCollection services, IConfiguration configuration) { // TODO: использовать конфиг var retry = new PeriodicRetryStrategy(1000); var httpService = new HttpMessageSender <StringMessage>(@"https://localhost:44342/api/secure/incomingmessages"); var retryService = new RetryMessageQueue <StringMessage>(retry, httpService); var backup = new FileSystemFileStorage <StringMessage>(); services.Add(ServiceDescriptor.Singleton(typeof(IMessageQueue <StringMessage>), new BackedUpMessageQueue <StringMessage>(backup, retryService))); }
public void Should_throw_timeout_exception_if_operation_cancelled( CastleConfiguration configuration, HttpMessageHandler handler) { var logger = Substitute.For <IInternalLogger>(); var sut = new HttpMessageSender(configuration, logger, handler); foreach (var testMethod in TestMethods) { Func <Task> act = async() => await testMethod(sut); act.Should().Throw <CastleTimeoutException>(); } }
public async Task Should_return_response_if_success_code( CastleConfiguration configuration, HttpMessageHandler handler) { var logger = Substitute.For <IInternalLogger>(); var sut = new HttpMessageSender(configuration, logger, handler); foreach (var testMethod in TestMethods) { var result = await testMethod(sut); result.Should().BeOfType <VoidResponse>(); } }
public async Task Should_log_response_message( CastleConfiguration configuration, HttpMessageHandler handler) { var logger = Substitute.For <IInternalLogger>(); var sut = new HttpMessageSender(configuration, logger, handler); foreach (var testMethod in TestMethods) { var result = await testMethod(sut); logger .Received() .Info(Arg.Is <Func <string> >(func => func() .StartsWith("Response"))); } }
public async Task <HttpResponseMessage> DeleteDir(Common.Folder folder) { var deleteUri = _endpoint + "delete"; return(await HttpMessageSender.DeleteDir(folder, deleteUri)); }
public Common.Folder GetFilesAndDirs() { return(HttpMessageSender.GetMyFilesAndDirs(_endpoint)); }
public async Task <IDownloadedFile> GetFile(Common.FileInfo file) { return(await HttpMessageSender.GetFile(file, _endPoint + "get")); }
public async Task <HttpResponseMessage> DeleteFile(Common.FileInfo file) { return(await HttpMessageSender.DeleteFile(file, _endPoint + "delete")); }