Esempio n. 1
0
        public DiscoveryHelper(AuthenticationHelper authenticationHelper) : 
            base(authenticationHelper)
        {
            DiscoveryClient discoveryClient =
                new DiscoveryClient(
                    Office365ServicesUris.DiscoveryServiceEndpointUri,
                                    async () =>
                                    {
                                        var discoveryAuthResult =
                                            await this.AuthenticationHelper.AuthenticationContext.AcquireTokenSilentAsync(
                                                Office365ServicesUris.DiscoveryServiceResourceId,
                                                AuthenticationHelper.ClientId,
                                                new UserIdentifier(
                                                    this.AuthenticationHelper.AuthenticationResult.UserInfo.UniqueId, 
                                                    UserIdentifierType.UniqueId));

                                        return discoveryAuthResult.AccessToken;
                                    });

            this.DiscoveryClient = discoveryClient;
        }
Esempio n. 2
0
        public async Task<ActionResult> ListMyFiles()
        {
            HomeViewModel model = new HomeViewModel();

            var signInUserId = ClaimsPrincipal.Current.FindFirst(ClaimTypes.NameIdentifier).Value;
            AuthenticationHelper authenticationHelper = new AuthenticationHelper();
            authenticationHelper.EnsureAuthenticationContext(new ADALTokenCache(signInUserId));

            MyFilesHelper myFilesHelper = new MyFilesHelper(authenticationHelper);
            var myFiles = await myFilesHelper.GetMyFiles();

            model.Office365ActionResult = String.Format("Found {0} my files! Showing first 10, if any.", myFiles.Count());

            foreach (var item in myFiles.Take(10))
            {
                model.Items.Add(String.Format(
                    "URL: {0}",
                    !String.IsNullOrEmpty(item.WebUrl) ? item.WebUrl : String.Empty));
            }

            return View("UseOffice365API", model);
        }
Esempio n. 3
0
        protected async void ListFilesCommand_Click(object sender, EventArgs e)
        {
            var signInUserId = ClaimsPrincipal.Current.FindFirst(ClaimTypes.NameIdentifier).Value;
            AuthenticationHelper authenticationHelper = new AuthenticationHelper();
            authenticationHelper.EnsureAuthenticationContext(new ADALTokenCache(signInUserId));

            MyFilesHelper myFilesHelper = new MyFilesHelper(authenticationHelper);
            var myFiles = await myFilesHelper.GetMyFiles();

            List<String> results = new List<String>();

            commandResult.Text = String.Format("Found {0} my files! Showing first 10, if any.", myFiles.Count());

            foreach (var item in myFiles.Take(10))
            {
                results.Add(String.Format(
                    "URL: {0}",
                    !String.IsNullOrEmpty(item.WebUrl) ? item.WebUrl : String.Empty));
            }

            resultsList.DataSource = results;
            resultsList.DataBind();
        }
Esempio n. 4
0
        public async Task<ActionResult> ListMyContacts()
        {
            HomeViewModel model = new HomeViewModel();

            var signInUserId = ClaimsPrincipal.Current.FindFirst(ClaimTypes.NameIdentifier).Value;
            AuthenticationHelper authenticationHelper = new AuthenticationHelper();
            authenticationHelper.EnsureAuthenticationContext(new ADALTokenCache(signInUserId));

            ContactsHelper contactsHelper = new ContactsHelper(authenticationHelper);
            var contacts = await contactsHelper.GetContacts();

            model.Office365ActionResult = String.Format("Found {0} contacts! Showing first 10, if any.", contacts.Count());

            foreach (var item in contacts.Take(10))
            {
                model.Items.Add(String.Format(
                    "Name: {0} - Email: {1}",
                    !String.IsNullOrEmpty(item.DisplayName) ? item.DisplayName : String.Empty,
                    item.EmailAddresses != null ? item.EmailAddresses.First().Address : String.Empty));
            }

            return View("UseOffice365API", model);
        }
Esempio n. 5
0
        protected async void ListEmailsCommand_Click(object sender, EventArgs e)
        {
            var signInUserId = ClaimsPrincipal.Current.FindFirst(ClaimTypes.NameIdentifier).Value;
            AuthenticationHelper authenticationHelper = new AuthenticationHelper();
            authenticationHelper.EnsureAuthenticationContext(new ADALTokenCache(signInUserId));

            MailHelper mailHelper = new MailHelper(authenticationHelper);
            var mails = await mailHelper.GetMessages();

            List<String> results = new List<String>();

            commandResult.Text = String.Format("Found {0} mails! Showing first 10, if any.", mails.Count());

            foreach (var item in mails.Take(10))
            {
                results.Add(String.Format(
                    "From: {0} - Subject: {1}",
                    item.From != null ? item.From.EmailAddress.Address : "",
                    !String.IsNullOrEmpty(item.Subject) ? item.Subject : String.Empty));
            }

            resultsList.DataSource = results;
            resultsList.DataBind();
        }
