Exemple #1
0
        public override void Execute()
        {
            var tdmsObject = application.GetObjectByGUID("{52CE64C6-0461-4765-8DB9-33C048CD8B60}");

            var name      = "null";
            var attribute = tdmsObject.Attributes[name];

            var invocationWithExplicitTryCatchOperator = new Invocation <TDMSAttribute, bool>(
                attribute,
                a => {
                try {
                    return(Convert.ToBoolean(a.Value));
                }
                catch (Exception) {
                    return(default(bool));
                }
            }
                );

            application.DebugPrint($"invocation with try catch: {invocationWithExplicitTryCatchOperator.Invoke()}");

            var safeInvocation = new SafeInvocation <TDMSAttribute, bool>(
                new Invocation <TDMSAttribute, bool>(
                    attribute,
                    a => Convert.ToBoolean(a.Value)
                    )
                );

            application.DebugPrint($"invocation silent: {safeInvocation.Invoke()}");
        }
Exemple #2
0
        private void Run(string[] args, IEnumerable <Type> classes, Type expectException = null)
        {
            $"Running {string.Join(" ", args)}".H2();
            var errsb               = new StringBuilder();
            var invocation          = new Invocation(stdout: null, stderr: new StringWriter(errsb), ignoreCase: true);
            InvocationResult result = null;

            try
            {
                if (expectException == null)
                {
                    // no try/catch for easier debugging by default
                    result = invocation.Invoke(args, classes);
                    return;
                }

                try
                {
                    result = invocation.Invoke(args, classes);
                }
                catch (Exception e)
                {
                    if (expectException != null && expectException.IsAssignableFrom(e.GetType()))
                    {
                        $"Exception {expectException.GetTypeName()}".H2();
                        _sb.AppendLine();
                        return;
                    }

                    throw;
                }
            }
            finally
            {
                if (errsb.Length != 0)
                {
                    _sb.AppendLine("stderr:");
                    _sb.AppendLine("```");
                    _sb.Append(errsb.ToString());
                    _sb.AppendLine("```");
                    _sb.AppendLine();
                }
            }
        }
Exemple #3
0
 public void Intercept(Invocation methodInvoke)
 {
     // 执行目标方法
     methodInvoke.Invoke();
     // 如果输出流方式或包含输出流方式
     if (methodInvoke.MethodMetaData.OutputType == TypeCategory.BinaryType && methodInvoke.RetValue != null) {
         TransferFile tfile = ((TransferFile)methodInvoke.RetValue);
         NDWR.Util.Kit.SetAbsCache(tfile.ID, tfile);
         methodInvoke.RetValue = tfile.ID;
     }
 }
Exemple #4
0
 public void InvokeManual <C, D>(T callback, C caller, ref D data)
 {
     try
     {
         Invocation <T, C, D> .Invoke(caller, ref data, callback);
     }
     catch (Exception exception)
     {
         Debug.LogError(exception);
     }
 }
Exemple #5
0
 public void InvokeManual <C>(T callback, C caller)
 {
     try
     {
         Invocation <T, C> .Invoke(caller, callback);
     }
     catch (Exception exception)
     {
         Debug.LogError(exception);
     }
 }
Exemple #6
0
 public void Intercept(Invocation methodInvoke)
 {
     try {
         methodInvoke.Invoke();
     } catch (Exception ex) {
         methodInvoke.SystemErrors.Add(
             new RspError(SystemError.ServiceException, ex.Message)
         );
         log.Error("ExceptionInterceptor捕获到异常", ex);
         //throw ex;
     }
 }
 public void Intercept(Invocation methodInvoke)
 {
     var paramValues = methodInvoke.ParamValues; // 用户输入参数源信息
     var paramMetas = methodInvoke.MethodMetaData.Params; // 服务端方法参数信息
     // 参数个数映射不符
     if (paramValues.Length != paramMetas.Length) { // 两个参数理论不会为null
         methodInvoke.SystemErrors.Add(new RspError() {
             Name = SystemError.NoMatchParam.ToString(),
             Message = "参数不匹配"
         });
         return;
     }
     // 设置参数
     if (!setParamValue(methodInvoke)) {
         return ;
     }
     // 执行目标方法
     methodInvoke.Invoke();
 }
Exemple #8
0
 public object Invoke(List <object> parameters, InvocationContext ctx)
 {
     return(_invocation.Invoke(this, parameters, ctx));
 }
Exemple #9
0
 public override void Execute()
 {
     invocation.Invoke();
 }
Exemple #10
0
 /// <summary>
 /// Raisese the <see cref="vCommands.Commands.Command.Invocation"/> event.
 /// </summary>
 /// <param name="e">A <see cref="vCommands.EventArguments.CommandInvocationEventArgs"/> that contains event data.</param>
 protected virtual void OnInvocation(CommandInvocationEventArgs e)
 {
     Invocation?.Invoke(this, e);
 }
 object IFunction.Invoke(List <object> parameters, Stack stack)
 {
     return(m_invocation.Invoke(this, parameters, stack));
 }