private void UseSelectedTemplateExecute() { var templateName = m_selectedTemplatesfileName; var settings = SettingsHelper.GetTemplateSettings(templateName); if (settings.OrionSetting != null) { MainOrionViewModel = settings.OrionSetting; } else { if (SettingsHelper.IsTemplateAvaliable()) { var names = SettingsHelper.GetTemplatesNames(); foreach (var tempName in names) { CheckTemplate(tempName); } } MainOrionViewModel = new OrionSetupViewModel(); } MainOrionViewModel.Parent = this; if (settings.LeonCommunicationSetting != null) { LeonCommunication = settings.LeonCommunicationSetting; } else { LeonCommunication = new LeonCommunication(); } }
void DatabaseSetup_DbSelected(object sender) { this.InitDatabaseMode = false; if (DisableDb != null) { DisableDb(this); } var settings = SettingsHelper.GetSettings(); if (settings.OrionSetting != null) { MainOrionViewModel = settings.OrionSetting; } else { MainOrionViewModel = new OrionSetupViewModel(); } MainOrionViewModel.Parent = this; if (settings.LeonCommunicationSetting != null) { LeonCommunication = settings.LeonCommunicationSetting; } else { LeonCommunication = new LeonCommunication(); } }
void TemplateSetup_SelectTemplate(object sender) { var setupTemplate = sender as DatabaseSetup; m_selectedTemplatesfileName = setupTemplate.ChoosenTemplateName; this.InitTemplateMode = false; this.InitDatabaseMode = false; LeonCommunication = new LeonCommunication(); MainOrionViewModel = new OrionSetupViewModel(); MainOrionViewModel.Parent = this; if (DisableDb != null) { DisableDb(this); } }
public void StartProductionExecute() { SaveSettingsExecute(); var settings = SettingsHelper.GetSettings(); LeonCommunication.NewLeonRegistrations += LeonCommunication_NewLeonRegistrations; Leon = new LeonViewModel(); Leon.LoadFromDb(); LeonCommunication.StartLeonExecute(); OrionTeamsSetupViewModel = new OrionTeamsSetupViewModel(Leon, MainOrionViewModel); this.OrionTeamsSetupViewModel.GenerateOrionTeamsExecute(); OrionCommunicationViewModel = new OrionCommunicationViewModel(OrionTeamsSetupViewModel, MainOrionViewModel); this.OrionCommunicationViewModel.StartOrionCommunication(); this.OrionResultViewModel = new OrionResultViewModel(settings.OrionSetting); this.OrionResultViewModel.LoadFromDb(); this.OrionTeamsSetupViewModel.MoveRegistrations += OrionTeamsSetupViewModel_MoveRegistrations; this.OrionResultViewModel.NewOrionResults += OrionResultViewModel_NewOrionResults; m_orionResultUpdater = new OrionResultUpdater(settings.OrionSetting); m_orionResultUpdater.SetResultTypeOnOrionResult(OrionResultViewModel.OrionResults); this.OrionResultViewModel.StartOrionCommunication(); var minneRange = settings.OrionSetting.OrionViewModels.SelectMany(o => o.RangeViews).SingleOrDefault(r => r.MinneShooting == true); if (minneRange != null) { if (string.IsNullOrEmpty(minneRange.CommunicationSetup.SelectedPath)) { minneRange.CommunicationSetup.SelectedPath = LeonCommunication.CommunicationSetup.SelectedPath; //LeonCommunication.SetMinnePath(minneRange.CommunicationSetup.SelectedPath); } this.m_minneViewModel = new MinneViewModel(minneRange.CommunicationSetup); this.m_minneViewModel.LoadFromDB(); this.m_minneViewModel.StartReadNewRegistrations(); } ProductionMode = true; MainOrionViewModel.SendPropChanged(); }
internal List <string> Validate(LeonCommunication lc) { var errors = lc.Validate(); if (SortedRanges == null) { errors.Add("Det finnes ingen holdid generert "); return(errors); } var ids = SortedRanges.GroupBy(r => r.RangeId); var duplicateIds = ids.Where(i => i.Count() > 1); if (duplicateIds.Any()) { errors.Add("Duplikate holdid'er: " + string.Join(",", duplicateIds.Select(d => d.Key))); } // FirstTarget > LastTarget foreach (var rangeViewModel in SortedRanges) { if (rangeViewModel.RangeType == RangeType.Shooting && rangeViewModel.FirstTarget > rangeViewModel.LastTarget) { errors.Add("Første skivenr er høyere enn siste for holdid " + rangeViewModel.RangeId); } } // Targets overlap foreach (var orionViewModel in m_orionViewModels) { var sortedRanges = orionViewModel.RangeViews.Where(h => h.RangeType == RangeType.Shooting).OrderBy(r => r.FirstTarget).ThenBy(r => r.LastTarget).ToList(); for (int i = 0; i < sortedRanges.Count() - 1; i++) { if (sortedRanges[i].FirstTarget >= sortedRanges[i + 1].FirstTarget) { errors.Add("Overlappende skivenummer for holid'er: " + sortedRanges[i].RangeId + ", " + sortedRanges[i + 1].RangeId); } else if (sortedRanges[i].LastTarget >= sortedRanges[i + 1].FirstTarget) { errors.Add("Overlappende skivenummer for holid'er: " + sortedRanges[i].RangeId + ", " + sortedRanges[i + 1].RangeId); } } } // Number of targets per range not equal var groupByNumOfTargets = SortedRanges.Where(r => r.RangeType == RangeType.Shooting).GroupBy(r => r.LastTarget - r.FirstTarget); if (groupByNumOfTargets.Count() > 1) { errors.Add("Forskjellig antall skiver på hold"); } // Shooting ranges with zero counting shoots foreach (var rangeViewModel in SortedRanges) { if (rangeViewModel.RangeType == RangeType.Shooting && rangeViewModel.CountingShoots < 1) { errors.Add(string.Format("Tellende skudd = {0} for HoldId= {1}", rangeViewModel.CountingShoots, rangeViewModel.RangeId)); } } // Missing and duplicate communication catalogs var catalogs = new Dictionary <string, string>(); if (!string.IsNullOrWhiteSpace(lc.CommunicationSetup.SelectedPath)) { catalogs.Add(lc.CommunicationSetup.SelectedPath, "Leon kommunikasjon"); } foreach (var orionViewModel in m_orionViewModels) { if (string.IsNullOrWhiteSpace(orionViewModel.CommunicationSetup.SelectedPath)) { errors.Add("Kommunikasjonskatalog ikke satt opp for orion " + orionViewModel.OrionId); } else if (!Directory.Exists(orionViewModel.CommunicationSetup.SelectedPath)) { errors.Add("Kommunikasjonskatalog for orion finnes ikke: " + orionViewModel.CommunicationSetup.SelectedPath); } else if (catalogs.ContainsKey(orionViewModel.CommunicationSetup.SelectedPath)) { errors.Add(string.Format("Kommunikasjonskatalog \"{0}\" for OrionId = {1} er allerede i bruk for {2}", orionViewModel.CommunicationSetup.SelectedPath, orionViewModel.OrionId, catalogs[orionViewModel.CommunicationSetup.SelectedPath])); } else { catalogs.Add(orionViewModel.CommunicationSetup.SelectedPath, string.Format("OrionId = {0}", orionViewModel.OrionId)); } } var minnerange = SortedRanges.Where(r => r.MinneShooting == true); { foreach (var rangeViewModel in minnerange) { if (string.IsNullOrWhiteSpace(rangeViewModel.CommunicationSetup.SelectedPath)) { errors.Add("Kommunikasjonskatalog ikke satt opp for minneskyting"); } else if (!Directory.Exists(rangeViewModel.CommunicationSetup.SelectedPath)) { errors.Add("Kommunikasjonskatalog for minneskyting finnes ikke: " + rangeViewModel.CommunicationSetup.SelectedPath); } if (catalogs.ContainsKey(rangeViewModel.CommunicationSetup.SelectedPath)) { errors.Add(string.Format("Kommunikasjonskatalog \"{0}\" for minne på HoldId = {1} er allerede i bruk for {2}", rangeViewModel.CommunicationSetup.SelectedPath, rangeViewModel.RangeId, catalogs[rangeViewModel.CommunicationSetup.SelectedPath])); } else { catalogs.Add(rangeViewModel.CommunicationSetup.SelectedPath, string.Format("OrionId = {0}", rangeViewModel.RangeId)); } } } return(errors); }