Exemplo n.º 1
0
        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()));
            }
        }
Exemplo n.º 2
0
 public describe_HyperMedia(IHyperMedia hyperMedia)
 {
     HyperMedia = hyperMedia;
     Registry = new Dictionary<string, IHyperMedia>();
     Metadata = new ExpandoObject();
 }
Exemplo n.º 3
0
 /// <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);
     }
 }
Exemplo n.º 4
0
        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));
        }
Exemplo n.º 5
0
        string Format(ControllerContext context, IHyperMedia hyperMedia)
        {
            hyperMedia.UrlHelper = urlHelper;

            hyperMedia.Metadata = metadata;

            return Serialize(context, hyperMedia);
        }
Exemplo n.º 6
0
        string Format(ControllerContext context, IHyperMedia hyperMedia)
        {
            hyperMedia.UrlHelper = urlHelper;

            hyperMedia.ViewBag = viewBag;

            return Serialize(context, hyperMedia);
        }
Exemplo n.º 7
0
 public describe_HyperMedia(IHyperMedia hyperMedia)
 {
     HyperMedia = hyperMedia;
     Registry = new Dictionary<string, IHyperMedia>();
 }