当前位置: 首页>>代码示例>>C#>>正文


C# IRailsEngineContext.GetService方法代码示例

本文整理汇总了C#中IRailsEngineContext.GetService方法的典型用法代码示例。如果您正苦于以下问题:C# IRailsEngineContext.GetService方法的具体用法?C# IRailsEngineContext.GetService怎么用?C# IRailsEngineContext.GetService使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在IRailsEngineContext的用法示例。


在下文中一共展示了IRailsEngineContext.GetService方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Process

		/// <summary>
		/// Implementors should perform the action
		/// on the exception. Note that the exception
		/// is available in <see cref="IRailsEngineContext.LastException"/>
		/// </summary>
		/// <param name="context"></param>
        public override void Process(IRailsEngineContext context)
        {
            ILoggerFactory factory = (ILoggerFactory) context.GetService(typeof (ILoggerFactory));
            ILogger logger = factory.Create(context.CurrentController.GetType());

            logger.Error(BuildStandardMessage(context));
            InvokeNext(context);
        }
开发者ID:nats,项目名称:castle-1.0.3-mono,代码行数:14,代码来源:LoggingExceptionHandler.cs

示例2: InitializeFieldsFromServiceProvider

		/// <summary>
		/// Extracts the services the controller uses from the context -- which ultimately 
		/// is a service provider.
		/// </summary>
		/// <param name="context">The context/service provider.</param>
		public void InitializeFieldsFromServiceProvider(IRailsEngineContext context)
		{
			serviceProvider = context;

			viewEngineManager = (IViewEngineManager) serviceProvider.GetService(typeof(IViewEngineManager));

			IControllerDescriptorProvider controllerDescriptorBuilder = (IControllerDescriptorProvider)
				serviceProvider.GetService( typeof(IControllerDescriptorProvider) );

			metaDescriptor = controllerDescriptorBuilder.BuildDescriptor(this);

			ILoggerFactory loggerFactory = (ILoggerFactory) context.GetService(typeof(ILoggerFactory));
			
			if (loggerFactory != null)
			{
				logger = loggerFactory.Create(GetType().Name);
			}
			
			this.context = context;

			Initialize();
		}
开发者ID:nats,项目名称:castle-1.0.3-mono,代码行数:27,代码来源:Controller.cs

