Skip to content
This repository was archived by the owner on Nov 16, 2023. It is now read-only.

Commit bc172b4

Browse files
author
Jim Crowley
committed
adding snippets
1 parent d88600b commit bc172b4

File tree

4 files changed

+93
-19
lines changed

4 files changed

+93
-19
lines changed

Microsoft-Graph-Snippets-SDK/Assets/Resources.resw

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -246,24 +246,6 @@
246246
<data name="PleaseRegister" xml:space="preserve">
247247
<value>Please register your app before you run this sample</value>
248248
</data>
249-
<data name="Prop_AttachmentName" xml:space="preserve">
250-
<value>Attachment name</value>
251-
</data>
252-
<data name="Prop_AttachmentsCount" xml:space="preserve">
253-
<value>Attachment count</value>
254-
</data>
255-
<data name="Prop_AttachmentSize" xml:space="preserve">
256-
<value>Attachment size</value>
257-
</data>
258-
<data name="Prop_AttachmentType" xml:space="preserve">
259-
<value>Attachment type</value>
260-
</data>
261-
<data name="Prop_IsDraft" xml:space="preserve">
262-
<value>IsDraft</value>
263-
</data>
264-
<data name="Prop_ResponseStatus" xml:space="preserve">
265-
<value>Response status</value>
266-
</data>
267249
<data name="ProtectWorksheet" xml:space="preserve">
268250
<value>Protect Wksht</value>
269251
</data>

Microsoft-Graph-Snippets-SDK/MainPage.xaml.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,11 @@ private void CreateStoryList()
8282
StoryCollection.Add(new StoryDefinition() { GroupName = usersGroupName, Title = ResourceLoader.GetForCurrentView().GetString("GetMyInboxMessagesThatHaveAttachments"), ScopeGroup = ScopeGroupAll, RunStoryAsync = UserStories.TryGetMessagesThatHaveAttachments });
8383
StoryCollection.Add(new StoryDefinition() { GroupName = usersGroupName, Title = ResourceLoader.GetForCurrentView().GetString("SendMessage"), ScopeGroup = ScopeGroupAll, RunStoryAsync = UserStories.TrySendMailAsync });
8484
StoryCollection.Add(new StoryDefinition() { GroupName = usersGroupName, Title = ResourceLoader.GetForCurrentView().GetString("SendMessageWithAttachment"), ScopeGroup = ScopeGroupAll, RunStoryAsync = UserStories.TrySendMessageWithAttachmentAsync });
85+
StoryCollection.Add(new StoryDefinition() { GroupName = usersGroupName, Title = ResourceLoader.GetForCurrentView().GetString("ReplyToMessage"), ScopeGroup = ScopeGroupAll, RunStoryAsync = UserStories.TryReplyToMessageAsync });
86+
StoryCollection.Add(new StoryDefinition() { GroupName = usersGroupName, Title = ResourceLoader.GetForCurrentView().GetString("MoveMessage"), ScopeGroup = ScopeGroupAll, RunStoryAsync = UserStories.TryMoveMessageAsync });
8587

8688
StoryCollection.Add(new StoryDefinition() { GroupName = usersGroupName, Title = ResourceLoader.GetForCurrentView().GetString("GetUserFiles"), ScopeGroup = ScopeGroupAll, RunStoryAsync = UserStories.TryGetCurrentUserFilesAsync });
89+
StoryCollection.Add(new StoryDefinition() { GroupName = usersGroupName, Title = ResourceLoader.GetForCurrentView().GetString("GetSharingLink"), ScopeGroup = ScopeGroupAll, RunStoryAsync = UserStories.TryGetSharingLinkAsync });
8790
StoryCollection.Add(new StoryDefinition() { GroupName = usersGroupName, Title = ResourceLoader.GetForCurrentView().GetString("CreateTextFile"), ScopeGroup = ScopeGroupAll, RunStoryAsync = UserStories.TryCreateFileAsync });
8891
StoryCollection.Add(new StoryDefinition() { GroupName = usersGroupName, Title = ResourceLoader.GetForCurrentView().GetString("DownloadFile"), ScopeGroup = ScopeGroupAll, RunStoryAsync = UserStories.TryDownloadFileAsync });
8992
StoryCollection.Add(new StoryDefinition() { GroupName = usersGroupName, Title = ResourceLoader.GetForCurrentView().GetString("UpdateFile"), ScopeGroup = ScopeGroupAll, RunStoryAsync = UserStories.TryUpdateFileAsync });

Microsoft-Graph-Snippets-SDK/Users/UserSnippets.cs

Lines changed: 64 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -567,13 +567,56 @@ string RecipientAddress
567567

