Example #1
0
        public CrawlPlan(LocalManifest localManifest, RemoteManifest remoteManifest, RemoteDataAccess dao)
        {
            Debug.Assert (localManifest != null);
            Debug.Assert (remoteManifest != null);
            Debug.Assert (dao != null);

            this.dao = dao;

            // Clone the local manifest, because we need to make changes to this copy
            BuildCrawlPlan (localManifest.Clone (), remoteManifest);
        }
        public AccountSyncStateStore(
			DeliciousRequester requester,
			RemoteDataAccess remoteDao,
			DeliciousQueryable queryable)
        {
            Debug.Assert (requester != null);
            Debug.Assert (remoteDao != null);
            Debug.Assert (queryable != null);

            this.requester = requester;
            this.remoteDao = remoteDao;
            this.queryable = queryable;
        }
        CrawlingIndexableGenerator BuildIndexableGenerator()
        {
            Debug.Assert (account.IsValid);

            Log.Info ("Beginning sync for " + account.Username);

            // Create some common services
            DeliciousRequester requester = new DeliciousRequester (account);
            RemoteDataAccess remoteDao = new RemoteDataAccess (requester);

            // Load the sync state
            AccountSyncStateStore store = new AccountSyncStateStore (requester, remoteDao, queryable);
            AccountSyncState syncState = null;

            try
            {
                syncState = store.LoadSyncState ();
            }
            catch (DeliciousUnavailableException e)
            {
                Log.Warn (e.ToString());
                return null;
            }
            catch (Exception e)
            {
                Log.Error (e, "Error loading sync state");
                return null;
            }

            if (! syncState.ShouldCrawl ())
            {
                Log.Info ("Skipping crawl");
                return null;
            }

            // Build the crawl plan
            CrawlPlan crawlPlan = new CrawlPlan(
                syncState.LocalManifest,
                syncState.RemoteManifest,
                remoteDao);

            // Build indexables from the steps of the crawl plan
            IndexableBuilder indexableBuilder = new IndexableBuilder (requester);

            // Update the sync state's local manifest as bookmarks are indexed
            ManifestChangeTracker changeTracker = new ManifestChangeTracker (syncState.LocalManifest);

            // Create the indexable generator that will execute the crawl plan
            CrawlingIndexableGenerator indexableGenerator = new CrawlingIndexableGenerator(
                crawlPlan,
                indexableBuilder,
                changeTracker);

            // After the crawl is done, we'll need to save the sync state,
            // and set up another scheduled crawl
            indexableGenerator.FinishedCrawl +=()=> SaveStateAndReschedule (syncState, store, crawlPlan);

            return indexableGenerator;
        }