/// <summary> /// Populates the page with content passed during navigation. Any saved state is also /// provided when recreating a page from a prior session. /// </summary> /// <param name="navigationParameter">The parameter value passed to /// <see cref="Frame.Navigate(Type, Object)"/> when this page was initially requested. /// </param> /// <param name="pageState">A dictionary of state preserved by this page during an earlier /// session. This will be null the first time a page is visited.</param> protected override void LoadState(Object navigationParameter, Dictionary<String, Object> pageState) { _resourceType = navigationParameter as ResourceType; if (_resourceType == null) { var param = navigationParameter as List<object>; _resourceType = new ResourceType(param[2] as IProvider); _resourceType.Title = param[0] as string; DefaultViewModel["ResourceTypeTitle"] = _resourceType.Title; DefaultViewModel["Instances"] = new ObservableCollection<Resource>(); DefaultViewModel["FilteredInstances"] = new ObservableCollection<Resource>(); LoadQueriedState(new Uri(param[1] as string), _resourceType); } else { // load instances DefaultViewModel["ResourceTypeTitle"] = _resourceType.Title; DefaultViewModel["Instances"] = new ObservableCollection<Resource>(); DefaultViewModel["FilteredInstances"] = new ObservableCollection<Resource>(); var ctx = new object[] { DefaultViewModel["Instances"], DefaultViewModel["FilteredInstances"] }; var t = new Task((c) => { var context = c as object[]; var a = _resourceType.DataProvider.GetResources(_resourceType); Task.WaitAll(a); var b = a.Result; HomePage.UiThreadDispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () => { LoadingMessageTextBlock.Visibility = Visibility.Collapsed; foreach (var rt in a.Result) { (context[0] as ObservableCollection<Resource>).Add(rt); (context[1] as ObservableCollection<Resource>).Add(rt); } }); }, ctx); t.Start(); LoadingMessageTextBlock.Visibility = Visibility.Visible; LoadingMessageTextBlock.Text = "Loading..."; } }
public Resource(IProvider provider, ResourceType type) { DataProvider = provider; Type = type; // Image = new Uri("http://www.brightstardb.com/images/logo.png"; }
public async Task<List<Resource>> GetResources(Uri collectionUri, ResourceType type) { var entries = DataCache.Instance.Lookup<SyndicationFeed>(collectionUri.AbsoluteUri); if (entries == null) { AtomPubClient client = new AtomPubClient(); entries = await client.RetrieveFeedAsync(collectionUri); DataCache.Instance.Cache(collectionUri.AbsoluteUri, entries); } var resources = new List<Resource>(); var resourceIndex = new Dictionary<string, Resource>(); foreach (var entry in entries.Items) { var resource = new Resource(this, type); resource.Identity = new Uri(entry.Id); resource.Title = entry.Title.Text; resources.Add(resource); } // check for a link to more entries var nextLink = entries.Links.FirstOrDefault(l => l.Relationship.Equals("next")); if (nextLink != null) { var nextResourceType = new ResourceType(this); nextResourceType.Identity = new Uri("http://www.brightstardb.com/databrowser/core/next"); var nextResource = new Resource(this, nextResourceType); nextResource.Identity = nextLink.Uri; nextResource.Title = "More..."; resources.Add(nextResource); } return resources; }
private void LoadQueriedState(Uri query, ResourceType type) { ((ObservableCollection<Resource>)DefaultViewModel["Instances"]).Clear(); ((ObservableCollection<Resource>)DefaultViewModel["FilteredInstances"]).Clear(); var ctx = new object[] { DefaultViewModel["Instances"], DefaultViewModel["FilteredInstances"] }; var t = new Task((c) => { var context = c as object[]; var a = _resourceType.DataProvider.GetResources(query, _resourceType); Task.WaitAll(a); var b = a.Result; HomePage.UiThreadDispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () => { LoadingMessageTextBlock.Visibility = Visibility.Collapsed; foreach (var rt in a.Result) { (context[0] as ObservableCollection<Resource>).Add(rt); (context[1] as ObservableCollection<Resource>).Add(rt); } }); }, ctx); t.Start(); LoadingMessageTextBlock.Visibility = Visibility.Visible; LoadingMessageTextBlock.Text = "Loading..."; }
public async Task<List<ResourceType>> GetResourceTypes() { try { // read service document var client = new AtomPubClient(); var serviceDoc = await client.RetrieveServiceDocumentAsync(new Uri(_endpoint)); // get workspace 0 var workspace = serviceDoc.Workspaces[0]; // get collections list var resourceTypes = new List<ResourceType>(); foreach (var collection in workspace.Collections) { var rt = new ResourceType(this); rt.Identity = collection.Uri; rt.Title = collection.Title.Text; // check for type annotations var collectionName = collection.NodeValue; if (collectionName != null) { // get type name from collection name string typeName; if (!_collectionToTypeMappings.TryGetValue(collectionName, out typeName)) { continue; } // get type annotations var annotations = _annotations.Where(a => a.Target.Equals(typeName)).ToList(); if (annotations.Count > 0) { // see if we should hide the type var hideAnnotation = annotations.FirstOrDefault(a => a.Property.Equals(Annotation.Hide)); if (hideAnnotation != null && hideAnnotation.Value.Equals("True")) { continue; } // try and get a display name var displayNameAnnotation = annotations.FirstOrDefault(a => a.Property.Equals(Annotation.DisplayName)); if (displayNameAnnotation != null) { rt.Title = displayNameAnnotation.Value; } // try and get an image var imageAnnotation = annotations.FirstOrDefault(a => a.Property.Equals(Annotation.ThumbnailUrl)); if (imageAnnotation != null && Uri.IsWellFormedUriString(imageAnnotation.Value, UriKind.Absolute)) { rt.Image = new Uri(imageAnnotation.Value); } } } resourceTypes.Add(rt); } return resourceTypes; } catch(Exception ex) { return new List<ResourceType>(); } }