Esempio n. 1
0
 public static object[] GetParameters(MethodInfo methodInfo, NamedValues<ZValue> namedParameters, ErrorOptions option = ErrorOptions.None)
 {
     if (methodInfo == null)
         return null;
     List<object> parameters = new List<object>();
     //ParameterInfo[] methodParameters = methodInfo.GetParameters();
     foreach (ParameterInfo parameter in methodInfo.GetParameters())
     {
         object value;
         if (namedParameters != null && namedParameters.ContainsKey(parameter.Name))
         {
             // no control between parameter type and named parameter type
             value = namedParameters[parameter.Name].ToObject();
         }
         else if (parameter.HasDefaultValue)
         {
             value = parameter.DefaultValue;
         }
         else
         {
             Error.WriteMessage(option, $"no value for parameter \"{parameter.Name}\" of method \"{methodInfo.zGetName()}\", use default value");
             value = zReflection.GetDefaultValue(parameter.ParameterType);
         }
         parameters.Add(value);
     }
     return parameters.ToArray();
 }
Esempio n. 2
0
        //private static string[] gsException =
        //        {
        //            "BA_Bdd.cBABdd+BaBddException",
        //            "BA_IN.cCheckUpLiv+CheckUpLivException",
        //            "BA_IN.cFtp+FtpException",
        //            "BA_IN.cHoro+HoroException",
        //            "BA_IN.cLockFuturSchedule+LockFuturScheduleException",
        //            "BA_IN.cMain+MainException",
        //            "BA_IN.cProcess+ProcessException",
        //            "BA_IN.cScheduler+SchedulerException",
        //            "Pkt_AddZip.cAddZip+AddZipException",
        //            "Pkt_AddZip.cAddUnzip+AddUnzipException",
        //            "Pkt_Ado.cAdo+AdoException",
        //            "Pkt_Blat.cBlat+BlatException",
        //            "Pkt_Ftp.FtpClient.FtpException",
        //            "Pkt_Util.cu+IniException",
        //            "System.Web.HttpException",
        //            "Xceed.Ftp"
        //        };

        //private static string[] gsWarning =
        //        {
        //            "BA_IN.cLockFuturSchedule+LockFuturScheduleException",
        //            "Xceed.Ftp"
        //        };

        public static void WriteMessage(ErrorOptions option, string message, params object[] prm)
        {
            if (prm.Length > 0)
            {
                message = string.Format(message, prm);
            }
            switch ((ErrorOptions)((int)option >> 4 << 4))
            {
            case ErrorOptions.Trace:
                Trace.WriteLine(message);
                break;

            case ErrorOptions.TraceWarning:
                Trace.WriteLine("warning : " + message);
                break;

            case ErrorOptions.TraceError:
                Trace.WriteLine("error : " + message);
                break;
            }
            if ((option & ErrorOptions.ThrowError) == ErrorOptions.ThrowError)
            {
                throw new PBException(message);
            }
        }
 /// <summary>   Constructor. </summary>
 /// <param name="logger">               The logger. </param>
 /// <param name="mailService">          The mail service. </param>
 /// <param name="errorOptions">         Options for controlling the error. </param>
 /// <param name="localizerFactory">     The localizer factory. </param>
 /// <param name="applicationOptions">   Options for controlling the application. </param>
 public HomeController(ILogger <HomeController> logger, ITemplatingMailService mailService,
                       ErrorOptions errorOptions, IStringLocalizerFactory localizerFactory, ApplicationOptions applicationOptions)
 {
     _logger             = logger;
     _mailService        = mailService;
     _errorOptions       = errorOptions;
     _localizerFactory   = localizerFactory;
     _applicationOptions = applicationOptions;
 }
Esempio n. 4
0
 // typeName :
 //   full name               : "System.Int32"
 //   assembly qualified name : "System.Int32, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
 //                             "pb.IO.zPath, runsource.irunsource, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"
 public static Type GetType(string typeName, ErrorOptions errorOption = ErrorOptions.None)
 {
     if (typeName == null)
         throw new PBException("type name is null");
     //return Type.GetType(type, throwOnError: true, ignoreCase: false);
     Type type = Type.GetType(typeName);
     if (type == null)
         Error.WriteMessage(errorOption, "type not found \"{0}\"", typeName);
     return type;
 }
