Skip to content

Instantly share code, notes, and snippets.

@DVDPT
DVDPT / gist:1551438
Created January 2, 2012 17:24
C# 5.0 async wrapper for WCF services.
public class WcfAsyncWrapper<TEventArgs, TResult> where TEventArgs : AsyncCompletedEventArgs
{
private readonly bool _haveResult;
private readonly TaskCompletionSource<TResult> _taskCompletionSource;
private EventHandler<TEventArgs> _event;
public WcfAsyncWrapper(bool haveResult = true)
{
_haveResult = haveResult;
_taskCompletionSource = new TaskCompletionSource<TResult>();
@DVDPT
DVDPT / gist:1607680
Created January 13, 2012 17:34
RestSharp Async for windows phone 7
public static class RestSharpExtensions
{
public static Task<IRestResponse<T>> ExecuteAsync<T>(this IRestClient client, IRestRequest request) where T : new()
{
return client.ExecuteAsync<T>(request, CancellationToken.None);
}
public static Task<IRestResponse<T>> ExecuteAsync<T>(this IRestClient client, IRestRequest request, CancellationToken token) where T : new()
{
@DVDPT
DVDPT / t.cs
Last active March 5, 2021 00:41
A simple extension method to replace the async event based get requests from facebook C# sdk to a async task based.
static class FbServiceClientAsync
{
public static Task<FacebookApiEventArgs> DoGetAsync(this FacebookClient client, string getPath, object parameters = null)
{
var tcs = new TaskCompletionSource<FacebookApiEventArgs>();
var obj = new object();
EventHandler<FacebookApiEventArgs> eventHandler = null;
eventHandler = (s, a) =>
{
@DVDPT
DVDPT / Bindings
Created September 2, 2014 15:23
Xamarin really simple binding
/*
class MonetaryAmount
{
double Amount {get;}
}
class Report
{
MonetaryAmount Ecpm {get;}
}
public interface IDataController
{
Task Load();
Task Save();
}
public abstract class AppViewModelBase : ViewModelBase //MVVM Light
{
(...)
protected abstract void Save(IStorage storage);
public interface IDataController
{
Task Load();
Task Save();
}
public abstract class AppViewModelBase : ViewModelBase //MVVM Light
{
(...)
protected abstract void Save(IStorage storage);
@DVDPT
DVDPT / Example of command.cs
Last active August 29, 2015 14:16
Example of command
private ICommand _someCommand;
public ICommand SomeCommand
{
get
{
return _someCommand
?? (_someCommand = CreateCommandForUserAction(
async () =>
{
@DVDPT
DVDPT / ExceptionHandler.cs
Last active August 29, 2015 14:16
ExceptionHander
ExceptionHandlerService.Instance.AddHandler(typeof(ServerErrorException), e => ErrorResources.Error_ServerError);
@DVDPT
DVDPT / LoadingSafeRun.cs
Last active August 29, 2015 14:16
LoadingSafeRun
internal async Task LoadingSafeRun(Func<Task> func, string loadingMessage, bool startedByUser = false)
{
try
{
StartLoadingOperation(loadingMessage);
await func();
StopLoadingOperation();
}
catch (Exception e)
{
@DVDPT
DVDPT / AdMesh for mobfox nav service.cs
Last active August 29, 2015 14:16
AdMesh for mobfox nav service
public interface IAppNavigationService
{
void GoToLogin();
void GoToHome();
void GoToReportDetails();
void GoToApplication();
void GoToCustomReport();
void GoToAbout();