Skip to content

Instantly share code, notes, and snippets.

View dimitrispaxinos's full-sized avatar

Dimitris Paxinos dimitrispaxinos

View GitHub Profile
using System;
using System.Threading.Tasks;
using System.Windows.Input;
namespace AsyncDisablingScopeSample
{
public class RelayCommandAsync : ICommand
{
#region Fields
/// <summary>
/// DisableableCommandAsync Constructor
/// </summary>
/// <param name="asyncExecute">Executing Delegate</param>
/// <param name="canExecute">Predicate for enabling/disabling</param>
/// <param name="disablables">List of IDisaeable Items to be disabled while executing</param>
/// <param name="disableWhileInProgress">Disable the Command itself while executing</param>
public DisableableCommandAsync(Func<object,Task> asyncExecute,
Predicate<object> canExecute,
IEnumerable<IDisableableCommand> disablables = null,
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Input;
namespace AsyncDisablingScopeSample
{
public class DisableableCommandAsync : IDisableableCommand
{
private IDisableableCommand _addCommand;
public IDisableableCommand AddCommand
{
get
{
if (_addCommand == null)
_addCommand = new DisableableCommandAsync(
AddCommandHandler,
obj => true,
new List<IDisableableCommand>() { RemoveCommand, UpdateCommand });
@dimitrispaxinos
dimitrispaxinos / Logger.cs
Last active October 31, 2015 11:13
Serilog Logger Initialization
// Create an Logger
Log.Logger = new LoggerConfiguration()
.WriteTo.Seq("http://localhost:5341")
.CreateLogger();
@dimitrispaxinos
dimitrispaxinos / PublishLog.cs
Last active October 31, 2015 11:11
Publish a log event with Serilog
// Publish a log event of any of the available six levels
Log.Logger.Verbose("Verbose");
Log.Logger.Debug("Debug");
Log.Logger.Information("Information");
Log.Logger.Warning("Warning");
Log.Logger.Error("Error");
Log.Logger.Fatal("Fatal");
@dimitrispaxinos
dimitrispaxinos / ParametersInLoggingEvent.cs
Last active October 31, 2015 14:30
Serilog: Including Parameters in your Logging Event
// Define two input parameters
string fName = "Dimitris";
string lName = "Paxinos";
// Include them in a way similar to the String.Format way.
Log.Logger.Information("My name is {FirstName} {LastName}", fName, lName);
@dimitrispaxinos
dimitrispaxinos / SturcturedObjectInTheLogEvent.cs
Last active October 31, 2015 13:22
Serilog: Add Structured Objects to your Log Event
// Declare Person class
public class Person
{
public string FirstName { get; set; }
public string LastName { get; set; }
}
// Instantiate a Person
var person = new Person()
{
@dimitrispaxinos
dimitrispaxinos / ExceptionInTheLogEvent.cs
Last active October 31, 2015 18:16
Serilog: Attach an Exception to your Log Event
Log.Logger.Error(new InvalidOperationException("Something went wrong"),
"This exception occured in the {ApplicationComponent}", "UI");
@dimitrispaxinos
dimitrispaxinos / LoggerWithContext.cs
Created November 3, 2015 16:22
Serilog: Create Logger that can include some context
// Create Logger with Context
Log.Logger = new LoggerConfiguration()
.Enrich.FromLogContext() // Enrich with context when available
.WriteTo.Seq("http://localhost:5341")
.CreateLogger();