Exemplo n.º 1
0
			public object[] CreateExtensions(ExtensionPoint extensionPoint, ExtensionFilter filter, bool justOne)
			{
				if (extensionPoint.GetType() == typeof(DicomCodecFactoryExtensionPoint))
					return new object[]{ new DicomRleCodecFactory() };

				return new object[0];
			}
    	/// <summary>
    	/// Creates instances of available extensions that extend the specified extension point and match the specified filter.
    	/// </summary>
    	/// <param name="extensionPoint">The extension point for which to create extensions.</param>
    	/// <param name="filter">An <see cref="ExtensionFilter"/> used to limit the result set to extensions with particular characteristics.</param>
    	/// <param name="justOne">Indicates whether or not to return only the first matching extension that is found.</param>
    	/// <returns>A set of extension instances.</returns>
    	/// <remarks>
    	/// Available extensions are those which are both enabled and licensed.
    	/// If <paramref name="justOne"/> is true, the first matching extension that is successfully instantiated is returned,
    	/// an no other extensions are instantiated.
    	/// </remarks>
    	public object[] CreateExtensions(ExtensionPoint extensionPoint, ExtensionFilter filter, bool justOne)
        {
            // get subset of applicable extensions
            var extensions = ListExtensionsHelper(extensionPoint, filter);

            // attempt to instantiate the extension classes
            var createdObjects = new List<object>();
            foreach (var extension in extensions)
            {
                if (justOne && createdObjects.Count > 0)
                    break;

                try
                {
                    // instantiate
                    var o = Activator.CreateInstance(extension.ExtensionClass.Resolve());
                    createdObjects.Add(o);
                }
                catch (Exception e)
                {
                    // instantiation failed
					// this should not be considered an exceptional circumstance
					// instantiation may fail by design in some cases (e.g extension is designed only to run on a particular platform)
					Platform.Log(LogLevel.Debug, e);
                }
            }

            return createdObjects.ToArray();
        }
Exemplo n.º 3
0
        /// <summary>
        /// Creates one of each type of object that extends the input <paramref name="extensionPoint" />,
        /// matching the input <paramref name="filter" />; creates a single extension if <paramref name="justOne"/> is true.
        /// </summary>
        /// <param name="extensionPoint">The <see cref="ExtensionPoint"/> to create extensions for.</param>
        /// <param name="filter">The filter used to match each extension that is discovered.</param>
        /// <param name="justOne">Indicates whether or not to return only the first matching extension that is found.</param>
        /// <returns></returns>
        public object[] CreateExtensions(ExtensionPoint extensionPoint, ExtensionFilter filter, bool justOne)
        {
            // get subset of applicable extensions
            var extensions = ListExtensionsHelper(extensionPoint, filter);

            // attempt to instantiate the extension classes
            var createdObjects = new List <object>();

            foreach (var extension in extensions)
            {
                if (justOne && createdObjects.Count > 0)
                {
                    break;
                }

                try
                {
                    // instantiate
                    var o = Activator.CreateInstance(extension.ExtensionClass);
                    createdObjects.Add(o);
                }
                catch (Exception e)
                {
                    // instantiation failed
                    // this should not be considered an exceptional circumstance
                    // instantiation may fail by design in some cases (e.g extension is designed only to run on a particular platform)
                    Platform.Log(LogLevel.Debug, e);
                }
            }

            return(createdObjects.ToArray());
        }
			public ExtensionInfo[] ListExtensions(ExtensionPoint extensionPoint, ExtensionFilter filter)
			{
				if (extensionPoint is CacheProviderExtensionPoint)
				{
					return new[] { new ExtensionInfo(typeof(TestCacheProvider), typeof(CacheProviderExtensionPoint), null, null, true) };
				}
				throw new NotImplementedException();
			}
			public object[] CreateExtensions(ExtensionPoint extensionPoint, ExtensionFilter filter, bool justOne)
			{
				if (extensionPoint is CacheProviderExtensionPoint)
				{
					return new[] { new TestCacheProvider() };
				}

				throw new NotImplementedException();
			}
Exemplo n.º 6
0
		public object[] CreateExtensions(ExtensionPoint extensionPoint, ExtensionFilter filter, bool justOne)
		{
			if (extensionPoint.GetType() == typeof(ProcedureStepBuilderExtensionPoint))
			{
				return new object[] { new ModalityProcedureStepBuilder() };
			}

			return new object[] { };
		}
