/// <summary> /// Method to invoke when the AddCFile command is executed. /// </summary> private async Task OnAddCFileExecuteAsync() { try { var openFileService = ServiceLocator.Default.ResolveType <IOpenFileService>(); openFileService.Filter = "Kflop C Program File| *.c"; if (!string.IsNullOrEmpty(LastCProgramPath)) { openFileService.InitialDirectory = Path.GetDirectoryName(LastCProgramPath); openFileService.FileName = Path.GetFileNameWithoutExtension(LastCProgramPath); } else { openFileService.InitialDirectory = Path.GetFullPath(Path.Combine(Environment.CurrentDirectory, @"..\..\C Programs")); } if (openFileService.DetermineFile()) { List <int> freeThreads = new List <int>() { 1, 2, 3, 4, 5, 6, 7 }; freeThreads.DefaultIfEmpty(-1); foreach (ThreadCProgram cp in ThreadCPrograms) { if (cp.ThreadID != null) { freeThreads.Remove(cp.ThreadID.Value); } } int id = freeThreads.FirstOrDefault(); if (id == -1) { LogTo.Warning("All threads in use, resuing thread ID 1 for C Program {1}.", openFileService.FileName); } ThreadCProgram cprog = new ThreadCProgram() { FilePath = openFileService.FileName, ThreadID = id }; this.ThreadCPrograms.Add(cprog); LastCProgramPath = openFileService.FileName; ViewModelCommandManager.InvalidateCommands(true); LogTo.Info("Loaded C Program from: {0}", LastCProgramPath); } } catch (Exception ex) { string errmsg = string.Format("Error loading C program: {0}", ex.Message); LogTo.Error(errmsg); await Shared.Utility.ShowErrorMsgAsync(this, errmsg); } }
public void OnSelectedCProgramPropertyChanged(object sender, PropertyChangedEventArgs e) { ThreadCProgram cp = sender as ThreadCProgram; if (cp == null) { return; } if (e.PropertyName == "ThreadID") { ListCollectionView list = (ListCollectionView)FreeThreads; //this always returns 'null' (for no thread id) plus the unused ids //list.Filter = new Predicate<object>(x => !((int?)x).HasValue || ThreadCPrograms.FirstOrDefault(c=>c.ThreadID == (int?)x) == null || (int?)x==SelectedCProgram.ThreadID); list.Filter = new Predicate <object>(x => (!((int?)x).HasValue || ThreadCPrograms.FirstOrDefault(c => c.ThreadID == (int?)x) == null) && (int?)x != SelectedCProgram.ThreadID); list.Refresh(); ViewModelCommandManager.InvalidateCommands(true); } }