Exemplo n.º 1
0
        public virtual void Apply(AbstractNode abstractNode, SemanticDocument doc)
        {
            var type          = abstractNode.GetType().GetTypeInfo();
            var markedUpProps = type.DeclaredProperties
                                .Select(propertyInfo => new
            {
                propertyInfo = propertyInfo,
                att          = CustomAttributeExtensions.GetCustomAttribute <ExposeAttribute>((MemberInfo)propertyInfo),
                propertyUri  = UriHelper.Combine(abstractNode.Uri, propertyInfo.Name)
            }).Where(x => x.att != null);


            foreach (var x in markedUpProps)
            {
                if (typeof(AbstractNode).GetTypeInfo().IsAssignableFrom(x.propertyInfo.PropertyType.GetTypeInfo()))
                {
                    var childNode = (AbstractNode)x.propertyInfo.GetValue(abstractNode);
                    doc.AddLink(Links.CreateLink(childNode.Title, childNode.Uri, childNode.Term));
                }
                else
                {
                    doc.Value.Add(SemanticProperty.CreateValue(TermFactory.From(x.propertyInfo),
                                                               JToken.FromObject(x.propertyInfo.GetValue(abstractNode))));
                }
            }
        }
Exemplo n.º 2
0
        private static void AddSemanticItemsFromMethodInfo(MethodInfoNode methodInfoNode,
                                                           SemanticDocument representation)
        {
            var term             = TermFactory.From(methodInfoNode.MethodInfo);
            var methodParameters = methodInfoNode.GetParameters();
            var operation        = Operation.Create(methodInfoNode.Title, methodParameters, methodInfoNode.Uri, term);

            representation.Value.Add(operation);

            representation.AddLink(Links.CreateLink(methodInfoNode.Parent.Title, methodInfoNode.Parent.Uri, Terms.Parent));
        }
        internal static SemanticProperty AddLink(this SemanticDocument doc, SemanticPropertiesSet link)
        {
            var linksRel = TermFactory.From <Links>();
            var links    = doc.Value[linksRel] ??
                           (SemanticProperty.CreateList(linksRel, new SemanticPropertiesList())).Then(
                sp => doc.Value.Add(sp));
            var semanticPropertiesList = links.Value.AsT3;

            semanticPropertiesList.Add(link);
            return(links);
        }
Exemplo n.º 4
0
        public void Configuration(IAppBuilder app)
        {
            var representors = new Representor <SemanticDocument>[]
            {
                new Siren.SirenRepresentor(),
                new SirenServerSideHtmlRepresentor(),
                //new SirenReactHtmlRepresentor()
            };

            var taskListAppRoot = BuildTaskListAppRoot(new Uri("/tasks", UriKind.Relative));

            app.ExposeRootNodeAsHypermediaApi(taskListAppRoot, LocateAdaptors, representors);


            var chessAppRoot = new ChessEngineApp("ChessEngine", new Uri("/chess", UriKind.Relative), TermFactory.From <ChessEngineApp>());

            app.ExposeRootNodeAsHypermediaApi(chessAppRoot, LocateAdaptors, representors);

            var indexAppRoot = new IndexRootNode("Index", new Uri("/", UriKind.Relative));

            indexAppRoot.AddLink("chess engine app", chessAppRoot.Uri, TermFactory.From <ChessEngineApp>());
            indexAppRoot.AddLink("task list app", taskListAppRoot.Uri, TermFactory.From <TaskListAppRoot>());
            app.ExposeRootNodeAsHypermediaApi(indexAppRoot, LocateAdaptors, representors);
        }
Exemplo n.º 5
0
 public static SemanticProperty Create <T>(OneOf <SemanticPropertiesSet, JToken, Term, SemanticPropertiesList> value)
 {
     return(new SemanticProperty(TermFactory.From <T>(), value));
 }
Exemplo n.º 6
0
 public static SemanticProperty <SemanticPropertiesList> CreateList <TTerm>(SemanticPropertiesList value)
 {
     return(CreateList(TermFactory.From <TTerm>(), value));
 }
Exemplo n.º 7
0
 public static SemanticProperty <Term> CreateTerm <TTerm, TValueTerm>()
 {
     return(CreateTerm(TermFactory.From <TTerm>(), TermFactory.From <TValueTerm>()));
 }
Exemplo n.º 8
0
 public static SemanticProperty <Term> CreateTerm <TTerm>(Term value)
 {
     return(CreateTerm(TermFactory.From <TTerm>(), value));
 }
Exemplo n.º 9
0
 public static SemanticProperty <JToken> CreateValue <T>(JToken value)
 {
     return(CreateValue(TermFactory.From <T>(), value));
 }
Exemplo n.º 10
0
 public static SemanticProperty <SemanticPropertiesSet> CreateSet <TTerm>(SemanticPropertiesSet value = null)
 {
     return(CreateSet(TermFactory.From <TTerm>(), value));
 }
Exemplo n.º 11
0
 public GlossaryNode(AbstractNode parent)
 {
     this.parent = parent;
     this.terms.Add(TermFactory.From <GlossaryNode>(), new TermNode(this, TermFactory.From <GlossaryNode>()));
 }
Exemplo n.º 12
0
 public Card(Board parent, UrlPart urlPart, string title) : base(parent, urlPart, title, TermFactory.From <Card>())
 {
 }
Exemplo n.º 13
0
 public Boards(TaskListAppRoot parent, UrlPart urlPart) : base(parent, urlPart, nameof(Boards), TermFactory.From <Boards>())
 {
 }
Exemplo n.º 14
0
 public Authentication(TaskListAppRoot parent, UrlPart urlPart) : base(parent, urlPart, nameof(Authentication), TermFactory.From <Authentication>())
 {
 }
