Esempio n. 1
0
        // 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 resultBundle =
                BundleEntryFactory.CreateBundleWithEntries(snapshot.FeedTitle, new Uri(snapshot.FeedSelfLink),
                                                           "Spark MatchBox Search Engine", null, pageContents);

            if (snapshot.MatchCount != Snapshot.NOCOUNT)
            {
                resultBundle.TotalResults = snapshot.MatchCount;
            }
            else
            {
                resultBundle.TotalResults = null;
            }

            // If we need paging, add the paging links
            if (snapshot.Contents.Count() > count)
            {
                buildLinks(resultBundle, snapshot.Id, start, count, resultBundle.TotalResults.Value);
            }

            return(resultBundle);
        }
Esempio n. 2
0
        private Bundle loadExamples()
        {
            var examples = new Spark.Support.ExampleImporter();

            examples.ImportZip(Settings.ExamplesFile);

            var batch = BundleEntryFactory.CreateBundleWithEntries("Imported examples", _service.Endpoint, "ExampleImporter", null);

            foreach (var resourceName in ModelInfo.SupportedResources)
            {
                //var key = resourceName.ToLower(); //  the importedEntry keys are no longer in lower // 2013.12.21 mh
                var key = resourceName;
                if (examples.ImportedEntries.ContainsKey(key))
                {
                    var exampleEntries = examples.ImportedEntries[key];

                    foreach (var exampleEntry in exampleEntries)
                    {
                        batch.Entries.Add(exampleEntry);
                    }
                }
            }

            return(batch);
        }
Esempio n. 3
0
        public Bundle History(string collection, DateTimeOffset?since)
        {
            RequestValidator.ValidateCollectionName(collection);
            if (since == null)
            {
                since = DateTimeOffset.MinValue;
            }
            string  title = String.Format("Full server-wide history for updates since {0}", since);
            RestUrl self  = new RestUrl(this.Endpoint).AddPath(collection, RestOperation.HISTORY);

            IEnumerable <BundleEntry> entries = _store.ListVersionsInCollection(collection, since, Const.MAX_HISTORY_RESULT_SIZE);
            Bundle bundle = BundleEntryFactory.CreateBundleWithEntries(title, self.Uri, Const.AUTHOR, Settings.AuthorUri, entries);

            return(exportPagedBundle(bundle));
        }
Esempio n. 4
0
        public Bundle History(DateTimeOffset?since)
        {
            if (since == null)
            {
                since = DateTimeOffset.MinValue;
            }
            string  title = String.Format("Full server-wide history for updates since {0}", since);
            RestUrl self  = new RestUrl(this.Endpoint).AddPath(RestOperation.HISTORY);

            IEnumerable <BundleEntry> entries = _store.ListVersions(since, Const.MAX_HISTORY_RESULT_SIZE);

            Snapshot.Create(title, self.Uri, entries, Snapshot.NOCOUNT);
            Bundle bundle = BundleEntryFactory.CreateBundleWithEntries(title, Endpoint, Const.AUTHOR, Settings.AuthorUri, entries);

            return(exportPagedBundle(bundle));
        }
Esempio n. 5
0
        public Bundle History(string collection, string id, DateTimeOffset?since)
        {
            RequestValidator.ValidateCollectionName(collection);
            RequestValidator.ValidateId(id);

            if (since == null)
            {
                since = DateTimeOffset.MinValue;
            }
            string  title = String.Format("History for updates on '{0}' resource '{1}' since {2}", collection, id, since);
            RestUrl self  = new RestUrl(this.Endpoint).AddPath(collection, id, RestOperation.HISTORY);

            if (!entryExists(collection, id))
            {
                throw new SparkException(HttpStatusCode.NotFound, "There is no history because there is no {0} resource with id {1}.", collection, id);
            }

            var identity = ResourceIdentity.Build(collection, id).OperationPath;
            IEnumerable <BundleEntry> entries = _store.ListVersionsById(identity, since, Const.MAX_HISTORY_RESULT_SIZE);
            Bundle bundle = BundleEntryFactory.CreateBundleWithEntries(title, self.Uri, Const.AUTHOR, Settings.AuthorUri, entries);

            return(exportPagedBundle(bundle));
        }