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
        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.º 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());
        }
Exemplo n.º 9
0
        /// <summary>
        /// Sets the extension factory that is used to instantiate extensions.
        /// </summary>
        /// <remarks>
        /// This purpose of this method is to facilitate unit testing by allowing the creation of extensions
        /// to be controlled by the testing code.
        /// </remarks>
        /// <param name="factory"></param>
        public static void SetExtensionFactory(IExtensionFactory factory)
        {
            lock (_syncRoot)
            {
                //I'm sure there are other places where this might be a problem, but if
                //you use an extension factory that creates service provider extensions,
                //you can get UnknownServiceException problems in unit tests unless
                //these 2 variables are repopulated.
                _serviceProviders       = null;
                _duplexServiceProviders = null;
            }

            ExtensionPoint.SetExtensionFactory(factory);
        }
Exemplo n.º 10
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();
        }
Exemplo n.º 11
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.º 12
0
 /// <summary>
 /// Sets the extension factory that is used to instantiate extensions.
 /// </summary>
 /// <remarks>
 /// This purpose of this method is to facilitate unit testing by allowing the creation of extensions
 /// to be controlled by the testing code.
 /// </remarks>
 /// <param name="factory"></param>
 public static void SetExtensionFactory(IExtensionFactory factory)
 {
     ExtensionPoint.SetExtensionFactory(factory);
 }
Exemplo n.º 13
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.º 14
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.º 15
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.º 16
0
			public ExtensionInfo[] ListExtensions(ExtensionPoint extensionPoint, ExtensionFilter filter)
			{
				return new ExtensionInfo[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.º 18
0
		public ExtensionInfo[] ListExtensions(ExtensionPoint extensionPoint, ExtensionFilter filter)
		{
			throw new Exception("The method or operation is not implemented.");
		}