Пример #1
0
        internal void OnCustomUri(GetUriArgs e)
        {
            var handler = CustomUri;

            if (handler != null)
            {
                handler(this, e);
            }
        }
Пример #2
0
        /// <summary>
        /// Executes the command.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="cmdName">Name of the CMD.</param>
        /// <param name="workStr">The work STR.</param>
        /// <param name="finishStr">The finish STR.</param>
        /// <param name="worker">The worker.</param>
        /// <param name="baseUri">The base URI.</param>
        /// <param name="uriProcessor">The URI processor.</param>
        /// <param name="cmdProcessor">The CMD processor.</param>
        /// <param name="postProcessor">The post processor.</param>
        /// <param name="cmdArgs">The CMD args.</param>
        /// <returns></returns>
        private T executeCommand <T>(string cmdName, string workStr, string finishStr,
                                     ActionWorker worker, string baseUri,
                                     Func <string, ActionWorker, string, object[], Uri> uriProcessor,
                                     Func <string, ActionWorker, Uri, object[], T> cmdProcessor,
                                     Func <string, ActionWorker, object, T> postProcessor,
                                     params object[] cmdArgs)
        {
            var uri  = uriProcessor(cmdName, worker, baseUri, cmdArgs);
            var args = new GetUriArgs(cmdName, uri, cmdArgs);

            OnCustomUri(args);
            uri = args.ResultUri;
            T result = default(T);

            if (uriIsValid(uri))
            {
                OnBeforeCommand(new CommandArgs(cmdName, uri, cmdArgs));
                worker.ReportProgress(workStr, cmdArgs);
                try
                {
                    result = cmdProcessor(cmdName, worker, uri, cmdArgs);
                }
                catch (Exception exception)
                {
                    worker.ReportError(Localization.Localizer.CommandError, cmdName, exception.Message);
                }
                OnAfterCommand(new CommandArgs(cmdName, uri, cmdArgs));
                if (postProcessor != null)
                {
                    result = postProcessor(cmdName, worker, result);
                }
                worker.ReportProgress(finishStr, cmdArgs);
            }
            else
            {
                worker.ReportError(Localization.Localizer.InvalidUri, uri.ToString());
            }

            return(result);
        }