Esempio n. 5
0
 public static Type GetType(Assembly assembly, string typeName, ErrorOptions errorOption = ErrorOptions.None)
 {
     if (assembly == null)
         throw new PBException("assembly is null");
     if (typeName == null)
         throw new PBException("type name is null");
     Type type = assembly.GetType(typeName);
     if (type == null)
         Error.WriteMessage(errorOption, "type not found \"{0}\" in assembly \"{1}\"", typeName, assembly.Location);
     return type;
 }
Esempio n. 6
0
        /// <summary>	An IServiceCollection extension method that configures error handling. </summary>
        /// <param name="services">			The services to act on. </param>
        /// <param name="configuration">	The configuration. </param>
        /// <param name="configure">		The configure. </param>
        /// <returns>	An IServiceCollection. </returns>
        public static IServiceCollection ConfigureErrorHandling(this IServiceCollection services,
                                                                IConfigurationRoot configuration, Action <ErrorOptions> configure = null)
        {
            // parse options from configuration
            _options = configuration.GetConfiguration <ErrorOptions>();

            // let the user apply additional changes
            configure?.Invoke(_options);

            // add options to the DI
            services.AddSingleton(configuration.GetConfiguration <ErrorOptions>());
            return(services);
        }
Esempio n. 7
0
        public static Assembly GetAssembly(string assemblyQualifiedName, ErrorOptions errorOption = ErrorOptions.None)
        {
            if (assemblyQualifiedName == null)
            {
                throw new PBException("assembly qualified name is null");
            }
            Assembly assembly = AppDomain.CurrentDomain.GetAssemblies().Where(assembly2 => assembly2.FullName == assemblyQualifiedName).FirstOrDefault();

            if (assembly == null)
            {
                Error.WriteMessage(errorOption, "assembly not found \"{0}\"", assemblyQualifiedName);
            }
            return(assembly);
        }
Esempio n. 8
0
        //public static MethodInfo GetMethod(string typeName, string methodName, ErrorOptions errorOption = ErrorOptions.None)
        //{
        //    if (methodName == null)
        //        return null;
        //    return GetMethod(GetType(typeName, errorOption), methodName, errorOption);
        //}

        //public static MethodInfo GetMethod(Assembly assembly, string typeName, string methodName, ErrorOptions errorOption = ErrorOptions.None)
        //{
        //    if (methodName == null)
        //        return null;
        //    return GetMethod(GetType(assembly, typeName, errorOption), methodName, errorOption);
        //}

        public static MethodInfo GetMethod(Type type, string methodName, ErrorOptions errorOption = ErrorOptions.None)
        {
            if (type == null || methodName == null)
            {
                return(null);
            }
            MethodInfo method = type.GetMethod(methodName);

            if (method == null)
            {
                Error.WriteMessage(errorOption, "method not found \"{0}\" type \"{1}\" in assembly \"{2}\"", methodName, type.zGetTypeName(), type.Assembly.Location);
            }
            return(method);
        }
Esempio n. 9
0
        // typeName :
        //   full name               : "System.Int32"
        //   assembly qualified name : "System.Int32, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
        //                             "pb.IO.zPath, runsource.irunsource, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"
        public static Type GetType(string typeName, ErrorOptions errorOption = ErrorOptions.None)
        {
            if (typeName == null)
            {
                throw new PBException("type name is null");
            }
            //return Type.GetType(type, throwOnError: true, ignoreCase: false);
            Type type = Type.GetType(typeName);

            if (type == null)
            {
                Error.WriteMessage(errorOption, "type not found \"{0}\"", typeName);
            }
            return(type);
        }
Esempio n. 10
0
        public static Type GetType(string assemblyQualifiedName, string typeName, ErrorOptions errorOption = ErrorOptions.None)
        {
            if (typeName == null)
            {
                throw new PBException("type name is null");
            }
            Assembly assembly = GetAssembly(assemblyQualifiedName, errorOption);

            if (assembly != null)
            {
                return(GetType(assembly, typeName, errorOption));
            }
            else
            {
                return(null);
            }
        }
