Skip to content

Code Quality: Refactoring of SidebarControl.xaml.cs #10467

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 33 commits into from
Dec 31, 2022

Conversation

QuaintMako
Copy link
Contributor

Resolved / Related Issues
Items resolved / related issues by this PR.

What has been done

  • Refactored src/Files.App/UserControls/SidebarControl.xaml.cs extensively.
  • Merged several duplicated sections into methods.
  • Reduced the nesting levels.
  • Nullable references annotations added.
  • Formatting.

Validation
How did you test these changes?

  • Built and ran the app

@BanCrash
Copy link
Contributor

On home section, if you click on a tag color on the sidebar, it will throw a notification error and the below error on Visual Studio. However on the last preview there is no error.

--- MESSAGE ---A Task's exception(s) were not observed either by Waiting on the Task or accessing its Exception property. As a result, the unobserved exception was rethrown by the finalizer thread. (Cannot access a disposed object.)
--- INNER ---System.ObjectDisposedException: Cannot access a disposed object.
   at System.Threading.ReaderWriterLockSlim.TryEnterReadLockCore(TimeoutTracker timeout)
   at System.Threading.ReaderWriterLockSlim.TryEnterReadLock(TimeSpan timeout)
   at LiteDB.Engine.LockService.EnterTransaction()
   at LiteDB.Engine.TransactionMonitor.GetTransaction(Boolean create, Boolean queryOnly, Boolean& isNew)
   at LiteDB.Engine.QueryExecutor.ExecuteQuery(Boolean executionPlan)
   at LiteDB.Engine.QueryExecutor.ExecuteQuery()
   at LiteDB.Engine.LiteEngine.Query(String collection, Query query)
   at LiteDB.LiteQueryable`1.ExecuteReader()
   at LiteDB.LiteQueryable`1.ToDocuments()+MoveNext()
   at System.Linq.Enumerable.SelectEnumerableIterator`2.MoveNext()
   at System.Linq.Enumerable.WhereEnumerableIterator`1.MoveNext()
   at Files.App.Filesystem.Search.FolderSearch.SearchTagsAsync(String folder, IList`1 results, CancellationToken token)
   at Files.App.Filesystem.Search.FolderSearch.AddItemsAsync(String folder, IList`1 results, CancellationToken token)
   at Files.App.Filesystem.Search.FolderSearch.AddItemsAsyncForHome(IList`1 results, CancellationToken token)
   at Files.App.ViewModels.ItemViewModel.SearchAsync(FolderSearch search)---------------------------------------

@QuaintMako
Copy link
Contributor Author

On home section, if you click on a tag color on the sidebar, it will throw a notification error and the below error on Visual Studio. However on the last preview there is no error.

--- MESSAGE ---A Task's exception(s) were not observed either by Waiting on the Task or accessing its Exception property. As a result, the unobserved exception was rethrown by the finalizer thread. (Cannot access a disposed object.)
--- INNER ---System.ObjectDisposedException: Cannot access a disposed object.
   at System.Threading.ReaderWriterLockSlim.TryEnterReadLockCore(TimeoutTracker timeout)
   at System.Threading.ReaderWriterLockSlim.TryEnterReadLock(TimeSpan timeout)
   at LiteDB.Engine.LockService.EnterTransaction()
   at LiteDB.Engine.TransactionMonitor.GetTransaction(Boolean create, Boolean queryOnly, Boolean& isNew)
   at LiteDB.Engine.QueryExecutor.ExecuteQuery(Boolean executionPlan)
   at LiteDB.Engine.QueryExecutor.ExecuteQuery()
   at LiteDB.Engine.LiteEngine.Query(String collection, Query query)
   at LiteDB.LiteQueryable`1.ExecuteReader()
   at LiteDB.LiteQueryable`1.ToDocuments()+MoveNext()
   at System.Linq.Enumerable.SelectEnumerableIterator`2.MoveNext()
   at System.Linq.Enumerable.WhereEnumerableIterator`1.MoveNext()
   at Files.App.Filesystem.Search.FolderSearch.SearchTagsAsync(String folder, IList`1 results, CancellationToken token)
   at Files.App.Filesystem.Search.FolderSearch.AddItemsAsync(String folder, IList`1 results, CancellationToken token)
   at Files.App.Filesystem.Search.FolderSearch.AddItemsAsyncForHome(IList`1 results, CancellationToken token)
   at Files.App.ViewModels.ItemViewModel.SearchAsync(FolderSearch search)---------------------------------------

