public void Format(IPaperContext context, IObjectFactory factory, Entity entity) { // TODO: deveriamos consultar o catalogo // var paperCatalog = factory.GetInstance<IPaperCatalog>(); // paperCatalog.FindByType(typeof(TPaper)); var paper = (IPaper)Activator.CreateInstance(paperType); var paperDescriptor = new PaperDescriptor(paper); var href = paperDescriptor.PathTemplate.Substring(1); if (paperArgs != null) { foreach (var arg in paperArgs) { var value = Change.To <string>(arg); href = Regex.Replace(href, @"\{[^{}]+\}", value); } } if (Rel?.Any() != true) { this.AddRel(RelNames.Link); } this.Href = href; }
public void Format(IPaperContext context, IObjectFactory factory, Entity entity) { if (Rel?.Any() != true) { this.AddRel(RelNames.Link); } }
public ICollection <INode <TValue> > GetNodes(IPaperContext ctx) { try { return((ICollection <INode <TValue> >)ctx.Cache[nodesKey]); } catch (Exception ex) { throw new InvalidCastException($"O valor obtido não corresponde ao tipo esperado: {typeof(TValue).FullName}", ex); } }
public TValue GetRecord(IPaperContext ctx) { try { return((TValue)ctx.Cache[recordKey]); } catch (Exception ex) { throw new InvalidCastException($"O valor obtido não corresponde ao tipo esperado: {typeof(TValue).FullName}", ex); } }
public void RenderPaper(IPaperContext ctx) { Func <IPaperContext, IEntity> statement = null; switch (ctx.Verb) { case VerbNames.Get: statement = GetStatement; break; case VerbNames.Post: statement = PostStatement; break; } if (statement == null) { throw new HttpException(HttpStatusCode.MethodNotAllowed); } var result = statement.Invoke(ctx); ctx.OutgoingData.WriteData(result); }
private IEntity MethodNotAllowed(IPaperContext ctx) { throw new HttpException(HttpStatusCode.MethodNotAllowed); }
public void Format(IPaperContext context, IObjectFactory factory, Entity entity) { OnFormat?.Invoke(context, factory, entity); }