示例#1
0
文件: Pager.cs 项目: TonyAbell/spark
        public Bundle FirstPage(Snapshot snapshot, int count)
        {
            _store.StoreSnapshot(snapshot);

            // Return the first page
            return GetPage(snapshot.Id, 0, count);
        }
示例#2
0
 public static Snapshot Create(string title, Uri selflink, ICollection<string> includes, IEnumerable<Uri> keys, int matchCount)
 {
     Snapshot snapshot = new Snapshot();
     snapshot.Id = Guid.NewGuid().ToString();
     snapshot.FeedTitle = title;
     snapshot.FeedSelfLink = selflink.ToString(); // todo: moet FeedSelfLink geen Uri zijn? - yes. possible.
     snapshot.Includes = includes;
     snapshot.Contents = keys;
     snapshot.MatchCount = (matchCount == 0) ? keys.Count() : matchCount;
     return snapshot;
 }
示例#3
0
 public static Snapshot TakeSnapshotFromBundle(Bundle bundle)
 {
     // Is Snapshot not a type of bundle???
     Snapshot snapshot = new Snapshot();
     snapshot.FeedTitle = bundle.Title;
     snapshot.Id = Guid.NewGuid().ToString();
     snapshot.FeedSelfLink = bundle.Links.SelfLink.ToString();
     snapshot.Contents = bundle.SelfLinks();
     snapshot.MatchCount = snapshot.Contents.Count();
     return snapshot;
 }
示例#4
0
 public static Snapshot Create(string title, Uri selflink, IEnumerable<Uri> keys, string sortby, IEnumerable<string> includes = null)
 {
     Snapshot snapshot = new Snapshot();
     snapshot.Id = CreateKey();
     snapshot.WhenCreated = DateTimeOffset.UtcNow;
     snapshot.FeedTitle = title;
     snapshot.FeedSelfLink = selflink.ToString();
     snapshot.Includes = (includes != null) ? includes.ToList() : null;
     snapshot.Keys = keys;
     snapshot.Count = keys.Count();
     snapshot.SortBy = sortby;
     return snapshot;
 }
示例#5
0
文件: Pager.cs 项目: TonyAbell/spark
        public Bundle GetPage(Snapshot snapshot, int start, int pagesize)
        {
            if (pagesize > MAX_PAGE_SIZE) pagesize = MAX_PAGE_SIZE;

            if (snapshot == null)
                throw new SparkException(HttpStatusCode.NotFound, "There is no paged snapshot with id '{0}'", snapshot.Id);

            if (!snapshot.InRange(start))
            {
                throw new SparkException(HttpStatusCode.NotFound, 
                    "The specified index lies outside the range of available results ({0}) in snapshot {1}",
                    snapshot.Contents.Count(), snapshot.Id);
            }

            return createBundle(snapshot, start, pagesize);
        }
示例#6
0
文件: Pager.cs 项目: Ravenheart/spark
        public Bundle CreateBundle(Snapshot snapshot, int start, int count)
        {
            Bundle bundle = new Bundle();
            bundle.Title = snapshot.FeedTitle;
            bundle.TotalResults = snapshot.Count;
            bundle.Id = Key.NewUuid();
            bundle.AuthorName = "Furore Spark FHIR server";
            bundle.AuthorUri = "http://fhir.furore.com";

            bundle.Links = new UriLinkList();
            bundle.Links.SelfLink = new Uri(snapshot.FeedSelfLink);
            bundle.LastUpdated = snapshot.WhenCreated;

            IEnumerable<Uri> keys = snapshot.Keys.Skip(start).Take(count);
            bundle.Entries = store.Get(keys, snapshot.SortBy).ToList();
            Include(bundle, snapshot.Includes);
            buildLinks(bundle, snapshot, start, count);
            exporter.Externalize(bundle);
            return bundle;
        }
