Пример #1
0
 /// <summary>
 /// Initializes a new instance of the <see cref="FtpCommandSelection"/> class.
 /// </summary>
 /// <param name="handler">The FTP command handler.</param>
 /// <param name="handlerInformation">The FTP command handler information.</param>
 public FtpCommandSelection(
     IFtpCommandBase handler,
     IFtpCommandInformation handlerInformation)
 {
     Handler     = handler;
     Information = handlerInformation;
 }
Пример #2
0
 /// <summary>
 /// Initializes a new instance of the <see cref="FtpCommandSelection"/> class.
 /// </summary>
 /// <param name="handler">The FTP command handler.</param>
 /// <param name="handlerInformation">The FTP command handler information.</param>
 public FtpCommandSelection(
     [NotNull] IFtpCommandBase handler,
     [NotNull] IFtpCommandInformation handlerInformation)
 {
     Handler     = handler;
     Information = handlerInformation;
 }
Пример #3
0
        private FtpCommandSelection?ActivateCommandHandler(FtpCommandHandlerContext context)
        {
            if (!_nameToHandlerInfo.TryGetValue(context.FtpContext.Command.Name, out var handlerInfo))
            {
                return(null);
            }

            if (_commandHandlers.TryGetValue(handlerInfo.Type, out var handler))
            {
                return(new FtpCommandSelection(handler, handlerInfo));
            }

#pragma warning disable 612
            if (handlerInfo is IFtpCommandHandlerInstanceInformation handlerInstanceInfo)
#pragma warning restore 612
            {
                handler = handlerInstanceInfo.Instance;
            }
            else
            {
                handler = (IFtpCommandHandler)ActivatorUtilities.CreateInstance(
                    _serviceProvider,
                    handlerInfo.Type);
            }

            IFtpCommandInformation commandInformation = handlerInfo;
            if (handlerInfo.IsExtensible && handler is IFtpCommandHandlerExtensionHost extensionHost)
            {
                var extensions     = ActivateExtensions(context, handlerInfo).ToList();
                var hostExtensions = extensions.ToDictionary(
                    x => x.Item2.Name,
                    x => Tuple.Create(x.Item1, x.Item2),
                    StringComparer.OrdinalIgnoreCase);
                extensionHost.Extensions = hostExtensions.ToDictionary(
                    x => x.Key,
                    x => x.Value.Item1);

                var argument = FtpCommand.Parse(context.FtpContext.Command.Argument);
                if (hostExtensions.TryGetValue(argument.Name, out var hostExtensionDictValue))
                {
                    commandInformation = hostExtensionDictValue.Item2;
                }
            }

            _commandHandlers.Add(handlerInfo.Type, handler);

            return(new FtpCommandSelection(handler, commandInformation));
        }