private void ImportOpmlItem(OpmlItem item) { foreach (OpmlItem childItem in item.ChildItems) { ImportOpmlItem(childItem); } var newLink = new Link { Title = item.Title, Url = item.HtmlUrl, Rss = item.XmlUrl, CategoryId = _categoryID, IsActive = true, NewWindow = false }; // TODO: let user specify and pass as command props // this isn't a valid collision test really if (!_allLinks.Contains(newLink)) { Links.CreateLink(newLink); } }
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)))); } } }
public void Apply(AbstractNode node, SemanticDocument doc) { if (node.Parent != null) { doc.AddLink(Links.CreateLink(node.Parent.Title, node.Parent.Uri, Terms.Parent)); } }
public virtual void Apply(AbstractNode abstractNode, SemanticDocument doc) { var hyperlinks = (abstractNode as IHasHyperlinks)?.Hyperlinks ?? Enumerable.Empty <Tuple <Term, Uri, string> >(); foreach (var hyperlink in hyperlinks) { doc.AddLink(Links.CreateLink(hyperlink.Item3, hyperlink.Item2, hyperlink.Item1)); } }
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)); }
public virtual void Apply(AbstractNode abstractNode, SemanticDocument doc) { var childNodes = (abstractNode as IHasChildNodes)?.ChildNodes; if (childNodes == null) { return; } ; foreach (var child in childNodes) { doc.AddLink(Links.CreateLink(child.Item4, child.Item3, child.Item1)); } }
public static Link CreateLinkInDb(int categoryId, string title, int?entryId, string rel) { var link = new Link { BlogId = Config.CurrentBlog.Id, IsActive = true, CategoryId = categoryId, Title = title, Url = "http://noneofyourbusiness.com/", Relation = rel }; if (entryId != null) { link.PostId = (int)entryId; } link.Id = Links.CreateLink(link); return(link); }
static Link CreateLink(string title, int?categoryId, int?postId) { var link = new Link(); link.IsActive = true; link.BlogId = Config.CurrentBlog.Id; if (categoryId != null) { link.CategoryId = (int)categoryId; } link.Title = title; if (postId != null) { link.PostId = (int)postId; } int linkId = Links.CreateLink(link); Assert.AreEqual(linkId, link.Id); return(link); }
private static MethodHandler <SemanticDocument> BuildPostHandlerForMethodInfo(MethodInfoNode methodNode, ServiceLocatorDelegate serviceLocator) { MethodHandler <SemanticDocument> .InvokeMethodDelegate invoke2 = async(submittedArgs) => { var argsEnumerator = submittedArgs.GetEnumerator(); var argsList = methodNode.MethodInfo.GetParameters() .Select(pi => { if (pi.GetCustomAttribute <InjectAttribute>() != null) { if (serviceLocator == null) { throw new InvalidOperationException( $"Cannot [Inject] parameter {pi.Name} for {methodNode.MethodInfo.DeclaringType.Name}.{methodNode.MethodInfo.DeclaringType.Name} Please set ServiceLocator at startup"); } return(serviceLocator(pi.ParameterType)); } else { argsEnumerator.MoveNext(); var current = argsEnumerator.Current; if (current.Item1 != new UrlPart(pi.Name)) { throw new ArgumentException("Mismatch: expected " + pi.Name + ", received" + current.Item1.ToString()); } return(Tuple.Create(current.Item2, null as Action)); } }).ToList(); var parameters = argsList.Select(a => a.Item1).ToArray(); var invokeResult = methodNode.MethodInfo.Invoke(methodNode.Parent, parameters); foreach (var tuple in argsList) { tuple.Item2?.Invoke(); } if (methodNode.MethodInfo.ReturnType == typeof(void)) { } var task = invokeResult as Task; if (task != null) { await task; invokeResult = task.GetType().GetRuntimeProperty("Result")?.GetValue(task) ?? invokeResult; } var representation = new SemanticDocument(); //Add a link back to the thing that the action happened to { OneOf.OneOf <Modified, Created> result = default(OneOf.OneOf <Modified, Created>); if (invokeResult is Created) { result = (Created)invokeResult; } if (invokeResult is Modified) { result = (Modified)invokeResult; } if (invokeResult is AbstractNode) { result = new Created((AbstractNode)invokeResult); } result = new Modified(methodNode.Parent); result.Switch( modified => representation.AddLink(Links.CreateLink($"Modified \'{modified.Node.Title}\'", modified.Node.Uri, modified.Node.Term)), created => representation.AddLink(Links.CreateLink($"Created \'{created.Node.Title}\'", created.Node.Uri, created.Node.Term))); } representation.Value.Add(SemanticProperty.CreateValue(Terms.Title, JToken.FromObject(methodNode.Title))); return(new InvokeResult <SemanticDocument> .RepresentationResult(representation)); }; var parameterInfo = methodNode.GetParameters(); return(new MethodHandler <SemanticDocument>(new Method.Post(), parameterInfo, invoke2)); }