Ejemplo 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);
        }
Ejemplo 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);
        }
Ejemplo n.º 3
0
        /*
         * public void QueueNewResourceEntry(string collection, string id, ResourceEntry entry)
         * {
         *  if (collection == null) throw new ArgumentNullException("collection");
         *  if (id == null) throw new ArgumentNullException("resource");
         *
         *  QueueNewResourceEntry(ResourceIdentity.Build(_endpoint, collection, id), entry);
         * }
         */

        public void EnqueueDelete(Uri key)
        {
            if (key == null)
            {
                throw new ArgumentNullException("id");
            }

            var newEntry = BundleEntryFactory.CreateNewDeletedEntry(key);

            queue.Enqueue(newEntry);
        }
Ejemplo n.º 4
0
        public void QueueNewDeletedEntry(Uri id)
        {
            if (id == null)
            {
                throw new ArgumentNullException("id");
            }
            if (!id.IsAbsoluteUri)
            {
                throw new ArgumentException("Uri for new resource must be absolute");
            }

            var newEntry = BundleEntryFactory.CreateNewDeletedEntry(id);

            queue.Add(newEntry);
        }
Ejemplo n.º 5
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));
        }
Ejemplo n.º 6
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));
        }
Ejemplo n.º 7
0
        public void QueueNewResourceEntry(Uri id, ResourceEntry entry)
        {
            if (id == null)
            {
                throw new ArgumentNullException("id");
            }
            if (!id.IsAbsoluteUri)
            {
                throw new ArgumentException("Uri for new resource must be absolute");
            }

            var location = new ResourceIdentity(id);
            var title    = String.Format("{0} resource with id {1}", location.Collection, location.Id);


            var newEntry = BundleEntryFactory.CreateFromResource(entry.Resource, id, DateTimeOffset.Now, title);

            newEntry.Tags = entry.Tags;
            queue.Add(newEntry);
        }
Ejemplo n.º 8
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));
        }