コード例 #1
0
        private void UpdateBasicSpoAttribute(ClientContext clientContext, UpnIdentifier upn, string attributeName, string value)
        {
            var           targetUser    = O365Settings.SpoProfilePrefix + upn.Upn;
            PeopleManager peopleManager = new PeopleManager(clientContext);

            peopleManager.SetSingleValueProfileProperty(targetUser, attributeName, value.ToString());
        }
コード例 #2
0
        public SampleEmployee(EmployeeIdIdentifier employeeId, UpnIdentifier upnIdentifier)
            : this()
        {
            this.EmployeeId = employeeId;
            this.Upn        = upnIdentifier;

            this.Identifiers.Add(this.EmployeeId);
            this.Identifiers.Add(this.Upn);
        }
コード例 #3
0
        private SampleEmployee CreateNewPerson(UpnIdentifier identifier)
        {
            EmployeeIdIdentifier id = new EmployeeIdIdentifier(DateTime.UtcNow.Ticks.ToString());

            var emp = new SampleEmployee(id, identifier);

            emp.Properties["compensation"] = "$100,000";
            emp.Properties["startdate"]    = "2-May-2008";

            if (identifier.IdentifierType.Matches(_secondaryIdentifierType))
            {
                Logger?.Debug($"Setting upn: {identifier}");

                emp.Upn = new UpnIdentifier(identifier.StringValue);
            }

            return(emp);
        }
コード例 #4
0
        private void UpdateExoPhoto(UpnIdentifier upn, Stream photoStream)
        {
            try
            {
                Logger?.Debug($"Resizing image");

                var newImage = FormatAndSizeImageForExo(photoStream);

                // upload
                var service = GetExoClientContext();

                Logger?.Debug($"Uploading photo to Exo");

                service.SetUserPhoto(upn.Upn, newImage);

                Console.WriteLine("Uploaded photo to Exo");
            }
            catch (Exception ex)
            {
                Logger?.Error($"Problem resizing/uploading EXO photo. Message: {ex.Message}");
                throw new O365Exception($"Problem resizing/uploading EXO photo. Message: {ex.Message}", ex);
            }
        }
コード例 #5
0
        private void UpdateSpoPhoto(ClientContext clientContext, UpnIdentifier upn, Stream photoStream)
        {
            const string library = @"/User Photos/Profile Pictures";

            var mySitePhotos = new List <ProfilePhoto>()
            {
                new ProfilePhoto(PhotoSize.S), new ProfilePhoto(PhotoSize.M), new ProfilePhoto(PhotoSize.L)
            };

            var mySiteHostClientContext = GetSpoClientContextForSite(SpoSite.MySite);

            try
            {
                foreach (var mySitePhoto in mySitePhotos)
                {
                    Logger?.Debug($"Resizing image: {mySitePhoto.Size.ToString()} to {mySitePhoto.MaxWidth} max width");

                    using (Stream thumb = ImageHelper.ResizeImage(photoStream, mySitePhoto.MaxWidth))
                    {
                        if (thumb != null)
                        {
                            var url = mySitePhoto.Url(upn.Upn, library);

                            Logger?.Debug($"Uploading {mySitePhoto.Size.ToString()} photo to {url}");

                            Microsoft.SharePoint.Client.File.SaveBinaryDirect(mySiteHostClientContext, url, thumb, true);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Logger?.Error($"Problem resizing/uploading photo. Message: {ex.Message}");
                throw new O365Exception($"Problem resizing/uploading photo. Message: {ex.Message}", ex);
            }

            try
            {
                Logger?.Debug($"Setting the PictureUrl and SPS-PicturePlaceholderState");

                var relativeMedPhotoPath = mySitePhotos.First(p => p.Size == PhotoSize.M).Url(upn.Upn, library);
                var medPhotoPath         = new Uri(new Uri(mySiteHostClientContext.Url), relativeMedPhotoPath).AbsoluteUri;

                // update the profile with the URL for the photo and the placeholderstate
                this.UpdateBasicSpoAttribute(clientContext, upn, "PictureURL", medPhotoPath);
                this.UpdateBasicSpoAttribute(clientContext, upn, "SPS-PicturePlaceholderState", "0");

                // make the changes
                clientContext.ExecuteQueryWithIncrementalRetry(SpoRetries, SpoBackoff, Logger);
            }
            catch (MaximumRetryAttemptedException ex)
            {
                // Exception handling for the Maximum Retry Attempted
                Logger?.Error($"[O365] Max retries / throttle for SPO reached updating SPO photo. Message {ex.Message}");
                throw new O365Exception($"Max retries / throttle for SPO reached. Message {ex.Message}", ex);
            }
            catch (Exception ex)
            {
                Logger?.Error($"Problem setting the PictureUrl and SPS-PicturePlaceholderState. Message: {ex.Message}");
                throw new O365Exception($"Problem setting the PictureUrl and SPS-PicturePlaceholderState. Message: {ex.Message}", ex);
            }
        }
コード例 #6
0
 public void UpdateAttribute(UpnIdentifier upn, AdAttribute propertyName, object propertyValue)
 {
     this.SetAdInfo(upn, propertyName, propertyValue);
 }
コード例 #7
0
 public O365Profile(UpnIdentifier upn)
 {
     this.Properties = new Dictionary <string, object>();
     this.Upn        = upn;
 }