Example #1
0
        public static DualDifferentReturn <TasksService, PlusService> autenthicate()
        {
            DualDifferentReturn <TasksService, PlusService> returnValue = null;

            Thread tLogin = new Thread(() =>
            {
                UserCredential credential;

                using (var stream =
                           new FileStream("client_secret.json", FileMode.Open, FileAccess.Read))
                {
                    string credPath = Directory.GetParent(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)).FullName;
                    credPath        = Path.Combine(credPath, @"Local\Agenda\data\credentials");

                    credential = GoogleWebAuthorizationBroker.AuthorizeAsync(GoogleClientSecrets.Load(stream).Secrets,
                                                                             Scopes,
                                                                             "user",
                                                                             CancellationToken.None,
                                                                             new FileDataStore(credPath, true)).Result;
                }

                XmlDocument xdoc = new XmlDocument();
                xdoc.Load("config.xml");
                XmlNodeList xnodelist = xdoc.SelectNodes("//config/loggedIn");

                foreach (XmlNode node in xnodelist)
                {
                    if (node.Name == "loggedIn")
                    {
                        node.InnerText = "true";
                    }
                }
                xdoc.Save("config.xml");

                TasksService tasksService = new TasksService(new BaseClientService.Initializer()
                {
                    HttpClientInitializer = credential,
                    ApplicationName       = "Agenda",
                });

                PlusService plusService = new PlusService(new BaseClientService.Initializer()
                {
                    HttpClientInitializer = credential,
                    ApplicationName       = "Agenda",
                });

                returnValue = new DualDifferentReturn <TasksService, PlusService>(tasksService, plusService);
            });

            tLogin.Start();
            tLogin.Join();

            return(returnValue);
        }
Example #2
0
        public MainUI(DualDifferentReturn <TasksService, PlusService> services)
        {
            InitializeComponent();

            try
            {
                TasksService tasksService = services.returnValue1;
                PlusService  plusService  = services.returnValue2;

                var    me    = plusService.People.Get("me").Execute();
                string email = me.Emails.FirstOrDefault().Value;
                string name  = me.DisplayName;

                MainUI_lblAccountInfo.Content = name + " (" + email + ")";

                TasklistsResource.ListRequest tasklistRequest = tasksService.Tasklists.List();
                IList <TaskList> taskLists = tasklistRequest.Execute().Items;

                if (taskLists != null && taskLists.Count > 0)
                {
                    eTasklists = new List <ETasklist>();
                    foreach (TaskList taskList in taskLists)
                    {
                        TasksResource.ListRequest taskRequest = tasksService.Tasks.List(taskList.Id);
                        IList <Task> tasks = taskRequest.Execute().Items;

                        ETasklist eTasklist = new ETasklist(taskList, tasks);
                        eTasklists.Add(eTasklist);
                    }

                    listTasks(eTasklists);
                }
                else
                {
                    Console.WriteLine("No task lists found.");
                }
            }
            catch (Exception e)
            {
                MessageBox.Show(e.ToString() + " " + e.StackTrace);
            }

            this.BringIntoView();
            this.Activate();
        }