/
vshmidt
/
masstransit
Обзор
Документация
Войти
/
vshmidt
/
masstransit
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
develop
src/Persistence/MassTransit.MongoDbIntegration/MongoDbIntegration/MessageData/MessageDataResolver.cs
34 строки
1 KB
Chris Patterson
Integration of all external packages into MassTransit, split out into Abstractions, Middleware, and the core MassTransit assembly.
22 янв 2022, 18:24
22 янв 2022, 18:24
b5b4f50
Код
Авторство
О чём код?
namespace MassTransit.MongoDbIntegration.MessageData { using System; using MongoDB.Bson; public class MessageDataResolver : IMessageDataResolver { const string Scheme = "urn"; const string System = "mongodb"; const string Specification = "gridfs"; readonly string _format = string.Join(":", Scheme, System, Specification); public ObjectId GetObjectId(Uri address) { if (address.Scheme != Scheme) throw new UriFormatException($"The scheme did not match the expected value: {Scheme}"); string[] tokens = address.AbsolutePath.Split(':'); if (tokens.Length != 3 || !address.AbsoluteUri.StartsWith($"{_format}:")) throw new UriFormatException($"Urn is not in the correct format. Use '{_format}:{{resourceId}}'"); return ObjectId.Parse(tokens[2]); } public Uri GetAddress(ObjectId id) { return new Uri($"{_format}:{id}"); } } }