internal Tuple <IBundle, IBundleMetadata> AddBundleData(BundleData bundleData) { this.FrameworkAdaptor.InstalledBundles.Add(bundleData); IBundle item = this.ServiceContainer.GetFirstOrDefaultService <IBundleFactory>().CreateBundle(bundleData); this.Bundles.Add(item); IBundleMetadata bundle = this.FrameworkAdaptor.State.MetadataBuilder.BuildBundleMetadata(bundleData, item.BundleID); this.FrameworkAdaptor.State.AddBundle(bundle); return(TupleUtility.CreateTuple <IBundle, IBundleMetadata>(item, bundle)); }
private static List <Template <Func <SmtpClient>, List <MailMessage> > > PrepareShipment(MailDistributor distributor, IEnumerable <MailMessage> mails, Func <MailMessage, bool> filter) { var partitionedMails = new PartitionCollection <MailMessage>(mails, distributor.DeliverySize); var carriers = new List <Template <Func <SmtpClient>, List <MailMessage> > >(); while (partitionedMails.HasPartitions) { carriers.Add(TupleUtility.CreateTwo(distributor.Carrier, new List <MailMessage>(filter == null ? partitionedMails : partitionedMails.FindAll(filter) ))); } return(carriers); }
private Template <string, string> AuthorizationHeaderParser(HttpContext context, string authorizationHeader) { if (AuthenticationUtility.IsAuthenticationSchemeValid(authorizationHeader, Options.AuthenticationScheme) && authorizationHeader.Length > Options.AuthenticationScheme.Length) { var credentials = authorizationHeader.Remove(0, Options.AuthenticationScheme.Length + 1).Split(':'); if (credentials.Length == 2) { var publicKey = credentials[0]; var signature = credentials[1]; if (!publicKey.IsNullOrWhiteSpace() && !signature.IsNullOrWhiteSpace()) { return(TupleUtility.CreateTwo(publicKey, signature)); } } } return(null); }
public List <Tuple <IFragmentBundleMetadataNode, List <IAssemblyMetadataNode> > > AttachAllFragments() { List <IFragmentBundleMetadata> metadatas = BundleUtility.GetMetadatas <IFragmentBundleMetadata>(base.ConstraintResolver.State.Bundles); BundleUtility.BindFragmentMetadatas((Interface1)base.Metadata, metadatas); List <Interface2> unResolverNodes = base.ConstraintResolver.State.Resolver.UnResolverNodes; BundleUtility.BuildFragments(this); List <Tuple <IFragmentBundleMetadataNode, List <IAssemblyMetadataNode> > > rt = new List <Tuple <IFragmentBundleMetadataNode, List <IAssemblyMetadataNode> > >(this.FragmentNodes.Count); this.FragmentNodes.ForEach(delegate(IFragmentBundleMetadataNode a) { base.ConstraintResolver.ResolvedAssemblyMetadataNodes.AddRange(a.SharedAssemblyNodes); base.ConstraintResolver.ResolvedAssemblyMetadataNodes.AddRange(a.PrivateAssemblyNodes); }); this.FragmentNodes.ForEach(delegate(IFragmentBundleMetadataNode fragementNode) { rt.Add(TupleUtility.CreateTuple <IFragmentBundleMetadataNode, List <IAssemblyMetadataNode> >(fragementNode, new List <IAssemblyMetadataNode>(fragementNode.SharedAssemblyNodes))); }); return(rt); }
private bool TryAuthenticate(HttpContext context, Dictionary <string, string> credentials, out ClaimsPrincipal result) { if (Options.Authenticator == null) { throw new InvalidOperationException("The {0} delegate cannot be null.".FormatWith(Options.Authenticator)); } string password, userName, clientResponse, nonce, nonceCount; credentials.TryGetValue(DigestAuthenticationUtility.CredentialUserName, out userName); credentials.TryGetValue(DigestAuthenticationUtility.CredentialResponse, out clientResponse); credentials.TryGetValue(DigestAuthenticationUtility.CredentialNonceCount, out nonceCount); if (credentials.TryGetValue(DigestAuthenticationUtility.CredentialNonce, out nonce)) { result = null; Func <string, TimeSpan, bool> nonceExpiredParser = Options.NonceExpiredParser; bool staleNonce = nonceExpiredParser(nonce, TimeSpan.FromSeconds(30)); context.Items["staleNonce"] = staleNonce.ToString().ToUpperInvariant(); if (staleNonce) { return(false); } Template <DateTime, string> previousNonce; if (NonceCounter.TryGetValue(nonce, out previousNonce)) { if (previousNonce.Arg2.Equals(nonceCount, StringComparison.Ordinal)) { return(false); } } else { NonceCounter.TryAdd(nonce, TupleUtility.CreateTwo(DateTime.UtcNow, nonceCount)); } } result = Options.Authenticator(userName, out password); string serverResponse = Options?.DigestAccessSigner(new DigestAccessAuthenticationParameters(credentials.ToImmutableDictionary(), context.Request.Method, password, Options.Algorithm))?.ToHexadecimal(); return(serverResponse != null && (serverResponse.Equals(clientResponse, StringComparison.Ordinal) && Condition.IsNotNull(result))); }
private Template <string, string> AuthorizationHeaderParser(HttpContext context, string authorizationHeader) { if (AuthenticationUtility.IsAuthenticationSchemeValid(authorizationHeader, AuthenticationScheme)) { string base64Credentials = authorizationHeader.Remove(0, AuthenticationScheme.Length + 1); if (StringUtility.IsBase64(base64Credentials)) { string[] credentials = StringConverter.FromBytes(Convert.FromBase64String(base64Credentials), options => { options.Encoding = EncodingUtility.AsciiEncoding; options.Preamble = PreambleSequence.Remove; }).Split(AuthenticationUtility.BasicAuthenticationCredentialSeparator); if (credentials.Length == 2 && !string.IsNullOrEmpty(credentials[0]) && !string.IsNullOrEmpty(credentials[1])) { return(TupleUtility.CreateTwo(credentials[0], credentials[1])); } } } return(null); }
private object ParseReadXmlDictionary(XmlReader reader, Type valueType) { var values = new Dictionary <string, string>(); var hierarchy = reader.ToHierarchy(); var items = hierarchy.Find(h => h.Instance.Name == EnumerableElementName && h.Depth == 1).ToList(); foreach (var item in items) { if (item.HasChildren) { try { var key = item.GetChildren().SingleOrDefault(); var value = key?.GetChildren().SingleOrDefault(); if (value != null) { values.Add(key.Instance.Value.ToString(), value.Instance.Value.ToString()); } } catch (Exception ex) { throw new NotSupportedException("Deserialization of complex objects is not supported in this version.", ex); } } } var dictionaryType = (valueType.GetGenericArguments() ?? valueType.GetAncestorsAndSelf(typeof(object)).Yield()).ToArray(); var dictionary = typeof(Dictionary <,>).MakeGenericType(dictionaryType); var castedValues = values.Select(pair => TupleUtility.CreateTwo(ObjectConverter.ChangeType(pair.Key, dictionaryType[0]), ObjectConverter.ChangeType(pair.Value, dictionaryType[1]))).ToList(); var instance = Activator.CreateInstance(dictionary); var addMethod = valueType.GetMethod("Add"); foreach (var item in castedValues) { addMethod.Invoke(instance, new[] { item.Arg1, item.Arg2 }); } return(instance); }
/// <summary> /// Creates a new <see cref="ActionFactory{TTuple}"/> instance encapsulating the specified <paramref name="method"/> and five generic arguments. /// </summary> /// <typeparam name="T1">The type of the first parameter of the delegate <paramref name="method"/>.</typeparam> /// <typeparam name="T2">The type of the second parameter of the delegate <paramref name="method"/>.</typeparam> /// <typeparam name="T3">The type of the third parameter of the delegate <paramref name="method"/>.</typeparam> /// <typeparam name="T4">The type of the fourth parameter of the delegate <paramref name="method"/>.</typeparam> /// <typeparam name="T5">The type of the fifth parameter of the delegate <paramref name="method"/>.</typeparam> /// <param name="method">The delegate to invoke.</param> /// <param name="arg1">The first parameter of the delegate <paramref name="method"/>.</param> /// <param name="arg2">The second parameter of the delegate <paramref name="method"/>.</param> /// <param name="arg3">The third parameter of the delegate <paramref name="method"/>.</param> /// <param name="arg4">The fourth parameter of the delegate <paramref name="method"/>.</param> /// <param name="arg5">The fifth parameter of the delegate <paramref name="method"/>.</param> /// <returns>An instance of <see cref="ActionFactory{TTuple}"/> object initialized with the specified <paramref name="method"/> and five generic arguments.</returns> public static ActionFactory <Template <T1, T2, T3, T4, T5> > Create <T1, T2, T3, T4, T5>(Action <T1, T2, T3, T4, T5> method, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5) { return(new ActionFactory <Template <T1, T2, T3, T4, T5> >(tuple => method(tuple.Arg1, tuple.Arg2, tuple.Arg3, tuple.Arg4, tuple.Arg5), TupleUtility.CreateFive(arg1, arg2, arg3, arg4, arg5), method)); }
/// <summary> /// Creates a new <see cref="ActionFactory{TTuple}"/> instance encapsulating the specified <paramref name="method"/> and three generic arguments. /// </summary> /// <typeparam name="T1">The type of the first parameter of the delegate <paramref name="method"/>.</typeparam> /// <typeparam name="T2">The type of the second parameter of the delegate <paramref name="method"/>.</typeparam> /// <typeparam name="T3">The type of the third parameter of the delegate <paramref name="method"/>.</typeparam> /// <param name="method">The delegate to invoke.</param> /// <param name="arg1">The first parameter of the delegate <paramref name="method"/>.</param> /// <param name="arg2">The second parameter of the delegate <paramref name="method"/>.</param> /// <param name="arg3">The third parameter of the delegate <paramref name="method"/>.</param> /// <returns>An instance of <see cref="ActionFactory{TTuple}"/> object initialized with the specified <paramref name="method"/> and three generic arguments.</returns> public static ActionFactory <Template <T1, T2, T3> > Create <T1, T2, T3>(Action <T1, T2, T3> method, T1 arg1, T2 arg2, T3 arg3) { return(new ActionFactory <Template <T1, T2, T3> >(tuple => method(tuple.Arg1, tuple.Arg2, tuple.Arg3), TupleUtility.CreateThree(arg1, arg2, arg3), method)); }
/// <summary> /// Creates a new <see cref="ActionFactory{TTuple}"/> instance encapsulating the specified <paramref name="method"/> and sixteen generic arguments. /// </summary> /// <typeparam name="T1">The type of the first parameter of the delegate <paramref name="method"/>.</typeparam> /// <typeparam name="T2">The type of the second parameter of the delegate <paramref name="method"/>.</typeparam> /// <typeparam name="T3">The type of the third parameter of the delegate <paramref name="method"/>.</typeparam> /// <typeparam name="T4">The type of the fourth parameter of the delegate <paramref name="method"/>.</typeparam> /// <typeparam name="T5">The type of the fifth parameter of the delegate <paramref name="method"/>.</typeparam> /// <typeparam name="T6">The type of the sixth parameter of the delegate <paramref name="method"/>.</typeparam> /// <typeparam name="T7">The type of the seventh parameter of the delegate <paramref name="method"/>.</typeparam> /// <typeparam name="T8">The type of the eighth parameter of the delegate <paramref name="method"/>.</typeparam> /// <typeparam name="T9">The type of the ninth parameter of the delegate <paramref name="method"/>.</typeparam> /// <typeparam name="T10">The type of the tenth parameter of the delegate <paramref name="method"/>.</typeparam> /// <typeparam name="T11">The type of the eleventh parameter of the delegate <paramref name="method"/>.</typeparam> /// <typeparam name="T12">The type of the twelfth parameter of the delegate <paramref name="method"/>.</typeparam> /// <typeparam name="T13">The type of the thirteenth parameter of the delegate <paramref name="method"/>.</typeparam> /// <typeparam name="T14">The type of the fourteenth parameter of the delegate <paramref name="method"/>.</typeparam> /// <typeparam name="T15">The type of the fifteenth parameter of the delegate <paramref name="method"/>.</typeparam> /// <typeparam name="T16">The type of the sixteenth parameter of the delegate <paramref name="method"/>.</typeparam> /// <param name="method">The delegate to invoke.</param> /// <param name="arg1">The first parameter of the delegate <paramref name="method"/>.</param> /// <param name="arg2">The second parameter of the delegate <paramref name="method"/>.</param> /// <param name="arg3">The third parameter of the delegate <paramref name="method"/>.</param> /// <param name="arg4">The fourth parameter of the delegate <paramref name="method"/>.</param> /// <param name="arg5">The fifth parameter of the delegate <paramref name="method"/>.</param> /// <param name="arg6">The sixth parameter of the delegate <paramref name="method"/>.</param> /// <param name="arg7">The seventh parameter of the delegate <paramref name="method"/>.</param> /// <param name="arg8">The eighth parameter of the delegate <paramref name="method"/>.</param> /// <param name="arg9">The ninth parameter of the delegate <paramref name="method"/>.</param> /// <param name="arg10">The tenth parameter of the delegate <paramref name="method"/>.</param> /// <param name="arg11">The eleventh parameter of the delegate <paramref name="method"/>.</param> /// <param name="arg12">The twelfth parameter of the delegate <paramref name="method"/>.</param> /// <param name="arg13">The thirteenth parameter of the delegate <paramref name="method"/>.</param> /// <param name="arg14">The fourteenth parameter of the delegate <paramref name="method"/>.</param> /// <param name="arg15">The fifteenth parameter of the delegate <paramref name="method"/>.</param> /// <param name="arg16">The sixteenth parameter of the delegate <paramref name="method"/>.</param> /// <returns>An instance of <see cref="ActionFactory{TTuple}"/> object initialized with the specified <paramref name="method"/> and sixteen generic arguments.</returns> public static ActionFactory <Template <T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16> > Create <T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16>(Action <T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16> method, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9, T10 arg10, T11 arg11, T12 arg12, T13 arg13, T14 arg14, T15 arg15, T16 arg16) { return(new ActionFactory <Template <T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16> >(tuple => method(tuple.Arg1, tuple.Arg2, tuple.Arg3, tuple.Arg4, tuple.Arg5, tuple.Arg6, tuple.Arg7, tuple.Arg8, tuple.Arg9, tuple.Arg10, tuple.Arg11, tuple.Arg12, tuple.Arg13, tuple.Arg14, tuple.Arg15, tuple.Arg16), TupleUtility.CreateSixteen(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, arg14, arg15, arg16), method)); }
/// <summary> /// Creates a new <see cref="ActionFactory{TTuple}"/> instance encapsulating the specified <paramref name="method"/> and two generic arguments. /// </summary> /// <typeparam name="T1">The type of the first parameter of the delegate <paramref name="method"/>.</typeparam> /// <typeparam name="T2">The type of the second parameter of the delegate <paramref name="method"/>.</typeparam> /// <param name="method">The delegate to invoke.</param> /// <param name="arg1">The first parameter of the delegate <paramref name="method"/>.</param> /// <param name="arg2">The second parameter of the delegate <paramref name="method"/>.</param> /// <returns>An instance of <see cref="ActionFactory{TTuple}"/> object initialized with the specified <paramref name="method"/> and two generic arguments.</returns> public static ActionFactory <Template <T1, T2> > Create <T1, T2>(Action <T1, T2> method, T1 arg1, T2 arg2) { return(new ActionFactory <Template <T1, T2> >(tuple => method(tuple.Arg1, tuple.Arg2), TupleUtility.CreateTwo(arg1, arg2), method)); }
/// <summary> /// Creates a new <see cref="ActionFactory{TTuple}"/> instance encapsulating the specified <paramref name="method"/> and one generic argument. /// </summary> /// <typeparam name="T">The type of the parameter of the delegate <paramref name="method"/>.</typeparam> /// <param name="method">The delegate to invoke.</param> /// <param name="arg">The parameter of the delegate <paramref name="method"/>.</param> /// <returns>An instance of <see cref="ActionFactory{TTuple}"/> object initialized with the specified <paramref name="method"/> and one generic argument.</returns> public static ActionFactory <Template <T> > Create <T>(Action <T> method, T arg) { return(new ActionFactory <Template <T> >(tuple => method(tuple.Arg1), TupleUtility.CreateOne(arg), method)); }
/// <summary> /// Creates a new <see cref="ActionFactory{TTuple}"/> instance encapsulating the specified <paramref name="method"/> and ten generic arguments. /// </summary> /// <typeparam name="T1">The type of the first parameter of the delegate <paramref name="method"/>.</typeparam> /// <typeparam name="T2">The type of the second parameter of the delegate <paramref name="method"/>.</typeparam> /// <typeparam name="T3">The type of the third parameter of the delegate <paramref name="method"/>.</typeparam> /// <typeparam name="T4">The type of the fourth parameter of the delegate <paramref name="method"/>.</typeparam> /// <typeparam name="T5">The type of the fifth parameter of the delegate <paramref name="method"/>.</typeparam> /// <typeparam name="T6">The type of the sixth parameter of the delegate <paramref name="method"/>.</typeparam> /// <typeparam name="T7">The type of the seventh parameter of the delegate <paramref name="method"/>.</typeparam> /// <typeparam name="T8">The type of the eighth parameter of the delegate <paramref name="method"/>.</typeparam> /// <typeparam name="T9">The type of the ninth parameter of the delegate <paramref name="method"/>.</typeparam> /// <typeparam name="T10">The type of the tenth parameter of the delegate <paramref name="method"/>.</typeparam> /// <param name="method">The delegate to invoke.</param> /// <param name="arg1">The first parameter of the delegate <paramref name="method"/>.</param> /// <param name="arg2">The second parameter of the delegate <paramref name="method"/>.</param> /// <param name="arg3">The third parameter of the delegate <paramref name="method"/>.</param> /// <param name="arg4">The fourth parameter of the delegate <paramref name="method"/>.</param> /// <param name="arg5">The fifth parameter of the delegate <paramref name="method"/>.</param> /// <param name="arg6">The sixth parameter of the delegate <paramref name="method"/>.</param> /// <param name="arg7">The seventh parameter of the delegate <paramref name="method"/>.</param> /// <param name="arg8">The eighth parameter of the delegate <paramref name="method"/>.</param> /// <param name="arg9">The ninth parameter of the delegate <paramref name="method"/>.</param> /// <param name="arg10">The tenth parameter of the delegate <paramref name="method"/>.</param> /// <returns>An instance of <see cref="ActionFactory{TTuple}"/> object initialized with the specified <paramref name="method"/> and ten generic arguments.</returns> public static ActionFactory <Template <T1, T2, T3, T4, T5, T6, T7, T8, T9, T10> > Create <T1, T2, T3, T4, T5, T6, T7, T8, T9, T10>(Action <T1, T2, T3, T4, T5, T6, T7, T8, T9, T10> method, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9, T10 arg10) { return(new ActionFactory <Template <T1, T2, T3, T4, T5, T6, T7, T8, T9, T10> >(tuple => method(tuple.Arg1, tuple.Arg2, tuple.Arg3, tuple.Arg4, tuple.Arg5, tuple.Arg6, tuple.Arg7, tuple.Arg8, tuple.Arg9, tuple.Arg10), TupleUtility.CreateTen(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10), method)); }
/// <summary> /// Creates a new <see cref="ActionFactory{TTuple}"/> instance encapsulating the specified <paramref name="method"/> and eight generic arguments. /// </summary> /// <typeparam name="T1">The type of the first parameter of the delegate <paramref name="method"/>.</typeparam> /// <typeparam name="T2">The type of the second parameter of the delegate <paramref name="method"/>.</typeparam> /// <typeparam name="T3">The type of the third parameter of the delegate <paramref name="method"/>.</typeparam> /// <typeparam name="T4">The type of the fourth parameter of the delegate <paramref name="method"/>.</typeparam> /// <typeparam name="T5">The type of the fifth parameter of the delegate <paramref name="method"/>.</typeparam> /// <typeparam name="T6">The type of the sixth parameter of the delegate <paramref name="method"/>.</typeparam> /// <typeparam name="T7">The type of the seventh parameter of the delegate <paramref name="method"/>.</typeparam> /// <typeparam name="T8">The type of the eighth parameter of the delegate <paramref name="method"/>.</typeparam> /// <param name="method">The delegate to invoke.</param> /// <param name="arg1">The first parameter of the delegate <paramref name="method"/>.</param> /// <param name="arg2">The second parameter of the delegate <paramref name="method"/>.</param> /// <param name="arg3">The third parameter of the delegate <paramref name="method"/>.</param> /// <param name="arg4">The fourth parameter of the delegate <paramref name="method"/>.</param> /// <param name="arg5">The fifth parameter of the delegate <paramref name="method"/>.</param> /// <param name="arg6">The sixth parameter of the delegate <paramref name="method"/>.</param> /// <param name="arg7">The seventh parameter of the delegate <paramref name="method"/>.</param> /// <param name="arg8">The eighth parameter of the delegate <paramref name="method"/>.</param> /// <returns>An instance of <see cref="ActionFactory{TTuple}"/> object initialized with the specified <paramref name="method"/> and eight generic arguments.</returns> public static ActionFactory <Template <T1, T2, T3, T4, T5, T6, T7, T8> > Create <T1, T2, T3, T4, T5, T6, T7, T8>(Action <T1, T2, T3, T4, T5, T6, T7, T8> method, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8) { return(new ActionFactory <Template <T1, T2, T3, T4, T5, T6, T7, T8> >(tuple => method(tuple.Arg1, tuple.Arg2, tuple.Arg3, tuple.Arg4, tuple.Arg5, tuple.Arg6, tuple.Arg7, tuple.Arg8), TupleUtility.CreateEight(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8), method)); }
/// <summary> /// Creates a new <see cref="ActionFactory{TTuple}"/> instance encapsulating the specified <paramref name="method"/>. /// </summary> /// <param name="method">The delegate to invoke.</param> /// <returns>An instance of <see cref="ActionFactory{TTuple}"/> object initialized with the specified <paramref name="method"/>.</returns> public static ActionFactory <Template> Create(Action method) { return(new ActionFactory <Template>(tuple => method(), TupleUtility.CreateZero(), method)); }