private void SynchronizeProjects() { var existedItemsWithDifferentGuid = Cache.Instance.ScanProjects.Where( x => SyncProjects.Any(sp => sp.ProjectName == x.ProjectName && sp.ProjectGuid != x.ProjectGuid)); var newItems = SyncProjects.Where(x => Cache.Instance.ScanProjects.All(sp => sp.ProjectName != x.ProjectName)); var deleteItems = Cache.Instance.ScanProjects.Where(x => SyncProjects.All(sp => sp.ProjectName != x.ProjectName)).ToList(); foreach (var deleteItem in deleteItems) { Cache.Instance.ScanProjects.Remove(deleteItem); } foreach (var existedItem in existedItemsWithDifferentGuid) { var syncItem = SyncProjects.FirstOrDefault(x => x.ProjectName == existedItem.ProjectName); if (syncItem != null) { existedItem.ProjectGuid = syncItem.ProjectGuid; } } foreach (var newItem in newItems) { Cache.Instance.ScanProjects.Add(new ProjectScanItem { ProjectName = newItem.ProjectName, ProjectGuid = newItem.ProjectGuid }); ProjectService.ProcessNewProject(newItem); } }
public void AddNewProjectSync() { if (_selectedProjectGuidParsed == Guid.Empty) { return; } if (SyncProjects.All(x => x.ProjectGuid != _selectedProjectGuidParsed)) { var existed = SyncProjects.FirstOrDefault(x => x.ProjectName == SelectedProject); if (existed != null) { existed.ProjectGuid = _selectedProjectGuidParsed; var control = SyncProjectControls.FirstOrDefault(x => x.Item.ProjectName == existed.ProjectName); if (control != null) { control.Item = existed; } } else { SyncProjects.Add(new ProjectSyncItem { ProjectGuid = _selectedProjectGuidParsed, ProjectName = SelectedProject }); } } SelectedProject = null; SelectedProjectGuid = null; OnPropertyChanged(nameof(IsSaveEnabled)); }