Skip to content

Commit a739992

Browse files
committed
Small changes + documentation changes, including document MD template
1 parent dd4459c commit a739992

File tree

6 files changed

+161
-31
lines changed

6 files changed

+161
-31
lines changed

Samples/Office365Api.Overview/Office365Api.Demo/MainWindow.xaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
<RowDefinition Height="285*"/>
99
</Grid.RowDefinitions>
1010
<Button x:Name="btnGo" Content="Run demo" Margin="10,4" Click="Button_Click"/>
11-
<ScrollViewer Grid.Row="1" HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Auto">
11+
<ScrollViewer x:Name="scrollViewerOutput" Grid.Row="1" HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Auto" LayoutUpdated="ScrollViewer_LayoutUpdated">
1212
<TextBlock x:Name="txtOutput" Grid.Row="1" TextWrapping="NoWrap" FontSize="18" FontFamily="Consolas" Margin="0" Padding="10,10,0,0"/>
1313
</ScrollViewer>
1414
</Grid>

Samples/Office365Api.Overview/Office365Api.Demo/MainWindow.xaml.cs

+26-10
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,23 @@ namespace Office365Api.Demo
2020
/// </summary>
2121
public partial class MainWindow : Window
2222
{
23+
private double scrollViewerHeight = 0.0d;
24+
25+
//TODO: update these values to make them relevant for your environment
26+
private string uploadFile = @"C:\temp\bulkadusers.xlsx";
27+
private string serviceResourceId = "https://bertonline.sharepoint.com";
28+
//https://bertonline.sharepoint.com/sites/20140050 should work due to the user having read access
29+
//https://bertonline.sharepoint.com/sites/20140052 should not work due to the user not having access
30+
//https://bertonline.sharepoint.com/sites/20140053 should not work due to the user being site collection admin
31+
private string siteUrl = "https://bertonline.sharepoint.com/sites/20140053";
32+
private string sendMailTo = "[email protected]";
33+
2334
public MainWindow()
2435
{
2536
InitializeComponent();
2637
txtOutput.Background = Brushes.Black;
2738
}
28-
39+
2940
private async void Button_Click(object sender, RoutedEventArgs e)
3041
{
3142
try
@@ -56,7 +67,7 @@ private async void Button_Click(object sender, RoutedEventArgs e)
5667

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

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

6980
PrintHeader("Sites API demo");
7081
//set the SharePointResourceId
71-
SitesApiSample.ServiceResourceId = "https://bertonline.sharepoint.com";
72-
73-
//https://bertonline.sharepoint.com/sites/20140050 should work due to the user having read access
74-
//https://bertonline.sharepoint.com/sites/20140052 should not work due to the user not having access
75-
//https://bertonline.sharepoint.com/sites/20140053 should not work due to the user being site collection admin
76-
var mySharePointFiles = await SitesApiSample.GetDefaultDocumentFiles("https://bertonline.sharepoint.com/sites/20140053");
82+
SitesApiSample.ServiceResourceId = serviceResourceId;
83+
var mySharePointFiles = await SitesApiSample.GetDefaultDocumentFiles(siteUrl);
7784
foreach (var item in mySharePointFiles)
7885
{
7986
PrintAttribute("URL", item.Url);
@@ -98,11 +105,11 @@ private async void Button_Click(object sender, RoutedEventArgs e)
98105

99106
//Send mail
100107
PrintSubHeader("Send a mail");
101-
await MailApiSample.SendMail("[email protected]", "Let's Hack-A-Thon", "This will be <B>fun...</B>");
108+
await MailApiSample.SendMail(sendMailTo, "Let's Hack-A-Thon", "This will be <B>fun...</B>");
102109

103110
//Create message in drafts folder
104111
PrintSubHeader("Store a mail in the drafts folder");
105-
await MailApiSample.DraftMail("[email protected]", "Let's Hack-A-Thon", "This will be fun (in draft folder)...");
112+
await MailApiSample.DraftMail(sendMailTo, "Let's Hack-A-Thon", "This will be fun (in draft folder)...");
106113

107114
PrintHeader("Active Directory API demo");
108115
PrintSubHeader("Get all users, print first 10");
@@ -170,5 +177,14 @@ private void PrintAttribute(string attribute)
170177
{
171178
PrintAttribute(attribute, null);
172179
}
180+
181+
private void ScrollViewer_LayoutUpdated(object sender, EventArgs e)
182+
{
183+
if (this.scrollViewerOutput.ExtentHeight != scrollViewerHeight)
184+
{
185+
this.scrollViewerOutput.ScrollToVerticalOffset(this.scrollViewerOutput.ExtentHeight);
186+
this.scrollViewerHeight = this.scrollViewerOutput.ExtentHeight;
187+
}
188+
}
173189
}
174190
}

Samples/Office365Api.Overview/Office365Api.Demo/MyFilesApiSample.cs

-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ public static DiscoveryContext _discoveryContext
2323
set;
2424
}
2525

