Esempio n. 1
0
        public IEnumerable <IMessage> Deserialize(ISession session, byte[] data)
        {
            // preprocessing...
            byte[] buffer = this.encryptor.Decrypt(data);

            // let the factory create the messages
            var result = messageFactory.CreateMessages(data);

            foreach (var msg in result)
            {
                // postprocessing...
                msg.Owner = session;
            }

            return(result);
        }
        /// <summary>
        ///		Makes an attempt to get the message translations from cache
        ///		delegating its initial population to the factory.
        /// </summary>
        /// <exception cref="Datapoint.Globalization.MessageFactoryException">
        ///		Thrown when an unexpected error is encountered while creating
        ///		the repository population.
        ///	</exception>
        /// <param name="locale">
        ///		The locale to get the message translations for.
        /// </param>
        /// <param name="domain">
        ///		The domain to get the message translations for.
        /// </param>
        /// <returns>
        ///		The message translations, by message.
        /// </returns>
        private Dictionary <string, string> GetMessagesWithCache(ILocale locale, string domain)
        {
            if (!_messages.TryGetValue(locale, out var localeDomainsMessages))
            {
                _messages.Add
                (
                    locale,
                    localeDomainsMessages = new Dictionary <string, Dictionary <string, string> >()
                );
            }

            if (!localeDomainsMessages.TryGetValue(domain, out var localeDomainMessages))
            {
                var messages = new Dictionary <string, string>();

                try
                {
                    foreach (var message in _factory.CreateMessages(locale, domain))
                    {
                        if (!messages.TryAdd(message.Key, message.Value))
                        {
                            throw new Exception($"Message '{message.Key}' was created by the factory more than once.");
                        }
                    }
                }
                catch (Exception e)
                {
                    throw new MessageFactoryException
                          (
                              _factory,
                              "An exception was caught while trying to create the message repository population.",
                              e
                          );
                }

                localeDomainsMessages.Add
                (
                    domain,
                    localeDomainMessages = messages
                );
            }

            return(localeDomainMessages);
        }