示例#1
0
        static void Main(string[] args)
        {
            SendPool.SendingStarted += SendPool_SendingStarted;
            SendPool.SendingCompleted += SendPool_SendingCompleted;
            SendPool.SendingCancelled += SendPool_SendingCancelled;

            for (int i = 0; i < 10; i++)
            {
                SqlConnectionStringBuilder builder = new SqlConnectionStringBuilder();
                builder.DataSource = "(local)";
                builder.IntegratedSecurity = true;
                builder.InitialCatalog = "IrisData";

                SqlServerDataSource dataSource = new SqlServerDataSource(builder.ConnectionString, "mailing");
                dataSource.Limit = 5000;

                DataSchema schema = new DataSchema();
                var names = new DataSchemaIterator("Names", 2);
                names.AddChild(new DataSchemaIteratorValue("Name", new List<DataSchemaIteratorValueMappedColumn>()
                {
                    new DataSchemaIteratorValueMappedColumn(new Dictionary<DataSchemaIterator, int>()
                    {
                        {names, 0}
                    }, "Name"),
                    new DataSchemaIteratorValueMappedColumn(new Dictionary<DataSchemaIterator, int>()
                    {
                        {names, 1}
                    }, "FirstName")
                }));

                schema.Root.AddChild(names);
                schema.Root.AddChild(new DataSchemaValue("id", "id"));

                TemplateMessage message = new TemplateMessage
                {
                    Subject = "Salut @Model.id",
                    Email = "*****@*****.**",
                    MailFrom = "*****@*****.**",
                    NameFrom = "Thib",
                    HtmlBody = "Hey ça va ?"
                };

                MaillingCommunication com = new MaillingCommunication(dataSource, message, schema);

                com.CompileTemplate();

                SendPool.SendCommunication(com);
            }

            while (true)
            {
                long s = 0;
                foreach (MaillingCommunication c in SendPool.ActiveCommunications)
                    s += c.CurrentSpeed;
                Console.WriteLine("Speed : " + s);
                Thread.Sleep(1000);
            }

            Console.ReadLine();
        }
 public MaillingCommunication(DataSourceBase dataSource, TemplateMessage message, DataSchema schema)
 {
     State = SendingState.Stopped;
     this.dataSource = dataSource;
     this.message = message;
     dataSchema = schema;
     sendResults = new ConcurrentBag<SendResult>();
     PostModifiers = new List<IModifier<MailMessage>>();
     PreModifiers = new List<IModifier<TemplateMessage>>();
 }
        public MaillingCommunication(DataSourceBase dataSource, TemplateMessage message, long maxSpeed, DataSchema schema)
        {
            if (maxSpeed < 0)
                throw new ArgumentOutOfRangeException("maxSpeed", maxSpeed, "Maximum speed must be positive");

            State = SendingState.Stopped;
            this.dataSource = dataSource;
            this.message = message;
            dataSchema = schema;
            MaxSendSpeed = maxSpeed;
            sendResults = new ConcurrentBag<SendResult>();
            PostModifiers = new List<IModifier<MailMessage>>();
            PreModifiers = new List<IModifier<TemplateMessage>>();
        }