Skip to content

Commit

Permalink
Wrap cursor wait state in a try (good suggestion bclothier).
Browse files Browse the repository at this point in the history
  • Loading branch information
comintern committed Dec 19, 2018
1 parent d30fc88 commit c4524c7
Showing 1 changed file with 61 additions and 42 deletions.
Expand Up @@ -55,64 +55,83 @@ public AddRemoveReferencesPresenter Create(ProjectDeclaration project)
return null;
}

Cursor.Current = Cursors.WaitCursor;
AddRemoveReferencesModel model = null;

var refs = new Dictionary<RegisteredLibraryKey, RegisteredLibraryInfo>();
// Iterating the returned libraries here instead of just .ToDictionary() using because we can't trust that the registry doesn't contain errors.
foreach (var reference in _finder.FindRegisteredLibraries())
try
{
if (refs.ContainsKey(reference.UniqueId))
{
_logger.Warn($"Duplicate registry definition for {reference.Guid} version {reference.Version}.");
continue;
}
refs.Add(reference.UniqueId, reference);
}
Cursor.Current = Cursors.WaitCursor;

var models = new Dictionary<RegisteredLibraryKey, ReferenceModel>();
using (var references = project.Project?.References)
{
if (references is null)
var refs = new Dictionary<RegisteredLibraryKey, RegisteredLibraryInfo>();
// Iterating the returned libraries here instead of just .ToDictionary() using because we can't trust that the registry doesn't contain errors.
foreach (var reference in _finder.FindRegisteredLibraries())
{
return null;
if (refs.ContainsKey(reference.UniqueId))
{
_logger.Warn(
$"Duplicate registry definition for {reference.Guid} version {reference.Version}.");
continue;
}

refs.Add(reference.UniqueId, reference);
}
var priority = 1;
foreach (var reference in references)

var models = new Dictionary<RegisteredLibraryKey, ReferenceModel>();
using (var references = project.Project?.References)
{
var guid = Guid.TryParse(reference.Guid, out var result) ? result : Guid.Empty;
var libraryId = new RegisteredLibraryKey(guid, reference.Major, reference.Minor);
if (references is null)
{
return null;
}

var priority = 1;
foreach (var reference in references)
{
var guid = Guid.TryParse(reference.Guid, out var result) ? result : Guid.Empty;
var libraryId = new RegisteredLibraryKey(guid, reference.Major, reference.Minor);

// TODO: If for some reason the VBA reference is broken, we could technically use this to repair it. Just a thought...
var adding = refs.ContainsKey(libraryId)
? new ReferenceModel(refs[libraryId], reference, priority++)
: new ReferenceModel(reference, priority++);
// TODO: If for some reason the VBA reference is broken, we could technically use this to repair it. Just a thought...
var adding = refs.ContainsKey(libraryId)
? new ReferenceModel(refs[libraryId], reference, priority++)
: new ReferenceModel(reference, priority++);

adding.IsUsed = adding.IsBuiltIn || _state.DeclarationFinder.IsReferenceUsedInProject(project, adding.ToReferenceInfo());
adding.IsUsed = adding.IsBuiltIn ||
_state.DeclarationFinder.IsReferenceUsedInProject(project,
adding.ToReferenceInfo());

models.Add(libraryId, adding);
reference.Dispose();
models.Add(libraryId, adding);
reference.Dispose();
}
}

foreach (var reference in refs.Where(library =>
(_use64BitPaths || library.Value.Has32BitVersion) &&
!models.ContainsKey(library.Key)))
{
models.Add(reference.Key, new ReferenceModel(reference.Value));
}
}

foreach (var reference in refs.Where(library =>
(_use64BitPaths || library.Value.Has32BitVersion) &&
!models.ContainsKey(library.Key)))
var settings = _settings.Create();
model = new AddRemoveReferencesModel(project, models.Values, settings);
if (AddRemoveReferencesViewModel.HostHasProjects)
{
model.References.AddRange(GetUserProjectFolderModels(model.Settings).Where(proj =>
!model.References.Any(item =>
item.FullPath.Equals(proj.FullPath, StringComparison.OrdinalIgnoreCase))));
}
}
catch (Exception ex)
{
models.Add(reference.Key, new ReferenceModel(reference.Value));
_logger.Warn(ex, "Unexpected exception attempting to create AddRemoveReferencesModel.");
}

var settings = _settings.Create();
var model = new AddRemoveReferencesModel(project, models.Values, settings);
if (AddRemoveReferencesViewModel.HostHasProjects)
finally
{
model.References.AddRange(GetUserProjectFolderModels(model.Settings).Where(proj =>
!model.References.Any(item =>
item.FullPath.Equals(proj.FullPath, StringComparison.OrdinalIgnoreCase))));
Cursor.Current = Cursors.Default;
}

Cursor.Current = Cursors.Default;

return new AddRemoveReferencesPresenter(new AddRemoveReferencesDialog(new AddRemoveReferencesViewModel(model, _reconciler, _browser)));
return (model != null)
? new AddRemoveReferencesPresenter(
new AddRemoveReferencesDialog(new AddRemoveReferencesViewModel(model, _reconciler, _browser)))
: null;
}

private IEnumerable<ReferenceModel> GetUserProjectFolderModels(IReferenceSettings settings)
Expand Down

0 comments on commit c4524c7

Please sign in to comment.