示例#7
0
文件: Pager.cs 项目: TonyAbell/spark
        // Given a set of version id's, go fetch a subset of them from the store and build a Bundle
        private Bundle createBundle(Snapshot snapshot, int start, int count)
        {
            var entryVersionIds = snapshot.Contents.Skip(start).Take(count).ToList();
            var pageContents = _store.FindByVersionIds(entryVersionIds).ToList();

            var bundle =
                BundleEntryFactory.CreateBundleWithEntries(snapshot.FeedTitle, new Uri(snapshot.FeedSelfLink),
                      "Spark MatchBox Search Engine", null, pageContents);

            if (snapshot.MatchCount != Snapshot.NOCOUNT)
                bundle.TotalResults = snapshot.MatchCount;
            else
                bundle.TotalResults = null;

            var total = snapshot.Contents.Count();

            // If we need paging, add the paging links
            if (total > count)
                buildLinks(bundle, snapshot.Id, start, count, total);

            return bundle;
        }
示例#8
0
 public void AddSnapshot(Snapshot snapshot)
 {
     var collection = database.GetCollection(Collection.SNAPSHOT);
     collection.Save<Snapshot>(snapshot);
 }
示例#9
0
 public void AddSnapshot(Snapshot snapshot)
 {
     throw new NotImplementedException();
 }
示例#10
0
 private Bundle exportPagedSnapshot(Snapshot snapshot, int pagesize = Const.DEFAULT_PAGE_SIZE)
 {
     Bundle result = pager.FirstPage(snapshot, pagesize);
     exporter.EnsureAbsoluteUris(result);
     return result;
 }
示例#11
0
文件: Pager.cs 项目: Ravenheart/spark
        // Given a set of version id's, go fetch a subset of them from the store and build a Bundle
        /*private Bundle createBundle(Snapshot snapshot, int start, int count)
        {
            var entryVersionIds = snapshot.Keys.Skip(start).Take(count).ToList();
            var pageContents = store.Get(entryVersionIds, snapshot.SortBy).ToList();

            var bundle =
                BundleEntryFactory.CreateBundleWithEntries(snapshot.FeedTitle, new Uri(snapshot.FeedSelfLink),
                      "Spark MatchBox Search Engine", null, pageContents);

            if (snapshot.Count != Snapshot.NOCOUNT)
                bundle.TotalResults = snapshot.Count;
            else
                bundle.TotalResults = null;

            var total = snapshot.Keys.Count();

            // If we need paging, add the paging links
            if (total > count)
                buildLinks(bundle, snapshot, start, count);

            return bundle;
        }
        */
        private static void buildLinks(Bundle bundle, Snapshot snapshot, int start, int count)
        {
            var lastPage = snapshot.Count / count;

            // http://spark.furore.com/fhir/_snapshot/

            Uri baseurl = new Uri(Settings.Endpoint.ToString() + "/" + FhirRestOp.SNAPSHOT);

            bundle.Links.SelfLink =
                baseurl
                .AddParam(FhirParameter.SNAPSHOT_ID, snapshot.Id)
                .AddParam(FhirParameter.SNAPSHOT_INDEX, start.ToString())
                .AddParam(FhirParameter.COUNT, count.ToString());

            // First
            bundle.Links.FirstLink =
                baseurl
                .AddParam(FhirParameter.SNAPSHOT_ID, snapshot.Id)
                .AddParam(FhirParameter.SNAPSHOT_INDEX, "0");

            // Last
            bundle.Links.LastLink =
                baseurl
                .AddParam(FhirParameter.SNAPSHOT_ID, snapshot.Id)
                .AddParam(FhirParameter.SNAPSHOT_INDEX, (lastPage * count).ToString());

            // Only do a Previous if we can go back
            if (start > 0)
            {
                int prevIndex = start - count;
                if (prevIndex < 0) prevIndex = 0;

                bundle.Links.PreviousLink =
                    baseurl
                    .AddParam(FhirParameter.SNAPSHOT_ID, snapshot.Id)
                    .AddParam(FhirParameter.SNAPSHOT_INDEX, prevIndex.ToString());
            }

            // Only do a Next if we can go forward
            if (start + count < snapshot.Count)
            {
                int nextIndex = start + count;

                bundle.Links.NextLink =
                    baseurl
                    .AddParam(FhirParameter.SNAPSHOT_ID, snapshot.Id)
                    .AddParam(FhirParameter.SNAPSHOT_INDEX, nextIndex.ToString());
            }
        }