Exemplo n.º 7
0
        /// <summary>
        /// Starts the application.
        /// </summary>
        /// <param name="applicationRootFilter">An extension filter that selects the application root extension to execute.</param>
        /// <param name="args">The set of arguments passed from the command line.</param>
        /// <remarks>
        /// A ClearCanvas based application is started by calling this convenience method from
        /// a bootstrap executable of some kind.  Calling this method results in the loading
        /// of all plugins and creation of an <see cref="IApplicationRoot"/> extension.
        /// This method is not thread-safe as it should only ever be invoked once per execution, by a single thread.
        /// </remarks>
        public static void StartApp(ExtensionFilter applicationRootFilter, string[] args)
        {
            FatalExceptionHandler.Initialize();

            ApplicationRootExtensionPoint xp = new ApplicationRootExtensionPoint();

            _applicationRoot = (applicationRootFilter == null) ?
                               (IApplicationRoot)xp.CreateExtension() :
                               (IApplicationRoot)xp.CreateExtension(applicationRootFilter);
            _applicationRoot.RunApplication(args);
        }
Exemplo n.º 8
0
        /// <summary>
        /// Creates one of each type of object that extends the input <paramref name="extensionPoint" />,
        /// matching the input <paramref name="filter" />; creates a single extension if <paramref name="justOne"/> is true.
        /// </summary>
        /// <param name="extensionPoint">The <see cref="ExtensionPoint"/> to create extensions for.</param>
        /// <param name="filter">The filter used to match each extension that is discovered.</param>
        /// <param name="justOne">Indicates whether or not to return only the first matching extension that is found.</param>
        /// <returns></returns>
        public object[] CreateExtensions(ExtensionPoint extensionPoint, ExtensionFilter filter, bool justOne)
        {
            // get subset of applicable extensions
            List <ExtensionInfo> extensions = ListExtensionsHelper(extensionPoint, filter);

            // attempt to instantiate the extension classes
            List <object> createdObjects = new List <object>();

            foreach (ExtensionInfo extension in extensions)
            {
                if (justOne && createdObjects.Count > 0)
                {
                    break;
                }

                // is the extension a concrete class?
                if (!IsConcreteClass(extension.ExtensionClass))
                {
                    Platform.Log(LogLevel.Warn, SR.ExceptionExtensionMustBeConcreteClass,
                                 extension.ExtensionClass.FullName);
                    continue;
                }

                // does the extension implement the required interface?
                if (!extensionPoint.InterfaceType.IsAssignableFrom(extension.ExtensionClass))
                {
                    Platform.Log(LogLevel.Warn, SR.ExceptionExtensionDoesNotImplementRequiredInterface,
                                 extension.ExtensionClass.FullName,
                                 extensionPoint.InterfaceType);

                    continue;
                }

                try
                {
                    // instantiate
                    object o = Activator.CreateInstance(extension.ExtensionClass);
                    createdObjects.Add(o);
                }
                catch (Exception e)
                {
                    // instantiation failed
                    // this should not be considered an exceptional circumstance
                    // instantiation may fail by design in some cases (e.g extension is designed only to run on a particular platform)
                    Platform.Log(LogLevel.Debug, e);
                }
            }

            return(createdObjects.ToArray());
        }
        /// <summary>
        /// Creates one of each type of object that extends the input <paramref name="extensionPoint" />, 
        /// matching the input <paramref name="filter" />; creates a single extension if <paramref name="justOne"/> is true.
        /// </summary>
        /// <param name="extensionPoint">The <see cref="ExtensionPoint"/> to create extensions for.</param>
        /// <param name="filter">The filter used to match each extension that is discovered.</param>
        /// <param name="justOne">Indicates whether or not to return only the first matching extension that is found.</param>
        /// <returns></returns>
        public object[] CreateExtensions(ExtensionPoint extensionPoint, ExtensionFilter filter, bool justOne)
        {
            // get subset of applicable extensions
            List<ExtensionInfo> extensions = ListExtensionsHelper(extensionPoint, filter);

            // attempt to instantiate the extension classes
            List<object> createdObjects = new List<object>();
            foreach (ExtensionInfo extension in extensions)
            {
                if (justOne && createdObjects.Count > 0)
                    break;

                // is the extension a concrete class?
                if (!IsConcreteClass(extension.ExtensionClass))
                {
                    Platform.Log(LogLevel.Warn, SR.ExceptionExtensionMustBeConcreteClass,
                        extension.ExtensionClass.FullName);
                    continue;
                }

                // does the extension implement the required interface?
                if (!extensionPoint.InterfaceType.IsAssignableFrom(extension.ExtensionClass))
                {
                    Platform.Log(LogLevel.Warn, SR.ExceptionExtensionDoesNotImplementRequiredInterface,
                        extension.ExtensionClass.FullName,
                        extensionPoint.InterfaceType);

                    continue;
                }

                try
                {
                    // instantiate
                    object o = Activator.CreateInstance(extension.ExtensionClass);
                    createdObjects.Add(o);
                }
                catch (Exception e)
                {
                    // instantiation failed
					// this should not be considered an exceptional circumstance
					// instantiation may fail by design in some cases (e.g extension is designed only to run on a particular platform)
					Platform.Log(LogLevel.Debug, e);
                }
            }

            return createdObjects.ToArray();
        }
