Example #1
0
        private static IDictionary <AnyVersionMessageIdentifier, DomainPrivateKey> CreateMessageMapping(IDictionary <string, DomainPrivateKey> domainKeys,
                                                                                                        IDomainScopeResolver domainScopeResolver)
        {
            var mappings     = new Dictionary <AnyVersionMessageIdentifier, DomainPrivateKey>();
            var domainScopes = domainScopeResolver.GetDomainMessages(domainKeys.Select(dk => dk.Key));

            foreach (var message in domainScopes.SelectMany(dm => dm.MessageIdentities,
                                                            (dm, id) => new
            {
                Identity = id,
                Domain = dm.Domain
            }))
            {
                if (domainKeys.TryGetValue(message.Domain, out var key))
                {
                    var messageIdentifier = new AnyVersionMessageIdentifier(message.Identity.GetBytes());
                    DomainPrivateKey _;
                    if (!mappings.TryGetValue(messageIdentifier, out _))
                    {
                        mappings.Add(messageIdentifier, key);
                    }
                    else
                    {
                        throw new Exception($"Message {message.Identity} is already mapped to Domain {_.Domain}!");
                    }
                }
                else
                {
                    throw new Exception($"PrivateKey for Domain {message.Domain} is not found!");
                }
            }

            return(mappings);
        }
Example #2
0
 private DomainPrivateKey FindDomain(AnyVersionMessageIdentifier identity)
 {
     if (messageToDomainMap.TryGetValue(identity, out var domain))
     {
         return(domain);
     }
     throw new MessageNotSupportedException(identity.ToString());
 }