コード例 #1
0
        /// <summary>
        /// Initializes the domain context.
        /// </summary>
        /// <remarks>
        /// If the domain context has not already been set, this method trys to instantiate
        /// one specified by the <see cref="DomainContextType"/> string.
        /// </remarks>
        /// <exception cref="InvalidOperationException"> is thrown if the
        /// <see cref="WebAuthenticationService.DomainContext"/> is <c>null</c> and a new instance
        /// cannot be created.
        /// </exception>
        private void InitializeDomainContext()
        {
            if (this._domainContext == null)
            {
                // Get application assembly so we can start searching for web context type there
                Assembly applicationAssembly =
#if PORTABLE
                    // just return an assembly, internal will probably be wrong but
                    // as long as internal is non null we will try to load domain context by name
                    Assembly.GetCallingAssembly();
#elif NETSTANDARD1_3
                    TypeUtility.GetAssembly(typeof(DomainContext));
#elif SILVERLIGHT
                    Application.Current.GetType().Assembly;
#else
                    Assembly.GetEntryAssembly();
#endif

                Type type = FindDomainContextType(applicationAssembly);

                if ((type != null) && typeof(AuthenticationDomainContextBase).IsAssignableFrom(type))
                {
                    ConstructorInfo constructor = type.GetConstructor(TypeUtility.EmptyTypes);
                    if (constructor != null)
                    {
                        try
                        {
                            this._domainContext = constructor.Invoke(TypeUtility.EmptyTypes) as AuthenticationDomainContextBase;
                        }
                        catch (TargetInvocationException tie)
                        {
                            if (tie.InnerException != null)
                            {
                                throw tie.InnerException;
                            }
                            throw;
                        }
                    }
                }
            }

            if (this._domainContext == null)
            {
                throw new InvalidOperationException(Resources.ApplicationServices_CannotInitializeDomainContext);
            }
        }
コード例 #2
0
        /// <summary>
        /// Initializes the domain context.
        /// </summary>
        /// <remarks>
        /// If the domain context has not already been set, this method trys to instantiate
        /// one specified by the <see cref="DomainContextType"/> string.
        /// </remarks>
        /// <exception cref="InvalidOperationException"> is thrown if the
        /// <see cref="WebAuthenticationService.DomainContext"/> is <c>null</c> and a new instance
        /// cannot be created.
        /// </exception>
        private void InitializeDomainContext()
        {
            if (this._domainContext == null)
            {
                // Get application assembly so we can start searching for web context type there
                Assembly applicationAssembly =
#if SILVERLIGHT
                    Application.Current.GetType().Assembly;
#else
                    Assembly.GetEntryAssembly();
#endif

                Type type = FindDomainContextType(applicationAssembly);

                if ((type != null) && typeof(AuthenticationDomainContextBase).IsAssignableFrom(type))
                {
                    ConstructorInfo constructor = type.GetConstructor(TypeUtility.EmptyTypes);
                    if (constructor != null)
                    {
                        try
                        {
                            this._domainContext = constructor.Invoke(TypeUtility.EmptyTypes) as AuthenticationDomainContextBase;
                        }
                        catch (TargetInvocationException tie)
                        {
                            if (tie.InnerException != null)
                            {
                                throw tie.InnerException;
                            }
                            throw;
                        }
                    }
                }
            }

            if (this._domainContext == null)
            {
                throw new InvalidOperationException(Resources.ApplicationServices_CannotInitializeDomainContext);
            }
        }
