Пример #1
0
 public System.Windows.Input.ICommand GetGoToInputCmd(ICreateListVM vm)
 {
     return(new Command(() =>
     {
         (vm.Parent as MainVM).SetPageIndex(2);
     }));
 }
Пример #2
0
        private async Task <int> ReadFromGmail(Account acc, ICreateListVM vm)
        {
            User user = null;

            // If the user is authenticated, request their basic user data from Google
            // UserInfoUrl = https://www.googleapis.com/oauth2/v2/userinfo
            var request  = new OAuth2Request("GET", new Uri(Constants.UserInfoUrl), null, acc);
            var response = await request.GetResponseAsync();

            if (response != null)
            {
                StoreFactory.CurrentVM.Logs.Add("Gmail user info received");

                // Deserialize the data and store it in the account store
                // The users email address will be used to identify data in SimpleDB
                string userJson = await response.GetResponseTextAsync();

                user = JsonConvert.DeserializeObject <User>(userJson);
            }

            if (account != null)
            {
                store.Delete(account, Constants.AppName);
            }

            DateTime date      = DateTime.Now.Subtract(new TimeSpan(vm.Days * 24, 0, 0));
            var      request2  = new OAuth2Request("GET", new Uri(string.Format(Constants.MessageList, "\"" + vm.Subject + "\"", vm.From, date.ToString("yyyy/MM/dd"))), null, acc);
            var      response2 = await request2.GetResponseAsync();

            if (response2 != null)
            {
                StoreFactory.CurrentVM.Logs.Add("Gmail message list received");
                // Deserialize the data and store it in the account store
                // The users email address will be used to identify data in SimpleDB
                string userJson = await response2.GetResponseTextAsync();

                vm.Percentage = 0;
                vm.Messages.Clear();
                foreach (string id in StoreFactory.HalProxy.ReadMailIds(userJson))
                {
                    StoreFactory.CurrentVM.Logs.Add("Gmail message id = " + id);
                    var email = await ReadEmail(id, acc, vm);

                    vm.Messages.Add(email);
                    StoreFactory.HalProxy.RunOnUiThread(
                        new Action(() => { vm.Percentage++; }));
                }
                vm.RaiseChanges();
            }


            await store.SaveAsync(acc, Constants.AppName);

            vm.IsRunning = false;
            StoreFactory.CurrentVM.Logs.Add("Gmail message count = " + vm.Messages.Count);

            return(vm.Messages.Count);
        }
Пример #3
0
        public Email(ICreateListVM vm)
        {
            this.InputFromGmailCmd = new Command((nothing) =>
            {
                StoreFactory.Items.InitInput(this.Body.Split(new String[] { Environment.NewLine, "\n" }, StringSplitOptions.RemoveEmptyEntries), true, StoreFactory.CurrentVM);
                StoreFactory.CurrentVM.RefreshOutputList();
                this.GoToInputCmd.Execute(null);
            });

            this.GoToInputCmd = StoreFactory.HalProxy.GetGoToInputCmd(vm);
        }
Пример #4
0
        async Task <Email> ReadEmail(string id, Account account, ICreateListVM vm)
        {
            Email email    = null;
            var   request  = new OAuth2Request("GET", new Uri(string.Format(Constants.MessageGet, id)), null, account);
            var   response = await request.GetResponseAsync();

            if (response != null)
            {
                // Deserialize the data and store it in the account store
                // The users email address will be used to identify data in SimpleDB
                string userJson = await response.GetResponseTextAsync();

                email = StoreFactory.HalProxy.ReadMailContent(userJson, vm);
                StoreFactory.CurrentVM.Logs.Add("Gmail message received " + email.Subject);
            }

            return(email);
        }
Пример #5
0
        public Email ReadMailContent(string userJson, ICreateListVM vm)
        {
            var           message = JsonConvert.DeserializeObject <Message>(userJson);
            StringBuilder builder = new StringBuilder();

            this.getPlainTextFromMessageParts(message.Payload.Parts, builder);
            try
            {
                string body = builder.ToString();
                return(new Email(vm)
                {
                    Subject = message.Payload.Headers.First(x => x.Name == "Subject").Value,
                    Body = body
                });
            }
            catch (Exception ex)
            {
                return(new Email(vm)
                {
                    Subject = message.Payload.Headers.First(x => x.Name == "Subject").Value,
                    Body = string.Empty
                });
            }
        }
Пример #6
0
 public LoginOAuth(ICreateListVM vm)
 {
     store   = AccountStore.Create();
     account = store.FindAccountsForService(Constants.AppName).FirstOrDefault();
     this.vm = vm;
 }
Пример #7
0
 public ILoginOAuth GetLogin(ICreateListVM vm)
 {
     return(new LoginOAuth(vm));
 }