Skip to content
This repository has been archived by the owner on Aug 24, 2021. It is now read-only.

Commit

Permalink
Small changes + documentation changes, including document MD template
Browse files Browse the repository at this point in the history
  • Loading branch information
jansenbe committed Aug 13, 2014
1 parent dd4459c commit a739992
Show file tree
Hide file tree
Showing 6 changed files with 161 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<RowDefinition Height="285*"/>
</Grid.RowDefinitions>
<Button x:Name="btnGo" Content="Run demo" Margin="10,4" Click="Button_Click"/>
<ScrollViewer Grid.Row="1" HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Auto">
<ScrollViewer x:Name="scrollViewerOutput" Grid.Row="1" HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Auto" LayoutUpdated="ScrollViewer_LayoutUpdated">
<TextBlock x:Name="txtOutput" Grid.Row="1" TextWrapping="NoWrap" FontSize="18" FontFamily="Consolas" Margin="0" Padding="10,10,0,0"/>
</ScrollViewer>
</Grid>
Expand Down
36 changes: 26 additions & 10 deletions Samples/Office365Api.Overview/Office365Api.Demo/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,23 @@ namespace Office365Api.Demo
/// </summary>
public partial class MainWindow : Window
{
private double scrollViewerHeight = 0.0d;

//TODO: update these values to make them relevant for your environment
private string uploadFile = @"C:\temp\bulkadusers.xlsx";
private string serviceResourceId = "https://bertonline.sharepoint.com";
//https://bertonline.sharepoint.com/sites/20140050 should work due to the user having read access
//https://bertonline.sharepoint.com/sites/20140052 should not work due to the user not having access
//https://bertonline.sharepoint.com/sites/20140053 should not work due to the user being site collection admin
private string siteUrl = "https://bertonline.sharepoint.com/sites/20140053";
private string sendMailTo = "bjansen@microsoft.com";

public MainWindow()
{
InitializeComponent();
txtOutput.Background = Brushes.Black;
}

private async void Button_Click(object sender, RoutedEventArgs e)
{
try
Expand Down Expand Up @@ -56,7 +67,7 @@ private async void Button_Click(object sender, RoutedEventArgs e)

// upload a file to the "Shared with everyone" folder
PrintSubHeader("Upload a file to OneDrive");
await MyFilesApiSample.UploadFile(@"C:\temp\bulkadusers.xlsx", "Shared with everyone");
await MyFilesApiSample.UploadFile(uploadFile, "Shared with everyone");

// iterate over the "Shared with everyone" folder
PrintSubHeader("List all files and folders in the Shared with everyone folder");
Expand All @@ -68,12 +79,8 @@ private async void Button_Click(object sender, RoutedEventArgs e)

PrintHeader("Sites API demo");
//set the SharePointResourceId
SitesApiSample.ServiceResourceId = "https://bertonline.sharepoint.com";

//https://bertonline.sharepoint.com/sites/20140050 should work due to the user having read access
//https://bertonline.sharepoint.com/sites/20140052 should not work due to the user not having access
//https://bertonline.sharepoint.com/sites/20140053 should not work due to the user being site collection admin
var mySharePointFiles = await SitesApiSample.GetDefaultDocumentFiles("https://bertonline.sharepoint.com/sites/20140053");
SitesApiSample.ServiceResourceId = serviceResourceId;
var mySharePointFiles = await SitesApiSample.GetDefaultDocumentFiles(siteUrl);
foreach (var item in mySharePointFiles)
{
PrintAttribute("URL", item.Url);
Expand All @@ -98,11 +105,11 @@ private async void Button_Click(object sender, RoutedEventArgs e)

//Send mail
PrintSubHeader("Send a mail");
await MailApiSample.SendMail("bjansen@microsoft.com", "Let's Hack-A-Thon", "This will be <B>fun...</B>");
await MailApiSample.SendMail(sendMailTo, "Let's Hack-A-Thon", "This will be <B>fun...</B>");

//Create message in drafts folder
PrintSubHeader("Store a mail in the drafts folder");
await MailApiSample.DraftMail("bjansen@microsoft.com", "Let's Hack-A-Thon", "This will be fun (in draft folder)...");
await MailApiSample.DraftMail(sendMailTo, "Let's Hack-A-Thon", "This will be fun (in draft folder)...");

PrintHeader("Active Directory API demo");
PrintSubHeader("Get all users, print first 10");
Expand Down Expand Up @@ -170,5 +177,14 @@ private void PrintAttribute(string attribute)
{
PrintAttribute(attribute, null);
}

private void ScrollViewer_LayoutUpdated(object sender, EventArgs e)
{
if (this.scrollViewerOutput.ExtentHeight != scrollViewerHeight)
{
this.scrollViewerOutput.ScrollToVerticalOffset(this.scrollViewerOutput.ExtentHeight);
this.scrollViewerHeight = this.scrollViewerOutput.ExtentHeight;
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ public static DiscoveryContext _discoveryContext
set;
}


public static async Task<IEnumerable<IFileSystemItem>> GetMyFiles()
{
var client = await EnsureClientCreated();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,6 @@ public static async Task<IEnumerable<IFileSystemItem>> GetDefaultDocumentFiles(s
return files;
}

//private static async Task<SharePointClient> EnsureClientCreated(string siteUrl)
//{
// Authenticator authenticator = new Authenticator();
// var authInfo = await authenticator.AuthenticateAsync(SharePointResourceId, ServiceIdentifierKind.Resource);

// // Create the SharePoint client proxy:
// return new SharePointClient(new Uri(string.Format("{0}/_api", siteUrl)), authInfo.GetAccessToken);
//}

public static async Task<SharePointClient> EnsureClientCreated(string siteUrl)
{
if (_discoveryContext == null)
Expand Down
85 changes: 75 additions & 10 deletions Samples/Office365Api.Overview/readme.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,79 @@
#Readme
# Office 365 API demo application (PREVIEW) #

THIS CODE IS PROVIDED AS IS WITHOUT WARRANTY OF
ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY
IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR
PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT.
### Summary ###
This WPF app show the output of various Office 365 API calls in a console alike output format. The goal of this app is the see the new API while keeping focus on the API calls themselves and less on the UI layer they're hosted in.

###A console application that shows the base features of the new Office 365 API
### Applies to ###
- Office 365 Multi Tenant (MT)

- Author - Bert Jansen (Microsoft)
- Date - 29/07/2014
- Version - 2.0
### Prerequisites ###
This sample requires the Office 365 API **preview** version released on August 5th 2014. See http://blogs.office.com/2014/08/05/office-365-api-tool-visual-studio-2013-summer-update/ for more details.

Note: this sample requires the Office 365 API preview version released on August 5th 2014. See http://blogs.office.com/2014/08/05/office-365-api-tool-visual-studio-2013-summer-update/ for more details.
### Solution ###
Solution | Author(s)
---------|----------
Office365Api.Overview | Bert Jansen (**Microsoft**)

### Version history ###
Version | Date | Comments
---------| -----| --------
2.0 | August 12th 2014 | Switched to WPF app and added documentation
1.0 | July 29th 2014 | Initial release

### Disclaimer ###
**THIS CODE IS PROVIDED *AS IS* WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT.**


----------

# Prepare the scenario for your environment #
This application will use the new Office 365 API's to perform the following list of tasks:
- Discover the current user's OneDrive URL
- Discover the current user's Mail URL
- List the files and folders from the user's OneDrive
- Upload a file to the "Shared with everyone" folder in the user's OneDrive
- List all files and folders in the "Shared with everyone" folder of the user's OneDrive
- List the total number of mails in the user's mailbox
- Retrieve all mails in the Inbox, just print the first 10
- Send a mail with the sent mail ending up in the user's "Sent items" mailbox folder
- Create a mail in the "Drafts" mailbox folder
- Get all users from Azure AD, just print the first 10

For these tasks to succeed you need to provide some input before you run the application. This is done by changing the below code snippet in the MainWindow.xaml.cs class:
```C#
//TODO: update these values to make them relevant for your environment
private string uploadFile = @"C:\temp\bulkadusers.xlsx";
private string serviceResourceId = "https://<tenant>.sharepoint.com";
private string siteUrl = "https://<tenant>.sharepoint.com/sites/<sitename>";
private string sendMailTo = "<email address>";
```
## Run the sample ##
When you run the sample you'll see a window with a big button named "Run demo" and a black output section. Click on the "Run demo" button to trigger the demo. What will first happen is that you need to logon with an Office 365 user account.
![](http://i.imgur.com/RIGgm7H.png)

Once you've logged on the Office 365 API will ask you for permissions: you need to consent that the app access your data for the listed categories:
![](http://i.imgur.com/6bDBl5w.png)

After those 2 steps are done the app can run and use all the API's to do it's work. The output is shown in console style:
![](http://i.imgur.com/LQnkq5W.png)

## Some explanation about the API's themselves ##
The app is built by extending the default classess added when you hookup a connected service:
- ActiveDirectoryApiSample.cs
- CalendarApiSample.cs
- ContactsApiSample.cs
- MailApiSample.cs
- MyFilesApiSample.cs
- SitesApiSample.cs

The class DiscoveryAPISample.cs has been created manually. The default classes have been adopted to so that they can pass along the DiscoveryContext created during the first use. This is needed to avoid continues prompting for consent.

```C#
//static DiscoveryContext _discoveryContext;
public static DiscoveryContext _discoveryContext
{
get;
set;
}

```
59 changes: 59 additions & 0 deletions readme-template.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# title of the PnP sample #

### Summary ###
Short summary.

### Applies to ###
- Office 365 Multi Tenant (MT)
- Office 365 Dedicated (D)
- SharePoint 2013 on-premises

-> Remove platforms if needed

### Prerequisites ###
Any special pre-requisites?

### Solution ###
Solution | Author(s)
---------|----------
solution name | Author

### Version history ###
Version | Date | Comments
---------| -----| --------
2.0 | March 21st 2014 (to update/remove)| comment
1.0 | November 6th 2013 (to update) | Initial release

### Disclaimer ###
**THIS CODE IS PROVIDED *AS IS* WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT.**


----------

# Doc scenario 1 #
Description
Image


## Sub level 1.1 ##
Description:
Code snippet:
```C#
string scenario1Page = String.Format("scenario1-{0}.aspx", DateTime.Now.Ticks);
string scenario1PageUrl = csomService.AddWikiPage("Site Pages", scenario1Page);
```

## Sub level 1.2 ##

# Doc scenario 2 #

## Sub level 2.1 ##

## Sub level 2.2 ##

### Note: ###

## Sub level 2.3 ##

# Doc scenario 3#

0 comments on commit a739992

Please sign in to comment.