/// <summary>
        /// Initialize the aggregator host by loading the appropriate assembly as specified by the config
        /// </summary>
        /// <param name="config">Configuration string</param>
        public void InitializeHost(string config)
        {
            MASShared masShared      = new MASShared();
            string    aggregatorType = masShared.GetAggregatorTypeFromConfig(config);

            magsource = masShared.GetMASAssembly(aggregatorType);
            if (magsource == null)
            {
                RaiseAggregatorHostError(string.Format("Mail aggregator with type '{0}' could not be found!", aggregatorType));
            }
            else
            {
                magsource.AggregatorError   += new RaiseMessageDelegate(magsource_AggregatorError);
                magsource.AggregatorWarning += new RaiseMessageDelegate(magsource_AggregatorWarning);
                if (Properties.Settings.Default.MessageBodyTemplate != null || Properties.Settings.Default.MessageBodyTemplate.Length > 0)
                {
                    magsource.MessageBodyTemplate = Properties.Settings.Default.MessageBodyTemplate;
                }
                if (Properties.Settings.Default.MessageSeparatorTemplate != null || Properties.Settings.Default.MessageSeparatorTemplate.Length > 0)
                {
                    magsource.MessageSeparatorTemplate = Properties.Settings.Default.MessageSeparatorTemplate;
                }

                if (!magsource.SetConfig(config))
                {
                    RaiseAggregatorHostError(string.Format("An error occured while configuring the aggregator with config {0}\r\n(1}", config, magsource.LastError));
                    magsource = null;
                }
            }
        }
Exemplo n.º 2
0
        static void Main(string[] args)
        {
            MASShared masShared = new MASShared();

            foreach (var sourceConfig in Properties.Settings.Default.AggrSources)
            {
                string aggregatorType = masShared.GetAggregatorTypeFromConfig(sourceConfig);

                if (aggregatorType.Length > 0)
                {
                    IMailAggregatorSource magsource = masShared.GetMASAssembly(aggregatorType);
                    if (magsource == null)
                    {
                        Console.WriteLine("Mail aggregator with type '{0}' could not be found!", aggregatorType);
                    }
                    else
                    {
                        magsource.AggregatorError += new RaiseMessageDelegate(magsource_AggregatorError);
                        magsource.SetConfig(sourceConfig);
                        foreach (MailAggregatedMessage msg in magsource.GetMessages())
                        {
                            Console.WriteLine("To:" + msg.ToAddress);
                            Console.WriteLine("Subject:" + msg.Subject + (msg.MsgRepeatCounter > 1 ? " (" + msg.MsgRepeatCounter.ToString() + ")" : ""));
                            Console.WriteLine(msg.Body.Length);
                            Console.WriteLine(">---------------");
                        }
                    }
                }
            }

            //foreach (var sourceConfig in Properties.Settings.Default.AggrSources)
            //{
            //    IMailAggregatorSource magsource = null;
            //    if (sourceConfig.Contains("FlatFile"))
            //    {
            //        magsource = new MailAggregatorFFSource();
            //        magsource.AggregatorError += new RaiseMessageDelegate(magsource_AggregatorError);
            //    }

            //    if (magsource != null)
            //    {
            //        magsource.SetConfig(sourceConfig);
            //        foreach (MailAggregatedMessage msg in magsource.GetMessages())
            //        {
            //            Console.WriteLine("To:" + msg.ToAddress);
            //            Console.WriteLine("Subject:" + msg.Subject + (msg.MsgRepeatCounter > 1 ? " (" + msg.MsgRepeatCounter.ToString() + ")" : ""));
            //            Console.WriteLine(msg.Body.Length);
            //            Console.WriteLine(">---------------");
            //        }
            //    }
            //}
            Console.WriteLine("Done");
            Console.ReadKey();
        }