26-
2726
public static async Task<IEnumerable<IFileSystemItem>> GetMyFiles()
2827
{
2928
var client = await EnsureClientCreated();

Samples/Office365Api.Overview/Office365Api.Demo/SitesApiSample.cs

-9
Original file line numberDiff line numberDiff line change
@@ -39,15 +39,6 @@ public static async Task<IEnumerable<IFileSystemItem>> GetDefaultDocumentFiles(s
3939
return files;
4040
}
4141

42-
//private static async Task<SharePointClient> EnsureClientCreated(string siteUrl)
43-
//{
44-
// Authenticator authenticator = new Authenticator();
45-
// var authInfo = await authenticator.AuthenticateAsync(SharePointResourceId, ServiceIdentifierKind.Resource);
46-
47-
// // Create the SharePoint client proxy:
48-
// return new SharePointClient(new Uri(string.Format("{0}/_api", siteUrl)), authInfo.GetAccessToken);
49-
//}
50-
5142
public static async Task<SharePointClient> EnsureClientCreated(string siteUrl)
5243
{
5344
if (_discoveryContext == null)
+75-10
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,79 @@
1-
#Readme
1+
# Office 365 API demo application (PREVIEW) #
22

3-
THIS CODE IS PROVIDED AS IS WITHOUT WARRANTY OF
4-
ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY
5-
IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR
6-
PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT.
3+
### Summary ###
4+
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.
75

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

10-
- Author - Bert Jansen (Microsoft)
11-
- Date - 29/07/2014
12-
- Version - 2.0
9+
### Prerequisites ###
10+
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.
1311

14-
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.
12+
### Solution ###
13+
Solution | Author(s)
14+
---------|----------
15+
Office365Api.Overview | Bert Jansen (**Microsoft**)
16+
17+
### Version history ###
18+
Version | Date | Comments
19+
---------| -----| --------
20+
2.0 | August 12th 2014 | Switched to WPF app and added documentation
21+
1.0 | July 29th 2014 | Initial release
22+
23+
### Disclaimer ###
24+
**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.**
25+
26+
27+
----------
28+
29+
# Prepare the scenario for your environment #
30+
This application will use the new Office 365 API's to perform the following list of tasks:
31+
- Discover the current user's OneDrive URL
32+
- Discover the current user's Mail URL
33+
- List the files and folders from the user's OneDrive
34+
- Upload a file to the "Shared with everyone" folder in the user's OneDrive
35+
- List all files and folders in the "Shared with everyone" folder of the user's OneDrive
36+
- List the total number of mails in the user's mailbox
37+
- Retrieve all mails in the Inbox, just print the first 10
38+
- Send a mail with the sent mail ending up in the user's "Sent items" mailbox folder
39+
- Create a mail in the "Drafts" mailbox folder
40+
- Get all users from Azure AD, just print the first 10
41+
42+
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:
43+
```C#
44+
//TODO: update these values to make them relevant for your environment
45+
private string uploadFile = @"C:\temp\bulkadusers.xlsx";
46+
private string serviceResourceId = "https://<tenant>.sharepoint.com";
47+
private string siteUrl = "https://<tenant>.sharepoint.com/sites/<sitename>";
48+
private string sendMailTo = "<email address>";
49+
```
50+
## Run the sample ##
51+
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.
52+
![](http://i.imgur.com/RIGgm7H.png)
53+
54+
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:
55+
![](http://i.imgur.com/6bDBl5w.png)
56+
57+
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:
58+
![](http://i.imgur.com/LQnkq5W.png)
59+
60+
## Some explanation about the API's themselves ##
61+
The app is built by extending the default classess added when you hookup a connected service:
62+
- ActiveDirectoryApiSample.cs
63+
- CalendarApiSample.cs
64+
- ContactsApiSample.cs
65+
- MailApiSample.cs
66+
- MyFilesApiSample.cs
67+
- SitesApiSample.cs
68+
69+
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.
70+
71+
```C#
72+
//static DiscoveryContext _discoveryContext;
73+
public static DiscoveryContext _discoveryContext
74+
{
75+
get;
76+
set;
77+
}
78+
79+
```

readme-template.md

+59
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
# title of the PnP sample #
2+
3+
### Summary ###
4+
Short summary.
5+
6+
### Applies to ###
7+
- Office 365 Multi Tenant (MT)
8+
- Office 365 Dedicated (D)
9+
- SharePoint 2013 on-premises
10+
11+
-> Remove platforms if needed
12+
13+
### Prerequisites ###
14+
Any special pre-requisites?
15+
16+
### Solution ###
17+
Solution | Author(s)
18+
---------|----------
19+
solution name | Author
20+
21+
### Version history ###
22+
Version | Date | Comments
23+
---------| -----| --------
24+
2.0 | March 21st 2014 (to update/remove)| comment
25+
1.0 | November 6th 2013 (to update) | Initial release
26+
27+
### Disclaimer ###
28+
**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.**
29+
30+
31+
----------
32+
33+
# Doc scenario 1 #
34+
Description
35+
Image
36+
37+
38+
## Sub level 1.1 ##
39+
Description:
40+
Code snippet:
41+
```C#
42+
string scenario1Page = String.Format("scenario1-{0}.aspx", DateTime.Now.Ticks);
43+
string scenario1PageUrl = csomService.AddWikiPage("Site Pages", scenario1Page);
44+
```
45+
46+
## Sub level 1.2 ##
47+
48+
# Doc scenario 2 #
49+
50+
## Sub level 2.1 ##
51+
52+
## Sub level 2.2 ##
53+
54+
### Note: ###
55+
56+
## Sub level 2.3 ##
57+
58+
# Doc scenario 3#
59+

0 commit comments

Comments
 (0)