Esempio n. 11
0
        public static Type GetType(Assembly assembly, string typeName, ErrorOptions errorOption = ErrorOptions.None)
        {
            if (assembly == null)
            {
                throw new PBException("assembly is null");
            }
            if (typeName == null)
            {
                throw new PBException("type name is null");
            }
            Type type = assembly.GetType(typeName);

            if (type == null)
            {
                Error.WriteMessage(errorOption, "type not found \"{0}\" in assembly \"{1}\"", typeName, assembly.Location);
            }
            return(type);
        }
Esempio n. 12
0
        //private static string[] gsException =
        //        {
        //            "BA_Bdd.cBABdd+BaBddException",
        //            "BA_IN.cCheckUpLiv+CheckUpLivException",
        //            "BA_IN.cFtp+FtpException",
        //            "BA_IN.cHoro+HoroException",
        //            "BA_IN.cLockFuturSchedule+LockFuturScheduleException",
        //            "BA_IN.cMain+MainException",
        //            "BA_IN.cProcess+ProcessException",
        //            "BA_IN.cScheduler+SchedulerException",
        //            "Pkt_AddZip.cAddZip+AddZipException",
        //            "Pkt_AddZip.cAddUnzip+AddUnzipException",
        //            "Pkt_Ado.cAdo+AdoException",
        //            "Pkt_Blat.cBlat+BlatException",
        //            "Pkt_Ftp.FtpClient.FtpException",
        //            "Pkt_Util.cu+IniException",
        //            "System.Web.HttpException",
        //            "Xceed.Ftp"
        //        };

        //private static string[] gsWarning =
        //        {
        //            "BA_IN.cLockFuturSchedule+LockFuturScheduleException",
        //            "Xceed.Ftp"
        //        };

        public static void WriteMessage(ErrorOptions option, string message, params object[] prm)
        {
            if (prm.Length > 0)
                message = string.Format(message, prm);
            switch ((ErrorOptions)((int)option >> 4 << 4))
            {
                case ErrorOptions.Trace:
                    Trace.WriteLine(message);
                    break;
                case ErrorOptions.TraceWarning:
                    Trace.WriteLine("warning : " + message);
                    break;
                case ErrorOptions.TraceError:
                    Trace.WriteLine("error : " + message);
                    break;
            }
            if ((option & ErrorOptions.ThrowError) == ErrorOptions.ThrowError)
                throw new PBException(message);
        }
		public extern void SetErrorOptions(ErrorOptions value);
Esempio n. 14
0
        // get MethodInfo
        //   if assembly is not found, try to load assembly with Assembly.Load()
        public static MethodInfo GetMethod(string methodName, Assembly defaultAssembly = null, ErrorOptions option = ErrorOptions.None)
        {
            if (methodName == null)
            {
                return(null);
            }

            MethodElements runMethodElements = GetMethodElements(methodName);

            if (runMethodElements.TypeName == null)
            {
                Error.WriteMessage(option, $"type name not defined");
                return(null);
            }

            Assembly assembly;

            if (runMethodElements.AssemblyName != null)
            {
                assembly = GetAssembly(runMethodElements.AssemblyName, ErrorOptions.None);
                if (assembly == null)
                {
                    assembly = Assembly.Load(runMethodElements.AssemblyName);
                }
                if (assembly == null)
                {
                    Error.WriteMessage(option, $"unable to load assembly \"{runMethodElements.AssemblyName}\"");
                    return(null);
                }
            }
            else
            {
                assembly = defaultAssembly;
            }

            Type type = GetType(assembly, runMethodElements.TypeName, option);

            if (type == null)
            {
                Error.WriteMessage(option, $"type not found \"{runMethodElements.TypeName}\"");
                return(null);
            }

            return(zReflection.GetMethod(type, runMethodElements.MethodName, option));
        }
Esempio n. 15
0
 public static Assembly GetAssembly(string assemblyQualifiedName, ErrorOptions errorOption = ErrorOptions.None)
 {
     if (assemblyQualifiedName == null)
         throw new PBException("assembly qualified name is null");
     Assembly assembly = AppDomain.CurrentDomain.GetAssemblies().Where(assembly2 => assembly2.FullName == assemblyQualifiedName).FirstOrDefault();
     if (assembly == null)
         Error.WriteMessage(errorOption, "assembly not found \"{0}\"", assemblyQualifiedName);
     return assembly;
 }
