示例#1
0
        private void NotifyIfNewAchievements(IList <BuildStatus> changedBuildStatuses)
        {
            if (!changedBuildStatuses.Any(i => i.IsWorkingOrBroken()))
            {
                return;
            }
            var visiblePeopleWithNewChanges = from changedBuildStatus in changedBuildStatuses
                                              join person in _settings.VisiblePeople on changedBuildStatus.RequestedBy equals person.RawName
                                              where changedBuildStatus.IsWorkingOrBroken()
                                              select new
            {
                Person = person,
                Build  = changedBuildStatus
            };

            foreach (var personWithNewChange in visiblePeopleWithNewChanges)
            {
                var newAchievements = personWithNewChange.Person.CalculateNewAchievements(_settings, personWithNewChange.Build);
                List <AchievementLookup> achievements = newAchievements.ToList();
                if (achievements.Any())
                {
                    personWithNewChange.Person.AddAchievements(achievements);
                    InvokeNewAchievement(personWithNewChange.Person, achievements);
                }
            }
            // this is required because achievements often write to settings e.g. cumulative build time
            _settings.Save();
        }
示例#2
0
 private void SaveSosOnlineSettings()
 {
     _settings.SosOnlineUsername = _sosOnlineLogin.Text;
     _settings.SetSosOnlinePassword(_sosOnlinePassword.Text);
     _settings.SosOnlineProxyUrl      = _proxyUrl.Text;
     _settings.SosOnlineProxyUsername = _proxyUsername.Text;
     _settings.SetSosOnlineProxyPassword(_proxyPassword.Text);
     _settings.Save();
 }
        public virtual void TryToGetAndSendNewSosOnlineAlerts(SirenOfShameSettings settings, DateTime now, Action <NewAlertEventArgs> invokeNewAlert)
        {
            if (!settings.GetSosOnlineContent())
            {
                return;
            }

            bool weHaveAlreadyCheckedForAlertsToday = settings.LastCheckedForAlert != null && (now - settings.LastCheckedForAlert.Value).TotalHours < 24;

            if (weHaveAlreadyCheckedForAlertsToday)
            {
                return;
            }

            settings.LastCheckedForAlert = DateTime.Now;
            settings.Save();
            var webClient = GetWebClient();

            webClient.DownloadStringCompleted += (s, e) =>
            {
                try
                {
                    if (e.Error != null)
                    {
                        _log.Error("Error retrieving alert", e.Error);
                        return;
                    }
                    NewAlertEventArgs args = new NewAlertEventArgs();
                    var successParsing     = args.Instantiate(e.Result);
                    if (successParsing)
                    {
                        if (settings.SoftwareInstanceId == null)
                        {
                            settings.SoftwareInstanceId = args.SoftwareInstanceId;
                            settings.Save();
                        }
                        if (settings.AlertClosed == null || args.AlertDate > settings.AlertClosed)
                        {
                            invokeNewAlert(args);
                        }
                    }
                }
                catch (Exception ex)
                {
                    _log.Error("Error retrieving alert", ex);
                }
            };
            string url = string.Format(SOS_URL + "/GetAlert?SirenEverConnected={0}&SoftwareInstanceId={1}&ServerType={2}&Version={3}",
                                       settings.SirenEverConnected,
                                       settings.SoftwareInstanceId,
                                       string.Join(",", settings.CiEntryPointSettings.Select(cip => cip.Name)),
                                       Application.ProductVersion
                                       );

            webClient.DownloadStringAsync(new Uri(url));
        }
示例#4
0
 private void AvatarPickerOnOnAvatarClicked(object sender, AvatarClickedArgs args)
 {
     if (_personSetting == null)
     {
         return;
     }
     _settings.Save();
     avatar1.SetImage(_personSetting, _avatarImageList);
     InvokeOnOnUserChangedAvatarId();
 }
示例#5
0
        private void SirenofShameDeviceConnected(object sender, EventArgs e)
        {
            bool firstTimeSirenHasEverBeenConnected = !_settings.SirenEverConnected;

            if (firstTimeSirenHasEverBeenConnected)
            {
                _settings.SirenEverConnected = true;
                _settings.ResetSirenSettings();
                _settings.Save();
            }

            EnableSirenMenuItem(true);
        }
示例#6
0
        private void AvatarPickerOnOnAvatarClicked(object sender, AvatarClickedArgs args)
        {
            if (_personSetting == null)
            {
                return;
            }
            int newImageIndex = args.Index;

            _personSetting.AvatarId = newImageIndex;
            _settings.Save();
            avatar1.ImageIndex = newImageIndex;
            InvokeOnOnUserChangedAvatarId(newImageIndex);
        }
