Skip to content

Fix nuget package push to github feed #911

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 4 commits into from
Nov 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/dotnet.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ jobs:
- name: Setup NuGet.exe for use with actions
# You may pin to the exact commit or the version.
# uses: NuGet/setup-nuget@fd9fffd6ca4541cf4152a9565835ca1a88a6eb37
uses: NuGet/setup-nuget@v1.1.1
uses: NuGet/setup-nuget@v2
- name: Add msbuild to PATH
uses: microsoft/setup-msbuild@v2

Expand Down Expand Up @@ -81,5 +81,5 @@ jobs:
run: msbuild ${{env.caliburn_sln}} /t:package /p:Configuration=${{env.build_configuration}}

- name: publish Nuget Packages to GitHub
run: dotnet nuget publish ${{env.nuget_folder}} --source ${{env.package_feed}} --api-key ${{secrets.PUBLISH_NUGET_PACKAGE}} --skip-duplicate
run: dotnet nuget push ${{env.nuget_folder}} --source ${{env.package_feed}} --api-key ${{secrets.PUBLISH_NUGET_PACKAGE}} --skip-duplicate
if: github.event_name != 'pull_request'
7 changes: 7 additions & 0 deletions src/Caliburn.Micro.Core/AsyncEventHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,13 @@

namespace Caliburn.Micro
{
/// <summary>
/// Represents an asynchronous event handler.
/// </summary>
/// <typeparam name="TEventArgs">The type of the event data generated by the event.</typeparam>
/// <param name="sender">The source of the event.</param>
/// <param name="e">An object that contains the event data.</param>
/// <returns>A task that represents the asynchronous operation.</returns>
public delegate Task AsyncEventHandler<TEventArgs>(
object sender,
TEventArgs e)
Expand Down
20 changes: 20 additions & 0 deletions src/Caliburn.Micro.Core/AsyncEventHandlerExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,33 @@

namespace Caliburn.Micro
{
/// <summary>
/// AsyncEventHandlerExtensions class.
/// </summary>
/// <remarks>
/// Contains helper functions to run Invoke methods asynchronously.
/// </remarks>
public static class AsyncEventHandlerExtensions
{
/// <summary>
/// Gets the invocation list of the specified async event handler.
/// </summary>
/// <typeparam name="TEventArgs">The type of the event arguments.</typeparam>
/// <param name="handler">The async event handler.</param>
/// <returns>An enumerable of async event handlers.</returns>
public static IEnumerable<AsyncEventHandler<TEventArgs>> GetHandlers<TEventArgs>(
this AsyncEventHandler<TEventArgs> handler)
where TEventArgs : EventArgs
=> handler.GetInvocationList().Cast<AsyncEventHandler<TEventArgs>>();

/// <summary>
/// Invokes all handlers of the specified async event handler asynchronously.
/// </summary>
/// <typeparam name="TEventArgs">The type of the event arguments.</typeparam>
/// <param name="handler">The async event handler.</param>
/// <param name="sender">The source of the event.</param>
/// <param name="e">The event data.</param>
/// <returns>A task that represents the completion of all handler invocations.</returns>
public static Task InvokeAllAsync<TEventArgs>(
this AsyncEventHandler<TEventArgs> handler,
object sender,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,54 +1,48 @@
namespace Caliburn.Micro.Maui
namespace Caliburn.Micro.Maui
{
using System;
using System.Collections.Generic;
using System.Reflection;
using System.Threading;
using System.Threading.Tasks;
using System.Reflection;
using Windows.UI.Core;
//using Windows.UI.Xaml;
using Microsoft.UI;
using Microsoft.UI.Xaml;

using Windows.UI.Core;

/// <summary>
/// A <see cref="IPlatformProvider"/> implementation for the XAML platfrom.
/// A <see cref="IPlatformProvider"/> implementation for the .NET MAUI platform.
/// </summary>
public class MauiPlatformProvider : IPlatformProvider
public class MauiPlatformProvider : IPlatformProvider
{
private readonly CoreDispatcher dispatcher;


/// <summary>
/// Initializes a new instance of the <see cref="XamlPlatformProvider"/> class.
/// Initializes a new instance of the <see cref="MauiPlatformProvider"/> class.
/// </summary>
public MauiPlatformProvider()
public MauiPlatformProvider()
{

dispatcher = Window.Current?.Dispatcher;

}

/// <summary>
/// Whether or not classes should execute property change notications on the UI thread.
/// Whether or not classes should execute property change notifications on the UI thread.
/// </summary>
public virtual bool PropertyChangeNotificationsOnUIThread => true;

/// <summary>
/// Indicates whether or not the framework is in design-time mode.
/// </summary>
public virtual bool InDesignMode
public virtual bool InDesignMode
{
get { return View.InDesignMode; }
}

private void ValidateDispatcher()
private void ValidateDispatcher()
{
if (dispatcher == null)
throw new InvalidOperationException("Not initialized with dispatcher.");
}

private bool CheckAccess()
private bool CheckAccess()
{
return dispatcher == null || Window.Current != null;
}
Expand All @@ -57,7 +51,7 @@ private bool CheckAccess()
/// Executes the action on the UI thread asynchronously.
/// </summary>
/// <param name="action">The action to execute.</param>
public virtual void BeginOnUIThread(System.Action action)
public virtual void BeginOnUIThread(System.Action action)
{
ValidateDispatcher();
var dummy = dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => action());
Expand All @@ -67,23 +61,22 @@ public virtual void BeginOnUIThread(System.Action action)
/// Executes the action on the UI thread asynchronously.
/// </summary>
/// <param name="action">The action to execute.</param>
/// <returns></returns>
public virtual Task OnUIThreadAsync(Func<Task> action) {
/// <returns>A task that represents the asynchronous operation.</returns>
public virtual Task OnUIThreadAsync(Func<Task> action)
{
ValidateDispatcher();
return dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => action()).AsTask();

}

/// <summary>
/// Executes the action on the UI thread.
/// </summary>
/// <param name="action">The action to execute.</param>
/// <exception cref="System.NotImplementedException"></exception>
public virtual void OnUIThread(System.Action action)
public virtual void OnUIThread(System.Action action)
{
if (CheckAccess())
action();
else
else
{
dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => action()).AsTask().Wait();
}
Expand All @@ -93,33 +86,31 @@ public virtual void OnUIThread(System.Action action)
/// Used to retrieve the root, non-framework-created view.
/// </summary>
/// <param name="view">The view to search.</param>
/// <returns>
/// The root element that was not created by the framework.
/// </returns>
/// <returns>The root element that was not created by the framework.</returns>
/// <remarks>
/// In certain instances the services create UI elements.
/// For example, if you ask the window manager to show a UserControl as a dialog, it creates a window to host the UserControl in.
/// The WindowManager marks that element as a framework-created element so that it can determine what it created vs. what was intended by the developer.
/// Calling GetFirstNonGeneratedView allows the framework to discover what the original element was.
/// </remarks>
public virtual object GetFirstNonGeneratedView(object view)
public virtual object GetFirstNonGeneratedView(object view)
{
return View.GetFirstNonGeneratedView(view);
}

private static readonly DependencyProperty PreviouslyAttachedProperty = DependencyProperty.RegisterAttached(
"PreviouslyAttached",
typeof (bool),
typeof (MauiPlatformProvider),
typeof(bool),
typeof(MauiPlatformProvider),
null
);
);

/// <summary>
/// Executes the handler the fist time the view is loaded.
/// Executes the handler the first time the view is loaded.
/// </summary>
/// <param name="view">The view.</param>
/// <param name="handler">The handler.</param>
public virtual void ExecuteOnFirstLoad(object view, Action<object> handler)
public virtual void ExecuteOnFirstLoad(object view, Action<object> handler)
{
//var element = view as FrameworkElement;
//if (element != null && !(bool) element.GetValue(PreviouslyAttachedProperty)) {
Expand All @@ -133,7 +124,7 @@ public virtual void ExecuteOnFirstLoad(object view, Action<object> handler)
/// </summary>
/// <param name="view">The view.</param>
/// <param name="handler">The handler.</param>
public virtual void ExecuteOnLayoutUpdated(object view, Action<object> handler)
public virtual void ExecuteOnLayoutUpdated(object view, Action<object> handler)
{
//var element = view as FrameworkElement;
//if (element != null) {
Expand All @@ -147,31 +138,29 @@ public virtual void ExecuteOnLayoutUpdated(object view, Action<object> handler)
/// <param name="viewModel">The view model to close.</param>
/// <param name="views">The associated views.</param>
/// <param name="dialogResult">The dialog result.</param>
/// <returns>
/// An <see cref="Action" /> to close the view model.
/// </returns>
/// <exception cref="System.NotImplementedException"></exception>
/// <returns>An <see cref="Func{CancellationToken, Task}"/> to close the view model.</returns>
public virtual Func<CancellationToken, Task> GetViewCloseAction(object viewModel, ICollection<object> views, bool? dialogResult)
{
foreach (var contextualView in views) {
foreach (var contextualView in views)
{
var viewType = contextualView.GetType();

var closeMethod = viewType.GetRuntimeMethod("Close", new Type[0]);

if (closeMethod != null)
return ct => {

return ct =>
{
closeMethod.Invoke(contextualView, null);
return Task.FromResult(true);
};

var isOpenProperty = viewType.GetRuntimeProperty("IsOpen");

if (isOpenProperty != null) {
if (isOpenProperty != null)
{
return ct =>
{
isOpenProperty.SetValue(contextualView, false, null);

return Task.FromResult(true);
};
}
Expand All @@ -185,4 +174,3 @@ public virtual Func<CancellationToken, Task> GetViewCloseAction(object viewModel
}
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,9 @@ public JournalEntry RemoveBackEntry()
return frame.RemoveBackEntry();
}

/// <summary>
/// Disposes the FrameAdapter instance, detaching event handlers to prevent memory leaks.
/// </summary>
public void Dispose()
{
this.frame.Navigating -= OnNavigating;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@

namespace Caliburn.Micro
{
/// <summary>
/// Manages the lifecycle of a window and its associated view model.
/// </summary>
public class WindowConductor
{
private bool deactivatingFromView;
Expand All @@ -14,12 +17,21 @@ public class WindowConductor
private readonly Window view;
private readonly object model;

/// <summary>
/// Initializes a new instance of the <see cref="WindowConductor"/> class.
/// </summary>
/// <param name="model">The view model associated with the window.</param>
/// <param name="view">The window being managed.</param>
public WindowConductor(object model, Window view)
{
this.model = model;
this.view = view;
}

/// <summary>
/// Initializes the conductor asynchronously.
/// </summary>
/// <returns>A task that represents the asynchronous operation.</returns>
public async Task InitialiseAsync()
{
if (model is IActivate activator)
Expand All @@ -39,6 +51,9 @@ public async Task InitialiseAsync()
}
}

/// <summary>
/// Handles the window's Closed event.
/// </summary>
private async void Closed(object sender, EventArgs e)
{
view.Closed -= Closed;
Expand All @@ -56,6 +71,9 @@ private async void Closed(object sender, EventArgs e)
deactivatingFromView = false;
}

/// <summary>
/// Handles the view model's Deactivated event.
/// </summary>
private Task Deactivated(object sender, DeactivationEventArgs e)
{
if (!e.WasClosed)
Expand All @@ -79,6 +97,9 @@ private Task Deactivated(object sender, DeactivationEventArgs e)
return Task.FromResult(true);
}

/// <summary>
/// Handles the window's Closing event.
/// </summary>
private async void Closing(object sender, CancelEventArgs e)
{
if (e.Cancel)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,24 @@

namespace Caliburn.Micro
{
/// <summary>
/// DispatcherTaskExtensions class.
/// </summary>
/// <remarks>
/// Contains helper functions to run tasks asynchronously on a <see cref="CoreDispatcher"/>.
/// </remarks>
public static class DispatcherTaskExtensions
{
/// <summary>
/// Runs a task asynchronously on the specified <see cref="CoreDispatcher"/>.
/// </summary>
/// <typeparam name="T">The type of the result produced by the task.</typeparam>
/// <param name="dispatcher">The dispatcher on which to run the task.</param>
/// <param name="func">The function that returns the task to be run.</param>
/// <param name="priority">The priority with which the task should be run.</param>
/// <returns>A task that represents the asynchronous operation.</returns>
public static async Task<T> RunTaskAsync<T>(this CoreDispatcher dispatcher,
Func<Task<T>> func, CoreDispatcherPriority priority = CoreDispatcherPriority.Normal)
Func<Task<T>> func, CoreDispatcherPriority priority = CoreDispatcherPriority.Normal)
{
var taskCompletionSource = new TaskCompletionSource<T>();
await dispatcher.RunAsync(priority, async () =>
Expand All @@ -24,7 +38,16 @@ await dispatcher.RunAsync(priority, async () =>
return await taskCompletionSource.Task;
}

// There is no TaskCompletionSource<void> so we use a bool that we throw away.
/// <summary>
/// Runs a task asynchronously on the specified <see cref="CoreDispatcher"/>.
/// </summary>
/// <param name="dispatcher">The dispatcher on which to run the task.</param>
/// <param name="func">The function that returns the task to be run.</param>
/// <param name="priority">The priority with which the task should be run.</param>
/// <returns>A task that represents the asynchronous operation.</returns>
/// <remarks>
/// There is no <see cref="TaskCompletionSource{Void}"/> so a <see cref="bool"/> is used and discarded.
/// </remarks>
public static async Task RunTaskAsync(this CoreDispatcher dispatcher,
Func<Task> func, CoreDispatcherPriority priority = CoreDispatcherPriority.Normal) =>
await RunTaskAsync(dispatcher, async () => { await func(); return false; }, priority);
Expand Down
3 changes: 3 additions & 0 deletions src/Caliburn.Micro.Platform/Platforms/uap/FrameAdapter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -435,6 +435,9 @@ private static ApplicationDataContainer GetSettingsContainer()
ApplicationDataCreateDisposition.Always);
}

/// <summary>
/// Disposes the FrameAdapter instance, detaching event handlers to prevent memory leaks.
/// </summary>
public void Dispose()
{
this.frame.Navigating -= OnNavigating;
Expand Down
Loading