Inheritance: MessageVisitorBase
Example #1
0
        private void Fixup(string srcPath, string dstPath)
        {
            Message message;
            var stats = new Statistics();
            var classifier = new MessageClassifier();
            var translator = new LiveMessageTranslator();

            using(var input = File.OpenRead(srcPath))
            using(var reader = new DecoratedObjectReader(input))
            using(var output = File.Create(dstPath))
            using(var writer = new DecoratedObjectWriter(output))
            {
                while(true)
                {
                    if((message = reader.Read<Message>()) == null)
                    {
                        break;
                    }
                    ++stats.Read;
                    if(classifier.IsTranslated(message))
                    {
                        ++stats.OrgTranslated;
                        continue;
                    }
                    writer.Write(message);
                    ++stats.Written;
                    if((message = translator.Translate(message)) != null)
                    {
                        if(message is CompositeMessage)
                        {
                            foreach(var component in ((CompositeMessage)message).Messages)
                            {
                                writer.Write(component);
                                ++stats.Written;
                                ++stats.NewTranslated;
                            }
                        }
                        else
                        {
                            writer.Write(message);
                            ++stats.Written;
                            ++stats.NewTranslated;
                        }
                    }
                }
                writer.Write(null);
            }

            stats.Print();
        }
        /// <summary>
        /// 
        /// </summary>        
        /// <param name="messageStreamEndpoint"></param>
        /// <param name="decrypterFactory"></param>
        public LiveMessageReader(IMessageStreamEndpoint messageStreamEndpoint,
            IDecrypterFactory decrypterFactory)
        {
            Guard.NotNull(messageStreamEndpoint, "messageStreamEndpoint");
            Guard.NotNull(decrypterFactory, "decrypterFactory");

            MessageStreamEndpoint = messageStreamEndpoint;
            DecrypterFactory = decrypterFactory;
            QueuedMessages = new Queue<Message>();
            SessionType = SessionType.None;
            State = LiveMessageReaderState.Uninitialised;
            StateEngine = new LiveMessageReaderStateEngine(this);
            MessageTranslator = new LiveMessageTranslator();
        }
 /// <summary>
 /// Initialises a new instance of the <see cref="LiveMessageTranslatorStateEngine"/> class
 /// and specified the <paramref name="translator"/> to update.
 /// </summary>
 /// <param name="translator">The translator to update.</param>
 public LiveMessageTranslatorStateEngine(LiveMessageTranslator translator)
 {
     Translator = translator;
 }