Exemple #1
0
        /// <summary>
        /// Runs the specified G'MIC command.
        /// </summary>
        /// <param name="command">The G'MIC command.</param>
        /// <param name="customResourcePath">The custom resource path.</param>
        /// <param name="hostName">The host application name.</param>
        /// <param name="imageList">The image list.</param>
        /// <param name="hasProgressEvent"><c>true</c> if the caller whats progress reports; otherwise, <c>false</c>.</param>
        /// <param name="taskState">The task state.</param>
        /// <exception cref="InvalidOperationException">This G'MIC instance is already running.</exception>
        /// <exception cref="OperationCanceledException">The operation was canceled.</exception>
        public void StartAsync(string command,
                               string customResourcePath,
                               string hostName,
                               GmicImageList imageList,
                               bool hasProgressEvent,
                               GmicRunnerTaskState <TGmicBitmap> taskState)
        {
            if (IsBusy)
            {
                ExceptionUtil.ThrowInvalidOperationException("This G'MIC instance is already running.");
            }

            progress    = -1;
            shouldAbort = 0;

            GmicWorkerArgs args = new GmicWorkerArgs(command,
                                                     customResourcePath,
                                                     hostName,
                                                     imageList,
                                                     hasProgressEvent,
                                                     taskState);

            Task task = Task.Run(() => GmicWorker(args), taskState?.CancellationToken ?? CancellationToken.None);

            IsBusy = TaskIsRunning(task);
        }
Exemple #2
0
 public GmicWorkerArgs(string command,
                       string customResourcePath,
                       string hostName,
                       GmicImageList imageList,
                       bool hasProgressEvent,
                       GmicRunnerTaskState <TGmicBitmap> taskState)
 {
     Command            = command;
     CustomResourcePath = customResourcePath;
     HostName           = hostName;
     ImageList          = imageList;
     HasProgressEvent   = hasProgressEvent;
     if (taskState != null)
     {
         CanBeCanceled     = taskState.CancellationToken.CanBeCanceled;
         CancellationToken = taskState.CancellationToken;
         Task = taskState.CompletionSource;
     }
     else
     {
         CanBeCanceled     = true;
         CancellationToken = CancellationToken.None;
         Task = null;
     }
 }
Exemple #3
0
 /// <summary>
 /// Runs the specified G'MIC command.
 /// </summary>
 /// <param name="command">The G'MIC command.</param>
 /// <param name="customResourcePath">The custom resource path.</param>
 /// <param name="hostName">The host application name.</param>
 /// <param name="imageList">The image list.</param>
 /// <param name="hasProgressEvent"><c>true</c> if the caller whats progress reports; otherwise, <c>false</c>.</param>
 /// <exception cref="InvalidOperationException">This G'MIC instance is already running.</exception>
 /// <exception cref="OperationCanceledException">The operation was canceled.</exception>
 public void StartAsync(string command,
                        string customResourcePath,
                        string hostName,
                        GmicImageList imageList,
                        bool hasProgressEvent)
 {
     StartAsync(command, customResourcePath, hostName, imageList, hasProgressEvent, null);
 }
Exemple #4
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Gmic{TGmicBitmap}" /> class.
        /// </summary>
        /// <param name="outputImageFactory">The factory that creates the output images.</param>
        /// <exception cref="ArgumentNullException"><paramref name="outputImageFactory"/> is null.</exception>
        /// <exception cref="GmicException">
        /// The native library could not be found or loaded.
        ///
        /// or
        ///
        /// The GmicSharp and libGmicSharpNative versions do not match.
        ///
        /// or
        ///
        /// Unable to create the G'MIC image list.
        /// </exception>
        public Gmic(IGmicOutputImageFactory <TGmicBitmap> outputImageFactory)
        {
            if (outputImageFactory is null)
            {
                ExceptionUtil.ThrowArgumentNullException(nameof(outputImageFactory));
            }

            this.outputImageFactory = outputImageFactory;
            gmicImages        = new GmicImageList();
            gmicRunner        = new GmicRunner <TGmicBitmap>(GmicRunnerCompleted);
            completedCallback = new SendOrPostCallback(RunGmicCompletedCallback);
            progressCallback  = new SendOrPostCallback(RunGmicProgressCallback);
        }