public HyperMediaResult(string resourceName, string hyperMediaName, UrlHelper urlHelper, dynamic metdata, object model = null) { Model = model; this.urlHelper = urlHelper; this.metadata = metdata; this.resourceName = resourceName; this.hyperMediaName = hyperMediaName; hyperMedia = HyperMediaRegistry.Instance.FindFirst(HyperMediaName()); if (hyperMedia == null) { throw new InvalidOperationException(string.Format("Cannot find a class that implements IHyperMedia with namespace and name {0}.{1}. Make sure you have the following line in Global.asax.cs's Application_Start() method: HyperMediaRegistry.Instance.FindAllIn<MvcApplication>();", HyperMediaRegistry.Instance.NamespaceFilter, HyperMediaName())); } }
public describe_HyperMedia(IHyperMedia hyperMedia) { HyperMedia = hyperMedia; Registry = new Dictionary<string, IHyperMedia>(); Metadata = new ExpandoObject(); }
/// <summary> /// Use this method to registry hypermedia that is used for partial conversions. /// </summary> /// <param name="hyperMediaName"></param> /// <param name="hyperMedia"></param> protected void Register(string hyperMediaName, IHyperMedia hyperMedia) { if (!Registry.ContainsKey(hyperMediaName)) { Registry.Add(hyperMediaName, hyperMedia); } }
private string Serialize(ControllerContext context, IHyperMedia hyperMedia) { Func<string, dynamic, dynamic> hyperMediaFor = null; hyperMediaFor = (relativeHyperMediaName, entity) => { string fullName = resourceName + "." + relativeHyperMediaName; var relativeHyperMedia = HyperMediaRegistry.Instance.FindFirst(fullName); relativeHyperMedia.UrlHelper = urlHelper; relativeHyperMedia.Metadata = metadata; if (relativeHyperMedia == null) { throw new InvalidOperationException(string.Format("Cannot find a class that implements IHyperMedia with namespace and name {0}.{1}. Make sure you have the following line in Global.asax.cs's Application_Start() method: HyperMediaRegistry.Instance.FindAllIn<MvcApplication>();", HyperMediaRegistry.Instance.NamespaceFilter, fullName)); } return relativeHyperMedia.ToHyperMedia(entity, hyperMediaFor); }; var acceptHeader = WinningFormatter(context); return FindFormatter(WinningFormatter(context)).Content(hyperMedia.ToHyperMedia(Model, hyperMediaFor)); }
string Format(ControllerContext context, IHyperMedia hyperMedia) { hyperMedia.UrlHelper = urlHelper; hyperMedia.Metadata = metadata; return Serialize(context, hyperMedia); }
string Format(ControllerContext context, IHyperMedia hyperMedia) { hyperMedia.UrlHelper = urlHelper; hyperMedia.ViewBag = viewBag; return Serialize(context, hyperMedia); }
public describe_HyperMedia(IHyperMedia hyperMedia) { HyperMedia = hyperMedia; Registry = new Dictionary<string, IHyperMedia>(); }