Esempio n. 6
0
        protected async void ListContactsCommand_Click(object sender, EventArgs e)
        {
            var signInUserId = ClaimsPrincipal.Current.FindFirst(ClaimTypes.NameIdentifier).Value;
            AuthenticationHelper authenticationHelper = new AuthenticationHelper();
            authenticationHelper.EnsureAuthenticationContext(new ADALTokenCache(signInUserId));

            ContactsHelper contactsHelper = new ContactsHelper(authenticationHelper);
            var contacts = await contactsHelper.GetContacts();

            List<String> results = new List<String>();

            commandResult.Text = String.Format("Found {0} contacts! Showing first 10, if any.", contacts.Count());

            foreach (var item in contacts.Take(10))
            {
                results.Add(String.Format(
                    "Name: {0} - Email: {1}",
                    !String.IsNullOrEmpty(item.DisplayName) ? item.DisplayName : String.Empty,
                    item.EmailAddresses != null ? item.EmailAddresses.First().Address : String.Empty));
            }

            resultsList.DataSource = results;
            resultsList.DataBind();
        }
Esempio n. 7
0
 public MailHelper(AuthenticationHelper authenticationHelper) : 
     base(authenticationHelper)
 {
 }
Esempio n. 8
0
 public ActiveDirectoryHelper(AuthenticationHelper authenticationHelper) :
     base(authenticationHelper)
 {
 }
Esempio n. 9
0
        public async Task<ActionResult> SendMail(String targetEMail)
        {
            HomeViewModel model = new HomeViewModel();

            model.TargetEMail = targetEMail;

            var signInUserId = ClaimsPrincipal.Current.FindFirst(ClaimTypes.NameIdentifier).Value;
            AuthenticationHelper authenticationHelper = new AuthenticationHelper();
            authenticationHelper.EnsureAuthenticationContext(new ADALTokenCache(signInUserId));

            MailHelper mailHelper = new MailHelper(authenticationHelper);
            await mailHelper.SendMail(targetEMail, "Let's Hack-A-Thon - Office365Api.MVCDemo", "This will be <B>fun...</B>");
            model.Office365ActionResult = "Email sent!";

            return View("UseOffice365API", model);
        }
Esempio n. 10
0
        private async void Button_Click(object sender, RoutedEventArgs e)
        {
            Uri authorityUri;
            Uri sharePointTenantUri;
            Uri siteCollectionUri;

            Regex mailRegex = new Regex(@"^([\w\.\-]+)@([\w\-]+)((\.(\w){2,3})+)$");

            // Input parameters sanity check 
            if ((String.IsNullOrEmpty(this.Authority.Text) || !Uri.TryCreate(this.Authority.Text, UriKind.Absolute, out authorityUri)) ||
                (String.IsNullOrEmpty(this.SharePointTenantUri.Text) || !Uri.TryCreate(this.SharePointTenantUri.Text, UriKind.Absolute, out sharePointTenantUri)) ||
                (String.IsNullOrEmpty(this.SiteCollectionUri.Text) || !Uri.TryCreate(this.SiteCollectionUri.Text, UriKind.Absolute, out siteCollectionUri)) ||
                (String.IsNullOrEmpty(this.MailAddressTo.Text) || !mailRegex.IsMatch(this.MailAddressTo.Text)) ||
                (String.IsNullOrEmpty(this.FileToUploadPath.Text) || !File.Exists(this.FileToUploadPath.Text)))
            {
                MessageBoxResult msgBoxResult = MessageBox.Show("Please fill all the input parameters!");
                return;
            }

            try
            {
                PrintHeader("Authentication Phase");
                AuthenticationHelper authenticationHelper = new AuthenticationHelper();
                authenticationHelper.EnsureAuthenticationContext(this.Authority.Text);

                PrintHeader("Discovery API demo");
                DiscoveryHelper discoveryHelper = new DiscoveryHelper(authenticationHelper);
                var t = await discoveryHelper.DiscoverMyFiles();
                PrintSubHeader("Current user information");
                PrintAttribute("OneDrive URL", t.ServiceEndpointUri);

                var t3 = await discoveryHelper.DiscoverMail();
                PrintAttribute("Mail URL", t3.ServiceEndpointUri);

                PrintHeader("Files API demo");
                // Read all files on your onedrive
                PrintSubHeader("List TOP 20 files and folders in the OneDrive");

                MyFilesHelper myFilesHelper = new MyFilesHelper(authenticationHelper);
                var allMyFolders = await myFilesHelper.GetMyFolders();

                var allMyFiles = await myFilesHelper.GetMyFiles();
                foreach (var item in allMyFiles.Take(20))
                {
                    PrintAttribute("URL", item.WebUrl);
                }

                // Upload a file to the "Shared with everyone" folder
                PrintSubHeader("Upload a file to OneDrive");
                if (allMyFolders.Any())
                {
                    await myFilesHelper.UploadFile(this.FileToUploadPath.Text, allMyFolders.First().Id);
                }
                else
                {
                    await myFilesHelper.UploadFile(this.FileToUploadPath.Text);
                }
                // Shared with everyone

                // Iterate over the "Shared with everyone" folder
                PrintSubHeader("List all files and folders in the Shared with everyone folder");
                var myFiles = await myFilesHelper.GetMyFiles(allMyFolders.First().Id);
                foreach (var item in myFiles)
                {
                    PrintAttribute("URL", item.WebUrl);
                }

                PrintHeader("Mail API demo");

                //Get mails
                PrintSubHeader("Retrieve mails from INBOX");
                MailHelper mailHelper = new MailHelper(authenticationHelper);
                var mails = await mailHelper.GetMessages();
                PrintSubHeader(String.Format("Printing TOP 10 mails of {0}", mails.Count()));
                foreach (var item in mails.Take(10))
                {
                    PrintAttribute("From ", String.Format("{0} / {1}", item.From != null ? item.From.EmailAddress.Address : "", item.Subject));
                }

                //Send mail
                PrintSubHeader("Send a mail");
                await mailHelper.SendMail(this.MailAddressTo.Text, "Let's Hack-A-Thon - Office365Api.Demo", "This will be <B>fun...</B>");

                //Create message in drafts folder
                PrintSubHeader("Store a mail in the drafts folder");
                await mailHelper.DraftMail(this.MailAddressTo.Text, "Let's Hack-A-Thon - Office365Api.Demo", "This will be fun (in draft folder)...");

                PrintHeader("Active Directory API demo");
                ActiveDirectoryHelper activeDirectoryHelper = new ActiveDirectoryHelper(authenticationHelper);
                var allADUsers = await activeDirectoryHelper.GetUsers();
                PrintSubHeader(String.Format("Printing TOP 10 users of {0}", allADUsers.Count()));
                foreach (var user in allADUsers.Take(10))
                {
                    PrintAttribute("User", user.UserPrincipalName);
                }

                PrintHeader("All done...");
            }
            catch (Exception ex)
            {
                string message = "";
                if (ex is AggregateException)
                {
                    message = ex.InnerException.Message;
                }
                else
                {
                    message = ex.Message;
                }

                PrintException(message);
            }
        }
