public static Renderer GetRenderer(ProcessURI uri, IProcessResponse response) { RenderingSection config = RenderingSection.Current; if (renderer == null) { Type rendererType = Type.GetType(config.Type); Assembly asm = rendererType.Assembly; renderer = asm.CreateInstance(rendererType.FullName) as Renderer; renderer.Path = ParseRendererPath(config); //foreach (CustomHelper helper in config.CustomHelpers) // renderer.Helpers.Add(CreateHelperInstance(helper)); renderer.UrlHelper = new UrlHelper("url"); renderer.AppHelper = new AppHelper("app"); renderer.StateHelper = new StateHelper("state"); renderer.AjaxHelper = new AjaxHelper("ajax"); renderer.TypeHelper = new TypeHelper("type"); } renderer.URI = uri; Configuration.Template template = renderer.GetTemplate(response); renderer.LayoutFileName = template != null ? ((string.IsNullOrEmpty(template.LayoutFileName)) ? config.LayoutFileName : template.LayoutFileName) : config.LayoutFileName; return renderer; }
/// <summary> /// Executes the supplied <see cref="uri"/>. /// </summary> /// <param name="uri">Specifies the <see cref="ProcessURI"/> to be executed.</param> /// <param name="domain">Specifies the <see cref="Domain"/> with the information necessary to execute.</param> /// <returns>The <see cref="IProcessResponse"/> of the executed process.</returns> public static IProcessResponse Execute(ProcessURI uri, Domain domain) { List<IInterceptor> interceptors = CoreSection.Current.GetInteceptors(); return GetProcess(uri).Execute(domain, o => interceptors.ForEach(i => i.OnProcessExecuting(uri, o)), o => interceptors.ForEach(i => i.OnProcessExecuted(uri, o))); }
public static AuthorizationRule GetRule(ProcessURI uri) { AuthorizationURI authorizationURI = SecuritySection.Current.Authorization.URIs.Find(uri); if (authorizationURI != null) return GetRule(authorizationURI); return null; }
public Template Find(ProcessURI uri) { foreach (Template tpl in this) if (tpl.IsUriTemplate(uri)) return tpl; return null; }
public AuthorizationURI Find(ProcessURI uri) { foreach (AuthorizationURI authorizationURI in this) if (uri.ToString().Contains(authorizationURI.Pattern)) return authorizationURI; return null; }
public EntityCollectionDomain(Type type, Type collectionType, ProcessURI uri, object instance, Domain parent) : base(type, uri, null) { if (collectionType == null) throw new ArgumentNullException("collectionType"); CollectionType = collectionType; Instance = instance; Parent = parent; }
public void OnProcessExecuted(ProcessURI uri, object obj) { switch (uri.Behavior) { case ProcessBehavior.New: SaveChange(uri, obj); break; } }
public virtual ProcessURI Evaluate(Expression expression, ProcessURI uri) { var nodes = Evaluate(expression); var args = new List<object>(); foreach (var node in nodes) args.AddRange(ExtractValue(node)); uri.Argument = ProcessArgument.Parse(uri.Behavior, args.ToArray()); return uri; }
public void OnProcessExecuting(ProcessURI uri, object obj) { switch (uri.Behavior) { case ProcessBehavior.Edit: case ProcessBehavior.Delete: case ProcessBehavior.Exec: SaveChange(uri, obj); break; } }
private VelocityContext CreateTemplateContext(ProcessURI uri, IProcessResponse response, Domain domain) { VelocityContext context = new VelocityContext(); context.Put("uri", uri); context.Put("renderer", this); if (response != null) context.Put("response", response); if (domain != null) context.Put("domain", domain); foreach (RendererHelper helper in Helpers) context.Put(helper.Name, helper); return context; }
public static IProcessResponse Evaluate(ProcessURI uri, IProcessResponse response) { if (IsAuthorized(uri)) { Expression expression = GetRuleResponseExpression(uri) ?? Expression.Empty; if (expression != Expression.Empty) { var expressionURI = ProcessURI.Parse(expression.ToString()); foreach (AuthorizationKeyEvaluator evaluator in Evaluators) expressionURI = evaluator.Evaluate(expression, expressionURI); //TODO: Apply new URI to the response subset } } return response; }
public static ProcessURI Evaluate(ProcessURI uri) { if (IsAuthorized(uri)) { if (uri.Behavior == ProcessBehavior.Query) { Expression expression = GetRuleExpression(uri) ?? Expression.Parse(uri.Argument.ToString(), uri.Behavior) ?? Expression.Empty; foreach (AuthorizationKeyEvaluator evaluator in Evaluators) uri = evaluator.Evaluate(expression, uri); } } return uri; }
private static void SaveChange(ProcessURI uri, object obj) { if (obj != null) { object userId = null; if (SecurityHelper.IsAuthenticated) { var token = SecurityHelper.AuthenticationToken; userId = ContextFactory.GetContext(token.GetType()).GetID(token); } var entityId = ContextFactory.GetContext(obj.GetType()).GetID(obj); var change = new EntityChange(DateTime.Now, uri.ToString(), entityId, obj, userId != null ? userId.ToString() : null); ContextFactory.GetContext(typeof(EntityChange)).Insert(change); } }
private static QueryProcessResponse CreateResponse(Type type, IEnumerable items, ProcessURI uri) { var domains = new DomainCollection(); var enumerator = items.GetEnumerator(); while (enumerator.MoveNext()) { var instance = enumerator.Current; var entity = new EntityDomain(type, uri) { Instance = instance, Value = ContextFactory.GetContext(type).GetID(instance), }; domains.Add(entity); } return new QueryProcessResponse(type, domains) { URI = uri }; }
private static EntityProcess Create(ProcessURI uri) { switch (uri.Behavior) { case ProcessBehavior.New: return new EntityNewProcess(uri); case ProcessBehavior.Exec: return new EntityExecProcess(uri); case ProcessBehavior.Edit: return new EntityEditProcess(uri); case ProcessBehavior.View: return new EntityViewProcess(uri); case ProcessBehavior.Delete: return new EntityDeleteProcess(uri); } return null; }
/// <summary> /// Get the process specified by ProcessURI uri. /// </summary> /// <param name="uri">A ProcessURI uri.</param> /// <returns>A Process' instance.</returns> private static Process GetProcess(ProcessURI uri) { switch (uri.Behavior) { case ProcessBehavior.Schema: return new SchemaProcess(uri); case ProcessBehavior.Service: return new ServiceProcess(uri); case ProcessBehavior.Workflow: return new WorkflowProcess(uri); case ProcessBehavior.Query: return new QueryProcess(uri); case ProcessBehavior.Index: return new IndexProcess(uri); case ProcessBehavior.Session: return new SessionProcess(uri); default: return new EntityProcess(uri); } }
public QueryProcess(ProcessURI uri) : base(uri) { }
public static bool IsAuthorized(ProcessURI uri) { return SecurityHandler.IsAuthorized(uri); }
public ServiceProcess(ProcessURI uri) : base(uri) { }
public RedirectProcessResponse(ProcessURI uri) { if (uri == null) throw new ArgumentNullException("uri"); URI = uri; }
protected HttpHandlerBase(ProcessURI requestedURI) { this.requestedURI = requestedURI; }
public SessionProcess(ProcessURI uri) : base(uri) { }
public EntityEditProcess(ProcessURI uri) : base(uri) { }
public EntityDomain(Type type, ProcessURI uri, object value) : this(type, uri) { Value = value; }
protected string GetTemplateName(ProcessURI uri, Domain domain) { Template template = RenderingSection.Current.Templates.Find(uri); if (template != null) return template.TemplateDomains.Find(domain).FileName; return string.Empty; }
public EntityDeleteProcess(ProcessURI uri) : base(uri) { }
public EntityDomain(Type type, ProcessURI uri, object value, object instance) : this(type, uri, value) { Instance = instance; }
public static EntityDomain CreateDomain(Type type, ProcessURI uri) { return new EntityDomain(type, uri); }
public WorkflowProcess(ProcessURI uri) : base(uri) { }
public static IProcessResponse ExecuteProcess(ProcessURI uri, Domain domain) { return ProcessFactory.Execute(uri, domain); }