예제 #1
0
        protected override CrawlerQueueEntry PopImpl()
        {
            return(m_EsentInstance.Cursor((session, dbid) =>
            {
                using (Transaction transaction = new Transaction(session))
                {
                    using (Table table = new Table(session, dbid, EsentTableDefinitions.QueueTableName, OpenTableGrbit.None))
                    {
                        if (Api.TryMoveFirst(session, table))
                        {
                            var data = Api.RetrieveColumnAsString(session, table, dataColumn.columnid, Encoding.Unicode);
                            Api.JetDelete(session, table);

                            using (Table table2 = new Table(session, dbid, EsentTableDefinitions.GlobalsTableName, OpenTableGrbit.None))
                            {
                                Api.EscrowUpdate(session, table2, queueCountColumn.columnid, -1);
                            }

                            transaction.Commit(CommitTransactionGrbit.None);
                            return data.FromJson <CrawlerQueueEntry>();
                        }
                    }

                    transaction.Rollback();
                    return null;
                }
            }));
        }
        public EsentCrawlQueueService(Uri baseUri, bool resume)
        {
            m_DatabaseFileName = Path.GetFullPath("NCrawlQueue{0}\\Queue.edb".FormatWith(baseUri.GetHashCode()));

            if (!resume && File.Exists(m_DatabaseFileName))
            {
                ClearQueue();
            }

            m_EsentInstance = new EsentInstance(m_DatabaseFileName, (session, dbid) =>
                {
                    EsentTableDefinitions.CreateGlobalsTable(session, dbid);
                    EsentTableDefinitions.CreateQueueTable(session, dbid);
                });

            // Get columns
            m_EsentInstance.Cursor((session, dbid) =>
                {
                    Api.JetGetColumnInfo(session, dbid, EsentTableDefinitions.GlobalsTableName,
                        EsentTableDefinitions.GlobalsCountColumnName,
                        out queueCountColumn);
                    Api.JetGetColumnInfo(session, dbid, EsentTableDefinitions.QueueTableName,
                        EsentTableDefinitions.QueueTableDataColumnName,
                        out dataColumn);
                });
        }
		public EsentCrawlerHistoryService(Uri baseUri, bool resume)
		{
			m_Resume = resume;
			m_DatabaseFileName = Path.GetFullPath("NCrawlHist{0}\\Hist.edb".FormatWith(baseUri.GetHashCode()));

			if (!resume)
			{
				ClearHistory();
			}

			m_EsentInstance = new EsentInstance(m_DatabaseFileName, (session, dbid) =>
				{
					EsentTableDefinitions.CreateGlobalsTable(session, dbid);
					EsentTableDefinitions.CreateHistoryTable(session, dbid);
				});

			// Get columns
			m_EsentInstance.Cursor((session, dbid) =>
				{
					Api.JetGetColumnInfo(session, dbid, EsentTableDefinitions.GlobalsTableName,
						EsentTableDefinitions.GlobalsCountColumnName, out historyCountColumn);
					Api.JetGetColumnInfo(session, dbid, EsentTableDefinitions.HistoryTableName,
						EsentTableDefinitions.HistoryTableUrlColumnName, out historyUrlColumn);
				});
		}
예제 #4
0
        public EsentCrawlQueueService(Uri baseUri, bool resume)
        {
            m_DatabaseFileName = Path.GetFullPath("NCrawlQueue{0}\\Queue.edb".FormatWith(baseUri.GetHashCode()));

            if (!resume && File.Exists(m_DatabaseFileName))
            {
                ClearQueue();
            }

            m_EsentInstance = new EsentInstance(m_DatabaseFileName, (session, dbid) =>
            {
                EsentTableDefinitions.CreateGlobalsTable(session, dbid);
                EsentTableDefinitions.CreateQueueTable(session, dbid);
            });

            // Get columns
            m_EsentInstance.Cursor((session, dbid) =>
            {
                Api.JetGetColumnInfo(session, dbid, EsentTableDefinitions.GlobalsTableName,
                                     EsentTableDefinitions.GlobalsCountColumnName,
                                     out queueCountColumn);
                Api.JetGetColumnInfo(session, dbid, EsentTableDefinitions.QueueTableName,
                                     EsentTableDefinitions.QueueTableDataColumnName,
                                     out dataColumn);
            });
        }
예제 #5
0
        public EsentCrawlerHistoryService(Uri baseUri, bool resume)
        {
            m_Resume           = resume;
            m_DatabaseFileName = Path.GetFullPath("NCrawlHist{0}\\Hist.edb".FormatWith(baseUri.GetHashCode()));

            if (!resume)
            {
                ClearHistory();
            }

            m_EsentInstance = new EsentInstance(m_DatabaseFileName, (session, dbid) =>
            {
                EsentTableDefinitions.CreateGlobalsTable(session, dbid);
                EsentTableDefinitions.CreateHistoryTable(session, dbid);
            });

            // Get columns
            m_EsentInstance.Cursor((session, dbid) =>
            {
                Api.JetGetColumnInfo(session, dbid, EsentTableDefinitions.GlobalsTableName,
                                     EsentTableDefinitions.GlobalsCountColumnName, out historyCountColumn);
                Api.JetGetColumnInfo(session, dbid, EsentTableDefinitions.HistoryTableName,
                                     EsentTableDefinitions.HistoryTableUrlColumnName, out historyUrlColumn);
            });
        }
예제 #6
0
        protected override void Add(string key)
        {
            m_EsentInstance.Cursor((session, dbid) =>
            {
                using (Transaction transaction = new Transaction(session))
                {
                    using (Table table = new Table(session, dbid, EsentTableDefinitions.HistoryTableName, OpenTableGrbit.None))
                    {
                        using (Update update = new Update(session, table, JET_prep.Insert))
                        {
                            Api.SetColumn(session, table, historyUrlColumn.columnid, key, Encoding.Unicode);
                            update.Save();
                        }
                    }

                    using (Table table = new Table(session, dbid, EsentTableDefinitions.GlobalsTableName, OpenTableGrbit.None))
                    {
                        Api.EscrowUpdate(session, table, historyCountColumn.columnid, 1);
                    }

                    transaction.Commit(CommitTransactionGrbit.None);
                }
            });
        }