I cannot seem to reproduce this error. @BanCrash is it still an issue for you? Is it reproductible 100% ?

@gave92
Copy link
Member

gave92 commented Nov 29, 2022

On home section, if you click on a tag color on the sidebar, it will throw a notification error and the below error on Visual Studio. However on the last preview there is no error.

--- MESSAGE ---A Task's exception(s) were not observed either by Waiting on the Task or accessing its Exception property. As a result, the unobserved exception was rethrown by the finalizer thread. (Cannot access a disposed object.)
--- INNER ---System.ObjectDisposedException: Cannot access a disposed object.
   at System.Threading.ReaderWriterLockSlim.TryEnterReadLockCore(TimeoutTracker timeout)
   at System.Threading.ReaderWriterLockSlim.TryEnterReadLock(TimeSpan timeout)

I cannot seem to reproduce this error. @BanCrash is it still an issue for you? Is it reproductible 100% ?

That error has been fixed by @hez2010 in #10503, just make you have merged main and the error should go away.

@QuaintMako QuaintMako dismissed stale reviews from yaira2 and d2dyno1 via 6d0c92d December 18, 2022 18:33
Co-authored-by: yaira2 <39923744+yaira2@users.noreply.github.com>
@yaira2 yaira2 requested a review from d2dyno1 December 23, 2022 16:22
@gave92
Copy link
Member

gave92 commented Dec 31, 2022

If you agree with the changes in 496b161, LGTM.

@QuaintMako
Copy link
Contributor Author

If you agree with the changes in 496b161, LGTM.

All good for me!

Copy link
Member

@yaira2 yaira2 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@yaira2 yaira2 merged commit 4b8f172 into files-community:main Dec 31, 2022
@yaira2 yaira2 added ready to merge Pull requests that are approved and ready to merge and removed needs - code review labels Dec 31, 2022
@yaira2
Copy link
Member

yaira2 commented Jan 1, 2023

@QuaintMako Does expanding/collapsing sidebar sections crash the app for you?

@@ -510,12 +448,10 @@ private async void Sidebar_ItemInvoked(NavigationView sender, NavigationViewItem
return;
}

string navigationPath = args.InvokedItemContainer.Tag?.ToString();
Copy link
Member

@gave92 gave92 Jan 1, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah removing null checks.. always risky :)

@QuaintMako
Copy link
Contributor Author

@yaira2 I actually don't have a crash expanding/collapsing the sidebar section... Could you open an issue with the logs?

@gave92
Copy link
Member

gave92 commented Jan 2, 2023

Collapsing the favorite section:

2023-01-02 19:31:05.2671|ERROR|AppUnhandledException|Object reference not set to an instance of an object.
System.NullReferenceException: Object reference not set to an instance of an object.
at Files.App.UserControls.SidebarControl.Sidebar_ItemInvoked(NavigationView sender, NavigationViewItemInvokedEventArgs args)
at System.Threading.Tasks.Task.<>c.b__128_0(Object state)

@QuaintMako
Copy link
Contributor Author

I cannot seem to reproduce it at all.
@gave92 do you think adding back the null checking could fix the issue?

@gave92
Copy link
Member

gave92 commented Jan 2, 2023

Funny. Yeah adding back that null check fixes the issue for me.

@QuaintMako QuaintMako deleted the MoveItemRefactoring branch January 3, 2023 14:27
yaira2 pushed a commit that referenced this pull request Jan 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ready to merge Pull requests that are approved and ready to merge
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants