Ejemplo n.º 1
0
        /// <summary>
        /// This method retrieves the email messages from a folder in the current user's mailbox
        /// </summary>
        /// <param name="folderId">The ID of the target folder, optional</param>
        /// <param name="startIndex">The startIndex (0 based) of the email messages to retrieve, optional</param>
        /// <param name="includeAttachments">Defines whether to include attachments or not, optional</param>
        /// <returns>A page of up to 10 email messages in the folder</returns>
        public static List <MailMessage> ListMessages(String folderId = null, Int32 startIndex = 0, Boolean includeAttachments = false)
        {
            String targetUrl = null;

            if (!String.IsNullOrEmpty(folderId))
            {
                targetUrl = String.Format("{0}me/mailFolders/{1}/messages?$skip={2}",
                                          MicrosoftGraphHelper.MicrosoftGraphV1BaseUri,
                                          folderId, startIndex);
            }
            else
            {
                targetUrl = String.Format("{0}me/messages?$skip={1}",
                                          MicrosoftGraphHelper.MicrosoftGraphV1BaseUri,
                                          startIndex);
            }

            String jsonResponse = MicrosoftGraphHelper.MakeGetRequestForString(targetUrl);

            var messages = JsonConvert.DeserializeObject <MailMessageList>(jsonResponse);

            if (includeAttachments)
            {
                foreach (var message in messages.Messages.Where(m => m.HasAttachments))
                {
                    message.LoadAttachments();
                }
            }

            return(messages.Messages);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// This method returns the root folder of the personal drive of the current user
        /// </summary>
        /// <returns>The root folder of the current user's personal drive</returns>
        public static DriveItem GetUserPersonalDriveRoot()
        {
            String jsonResponse = MicrosoftGraphHelper.MakeGetRequestForString(
                String.Format("{0}me/drive/root",
                              MicrosoftGraphHelper.MicrosoftGraphV1BaseUri));

            var folder = JsonConvert.DeserializeObject <DriveItem>(jsonResponse);

            return(folder);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// This method returns the personal drive of the current user
        /// </summary>
        /// <returns>The current user's personal drive</returns>
        public static Drive GetUserPersonalDrive()
        {
            String jsonResponse = MicrosoftGraphHelper.MakeGetRequestForString(
                String.Format("{0}me/drive",
                              MicrosoftGraphHelper.MicrosoftGraphV1BaseUri));

            var drive = JsonConvert.DeserializeObject <Drive>(jsonResponse);

            return(drive);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// This method retrieves the OneDrive for Business of an Office 365 Group
        /// </summary>
        /// <param name="groupId">The ID of the group</param>
        /// <returns>The OneDrive for Business of an Office 365 Group</returns>
        public static Drive GetUnifiedGroupDrive(String groupId)
        {
            String jsonResponse = MicrosoftGraphHelper.MakeGetRequestForString(
                String.Format("{0}groups/{1}/drive",
                              MicrosoftGraphHelper.MicrosoftGraphV1BaseUri,
                              groupId));

            var drive = JsonConvert.DeserializeObject <Drive>(jsonResponse);

            return(drive);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// This method returns a list of permissions for a specific DriveItem in OneDrive for Business
        /// </summary>
        /// <param name="driveItemId">The ID of the DriveItem</param>
        /// <returns>The list of permissions for the object</returns>
        public static List <Permission> GetDriveItemPermissions(String driveItemId)
        {
            var jsonResponse = MicrosoftGraphHelper.MakeGetRequestForString(
                String.Format("{0}me/drive/items/{1}/permissions",
                              MicrosoftGraphHelper.MicrosoftGraphV1BaseUri,
                              driveItemId));

            var permissions = JsonConvert.DeserializeObject <PermissionList>(jsonResponse);

            return(permissions.Permissions);
        }
Ejemplo n.º 6
0
        /// <summary>
        /// This method retrieves a single contact
        /// </summary>
        /// <param name="contactId">The ID of the contact to retrieve</param>
        /// <returns>The retrieved contact</returns>
        public static Contact GetContact(String contactId)
        {
            String jsonResponse = MicrosoftGraphHelper.MakeGetRequestForString(
                String.Format("{0}me/contacts/{1}",
                              MicrosoftGraphHelper.MicrosoftGraphV1BaseUri,
                              contactId));

            var contact = JsonConvert.DeserializeObject <Contact>(jsonResponse);

            return(contact);
        }
Ejemplo n.º 7
0
        /// <summary>
        /// This method retrieves the contacts of the current user
        /// </summary>
        /// <param name="startIndex">The startIndex (0 based) of the contacts to retrieve, optional</param>
        /// <returns>A page of up to 10 contacts</returns>
        public static List <Contact> ListContacts(Int32 startIndex = 0)
        {
            String jsonResponse = MicrosoftGraphHelper.MakeGetRequestForString(
                String.Format("{0}me/contacts?$skip={1}",
                              MicrosoftGraphHelper.MicrosoftGraphV1BaseUri,
                              startIndex));

            var contactList = JsonConvert.DeserializeObject <ContactList>(jsonResponse);

            return(contactList.Contacts);
        }
Ejemplo n.º 8
0
        /// <summary>
        /// This method retrieves the list of threads of an Office 365 Group
        /// </summary>
        /// <param name="groupId">The ID of the group</param>
        /// <returns>The threads of an Office 365 Group</returns>
        public static List <ConversationThread> ListUnifiedGroupThreads(String groupId)
        {
            String jsonResponse = MicrosoftGraphHelper.MakeGetRequestForString(
                String.Format("{0}groups/{1}/threads",
                              MicrosoftGraphHelper.MicrosoftGraphV1BaseUri,
                              groupId));

            var conversationThreadsList = JsonConvert.DeserializeObject <ConversationThreadsList>(jsonResponse);

            return(conversationThreadsList.Threads);
        }
Ejemplo n.º 9
0
        /// <summary>
        /// This method retrieves an event from a calendar
        /// </summary>
        /// <param name="calendarId">The ID of the calendar</param>
        /// <param name="eventId">The ID of the event</param>
        /// <returns>The retrieved event</returns>
        public static Event GetEvent(String calendarId, String eventId)
        {
            String jsonResponse = MicrosoftGraphHelper.MakeGetRequestForString(
                String.Format("{0}me/calendars/{1}/events/{2}",
                              MicrosoftGraphHelper.MicrosoftGraphV1BaseUri,
                              calendarId, eventId));

            var calendarEvent = JsonConvert.DeserializeObject <Event>(jsonResponse);

            return(calendarEvent);
        }
Ejemplo n.º 10
0
        /// <summary>
        /// This method retrieves a specific group registered in Azure AD
        /// </summary>
        /// <param name="groupId">The ID of the group</param>
        /// <returns>The group instance</returns>
        public static Group GetGroup(String groupId)
        {
            String jsonResponse = MicrosoftGraphHelper.MakeGetRequestForString(
                String.Format("{0}groups/{1}",
                              MicrosoftGraphHelper.MicrosoftGraphV1BaseUri,
                              groupId));

            var group = JsonConvert.DeserializeObject <Group>(jsonResponse);

            return(group);
        }
Ejemplo n.º 11
0
        /// <summary>
        /// This method retrieves the list of Security Groups
        /// </summary>
        /// <param name="numberOfItems">Defines the TOP number of items to retrieve</param>
        /// <returns>The list of Security Groups</returns>
        public static List <Group> ListSecurityGroups(Int32 numberOfItems = 100)
        {
            String jsonResponse = MicrosoftGraphHelper.MakeGetRequestForString(
                String.Format("{0}groups?$filter=SecurityEnabled%20eq%20true" +
                              "&$top={1}", MicrosoftGraphHelper.MicrosoftGraphV1BaseUri,
                              numberOfItems));

            var groupsList = JsonConvert.DeserializeObject <GroupsList>(jsonResponse);

            return(groupsList.Groups);
        }
Ejemplo n.º 12
0
        /// <summary>
        /// This method retrieves the list of Office 365 Groups
        /// </summary>
        /// <param name="numberOfItems">Defines the TOP number of items to retrieve</param>
        /// <returns>The list of Office 365 Groups</returns>
        public static List <Group> ListUnifiedGroups(Int32 numberOfItems = 100)
        {
            String jsonResponse = MicrosoftGraphHelper.MakeGetRequestForString(
                String.Format("{0}groups?$filter=groupTypes/any(gt:%20gt%20eq%20'Unified')" +
                              "&$top={1}", MicrosoftGraphHelper.MicrosoftGraphV1BaseUri,
                              numberOfItems));

            var groupsList = JsonConvert.DeserializeObject <GroupsList>(jsonResponse);

            return(groupsList.Groups);
        }
Ejemplo n.º 13
0
        /// <summary>
        /// This method retrieves the calendar of an Office 365 Group
        /// </summary>
        /// <param name="groupId">The ID of the group</param>
        /// <returns>The calendar of an Office 365 Group</returns>
        public static Calendar GetUnifiedGroupCalendar(String groupId)
        {
            String jsonResponse = MicrosoftGraphHelper.MakeGetRequestForString(
                String.Format("{0}groups/{1}/calendar",
                              MicrosoftGraphHelper.MicrosoftGraphV1BaseUri,
                              groupId));

            var calendar = JsonConvert.DeserializeObject <Calendar>(jsonResponse);

            return(calendar);
        }
Ejemplo n.º 14
0
        /// <summary>
        /// This method returns the groups of a user
        /// </summary>
        /// <param name="upn">The UPN of the user</param>
        /// <returns>The user's groups</returns>
        public static List <Group> GetUserGroups(String upn)
        {
            String jsonResponse = MicrosoftGraphHelper.MakeGetRequestForString(
                String.Format("{0}users/{1}/memberOf",
                              MicrosoftGraphHelper.MicrosoftGraphV1BaseUri,
                              upn));

            var userGroups = JsonConvert.DeserializeObject <GroupsList>(jsonResponse);

            return(userGroups.Groups);
        }
Ejemplo n.º 15
0
        /// <summary>
        /// This method retrieves the email folders of the current user
        /// </summary>
        /// <param name="startIndex">The startIndex (0 based) of the folders to retrieve, optional</param>
        /// <returns>A page of up to 10 email folders</returns>
        public static List <MailFolder> ListFolders(Int32 startIndex = 0)
        {
            String jsonResponse = MicrosoftGraphHelper.MakeGetRequestForString(
                String.Format("{0}me/mailFolders?$skip={1}",
                              MicrosoftGraphHelper.MicrosoftGraphV1BaseUri,
                              startIndex));

            var folders = JsonConvert.DeserializeObject <MailFolderList>(jsonResponse);

            return(folders.Folders);
        }
Ejemplo n.º 16
0
        /// <summary>
        /// This method returns the manager of a user
        /// </summary>
        /// <param name="upn">The UPN of the user</param>
        /// <returns>The user's manager</returns>
        public static User GetUserManager(String upn)
        {
            String jsonResponse = MicrosoftGraphHelper.MakeGetRequestForString(
                String.Format("{0}users/{1}/manager",
                              MicrosoftGraphHelper.MicrosoftGraphV1BaseUri,
                              upn));

            var user = JsonConvert.DeserializeObject <User>(jsonResponse);

            return(user);
        }
Ejemplo n.º 17
0
        /// <summary>
        /// This method retrieves the calendars of the current user
        /// </summary>
        /// <param name="id">The ID of the calendar</param>
        /// <returns>The calendar</returns>
        public static Calendar GetCalendar(String id)
        {
            String jsonResponse = MicrosoftGraphHelper.MakeGetRequestForString(
                String.Format("{0}me/calendars/{1}",
                              MicrosoftGraphHelper.MicrosoftGraphV1BaseUri,
                              id));

            var calendar = JsonConvert.DeserializeObject <Calendar>(jsonResponse);

            return(calendar);
        }
Ejemplo n.º 18
0
        /// <summary>
        /// This method retrieves the list of all the external users for a tenant
        /// </summary>
        /// <param name="numberOfItems">Defines the TOP number of items to retrieve</param>
        /// <returns>The list of externa users in Azure AD</returns>
        public static List <User> ListExternalUsers(Int32 numberOfItems = 100)
        {
            String jsonResponse = MicrosoftGraphHelper.MakeGetRequestForString(
                String.Format("{0}users?$filter=userType%20eq%20'Guest'&$top={1}",
                              MicrosoftGraphHelper.MicrosoftGraphV1BaseUri,
                              numberOfItems));

            var usersList = JsonConvert.DeserializeObject <UsersList>(jsonResponse);

            return(usersList.Users);
        }
Ejemplo n.º 19
0
        /// <summary>
        /// This method retrieves the list of owners of a group
        /// </summary>
        /// <param name="groupId">The ID of the group</param>
        /// <returns>The owners of the group</returns>
        public static List <User> ListGroupOwners(String groupId)
        {
            String jsonResponse = MicrosoftGraphHelper.MakeGetRequestForString(
                String.Format("{0}groups/{1}/owners",
                              MicrosoftGraphHelper.MicrosoftGraphV1BaseUri,
                              groupId));

            var usersList = JsonConvert.DeserializeObject <UsersList>(jsonResponse);

            return(usersList.Users);
        }
Ejemplo n.º 20
0
        /// <summary>
        /// This method returns the direct reports of a user
        /// </summary>
        /// <param name="upn">The UPN of the user</param>
        /// <returns>The user's direct reports</returns>
        public static List <User> GetUserDirectReports(String upn)
        {
            String jsonResponse = MicrosoftGraphHelper.MakeGetRequestForString(
                String.Format("{0}users/{1}/directReports",
                              MicrosoftGraphHelper.MicrosoftGraphV1BaseUri,
                              upn));

            var directReports = JsonConvert.DeserializeObject <UsersList>(jsonResponse);

            return(directReports.Users);
        }
Ejemplo n.º 21
0
        /// <summary>
        /// This method returns a specific file by ID
        /// </summary>
        /// <param name="driveId">The ID of the target drive</param>
        /// <param name="fileId">The ID of the target file</param>
        /// <returns>The file object</returns>
        public static DriveItem GetFile(String driveId, String fileId)
        {
            String jsonResponse = MicrosoftGraphHelper.MakeGetRequestForString(
                String.Format("{0}drives/{1}/items/{2}",
                              MicrosoftGraphHelper.MicrosoftGraphV1BaseUri,
                              driveId,
                              fileId));

            var driveItem = JsonConvert.DeserializeObject <DriveItem>(jsonResponse);

            return(driveItem);
        }
Ejemplo n.º 22
0
        /// <summary>
        /// This method retrieves the events of an Office 365 Group calendar
        /// </summary>
        /// <param name="groupId">The ID of the group</param>
        /// <param name="startIndex">The startIndex (0 based) of the items to retrieve, optional</param>
        /// <returns>A page of up to 10 events</returns>
        public static List <Event> ListUnifiedGroupEvents(String groupId, Int32 startIndex = 0)
        {
            String jsonResponse = MicrosoftGraphHelper.MakeGetRequestForString(
                String.Format("{0}groups/{1}/events?$skip={2}",
                              MicrosoftGraphHelper.MicrosoftGraphV1BaseUri,
                              groupId,
                              startIndex));

            var eventList = JsonConvert.DeserializeObject <EventList>(jsonResponse);

            return(eventList.Events);
        }
Ejemplo n.º 23
0
        /// <summary>
        /// This method returns the thumbnails of a specific file by ID
        /// </summary>
        /// <param name="driveId">The ID of the target drive</param>
        /// <param name="fileId">The ID of the target file</param>
        /// <returns>The file thumbnails for the specific file</returns>
        public static ThumbnailSet GetFileThumbnails(String driveId, String fileId)
        {
            String jsonResponse = MicrosoftGraphHelper.MakeGetRequestForString(
                String.Format("{0}drives/{1}/items/{2}/thumbnails",
                              MicrosoftGraphHelper.MicrosoftGraphV1BaseUri,
                              driveId,
                              fileId));

            var thumbnails = JsonConvert.DeserializeObject <ThumbnailSetResponse>(jsonResponse);

            return(thumbnails.Value.Count > 0 ? thumbnails.Value[0] : null);
        }
Ejemplo n.º 24
0
        /// <summary>
        /// Extension method to load the content of a specific attachment
        /// </summary>
        /// <param name="message">The target email message</param>
        public static void EnsureContent(this MailAttachment attachment)
        {
            String jsonResponse = MicrosoftGraphHelper.MakeGetRequestForString(
                String.Format("{0}me/messages/{1}/attachments/{2}",
                              MicrosoftGraphHelper.MicrosoftGraphV1BaseUri,
                              attachment.ParentMessageId,
                              attachment.Id));

            var result = JsonConvert.DeserializeObject <MailAttachment>(jsonResponse);

            attachment.Content = result.Content;
        }
Ejemplo n.º 25
0
        /// <summary>
        /// This method retrieves the list of users working in a specific department
        /// </summary>
        /// <param name="department">The department to filter the users on</param>
        /// <param name="numberOfItems">Defines the TOP number of items to retrieve</param>
        /// <returns>The list of users in Azure AD</returns>
        public static List <User> ListUsersByDepartment(String department,
                                                        Int32 numberOfItems = 100)
        {
            String jsonResponse = MicrosoftGraphHelper.MakeGetRequestForString(
                String.Format("{0}users?$filter=department%20eq%20'{1}'&$top={2}",
                              MicrosoftGraphHelper.MicrosoftGraphV1BaseUri,
                              department,
                              numberOfItems));

            var usersList = JsonConvert.DeserializeObject <UsersList>(jsonResponse);

            return(usersList.Users);
        }
Ejemplo n.º 26
0
        /// <summary>
        /// This method retrieves a single post of a conversation thread for an Office 365 Group
        /// </summary>
        /// <param name="groupId">The ID of the thread</param>
        /// <param name="threadId">The ID of the thread</param>
        /// <param name="postId">The ID of the post</param>
        /// <returns>The post of the conversation thread for an Office 365 Group</returns>
        public static ConversationThreadPost GetUnifiedGroupThreadPost(String groupId, String threadId, String postId)
        {
            String jsonResponse = MicrosoftGraphHelper.MakeGetRequestForString(
                String.Format("{0}groups/{1}/threads/{2}/posts/{3}",
                              MicrosoftGraphHelper.MicrosoftGraphV1BaseUri,
                              groupId,
                              threadId,
                              postId));

            var conversationThreadPost = JsonConvert.DeserializeObject <ConversationThreadPost>(jsonResponse);

            return(conversationThreadPost);
        }
Ejemplo n.º 27
0
        /// <summary>
        /// This method returns a thumbnail by size of a specific file by ID
        /// </summary>
        /// <param name="driveId">The ID of the target drive</param>
        /// <param name="fileId">The ID of the target file</param>
        /// <param name="size">The size of the target thumbnail</param>
        /// <returns>The file thumbnails for the specific file</returns>
        public static Thumbnail GetFileThumbnail(String driveId, String fileId, ThumbnailSize size)
        {
            String jsonResponse = MicrosoftGraphHelper.MakeGetRequestForString(
                String.Format("{0}drives/{1}/items/{2}/thumbnails/0/{3}",
                              MicrosoftGraphHelper.MicrosoftGraphV1BaseUri,
                              driveId,
                              fileId,
                              size.ToString().ToLower()));

            var thumbnail = JsonConvert.DeserializeObject <Thumbnail>(jsonResponse);

            return(thumbnail);
        }
Ejemplo n.º 28
0
        /// <summary>
        /// This method returns the children items of a specific folder
        /// </summary>
        /// <param name="driveId">The ID of the target drive</param>
        /// <param name="folderId">The ID of the target folder</param>
        /// <param name="numberOfItems">The number of items to retrieve</param>
        /// <returns>The children items</returns>
        public static List <DriveItem> ListFolderChildren(String driveId, String folderId, Int32 numberOfItems = 100)
        {
            String jsonResponse = MicrosoftGraphHelper.MakeGetRequestForString(
                String.Format("{0}drives/{1}/items/{2}/children?$top={3}",
                              MicrosoftGraphHelper.MicrosoftGraphV1BaseUri,
                              driveId,
                              folderId,
                              numberOfItems));

            var driveItems = JsonConvert.DeserializeObject <DriveItemList>(jsonResponse);

            return(driveItems.DriveItems);
        }
Ejemplo n.º 29
0
        /// <summary>
        /// Retrieves the events of an Office 365 Group calendar within a specific date range
        /// </summary>
        /// <param name="groupId">The ID of the group</param>
        /// <param name="startDate">The start date of the range</param>
        /// <param name="endDate">The end date of the range</param>
        /// <param name="startIndex">The startIndex (0 based) of the items to retrieve, optional</param>
        /// <returns>A page of up to 10 events</returns>
        public static List <Event> ListUnifiedGroupEvents(String groupId, DateTime startDate,
                                                          DateTime endDate, Int32 startIndex = 0)
        {
            String jsonResponse = MicrosoftGraphHelper.MakeGetRequestForString(
                String.Format("{0}groups/{1}/calendarView?startDateTime={2:o}&endDateTime={3:o}&$skip={4}",
                              MicrosoftGraphHelper.MicrosoftGraphV1BaseUri,
                              groupId,
                              startDate.ToUniversalTime(),
                              endDate.ToUniversalTime(),
                              startIndex));

            var eventList = JsonConvert.DeserializeObject <EventList>(jsonResponse);

            return(eventList.Events);
        }
Ejemplo n.º 30
0
        /// <summary>
        /// This method retrieves an email message from the current user's mailbox
        /// </summary>
        /// <param name="id">The ID of the email message</param>
        /// <param name="includeAttachments">Defines whether to include attachments or not, optional</param>
        /// <returns>The email message</returns>
        public static MailMessage GetMessage(String id, Boolean includeAttachments = false)
        {
            String jsonResponse = MicrosoftGraphHelper.MakeGetRequestForString(
                String.Format("{0}me/messages/{1}",
                              MicrosoftGraphHelper.MicrosoftGraphV1BaseUri,
                              id));

            var message = JsonConvert.DeserializeObject <MailMessage>(jsonResponse);

            if (includeAttachments)
            {
                // message.LoadAttachments();
                message.LoadAttachmentsSmartly();
            }

            return(message);
        }