public static Tuple<Point, Point> IntersectLineAndCircle(this Builder builder, Line l, Circle c) { var eqXA = builder.Build((A, B) => (B ^ 2) + (A ^ 2), l.A, l.B); var eqXB = builder.Build((A, B, C, X, Y) => 2 * Y * A * B - 2 * X * (B ^ 2) + 2 * C * A, l.A, l.B, l.C, c.X, c.Y); var eqXC = builder.Build((A, B, C, X, Y, R) => 2 * Y * B * C + (Y ^ 2) * (B ^ 2) + (C ^ 2) + (X ^ 2) * (B ^ 2) - R * (B ^ 2), l.A, l.B, l.C, c.X, c.Y, c.R); var xRoots = builder.SolveQuadraticEquation(eqXA, eqXB, eqXC); var yRoots = xRoots.FMap(root => builder.GetLineYByX(l, root)); return Tuple.Create(new Point(xRoots.Item1, yRoots.Item1), new Point(xRoots.Item2, yRoots.Item2)); }
public static Tuple<Point, Point> IntersectCircles(this Builder builder, Circle c1, Circle c2) { var c = builder.Offset(c2, builder.Invert(c1.Center)); var eqA = builder.Build((X0, Y0) => 4 * (X0 ^ 2) + 4 * (Y0 ^ 2), c.X, c.Y); var eqYB = builder.Build((X0, Y0, R1, R2) => -4 * (Y0 ^ 3) - 4 * R1 * Y0 + 4 * Y0 * R2 - 4 * (X0 ^ 2) * Y0, c.X, c.Y, c1.R, c.R); var eqXB = builder.Build((X0, Y0, R1, R2) => -4 * (X0 ^ 3) - 4 * R1 * X0 + 4 * X0 * R2 - 4 * (Y0 ^ 2) * X0, c.X, c.Y, c1.R, c.R); var eqYC = builder.Build((X0, Y0, R1, R2) => (X0 ^ 4) + (R1 ^ 2) - 2 * (Y0 ^ 2) * R2 + 2 * (X0 ^ 2) * (Y0 ^ 2) - 2 * (X0 ^ 2) * R2 + (Y0 ^ 4) + (R2 ^ 2) + 2 * R1 * (Y0 ^ 2) - 2 * R1 * R2 - 2 * R1 * (X0 ^ 2), c.X, c.Y, c1.R, c.R); var eqXC = builder.Build((X0, Y0, R1, R2) => (Y0 ^ 4) + (R1 ^ 2) - 2 * (X0 ^ 2) * R2 + 2 * (Y0 ^ 2) * (X0 ^ 2) - 2 * (Y0 ^ 2) * R2 + (X0 ^ 4) + (R2 ^ 2) + 2 * R1 * (X0 ^ 2) - 2 * R1 * R2 - 2 * R1 * (Y0 ^ 2), c.X, c.Y, c1.R, c.R); var xRoots = builder.SolveQuadraticEquation(eqA, eqXB, eqXC); var yRoots = builder.SolveQuadraticEquation(eqA, eqYB, eqYC); return Tuple.Create( new Point(xRoots.Item1, yRoots.Item2), new Point(xRoots.Item2, yRoots.Item1) ).FMap(x => builder.Offset(x, c1.Center)); }
/// <summary> /// Starts running a new RestBus host. /// </summary> /// <param name="app">The Application builder</param> /// <param name="subscriber">The RestBus subscriber</param> /// <param name="skipRestBusServerCheck">Set to true to run the host even if the application server is the RestBus.AspNet server</param> public static void RunRestBusHost(this IApplicationBuilder app, IRestBusSubscriber subscriber, bool skipRestBusServerCheck) { if (app == null) throw new ArgumentNullException("app"); if (subscriber == null) throw new ArgumentNullException("subscriber"); if (!skipRestBusServerCheck && app.ApplicationServices.GetRequiredService<IHostingEnvironment>().Configuration[Server.Server.ConfigServerArgumentName] == Server.Server.ConfigServerAssembly) { //The application is running RestBusServer, so exit return; } var appFunc = app.Build(); var _loggerFactory = app.ApplicationServices.GetRequiredService<ILoggerFactory>(); var diagnosticSource = app.ApplicationServices.GetRequiredService<DiagnosticSource>(); var httpContextFactory = app.ApplicationServices.GetRequiredService<IHttpContextFactory>(); //TODO: Work on counting instances (all hosts + server) and adding the count to the logger name e.g RestBus.AspNet (2), consider including the typename as well. var application = new HostingApplication(appFunc, _loggerFactory.CreateLogger(Server.Server.ConfigServerAssembly), diagnosticSource, httpContextFactory); var host = new RestBusHost<HostingApplication.Context>(subscriber, application); //Register host for disposal var appLifeTime = app.ApplicationServices.GetRequiredService<IApplicationLifetime>(); appLifeTime.ApplicationStopping.Register(() => host.Dispose()); //TODO: Make ApplicationStopping event stop dequeueing items (StopPollingQueue) appLifeTime.ApplicationStopped.Register(() => host.Dispose()); //Start host host.Start(); }
internal static bool VerifyWithExtraRoots( this X509Chain chain, X509Certificate certificate, X509Certificate2Collection extraRoots) { chain.ChainPolicy.ExtraStore.AddRange(extraRoots); if (chain.Build(new X509Certificate2(certificate))) return true; else { // .NET returns UntrustedRoot status flag if the certificate is not in // the SYSTEM trust store. Check if it's the only problem with the chain. var onlySystemUntrusted = chain.ChainStatus.Length == 1 && chain.ChainStatus[0].Status == X509ChainStatusFlags.UntrustedRoot; // Sanity check that indeed that is the only problem with the root // certificate. var rootCert = chain.ChainElements[chain.ChainElements.Count - 1]; var rootOnlySystemUntrusted = rootCert.ChainElementStatus.Length == 1 && rootCert.ChainElementStatus[0].Status == X509ChainStatusFlags.UntrustedRoot; // Double check it's indeed one of the extra roots we've been given. var rootIsUserTrusted = extraRoots.Contains(rootCert.Certificate); return onlySystemUntrusted && rootOnlySystemUntrusted && rootIsUserTrusted; } }
/// <summary> /// Asserts that the specification is met. /// </summary> /// <param name="builder">The specification builder.</param> /// <param name="comparer">The result comparer.</param> public static void Assert(this IResultCentricAggregateQueryTestSpecificationBuilder builder, IResultComparer comparer) { if (builder == null) throw new ArgumentNullException("builder"); if (comparer == null) throw new ArgumentNullException("comparer"); var specification = builder.Build(); var runner = new ResultCentricAggregateQueryTestRunner(comparer); var result = runner.Run(specification); if (result.Failed) { if (result.ButException.HasValue) { using (var writer = new StringWriter()) { writer.WriteLine(" Expected: {0},", result.Specification.Then); writer.WriteLine(" But was: {0}", result.ButException.Value); #if NUNIT throw new NUnit.Framework.AssertionException(writer.ToString()); #elif XUNIT throw new Xunit.Sdk.AssertException(writer.ToString()); #endif } } if (result.ButResult.HasValue) { using (var writer = new StringWriter()) { writer.WriteLine(" Expected: {0},", result.Specification.Then); writer.WriteLine(" But was: {0}", result.ButResult.Value); #if NUNIT throw new NUnit.Framework.AssertionException(writer.ToString()); #elif XUNIT throw new Xunit.Sdk.AssertException(writer.ToString()); #endif } } if (result.ButEvents.HasValue) { using (var writer = new StringWriter()) { writer.WriteLine(" Expected: {0},", result.Specification.Then); writer.WriteLine(" But was: {0} event(s) ({1})", result.ButEvents.Value.Length, String.Join(",", result.ButEvents.Value.Select(_ => _.GetType().Name).ToArray())); #if NUNIT throw new NUnit.Framework.AssertionException(writer.ToString()); #elif XUNIT throw new Xunit.Sdk.AssertException(writer.ToString()); #endif } } } }
/// <summary> /// Removes any custom placement for a specific shape /// </summary> public static ContentTypeDefinitionBuilder ResetPlacement(this ContentTypeDefinitionBuilder builder, PlacementType placementType, string shapeType, string differentiator) { var serializer = new JavaScriptSerializer(); var placementSettings = GetPlacement(builder.Build(), placementType).ToList(); placementSettings = placementSettings.Where(x => x.ShapeType != shapeType && x.Differentiator != differentiator).ToList(); var placement = serializer.Serialize(placementSettings.ToArray()); return builder.WithSetting("ContentTypeSettings.Placement." + placementType, placement); }
public static void Assert(this IThenStateBuilder builder) { using (var scope = CompositionRoot.Instance.BeginLifetimeScope()) { var specification = builder.Build(); StoreGivens(scope, specification.Givens); HandleWhen(scope, specification.When); CompareActualAndExpectedThens(scope, specification.Thens); } }
public static void AssertNothingHappened(this IWhenStateBuilder builder) { using (var scope = CompositionRoot.Instance.BeginLifetimeScope()) { var specification = builder.Build(); StoreGivens(scope, specification.Givens); HandleWhen(scope, specification.When); var unitOfWork = scope.Resolve<UnitOfWork>(); NUnit.Framework.Assert.That(unitOfWork.GetChanges().SelectMany(aggregate => aggregate.Root.GetChanges()), Is.Empty, "Expected no events but found the following events:\n\t{0}", string.Join(",", unitOfWork.GetChanges().SelectMany(aggregate => aggregate.Root.GetChanges()).Select(@event => @event.GetType().Name))); } }
/// <summary> /// Builds the autofac container and applies the advices from the configuration to the registered services /// </summary> /// <param name="builder"></param> /// <param name="configuration"></param> /// <returns></returns> public static IForceFieldAutofacContainer Build(this ContainerBuilder builder, Configuration configuration) { Guard.ArgumentIsNotNull(() => builder); Guard.ArgumentIsNotNull(() => configuration); //Register all advices into the container, so they can be resolved foreach (var adviceType in configuration.GetRegisteredAdvices()) builder.RegisterType(adviceType); //Build the real autofac container and set it as inner container var innerContainer = builder.Build(); //Inject the builded autofac container into the configuration so it can resolve the builded advices when needed configuration.SetContainer(innerContainer); return new ForceFieldAutofacContainer(innerContainer, configuration); }
// ------------------------------------------------------------------ // Desc: // ------------------------------------------------------------------ public static void Rebuild( this exSpriteBorder _spriteBorder ) { Texture2D texture = exEditorHelper.LoadAssetFromGUID<Texture2D>(_spriteBorder.guiBorder.textureGUID); _spriteBorder.Build (texture); }
public static void BuildAsBuilder(this IBuilder builder) { builder.Build(); }
public static Tuple<Expr, Expr> SolveQuadraticEquation(this Builder builder, Expr a, Expr b, Expr c) { var d = builder.Build((A, B, C) => sqrt((B ^ 2) - 4 * A * C), a, b, c); var x1 = builder.Build((A, B, D) => (-B + D) / (2 * A), a, b, d); var x2 = builder.Build((A, B, D) => (-B - D) / (2 * A), a, b, d); return Tuple.Create(x1, x2); }
public static Expr GetLineYByX(this Builder builder, Line l, Expr x) { return builder.Build((A, B, C, X) => -(A * X + C) / B, l.A, l.B, l.C, x); }
public static Expr CotangentBetweenLine(this Builder builder, Line l1, Line l2) { return builder.Build((A1, B1, A2, B2) => (A1 * A2 + B1 * B2) / (A1 * B2 - A2 * B1), l1.A, l1.B, l2.A, l2.B); }
public static IAppBuilder Where(this IAppBuilder builder, Action<Environment, Action<bool>> predicate, Action<IAppBuilder> stack) { return builder.Use(Middleware, predicate, builder.Build<AppDelegate>(stack)); }
public static HttpWebRequest CreateRequest(this IUri uri) { var request = (HttpWebRequest)WebRequest.Create(uri.Build()); request.Method = "GET"; request.ContentType = "application/xml"; request.Headers.Add("x-ms-version", "2012-08-01"); return request; }
static IContainer CreateContainer(this ContainerBuilder builder) { return builder.Build(); }
public static void Register(this MemcachedConfigBuilder builder) { client = new MemcachedClient(builder.Build()); }
/// <summary> /// Asserts that the specification is met. /// </summary> /// <param name="builder">The specification builder.</param> /// <param name="comparer">The event comparer.</param> public static void Assert(this IEventCentricAggregateCommandTestSpecificationBuilder builder, IEventComparer comparer) { if (builder == null) throw new ArgumentNullException("builder"); if (comparer == null) throw new ArgumentNullException("comparer"); var specification = builder.Build(); var runner = new EventCentricAggregateCommandTestRunner(comparer); var result = runner.Run(specification); if (result.Failed) { if (result.ButException.HasValue) { using (var writer = new StringWriter()) { writer.WriteLine(" Expected: {0} event(s),", result.Specification.Thens.Length); writer.WriteLine(" But was: {0}", result.ButException.Value); #if NUNIT throw new NUnit.Framework.AssertionException(writer.ToString()); #elif XUNIT throw new Xunit.Sdk.AssertException(writer.ToString()); #endif } } if (result.ButEvents.HasValue) { if (result.ButEvents.Value.Length != result.Specification.Thens.Length) { using (var writer = new StringWriter()) { writer.WriteLine(" Expected: {0} event(s) ({1}),", result.Specification.Thens.Length, String.Join(",", result.Specification.Thens.Select(_ => _.GetType().Name).ToArray())); writer.WriteLine(" But was: {0} event(s) ({1})", result.ButEvents.Value.Length, String.Join(",", result.ButEvents.Value.Select(_ => _.GetType().Name).ToArray())); #if NUNIT throw new NUnit.Framework.AssertionException(writer.ToString()); #elif XUNIT throw new Xunit.Sdk.AssertException(writer.ToString()); #endif } } using (var writer = new StringWriter()) { writer.WriteLine(" Expected: {0} event(s) ({1}),", result.Specification.Thens.Length, String.Join(",", result.Specification.Thens.Select(_ => _.GetType().Name).ToArray())); writer.WriteLine(" But found the following differences:"); foreach (var difference in result.Specification.Thens. Zip(result.ButEvents.Value, (expected, actual) => new Tuple<object, object>(expected, actual)). SelectMany(_ => comparer.Compare(_.Item1, _.Item2))) { writer.WriteLine(" {0}", difference.Message); } #if NUNIT throw new NUnit.Framework.AssertionException(writer.ToString()); #elif XUNIT throw new Xunit.Sdk.AssertException(writer.ToString()); #endif } } } }
public static void AddFromXml(this IGraph g, XElement xRDF) { g.Build(xRDF.Elements().SelectMany(element => Xml2Triples(element,g))); }
/// <summary> /// Defines a custom placement /// </summary> public static ContentTypeDefinitionBuilder Placement(this ContentTypeDefinitionBuilder builder, PlacementType placementType, string shapeType, string differentiator, string zone, string position) { var placement = AddPlacement(builder.Build(), placementType, shapeType, differentiator, zone, position); return builder.WithSetting("ContentTypeSettings.Placement." + placementType, placement); }
/// <summary> /// Returns a list of actions /// </summary> /// <param name="actions"></param> /// <returns></returns> private static IEnumerable<IAction> GetActions(this TouchActions actions) { List<IAction> retVal = null; if (null == actions) { return null; } try { //var compositeActionObj = _ActionFieldInfo.Value.GetValue(actions); retVal = _ActionsListFieldInfo.Value.GetValue(actions.Build()) as List<IAction>; } catch { // unable to get the field } return retVal; }
// ------------------------------------------------------------------ // Desc: // ------------------------------------------------------------------ public static void Rebuild( this exTileMapRenderer _tileMapRenderer ) { _tileMapRenderer.Build (); }
static Expr Mean(this Builder builder, Expr a, Expr b) => builder.Build((x, y) => (x + y) / 2, a, b);
/// <summary> /// Asserts that the specification is met. /// </summary> /// <param name="builder">The specification builder.</param> /// <param name="comparer">The exception comparer.</param> public static void Assert(this IExceptionCentricAggregateCommandTestSpecificationBuilder builder, IExceptionComparer comparer) { if (builder == null) throw new ArgumentNullException("builder"); if (comparer == null) throw new ArgumentNullException("comparer"); var specification = builder.Build(); var runner = new ExceptionCentricAggregateCommandTestRunner(comparer); var result = runner.Run(specification); if (result.Failed) { if (result.ButException.HasValue) { if (result.ButException.Value.GetType() != result.Specification.Throws.GetType()) { using (var writer = new StringWriter()) { writer.WriteLine(" Expected: {0},", result.Specification.Throws); writer.WriteLine(" But was: {0}", result.ButException.Value); #if NUNIT throw new NUnit.Framework.AssertionException(writer.ToString()); #elif XUNIT throw new Xunit.Sdk.AssertException(writer.ToString()); #endif } } using (var writer = new StringWriter()) { writer.WriteLine(" Expected: {0},", result.Specification.Throws); writer.WriteLine(" But found the following differences:"); foreach (var difference in comparer.Compare(result.Specification.Throws, result.ButException.Value)) { writer.WriteLine(" {0}", difference.Message); } #if NUNIT throw new NUnit.Framework.AssertionException(writer.ToString()); #elif XUNIT throw new Xunit.Sdk.AssertException(writer.ToString()); #endif } } if (result.ButEvents.HasValue) { using (var writer = new StringWriter()) { writer.WriteLine(" Expected: {0},", result.Specification.Throws); writer.WriteLine(" But was: {0} event(s) ({1})", result.ButEvents.Value.Length, String.Join(",", result.ButEvents.Value.Select(_ => _.GetType().Name).ToArray())); #if NUNIT throw new NUnit.Framework.AssertionException(writer.ToString()); #elif XUNIT throw new Xunit.Sdk.AssertException(writer.ToString()); #endif } } using (var writer = new StringWriter()) { writer.WriteLine(" Expected: {0},", result.Specification.Throws); writer.WriteLine(" But no exception occurred"); #if NUNIT throw new NUnit.Framework.AssertionException(writer.ToString()); #elif XUNIT throw new Xunit.Sdk.AssertException(writer.ToString()); #endif } } }
public static Circle MakeCircle(this Builder builder, Point p1, Point p2) { var r = builder.Build((x1, x2, y1, y2) => ((x1 - x2) ^ 2) + ((y1 - y2) ^ 2), p1.X, p2.X, p1.Y, p2.Y); return new Circle(builder, p1.X, p1.Y, r); }
public static string AsRequestBody(this FormBodyBuilder This) { return This.Build().AsRequestBody(); }
public static Point IntersectLines(this Builder builder, Line l1, Line l2) { var x = builder.Build((A1, B1, C1, A2, B2, C2) => (B1 * C2 - B2 * C1) / (A1 * B2 - A2 * B1), l1.A, l1.B, l1.C, l2.A, l2.B, l2.C); var y = builder.Build((A1, B1, C1, A2, B2, C2) => (C1 * A2 - C2 * A1) / (A1 * B2 - A2 * B1), l1.A, l1.B, l1.C, l2.A, l2.B, l2.C); return new Point(x, y); }
/// <summary> /// Gets the output assembly of the given project. If the project /// was never built before, it's built before returning the output /// assembly. /// </summary> /// <param name="project">The project to get the output assembly from.</param> /// <param name="buildIfMissing">Whether to build the project if the output assembly is missing.</param> public static Task<Assembly> GetOutputAssembly(this IProjectNode project, bool buildIfMissing = true) { var fileName = (string)project.Properties.TargetFileName; var msBuild = project.Adapt().AsMsBuildProject(); if (msBuild == null) throw new ArgumentException(Strings.IProjectNodeExtensions.NotMsBuildProject(project.DisplayName)); // NOTE: we load from the obj/Debug|Release folder, which is // the one built in the background by VS continuously. var intermediateDir = msBuild.AllEvaluatedProperties .Where(p => p.Name == "IntermediateOutputPath") // If we grab the EvaluatedValue, it won't have the current // global properties overrides, like Configuration and Debug. .Select(p => msBuild.ExpandString(p.UnevaluatedValue)) .FirstOrDefault(); if (string.IsNullOrEmpty(fileName) || string.IsNullOrEmpty(intermediateDir) || string.IsNullOrEmpty(project.Properties.MSBuildProjectDirectory)) { tracer.Warn(Strings.IProjectNodeExtensions.NoTargetAssemblyName(project.DisplayName)); return TaskHelpers.FromResult<Assembly>(null); } var outDir = (string)Path.Combine(project.Properties.MSBuildProjectDirectory, intermediateDir); var assemblyFile = Path.Combine(outDir, fileName); if (!File.Exists(assemblyFile) && !buildIfMissing) return TaskHelpers.FromResult<Assembly>(null); return Task.Factory.StartNew<Assembly>(() => { if (!File.Exists(assemblyFile)) { var success = project.Build().Result; if (success) { // Let the build finish writing the file for (int i = 0; i < 5; i++) { if (File.Exists(assemblyFile)) break; Thread.Sleep(200); } } if (!File.Exists(assemblyFile)) { tracer.Warn(Strings.IProjectNodeExtensions.NoBuildOutput(project.DisplayName, assemblyFile)); return null; } } var assemblyName = AssemblyName.GetAssemblyName(assemblyFile); var vsProject = project.As<IVsHierarchy>(); var localServices = project.As<IServiceProvider>(); var globalServices = GlobalServiceProvider.Instance; if (vsProject == null || localServices == null || globalServices == null) { tracer.Warn(Strings.IProjectNodeExtensions.InvalidVsContext); return null; } var openScope = globalServices.GetService<SVsSmartOpenScope, IVsSmartOpenScope>(); var dtar = localServices.GetService<SVsDesignTimeAssemblyResolution, IVsDesignTimeAssemblyResolution>(); // As suggested by Christy Henriksson, we reuse the type discovery service // but just for the IDesignTimeAssemblyLoader interface. The actual // assembly reading is done by the TFP using metadata only :) var dts = globalServices.GetService<DynamicTypeService>(); var ds = dts.GetTypeDiscoveryService(vsProject); var dtal = ds as IDesignTimeAssemblyLoader; if (openScope == null || dtar == null || dts == null || ds == null || dtal == null) { tracer.Warn(Strings.IProjectNodeExtensions.InvalidTypeContext); return null; } var provider = new VsTargetFrameworkProvider(dtar, dtal, openScope); return provider.GetReflectionAssembly(assemblyName); }, CancellationToken.None, TaskCreationOptions.None, TaskScheduler.Default); }
// ------------------------------------------------------------------ // Desc: // ------------------------------------------------------------------ public static void Rebuild( this exSpriteFont _spriteFont ) { _spriteFont.Build (); }