Пример #1
0
            public void PlayEmailAutomation()
            {
                retValue = new StringBuilder("--------Start--------\r\n\r\n");
                int countMail = 0;

                ((ITraceable)client).LogTrace += new TraceEventHandler(TraceLog);

                ProgressValueChangeEventArgs pvce = new ProgressValueChangeEventArgs()
                {
                    MinValue = 0, MaxValue = 4
                };
                StatusChangeEventArgs sce = new StatusChangeEventArgs()
                {
                    CurrentStatus = "Connecting " + client.GetHostName() + "...", PreviousStatus = "--------Start--------"
                };

                OnStatusChanged(sce);

                var result = client.Login(username, password);

                if (string.IsNullOrEmpty(result))
                {
                    pvce.Value = 1;

                    OnProgressValueChanged(pvce);

                    sce.CurrentStatus  = "Authenticating client...";
                    sce.PreviousStatus = retValue.ToString();

                    OnStatusChanged(sce);

                    pvce.Value = 2;

                    OnProgressValueChanged(pvce);

                    sce.CurrentStatus  = "Selecting Inbox...";
                    sce.PreviousStatus = retValue.ToString();

                    OnStatusChanged(sce);

                    if (string.IsNullOrEmpty(result))
                    {
                        pvce.Value = 3;

                        OnProgressValueChanged(pvce);

                        sce.CurrentStatus  = "Getting total mail from Inbox...";
                        sce.PreviousStatus = retValue.ToString();

                        OnStatusChanged(sce);

                        result = client.GetTotalMail(out countMail);

                        if (string.IsNullOrEmpty(result))
                        {
                            if (countMail > 0)
                            {
                                sce.CurrentStatus  = "Getting mail detail from Inbox...";
                                sce.PreviousStatus = retValue.ToString();

                                OnStatusChanged(sce);

                                IEnumerable <int> msgIds = null;

                                result = client.GetAllMessageFlags(MailFlag.All, out msgIds);

                                if (!string.IsNullOrEmpty(result))
                                {
                                    TerminateEmailAutomation("Problem in getting mail(s).", retValue.ToString());
                                }
                            }

                            pvce.Value = 4;

                            OnProgressValueChanged(pvce);

                            sce.CurrentStatus  = "Logout from Inbox...";
                            sce.PreviousStatus = retValue.ToString();

                            OnStatusChanged(sce);

                            client.LogOut();

                            sce.CurrentStatus  = "Logout completed...";
                            sce.PreviousStatus = retValue.ToString();

                            OnStatusChanged(sce);
                        }
                        else
                        {
                            TerminateEmailAutomation("Problem in getting mail count.", retValue.ToString());
                        }
                    }
                    else
                    {
                        TerminateEmailAutomation("Problem in getting mail count.", retValue.ToString());
                    }

                    ((IDisposable)client).Dispose();
                    ((ITraceable)client).LogTrace -= new TraceEventHandler(TraceLog);
                }
            }