Esempio n. 11
0
 public MailHelper(AuthenticationHelper authenticationHelper) :
     base(authenticationHelper)
 {
 }
Esempio n. 12
0
 public CalendarHelper(AuthenticationHelper authenticationHelper) : 
     base(authenticationHelper)
 {
 }
Esempio n. 13
0
 public ContactsHelper(AuthenticationHelper authenticationHelper) :
     base(authenticationHelper)
 {
 }
Esempio n. 14
0
 public SitesHelper(AuthenticationHelper authenticationHelper) : 
     base(authenticationHelper)
 {
 }
Esempio n. 15
0
        protected async void SendMailCommand_Click(object sender, EventArgs e)
        {
            var signInUserId = ClaimsPrincipal.Current.FindFirst(ClaimTypes.NameIdentifier).Value;
            AuthenticationHelper authenticationHelper = new AuthenticationHelper();
            authenticationHelper.EnsureAuthenticationContext(new ADALTokenCache(signInUserId));

            MailHelper mailHelper = new MailHelper(authenticationHelper);
            await mailHelper.SendMail(TargetEmail.Text, "Let's Hack-A-Thon - Office365Api.WebForms", "This will be <B>fun...</B>");
            commandResult.Text = "Email sent!";

            resultsList.DataSource = new List<String>();
            resultsList.DataBind();
        }
Esempio n. 16
0
 public BaseOffice365Helper(AuthenticationHelper authenticationHelper)
 {
     this.AuthenticationHelper = authenticationHelper;
 }
Esempio n. 17
0
 public ActiveDirectoryHelper(AuthenticationHelper authenticationHelper) : 
     base(authenticationHelper)
 {
 }
Esempio n. 18
0
 public MyFilesHelper(AuthenticationHelper authenticationHelper) : 
     base(authenticationHelper)
 {
 }
Esempio n. 19
0
 public ContactsHelper(AuthenticationHelper authenticationHelper) : 
     base(authenticationHelper)
 {
 }
Esempio n. 20
0
        public async Task<ActionResult> ListMyMessages()
        {
            HomeViewModel model = new HomeViewModel();

            var signInUserId = ClaimsPrincipal.Current.FindFirst(ClaimTypes.NameIdentifier).Value;
            AuthenticationHelper authenticationHelper = new AuthenticationHelper();
            authenticationHelper.EnsureAuthenticationContext(new ADALTokenCache(signInUserId));

            MailHelper mailHelper = new MailHelper(authenticationHelper);
            var mails = await mailHelper.GetMessages();

            model.Office365ActionResult = String.Format("Found {0} mails! Showing first 10, if any.", mails.Count());

            foreach (var item in mails.Take(10))
            {
                model.Items.Add(String.Format(
                    "From: {0} - Subject: {1}",
                    item.From != null ? item.From.EmailAddress.Address : "",
                    !String.IsNullOrEmpty(item.Subject) ? item.Subject : String.Empty));
            }

            return View("UseOffice365API", model);
        }
Esempio n. 21
0
 public MyFilesHelper(AuthenticationHelper authenticationHelper) :
     base(authenticationHelper)
 {
 }