Skip to content

Commit

Permalink
(GH-267) Fixing Code Analysis errors
Browse files Browse the repository at this point in the history
  • Loading branch information
gep13 committed Apr 16, 2016
1 parent ecd29a1 commit c380be1
Show file tree
Hide file tree
Showing 8 changed files with 47 additions and 53 deletions.
4 changes: 2 additions & 2 deletions Source/ChocolateyGui/Models/PackageSearchOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,15 @@ public PackageSearchOptions(int pageSize, int currentPage)
this._currentPage = currentPage;
}

public PackageSearchOptions(int pageSize, int currentPage, string sortColumn, bool sortDescending)
public PackageSearchOptions(int pageSize, int currentPage, string sortColumn)
: this()
{
this._pageSize = pageSize;
this._currentPage = currentPage;
this._sortColumn = sortColumn;
}

public PackageSearchOptions(int pageSize, int currentPage, string sortColumn, bool sortDescending, bool includePrerelease, bool includeAllVersions, bool matchWord)
public PackageSearchOptions(int pageSize, int currentPage, string sortColumn, bool includePrerelease, bool includeAllVersions, bool matchWord)
: this()
{
this._pageSize = pageSize;
Expand Down
26 changes: 13 additions & 13 deletions Source/ChocolateyGui/Services/PackageServices/BasePackageService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public abstract class BasePackageService
/// Synchronizes the GetPackages method.
/// </summary>
internal readonly AsyncLock GetInstalledLock;

private static MemoryCache cache = MemoryCache.Default;
private ILogService logService;
private IProgressService progressService;
Expand Down Expand Up @@ -112,11 +112,21 @@ public IChocolateyConfigurationProvider ChocolateyConfigurationProvider
}
}

public void ClearPackageCache()
public static void ClearPackageCache()
{
Cache.Remove(LocalPackagesCacheKeyName);
}

public static void PopulatePackages(IPackageViewModel packageInfo, ICollection<IPackageViewModel> packages)
{
if (packages == null)
{
throw new ArgumentNullException("packages");
}

packages.Add(packageInfo);
}

public void NotifyPackagesChanged(PackagesChangedEventType command, string packageId = "", string packageVersion = "")
{
var packagesUpdated = this.PackagesUpdated;
Expand All @@ -133,16 +143,6 @@ public void NotifyPackagesChanged(PackagesChangedEventType command, string packa
}
}

public void PopulatePackages(IPackageViewModel packageInfo, ICollection<IPackageViewModel> packages)
{
if (packages == null)
{
throw new ArgumentNullException("packages");
}

packages.Add(packageInfo);
}

public async Task InstalledPackage(string id, SemanticVersion version)
{
ClearPackageCache();
Expand All @@ -157,7 +157,7 @@ public async Task UninstalledPackage(string id, SemanticVersion version)
await this.ProgressService.StopLoading();
}

