Skip to content

Instantly share code, notes, and snippets.

View poulfoged's full-sized avatar

Poul Foged Nielsen poulfoged

View GitHub Profile
using System;
using System.IO;
using System.Linq;
using System.Threading;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.Net.Http;
using System.Collections.Generic;
using System.Net;
using System.Threading.Tasks;
using System.Text;
internal static class AsyncHelper
{
public static Task ForEachAsync<T>(this IEnumerable<T> source, int dop, Func<T, Task> body)
{
return Task.WhenAll(
Partitioner.Create(source)
.GetPartitions(dop)
.Select(partition => Task.Run(async delegate
{
using (partition)
using System.IO;
namespace Streams
{
/// <summary>
/// Just a basis class that makes it easy to overwrite what you want
/// </summary>
public abstract class StreamDecoratorBase : Stream
{
/// <summary>
internal class ShortNameSerializationBinder<TBase> : DefaultSerializationBinder where TBase : class
{
private static Dictionary<string, Type> types;
public ShortNameSerializationBinder()
{
types = ReflectiveEnumerator.GetEnumerableOfType<TBase>().ToDictionary(i => i.Name, i => i);
}
public override void BindToName(Type serializedType, out string assemblyName, out string typeName)
internal static class StringExtensions
{
public static string ReplaceCaseInsensitive(this string source, object replacements)
{
replacements
.GetType()
.GetProperties()
.Select(p => new {p.Name, Value = p.GetValue(replacements) as string ?? ""})
.ToList()
.ForEach(p => { source = ReplaceCaseInsensitive(source, string.Format("{{{0}}}", p.Name), p.Value); });
public class StreamFormatter : MediaTypeFormatter
{
private readonly MediaTypeHeaderValue _mediaType;
/// <summary>
/// Default constructor
/// </summary>
/// <param name="mediaType"></param>
public StreamFormatter(MediaTypeHeaderValue mediaType)
{
internal class TemporaryDirectory : IDisposable
{
private readonly DirectoryInfo _directoryInfo;
private bool _disposed;
public TemporaryDirectory()
{
_directoryInfo = new DirectoryInfo(Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString("N")));
_directoryInfo.Create();
}
internal class TemporaryFile : IDisposable
{
private readonly FileInfo _fileInfo;
private bool _disposed;
public TemporaryFile(string extension = "tmp")
{
_fileInfo = CreateFilename(extension);
}
internal static class ReflectiveEnumerator
{
public static IEnumerable<Type> GetEnumerableOfType<T>() where T : class
{
var objects = Assembly
.GetAssembly(typeof (T))
.GetTypes()
.Where(myType => myType.IsClass && !myType.IsAbstract && myType.IsSubclassOf(typeof (T)))
.ToList();
<link rel="import" href="../core-ajax/core-ajax.html">
<link rel="import" href="../core-scaffold/core-scaffold.html">
<link rel="import" href="../core-header-panel/core-header-panel.html">
<link rel="import" href="../core-menu/core-menu.html">
<link rel="import" href="../core-item/core-item.html">
<link rel="import" href="../core-icon-button/core-icon-button.html">
<link rel="import" href="../core-toolbar/core-toolbar.html">
<link rel="import" href="../core-menu/core-submenu.html">
<link rel="import" href="../core-field/core-field.html">
<link rel="import" href="../core-icon/core-icon.html">