示例#7
0
        private void AddClick(object sender, EventArgs e)
        {
            Rule rule = _rule ?? new Rule();

            rule.TriggerType          = ((KeyValuePair <TriggerType, string>)_when.SelectedItem).Key;
            rule.BuildDefinitionId    = GetBuildDefinitionId();
            rule.TriggerPerson        = _whoIsAnyone.Checked ? null : _who.Text;
            rule.AlertType            = GetAlertType();
            rule.AudioDuration        = GetAudioDuration();
            rule.LightsDuration       = GetLightsDuration();
            rule.InheritAudioSettings = _inheritAudio.Checked;
            rule.InheritLedSettings   = _inheritLightSetting.Checked;
            rule.WindowsAudioLocation = _windowsAudio.SelectedItem == null ? null : ((AudioFile)_windowsAudio.SelectedItem).Location;

            if (!rule.InheritLedSettings)
            {
                rule.LedPattern = GetLedPattern();
            }
            if (!rule.InheritAudioSettings)
            {
                rule.AudioPattern = GetAudioPattern();
            }

            if (_rule == null)
            {
                _settings.Rules.Add(rule);
            }
            _settings.Save();
            Close();
        }
示例#8
0
        public Sound AddSound(SirenOfShameSettings settings, string fileNameAndPath, string fileNameAndExtension)
        {
            var existingSound = settings.Sounds.FirstOrDefault(i => i.DisplayName == fileNameAndExtension);

            if (existingSound != null)
            {
                DeleteSound(settings, existingSound);
            }

            var soundsDir     = GetSoundsDirAndEnsureExists();
            var fileNameAsWav = Path.ChangeExtension(fileNameAndExtension, "wav");
            var destinationFileNameAndPath = Path.Combine(soundsDir, fileNameAsWav);

            CopyOrConvertToWav(fileNameAndPath, destinationFileNameAndPath);

            Sound sound = new Sound
            {
                Location    = destinationFileNameAndPath,
                DisplayName = fileNameAndExtension
            };

            settings.Sounds.Add(sound);
            settings.Save();
            return(sound);
        }
示例#9
0
        private void OkClick(object sender, EventArgs e)
        {
            _settings.PollInterval = _pollInterval.Value;
            UpdateLocation updateLocation = GetUpdateLocation();

            _settings.UpdateLocationOther = null;
            _settings.UpdateLocationOther = _updateLocationOtherLocation.Text;
            _settings.UpdateLocation      = updateLocation;

            SetShowAchievements();
            _settings.SaveUserIAm(_userIAm);
            SetMiscSection();

            _settings.Save();
            Close();
        }
示例#10
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();
            }
        }
示例#11
0
        private void SaveResultsClick(object sender, EventArgs e)
        {
            var  newHighWaterMarkStr = _result.Text;
            long newHighwaterMarkInt;

            if (long.TryParse(newHighWaterMarkStr, out newHighwaterMarkInt))
            {
                var dateTime = new DateTime(newHighwaterMarkInt);
                if (dateTime.Year < 2012 || dateTime.Year > 3000)
                {
                    InvalidHighWaterMark();
                }
                else
                {
                    _settings.SosOnlineHighWaterMark = dateTime.Ticks;
                    _settings.Save();
                    if (ParentForm == null)
                    {
                        throw new Exception("ParentForm was null");
                    }
                    ParentForm.Close();
                }
            }
            else
            {
                InvalidHighWaterMark();
            }
        }
 public void ResetOnly()
 {
     _settings.Backup();
     foreach (var person in _settings.People)
     {
         person.TotalBuilds                            = 0;
         person.FailedBuilds                           = 0;
         person.Achievements                           = new List <AchievementSetting>();
         person.CumulativeBuildTime                    = 0;
         person.CurrentBuildRatio                      = 0;
         person.CurrentSuccessInARow                   = 0;
         person.LowestBuildRatioAfter50Builds          = 0;
         person.MaxBuildsInOneDay                      = 0;
         person.NumberOfTimesFixedSomeoneElsesBuild    = 0;
         person.NumberOfTimesPerformedBackToBackBuilds = 0;
     }
     _settings.Save();
 }
示例#13
0
        private void _configureSiren_Click(object sender, EventArgs e)
        {
            const string         fileName = "HardwareTestGui.Settings.xml";
            SirenOfShameSettings settings = SirenOfShameSettings.GetAppSettings(fileName);
            ConfigureSirenDialog dlg      = new ConfigureSirenDialog(settings, Program.SirenOfShameDevice);

            if (dlg.ShowDialog(this) == DialogResult.OK)
            {
                settings.Save(fileName);
            }
        }
示例#14
0
 private void DeleteClick(object sender, System.EventArgs e)
 {
     if (_servers.SelectedItem != null)
     {
         _dirty = true;
         var ciEntryPointSetting = (CiEntryPointSetting)_servers.SelectedItem;
         _settings.CiEntryPointSettings.Remove(ciEntryPointSetting);
         _settings.Save();
         Close();
     }
 }