568568
catch (ServiceException e)
569569
{
570-
Debug.WriteLine("We could not send the message. The request returned this status code: " + e.Error.Message);
570+
Debug.WriteLine("We could not send the message with an attachment. The request returned this status code: " + e.Error.Message);
571571
emailSent = false;
572572
}
573573

574574
return emailSent;
575575
}
576576

577+
// Reply to a specified message
578+
public static async Task<bool> ReplyToMessageAsync(string Id)
579+
{
580+
bool replySent = false;
581+
string responseText = ResourceLoader.GetForCurrentView().GetString("GenericText");
582+
583+
try
584+
{
585+
var graphClient = AuthenticationHelper.GetAuthenticatedClient();
586+
await graphClient.Me.Messages[Id].Reply(responseText).Request().PostAsync();
587+
Debug.WriteLine("Reply sent");
588+
replySent = true;
589+
}
590+
591+
catch (ServiceException e)
592+
{
593+
Debug.WriteLine("We could not reply to the message. The request returned this status code: " + e.Error.Message);
594+
replySent = false;
595+
}
596+
597+
return replySent;
598+
}
599+
600+
// Move a specified message. This creates a new copy of the message to the specified folder.
601+
public static async Task<Message> MoveMessageAsync(string Id, string folderName)
602+
{
603+
Message message = null;
604+
605+
try
606+
{
607+
var graphClient = AuthenticationHelper.GetAuthenticatedClient();
608+
message = await graphClient.Me.Messages[Id].Move(folderName).Request().PostAsync();
609+
Debug.WriteLine("Message " + Id + " moved to " + folderName );
610+
}
611+
612+
catch (ServiceException e)
613+
{
614+
Debug.WriteLine("We could not move the message. The request returned this status code: " + e.Error.Message);
615+
}
616+
617+
return message;
618+
619+
}
577620

578621
// Gets the signed-in user's manager.
579622
// This snippet doesn't work with personal accounts.
@@ -743,6 +786,26 @@ public static async Task<IDriveItemChildrenCollectionPage> GetCurrentUserFilesAs
743786

744787
}
745788

789+
public static async Task<Permission> GetSharingLinkAsync(string Id)
790+
{
791+
Permission permission = null;
792+
793+
try
794+
{
795+
var graphClient = AuthenticationHelper.GetAuthenticatedClient();
796+
permission = await graphClient.Me.Drive.Items[Id].CreateLink("view").Request().PostAsync();
797+
Debug.WriteLine("Got sharing link for file: " + permission.Link.WebUrl);
798+
}
799+
800+
catch (ServiceException e)
801+
{
802+
Debug.WriteLine("We could not get the sharing link: " + e.Error.Message);
803+
return null;
804+
}
805+
806+
return permission;
807+
}
808+
746809
// Creates a text file in the user's root directory.
747810
public static async Task<string> CreateFileAsync(string fileName, string fileContent)
748811
{

Microsoft-Graph-Snippets-SDK/Users/UserStories.cs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,25 @@ public static async Task<bool> TrySendMessageWithAttachmentAsync()
145145
);
146146
}
147147

148+
// Replies to the first message returned by the GetMessages snippet
149+
public static async Task<bool> TryReplyToMessageAsync()
150+
{
151+
var graphClient = AuthenticationHelper.GetAuthenticatedClient();
152+
var messages = await UserSnippets.GetMessagesAsync();
153+
return await UserSnippets.ReplyToMessageAsync(messages[0].Id);
154+
}
155+
156+
// Moves a message to the "Drafts" folder
157+
public static async Task<bool> TryMoveMessageAsync()
158+
{
159+
var graphClient = AuthenticationHelper.GetAuthenticatedClient();
160+
var currentUser = await graphClient.Me.Request().GetAsync();
161+
162+
var messages = await UserSnippets.GetMessagesAsync();
163+
var message = await UserSnippets.MoveMessageAsync(messages[0].Id, "Drafts");
164+
return message != null;
165+
}
166+
148167
// This story does not work with a personal account
149168
public static async Task<bool> TryGetCurrentUserManagerAsync()
150169
{
@@ -186,6 +205,13 @@ public static async Task<bool> TryGetCurrentUserFilesAsync()
186205
return files != null;
187206
}
188207

208+
public static async Task<bool> TryGetSharingLinkAsync()
209+
{
210+
string fileId = await UserSnippets.CreateFileAsync(Guid.NewGuid().ToString(), STORY_DATA_IDENTIFIER);
211+
Permission permission = await UserSnippets.GetSharingLinkAsync(fileId);
212+
return permission != null;
213+
}
214+
189215
public static async Task<bool> TryCreateFileAsync()
190216
{
191217
var createdFileId = await UserSnippets.CreateFileAsync(Guid.NewGuid().ToString(), STORY_DATA_IDENTIFIER);

0 commit comments

Comments
 (0)