Exemple #1
0
        private void SendNewCustomImages(SirenOfShameSettings settings, List <InstanceUserDto> changedUsers)
        {
            var changedPeople = changedUsers
                                .Select(changedUser => settings.FindPersonByRawName(changedUser.RawName))
                                .Where(person => person != null);

            var changedPeopleWithUnUploadedCustomImages = changedPeople
                                                          .Where(i => !string.IsNullOrEmpty(i.AvatarImageName) && !i.AvatarImageUploaded);

            foreach (var person in changedPeopleWithUnUploadedCustomImages)
            {
                var webClientXml = new WebClientXml();
                AddSosOnlineCredentials(settings, webClientXml);
                webClientXml.Add("AvatarImageName", person.AvatarImageName);
                var avatarImagePath = SirenOfShameSettings.GetAvatarImagePath(person.AvatarImageName);
                var imageAsBytes    = File.ReadAllBytes(avatarImagePath);
                var imageAsString   = Convert.ToBase64String(imageAsBytes);
                webClientXml.Add("AvatarImage", imageAsString);
                string url     = SOS_URL + "/ApiV1/AddImage";
                var    person1 = person;
                webClientXml.UploadValuesAndReturnStringAsync(url, s => _log.Debug("Uploaded " + person1.AvatarImageName), ex => _log.Error("Error uploading image for " + person1.AvatarImageName), settings.GetSosOnlineProxy());
                person.AvatarImageUploaded = true;
                settings.Save();
            }
        }
        public int LoadAvatarFromFile(string avatarImageName, ImageList avatarImageList)
        {
            if (avatarImageList.Images.ContainsKey(avatarImageName))
            {
                return(avatarImageList.Images.IndexOfKey(avatarImageName));
            }

            try
            {
                var imagePath = SirenOfShameSettings.GetAvatarImagePath(avatarImageName);
                var image     = Image.FromFile(imagePath);
                avatarImageList.Images.Add(avatarImageName, image);
                return(avatarImageList.Images.Count - 1);
            }
            catch (Exception ex)
            {
                _log.Error("Unable to retrieve avatar, defaulting to a random avatar", ex);
                return(new Random(avatarImageName.GetHashCode()).Next(0, 19));
            }
        }