コード例 #1
0
        public async Task CreateUnifiedGroupsForPropertiesAsync(GraphServiceClient graphService, string graphAccessToken)
        {
            var properties = Task.Run(() => CSOMUtil.GetListItems(clientContext, "Properties"));

            var members = new List <Graph.User>();

            {
                var queryUsers = (await graphService.Users.Request().Filter(string.Format("mail eq '{0}'", AppSettings.DispatcherEmail)).GetAsync()).CurrentPage;
                var dispatcher = queryUsers.Count > 0 ? queryUsers[0]: null;
                if (dispatcher == null)
                {
                    return;
                }

                var inspectors = await graphService.GetGroupMembersAsync("Inspectors");

                var repairPeople = await graphService.GetGroupMembersAsync("Repair People");

                if (dispatcher != null)
                {
                    members.Add(dispatcher);
                }
                members.AddRange(inspectors);
                members.AddRange(repairPeople);
            }

            foreach (var property in await properties)
            {
                var group = await graphService.GetGroupByDisplayNameAsync((string)property["Title"]);

                if (group == null)
                {
                    group = await CreateUnifiedGroupForPropertyAsync(graphService, graphAccessToken, property, members);
                }

                property["sl_group"] = group.Id;
                property.Update();
            }
            clientContext.ExecuteQuery();

            await UpdateGroupPhotoAsync(graphService);
        }
コード例 #2
0
        public async Task <bool> UploadFileAsync(GraphServiceClient graphService, UploadFileModel model)
        {
            try
            {
                var graphToken    = AuthenticationHelper.GetGraphAccessTokenAsync();
                var propertyGroup = await graphService.GetGroupByDisplayNameAsync(model.PropertyTitle);

                if (propertyGroup == null)
                {
                    return(false);
                }

                DriveItem driveItem = new DriveItem();
                driveItem.Name = model.File.FileName;
                driveItem.File = new Microsoft.Graph.File();
                driveItem      = await graphService.Groups[propertyGroup.Id].Drive.Root.Children.Request().AddAsync(driveItem);
                await graphService.Groups[propertyGroup.Id].Drive.Items[driveItem.Id].Content.Request().PutAsync <DriveItem>(model.File.InputStream);
            }
            catch (Exception el)
            {
                throw el;
            }
            return(false);
        }
コード例 #3
0
        public async Task CreateUnifiedGroupsForPropertiesAsync(GraphServiceClient graphService, string graphAccessToken)
        {
            var properties = Task.Run(() => CSOMUtil.GetListItems(clientContext, "Properties"));

            var members = new List<Graph.User>();
            {
                var queryUsers = (await graphService.Users.Request().Filter(string.Format("mail eq '{0}'", AppSettings.DispatcherEmail)).GetAsync()).CurrentPage;
                var dispatcher = queryUsers.Count>0 ? queryUsers[0]: null;
                if (dispatcher == null) return;

                var inspectors = await graphService.GetGroupMembersAsync("Inspectors");
                var repairPeople = await graphService.GetGroupMembersAsync("Repair People");

                if (dispatcher != null) members.Add(dispatcher);
                members.AddRange(inspectors);
                members.AddRange(repairPeople);
            }

            foreach (var property in await properties)
            {
                var group = await graphService.GetGroupByDisplayNameAsync((string)property["Title"]);
                if (group == null)
                {
                    group = await CreateUnifiedGroupForPropertyAsync(graphService, graphAccessToken, property, members);
                }

                property["sl_group"] = group.Id;
                property.Update();
            }
            clientContext.ExecuteQuery();

            await UpdateGroupPhotoAsync(graphService);
        }
コード例 #4
0
        public async Task<bool> UploadFileAsync(GraphServiceClient graphService, UploadFileModel model)
        {
            try
            {
                var graphToken = AuthenticationHelper.GetGraphAccessTokenAsync();
                var propertyGroup = await graphService.GetGroupByDisplayNameAsync(model.PropertyTitle);

                if (propertyGroup == null) return false;

                DriveItem driveItem = new DriveItem();
                driveItem.Name = model.File.FileName;
                driveItem.File = new Microsoft.Graph.File();
                driveItem = await graphService.Groups[propertyGroup.Id].Drive.Root.Children.Request().AddAsync(driveItem);
                await graphService.Groups[propertyGroup.Id].Drive.Items[driveItem.Id].Content.Request().PutAsync<DriveItem>(model.File.InputStream);
            }
            catch (Exception el)
            {
                throw el;
            }
            return false;
        }