Exemplo n.º 15
0
 public TaskListAppRoot(Uri uri) : base("Task Lists App", uri, TermFactory.From <TaskListAppRoot>())
 {
     this.Authentication = (new Authentication(this, nameof(Authentication)));
     this.Boards         = (new Boards(this, nameof(Boards)));
 }
Exemplo n.º 16
0
 public Board(Boards parent, string key, string title) : base(parent, key, title, TermFactory.From <Board>())
 {
 }
Exemplo n.º 17
0
 public SemanticDocument() : base(TermFactory.From <SemanticDocument>(), new SemanticPropertiesSet())
 {
 }
Exemplo n.º 18
0
 public Task(Card parent, UrlPart urlPart, string title) : base(parent, urlPart, title, TermFactory.From <Task>())
 {
 }
Exemplo n.º 19
0
        public MethodParameter[] GetParameters()
        {
            var parameterInfo = this.MethodInfo.GetParameters()
                                .Where(mi => mi.GetCustomAttribute <InjectAttribute>() == null)
                                .Select(pi => new MethodParameter(pi.Name, GetMethodParameterType(pi), TermFactory.From(pi))).ToArray();

            return(parameterInfo.ToArray());
        }
Exemplo n.º 20
0
 public ChessGameNode(ChessGame chessGame, ChessEngineApp parent, UrlPart gameId) : base(parent, gameId, "Game " + gameId, TermFactory.From <ChessGameNode>())
 {
     _chessGame = chessGame;
 }
Exemplo n.º 21
0
 public IndexRootNode(string title, Uri uri) : base(title, uri, TermFactory.From <IndexRootNode>())
 {
 }
Exemplo n.º 22
0
        public SirenDotNet.Entity BuildFromSemanticDocument(SemanticDocument semanticDocument, FindUriForTerm uriTermFinder)
        {
            var links   = new List <SirenDotNet.Link>();
            var actions = new List <Action>();

            var subEntities = new List <SubEntity>();

            var jo = new JObject();

            string sirenTitle = null;

            foreach (var property in semanticDocument.Value)
            {
                property.Value.Switch(set =>
                {
                    if (property.Term.Means(TermFactory.From <Operation>()))
                    {
                        Func <SemanticProperty, Field> buildField = mp =>
                        {
                            var fieldSet  = mp.Value.AsT0;
                            var fieldKind = fieldSet[TermFactory.From <Operation.FieldKind>()].Value.AsT2;

                            var field = new Field()
                            {
                                Name = fieldSet[TermFactory.From <FieldName>()].Value.AsT1.Value <string>(),
                            };
                            if (fieldKind == TermFactory.From <Operation.TextField>())
                            {
                                field.Type = SirenDotNet.FieldTypes.Text;
                            }
                            else if (fieldKind == TermFactory.From <Operation.PasswordField>())
                            {
                                field.Type = SirenDotNet.FieldTypes.Password;
                            }
                            else if (fieldKind == TermFactory.From <Operation.SelectField>())
                            {
                                field.Type  = new FieldTypes("select");
                                var options = fieldSet[TermFactory.From <Operation.Options>()].Value.AsT3;

                                field.ExtensionData["options"] = options.Select(o => o.AsT0)
                                                                 .Select(
                                    o => new
                                {
                                    name  = o[TermFactory.From <DisplayText>()].Value.AsT1.Value <string>(),
                                    value = o[TermFactory.From <Operation.FieldValue>()].Value.AsT1.Value <string>()
                                })
                                                                 .Select(JObject.FromObject).ToArray();
                            }


                            return(field);
                        };
                        ;
                        var href   = new Uri(set[TermFactory.From <Operation.ActionUrl>()].Value.AsT1.Value <string>(), UriKind.Relative);
                        var action = new SirenDotNet.Action(uriTermFinder(property.Term).ToString(), href)
                        {
                            Method = HttpVerbs.POST,
                            Title  = set[TermFactory.From <DisplayText>()].Value.AsT1.Value <string>(),
                            Fields = set[TermFactory.From <Operation.Fields>()].Value.AsT0.Select(x => buildField(x)).ToArray()
                        };
                        actions.Add(action);
                    }
                },
                                      value =>
                {
                    var isTitle = property.Term == Terms.Title;
                    if (isTitle)
                    {
                        sirenTitle = value.ToObject <string>();
                    }
                    else
                    {
                        jo[uriTermFinder(property.Term).ToString()] = value.ToString();
                    }
                },
                                      term => { },
                                      list =>
                {
                    if (property.Term == TermFactory.From <Vocab.Links>())
                    {
                        foreach (var value in list)
                        {
                            var set         = value.AsT0;
                            var displayName = set[TermFactory.From <DisplayText>()].Value.AsT1.Value <string>();
                            Term rel        = set[TermFactory.From <Vocab.Links.Rel>()].Value.AsT2;
                            var href        = new Uri(set[TermFactory.From <Vocab.Links.Href>()].Value.AsT1.Value <string>(), UriKind.Relative);
                            var action      = new SirenDotNet.Link(href, uriTermFinder(rel).ToString())
                            {
                                Title = displayName
                            };
                            links.Add(action);
                        }
                    }
                });
            }



            if (sirenTitle == null)
            {
                throw new Exception("Title cannot be null for siren, attach a Term.Title property");
            }

            var entity = new SirenDotNet.Entity
            {
                Title = sirenTitle,
                //Class = semanticDocument.Class?.Select(c => c.ToString()),
                Links      = links.Any() ? links : null,
                Actions    = actions.Any() ? actions : null,
                Entities   = subEntities.Any() ? subEntities : null,
                Properties = jo.HasValues ? jo : null
            };

            return(entity);
        }