public async Task UpdatedPackage(string id, SemanticVersion oldVersion, SemanticVersion newVersion)
public async Task UpdatedPackage(string id)
{
ClearPackageCache();
this.NotifyPackagesChanged(PackagesChangedEventType.Updated, id);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ public class ChocolateyPackageService : BasePackageService, IChocolateyPackageSe
private readonly Func<IPackageViewModel> _packageFactory;

public ChocolateyPackageService(
IProgressService progressService,
Func<Type, ILogService> logServiceFunc,
IProgressService progressService,
Func<Type, ILogService> logServiceFunc,
IChocolateyConfigurationProvider chocolateyConfigurationProvider,
Func<IPackageViewModel> packageFactory)
: base(progressService, logServiceFunc, chocolateyConfigurationProvider)
Expand All @@ -42,7 +42,7 @@ public async Task<IEnumerable<IPackageViewModel>> GetInstalledPackages(bool forc
if (!force)
{
packages = CachedPackages;

if (packages != null)
{
return packages;
Expand All @@ -64,7 +64,7 @@ public async Task<IEnumerable<IPackageViewModel>> GetInstalledPackages(bool forc
packages = packageResults
.Select(
package => AutoMapper.Mapper.Map(package.Package, _packageFactory()))
.Select(package =>
.Select(package =>
{
package.IsInstalled = true;
return package;
Expand Down Expand Up @@ -103,7 +103,7 @@ public async Task InstallPackage(string id, SemanticVersion version = null, Uri
config.Force = true;
}
});

await choco.RunAsync();

var newPackage =
Expand Down Expand Up @@ -132,7 +132,7 @@ public async Task UninstallPackage(string id, SemanticVersion version, bool forc
config.Version = version.ToString();
}
});

await choco.RunAsync();

await GetInstalledPackages(force: true);
Expand All @@ -147,7 +147,7 @@ public async Task UpdatePackage(string id, Uri source = null)
{
StartProgressDialog("Updating", "Updating package", id);

var oldPackage = (await GetInstalledPackages()).FirstOrDefault(package => package.Id == id);
(await GetInstalledPackages()).FirstOrDefault(package => package.Id == id);

var choco = Lets.GetChocolatey();
choco.Set(config =>
Expand All @@ -156,11 +156,12 @@ public async Task UpdatePackage(string id, Uri source = null)
config.PackageNames = id;
config.AllowUnofficialBuild = true;
});

await choco.RunAsync();

var newPackage = (await GetInstalledPackages(true)).FirstOrDefault(package => package.Id == id);
(await GetInstalledPackages(true)).FirstOrDefault(package => package.Id == id);

await UpdatedPackage(id, oldPackage != null ? oldPackage.Version : null, newPackage != null ? newPackage.Version : null);
await UpdatedPackage(id);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,25 +16,14 @@ namespace ChocolateyGui.Services
public class RemotePackageService : IRemotePackageService
{
private readonly IProgressService _progressService;
private readonly ISourceService _sourceService;
private readonly Func<IPackageViewModel> _packageFactory;
private readonly ILogService _logService;

public RemotePackageService(
IProgressService progressService,
ISourceService sourceService,
Func<IPackageViewModel> packageFactory,
Func<Type, ILogService> logFunc)
IProgressService progressService,
Func<IPackageViewModel> packageFactory)
{
if (logFunc == null)
{
throw new ArgumentNullException("logFunc");
}

_progressService = progressService;
_sourceService = sourceService;
_packageFactory = packageFactory;
_logService = logFunc(typeof(RemotePackageService));
}

public async Task<PackageSearchResults> Search(string query)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ private async void LoadPackages()
{
_hasLoaded = false;

var result = await _remotePackageService.Search(SearchQuery, new PackageSearchOptions(PageSize, CurrentPage - 1, SortColumn, SortDescending, IncludePrerelease, IncludeAllVersions, MatchWord));
var result = await _remotePackageService.Search(SearchQuery, new PackageSearchOptions(PageSize, CurrentPage - 1, SortColumn, IncludePrerelease, IncludeAllVersions, MatchWord));
var installed = await _chocolateyPackageService.GetInstalledPackages();

PageCount = result.TotalCount / PageSize;
Expand Down
20 changes: 16 additions & 4 deletions Source/ChocolateyGui/ViewModels/Items/PackageViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,8 @@ public class PackageViewModel : ObservableBase, IPackageViewModel, IWeakEventLis
private int _versionDownloadCount;

public PackageViewModel(
IRemotePackageService remotePackageService,
IChocolateyPackageService chocolateyService,
IRemotePackageService remotePackageService,
IChocolateyPackageService chocolateyService,
INavigationService navigationService)
{
_remotePackageService = remotePackageService;
Expand All @@ -123,6 +123,12 @@ public string Copyright
set { SetPropertyValue(ref _copyright, value); }
}

public DateTime Created
{
get { return _created; }
set { SetPropertyValue(ref _created, value); }
}

public string Dependencies
{
get { return _dependencies; }
Expand Down Expand Up @@ -189,6 +195,12 @@ public string Language
set { SetPropertyValue(ref _language, value); }
}

public DateTime LastUpdated
{
get { return _lastUpdated; }
set { SetPropertyValue(ref _lastUpdated, value); }
}

public SemanticVersion LatestVersion
{
get { return _latestVersion; }
Expand Down Expand Up @@ -346,8 +358,8 @@ public async Task RetrieveLatestVersion()
}

_cache.Set(
string.Format("LatestVersion_{0}", Id),
version,
string.Format("LatestVersion_{0}", Id),
version,
new CacheItemPolicy
{
AbsoluteExpiration = DateTime.Now.AddHours(1)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ namespace ChocolateyGui.ViewModels.Windows

public class MainWindowViewModel : ObservableBase, IMainWindowViewModel, IWeakEventListener
{
private readonly Lazy<IRemotePackageService> _packageService;
private readonly IProgressService _progressService;
private readonly ISourceService _sourceService;
private readonly IVersionNumberProvider _versionNumberProvider;
Expand All @@ -28,16 +27,15 @@ public class MainWindowViewModel : ObservableBase, IMainWindowViewModel, IWeakEv
private string _newSourceUrl;
private SourceViewModel _selectedSourceViewModel;

public MainWindowViewModel(ISourceService sourceService, IProgressService progressService, Lazy<IRemotePackageService> packageServiceLazy, IVersionNumberProvider versionNumberProvider)
public MainWindowViewModel(ISourceService sourceService, IProgressService progressService, IVersionNumberProvider versionNumberProvider)
{
if (sourceService == null)
{
throw new ArgumentNullException("sourceService");
}

this._sourceService = sourceService;
this._progressService = progressService;
this._packageService = packageServiceLazy;
this._progressService = progressService;
this._versionNumberProvider = versionNumberProvider;
this.Sources = new ObservableCollection<SourceViewModel>(this._sourceService.GetSources());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@

namespace ChocolateyGui.Views.Controls
{
using System;
using System.Windows.Input;
using ChocolateyGui.Services;
using ChocolateyGui.ViewModels.Controls;
using ChocolateyGui.ViewModels.Items;

Expand All @@ -17,15 +15,11 @@ namespace ChocolateyGui.Views.Controls
/// </summary>
public partial class LocalSourceControl
{
private readonly Lazy<INavigationService> _navigationService;

public LocalSourceControl(ILocalSourceControlViewModel viewModel, Lazy<INavigationService> navigationService)
public LocalSourceControl(ILocalSourceControlViewModel viewModel)
{
InitializeComponent();
DataContext = viewModel;

this._navigationService = navigationService;

Loaded += viewModel.Loaded;
}

Expand Down

0 comments on commit c380be1

Please sign in to comment.