This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static int Main(string[] args) => | |
Try | |
.Action(() => 0) | |
.WithCatch<Exception>(ex => 1}) | |
.Finally(CleanUpMethod); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static string CleanFileName(string fileName) | |
{ | |
return Path.GetInvalidFileNameChars().Aggregate(fileName, (current, c) => current.Replace(c.ToString(), string.Empty)); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static Task<HttpResponseMessage> GetAsync | |
(this HttpClient httpClient, string uri, Action<HttpRequestMessage> preAction) | |
{ | |
var httpRequestMessage = new HttpRequestMessage(HttpMethod.Get, uri); | |
preAction(httpRequestMessage); | |
return httpClient.SendAsync(httpRequestMessage); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static class DynamicExtensions | |
{ | |
public static dynamic ToDynamic(this object value) | |
{ | |
IDictionary<string, object> expando = new ExpandoObject(); | |
foreach (PropertyDescriptor property in TypeDescriptor.GetProperties(value.GetType())) | |
expando.Add(property.Name, property.GetValue(value)); | |
return expando as ExpandoObject; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
add-type @" | |
using System.Net; | |
using System.Security.Cryptography.X509Certificates; | |
public class TrustAllCertsPolicy : ICertificatePolicy { | |
public bool CheckValidationResult( | |
ServicePoint srvPoint, X509Certificate certificate, | |
WebRequest request, int certificateProblem) { | |
return true; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class HttpApiGuidlinesMiddleware : OwinMiddleware | |
{ | |
public HttpApiGuidlinesMiddleware(OwinMiddleware next) : base(next) { } | |
public override async Task Invoke(IOwinContext context) | |
{ | |
var isApiCall = context.Request.Path.StartsWithSegments(new PathString("/api")); | |
Stream originalStream = null; | |
Stream responseBuffer = null; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Assembly assembly = Assembly.GetExecutingAssembly(); | |
FileVersionInfo fvi = FileVersionInfo.GetVersionInfo(assembly.Location); | |
string version = fvi.FileVersion; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public TValue Value<TValue>(string value, TValue defaultValue = default(TValue)) | |
{ | |
if (string.IsNullOrEmpty(value)) return defaultValue; | |
var converter = TypeDescriptor.GetConverter(typeof (TValue)); | |
return (TValue) converter.ConvertFrom(value); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Text; | |
using RabbitMQ.Client; | |
namespace Publisher | |
{ | |
class Program | |
{ | |
static void Main(string[] args) | |
{ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
static class UriManager | |
{ | |
private static readonly IDictionary<string, Uri> Uris = new Dictionary<string, Uri>(); | |
public static Uri GetUriForService<TService>() | |
{ | |
return GetUri(typeof (TService).Name); | |
} | |
public static Uri GetUri(string serviceName) |