Ejemplo n.º 1
0
 public void ParseErrorDesc(ICommandsBuilder builder, string command)
 {
     if (m_completionCode == CommandResponseStatus.COMPLD)
     {
         return;
     }
     m_errorDesc = builder.ParseErrorDesc(m_additionalInfo, command);
 }
        /// <summary>
        /// Adds command parsing infrastructure to the given
        /// <paramref name="builder"/>.
        /// </summary>
        /// <param name="builder">
        /// The <see cref="ICommandsBuilder"/> to add parsing infrastructure
        /// to.
        /// </param>
        /// <returns>
        /// The <paramref name="builder"/>.
        /// </returns>
        public static ICommandsBuilder AddPositionalCommandParser(
            this ICommandsBuilder builder)
        {
            builder.Services.TryAddScoped <ICommandParser, PositionalCommandParser>();
            builder.Services.TryAddScoped <ICommandBinder, PositionalCommandBinder>();

            return(builder);
        }
Ejemplo n.º 3
0
 public static ICommandsBuilder HandlersFromAssemblyOf <T>(this ICommandsBuilder me)
 {
     foreach (var handler in typeof(T).Assembly.GetTypes().Where(t => t.IsSubclassOfRawGeneric(typeof(ICommandHandler <>))))
     {
         foreach (var inter in handler.GetInterfaces().Where(t => t.IsSubclassOfRawGeneric(typeof(ICommandHandler <>))))
         {
             me.FuxionBuilder.Services.AddScoped(typeof(ICommandHandler <>).MakeGenericType(inter.GetGenericArguments()[0]), handler);
             me.FuxionBuilder.TypeKeyDirectory.Register(inter.GetGenericArguments()[0]);
         }
     }
     return(me);
 }
 public InternalCommandProcessor(ICommandsBuilder commandsBuilder, ILifetimeScopeService lifetimeScopeService, IAsyncCommand initialCommand)
 {
     _commandsBuilder   = commandsBuilder;
     _initialCommand    = initialCommand;
     _dependencyService = lifetimeScopeService.BeginLifetimeScope(this);
 }
Ejemplo n.º 5
0
        /// <summary>
        /// 格式见用户指南
        /// </summary>
        /// <param name="msg"></param>
        /// <returns></returns>
        public static CommandResponseMsg ConvertFromString(ICommandsBuilder builder, string msg)
        {
            if (msg == null || msg == "")
            {
                return(null);
            }
            try
            {
                CommandResponseMsg rm = new CommandResponseMsg();
                rm.m_replyContent = msg;
                //todo
                string[] list = msg.Split(new char[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries);
                //header
                string header = list[0];
                if (header.Substring(3, 1) != " ")
                {
                    rm.m_neID = header.Substring(3, header.IndexOf(' ', 3) - 3);
                }
                else
                {
                    rm.m_neID = "";
                }
                rm.OmcTime = Convert.ToDateTime(header.Substring(header.IndexOf(' ', 3) + 1));
                //response identification
                string identification = list[1];
                if (identification.Substring(3, 1) != " ")
                {
                    rm.m_ctag = identification.Substring(3, identification.IndexOf(' ', 3) - 3);
                }
                else
                {
                    rm.m_ctag = "";
                }
                string completionCode = identification.Substring(identification.IndexOf(' ', 3) + 1);
                if (completionCode == "COMPLD")
                {
                    rm.m_completionCode = CommandResponseStatus.COMPLD;
                }
                else
                {
                    rm.m_completionCode = CommandResponseStatus.DENY;
                }
                //text block
                Dictionary <string, string> info = new Dictionary <string, string>();
                string text = list[2];
                if (text != ";" && text.Contains("EN="))
                {
                    text = list[2];
                    string[] textAttr = text.Split(new string[] { "   " }, StringSplitOptions.RemoveEmptyEntries);
                    if (textAttr.Length > 0)
                    {
                        foreach (string s in textAttr)
                        {
                            string[] attr = s.Split('=');
                            info.Add(attr[0], attr[1]);
                        }
                    }
                }
                rm.m_additionalInfo = info;

                #region
                if (info.ContainsKey("EN"))
                {
                    if (info["EN"].Trim() == "0")
                    {
                        rm.m_completionCode = CommandResponseStatus.COMPLD;
                    }
                    else
                    {
                        rm.m_completionCode = CommandResponseStatus.DENY;
                    }
                }
                #endregion
                if (list.Length <= 4)
                {
                    rm.m_information = null;
                }
                else
                {
                    rm.m_information = builder.ParseInformation(msg);
                }

                return(rm);
            }
            catch (Exception ex)
            {
                throw new Exception("转化命令响应错误:\r\n" + ex.ToString());
            }
        }
Ejemplo n.º 6
0
 public ResultProcessor(Dictionary <Type, Func <object, TReturn> > resultParsers,
                        ICommandsBuilder commandsBuilder, ILifetimeScopeService lifetimeScopeService)
 {
     _resultParsers    = resultParsers;
     _commandProcessor = new CommandProcessor(commandsBuilder, lifetimeScopeService);
 }
Ejemplo n.º 7
0
 public ResultProcessor(ICommandsBuilder commandsBuilder, ILifetimeScopeService lifetimeScopeService)
     : this(new Dictionary <Type, Func <object, TReturn> >(), commandsBuilder, lifetimeScopeService)
 {
 }
Ejemplo n.º 8
0
 /// <summary>
 /// Adds commands using the attributed model to the given
 /// <paramref name="builder"/>.
 /// </summary>
 /// <param name="builder">
 /// The <see cref="ICommandsBuilder"/> to add attributed model commands
 /// to.
 /// </param>
 /// <returns>
 /// The <paramref name="builder"/>.
 /// </returns>
 public static ICommandsBuilder AddAttributedCommands(
     this ICommandsBuilder builder)
 => AddAttributedCommands(builder, static (_) => {});
Ejemplo n.º 9
0
 public CommandProcessor(ICommandsBuilder commandsBuilder, ILifetimeScopeService lifetimeScopeService)
 {
     _commandsBuilder      = commandsBuilder;
     _lifetimeScopeService = lifetimeScopeService;
 }