Skip to content

Commit

Permalink
(GH-267) Fixing InspectCode issues
Browse files Browse the repository at this point in the history
  • Loading branch information
gep13 committed Apr 16, 2016
1 parent c380be1 commit 5d570ef
Show file tree
Hide file tree
Showing 14 changed files with 74 additions and 75 deletions.
Binary file modified BuildScripts/dupfinder.config
Binary file not shown.
11 changes: 5 additions & 6 deletions Source/ChocolateyGui/Controls/Dialogs/ChocolateyDialog.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,9 @@
xmlns:MahDialogs="clr-namespace:MahApps.Metro.Controls.Dialogs;assembly=MahApps.Metro"
xmlns:Controls="clr-namespace:ChocolateyGui.Controls"
xmlns:Dialogs="clr-namespace:ChocolateyGui.Controls.Dialogs"
xmlns:conv="clr-namespace:MahApps.Metro.Converters;assembly=MahApps.Metro"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
mc:Ignorable="d"
x:Class="ChocolateyGui.Controls.Dialogs.ChocolateyDialog"
d:DesignHeight="300" d:DesignWidth="1300">
<MahDialogs:BaseMetroDialog.DialogBody>
Expand All @@ -18,10 +17,10 @@
</Grid.RowDefinitions>
<Controls:FauxPowerShellConsole x:Name="PART_Console" Padding="5"
MinHeight="300" MaxHeight="800"
VerticalAlignment="Stretch" HorizontalAlignment="Stretch"
BorderBrush="#FFEBEBEB" BorderThickness="5" Background="#FF012456"
VerticalAlignment="Stretch" HorizontalAlignment="Stretch"
BorderBrush="#FFEBEBEB" BorderThickness="5" Background="#FF012456"
Foreground="#FFEEEDF0" FontFamily="Lucida Console" FontSize="12"
IsReadOnly="True"/>
IsReadOnly="True"/>
<StackPanel Grid.Row="1"
Orientation="Horizontal"
HorizontalAlignment="Right">
Expand All @@ -36,7 +35,7 @@
</Grid>
</MahDialogs:BaseMetroDialog.DialogBody>
<MahDialogs:BaseMetroDialog.DialogBottom>
<MahControls:MetroProgressBar
<MahControls:MetroProgressBar
HorizontalAlignment="Stretch"
VerticalAlignment="Bottom"
Width="{Binding ActualWidth, RelativeSource={RelativeSource AncestorType=Dialogs:ChocolateyDialog, Mode=FindAncestor}, UpdateSourceTrigger=PropertyChanged}"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ public async Task CloseAsync()
{
IsOpen = false;
}));
return;
}

/// <summary>
Expand Down
64 changes: 32 additions & 32 deletions Source/ChocolateyGui/Controls/ObservableRingBufferCollection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,25 +25,25 @@ public sealed class ObservableRingBufferCollection<T> : INotifyCollectionChanged
private T[] _buffer;

/// <summary>
/// The all-over position within the ring buffer. The position
/// increases continuously by adding new items to the buffer. This
/// value is needed to calculate the current relative position within the
/// The all-over position within the ring buffer. The position
/// increases continuously by adding new items to the buffer. This
/// value is needed to calculate the current relative position within the
/// buffer.
/// </summary>
private int _position;

/// <summary>
/// The current version of the buffer, this is required for a correct
/// The current version of the buffer, this is required for a correct
/// exception handling while enumerating over the items of the buffer.
/// </summary>
private long _version;

/// <summary>
/// Initializes a new instance of the <see cref="ObservableRingBufferCollection{T}"/> class.
/// Initializes a new instance of the <see cref="ObservableRingBufferCollection{T}"/> class.
/// The observable ring buffer collection.
/// </summary>
/// <param name="capacity">
/// The maximum count of items to be stored within
/// The maximum count of items to be stored within
/// the ring buffer.
/// </param>
public ObservableRingBufferCollection(int capacity)
Expand Down Expand Up @@ -97,7 +97,7 @@ public void Add(T item)
}

this._buffer[index] = item;

// increase the count if capacity is not yet reached
if (this.Count < this.Capacity)
{
Expand All @@ -110,12 +110,12 @@ public void Add(T item)
}

