예제 #1
0
 protected override object InvokeListenerMethod(string methodName, object[] arguments)
 {
     try
     {
         MethodInfo mi = MethodNode.GetBestMethod(HandlerObject.GetType(), methodName, BINDING_FLAGS, arguments);
         if (mi == null)
         {
             throw new ListenerExecutionFailedException("Failed to invoke the target method '" + methodName +
                                                        "' with arguments " +
                                                        StringUtils.ArrayToCommaDelimitedString(arguments));
         }
         try
         {
             return(mi.Invoke(HandlerObject, arguments));
         } catch (Exception e)
         {
             throw new ListenerExecutionFailedException("Listener method '" + methodName + "' threw exception.", e);
         }
     } catch (Exception e)
     {
         throw new ListenerExecutionFailedException("Failed to invoke the target method '" + methodName +
                                                    "' with arguments " +
                                                    StringUtils.ArrayToCommaDelimitedString(arguments), e);
     }
 }
예제 #2
0
 /// <summary>
 /// Loads application context from the specified resource locations.
 /// </summary>
 /// <param name="locations">Resources to load object definitions from.</param>
 protected virtual IConfigurableApplicationContext LoadContextLocations(string[] locations)
 {
     if (logger.IsInfoEnabled)
     {
         logger.Info("Loading config for: " + StringUtils.ArrayToCommaDelimitedString(locations));
     }
     return(new FluentTestableXmlApplicationContext(locations));
 }
예제 #3
0
        /// <summary>
        /// Applies the assembly filters to the assembly candidates.
        /// </summary>
        /// <param name="assemblyCandidates">The assembly candidates.</param>
        /// <returns></returns>
        protected virtual IEnumerable <Assembly> ApplyAssemblyFiltersTo(IEnumerable <Assembly> assemblyCandidates)
        {
            var filteredAssemblies = assemblyCandidates.Where(IsIncludedAssembly).
                                     AsEnumerable();

            Logger.LogDebug($"Filtered Assemblies: {StringUtils.ArrayToCommaDelimitedString(filteredAssemblies.ToArray())}");

            return(filteredAssemblies);
        }
예제 #4
0
        private List <string> GetAllAssembliesInPath(string folderPath)
        {
            var assemblies = new List <string>();

            assemblies.AddRange(DiscoverAssemblies(folderPath, "*.dll"));
            assemblies.AddRange(DiscoverAssemblies(folderPath, "*.exe"));

            Logger.Debug(m => m("Assemblies to be scanned: {0}", StringUtils.ArrayToCommaDelimitedString(assemblies.ToArray())));

            return(assemblies);
        }
예제 #5
0
 /// <summary>
 /// Converts context key to string.
 /// </summary>
 /// <remarks>
 /// Subclasses can override this to return a string representation of
 /// their contextKey for use in logging.
 /// </remarks>
 /// <param name="contextKey">Context key to convert.</param>
 /// <returns>
 /// String representation of the specified <paramref name="contextKey"/>.  Null if
 /// contextKey is null.
 /// </returns>
 protected virtual string ContextKeyString(object contextKey)
 {
     if (contextKey == null)
     {
         return(null);
     }
     if (contextKey is string[])
     {
         return(StringUtils.ArrayToCommaDelimitedString((string[])contextKey));
     }
     else
     {
         return(contextKey.ToString());
     }
 }
예제 #6
0
        /// <summary>
        /// Instantiates and populates the underlying
        /// <see cref="Spring.Objects.Factory.IObjectFactory"/> with the object
        /// definitions yielded up by the <see cref="ConfigurationLocations"/>
        /// method.
        /// </summary>
        /// <exception cref="Spring.Objects.ObjectsException">
        /// In the case of errors encountered while refreshing the object factory.
        /// </exception>
        /// <exception cref="ApplicationContextException">
        /// In the case of errors encountered reading any of the resources
        /// yielded by the <see cref="ConfigurationLocations"/> method.
        /// </exception>
        /// <seealso cref="Spring.Context.Support.AbstractApplicationContext.RefreshObjectFactory()"/>
        protected override void RefreshObjectFactory()
        {
            // Shut down previous object factory, if any.
            DefaultListableObjectFactory oldObjectFactory = _objectFactory;

            _objectFactory = null;

            if (oldObjectFactory != null)
            {
                oldObjectFactory.Dispose();
            }

            try
            {
                DefaultListableObjectFactory objectFactory = CreateObjectFactory();
                CustomizeObjectFactory(objectFactory);
                LoadObjectDefinitions(objectFactory);

                _objectFactory = objectFactory;

                #region Instrumentation

                if (log.IsDebugEnabled)
                {
                    log.Debug(
                        string.Format(
                            "Refreshed ObjectFactory for application context '{0}'.",
                            Name));
                }

                #endregion
            }
            catch (IOException ex)
            {
                throw new ApplicationContextException(
                          string.Format(
                              "I/O error parsing XML resource for application context '{0}'.",
                              Name), ex);
            }
            catch (UriFormatException ex)
            {
                throw new ApplicationContextException(
                          string.Format(
                              "Error parsing resource locations [{0}] for application context '{1}'.",
                              StringUtils.ArrayToCommaDelimitedString(ConfigurationLocations),
                              Name), ex);
            }
        }