Esempio n. 16
0
        //public static MethodInfo GetMethod(string typeName, string methodName, ErrorOptions errorOption = ErrorOptions.None)
        //{
        //    if (methodName == null)
        //        return null;
        //    return GetMethod(GetType(typeName, errorOption), methodName, errorOption);
        //}

        //public static MethodInfo GetMethod(Assembly assembly, string typeName, string methodName, ErrorOptions errorOption = ErrorOptions.None)
        //{
        //    if (methodName == null)
        //        return null;
        //    return GetMethod(GetType(assembly, typeName, errorOption), methodName, errorOption);
        //}

        public static MethodInfo GetMethod(Type type, string methodName, ErrorOptions errorOption = ErrorOptions.None)
        {
            if (type == null || methodName == null)
                return null;
            MethodInfo method = type.GetMethod(methodName);
            if (method == null)
                Error.WriteMessage(errorOption, "method not found \"{0}\" type \"{1}\" in assembly \"{2}\"", methodName, type.zGetTypeName(), type.Assembly.Location);
            return method;
        }
Esempio n. 17
0
        // get MethodInfo
        //   if assembly is not found, try to load assembly with Assembly.Load()
        public static MethodInfo GetMethod(string methodName, Assembly defaultAssembly = null, ErrorOptions option = ErrorOptions.None)
        {
            if (methodName == null)
                return null;

            MethodElements runMethodElements = GetMethodElements(methodName);

            if (runMethodElements.TypeName == null)
            {
                Error.WriteMessage(option, $"type name not defined");
                return null;
            }

            Assembly assembly;
            if (runMethodElements.AssemblyName != null)
            {
                assembly = GetAssembly(runMethodElements.AssemblyName, ErrorOptions.None);
                if (assembly == null)
                {
                    assembly = Assembly.Load(runMethodElements.AssemblyName);
                }
                if (assembly == null)
                {
                    Error.WriteMessage(option, $"unable to load assembly \"{runMethodElements.AssemblyName}\"");
                    return null;
                }
            }
            else
                assembly = defaultAssembly;

            Type type = GetType(assembly, runMethodElements.TypeName, option);

            if (type == null)
            {
                Error.WriteMessage(option, $"type not found \"{runMethodElements.TypeName}\"");
                return null;
            }

            return zReflection.GetMethod(type, runMethodElements.MethodName, option);
        }
Esempio n. 18
0
        public static object[] GetParameters(MethodInfo methodInfo, NamedValues <ZValue> namedParameters, ErrorOptions option = ErrorOptions.None)
        {
            if (methodInfo == null)
            {
                return(null);
            }
            List <object> parameters = new List <object>();

            //ParameterInfo[] methodParameters = methodInfo.GetParameters();
            foreach (ParameterInfo parameter in methodInfo.GetParameters())
            {
                object value;
                if (namedParameters != null && namedParameters.ContainsKey(parameter.Name))
                {
                    // no control between parameter type and named parameter type
                    value = namedParameters[parameter.Name].ToObject();
                }
                else if (parameter.HasDefaultValue)
                {
                    value = parameter.DefaultValue;
                }
                else
                {
                    Error.WriteMessage(option, $"no value for parameter \"{parameter.Name}\" of method \"{methodInfo.zGetName()}\", use default value");
                    value = zReflection.GetDefaultValue(parameter.ParameterType);
                }
                parameters.Add(value);
            }
            return(parameters.ToArray());
        }
Esempio n. 19
0
 public static Type GetType(string assemblyQualifiedName, string typeName, ErrorOptions errorOption = ErrorOptions.None)
 {
     if (typeName == null)
         throw new PBException("type name is null");
     Assembly assembly = GetAssembly(assemblyQualifiedName, errorOption);
     if (assembly != null)
         return GetType(assembly, typeName, errorOption);
     else
         return null;
 }
Esempio n. 20
0
 public Data(int health, string name, int age, MethodOptions method = MethodOptions.POST, ErrorOptions error = ErrorOptions.ERROR_NONE, ResponseOptions response = ResponseOptions.OK)
 {
     this.Health   = health;
     this.Name     = name;
     this.Method   = method;
     this.Age      = age;
     this.Error    = error;
     this.Response = response;
     this.List     = new[] { "", "" };
 }