/// <summary>
/// Clears the whole buffer and releases all referenced objects
/// Clears the whole buffer and releases all referenced objects
/// currently stored within the buffer.
/// </summary>
public void Clear()
{
for (int i = 0; i < this.Count; i++)
for (var i = 0; i < this.Count; i++)
{
this._buffer[i] = default(T);
}
Expand All @@ -132,18 +132,18 @@ public void Clear()
/// </summary>
/// <param name="item">The item to search for within the current
/// buffer.</param>
/// <returns>True if the specified item is currently present within
/// <returns>True if the specified item is currently present within
/// the buffer; otherwise false.</returns>
public bool Contains(T item)
{
int index = this.IndexOf(item);
var index = this.IndexOf(item);
return index != -1;
}

/// <summary>
/// Copies the current items within the buffer to a specified array.
/// </summary>
/// <param name="array">The target array to copy the items of
/// <param name="array">The target array to copy the items of
/// the buffer to.</param>
/// <param name="arrayIndex">The start position within the target
/// array to start copying.</param>
Expand All @@ -154,7 +154,7 @@ public void CopyTo(T[] array, int arrayIndex)
throw new ArgumentNullException("array");
}

for (int i = 0; i < this.Count; i++)
for (var i = 0; i < this.Count; i++)
{
array[i + arrayIndex] = this._buffer[(this._position - this.Count + i) % this.Capacity];
}
Expand All @@ -167,8 +167,8 @@ public void CopyTo(T[] array, int arrayIndex)
/// </returns>
public IEnumerator<T> GetEnumerator()
{
long version = this._version;
for (int i = 0; i < this.Count; i++)
var version = this._version;
for (var i = 0; i < this.Count; i++)
{
if (version != this._version)
{
Expand Down Expand Up @@ -198,16 +198,16 @@ IEnumerator IEnumerable.GetEnumerator()
/// from the buffer; otherwise false.</returns>
/// <remarks>
/// <b>Warning</b>
/// Frequent usage of this method might become a bad idea if you are
/// working with a large buffer capacity. The removing of an item
/// Frequent usage of this method might become a bad idea if you are
/// working with a large buffer capacity. The removing of an item
/// requires a scan of the buffer to get the position of the specified
/// item. If the item was found, the deletion requires a move of all
/// item. If the item was found, the deletion requires a move of all
/// items stored above the found position.
/// </remarks>
public bool Remove(T item)
{
// find the position of the specified item
int index = this.IndexOf(item);
var index = this.IndexOf(item);

// item was not found; return false
if (index == -1)
Expand All @@ -225,16 +225,16 @@ public bool Remove(T item)
/// Gets the position of a specified item within the ring buffer.
/// </summary>
/// <param name="item">The item to get the current position for.</param>
/// <returns>The zero based index of the found item within the
/// <returns>The zero based index of the found item within the
/// buffer. If the item was not present within the buffer, this
/// method returns -1.</returns>
private int IndexOf(T item)
{
// loop over the current count of items
for (int i = 0; i < this.Count; i++)
for (var i = 0; i < this.Count; i++)
{
// get the item at the relative position within the internal array
T item2 = this._buffer[(this._position - this.Count + i) % this.Capacity];
var item2 = this._buffer[(this._position - this.Count + i) % this.Capacity];

// if both items are null, return true
if (null == item && null == item2)
Expand Down Expand Up @@ -268,8 +268,8 @@ private void NotifyCollectionChanged(NotifyCollectionChangedEventArgs args)
/// <exception cref="IndexOutOfRangeException">Thrown when incorrect argument passed in.</exception>
/// <remarks>
/// <b>Warning</b>
/// Frequent usage of this method might become a bad idea if you are
/// working with a large buffer capacity. The deletion requires a move
/// Frequent usage of this method might become a bad idea if you are
/// working with a large buffer capacity. The deletion requires a move
/// of all items stored above the found position.
/// </remarks>
private void RemoveAt(int index)
Expand All @@ -282,27 +282,27 @@ private void RemoveAt(int index)

// move all items above the specified position one step
// closer to zero
for (int i = index; i < this.Count - 1; i++)
for (var i = index; i < this.Count - 1; i++)
{
// get the next relative target position of the item
int to = (this._position - this.Count + i) % this.Capacity;
// get the next relative source position of the item
int from = (this._position - this.Count + i + 1) % this.Capacity;
var to = (this._position - this.Count + i) % this.Capacity;

// get the next relative source position of the item
var from = (this._position - this.Count + i + 1) % this.Capacity;

// move the item
this._buffer[to] = this._buffer[from];
}

// get the relative position of the last item, which becomes empty
// after deletion and set the item as empty
int last = (this._position - 1) % this.Capacity;
var last = (this._position - 1) % this.Capacity;
this._buffer[last] = default(T);

// adjust storage information
this._position--;
this.Count--;

// buffer changed; next version
this._version++;

Expand Down
5 changes: 2 additions & 3 deletions Source/ChocolateyGui/Resources/ControlStyles/Flyout.xaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:custom="http://metro.mahapps.com/winfx/xaml/shared">
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Style x:Key="SetttingsButtonStyle"
TargetType="{x:Type Button}">
<Setter Property="Background"
Expand All @@ -13,7 +12,7 @@
Value="25,5,10,5" />
<Setter Property="BorderThickness"
Value="0" />
<Setter Property="HorizontalContentAlignment"
<Setter Property="HorizontalContentAlignment"
Value="Left"/>
<Setter Property="Template">
<Setter.Value>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,12 @@ namespace ChocolateyGui.Services
{
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.IO;
using System.Linq;
using System.Runtime.Caching;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using ChocolateyGui.Enums;
using ChocolateyGui.Models;
using ChocolateyGui.Providers;
using ChocolateyGui.Utilities;
using ChocolateyGui.Utilities.Extensions;
using ChocolateyGui.ViewModels.Items;
using Newtonsoft.Json;
using NuGet;
using MemoryCache = System.Runtime.Caching.MemoryCache;

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

namespace ChocolateyGui.Services
{
using System.Collections.Generic;
using System.Threading.Tasks;
using ChocolateyGui.Models;
using ChocolateyGui.ViewModels.Items;
using NuGet;

public interface IBasePackageService
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,9 @@
namespace ChocolateyGui.Services.PackageServices
{
using System;
using System.Globalization;
using System.Threading.Tasks;
using ChocolateyGui.Models;
using ChocolateyGui.ViewModels.Items;

public static class FileSystemPackageService
{
public static Task<IPackageViewModel> EnsureIsLoaded(IPackageViewModel viewModel)
Expand All @@ -28,10 +26,5 @@ public static IPackageViewModel GetLatest(string id, IChocolateyPackageService c
{
throw new NotImplementedException();
}

private static string GetMemoryCacheKey(Uri source, string query, PackageSearchOptions options)
{
return string.Format(CultureInfo.CurrentCulture, "FileSystemPackageService.QueryResult.{0}|{1}|{2}|{3}", source, query, options.IncludeAllVersions, options.IncludePrerelease);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public static async Task<IPackageViewModel> GetLatest(string id, Func<IPackageVi
.FirstOrDefault(
result =>
includePrerelease ? result.Package.IsAbsoluteLatestVersion : result.Package.IsLatestVersion);

var mappedPackage = package == null ? null : AutoMapper.Mapper.Map(package.Package, packageFactory());
if (mappedPackage != null)
{
Expand Down
2 changes: 1 addition & 1 deletion Source/ChocolateyGui/Services/ProgressService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public class ProgressService : ObservableBase, IProgressService
{
private readonly AsyncLock _lock;
private readonly ObservableRingBufferCollection<PowerShellOutputLine> _output;
private CancellationTokenSource _cst = null;
private CancellationTokenSource _cst;
private bool _isLoading;
private int _loadingItems;
private double _progress;
Expand Down
18 changes: 14 additions & 4 deletions Source/ChocolateyGui/Utilities/PackagesChangedEventManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,23 @@ public static void RemoveListener(IChocolateyPackageService service, IWeakEventL
}

protected override void StartListening(object source)
{
(source as IChocolateyPackageService).PackagesUpdated += this.OnPackagedUpdated;
{
var chocolateyPackageService = source as IChocolateyPackageService;

if (chocolateyPackageService != null)
{
chocolateyPackageService.PackagesUpdated += this.OnPackagedUpdated;
}
}

protected override void StopListening(object source)
{
(source as IChocolateyPackageService).PackagesUpdated -= this.OnPackagedUpdated;
{
var chocolateyPackageService = source as IChocolateyPackageService;

if (chocolateyPackageService != null)
{
chocolateyPackageService.PackagesUpdated -= this.OnPackagedUpdated;
}
}

private void OnPackagedUpdated(object sender, PackagesChangedEventArgs e)
Expand Down
14 changes: 12 additions & 2 deletions Source/ChocolateyGui/Utilities/SourcesChangedEventManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,22 @@ public static void RemoveListener(ISourceService service, IWeakEventListener lis

protected override void StartListening(object source)
{
(source as ISourceService).SourcesChanged += this.OnSourceUpdated;
var sourceService = source as ISourceService;

if (sourceService != null)
{
sourceService.SourcesChanged += this.OnSourceUpdated;
}
}

protected override void StopListening(object source)
{
(source as ISourceService).SourcesChanged -= this.OnSourceUpdated;
var sourceService = source as ISourceService;

if (sourceService != null)
{
sourceService.SourcesChanged -= this.OnSourceUpdated;
}
}

private void OnSourceUpdated(object sender, SourcesChangedEventArgs e)
Expand Down
Loading

0 comments on commit 5d570ef

Please sign in to comment.