Beispiel #1
0
        public bool RunFilter(PluginData pluginData, bool showUI)
        {
            if (pluginData == null)
            {
                throw new ArgumentNullException(nameof(pluginData));
            }

            if (disposed)
            {
                throw new ObjectDisposedException(nameof(PSFilterHost));
            }

            if (!showUI && filterParameters == null)
            {
                throw new InvalidOperationException(Resources.ParametersNotSet);
            }

            bool result = false;

            using (LoadPsFilter lps = new LoadPsFilter(source, primaryColor, secondaryColor, selectedRegion, owner))
            {
                if (abortFunc != null)
                {
                    lps.SetAbortFunc(abortFunc);
                }

                if (pickColor != null)
                {
                    lps.SetPickColor(pickColor);
                }

                if (UpdateProgress != null)
                {
                    lps.SetProgressFunc(new ProgressProc(OnFilterReportProgress));
                }

                if (filterParameters != null)
                {
                    lps.ParameterData = filterParameters;
                    lps.ShowUI        = showUI;
                }

                if (pseudoResources != null)
                {
                    lps.PseudoResources = pseudoResources;
                }

                if (hostInfo != null)
                {
                    lps.HostInformation = hostInfo;
                }

                if (hostColorProfiles != null)
                {
                    lps.SetColorProfiles(hostColorProfiles);
                }

                if (sessionSettings != null)
                {
                    lps.SetPluginSettings(sessionSettings);
                }

                try
                {
                    result = lps.RunPlugin(pluginData);
                }
                catch (FileNotFoundException)
                {
                    throw;
                }
                catch (SecurityException)
                {
                    throw;
                }
                catch (Exception ex)
                {
                    if (ex is OutOfMemoryException || ex is StackOverflowException || ex is ThreadAbortException)
                    {
                        throw;
                    }

                    throw new FilterRunException(ex.Message, ex);
                }

                if (result)
                {
#if GDIPLUS
                    dest = lps.Dest.ToGdipBitmap();
#else
                    dest = lps.Dest.ToBitmapSource();
                    dest.Freeze();
#endif

                    filterParameters = lps.ParameterData;
                    pseudoResources  = lps.PseudoResources;
                    hostInfo         = lps.HostInformation;
                    sessionSettings  = lps.GetPluginSettings();
                }
                else if (!string.IsNullOrEmpty(lps.ErrorMessage))
                {
                    throw new FilterRunException(lps.ErrorMessage);
                }
            }

            return(result);
        }
Beispiel #2
0
 /// <summary>
 /// Executes the specified filter.
 /// </summary>
 /// <param name="pluginData">The <see cref="PluginData" /> of the filter to run.</param>
 /// <returns>
 /// <c>true</c> if the filter completed processing; otherwise, <c>false</c>.
 /// </returns>
 /// <overloads>Executes the specified filter.</overloads>
 /// <remarks>
 /// <para>
 /// When the <see cref="FilterParameters"/> have been set to execute a filter with settings from a previous session this method will not display the user interface.
 /// The <see cref="RunFilter(PluginData, bool)" /> overload must be used if the host wants the filter to display its user interface.
 /// </para>
 /// </remarks>
 /// <exception cref="ArgumentNullException"><paramref name="pluginData" /> is null.</exception>
 /// <exception cref="FileNotFoundException">The filter cannot be found.</exception>
 /// <exception cref="ObjectDisposedException">The object has been disposed.</exception>
 /// <exception cref="FilterRunException">The filter returns an error.</exception>
 public bool RunFilter(PluginData pluginData)
 {
     return(RunFilter(pluginData, filterParameters == null));
 }