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
| protected override void Load(ContainerBuilder builder) | |
| { | |
| builder.Register(CreatedDbFunc).As<Func<Owned<IDb>>>().InstancePerDependency(); | |
| builder.Register(c => CreatedDbWithConnectionFunc()).As<Func<DbConnection, Owned<IDb>>>().InstancePerDependency(); | |
| builder.RegisterType<CurrentDatabase>().InstancePerMatchingLifetimeScope(LifetimeScopes.Workspace); | |
| } | |
| private Func<Owned<IDb>> CreatedDbFunc(IComponentContext context) | |
| { |
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
| var sb = new StringBuilder(); | |
| foreach (var src in container.ComponentRegistry.Sources.Select(s => s.ToString()).OrderBy(s => s)) | |
| sb.AppendLine(src); | |
| sb.AppendLine(); | |
| foreach (var reg in container.ComponentRegistry.Registrations.OrderBy(r => r.Activator.LimitType.FullName)) | |
| { | |
| sb.AppendLine(reg.Activator.LimitType.FullName); | |
| sb.Append(" ").AppendLine(reg.Lifetime.GetType().Name); |
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
| void Main() | |
| { | |
| var result = MakeCalls("ABCDEFGHIJKLMNOP", c => CallWebService(c), 2).Result; | |
| result.Dump(); | |
| } | |
| public async System.Threading.Tasks.Task<string> CallWebService(char c) | |
| { | |
| await System.Threading.Tasks.Task.Delay(2000); | |
| return c.ToString() + DateTime.Now.Second.ToString(); |
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 void ForSingleMaybe<T>(this IEnumerable<T> sequence, Action<T> action) | |
| { | |
| using(var enumerator = sequence.GetEnumerator()) | |
| { | |
| if(!enumerator.MoveNext()) | |
| return; | |
| var item = enumerator.Current; | |
| if(enumerator.MoveNext()) | |
| throw new InvalidOperationException("Sequence contains too many elements"); |
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
| builder.RegisterAuthorizationFilterForAttribute<MustBeLoggedInFilter, MustBeLoggedInAttribute>(ThisAssembly); | |
| public static class AutofacExtensions | |
| { | |
| public static IRegistrationBuilder<object, IConcreteActivatorData, SingleRegistrationStyle> RegisterAuthorizationFilterForAttribute<TService, TAttribute>( | |
| this ContainerBuilder builder, | |
| params Assembly[] controllerAssemblies | |
| ) where TAttribute : Attribute |
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 Guid NewHotGuid() | |
| { | |
| using (var client = new HttpClient()) | |
| { | |
| var result = client.GetStringAsync("http://secretgeek.net/HotGuids/").Result; | |
| var guid = Regex.Match(result, @"id='guid'\>\{([^\}]+)").Groups[1].Value; | |
| return Guid.Parse(guid); | |
| } | |
| } |
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
| ko.bindingHandlers.tags = { | |
| init: function (element, valueAccessor, allBindingsAccessor) { | |
| var bind = function() { | |
| var observable = valueAccessor(); | |
| observable($(element).tagit("assignedTags").join(',')); | |
| }; | |
| var options = { | |
| allowSpaces: 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
| public static string Format(this Exception exception, bool includeStackTrace = false) | |
| { | |
| var sb = new StringBuilder(); | |
| Format(sb, exception, false); | |
| if (includeStackTrace) | |
| { | |
| sb.AppendLine(); | |
| Format(sb, exception, true); | |
| } | |
| return sb.ToString(); |
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
| private void RestoreDatabase(Server server) | |
| { | |
| Program.Log("Restoring {0} on {1}".With(_options.Database, _options.Server)); | |
| if (server.Databases[_options.Database] != null) | |
| server.KillAllProcesses(_options.Database); | |
| else | |
| new Database(server, _options.Database).Create(); |