private static Tuple <byte[], ImageFormat> QuadrasizeImage(byte[] adImage)
        {
            Image image    = ImageHelper.ByteArrayToImage(adImage);
            Image newImage = ImageHelper.QuadrasizeImage(image);

            byte[]      tfsImage       = ImageHelper.ImageToByteArray(newImage, System.Drawing.Imaging.ImageFormat.Png);
            ImageFormat tfsImageFormat = ImageFormatHelper.GetImageFormat(tfsImage);

            return(Tuple.Create(tfsImage, tfsImageFormat));
        }
Esempio n. 2
0
        public static void ChangeImage(string tfsUri)
        {
            var teamFoundationServer = new TfsTeamProjectCollection(new Uri(tfsUri));
            var service  = teamFoundationServer.GetService <FilteredIdentityService>();
            var service2 = teamFoundationServer.GetService <IIdentityManagementService2>();

            foreach (TeamFoundationIdentity identity in service.SearchForUsers(""))
            {
                if (!identity.IsActive)
                {
                    continue;
                }

                byte[] adImage = ADHelper.GetImageFromAD(identity.UniqueName);
                if (adImage == null)
                {
                    continue;
                }


                //to quadrasize image
                Image image    = ImageHelper.ByteArrayToImage(adImage);
                var   newImage = ImageHelper.QuadrasizeImage(image);

                //store image local
                ImageFormat adImageFormat = ImageFormatHelper.GetImageFormat(adImage);
                DumpImageToLocalPath(identity, adImageFormat, newImage);

                //Convert back to byte[]
                byte[]      tfsImage       = ImageHelper.ImageToByteArray(newImage, System.Drawing.Imaging.ImageFormat.Png);
                ImageFormat tfsImageFormat = ImageFormatHelper.GetImageFormat(tfsImage);

                identity.SetProperty("Microsoft.TeamFoundation.Identity.Image.Data", tfsImage);
                identity.SetProperty("Microsoft.TeamFoundation.Identity.Image.Type", "image/" + tfsImageFormat.ToString());
                identity.SetProperty("Microsoft.TeamFoundation.Identity.Image.Id", Guid.NewGuid().ToByteArray());
                identity.SetProperty("Microsoft.TeamFoundation.Identity.CandidateImage.Data", null);
                identity.SetProperty("Microsoft.TeamFoundation.Identity.CandidateImage.UploadDate", null);

                service2.UpdateExtendedProperties(identity);
            }
        }