示例#15
0
        private void RecalculateAchievements()
        {
            var sosDb       = new SosDb();
            var allSettings = sosDb
                              .ReadAll(_settings.GetAllActiveBuildDefinitions())
                              .OrderBy(i => i.StartedTime)
                              .ToList();

            foreach (var person in _settings.People)
            {
                person.TotalBuilds  = 0;
                person.FailedBuilds = 0;
                person.Achievements.Clear();
                person.CumulativeBuildTime = 0;
            }
            _status.Visible = true;
            var allActiveBuildDefinitionsOrderedChronoligically = new List <BuildStatus>();
            var buildCount = allSettings.Count;

            progressBar1.Maximum = buildCount;
            foreach (var buildStatus in allSettings)
            {
                _status.Text = string.Format("Processing {0:d}", buildStatus.StartedTime);
                progressBar1.Value++;
                var person = _settings.People.FirstOrDefault(i => i.RawName == buildStatus.RequestedBy);
                if (person == null)
                {
                    _log.Error("Could not find " + buildStatus.RequestedBy);
                    continue;
                }
                person.TotalBuilds++;
                if (buildStatus.BuildStatusEnum == BuildStatusEnum.Broken)
                {
                    person.FailedBuilds++;
                }
                allActiveBuildDefinitionsOrderedChronoligically.Add(buildStatus);
                var newAchievements = person
                                      .CalculateNewAchievements(_settings, buildStatus, allActiveBuildDefinitionsOrderedChronoligically)
                                      .ToList();

                if (!newAchievements.Any())
                {
                    continue;
                }

                person.AddAchievements(newAchievements);
                foreach (var achievementLookup in newAchievements)
                {
                    NewAchievement.ShowForm(_settings, achievementLookup, person, this, modal: true);
                }
            }
            _settings.Save();
        }
示例#16
0
        private void DeleteClick(object sender, EventArgs e)
        {
            if (_rulesList.SelectedItems.Count == 0)
            {
                return;
            }
            ListViewItem i    = _rulesList.SelectedItems[0];
            var          rule = _settings.Rules.First(r => i.Tag == r);

            _settings.Rules.Remove(rule);
            DataBind();
            _settings.Save();
        }
示例#17
0
        private void DeleteClick(object sender, System.EventArgs e)
        {
            if (_mappingList.SelectedItems.Count == 0)
            {
                return;
            }
            ListViewItem lvi     = _mappingList.SelectedItems[0];
            var          mapping = _settings.UserMappings.First(r => lvi.Tag == r);

            _settings.UserMappings.Remove(mapping);
            RefreshMappingList();
            _settings.Save();
        }
示例#18
0
        private static void UpdateStatsInSettings(BuildStatus buildStatus, SirenOfShameSettings settings)
        {
            if (string.IsNullOrEmpty(buildStatus.RequestedBy))
            {
                return;
            }
            var personSetting = settings.FindAddPerson(buildStatus.RequestedBy);

            if (buildStatus.BuildStatusEnum == BuildStatusEnum.Broken)
            {
                personSetting.FailedBuilds++;
            }
            personSetting.TotalBuilds++;
            settings.Save();
        }
示例#19
0
        private void AddClick(object sender, System.EventArgs e)
        {
            var pretendItsActually = (string)_pretendItsActually.SelectedItem;
            var whenISee           = (string)_whenISee.SelectedItem;

            if (!string.IsNullOrEmpty(whenISee) && !string.IsNullOrEmpty(pretendItsActually) && whenISee != pretendItsActually)
            {
                var whenISeePerson = _settings.FindPersonByRawName(whenISee);
                whenISeePerson.Hidden = true;
                _settings.UserMappings.Add(new UserMapping
                {
                    WhenISee           = whenISee,
                    PretendItsActually = pretendItsActually
                });
                _settings.Save();
            }
            Close();
            Dispose();
        }
示例#20
0
        public void DeleteSound(SirenOfShameSettings settings, Sound sound)
        {
            try
            {
                settings.Sounds.Remove(sound);
                settings.Save();

                var sosAppDataFolder  = SirenOfShameSettings.GetSosAppDataFolder();
                var fileIsInOurFolder = sound.Location.StartsWith(sosAppDataFolder);
                // should be, but we can't assume someone hasn't tampered with the settings file
                if (fileIsInOurFolder)
                {
                    File.Delete(sound.Location);
                }
            }
            catch (Exception ex)
            {
                _log.Warn("Unable to delete file", ex);
            }
        }
示例#21
0
 protected override void OnClosing(System.ComponentModel.CancelEventArgs e)
 {
     if (_settings == null)
     {
         throw new Exception("_settings was null");
     }
     if (_alwaysShowNewAchievements.Checked)
     {
         _settings.AchievementAlertPreference = AchievementAlertPreferenceEnum.Always;
     }
     if (_neverShowAchievements.Checked)
     {
         _settings.AchievementAlertPreference = AchievementAlertPreferenceEnum.Never;
     }
     if (_onlyShowMyAchievements.Checked)
     {
         TrySetMyRawNameFromUserIAm(e);
     }
     _settings.Save();
 }
示例#22
0
 private void AlwaysOfflineCheckedChanged(object sender, EventArgs e)
 {
     LoadChildControl();
     _settings.SosOnlineAlwaysOffline = _alwaysOffline.Checked;
     _settings.Save();
 }