示例3: GenerateJSProxy

		/// <summary>
		/// Generates an AJAX JavaScript proxy for a given controller.
		/// </summary>
		/// <param name="context">The context of the current request</param>
		/// <param name="proxyName">Name of the javascript proxy object</param>
		/// <param name="controller">Controller which will be target of the proxy</param>
		/// <param name="area">area which the controller belongs to</param>
		public String GenerateJSProxy(IRailsEngineContext context, string proxyName, string area, string controller)
		{
			String nl = Environment.NewLine;
			String cacheKey = (area + "|" + controller).ToLower(CultureInfo.InvariantCulture);
			String result = (String) ajaxProxyCache[cacheKey];

			if (result == null)
			{
				logger.Debug("Ajax Proxy for area: '{0}', controller: '{1}' was not found. Generating a new one", area, controller);
				IControllerTree controllerTree = (IControllerTree) context.GetService(typeof(IControllerTree));
				Type controllerType = controllerTree.GetController(area, controller);

				if (controllerType == null)
				{
					logger.Fatal("Controller not found for the area and controller specified");
					throw new RailsException("Controller not found with Area: '{0}', Name: '{1}'", area, controller);
				}

				String baseUrl = context.ApplicationPath + "/";

				if (area != null && area != String.Empty)
				{
					baseUrl += area + "/";
				}

				baseUrl += controller + "/";

				// TODO: develop a smarter function generation, inspecting the return
				// value of the action and generating a proxy that does the same.
				// also, think on a proxy pattern for the Ajax.Updater.

				StringBuilder functions = new StringBuilder(1024);

				functions.Append("{");

				ControllerMetaDescriptor metaDescriptor = controllerDescriptorBuilder.BuildDescriptor(controllerType);

				bool commaNeeded = false;

				foreach(MethodInfo ajaxActionMethod in metaDescriptor.AjaxActions)
				{
					if (!commaNeeded) commaNeeded = true;
					else functions.Append(',');

					String methodName = ajaxActionMethod.Name;

					AjaxActionAttribute ajaxActionAtt =
						(AjaxActionAttribute) GetSingleAttribute(ajaxActionMethod, typeof(AjaxActionAttribute), true);
					AccessibleThroughAttribute accessibleThroughAtt =
						(AccessibleThroughAttribute) GetSingleAttribute(ajaxActionMethod, typeof(AccessibleThroughAttribute), true);

					String url = baseUrl + methodName + "." + context.UrlInfo.Extension;
					String functionName = ToCamelCase(ajaxActionAtt.Name != null ? ajaxActionAtt.Name : methodName);

					functions.AppendFormat(nl + "\t{0}: function(", functionName);

					StringBuilder parameters = new StringBuilder("_=");

					foreach(ParameterInfo pi in ajaxActionMethod.GetParameters())
					{
						string paramName = GetParameterName(pi);

						// by default, just forward the parameter taken by the function as the request parameter value
						string paramValue = paramName;

						if (JsonBinderAttType != null)
						{
							// if we have a [JSONBinder] mark on the parameter, we can serialize the parameter using prototype's Object.toJSON().
							object jsonBinderAtt = GetSingleAttribute(pi, JsonBinderAttType, false);
							if (jsonBinderAtt != null)
							{
								// toJSON requires Prototype 1.5.1. Users of [JSONBinder] should be aware of that.
								paramName = (string) GetPropertyValue(jsonBinderAtt, "EntryKey");
								paramValue = "Object.toJSON(" + paramValue + ")";
							}
						}

						functions.AppendFormat("{0}, ", paramName);

						// appends " &<paramName>=' + <paramValue> + ' " to the string.
						// the paramValue will run on the client-side, so it can be a parameter name, or a function call like Object.toJSON().
						parameters.Append("\\x26").Append(paramName).Append("='+").Append(paramValue).Append("+'");
					}

					string httpRequestMethod = "get";
					if (accessibleThroughAtt != null)
					{
						httpRequestMethod = accessibleThroughAtt.Verb.ToString().ToLower();
					}

					functions.Append("callback)").Append(nl).Append("\t{").Append(nl);
					functions.AppendFormat("\t\tvar r=new Ajax.Request('{0}', " +
					                       "{{method: '{1}', asynchronous: !!callback, onComplete: callback, parameters: '{2}'}}); " + nl +
//.........这里部分代码省略.........
开发者ID:nats,项目名称:castle-1.0.3-mono,代码行数:101,代码来源:PrototypeAjaxProxyGenerator.cs

示例4: ObtainMonoRailHandlerProvider

		private IMonoRailHttpHandlerProvider ObtainMonoRailHandlerProvider(IRailsEngineContext mrContext)
		{
			return (IMonoRailHttpHandlerProvider) mrContext.GetService(typeof(IMonoRailHttpHandlerProvider));
		}
开发者ID:nats,项目名称:castle-1.0.3-mono,代码行数:4,代码来源:MonoRailHttpHandlerFactory.cs

示例5: CreateControllerExecutor

		/// <summary>
		/// Creates the and initialize executor.
		/// </summary>
		/// <param name="controller">The controller.</param>
		/// <param name="context">The context.</param>
		/// <returns></returns>
		private IControllerLifecycleExecutor CreateControllerExecutor(Controller controller, IRailsEngineContext context)
		{
			IControllerLifecycleExecutorFactory factory = 
				(IControllerLifecycleExecutorFactory) context.GetService(typeof(IControllerLifecycleExecutorFactory));

			IControllerLifecycleExecutor executor = factory.CreateExecutor(controller, context);
			
			context.Items[ControllerLifecycleExecutor.ExecutorEntry] = executor;

			return executor;
		}
开发者ID:nats,项目名称:castle-1.0.3-mono,代码行数:17,代码来源:EngineContextModule.cs

示例6: CreateController

		/// <summary>
		/// Uses the url information and the controller factory
		/// to instantiate the proper controller.
		/// </summary>
		/// <param name="context">MonoRail's request context</param>
		/// <returns>A controller instance</returns>
		private Controller CreateController(IRailsEngineContext context)
		{
			UrlInfo info = context.UrlInfo;

			if (logger.IsDebugEnabled)
			{
				logger.DebugFormat("Starting request process for '{0}'/'{1}.{2}' Extension '{3}' with url '{4}'",
					info.Area, info.Controller, info.Action, info.Extension, info.UrlRaw);
			}

			IControllerFactory controllerFactory = (IControllerFactory) context.GetService(typeof(IControllerFactory));

			Controller controller = controllerFactory.CreateController(info);

			return controller;
		}
开发者ID:nats,项目名称:castle-1.0.3-mono,代码行数:22,代码来源:EngineContextModule.cs


注:本文中的IRailsEngineContext.GetService方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。