Exemplo n.º 10
0
        /// <summary>
        /// Starts the application.
        /// </summary>
        /// <param name="applicationRootFilter">An extension filter that selects the application root extension to execute.</param>
        /// <param name="args">The set of arguments passed from the command line.</param>
        /// <remarks>
        /// A ClearCanvas based application is started by calling this convenience method from
        /// a bootstrap executable of some kind.  Calling this method results in the loading
        /// of all plugins and creation of an <see cref="IApplicationRoot"/> extension.
        /// This method is not thread-safe as it should only ever be invoked once per execution, by a single thread.
        /// </remarks>
        public static void StartApp(ExtensionFilter applicationRootFilter, string[] args)
        {
#if !DEBUG
            try
            {
#endif
            ApplicationRootExtensionPoint xp = new ApplicationRootExtensionPoint();
            _applicationRoot = (applicationRootFilter == null) ?
                               (IApplicationRoot)xp.CreateExtension() :
                               (IApplicationRoot)xp.CreateExtension(applicationRootFilter);
            _applicationRoot.RunApplication(args);

#if !DEBUG
        }
        catch (Exception e)
        {
            Platform.Log(LogLevel.Fatal, e);

            // for convenience, if this is console app, also print the message to the console
            Console.WriteLine(e.Message);
        }
#endif
        }
Exemplo n.º 11
0
 /// <summary>
 /// Gets metadata describing all enabled extensions of the input <paramref name="extensionPoint"/>, 
 /// matching the given <paramref name="filter"/>.
 /// </summary>
 /// <param name="extensionPoint">The <see cref="ExtensionPoint"/> whose extension metadata is to be retrieved.</param>
 /// <param name="filter">An <see cref="ExtensionFilter"/> used to filter out extensions with particular characteristics.</param>
 /// <returns></returns>
 public ExtensionInfo[] ListExtensions(ExtensionPoint extensionPoint, ExtensionFilter filter)
 {
 	return ListExtensionsHelper(extensionPoint, filter).ToArray();
 }
Exemplo n.º 12
0
        /// <summary>
		/// Protected method that actually retrieves the <see cref="ExtensionInfo"/>
		/// objects from an internal <see cref="IExtensionFactory"/>.
        /// </summary>
		protected ExtensionInfo[] ListExtensionsHelper(ExtensionFilter filter)
        {
            // we assume that the factory itself is thread-safe, and therefore we don't need to lock
            // (don't want to incur the cost of locking if not necessary)
            return _extensionFactory.ListExtensions(this, filter);
        }
Exemplo n.º 13
0
 /// <summary>
 /// List meta-data for enabled extensions of this point that match the supplied filter.
 /// </summary>
 /// <param name="filter"></param>
 /// <returns></returns>
 public ExtensionInfo[] ListExtensions(ExtensionFilter filter)
 {
     return ListExtensionsHelper(filter);
 }
Exemplo n.º 14
0
 /// <summary>
 /// Instantiates all enabled extensions of this point that match the supplied filter.
 /// </summary>
 public object[] CreateExtensions(ExtensionFilter filter)
 {
     return CreateExtensionsHelper(filter, false);
 }
Exemplo n.º 15
0
        /// <summary>
        /// Protected method that actually performs the extension creation
        /// from an internal <see cref="IExtensionFactory"/>.
        /// </summary>
		protected object[] CreateExtensionsHelper(ExtensionFilter filter, bool justOne)
        {
            // we assume that the factory itself is thread-safe, and therefore we don't need to lock
            // (don't want to incur the cost of locking if not necessary)
            return _extensionFactory.CreateExtensions(this, filter, justOne);
        }
		private List<ExtensionInfo> ListExtensionsHelper(ExtensionPoint extensionPoint, ExtensionFilter filter)
		{
			// ensure extension map has been constructed
			BuildExtensionMapOnce();

			List<ExtensionInfo> extensions;
			if (_extensionMap.TryGetValue(extensionPoint.GetType(), out extensions))
			{
				return CollectionUtils.Select(extensions,
					extension => extension.Enabled && extension.Authorized && (filter == null || filter.Test(extension)));
			}
			return new List<ExtensionInfo>();
		}
Exemplo n.º 17
0
 /// <summary>
 /// Instantiates one extension of this point that matches the specified filter.
 /// </summary>
 public object CreateExtension(ExtensionFilter filter)
 {
     return AtLeastOne(CreateExtensionsHelper(filter, true), this.GetType());
 }
