Hi Jim,
I Create plug-in to handle ResponseFromServerReceived event, using the your code. Its build and initialized OK when I set Plug-in Path, but its not doing anything. I was trying to debug and it would not attached to the process
with an arror: The breakpoint will not currently be hit. No symbols have been loaded for this document
Please let me know what I doing wrong.
Thanks
Alex
Here is my plug- code:
Imports System
Imports System.Collections.Generic
Imports System.Text
Imports Keyoti.SearchEngine.Events
Imports Keyoti.SearchEngine
Imports Keyoti.SearchEngine.Documents
Imports Keyoti.SearchEngine.DataAccess
Imports Keyoti.SearchEngine.DataAccess.IndexableSourceRecords
Public Class ExternalEventHandler
Private dispatcher As IEventDispatcher
Private conf As Configuration
Public lastResponseURI As Uri
Public lastResponseLastModified As DateTime
''' <summary>
''' New, attaches event handlers.
''' </summary>
''' <param name="dispatcher">The object which fires events that this plug-in handles.</param>
''' <param name="conf">The engine configuration.</param>
Public Sub New(ByVal dispatcher As IEventDispatcher, ByVal conf As Configuration)
MyBase.New()
DataAccess.Log.WriteLogEntry("Plug-in Template Project", "Initialized", conf)
'AddHandler dispatcher.Action, AddressOf Me.dispatcher_Action
AddHandler dispatcher.Action, AddressOf Me.CentralEventDispatcher_Action
AddHandler dispatcher.NeedObject, AddressOf Me.dispatcher_NeedObject
Me.dispatcher = dispatcher
Me.conf = conf
End Sub
''' <summary>
''' Removes the handlers, so that the object can be disposed of.
''' </summary>
''' <remarks>This is called when the DLL is unloaded.</remarks>
Public Sub DetachHandlers()
If (Not (dispatcher) Is Nothing) Then
'RemoveHandler dispatcher.Action, AddressOf Me.dispatcher_Action
RemoveHandler dispatcher.Action, AddressOf Me.CentralEventDispatcher_Action
RemoveHandler dispatcher.NeedObject, AddressOf Me.dispatcher_NeedObject
End If
End Sub
''' <summary>
''' Handles ACTION events. This method is called as the engine performs various actions.
''' </summary>
Public Sub dispatcher_Action(ByVal sender As Object, ByVal e As ActionEventArgs)
'Log everything - comment this line after debugging to optimize speed.
DataAccess.Log.WriteLogEntry("Plug-in Template Project", e.ActionData.Name.ToString, conf)
Dim document As Document
Dim documentRecord As DocumentRecord
Dim word As Word
Try
Select Case (e.ActionData.Name)
Case ActionName.ReadingText
Dim documentText As DocumentText = CType(e.ActionData.Data, DocumentText)
documentText.AppendText("append some test words zzz", conf)
documentText.PrependText("prepend some test words aaa", conf)
Case ActionName.AutoCompleteSuggestionsGenerated
Dim suggestionPairs As ArrayList = CType(e.ActionData.Data, ArrayList)
Dim helper As Keyoti.SearchEngine.Web.SearchBoxAutoCompleteHelper = CType(sender, Keyoti.SearchEngine.Web.SearchBoxAutoCompleteHelper)
Dim textEnteredByUser As String = helper.Query
Dim wordsInText() As String = helper.Segments
suggestionPairs.Add(New Keyoti.SearchEngine.Web.SearchBoxAutoCompleteHelper.SuggestionResultPair("testQuery", 99))
Case ActionName.DocumentBeingCrawled
document = CType(CType(e.ActionData.Data, Object())(0), Document)
Dim links As System.Collections.ArrayList = CType(CType(e.ActionData.Data, Object())(1), System.Collections.ArrayList)
Case ActionName.AutoAssignContent
documentRecord = CType(e.ActionData.Data, DocumentRecord)
Case ActionName.AutoAssignLocation
documentRecord = CType(e.ActionData.Data, DocumentRecord)
Case ActionName.AutoAssignSecurityGroup
documentRecord = CType(e.ActionData.Data, DocumentRecord)
Case ActionName.CalculateWordRelevancies
Dim words As WordCollection = CType(e.ActionData.Data, WordCollection)
document = CType(sender, Document)
If document.Uri.AbsolutePath.Contains("/important/") Then
For Each word2 As Word In words
word2.Weight = (word2.Weight * 2)
'boost the weight of all words by 2, if they're in the /important/ subdir.
Next
End If
Case ActionName.GetWordVariations
word = CType(CType(e.ActionData.Data, Object())(0), Word)
Dim variations As System.Collections.ArrayList = CType(CType(e.ActionData.Data, Object())(1), System.Collections.ArrayList)
If (word.WordContent = "test") Then
variations.Add("testword")
End If
'make the engine look for 'testword' as well, whenever 'test' is searched for.
Case ActionName.ImportStarted
Dim sourceRecord As IndexableSourceRecord = CType(e.ActionData.Data, IndexableSourceRecord)
Case ActionName.ImportFinished
If (TypeOf e.ActionData.Data Is Exception) Then
'something went wrong with the import
Dim exception As String = CType(e.ActionData.Data, Exception).Message
Else
'import was successful
Dim uris As ArrayList = CType(e.ActionData.Data, ArrayList)
For Each importedItem As Uri In uris
Next
End If
Case ActionName.IsDocumentToBeCrawled
Dim data As IsDocumentToBeCrawledEventData = CType(e.ActionData.Data, IsDocumentToBeCrawledEventData)
Dim doc As Document = data.Document
'use some logic to determine if 'data.WillCrawl' should be set to false, which will prevent the document from being crawled.
Case ActionName.IsDocumentToBeIndexed
Dim indexData As IsDocumentToBeIndexedEventData = CType(e.ActionData.Data, IsDocumentToBeIndexedEventData)
document = indexData.Document
'Use some logic to determine if 'indexData.WillIndex' should be set to false, which will prevent the document from being indexed.
Case ActionName.RequestingUri
Dim request As System.Net.HttpWebRequest = CType(e.ActionData.Data, System.Net.HttpWebRequest)
'Change any properties in request as needed.
Case ActionName.ResponseFromServerReceived
Dim response As System.Net.HttpWebResponse = CType(e.ActionData.Data, System.Net.HttpWebResponse)
'Process as needed
Case ActionName.ResultPreviewTextLoaded
Dim documentPreviewText As StringBuilder = CType(e.ActionData.Data, StringBuilder)
Dim uri As String = CType(sender, Keyoti.SearchEngine.Web.SearchResultPreviewHelper).Uri
'Change the document text, to put the Uri at the start of the text.
'Remember that if you reassign documentPreviewText to a new object, it will not be used by the previewer.
documentPreviewText.Insert(0, ("Document URL::" _
+ (uri + "" & vbCrLf & vbCrLf)))
End Select
Catch ex As Exception
DataAccess.Log.WriteLogEntry("Plug-in Template Project", "Exception occurred: " & ex.ToString, conf)
End Try
End Sub
''' <summary>
''' Handles need object events. This method is called as the engine requires new instances of various classes.
''' </summary>
Public Sub dispatcher_NeedObject(ByVal sender As Object, ByVal e As NeedObjectEventArgs)
'leave blank unless needed, to use default objects.
End Sub
Public Sub CentralEventDispatcher_Action(ByVal sender As Object, ByVal e As ActionEventArgs)
Try
If e.ActionData.Name = ActionName.ResponseFromServerReceived Then
lastResponseURI = CType(e.ActionData.Data, Net.HttpWebResponse).ResponseUri
lastResponseLastModified = (CType(e.ActionData.Data, Net.HttpWebResponse)).LastModified
End If
If e.ActionData.Name = ActionName.ReadText Then
If lastResponseURI = CType(sender, Document).Uri Then
CType(e.ActionData.Data, DocumentText).MetaCustomData = lastResponseLastModified.ToShortDateString()
End If
End If
Catch ex As Exception
End Try
End Sub
End Class
ag
ag