Skip to content

Commit

Permalink
Fix LinqPad samples
Browse files Browse the repository at this point in the history
Update NuGet.md
Update CHANGELOG.md
Clean up Program.cs
  • Loading branch information
Odotocodot committed Jun 4, 2024
1 parent 8a5085c commit 7a45b55
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 41 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

### Changed
- Updated logo!
- Renamed IOneNoteItemExtensions to OneNoteItemExtensions.
- OneNoteNotebook.Notebook returns itself rather than null.
- Updated documentation to include examples and more information on the library.
- The methods that create hierarchy items e.g. CreatePage, CreateSection, CreateSectionGroup, CreateNotebook now return the ID of the created item. Can be used with the new FindByID.
Expand Down
43 changes: 6 additions & 37 deletions Documentation/articles/samples.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,43 +4,18 @@ The library's original purpose was for the OneNote [Flow Launcher](https://www.f

The examples below are not exactly best practices, but they should give you a good starting point!

[//]: # (TODO Fix the LinqPad Link)
They can also be found in [LinqPad]() for easy viewing! (Though be weary of the [Create Page](#create-pages-in-sections-with-less-than-2-pages) example as it will create a pages in your OneNote!)
They can also be found in the free and paid version of [LinqPad](https://www.linqpad.net/) for easy viewing! (Though be weary of the [Create Page](#create-pages-in-sections-with-less-than-2-pages) example as it will create a pages in your OneNote!)
### Get Recent Pages

```csharp
var pages = OneNoteApplication.GetNotebooks()
.GetPages()
.Where(p => !p.IsInRecycleBin)
.OrderByDescending(p => p.LastModified)
.Take(5);

foreach (var page in pages)
{
Console.WriteLine(page.Name);
}
```
[!code-csharp[](../../linqpad-samples/RecentPages.linq#L7-L18)]

### Get All Items in Recycle Bins

```csharp
var items = OneNoteApplication.GetNotebooks()
.Traverse(i => i.IsInRecycleBin()) // use an extension method to check if the item is in the recycle bin
.Where(i => i switch
{
OneNoteSectionGroup sectionGroup when sectionGroup.IsRecycleBin => false, // skip the special recycle bin section group
OneNoteSection section when section.IsDeletedPages => false, // skip the special deleted pages section in a recycle bin
_ => true
})
.ToList();
[!code-csharp[](../../linqpad-samples/RecycleBinItems.linq#L7-L26)]

### Search for a Page and Open Its Section

Console.WriteLine(items.Count);
foreach (var item in items)
{
Console.WriteLine(item.Name);
}
```
[!code-csharp[](../../linqpad-samples/OpenSection.linq#L7-L17)]

### Create Pages in Sections With Less Than 2 Pages

Expand All @@ -60,12 +35,6 @@ foreach (var section in sections)
}
```

### Search for a Page and Open Its Section

```csharp
var page = OneNoteApplication.FindPages("This specific search").MaxBy(p => p.LastModified);
OneNoteApplication.OpenInOneNote(page.Section);
```

### TEST
[!code-csharp[](../../linqpad-samples/RecentPages.linq#L5-L16)]

4 changes: 2 additions & 2 deletions Odotocodot.OneNote.Linq.Playground/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
public class Program
{
public static void Main(string[] args)
{
BenchmarkSwitcher.FromAssembly(typeof(Program).Assembly).RunAll();
{

}
}
}
1 change: 0 additions & 1 deletion Odotocodot.OneNote.Linq/NuGet.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
![logo](https://github.com/Odotocodot/Linq2OneNote/assets/48138990/bf168880-0bb7-47ac-80dd-e0825a1e021a)
# LINQ to OneNote

A helper library for dealing with the [OneNote Interop API](https://learn.microsoft.com/en-us/office/client-developer/onenote/application-interface-onenote).
Expand Down
15 changes: 14 additions & 1 deletion linqpad-samples/OpenSection.linq
Original file line number Diff line number Diff line change
@@ -1,4 +1,17 @@
<Query Kind="Statements">
<NuGetReference>Odotocodot.OneNote.Linq</NuGetReference>
<Namespace>Odotocodot.OneNote.Linq</Namespace>
<IncludeUncapsulator>false</IncludeUncapsulator>
</Query>

using Odotocodot.OneNote.Linq;

var page = OneNoteApplication.FindPages("This specific search").MaxBy(p => p.LastModified);
OneNoteApplication.OpenInOneNote(page.Section);
if(page == null)
{
Console.WriteLine("No page found with that search, try changing it!");
}
else
{
OneNoteApplication.OpenInOneNote(page.Section);
}
6 changes: 6 additions & 0 deletions linqpad-samples/RecentPages.linq
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
<Query Kind="Statements">
<NuGetReference>Odotocodot.OneNote.Linq</NuGetReference>
<Namespace>Odotocodot.OneNote.Linq</Namespace>
<IncludeUncapsulator>false</IncludeUncapsulator>
</Query>

using Odotocodot.OneNote.Linq;

var pages = OneNoteApplication.GetNotebooks()
Expand Down
6 changes: 6 additions & 0 deletions linqpad-samples/RecycleBinItems.linq
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
<Query Kind="Statements">
<NuGetReference>Odotocodot.OneNote.Linq</NuGetReference>
<Namespace>Odotocodot.OneNote.Linq</Namespace>
<IncludeUncapsulator>false</IncludeUncapsulator>
</Query>

using Odotocodot.OneNote.Linq;

var items = OneNoteApplication.GetNotebooks()
Expand Down

0 comments on commit 7a45b55

Please sign in to comment.