Exemplo n.º 18
0
 /// <summary>
 /// Protected method that actually retrieves the <see cref="ExtensionInfo"/>
 /// objects from an internal <see cref="IExtensionFactory"/>.
 /// </summary>
 protected ExtensionInfo[] ListExtensionsHelper(ExtensionFilter filter)
 {
     // we assume that the factory itself is thread-safe, and therefore we don't need to lock
     // (don't want to incur the cost of locking if not necessary)
     return(_extensionFactory.ListExtensions(this, filter));
 }
Exemplo n.º 19
0
        private List <ExtensionInfo> ListExtensionsHelper(ExtensionPoint extensionPoint, ExtensionFilter filter)
        {
            // ensure extension map has been constructed
            BuildExtensionMapOnce();

            List <ExtensionInfo> extensions;

            if (_extensionMap.TryGetValue(extensionPoint.GetType(), out extensions))
            {
                return(CollectionUtils.Select(extensions,
                                              extension => extension.Enabled && extension.Authorized && (filter == null || filter.Test(extension))));
            }
            return(new List <ExtensionInfo>());
        }
Exemplo n.º 20
0
 /// <summary>
 /// Instantiates all enabled extensions of this point that match the supplied filter.
 /// </summary>
 public object[] CreateExtensions(ExtensionFilter filter)
 {
     return(CreateExtensionsHelper(filter, false));
 }
Exemplo n.º 21
0
 /// <summary>
 /// Protected method that actually performs the extension creation
 /// from an internal <see cref="IExtensionFactory"/>.
 /// </summary>
 protected object[] CreateExtensionsHelper(ExtensionFilter filter, bool justOne)
 {
     // we assume that the factory itself is thread-safe, and therefore we don't need to lock
     // (don't want to incur the cost of locking if not necessary)
     return(_extensionFactory.CreateExtensions(this, filter, justOne));
 }
Exemplo n.º 22
0
 /// <summary>
 /// Gets metadata describing all enabled extensions of the input <paramref name="extensionPoint"/>,
 /// matching the given <paramref name="filter"/>.
 /// </summary>
 /// <param name="extensionPoint">The <see cref="ExtensionPoint"/> whose extension metadata is to be retrieved.</param>
 /// <param name="filter">An <see cref="ExtensionFilter"/> used to filter out extensions with particular characteristics.</param>
 /// <returns></returns>
 public ExtensionInfo[] ListExtensions(ExtensionPoint extensionPoint, ExtensionFilter filter)
 {
     return(ListExtensionsHelper(extensionPoint, filter).ToArray());
 }
Exemplo n.º 23
0
 /// <summary>
 /// List meta-data for enabled extensions of this point that match the supplied filter.
 /// </summary>
 /// <param name="filter"></param>
 /// <returns></returns>
 public ExtensionInfo[] ListExtensions(ExtensionFilter filter)
 {
     return(ListExtensionsHelper(filter));
 }
Exemplo n.º 24
0
			public ExtensionInfo[] ListExtensions(ExtensionPoint extensionPoint, ExtensionFilter filter)
			{
				return new ExtensionInfo[0];
			}
Exemplo n.º 25
0
		private List<ExtensionInfo> ListExtensionsHelper(ExtensionPoint extensionPoint, ExtensionFilter filter)
		{
			// ensure extension map has been constructed
			BuildExtensionMapOnce();

			Type extensionPointClass = extensionPoint.GetType();

			List<ExtensionInfo> extensions;
			if (_extensionMap.TryGetValue(extensionPointClass, out extensions))
			{
				return CollectionUtils.Select(extensions,
					delegate(ExtensionInfo extension)
					{
						return extension.Enabled
								&& (filter == null || filter.Test(extension));
					});
			}
			else
			{
				return new List<ExtensionInfo>();
			}

		}
Exemplo n.º 26
0
        private List <ExtensionInfo> ListExtensionsHelper(ExtensionPoint extensionPoint, ExtensionFilter filter)
        {
            // ensure extension map has been constructed
            BuildExtensionMapOnce();

            Type extensionPointClass = extensionPoint.GetType();

            List <ExtensionInfo> extensions;

            if (_extensionMap.TryGetValue(extensionPointClass, out extensions))
            {
                return(CollectionUtils.Select(extensions,
                                              delegate(ExtensionInfo extension)
                {
                    return extension.Enabled &&
                    (filter == null || filter.Test(extension));
                }));
            }
            else
            {
                return(new List <ExtensionInfo>());
            }
        }
Exemplo n.º 27
0
 /// <summary>
 /// Instantiates one extension of this point that matches the specified filter.
 /// </summary>
 public object CreateExtension(ExtensionFilter filter)
 {
     return(AtLeastOne(CreateExtensionsHelper(filter, true), this.GetType()));
 }
Exemplo n.º 28
0
		public ExtensionInfo[] ListExtensions(ExtensionPoint extensionPoint, ExtensionFilter filter)
		{
			throw new Exception("The method or operation is not implemented.");
		}