예제 #7
0
        /// <summary>
        /// A <see cref="System.String"/> that represents the current
        /// invocation.
        /// </summary>
        /// <remarks>
        /// <p>
        /// <note type="implementnotes">
        /// Does <b>not</b> invoke <see cref="System.Object.ToString()"/> on the
        /// <see cref="Spring.Aop.Framework.AbstractMethodInvocation.This"/> target
        /// object, as that too may be proxied.
        /// </note>
        /// </p>
        /// </remarks>
        /// <returns>
        /// A <see cref="System.String"/> that represents the current invocation.
        /// </returns>
        public override string ToString()
        {
            StringBuilder buffer = new StringBuilder("Invocation: method '");

            buffer.Append(Method.Name).Append("', ").Append("arguments ");
            buffer.Append(this.arguments != null ? StringUtils.ArrayToCommaDelimitedString(this.arguments) : "[none]");
            buffer.Append("; ");
            if (this.target == null)
            {
                buffer.Append("target is null.");
            }
            else
            {
                buffer.Append("target is of Type [").Append(this.targetType.FullName).Append(']');
            }
            return(buffer.ToString());
        }
예제 #8
0
        public TradeResponse Handle(TradeRequest tradeRequest)
        {
            TradeResponse tradeResponse;
            ArrayList     errors = new ArrayList();

            if (creditCheckService.CanExecute(tradeRequest, errors))
            {
                tradeResponse = executionVenueService.ExecuteTradeRequest(tradeRequest);
            }
            else
            {
                tradeResponse              = new TradeResponse();
                tradeResponse.Error        = true;
                tradeResponse.ErrorMessage = StringUtils.ArrayToCommaDelimitedString(errors.ToArray());
            }
            tradingService.ProcessTrade(tradeRequest, tradeResponse);
            return(tradeResponse);
        }
예제 #9
0
        public TradeResponse Handle(TradeRequest tradeRequest)
        {
            log.Info("received trade request - sleeping 2s to simulate long-running task");
            TradeResponse tradeResponse;
            ArrayList     errors = new ArrayList();

            if (creditCheckService.CanExecute(tradeRequest, errors))
            {
                tradeResponse = executionVenueService.ExecuteTradeRequest(tradeRequest);
            }
            else
            {
                tradeResponse              = new TradeResponse();
                tradeResponse.Error        = true;
                tradeResponse.ErrorMessage = StringUtils.ArrayToCommaDelimitedString(errors.ToArray());
            }
            tradingService.ProcessTrade(tradeRequest, tradeResponse);

            Thread.Sleep(2000);
            return(tradeResponse);
        }
예제 #10
0
        private object DoInvokeMethod(MethodInfo method, object[] args, IMessage message)
        {
            object         result  = null;
            IMethodInvoker invoker = null;

            try {
                invoker = invokers.ContainsKey(method) ? invokers[method] : null;
                if (invoker == null)
                {
                    invoker = new DefaultMethodInvoker(_obj, method);
                    invokers.Add(method, invoker);
                }
                result = invoker.InvokeMethod(args);
            }
            catch (ArgumentException e) {
                try {
                    if (message != null)
                    {
                        result = invoker.InvokeMethod(message);
                        methodsExpectingMessage.Add(method);
                    }
                }
                catch (Exception ex) { //TODO NoSuchMethodException e2) {
                    throw new MessageHandlingException(message, "unable to resolve method for args: " + StringUtils.ArrayToCommaDelimitedString(args), ex);
                }
            }
            return(result == null || result.GetType().Equals(typeof(Missing)) ? null : result);
        }
예제 #11
0
        //TODO GetDbProviderClasses
        private static void InitializeDbProviderFactoryIfNeeded()
        {
            if (ctx == null)
            {
                lock (typeof(DbProviderFactory))
                {
                    if (ctx == null)
                    {
                        try
                        {
                            //TODO get from well know location in app.config....
                            ConfigurableResourceLoader loader = new ConfigurableResourceLoader(DBPROVIDER_ADDITIONAL_RESOURCE_NAME);


                            if (loader.GetResource(DBPROVIDER_ADDITIONAL_RESOURCE_NAME).Exists)
                            {
                                #region Instrumentation
                                if (log.IsDebugEnabled)
                                {
                                    log.Debug("Loading additional DbProviders from " + DBPROVIDER_ADDITIONAL_RESOURCE_NAME);
                                }
                                #endregion
                                ctx = new XmlApplicationContext(DBPROVIDER_CONTEXTNAME, true, new string[] { DBPROVIDER_DEFAULT_RESOURCE_NAME,
                                                                                                             DBPROVIDER_ADDITIONAL_RESOURCE_NAME });
                            }
                            else
                            {
                                ctx = new XmlApplicationContext(DBPROVIDER_CONTEXTNAME, true, new string[] { DBPROVIDER_DEFAULT_RESOURCE_NAME });
                            }

                            string[] dbProviderNames = ctx.GetObjectNamesForType(typeof(IDbProvider));
                            if (log.IsInfoEnabled)
                            {
                                log.Info(String.Format("{0} DbProviders Available. [{1}]", dbProviderNames.Length, StringUtils.ArrayToCommaDelimitedString(dbProviderNames)));
                            }
                        }
                        catch (Exception e)
                        {
                            log.Error("Error processing " + DBPROVIDER_DEFAULT_RESOURCE_NAME, e);
                            throw;
                        }
                    }
                }
            }
        }