コード例 #3
0
        /// <summary>
        /// Initializes the domain context.
        /// </summary>
        /// <remarks>
        /// If the domain context has not already been set, this method trys to instantiate
        /// one specified by the <see cref="DomainContextType"/> string.
        /// </remarks>
        /// <exception cref="InvalidOperationException"> is thrown if the
        /// <see cref="WebAuthenticationService.DomainContext"/> is <c>null</c> and a new instance
        /// cannot be created.
        /// </exception>
        private void InitializeDomainContext()
        {
            if (this._domainContext == null)
            {
                Type type = null;

                // Get application assembly so we can start searching for web context type there
                Assembly applicationAssembly =
#if SILVERLIGHT
                    Application.Current.GetType().Assembly;
#else
                    Assembly.GetEntryAssembly();
#endif

                if (!string.IsNullOrEmpty(this.DomainContextType))
                {
                    // First, try to load the type by full name from the application assembly

                    type = applicationAssembly.GetType(this.DomainContextType);
                    // If that doesn't work, allow for assembly qualified names
                    if (type == null)
                    {
                        type = Type.GetType(this.DomainContextType);
                    }
                }

                if (type == null)
                {
                    // Finally, we'll look for a domain context that has been generated from a domain 
                    // service extending AuthenticationBase<T>. Our CodeProcessor generates these 
                    // providers as extending AuthenticationDomainContextBase.
                    foreach (Type tempType in applicationAssembly.GetTypes())
                    {
                        if (typeof(AuthenticationDomainContextBase).IsAssignableFrom(tempType))
                        {
                            type = tempType;
                            break;
                        }
                    }
                }

                if ((type != null) && typeof(AuthenticationDomainContextBase).IsAssignableFrom(type))
                {
                    ConstructorInfo constructor = type.GetConstructor(Type.EmptyTypes);
                    if (constructor != null)
                    {
                        try
                        {
                            this._domainContext = constructor.Invoke(Type.EmptyTypes) as AuthenticationDomainContextBase;
                        }
                        catch (TargetInvocationException tie)
                        {
                            if (tie.InnerException != null)
                            {
                                throw tie.InnerException;
                            }
                            throw;
                        }
                    }
                }
            }

            if (this._domainContext == null)
            {
                throw new InvalidOperationException(Resources.ApplicationServices_CannotInitializeDomainContext);
            }
        }
コード例 #4
0
        /// <summary>
        /// Initializes the domain context.
        /// </summary>
        /// <remarks>
        /// If the domain context has not already been set, this method trys to instantiate
        /// one specified by the <see cref="DomainContextType"/> string.
        /// </remarks>
        /// <exception cref="InvalidOperationException"> is thrown if the
        /// <see cref="WebAuthenticationService.DomainContext"/> is <c>null</c> and a new instance
        /// cannot be created.
        /// </exception>
        private void InitializeDomainContext()
        {
            if (this._domainContext == null)
            {
                Type type = null;

                // Get application assembly so we can start searching for web context type there
                Assembly applicationAssembly =
#if SILVERLIGHT
                    Application.Current.GetType().Assembly;
#else
                    Assembly.GetEntryAssembly();
#endif

                if (!string.IsNullOrEmpty(this.DomainContextType))
                {
                    // First, try to load the type by full name from the application assembly

                    type = applicationAssembly.GetType(this.DomainContextType);
                    // If that doesn't work, allow for assembly qualified names
                    if (type == null)
                    {
                        type = Type.GetType(this.DomainContextType);
                    }
                }

                if (type == null)
                {
                    // Finally, we'll look for a domain context that has been generated from a domain
                    // service extending AuthenticationBase<T>. Our CodeProcessor generates these
                    // providers as extending AuthenticationDomainContextBase.
                    foreach (Type tempType in applicationAssembly.GetTypes())
                    {
                        if (typeof(AuthenticationDomainContextBase).IsAssignableFrom(tempType))
                        {
                            type = tempType;
                            break;
                        }
                    }
                }

                if ((type != null) && typeof(AuthenticationDomainContextBase).IsAssignableFrom(type))
                {
                    ConstructorInfo constructor = type.GetConstructor(Type.EmptyTypes);
                    if (constructor != null)
                    {
                        try
                        {
                            this._domainContext = constructor.Invoke(Type.EmptyTypes) as AuthenticationDomainContextBase;
                        }
                        catch (TargetInvocationException tie)
                        {
                            if (tie.InnerException != null)
                            {
                                throw tie.InnerException;
                            }
                            throw;
                        }
                    }
                }
            }

            if (this._domainContext == null)
            {
                throw new InvalidOperationException(Resources.ApplicationServices_CannotInitializeDomainContext);
            }
        }