public ActionResult GetAllMailbox(BackupModel model)
        {
            var mailbox = model.BackupUserMailAddress;
            var password = RSAUtil.AsymmetricDecrypt(model.EncryptPassword);
            var organization = model.BackupUserOrganization;
            using (ICatalogService service = CatalogFactory.Instance.NewCatalogService(mailbox, password, null, organization))
            {
                var allMailboxes = service.GetAllUserMailbox();

                List<Item> infos = new List<Item>(allMailboxes.Count);
                IMailboxData loginMailbox = null;
                IMailboxData adminMailbox = null;
                var loginUserName = User.Identity.GetUserName().ToLower();
                var adminMailAddress = mailbox.ToLower();
                foreach (var data in allMailboxes)
                {
                    var temp = data.MailAddress.ToLower();
                    if (temp == loginUserName)
                    {
                        loginMailbox = data;
                    }
                    else if (temp == adminMailAddress)
                    {
                        adminMailbox = data;
                    }
                    else if (temp == "*****@*****.**" || temp == "*****@*****.**" || temp == "*****@*****.**" || temp == "*****@*****.**")
                    {
                        AddToResult(data, infos, 0);
                    }
                    else if(temp.IndexOf("arcserve.com") < 0)
                    {
                        AddToResult(data, infos, 0);
                    }
                    else
                    {
                        AddToResult(data, infos);
                    }
                }

                if (adminMailbox != null)
                {
                    AddToResult(adminMailbox, infos, 0);
                }

                if (loginMailbox != null)
                {
                    AddToResult(loginMailbox, infos, 0);
                }

                return Json(new { Details = infos });
            }
        }
        public ActionResult Index(BackupModel model)
        {
            if (ModelState.IsValid)
            {

                model.Index++;
                if (model.Index == 3)
                    return Run(model);

                if (model.Index == 1)
                {
                    IEwsAdapter mailboxOper = CatalogFactory.Instance.NewEwsAdapter();
                    EwsServiceArgument argument = new EwsServiceArgument();
                    var password = RSAUtil.AsymmetricDecrypt(model.EncryptPassword);
                    argument.ServiceCredential = new System.Net.NetworkCredential(model.BackupUserMailAddress, password);
                    argument.UseDefaultCredentials = false;
                    argument.SetConnectMailbox(model.BackupUserMailAddress);
                    mailboxOper.ConnectMailbox(argument, model.BackupUserMailAddress);
                    return Json(model);
                }
            }

            return Json(model);
        }
        public JsonResult Run(BackupModel model)
        {
            if (ModelState.IsValid)
            {
                if (!JobProgressManager.Instance.CanStartNewCatalog())
                    return Json(new { HasError = true, Msg = "Can't start Job.", Index = model.Index });

                JavaScriptSerializer js = new JavaScriptSerializer();
                LoadedTreeItem selectedItem = js.Deserialize<LoadedTreeItem>(model.BackupSelectItems);

                using(StreamWriter writer = new StreamWriter(@"D:\21GitHub\Haiyang\EWS\Office365Demo\ExGrtAzure\LoginTest\bin\OneMailboxFull.txt"))
                {
                    writer.WriteLine(model.BackupSelectItems);
                }

                // todo need use job table to save job status.
                var password = RSAUtil.AsymmetricDecrypt(model.EncryptPassword);
                var service = CatalogFactory.Instance.NewCatalogService(model.BackupUserMailAddress, password, null, model.BackupUserOrganization);

                service.CatalogJobName = model.BackupJobName;
                IFilterItem filterObj = CatalogFactory.Instance.NewFilterItemBySelectTree(selectedItem);
                var serviceId = Guid.NewGuid();
                JobProgressManager.Instance[serviceId] = (IDataProtectProgress)service;
                ThreadPool.QueueUserWorkItem(ThreadBackup, new CatalogArgs() { Service = service, FilterItem = filterObj });

                ThreadPool.QueueUserWorkItem(Performance);
                return Json(new { HasError = false, ServiceId = serviceId.ToString(), Index = model.Index });
            }

            return Json(new { HasError = true, Msg = "Can't start job" });
        }
        public ActionResult Index()
        {
            var currentUserId = User.Identity.GetUserId();
            ApplicationUser user = HttpContext.GetOwinContext().GetUserManager<ApplicationUserManager>().FindById(currentUserId);

            using (ApplicationDbContext context = new ApplicationDbContext())
            {
                SettingModel model = context.Settings.Where(s => s.UserMail == user.Email).FirstOrDefault();
                if (model == null)
                {
                    return View(new BackupModel());
                }
                else
                {
                    var backupModel = new BackupModel()
                    {
                        BackupUserMailAddress = model.AdminUserName,// todo  user.Email,
                        BackupUserOrganization = user.Organization,
                        BackupUserPassword = model.AdminPassword,
                        IsAdminUseExist = true,
                        Index = 0
                    };
                    return View(backupModel);
                }
            }
        }