diff --git a/.gitignore b/.gitignore index 788e256..aa6c475 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,237 @@ +/Properties/launchSettings.json + +## Ignore Visual Studio temporary files, build results, and +## files generated by popular Visual Studio add-ons. + +# User-specific files *.suo -bin -obj \ No newline at end of file +*.user +*.userosscache +*.sln.docstates + +# User-specific files (MonoDevelop/Xamarin Studio) +*.userprefs + +# Build results +[Dd]ebug/ +[Dd]ebugPublic/ +[Rr]elease/ +[Rr]eleases/ +x64/ +x86/ +build/ +bld/ +bin/ +Bin/ +obj/ +Obj/ + +# Visual Studio 2015 cache/options directory +.vs/ +/wwwroot/dist/ +/ClientApp/dist/ + +# MSTest test Results +[Tt]est[Rr]esult*/ +[Bb]uild[Ll]og.* + +# NUNIT +*.VisualState.xml +TestResult.xml + +# Build Results of an ATL Project +[Dd]ebugPS/ +[Rr]eleasePS/ +dlldata.c + +*_i.c +*_p.c +*_i.h +*.ilk +*.meta +*.obj +*.pch +*.pdb +*.pgc +*.pgd +*.rsp +*.sbr +*.tlb +*.tli +*.tlh +*.tmp +*.tmp_proj +*.log +*.vspscc +*.vssscc +.builds +*.pidb +*.svclog +*.scc + +# Chutzpah Test files +_Chutzpah* + +# Visual C++ cache files +ipch/ +*.aps +*.ncb +*.opendb +*.opensdf +*.sdf +*.cachefile + +# Visual Studio profiler +*.psess +*.vsp +*.vspx +*.sap + +# TFS 2012 Local Workspace +$tf/ + +# Guidance Automation Toolkit +*.gpState + +# ReSharper is a .NET coding add-in +_ReSharper*/ +*.[Rr]e[Ss]harper +*.DotSettings.user + +# JustCode is a .NET coding add-in +.JustCode + +# TeamCity is a build add-in +_TeamCity* + +# DotCover is a Code Coverage Tool +*.dotCover + +# NCrunch +_NCrunch_* +.*crunch*.local.xml +nCrunchTemp_* + +# MightyMoose +*.mm.* +AutoTest.Net/ + +# Web workbench (sass) +.sass-cache/ + +# Installshield output folder +[Ee]xpress/ + +# DocProject is a documentation generator add-in +DocProject/buildhelp/ +DocProject/Help/*.HxT +DocProject/Help/*.HxC +DocProject/Help/*.hhc +DocProject/Help/*.hhk +DocProject/Help/*.hhp +DocProject/Help/Html2 +DocProject/Help/html + +# Click-Once directory +publish/ + +# Publish Web Output +*.[Pp]ublish.xml +*.azurePubxml +# TODO: Comment the next line if you want to checkin your web deploy settings +# but database connection strings (with potential passwords) will be unencrypted +*.pubxml +*.publishproj + +# NuGet Packages +*.nupkg +# The packages folder can be ignored because of Package Restore +**/packages/* +# except build/, which is used as an MSBuild target. +!**/packages/build/ +# Uncomment if necessary however generally it will be regenerated when needed +#!**/packages/repositories.config + +# Microsoft Azure Build Output +csx/ +*.build.csdef + +# Microsoft Azure Emulator +ecf/ +rcf/ + +# Microsoft Azure ApplicationInsights config file +ApplicationInsights.config + +# Windows Store app package directory +AppPackages/ +BundleArtifacts/ + +# Visual Studio cache files +# files ending in .cache can be ignored +*.[Cc]ache +# but keep track of directories ending in .cache +!*.[Cc]ache/ + +# Others +ClientBin/ +~$* +*~ +*.dbmdl +*.dbproj.schemaview +*.pfx +*.publishsettings +orleans.codegen.cs + +/node_modules + +/yarn.lock + +# RIA/Silverlight projects +Generated_Code/ + +# Backup & report files from converting an old project file +# to a newer Visual Studio version. Backup files are not needed, +# because we have git ;-) +_UpgradeReport_Files/ +Backup*/ +UpgradeLog*.XML +UpgradeLog*.htm + +# SQL Server files +*.mdf +*.ldf + +# Business Intelligence projects +*.rdl.data +*.bim.layout +*.bim_*.settings + +# Microsoft Fakes +FakesAssemblies/ + +# GhostDoc plugin setting file +*.GhostDoc.xml + +# Node.js Tools for Visual Studio +.ntvs_analysis.dat + +# Visual Studio 6 build log +*.plg + +# Visual Studio 6 workspace options file +*.opt + +# Visual Studio LightSwitch build output +**/*.HTMLClient/GeneratedArtifacts +**/*.DesktopClient/GeneratedArtifacts +**/*.DesktopClient/ModelManifest.xml +**/*.Server/GeneratedArtifacts +**/*.Server/ModelManifest.xml +_Pvt_Extensions + +# Paket dependency manager +.paket/paket.exe + +# FAKE - F# Make +.fake/ diff --git a/SharePointLogViewer/App.xaml.cs b/SharePointLogViewer/App.xaml.cs index 0b1fa6e..6976c78 100644 --- a/SharePointLogViewer/App.xaml.cs +++ b/SharePointLogViewer/App.xaml.cs @@ -1,8 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Configuration; -using System.Data; -using System.Windows; +using System.Windows; namespace SharePointLogViewer { diff --git a/SharePointLogViewer/Controls/AutoCompleteTextBox/AutoCompleteManager.cs b/SharePointLogViewer/Controls/AutoCompleteTextBox/AutoCompleteManager.cs index d8acbb0..e111177 100644 --- a/SharePointLogViewer/Controls/AutoCompleteTextBox/AutoCompleteManager.cs +++ b/SharePointLogViewer/Controls/AutoCompleteTextBox/AutoCompleteManager.cs @@ -9,7 +9,6 @@ using System.Windows.Interop; using System.Windows.Media; using System.Windows.Shapes; -using System.Windows.Threading; using Microsoft.Windows.Themes; using System.Linq; @@ -46,13 +45,13 @@ public class AutoCompleteManager public IAutoCompleteDataProvider DataProvider { - get { return _dataProvider; } - set { _dataProvider = value; } + get => _dataProvider; + set => _dataProvider = value; } public bool Disabled { - get { return _disabled; } + get => _disabled; set { _disabled = value; @@ -63,10 +62,7 @@ public bool Disabled } } - public bool AutoCompleting - { - get { return _popup.IsOpen; } - } + public bool AutoCompleting => _popup.IsOpen; public AutoCompleteManager() { @@ -207,8 +203,8 @@ private void TextBox_TextChanged(object sender, TextChangedEventArgs e) popupDelay = new Timer(_ => { var dispatcher = Application.Current.Dispatcher; - string text = (string)dispatcher.Invoke(new Func(() => GetWordUnderCursor())); - if (String.IsNullOrEmpty(text)) + string text = (string)dispatcher.Invoke(() => GetWordUnderCursor()); + if (string.IsNullOrEmpty(text)) dispatcher.Invoke((Action)(() => _popup.IsOpen = false)); else { @@ -464,7 +460,7 @@ private IntPtr HookHandler(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, r private bool PopupOnTop { - get { return _popupOnTop; } + get => _popupOnTop; set { if (_popupOnTop == value) @@ -549,8 +545,8 @@ private void UpdateText(string text, bool selectAll) int start, end; GetWordUnderCursor(out start, out end); - string prefix = start < _textBeforeChangedByCode.Length ? _textBeforeChangedByCode.Substring(0, start) : String.Empty; - string suffix = end < _textBeforeChangedByCode.Length ? _textBeforeChangedByCode.Substring(end + 1) : String.Empty; + string prefix = start < _textBeforeChangedByCode.Length ? _textBeforeChangedByCode.Substring(0, start) : string.Empty; + string suffix = end < _textBeforeChangedByCode.Length ? _textBeforeChangedByCode.Substring(end + 1) : string.Empty; _textChangedByCode = true; Debug.Print("@@@@@@@" + text); diff --git a/SharePointLogViewer/Controls/AutoCompleteTextBox/AutoCompleteTextBox.cs b/SharePointLogViewer/Controls/AutoCompleteTextBox/AutoCompleteTextBox.cs index b242a0f..e3ed15c 100644 --- a/SharePointLogViewer/Controls/AutoCompleteTextBox/AutoCompleteTextBox.cs +++ b/SharePointLogViewer/Controls/AutoCompleteTextBox/AutoCompleteTextBox.cs @@ -1,31 +1,24 @@ using System; -using System.Collections.Generic; using System.Linq; -using System.Text; using System.Windows.Controls; namespace SharePointLogViewer.Controls.AutoCompleteTextBox { public class AutoCompleteTextBox : TextBox { - private AutoCompleteManager _acm; - - public AutoCompleteManager AutoCompleteManager - { - get { return _acm; } - } + public AutoCompleteManager AutoCompleteManager { get; } public AutoCompleteTextBox() { - _acm = new AutoCompleteManager(); - _acm.DataProvider = new SimpleStaticDataProvider(Enumerable.Empty()); - this.Loaded += AutoCompleteTextBox_Loaded; + AutoCompleteManager = new AutoCompleteManager(); + AutoCompleteManager.DataProvider = new SimpleStaticDataProvider(Enumerable.Empty()); + Loaded += AutoCompleteTextBox_Loaded; } void AutoCompleteTextBox_Loaded(object sender, System.Windows.RoutedEventArgs e) { if (!System.ComponentModel.DesignerProperties.GetIsInDesignMode(this)) - _acm.AttachTextBox(this); + AutoCompleteManager.AttachTextBox(this); } } diff --git a/SharePointLogViewer/Controls/BaseWPFHelpers.cs b/SharePointLogViewer/Controls/BaseWPFHelpers.cs index e4a9754..1ce4622 100644 --- a/SharePointLogViewer/Controls/BaseWPFHelpers.cs +++ b/SharePointLogViewer/Controls/BaseWPFHelpers.cs @@ -8,22 +8,11 @@ #region Using using System; using System.Collections.Generic; -using System.Text; -using System.Data; -using System.Data.Common; -using System.Configuration; -using System.ComponentModel; -using System.Collections.ObjectModel; -using System.Threading; using System.Windows; -using System.Windows.Threading; -using System.IO; using System.Windows.Media.Imaging; using System.Windows.Controls; -using System.Windows.Data; using System.Windows.Media; -using System.Windows.Media.Animation; -using System.Windows.Navigation; + #endregion @@ -78,8 +67,8 @@ bool StopAfterFirst /// public class FinderMatchType : IFinderMatchVisualHelper { - private Type _ty = null; - private bool _stopafterfirst = false; + private Type _ty; + private bool _stopafterfirst; public FinderMatchType(Type ty) { @@ -99,14 +88,8 @@ public bool DoesMatch(DependencyObject item) public bool StopAfterFirst { - get - { - return _stopafterfirst; - } - set - { - _stopafterfirst = value; - } + get => _stopafterfirst; + set => _stopafterfirst = value; } } @@ -115,9 +98,9 @@ public bool StopAfterFirst /// public class FinderMatchName : IFinderMatchVisualHelper { - private String _name = ""; + private string _name = ""; - public FinderMatchName(String name) + public FinderMatchName(string name) { _name = name; } @@ -139,10 +122,7 @@ public bool DoesMatch(DependencyObject item) /// public bool StopAfterFirst { - get - { - return true; - } + get => true; set { } @@ -171,10 +151,7 @@ public bool DoesMatch(DependencyObject item) /// public bool StopAfterFirst { - get - { - return true; - } + get => true; set { } @@ -204,10 +181,7 @@ public bool DoesMatch(DependencyObject item) /// public bool StopAfterFirst { - get - { - return true; - } + get => true; set { } @@ -350,11 +324,9 @@ public static void FindUpInTree(List lst, Visual parent, Visua else { // Ok, now try to get a new parent... - FrameworkElement feCast = parent as FrameworkElement; - if (feCast != null) + if (parent is FrameworkElement feCast) { - FrameworkElement feNewParent = feCast.Parent as FrameworkElement; - if (feNewParent == null || feNewParent == feCast) + if (!(feCast.Parent is FrameworkElement feNewParent) || feNewParent == feCast) { // Try to get the templated parent feNewParent = feCast.TemplatedParent as FrameworkElement; @@ -414,9 +386,7 @@ public static void TurnOffMediaElements(Visual parent) foreach (FrameworkElement me in lst) { - MediaElement meCast = me as MediaElement; - - if (meCast != null) + if (me is MediaElement meCast) { if (meCast.CanPause) { @@ -443,9 +413,7 @@ public static void TurnOnMediaElements(Visual parent) foreach (FrameworkElement me in lst) { - MediaElement meCast = me as MediaElement; - - if (meCast != null) + if (me is MediaElement meCast) { try { @@ -485,7 +453,7 @@ public static FrameworkElement FindItemsHost(Visual parent) /// /// /// - public static FrameworkElement FindVisualElement(Visual parent, String ElementName) + public static FrameworkElement FindVisualElement(Visual parent, string ElementName) { return SingleFindDownInTree(parent, new FinderMatchName(ElementName)); } @@ -496,7 +464,7 @@ public static FrameworkElement FindVisualElement(Visual parent, String ElementNa /// /// /// - public static FrameworkElement FindVisualElementUp(Visual parent, String ElementName) + public static FrameworkElement FindVisualElementUp(Visual parent, string ElementName) { return SingleFindInTree(parent, new FinderMatchName(ElementName)); } diff --git a/SharePointLogViewer/Controls/FilterableListView.cs b/SharePointLogViewer/Controls/FilterableListView.cs index 007ec12..99f462f 100644 --- a/SharePointLogViewer/Controls/FilterableListView.cs +++ b/SharePointLogViewer/Controls/FilterableListView.cs @@ -1,14 +1,11 @@ using System; using System.Collections.Generic; -using System.Text; using System.Windows.Controls; using System.Windows.Controls.Primitives; using System.Windows; -using System.Collections; using System.ComponentModel; using System.Windows.Data; using System.Windows.Input; -using System.Windows.Media; using System.Linq; @@ -28,8 +25,8 @@ public abstract class FilterableListView : SortableListView /// public Style FilterButtonActiveStyle { - get { return (Style)GetValue(FilterButtonActiveStyleProperty); } - set { SetValue(FilterButtonActiveStyleProperty, value); } + get => (Style)GetValue(FilterButtonActiveStyleProperty); + set => SetValue(FilterButtonActiveStyleProperty, value); } public static readonly DependencyProperty FilterButtonActiveStyleProperty = @@ -40,8 +37,8 @@ public Style FilterButtonActiveStyle /// public Style FilterButtonInactiveStyle { - get { return (Style)GetValue(FilterButtonInactiveStyleProperty); } - set { SetValue(FilterButtonInactiveStyleProperty, value); } + get => (Style)GetValue(FilterButtonInactiveStyleProperty); + set => SetValue(FilterButtonInactiveStyleProperty, value); } public static readonly DependencyProperty FilterButtonInactiveStyleProperty = @@ -65,7 +62,7 @@ class FilterStruct public FilterStruct(PropertyDescriptor propertyDescriptor, Button button, FilterItem value) { this.value = value; - this.Button = button; + Button = button; PropertyDescriptor = propertyDescriptor; } @@ -91,20 +88,20 @@ class FilterItem : IComparable public string Item { - get { return item; } - set { item = value; } + get => item; + set => item = value; } /// /// The item viewed in the filter drop down list. Typically this is the same as the item /// property, however if item is null, this has the value of "[empty]" /// - private Object itemView; + private object itemView; - public Object ItemView + public object ItemView { - get { return itemView; } - set { itemView = value; } + get => itemView; + set => itemView = value; } public FilterItem(IComparable item) @@ -131,10 +128,9 @@ public override bool Equals(object obj) { if (obj == null) return false; - - FilterItem otherItem = obj as FilterItem; - if (otherItem != null) - return this.item == otherItem.item; + + if (obj is FilterItem otherItem) + return item == otherItem.item; return base.Equals(obj); } @@ -143,9 +139,9 @@ public int CompareTo(object obj) { FilterItem otherFilterItem = (FilterItem)obj; - if (this.Item == null && obj == null) + if (Item == null && obj == null) return 0; - else if (otherFilterItem.Item != null && this.Item != null) + else if (otherFilterItem.Item != null && Item != null) return ((IComparable)item).CompareTo((IComparable)otherFilterItem.item); else return -1; @@ -157,7 +153,7 @@ public int CompareTo(object obj) Predicate extraFilter; public Predicate ExtraFilter { - get { return extraFilter; } + get => extraFilter; set { extraFilter = value; @@ -167,14 +163,14 @@ public Predicate ExtraFilter Dictionary currentFilters = new Dictionary(); - private void AddFilter(String property, FilterItem value, Button button) + private void AddFilter(string property, FilterItem value, Button button) { var descriptor = TypeDescriptor.GetProperties(ListItemType)[property]; var filter = new FilterStruct(descriptor, button, value); currentFilters[property] = filter; } - protected bool IsPropertyFiltered(String property) + protected bool IsPropertyFiltered(string property) { return currentFilters.ContainsKey(property); } @@ -192,14 +188,12 @@ protected override void OnInitialized(EventArgs e) dictionary = Application.LoadComponent(uri) as ResourceDictionary; // cast the ListView's View to a GridView - GridView gridView = this.View as GridView; - if (gridView != null) + if (View is GridView gridView) { // apply the data template, that includes the popup, button etc ... to each column foreach (GridViewColumn gridViewColumn in gridView.Columns) { - SortableGridViewColumn sc = gridViewColumn as SortableGridViewColumn; - if (sc != null && sc.CanBeFiltered) + if (gridViewColumn is SortableGridViewColumn sc && sc.CanBeFiltered) gridViewColumn.HeaderTemplate = (DataTemplate)dictionary["FilterGridHeaderTemplate"]; else gridViewColumn.HeaderTemplate = (DataTemplate)dictionary["SortableGridHeaderTemplate"]; @@ -236,9 +230,7 @@ public override void OnApplyTemplate() /// private void ShowFilterCommand(object sender, ExecutedRoutedEventArgs e) { - Button button = e.OriginalSource as Button; - - if (button != null) + if (e.OriginalSource is Button button) { // navigate up to the header GridViewColumnHeader header = (GridViewColumnHeader)Helpers.FindElementOfTypeUp(button, typeof(GridViewColumnHeader)); @@ -249,7 +241,7 @@ private void ShowFilterCommand(object sender, ExecutedRoutedEventArgs e) if (popup != null) { SortableGridViewColumn column = (SortableGridViewColumn)header.Column; - String propertyName = column.SortPropertyName; + string propertyName = column.SortPropertyName; var filterList = new List(); @@ -262,7 +254,7 @@ private void ShowFilterCommand(object sender, ExecutedRoutedEventArgs e) bool containsNull = false; PropertyDescriptor filterPropDesc = TypeDescriptor.GetProperties(ListItemType)[propertyName]; - foreach (Object item in Items) + foreach (object item in Items) { object value = filterPropDesc.GetValue(item); if (value != null) @@ -327,12 +319,12 @@ protected void SelectionChangedHandler(object sender, SelectionChangedEventArgs GridViewColumnHeader header = (GridViewColumnHeader)Helpers.FindElementOfTypeUp(filterListView, typeof(GridViewColumnHeader)); SortableGridViewColumn column = (SortableGridViewColumn)header.Column; - String currentFilterProperty = column.SortPropertyName; + string currentFilterProperty = column.SortPropertyName; if (!column.CanBeFiltered) { FilterStruct filter = (FilterStruct)currentFilters[currentFilterProperty]; - filter.Button.Visibility = System.Windows.Visibility.Hidden; + filter.Button.Visibility = Visibility.Hidden; return; } diff --git a/SharePointLogViewer/Controls/LoadingAnimation.xaml.cs b/SharePointLogViewer/Controls/LoadingAnimation.xaml.cs index d612dc1..79ac85e 100644 --- a/SharePointLogViewer/Controls/LoadingAnimation.xaml.cs +++ b/SharePointLogViewer/Controls/LoadingAnimation.xaml.cs @@ -1,16 +1,6 @@ using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; using System.Windows; using System.Windows.Controls; -using System.Windows.Data; -using System.Windows.Documents; -using System.Windows.Input; -using System.Windows.Media; -using System.Windows.Media.Imaging; -using System.Windows.Navigation; -using System.Windows.Shapes; namespace SharePointLogViewer.Controls { @@ -19,12 +9,12 @@ namespace SharePointLogViewer.Controls /// public partial class LoadingAnimation : UserControl { - public static readonly DependencyProperty MessageProperty = DependencyProperty.Register("Message", typeof(String), typeof(LoadingAnimation), new PropertyMetadata("Loading...")); + public static readonly DependencyProperty MessageProperty = DependencyProperty.Register("Message", typeof(string), typeof(LoadingAnimation), new PropertyMetadata("Loading...")); public string Message { - get { return (string)GetValue(MessageProperty); } - set { SetValue(MessageProperty, value); } + get => (string)GetValue(MessageProperty); + set => SetValue(MessageProperty, value); } public LoadingAnimation() diff --git a/SharePointLogViewer/Controls/SortableGridViewColumn.cs b/SharePointLogViewer/Controls/SortableGridViewColumn.cs index 076123f..dc58f3d 100644 --- a/SharePointLogViewer/Controls/SortableGridViewColumn.cs +++ b/SharePointLogViewer/Controls/SortableGridViewColumn.cs @@ -1,15 +1,5 @@ -using System; -using System.Collections.Generic; -using System.Text; -using System.Windows; +using System.Windows; using System.Windows.Controls; -using System.Windows.Controls.Primitives; -using System.Windows.Data; -using System.Windows.Documents; -using System.Windows.Input; -using System.Windows.Media; -using System.Windows.Media.Imaging; -using System.Windows.Shapes; // SortableListView, from the following blog post: // @@ -19,12 +9,12 @@ namespace SharePointLogViewer.Controls { public class SortableGridViewColumn : GridViewColumn { - static Setter hideSetter = new Setter(GridViewColumnHeader.VisibilityProperty, Visibility.Collapsed); + static Setter hideSetter = new Setter(UIElement.VisibilityProperty, Visibility.Collapsed); public string SortPropertyName { - get { return (string)GetValue(SortPropertyNameProperty); } - set { SetValue(SortPropertyNameProperty, value); } + get => (string)GetValue(SortPropertyNameProperty); + set => SetValue(SortPropertyNameProperty, value); } // Using a DependencyProperty as the backing store for SortPropertyName. This enables animation, styling, binding, etc... @@ -33,8 +23,8 @@ public string SortPropertyName public bool IsDefaultSortColumn { - get { return (bool)GetValue(IsDefaultSortColumnProperty); } - set { SetValue(IsDefaultSortColumnProperty, value); } + get => (bool)GetValue(IsDefaultSortColumnProperty); + set => SetValue(IsDefaultSortColumnProperty, value); } public static readonly DependencyProperty IsDefaultSortColumnProperty = @@ -42,8 +32,8 @@ public bool IsDefaultSortColumn public bool CanBeFiltered { - get { return (bool)GetValue(CanBeFilteredColumnProperty); } - set { SetValue(CanBeFilteredColumnProperty, value); } + get => (bool)GetValue(CanBeFilteredColumnProperty); + set => SetValue(CanBeFilteredColumnProperty, value); } public static readonly DependencyProperty CanBeFilteredColumnProperty = @@ -51,7 +41,7 @@ public bool CanBeFiltered public bool Visible { - get { return (bool)GetValue(VisibleProperty); } + get => (bool)GetValue(VisibleProperty); set { if (Visible ^ value) diff --git a/SharePointLogViewer/Controls/SortableGridViewColumnHeader.cs b/SharePointLogViewer/Controls/SortableGridViewColumnHeader.cs index bea1262..be8a343 100644 --- a/SharePointLogViewer/Controls/SortableGridViewColumnHeader.cs +++ b/SharePointLogViewer/Controls/SortableGridViewColumnHeader.cs @@ -1,8 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Windows.Controls; +using System.Windows.Controls; namespace SharePointLogViewer.Controls { diff --git a/SharePointLogViewer/Controls/SortableListView.cs b/SharePointLogViewer/Controls/SortableListView.cs index a6c93b6..aac8f12 100644 --- a/SharePointLogViewer/Controls/SortableListView.cs +++ b/SharePointLogViewer/Controls/SortableListView.cs @@ -1,11 +1,11 @@ -using System; -using System.Windows.Controls; -using System.Windows; +using SharePointLogViewer.Searching; +using System; +using System.Collections; using System.ComponentModel; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Controls.Primitives; using System.Windows.Data; -using System.Collections; -using System.Reflection; -using SharePointLogViewer.Searching; // SortableListView, from the following blog post: // @@ -18,8 +18,8 @@ namespace SharePointLogViewer.Controls /// public class SortableListView : ListView { - SortableGridViewColumn lastSortedOnColumn = null; - GridViewColumnHeader lastSortedOnColumnHeader = null; + SortableGridViewColumn lastSortedOnColumn; + GridViewColumnHeader lastSortedOnColumnHeader; ListSortDirection? lastDirection = ListSortDirection.Ascending; protected ResourceDictionary dictionary; @@ -29,8 +29,8 @@ public class SortableListView : ListView public string ColumnHeaderSortedAscendingTemplate { - get { return (string)GetValue(ColumnHeaderSortedAscendingTemplateProperty); } - set { SetValue(ColumnHeaderSortedAscendingTemplateProperty, value); } + get => (string)GetValue(ColumnHeaderSortedAscendingTemplateProperty); + set => SetValue(ColumnHeaderSortedAscendingTemplateProperty, value); } // Using a DependencyProperty as the backing store for ColumnHeaderSortedAscendingTemplate. This enables animation, styling, binding, etc... @@ -40,8 +40,8 @@ public string ColumnHeaderSortedAscendingTemplate public string ColumnHeaderSortedDescendingTemplate { - get { return (string)GetValue(ColumnHeaderSortedDescendingTemplateProperty); } - set { SetValue(ColumnHeaderSortedDescendingTemplateProperty, value); } + get => (string)GetValue(ColumnHeaderSortedDescendingTemplateProperty); + set => SetValue(ColumnHeaderSortedDescendingTemplateProperty, value); } @@ -52,8 +52,8 @@ public string ColumnHeaderSortedDescendingTemplate public string ColumnHeaderNotSortedTemplate { - get { return (string)GetValue(ColumnHeaderNotSortedTemplateProperty); } - set { SetValue(ColumnHeaderNotSortedTemplateProperty, value); } + get => (string)GetValue(ColumnHeaderNotSortedTemplateProperty); + set => SetValue(ColumnHeaderNotSortedTemplateProperty, value); } @@ -74,11 +74,10 @@ protected override void OnInitialized(EventArgs e) // add the event handler to the GridViewColumnHeader. This strongly ties this ListView to a GridView. - this.AddHandler(GridViewColumnHeader.ClickEvent, new RoutedEventHandler(GridViewColumnHeaderClickedHandler)); + AddHandler(ButtonBase.ClickEvent, new RoutedEventHandler(GridViewColumnHeaderClickedHandler)); // cast the ListView's View to a GridView - GridView gridView = this.View as GridView; - if (gridView != null) + if (View is GridView gridView) { // determine which column is marked as IsDefaultSortColumn. Stops on the first column marked this way. SortableGridViewColumn sortableGridViewColumn = null; @@ -87,14 +86,17 @@ protected override void OnInitialized(EventArgs e) gridViewColumn.HeaderTemplate = (DataTemplate)dictionary["SortableGridHeaderTemplate"]; sortableGridViewColumn = gridViewColumn as SortableGridViewColumn; - + if (sortableGridViewColumn != null) { if (sortableGridViewColumn.IsDefaultSortColumn) + { break; + } + sortableGridViewColumn = null; } - + } // if the default sort column is defined, sort the data and then update the templates as necessary. @@ -103,10 +105,12 @@ protected override void OnInitialized(EventArgs e) lastSortedOnColumn = sortableGridViewColumn; Sort(sortableGridViewColumn.SortPropertyName, ListSortDirection.Ascending); - if (!String.IsNullOrEmpty(this.ColumnHeaderSortedAscendingTemplate)) - sortableGridViewColumn.HeaderTemplate = this.TryFindResource(ColumnHeaderSortedAscendingTemplate) as DataTemplate; + if (!string.IsNullOrEmpty(ColumnHeaderSortedAscendingTemplate)) + { + sortableGridViewColumn.HeaderTemplate = TryFindResource(ColumnHeaderSortedAscendingTemplate) as DataTemplate; + } - this.SelectedIndex = 0; + SelectedIndex = 0; } } @@ -123,36 +127,39 @@ private void GridViewColumnHeaderClickedHandler(object sender, RoutedEventArgs e { Uri uri = new Uri("/Controls/FiterListViewDictionary.xaml", UriKind.Relative); ResourceDictionary dictionary = Application.LoadComponent(uri) as ResourceDictionary; - - GridViewColumnHeader headerClicked = e.OriginalSource as GridViewColumnHeader; // ensure that we clicked on the column header and not the padding that's added to fill the space. - if (headerClicked != null && headerClicked.Role != GridViewColumnHeaderRole.Padding) + if (e.OriginalSource is GridViewColumnHeader headerClicked && headerClicked.Role != GridViewColumnHeaderRole.Padding) { // attempt to cast to the sortableGridViewColumn object. - SortableGridViewColumn sortableGridViewColumn = (headerClicked.Column) as SortableGridViewColumn; // ensure that the column header is the correct type and a sort property has been set. - if (sortableGridViewColumn != null && !String.IsNullOrEmpty(sortableGridViewColumn.SortPropertyName)) + if ((headerClicked.Column) is SortableGridViewColumn sortableGridViewColumn && !string.IsNullOrEmpty(sortableGridViewColumn.SortPropertyName)) { ListSortDirection? direction; // determine if this is a new sort, or a switch in sort direction. if (lastSortedOnColumn == null - || String.IsNullOrEmpty(lastSortedOnColumn.SortPropertyName) - || !String.Equals(sortableGridViewColumn.SortPropertyName, lastSortedOnColumn.SortPropertyName, StringComparison.InvariantCultureIgnoreCase)) + || string.IsNullOrEmpty(lastSortedOnColumn.SortPropertyName) + || !string.Equals(sortableGridViewColumn.SortPropertyName, lastSortedOnColumn.SortPropertyName, StringComparison.InvariantCultureIgnoreCase)) { direction = ListSortDirection.Ascending; } else { if (lastDirection == ListSortDirection.Ascending) + { direction = ListSortDirection.Descending; + } else if (lastDirection == ListSortDirection.Descending) - direction = null; + { + direction = null; + } else + { direction = ListSortDirection.Ascending; + } } @@ -161,27 +168,39 @@ private void GridViewColumnHeaderClickedHandler(object sender, RoutedEventArgs e // Sort the data. if (direction == null) + { RemoveSort(); + } else - Sort(sortPropertyName, direction.Value); + { + Sort(sortPropertyName, direction.Value); + } Label sortIndicator = (Label)Helpers.SingleFindDownInTree(headerClicked, new Helpers.FinderMatchName("sortIndicator")); - - if (direction == null) - sortIndicator.Style = (Style)dictionary["HeaderTemplateTransparent"]; - if (direction == ListSortDirection.Ascending) - sortIndicator.Style = (Style)dictionary["HeaderTemplateArrowUp"]; - else if(direction == ListSortDirection.Descending) - sortIndicator.Style = (Style)dictionary["HeaderTemplateArrowDown"]; - + if (dictionary != null) + { + if (direction == null) + { + sortIndicator.Style = (Style)dictionary["HeaderTemplateTransparent"]; + } + + if (direction == ListSortDirection.Ascending) + { + sortIndicator.Style = (Style)dictionary["HeaderTemplateArrowUp"]; + } + else if (direction == ListSortDirection.Descending) + { + sortIndicator.Style = (Style)dictionary["HeaderTemplateArrowDown"]; + } + } // Remove arrow from previously sorted header - if (lastSortedOnColumnHeader != null && lastSortedOnColumnHeader!=headerClicked) + if (lastSortedOnColumnHeader != null && lastSortedOnColumnHeader != headerClicked) { sortIndicator = (Label)Helpers.SingleFindDownInTree(lastSortedOnColumnHeader, new Helpers.FinderMatchName("sortIndicator")); - sortIndicator.Style = (Style)dictionary["HeaderTemplateTransparent"]; + if (dictionary != null) sortIndicator.Style = (Style) dictionary["HeaderTemplateTransparent"]; } if (direction == null) @@ -207,9 +226,8 @@ private void GridViewColumnHeaderClickedHandler(object sender, RoutedEventArgs e private void Sort(string sortBy, ListSortDirection direction) { lastDirection = direction; - ListCollectionView dataView = CollectionViewSource.GetDefaultView(this.ItemsSource) as ListCollectionView; - if (dataView != null) + if (CollectionViewSource.GetDefaultView(ItemsSource) is ListCollectionView dataView) { dataView.CustomSort = new ListSorter(sortBy, direction); dataView.Refresh(); @@ -217,21 +235,19 @@ private void Sort(string sortBy, ListSortDirection direction) } private void RemoveSort() - { - ListCollectionView dataView = CollectionViewSource.GetDefaultView(this.ItemsSource) as ListCollectionView; - - if (dataView != null) + { + if (CollectionViewSource.GetDefaultView(ItemsSource) is ListCollectionView dataView) { dataView.CustomSort = null; dataView.Refresh(); } } - class ListSorter: IComparer + class ListSorter : IComparer { FastMethodInvoker fastInvoker; - string sortBy; - ListSortDirection direction; + readonly string sortBy; + readonly ListSortDirection direction; public ListSorter(string sortBy, ListSortDirection direction) { @@ -245,20 +261,34 @@ public int Compare(object x, object y) { if (fastInvoker == null) { - var propInfo = x.GetType().GetProperty(sortBy); - fastInvoker = FastInvoke.GetMethodInvoker(propInfo.GetGetMethod()); + if (x != null) + { + var propInfo = x.GetType().GetProperty(sortBy); + fastInvoker = FastInvoke.GetMethodInvoker(propInfo.GetGetMethod()); + } } - var x1 = fastInvoker.Invoke(x, null) as IComparable; - var y1 = fastInvoker.Invoke(y, null) as IComparable; - if (x1 == null || y1 == null) - return 0; - else + + if (fastInvoker != null) { - var result = x1.CompareTo(y1); - if (direction == ListSortDirection.Descending) - result = -result; - return result; + var x1 = fastInvoker.Invoke(x, null) as IComparable; + var y1 = fastInvoker.Invoke(y, null) as IComparable; + if (x1 == null || y1 == null) + { + return 0; + } + else + { + var result = x1.CompareTo(y1); + if (direction == ListSortDirection.Descending) + { + result = -result; + } + + return result; + } } + + return 0; } #endregion diff --git a/SharePointLogViewer/Extensions.cs b/SharePointLogViewer/Extensions.cs index 2711982..ad7fec2 100644 --- a/SharePointLogViewer/Extensions.cs +++ b/SharePointLogViewer/Extensions.cs @@ -1,11 +1,10 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; +using System.Collections.Generic; using System.Collections.ObjectModel; namespace SharePointLogViewer { +/* + CLASS UNUSED static class Extensions { public static void AddRange(this ObservableCollection collection, IEnumerable list) @@ -14,4 +13,5 @@ public static void AddRange(this ObservableCollection collection, IEnumera collection.Add(item); } } +*/ } diff --git a/SharePointLogViewer/Filters/IFilter.cs b/SharePointLogViewer/Filters/IFilter.cs index 6fb81e2..1cf5ea0 100644 --- a/SharePointLogViewer/Filters/IFilter.cs +++ b/SharePointLogViewer/Filters/IFilter.cs @@ -1,9 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; - -namespace SharePointLogViewer.Filters +namespace SharePointLogViewer.Filters { interface IFilter { diff --git a/SharePointLogViewer/Filters/ListViewFilter.cs b/SharePointLogViewer/Filters/ListViewFilter.cs index fe0519e..5cec3bf 100644 --- a/SharePointLogViewer/Filters/ListViewFilter.cs +++ b/SharePointLogViewer/Filters/ListViewFilter.cs @@ -1,8 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Windows.Controls; +using System.Windows.Controls; namespace SharePointLogViewer.Filters { @@ -10,7 +6,7 @@ class ListViewFilter: IFilter { ListView lstLog; - public ListViewFilter(System.Windows.Controls.ListView lstLog) + public ListViewFilter(ListView lstLog) { this.lstLog = lstLog; } diff --git a/SharePointLogViewer/Filters/SeverityFilter.cs b/SharePointLogViewer/Filters/SeverityFilter.cs index ea57fda..4a96eed 100644 --- a/SharePointLogViewer/Filters/SeverityFilter.cs +++ b/SharePointLogViewer/Filters/SeverityFilter.cs @@ -1,9 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; - -namespace SharePointLogViewer.Filters +namespace SharePointLogViewer.Filters { class SeverityFilter: IFilter { diff --git a/SharePointLogViewer/HiglightBookmarkedValueConverter.cs b/SharePointLogViewer/HiglightBookmarkedValueConverter.cs index 836ac01..2334492 100644 --- a/SharePointLogViewer/HiglightBookmarkedValueConverter.cs +++ b/SharePointLogViewer/HiglightBookmarkedValueConverter.cs @@ -1,7 +1,4 @@ using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; using System.Windows.Data; namespace SharePointLogViewer @@ -15,7 +12,7 @@ public object Convert(object[] values, Type targetType, object parameter, System bool bookmarkedAndNotSelected = false; if (values.Length == 2) - bookmarkedAndNotSelected = (bool)values[0] == true && (bool)values[1] == false; + bookmarkedAndNotSelected = (bool)values[0] && (bool)values[1] == false; return bookmarkedAndNotSelected; } diff --git a/SharePointLogViewer/LogEntryViewModel.cs b/SharePointLogViewer/LogEntryViewModel.cs index 0e9510a..d8ba36d 100644 --- a/SharePointLogViewer/LogEntryViewModel.cs +++ b/SharePointLogViewer/LogEntryViewModel.cs @@ -1,8 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.ComponentModel; +using System.ComponentModel; using SharePointLogViewer.Monitoring; namespace SharePointLogViewer @@ -25,7 +21,7 @@ public LogEntryViewModel(LogEntry entry) public bool Bookmarked { - get { return bookmarked; } + get => bookmarked; set { bookmarked = value; @@ -33,24 +29,27 @@ public bool Bookmarked } } +/* public string Timestamp { - get { return entry.Timestamp; } + get => entry.Timestamp; set { entry.Timestamp = value; OnPropertyChanged("Timestamp"); } } +*/ public string Process { - get { return entry.Process; } + get => entry.Process; set { entry.Process = value; OnPropertyChanged("Process"); } } +/* public string TID { get { return entry.TID; } @@ -60,6 +59,8 @@ public string TID OnPropertyChanged("TID"); } } +*/ +/* public string Area { get { return entry.Area; } @@ -69,15 +70,17 @@ public string Area OnPropertyChanged("Area"); } } +*/ public string Category { - get { return entry.Category; } + get => entry.Category; set { entry.Category = value; OnPropertyChanged("Category"); } } +/* public string EventID { get { return entry.EventID; } @@ -87,9 +90,10 @@ public string EventID OnPropertyChanged("EventID"); } } +*/ public string Level { - get { return entry.Level; } + get => entry.Level; set { entry.Level = value; @@ -98,7 +102,7 @@ public string Level } public string Message { - get { return entry.Message; } + get => entry.Message; set { entry.Message = value; @@ -106,15 +110,17 @@ public string Message } } +/* public string Correlation { - get { return entry.Correlation; } + get => entry.Correlation; set { entry.Correlation = value; OnPropertyChanged("Correlation"); } } +*/ void OnPropertyChanged(string propertyName) { diff --git a/SharePointLogViewer/LogFilterListView.cs b/SharePointLogViewer/LogFilterListView.cs index 3a6f31e..aa63734 100644 --- a/SharePointLogViewer/LogFilterListView.cs +++ b/SharePointLogViewer/LogFilterListView.cs @@ -1,23 +1,10 @@ using System; -using System.Collections.Generic; -using System.Text; -using System.Windows.Controls; -using System.Windows.Controls.Primitives; -using System.Windows; -using System.Collections; -using System.ComponentModel; -using System.Windows.Data; -using System.Windows.Input; -using System.Windows.Media; using SharePointLogViewer.Controls; namespace SharePointLogViewer { class LogFilterListView : FilterableListView { - protected override Type ListItemType - { - get { return typeof(LogEntryViewModel); } - } + protected override Type ListItemType => typeof(LogEntryViewModel); } } diff --git a/SharePointLogViewer/MainWindow.xaml.cs b/SharePointLogViewer/MainWindow.xaml.cs index 6a3e9fc..8dec66c 100644 --- a/SharePointLogViewer/MainWindow.xaml.cs +++ b/SharePointLogViewer/MainWindow.xaml.cs @@ -9,7 +9,6 @@ using System.Linq; using System.Diagnostics; using SharePointLogViewer.Controls.AutoCompleteTextBox; -using System.Collections; using System.Collections.Generic; using SharePointLogViewer.Searching; using SharePointLogViewer.Monitoring; @@ -27,7 +26,7 @@ public partial class MainWindow : Window OverflowCollection logEntries = new OverflowCollection(le=>!le.Bookmarked); LogsLoader logsLoader = new LogsLoader(); - ILogMonitor logMonitor = null; + ILogMonitor logMonitor; DynamicFilter filter; bool liveMode; OpenFileDialog openDialog; @@ -60,12 +59,12 @@ public MainWindow() WindowState = WindowState.Maximized; lastWindowState = WindowState; - logsLoader.LoadCompleted += new EventHandler(logsLoader_LoadCompleted); + logsLoader.LoadCompleted += logsLoader_LoadCompleted; - this.Loaded += new RoutedEventHandler(MainWindow_Loaded); - this.Closing += new CancelEventHandler(MainWindow_Closing); + Loaded += MainWindow_Loaded; + Closing += MainWindow_Closing; trayNotifier = new SystemTrayNotifier(); - trayNotifier.Click += new EventHandler(trayIcon_Click); + trayNotifier.Click += trayIcon_Click; bookmarkNavigator = new BookmarkNavigator(lstLog, ()=>GetCollectionViewSource().View); @@ -86,7 +85,7 @@ public MainWindow() else { showMinimizeToolTip = true; - if (!String.IsNullOrEmpty(App.FileToOpen)) + if (!string.IsNullOrEmpty(App.FileToOpen)) { files = new string[] { App.FileToOpen }; LoadFiles(); @@ -103,9 +102,9 @@ void MainWindow_Closing(object sender, CancelEventArgs e) void LoadSettings() { - if (Properties.Settings.Default.EnableEmailNotifications && !(String.IsNullOrEmpty(Properties.Settings.Default.EmailSenders) || - String.IsNullOrEmpty(Properties.Settings.Default.EmailRecepients) || - String.IsNullOrEmpty(Properties.Settings.Default.EmailSmtpServer))) + if (Properties.Settings.Default.EnableEmailNotifications && !(string.IsNullOrEmpty(Properties.Settings.Default.EmailSenders) || + string.IsNullOrEmpty(Properties.Settings.Default.EmailRecepients) || + string.IsNullOrEmpty(Properties.Settings.Default.EmailSmtpServer))) { INotifier notifier = new EmailNotifier(Properties.Settings.Default.EmailSenders, Properties.Settings.Default.EmailRecepients, @@ -151,7 +150,7 @@ private void InitializeDialogs() void MainWindow_Loaded(object sender, RoutedEventArgs e) { - this.DataContext = logEntries; + DataContext = logEntries; txtFilter.AutoCompleteManager.DataProvider = new SimpleStaticDataProvider((new LogEntryTokenizer(logEntries)).Distinct()); UpdateFilter(); @@ -159,7 +158,7 @@ void MainWindow_Loaded(object sender, RoutedEventArgs e) if (SPUtility.IsWSSInstalled) { - if (String.IsNullOrEmpty(Properties.Settings.Default.LastDirectory)) + if (string.IsNullOrEmpty(Properties.Settings.Default.LastDirectory)) lastDirectory = SPUtility.GetLogsLocation(); else lastDirectory = Properties.Settings.Default.LastDirectory; @@ -167,7 +166,7 @@ void MainWindow_Loaded(object sender, RoutedEventArgs e) else lastDirectory = Properties.Settings.Default.LastDirectory; - if (!String.IsNullOrEmpty(lastDirectory) && Directory.Exists(lastDirectory)) + if (!string.IsNullOrEmpty(lastDirectory) && Directory.Exists(lastDirectory)) Environment.CurrentDirectory = lastDirectory; } @@ -213,7 +212,7 @@ private void UpdateFilter() CollectionViewSource GetCollectionViewSource() { - CollectionViewSource source = (CollectionViewSource)this.Resources["FilteredCollection"]; + CollectionViewSource source = (CollectionViewSource)Resources["FilteredCollection"]; return source; } @@ -280,7 +279,7 @@ void watcher_LogEntryDiscovered(object sender, LogEntryDiscoveredEventArgs e) { var le = new LogEntryViewModel(e.LogEntry); logEntries.Add(le); - if (this.Visibility == System.Windows.Visibility.Visible) + if (Visibility == Visibility.Visible) lstLog.ScrollIntoView(le); NotifyIfRequired(le); } @@ -312,7 +311,7 @@ void StartLiveMonitoring() else logMonitor = new LogMonitor(folderPath); - logMonitor.LogEntryDiscovered += new EventHandler(watcher_LogEntryDiscovered); + logMonitor.LogEntryDiscovered += watcher_LogEntryDiscovered; if (files.Length > 0) Reset(); @@ -356,7 +355,7 @@ void StartProcessing(string message) void StopProcessing() { bdrShadow.Visibility = Visibility.Hidden; - this.Cursor = Cursors.Arrow; + Cursor = Cursors.Arrow; } private void OpenFile_CanExecute(object sender, CanExecuteRoutedEventArgs e) @@ -398,8 +397,7 @@ private void Window_Closing(object sender, CancelEventArgs e) private void lvCopyCommand_Executed(object sender, ExecutedRoutedEventArgs e) { - var logEntry = lstLog.SelectedItem as LogEntryViewModel; - if (logEntry != null) + if (lstLog.SelectedItem is LogEntryViewModel logEntry) Clipboard.SetText(LogExporter.Format(logEntry)); } @@ -444,8 +442,7 @@ private void img_MouseLeftButtonUp(object sender, MouseButtonEventArgs e) private void ToggleLogEntryBookmark() { - LogEntryViewModel selected = lstLog.SelectedItem as LogEntryViewModel; - if (selected != null) + if (lstLog.SelectedItem is LogEntryViewModel selected) selected.Bookmarked = !selected.Bookmarked; } diff --git a/SharePointLogViewer/Monitoring/FileTail.cs b/SharePointLogViewer/Monitoring/FileTail.cs index 1302bda..4c17ac7 100644 --- a/SharePointLogViewer/Monitoring/FileTail.cs +++ b/SharePointLogViewer/Monitoring/FileTail.cs @@ -1,7 +1,5 @@ using System; -using System.Collections.Generic; using System.Linq; -using System.Text; using System.ComponentModel; using System.Threading; using System.IO; @@ -27,10 +25,7 @@ public FileTail() stopSync = new ManualResetEvent(true); } - public bool IsBusy - { - get { return worker.IsBusy; } - } + public bool IsBusy => worker.IsBusy; public void Start(string path) { @@ -39,8 +34,8 @@ public void Start(string path) worker = new BackgroundWorker(); worker.WorkerReportsProgress = true; worker.WorkerSupportsCancellation = true; - worker.DoWork += new DoWorkEventHandler(worker_DoWork); - worker.ProgressChanged += new ProgressChangedEventHandler(worker_ProgressChanged); + worker.DoWork += worker_DoWork; + worker.ProgressChanged += worker_ProgressChanged; worker.RunWorkerAsync(); } @@ -59,16 +54,16 @@ void worker_DoWork(object sender, DoWorkEventArgs e) using (StreamReader reader = new StreamReader(stream)) { reader.ReadToEnd(); - string data = String.Empty; + string data = string.Empty; while (!worker.CancellationPending) { - System.Threading.Thread.Sleep(1000); + Thread.Sleep(1000); if (reader.EndOfStream) continue; data += reader.ReadToEnd(); string[] lines = data.Split(seperators, StringSplitOptions.RemoveEmptyEntries); - data = data.EndsWith("\n") ? String.Empty : lines.Last(); - int validLines = data == String.Empty ? lines.Length : lines.Length - 1; + data = data.EndsWith("\n") ? string.Empty : lines.Last(); + int validLines = data == string.Empty ? lines.Length : lines.Length - 1; foreach (string line in lines.Take(validLines)) worker.ReportProgress(0, line); } @@ -78,7 +73,7 @@ void worker_DoWork(object sender, DoWorkEventArgs e) void worker_ProgressChanged(object sender, ProgressChangedEventArgs e) { - LineDiscovered(this, new LineDiscoveredEventArgs() { Line = (String)e.UserState }); + LineDiscovered(this, new LineDiscoveredEventArgs() { Line = (string)e.UserState }); } #region IDisposable Members diff --git a/SharePointLogViewer/Monitoring/ILogMonitor.cs b/SharePointLogViewer/Monitoring/ILogMonitor.cs index 604c81e..146b854 100644 --- a/SharePointLogViewer/Monitoring/ILogMonitor.cs +++ b/SharePointLogViewer/Monitoring/ILogMonitor.cs @@ -1,7 +1,4 @@ using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; namespace SharePointLogViewer.Monitoring { diff --git a/SharePointLogViewer/Monitoring/LogDirectoryWatcher.cs b/SharePointLogViewer/Monitoring/LogDirectoryWatcher.cs index 794bf6b..be32aa9 100644 --- a/SharePointLogViewer/Monitoring/LogDirectoryWatcher.cs +++ b/SharePointLogViewer/Monitoring/LogDirectoryWatcher.cs @@ -1,7 +1,4 @@ using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; using System.IO; namespace SharePointLogViewer.Monitoring @@ -25,7 +22,7 @@ public LogDirectoryWatcher(string folderPath) watcher.Path = folderPath; watcher.Filter = Filter; watcher.NotifyFilter = NotifyFilters.FileName; - watcher.Created += new FileSystemEventHandler(watcher_Created); + watcher.Created += watcher_Created; } public void Start() diff --git a/SharePointLogViewer/Monitoring/LogEntry.cs b/SharePointLogViewer/Monitoring/LogEntry.cs index e9538ee..781aa59 100644 --- a/SharePointLogViewer/Monitoring/LogEntry.cs +++ b/SharePointLogViewer/Monitoring/LogEntry.cs @@ -1,8 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Text; - -namespace SharePointLogViewer.Monitoring +namespace SharePointLogViewer.Monitoring { class LogEntry { diff --git a/SharePointLogViewer/Monitoring/LogExporter.cs b/SharePointLogViewer/Monitoring/LogExporter.cs index 86df1c3..93a18b3 100644 --- a/SharePointLogViewer/Monitoring/LogExporter.cs +++ b/SharePointLogViewer/Monitoring/LogExporter.cs @@ -1,7 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; +using System.Collections.Generic; using System.IO; namespace SharePointLogViewer.Monitoring diff --git a/SharePointLogViewer/Monitoring/LogMonitor.cs b/SharePointLogViewer/Monitoring/LogMonitor.cs index 0993a56..b04c2e0 100644 --- a/SharePointLogViewer/Monitoring/LogMonitor.cs +++ b/SharePointLogViewer/Monitoring/LogMonitor.cs @@ -1,7 +1,4 @@ using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; using System.IO; namespace SharePointLogViewer.Monitoring @@ -21,9 +18,9 @@ public LogMonitor(string folderPath) throw new ArgumentException("Directory does not exist.", folderPath); this.folderPath = folderPath; fileTail = new FileTail(); - fileTail.LineDiscovered += new EventHandler(fileTail_LineDiscovered); + fileTail.LineDiscovered += fileTail_LineDiscovered; watcher = new LogDirectoryWatcher(folderPath); - watcher.FileCreated += new EventHandler(watcher_FileCreated); + watcher.FileCreated += watcher_FileCreated; } public void Start() @@ -49,7 +46,7 @@ void watcher_FileCreated(object sender, FileCreatedEventArgs e) void fileTail_LineDiscovered(object sender, LineDiscoveredEventArgs e) { - if (!String.IsNullOrEmpty(e.Line.Trim()) && !firstLine) + if (!string.IsNullOrEmpty(e.Line.Trim()) && !firstLine) { var entry = LogEntry.Parse(e.Line); if (entry != null) diff --git a/SharePointLogViewer/Monitoring/LogParser.cs b/SharePointLogViewer/Monitoring/LogParser.cs index 9da560c..881119e 100644 --- a/SharePointLogViewer/Monitoring/LogParser.cs +++ b/SharePointLogViewer/Monitoring/LogParser.cs @@ -1,9 +1,5 @@ -using System; -using System.Collections.Generic; -using System.Text; -using System.Data; +using System.Collections.Generic; using System.IO; -using System.Linq; namespace SharePointLogViewer.Monitoring { diff --git a/SharePointLogViewer/Monitoring/LogsLoader.cs b/SharePointLogViewer/Monitoring/LogsLoader.cs index 0e92584..a102c1c 100644 --- a/SharePointLogViewer/Monitoring/LogsLoader.cs +++ b/SharePointLogViewer/Monitoring/LogsLoader.cs @@ -1,9 +1,6 @@ using System; using System.Collections.Generic; -using System.Linq; -using System.Text; using System.ComponentModel; -using System.Collections.ObjectModel; namespace SharePointLogViewer.Monitoring { @@ -21,8 +18,8 @@ class LogsLoader public LogsLoader() { worker = new BackgroundWorker(); - worker.DoWork += new DoWorkEventHandler(worker_DoWork); - worker.RunWorkerCompleted += new RunWorkerCompletedEventHandler(worker_RunWorkerCompleted); + worker.DoWork += worker_DoWork; + worker.RunWorkerCompleted += worker_RunWorkerCompleted; } void worker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e) @@ -33,9 +30,9 @@ void worker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e) void worker_DoWork(object sender, DoWorkEventArgs e) { logEntries.Clear(); - string[] files = e.Argument as string[]; - foreach (string file in files) - logEntries.AddRange(LogParser.PraseLog(file)); + if (e.Argument is string[] files) + foreach (string file in files) + logEntries.AddRange(LogParser.PraseLog(file)); } public void Start(string[] files) diff --git a/SharePointLogViewer/Monitoring/MultiLogMonitor.cs b/SharePointLogViewer/Monitoring/MultiLogMonitor.cs index 469105d..bb5abd3 100644 --- a/SharePointLogViewer/Monitoring/MultiLogMonitor.cs +++ b/SharePointLogViewer/Monitoring/MultiLogMonitor.cs @@ -1,7 +1,5 @@ using System; using System.Collections.Generic; -using System.Linq; -using System.Text; namespace SharePointLogViewer.Monitoring { @@ -21,7 +19,7 @@ public void Start() logMonitors.ForEach(monitor => { monitor.Start(); - monitor.LogEntryDiscovered += new EventHandler(monitor_LogEntryDiscovered); + monitor.LogEntryDiscovered += monitor_LogEntryDiscovered; }); } @@ -30,7 +28,7 @@ public void Stop() logMonitors.ForEach(monitor => { monitor.Stop(); - monitor.LogEntryDiscovered -= new EventHandler(monitor_LogEntryDiscovered); + monitor.LogEntryDiscovered -= monitor_LogEntryDiscovered; }); } diff --git a/SharePointLogViewer/Notifiers/EmailNotifier.cs b/SharePointLogViewer/Notifiers/EmailNotifier.cs index 4614a86..db5a57d 100644 --- a/SharePointLogViewer/Notifiers/EmailNotifier.cs +++ b/SharePointLogViewer/Notifiers/EmailNotifier.cs @@ -1,7 +1,4 @@ using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; using System.Net.Mail; namespace SharePointLogViewer.Notifiers @@ -15,11 +12,11 @@ class EmailNotifier: INotifier public EmailNotifier(string sender, string recepients, string smtpServer) { - if (String.IsNullOrEmpty(sender)) + if (string.IsNullOrEmpty(sender)) throw new ArgumentNullException("sender"); - if (String.IsNullOrEmpty(recepients)) + if (string.IsNullOrEmpty(recepients)) throw new ArgumentNullException("recepients"); - if (String.IsNullOrEmpty(smtpServer)) + if (string.IsNullOrEmpty(smtpServer)) throw new ArgumentNullException("smtpServer"); this.sender = sender; diff --git a/SharePointLogViewer/Notifiers/EventLogNotifier.cs b/SharePointLogViewer/Notifiers/EventLogNotifier.cs index b949ce5..3f3c856 100644 --- a/SharePointLogViewer/Notifiers/EventLogNotifier.cs +++ b/SharePointLogViewer/Notifiers/EventLogNotifier.cs @@ -1,8 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Diagnostics; +using System.Diagnostics; namespace SharePointLogViewer.Notifiers { diff --git a/SharePointLogViewer/Notifiers/INotifier.cs b/SharePointLogViewer/Notifiers/INotifier.cs index 76039bd..75d9503 100644 --- a/SharePointLogViewer/Notifiers/INotifier.cs +++ b/SharePointLogViewer/Notifiers/INotifier.cs @@ -1,9 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; - -namespace SharePointLogViewer.Notifiers +namespace SharePointLogViewer.Notifiers { interface INotifier { diff --git a/SharePointLogViewer/Notifiers/SystemTrayNotifier.cs b/SharePointLogViewer/Notifiers/SystemTrayNotifier.cs index 5940610..e18f828 100644 --- a/SharePointLogViewer/Notifiers/SystemTrayNotifier.cs +++ b/SharePointLogViewer/Notifiers/SystemTrayNotifier.cs @@ -1,7 +1,4 @@ using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; using System.IO; namespace SharePointLogViewer.Notifiers @@ -17,8 +14,8 @@ public SystemTrayNotifier() notifier = new System.Windows.Forms.NotifyIcon(); using (Stream iconStream = System.Windows.Application.GetResourceStream(new Uri("pack://application:,,/Images/SPLV.ico")).Stream) notifier.Icon = new System.Drawing.Icon(iconStream); - notifier.Click += new EventHandler(notifyIcon_Click); - notifier.BalloonTipClicked += new EventHandler(notifyIcon_Click); + notifier.Click += notifyIcon_Click; + notifier.BalloonTipClicked += notifyIcon_Click; } public void Notify(LogEntryViewModel logEntry) diff --git a/SharePointLogViewer/Properties/AssemblyInfo.cs b/SharePointLogViewer/Properties/AssemblyInfo.cs index 1227ec6..1ab74aa 100644 --- a/SharePointLogViewer/Properties/AssemblyInfo.cs +++ b/SharePointLogViewer/Properties/AssemblyInfo.cs @@ -1,6 +1,4 @@ using System.Reflection; -using System.Resources; -using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using System.Windows; diff --git a/SharePointLogViewer/Properties/Resources.Designer.cs b/SharePointLogViewer/Properties/Resources.Designer.cs index 2a7e1b4..79c528d 100644 --- a/SharePointLogViewer/Properties/Resources.Designer.cs +++ b/SharePointLogViewer/Properties/Resources.Designer.cs @@ -1,10 +1,10 @@ //------------------------------------------------------------------------------ // -// This code was generated by a tool. -// Runtime Version:4.0.21006.1 +// Ce code a été généré par un outil. +// Version du runtime :4.0.30319.42000 // -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. +// Les modifications apportées à ce fichier peuvent provoquer un comportement incorrect et seront perdues si +// le code est régénéré. // //------------------------------------------------------------------------------ @@ -13,13 +13,13 @@ namespace SharePointLogViewer.Properties { /// - /// A strongly-typed resource class, for looking up localized strings, etc. + /// Une classe de ressource fortement typée destinée, entre autres, à la consultation des chaînes localisées. /// - // This class was auto-generated by the StronglyTypedResourceBuilder - // class via a tool like ResGen or Visual Studio. - // To add or remove a member, edit your .ResX file then rerun ResGen - // with the /str option, or rebuild your VS project. - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")] + // Cette classe a été générée automatiquement par la classe StronglyTypedResourceBuilder + // à l'aide d'un outil, tel que ResGen ou Visual Studio. + // Pour ajouter ou supprimer un membre, modifiez votre fichier .ResX, puis réexécutez ResGen + // avec l'option /str ou régénérez votre projet VS. + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "15.0.0.0")] [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] internal class Resources { @@ -33,7 +33,7 @@ internal Resources() { } /// - /// Returns the cached ResourceManager instance used by this class. + /// Retourne l'instance ResourceManager mise en cache utilisée par cette classe. /// [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] internal static global::System.Resources.ResourceManager ResourceManager { @@ -47,8 +47,8 @@ internal Resources() { } /// - /// Overrides the current thread's CurrentUICulture property for all - /// resource lookups using this strongly typed resource class. + /// Remplace la propriété CurrentUICulture du thread actuel pour toutes + /// les recherches de ressources à l'aide de cette classe de ressource fortement typée. /// [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] internal static global::System.Globalization.CultureInfo Culture { diff --git a/SharePointLogViewer/Properties/Settings.Designer.cs b/SharePointLogViewer/Properties/Settings.Designer.cs index 91a2d07..7aadb04 100644 --- a/SharePointLogViewer/Properties/Settings.Designer.cs +++ b/SharePointLogViewer/Properties/Settings.Designer.cs @@ -1,10 +1,10 @@ //------------------------------------------------------------------------------ // -// This code was generated by a tool. -// Runtime Version:4.0.30319.1 +// Ce code a été généré par un outil. +// Version du runtime :4.0.30319.42000 // -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. +// Les modifications apportées à ce fichier peuvent provoquer un comportement incorrect et seront perdues si +// le code est régénéré. // //------------------------------------------------------------------------------ @@ -12,7 +12,7 @@ namespace SharePointLogViewer.Properties { [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "10.0.0.0")] + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "15.9.0.0")] internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase { private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); diff --git a/SharePointLogViewer/SPUtility.cs b/SharePointLogViewer/SPUtility.cs index f82f077..a642b7c 100644 --- a/SharePointLogViewer/SPUtility.cs +++ b/SharePointLogViewer/SPUtility.cs @@ -1,7 +1,6 @@ using System; using System.Collections.Generic; using System.Linq; -using System.Text; using System.IO; using Microsoft.Win32; using System.Security; @@ -66,18 +65,16 @@ public static bool IsWSSInstalled try { RegistryKey key = GetWSSRegistryKey(); - if (key != null) - { - object val = key.GetValue("SharePoint"); - if (val != null && val.Equals("Installed")) - return true; - } + object val = key?.GetValue("SharePoint"); + if (val != null && val.Equals("Installed")) + return true; } catch (SecurityException) { } return false; } } +/* public static bool IsMOSSInstalled { get @@ -100,6 +97,7 @@ public static bool IsMOSSInstalled return false; } } +*/ public static string LatestLogFile { @@ -116,7 +114,7 @@ public static string WSSInstallPath { get { - string installPath = String.Empty; + string installPath = string.Empty; try { using (RegistryKey key = GetWSSRegistryKey()) @@ -128,24 +126,18 @@ public static string WSSInstallPath } } - public static ICollection TraceSeverities - { - get - { - return new ReadOnlyCollection(severities); - } - } + public static ICollection TraceSeverities => new ReadOnlyCollection(severities); public static string GetLogsLocation() { - string logLocation = String.Empty; + string logLocation = string.Empty; if (IsWSSInstalled) { logLocation = GetSPDiagnosticsLogLocation(); - if (String.IsNullOrEmpty(logLocation)) + if (string.IsNullOrEmpty(logLocation)) logLocation = GetCustomLogLocation(); - if (String.IsNullOrEmpty(logLocation)) + if (string.IsNullOrEmpty(logLocation)) logLocation = GetStandardLogLocation(); } @@ -183,29 +175,39 @@ public static IEnumerable GetServerNames() { Type farmType = null; - if (SPUtility.SPVersion == SPVersion.SP2007) + if (SPVersion == SPVersion.SP2007) farmType = Type.GetType("Microsoft.SharePoint.Administration.SPFarm, Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c"); - else if (SPUtility.SPVersion == SPVersion.SP2010) + else if (SPVersion == SPVersion.SP2010) farmType = Type.GetType("Microsoft.SharePoint.Administration.SPFarm, Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c"); - else if (SPUtility.SPVersion == SPVersion.SP2013) + else if (SPVersion == SPVersion.SP2013) farmType = Type.GetType("Microsoft.SharePoint.Administration.SPFarm, Microsoft.SharePoint, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c"); if (farmType != null) { PropertyInfo propLocalFarm = farmType.GetProperty("Local", BindingFlags.Public | BindingFlags.Static); - object localFarm = propLocalFarm.GetValue(null, null); - PropertyInfo propServers = localFarm.GetType().GetProperty("Servers", BindingFlags.Public | BindingFlags.Instance); - IEnumerable servers = (IEnumerable)propServers.GetValue(localFarm, null); - foreach (object server in servers) + if (propLocalFarm != null) { - PropertyInfo propServerName = server.GetType().GetProperty("Name", BindingFlags.Public | BindingFlags.Instance); - string serverName = (string)propServerName.GetValue(server, null); - yield return serverName; + object localFarm = propLocalFarm.GetValue(null, null); + PropertyInfo propServers = localFarm.GetType().GetProperty("Servers", BindingFlags.Public | BindingFlags.Instance); + if (propServers != null) + { + IEnumerable servers = (IEnumerable)propServers.GetValue(localFarm, null); + foreach (object server in servers) + { + PropertyInfo propServerName = server.GetType().GetProperty("Name", BindingFlags.Public | BindingFlags.Instance); + if (propServerName != null) + { + string serverName = (string)propServerName.GetValue(server, null); + yield return serverName; + } + } + } } } } +/* static RegistryKey GetMOSSRegistryKey() { RegistryKey key = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Office Server\12.0"); @@ -215,21 +217,20 @@ static RegistryKey GetMOSSRegistryKey() key = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Office Server\15.0"); return key; } +*/ static RegistryKey GetWSSRegistryKey() { - RegistryKey key = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Shared Tools\Web Server Extensions\15.0"); - if (key == null) - key = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Shared Tools\Web Server Extensions\14.0"); - else if (key == null) - key = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Shared Tools\Web Server Extensions\12.0"); + RegistryKey key = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Shared Tools\Web Server Extensions\15.0") ?? + Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Shared Tools\Web Server Extensions\14.0"); + return key; } private static string GetStandardLogLocation() { string logLocation = WSSInstallPath; - if (logLocation != String.Empty) + if (logLocation != string.Empty) logLocation = Path.Combine(logLocation, "logs"); return logLocation; @@ -237,7 +238,7 @@ private static string GetStandardLogLocation() static string GetCustomLogLocation() { - string logLocation = String.Empty; + string logLocation = string.Empty; try { using (RegistryKey key = GetWSSRegistryKey()) @@ -252,21 +253,24 @@ static string GetCustomLogLocation() private static string GetSPDiagnosticsLogLocation() { - string logLocation = String.Empty; + string logLocation = string.Empty; Type diagSvcType = null; - if (SPUtility.SPVersion == SPVersion.SP2007) + if (SPVersion == SPVersion.SP2007) diagSvcType = Type.GetType("Microsoft.SharePoint.Administration.SPDiagnosticsService, Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c"); - else if (SPUtility.SPVersion == SPVersion.SP2010) + else if (SPVersion == SPVersion.SP2010) diagSvcType = Type.GetType("Microsoft.SharePoint.Administration.SPDiagnosticsService, Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c"); - else if (SPUtility.SPVersion == SPVersion.SP2013) + else if (SPVersion == SPVersion.SP2013) diagSvcType = Type.GetType("Microsoft.SharePoint.Administration.SPDiagnosticsService, Microsoft.SharePoint, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c"); if (diagSvcType != null) { PropertyInfo propLocalDiagSvc = diagSvcType.GetProperty("Local", BindingFlags.Public | BindingFlags.Static); - object localDiagSvc = propLocalDiagSvc.GetValue(null, null); - PropertyInfo property = localDiagSvc.GetType().GetProperty("LogLocation"); - logLocation = (string)property.GetValue(localDiagSvc, null); + if (propLocalDiagSvc != null) + { + object localDiagSvc = propLocalDiagSvc.GetValue(null, null); + PropertyInfo property = localDiagSvc.GetType().GetProperty("LogLocation"); + if (property != null) logLocation = (string) property.GetValue(localDiagSvc, null); + } } return logLocation; diff --git a/SharePointLogViewer/SPVersion.cs b/SharePointLogViewer/SPVersion.cs index 80be7e9..9359482 100644 --- a/SharePointLogViewer/SPVersion.cs +++ b/SharePointLogViewer/SPVersion.cs @@ -1,9 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; - -namespace SharePointLogViewer +namespace SharePointLogViewer { enum SPVersion { diff --git a/SharePointLogViewer/Searching/BookmarkNavigator.cs b/SharePointLogViewer/Searching/BookmarkNavigator.cs index b9b3d9c..ea24769 100644 --- a/SharePointLogViewer/Searching/BookmarkNavigator.cs +++ b/SharePointLogViewer/Searching/BookmarkNavigator.cs @@ -1,7 +1,6 @@ using System; using System.Collections.Generic; using System.Linq; -using System.Text; using System.Windows.Controls; using System.ComponentModel; @@ -34,10 +33,7 @@ IEnumerable LogEntries object SelectedItem { - get - { - return lstLog.SelectedItem; - } + get => lstLog.SelectedItem; set { lstLog.SelectedItem = value; diff --git a/SharePointLogViewer/Searching/DynamicFilter.cs b/SharePointLogViewer/Searching/DynamicFilter.cs index 2733e67..e278791 100644 --- a/SharePointLogViewer/Searching/DynamicFilter.cs +++ b/SharePointLogViewer/Searching/DynamicFilter.cs @@ -1,7 +1,5 @@ using System; -using System.Collections.Generic; using System.Linq; -using System.Text; using System.Reflection; namespace SharePointLogViewer.Searching @@ -24,10 +22,10 @@ public static DynamicFilter Create(string criterea, string searchText) static Predicate CreatePredicate(string propertyName, string searchText) { if (searchText == null) - searchText = String.Empty; + searchText = string.Empty; Predicate predicate; - if (searchText == String.Empty) + if (searchText == string.Empty) predicate = _ => true; else { @@ -53,7 +51,7 @@ public bool IsMatch(object item) static Predicate CreatePredicate(PropertyInfo property, params string[] keywords) { var comparer = new PropertyValueComparer(property, keywords); - return new Predicate(comparer.IsMatch); + return comparer.IsMatch; } #region Predicate @@ -66,7 +64,7 @@ class PropertyValueComparer public PropertyValueComparer(PropertyInfo property, params string[] keywords) { this.keywords = keywords; - this.fastInvoker = FastInvoke.GetMethodInvoker(property.GetGetMethod()); + fastInvoker = FastInvoke.GetMethodInvoker(property.GetGetMethod()); } public PropertyValueComparer(Type type, string propertyName, params string[] keywords) diff --git a/SharePointLogViewer/Searching/FastInvoke.cs b/SharePointLogViewer/Searching/FastInvoke.cs index 472e738..1f13d15 100644 --- a/SharePointLogViewer/Searching/FastInvoke.cs +++ b/SharePointLogViewer/Searching/FastInvoke.cs @@ -1,7 +1,4 @@ using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; using System.Reflection; using System.Reflection.Emit; @@ -14,10 +11,10 @@ public class FastInvoke FastMethodInvoker MyDelegate; public MethodInfo MyMethodInfo; public ParameterInfo[] MyParameters; - Object HostObject; + object HostObject; public int NumberOfArguments; - public FastInvoke(Object MyObject, String MyName) + public FastInvoke(object MyObject, string MyName) { HostObject = MyObject; Type t2 = MyObject.GetType(); @@ -36,7 +33,7 @@ public object ExecuteDelegate(object[] FunctionParameters) } catch (Exception e) { - Object o = new Object(); + object o = new object(); o = e.Message; return (o); @@ -114,7 +111,7 @@ public static FastMethodInvoker GetMethodInvoker(MethodInfo methodInfo) } private static void EmitCastToReference(ILGenerator il, - System.Type type) + Type type) { if (type.IsValueType) { @@ -126,7 +123,7 @@ private static void EmitCastToReference(ILGenerator il, } } - private static void EmitBoxIfNeeded(ILGenerator il, System.Type type) + private static void EmitBoxIfNeeded(ILGenerator il, Type type) { if (type.IsValueType) { @@ -172,7 +169,7 @@ private static void EmitFastInt(ILGenerator il, int value) if (value > -129 && value < 128) { - il.Emit(OpCodes.Ldc_I4_S, (SByte)value); + il.Emit(OpCodes.Ldc_I4_S, (sbyte)value); } else { @@ -183,7 +180,7 @@ private static void EmitFastInt(ILGenerator il, int value) public object TypeConvert(object source, Type DestType) { - object NewObject = System.Convert.ChangeType(source, DestType); + object NewObject = Convert.ChangeType(source, DestType); return (NewObject); } diff --git a/SharePointLogViewer/Searching/LogEntryTokenizer.cs b/SharePointLogViewer/Searching/LogEntryTokenizer.cs index 1e7ca4a..82fc117 100644 --- a/SharePointLogViewer/Searching/LogEntryTokenizer.cs +++ b/SharePointLogViewer/Searching/LogEntryTokenizer.cs @@ -1,7 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; +using System.Collections.Generic; namespace SharePointLogViewer.Searching { @@ -33,7 +30,7 @@ public IEnumerator GetEnumerator() System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() { - return this.GetEnumerator(); + return GetEnumerator(); } #endregion diff --git a/SharePointLogViewer/Searching/OverflowCollection.cs b/SharePointLogViewer/Searching/OverflowCollection.cs index 7fc5f95..d0eb9a5 100644 --- a/SharePointLogViewer/Searching/OverflowCollection.cs +++ b/SharePointLogViewer/Searching/OverflowCollection.cs @@ -1,7 +1,5 @@ using System; using System.Collections.Generic; -using System.Linq; -using System.Text; using System.Collections.ObjectModel; using System.Collections.Specialized; @@ -25,7 +23,7 @@ public void AddRange(IEnumerable collection) { deferNotification = true; foreach (T itm in collection) - this.Add(itm); + Add(itm); deferNotification = false; OnCollectionChanged(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Reset)); } @@ -36,7 +34,7 @@ protected override void InsertItem(int index, T item) T removeItem = default(T); if (MaxItems > 0 && Count == MaxItems) - foreach (var target in base.Items) + foreach (var target in Items) if (evictionCriterea(target)) { removeItem = target; @@ -46,7 +44,7 @@ protected override void InsertItem(int index, T item) base.InsertItem(index, item); if (itemFound) - base.Remove(removeItem); + Remove(removeItem); } protected override void OnCollectionChanged(NotifyCollectionChangedEventArgs e) diff --git a/SharePointLogViewer/SettingBinding.cs b/SharePointLogViewer/SettingBinding.cs index deba4fd..0a8add4 100644 --- a/SharePointLogViewer/SettingBinding.cs +++ b/SharePointLogViewer/SettingBinding.cs @@ -1,8 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Windows.Data; +using System.Windows.Data; namespace SharePointLogViewer { @@ -15,8 +11,8 @@ public SettingBinding(string path): base(path) private void Initialize() { - this.Source = SharePointLogViewer.Properties.Settings.Default; - this.Mode = BindingMode.TwoWay; + Source = Properties.Settings.Default; + Mode = BindingMode.TwoWay; } } } diff --git a/SharePointLogViewer/SettingsViewModel.cs b/SharePointLogViewer/SettingsViewModel.cs index 0d74782..e95edee 100644 --- a/SharePointLogViewer/SettingsViewModel.cs +++ b/SharePointLogViewer/SettingsViewModel.cs @@ -1,7 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; +using System.Collections.Generic; namespace SharePointLogViewer { @@ -28,7 +25,7 @@ class GeneralSettingsViewModel public bool RunAtStartup { get; set; } public bool HideToSystemTray { get; set; } public int LiveLimit { get; set; } - public List Columns { get; private set; } + public List Columns { get; } public GeneralSettingsViewModel() { @@ -38,9 +35,6 @@ public GeneralSettingsViewModel() class NotificationSettingsViewModel { - public NotificationSettingsViewModel() - { - } public bool EnableSystemTrayNotification { get; set; } public bool EnableEmailNotification { get; set; } public bool EnableEventLogNotification { get; set; } diff --git a/SharePointLogViewer/SettingsWindow.xaml.cs b/SharePointLogViewer/SettingsWindow.xaml.cs index 3f4f040..289c9aa 100644 --- a/SharePointLogViewer/SettingsWindow.xaml.cs +++ b/SharePointLogViewer/SettingsWindow.xaml.cs @@ -1,15 +1,7 @@ using System; -using System.Collections.Generic; using System.Linq; -using System.Text; using System.Windows; -using System.Windows.Controls; -using System.Windows.Data; -using System.Windows.Documents; using System.Windows.Input; -using System.Windows.Media; -using System.Windows.Media.Imaging; -using System.Windows.Shapes; using System.Collections.Specialized; using Microsoft.Win32; using System.Reflection; @@ -33,7 +25,7 @@ private void Window_Loaded(object sender, RoutedEventArgs e) { LoadGeneralSettings(); LoadNotificationSettings(); - this.DataContext = settingsVm; + DataContext = settingsVm; } private void LoadNotificationSettings() @@ -77,7 +69,7 @@ private void btnOK_Click(object sender, RoutedEventArgs e) { SaveGeneralSettings(); SaveNotificationSettings(); - this.DialogResult = true; + DialogResult = true; Close(); } diff --git a/SharePointLogViewer/SharePointLogViewer.csproj b/SharePointLogViewer/SharePointLogViewer.csproj index 2a1a293..9a0d465 100644 --- a/SharePointLogViewer/SharePointLogViewer.csproj +++ b/SharePointLogViewer/SharePointLogViewer.csproj @@ -1,5 +1,5 @@  - + Debug AnyCPU @@ -10,7 +10,7 @@ Properties SharePointLogViewer SharePointLogViewer - v3.5 + v4.7.2 512 {60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} 4 @@ -49,6 +49,7 @@ DEBUG;TRACE prompt 4 + false pdbonly @@ -57,6 +58,7 @@ DEBUG;TRACE prompt 4 + false @@ -66,10 +68,9 @@ 3.5 - - + 3.0 @@ -203,7 +204,9 @@ ResXFileCodeGenerator Resources.Designer.cs - + + Designer + SettingsSingleFileGenerator Settings.Designer.cs diff --git a/SharePointLogViewer/ValueConverter.cs b/SharePointLogViewer/ValueConverter.cs index 7964515..c633838 100644 --- a/SharePointLogViewer/ValueConverter.cs +++ b/SharePointLogViewer/ValueConverter.cs @@ -1,7 +1,4 @@ using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; using System.Windows.Data; using System.Windows.Controls; @@ -17,20 +14,23 @@ public object Convert(object value, Type targetType, object parameter, System.Gl { ListViewItem item = (ListViewItem)value; - ListView listView = ItemsControl.ItemsControlFromItemContainer(item) as ListView; // Get the index of a ListViewItem - int index = listView.ItemContainerGenerator.IndexFromContainer(item); - - if (index % 2 == 0) - { - return new SolidColorBrush(Colors.LightGray); - } - else + if (ItemsControl.ItemsControlFromItemContainer(item) is ListView listView) { - return new SolidColorBrush(Colors.White); + int index = listView.ItemContainerGenerator.IndexFromContainer(item ?? throw new InvalidOperationException()); + + if (index % 2 == 0) + { + return new SolidColorBrush(Colors.LightGray); + } + else + { + return new SolidColorBrush(Colors.White); + } } + return null; } diff --git a/SharePointLogViewer/app.config b/SharePointLogViewer/app.config index e6054d4..0be9d52 100644 --- a/SharePointLogViewer/app.config +++ b/SharePointLogViewer/app.config @@ -1,11 +1,11 @@ - -
+ +
- + 100 @@ -27,8 +27,7 @@ - + Timestamp Process TID @@ -54,13 +53,13 @@ False - + - + - + True @@ -69,7 +68,7 @@ Information - +