コード例 #1
0
        void AQSubscriberWikiPostNew_OnMessageReceived(string message)
        {
            try
            {
                lock (_mqLock)
                {
                    StoreEventData(_activeMQSettings.TopicNameWikiPostNew, message);
                    IncreaseProcessedCount();

                    HtmlAgilityPack.XmlDocument xmlDoc = new HtmlAgilityPack.XmlDocument();
                    xmlDoc.LoadXml(message);

                    _keui.AnnotateWikiPost(xmlDoc);
                    int itemId = _keui.IndexWikiPost(xmlDoc);
                    if (itemId == -1)
                        StoreEventData(_activeMQSettings.TopicNameWikiPostNew, message, true, "invalid_");
                    UpdateEventMetaData(xmlDoc, _activeMQSettings.TopicNameKEUIPublishWikiPostNew);

                    // publish it
                    string annotatedMessage = xmlDoc.DocumentNode.OuterHtml;
                    StoreEventData(_activeMQSettings.TopicNameKEUIPublishWikiPostNew, annotatedMessage);
                    using (var publisher = new ActiveMqHelper.TopicPublisher(AQSession, _activeMQSettings.TopicNameKEUIPublishWikiPostNew))
                    {
                        publisher.SendMessage(annotatedMessage);
                    }
                }
            }
            catch (Exception ex)
            {
                AddEvent("Exception while processing new wiki post: " + ex.Message);
                GenLib.Log.LogService.LogException("Exception while processing new wiki post. message: " + message, ex);
            }
        }
コード例 #2
0
        void AQSubscriberKEUIRequest_OnMessageReceived(string message)
        {
            try
            {
                lock (_mqLock)
                {
                    AddEvent("Received KEUI Request " + GetDateStamp());
                    StoreEventData(_activeMQSettings.TopicNameKEUIRequest, message);

                    HtmlAgilityPack.XmlDocument xmlDoc = new HtmlAgilityPack.XmlDocument();
                    xmlDoc.LoadXml(message);
                    var eventDataNode = xmlDoc.DocumentNode.SelectSingleNode("//ns1:eventData");
                    var requestNode = xmlDoc.DocumentNode.SelectSingleNode("//ns1:eventData/s1:keuiRequest");
                    if (requestNode == null) { AddEventAndLog("The KEUI request event did not contain //ns1:eventData/s1:keuiRequest node. Ignoring request"); return; }

                    string requestType = requestNode.SelectSingleNode("./s1:requestType").InnerText;
                    string publishTopic = requestNode.SelectSingleNode("./s1:publishResponseOnTopic") != null ? requestNode.SelectSingleNode("./s1:publishResponseOnTopic").InnerText.DecodeXMLString() : _activeMQSettings.TopicNameKEUIPublishResponse;

                    string keuiResponseData = null;

                    requestType = requestType.Trim();	// make sure we ignore the newlines and spaces
                    AddEvent("Request type: " + requestType);
                    if (requestType == "GetSuggestions")
                    {
                        var queryNode = requestNode.SelectSingleNode("./s1:requestData/query");
                        string prefix = queryNode.GetAttributeValue("prefix", "");
                        string suggestionTypes = queryNode.GetAttributeValue("suggestionTypes", "");
                        suggestionTypes = suggestionTypes.ToLower();

                        if (string.IsNullOrEmpty(prefix))
                        {
                            AddEventAndLog("Unable to provide suggestions. No prefix was specified in the event.");
                            return;
                        }
                        prefix = GenLib.Text.Text.ReplaceUnicodeCharsWithAscii(prefix);
                        keuiResponseData = "<suggestions>";
                        if (string.IsNullOrEmpty(suggestionTypes) || suggestionTypes.Contains("concepts"))
                        {
                            List<Tuple<string, string>> suggestionsConcepts = _keui.SuggestConceptsForPrefix(prefix);
                            foreach (var sugg in suggestionsConcepts)
                                keuiResponseData += String.Format("<concept label=\"{0}\" uri=\"{1}\" />", sugg.Item1.EncodeXMLString(), sugg.Item2.EncodeXMLString());
                        }
                        if (string.IsNullOrEmpty(suggestionTypes) || suggestionTypes.Contains("people"))
                        {
                            List<int> suggestionsPeople = _keui.SuggestPeopleForPrefix(prefix);
                            foreach (var personId in suggestionsPeople)
                            {
                                var personInfo = _keui.PeopleData.GetPerson(personId);
                                var accountIds = personInfo.GetAccountIds().ToList();
                                string account = "";
                                if (accountIds.Count > 0)
                                    account = _keui.PeopleData.GetAccount(accountIds[0]);
                                string name = _keui.GetSuggestedPersonName(personInfo.PersonId);
                                keuiResponseData += String.Format("<person name=\"{0}\" account=\"{1}\" uuid=\"{2}\" />", name.EncodeXMLString(), account.EncodeXMLString(), personInfo.CustomData.EncodeXMLString());
                            }
                        }
                        if (string.IsNullOrEmpty(suggestionTypes) || suggestionTypes.Contains("products")) {
                            foreach (var sugg in _keui.SuggestProductsForPrefix(prefix))
                                keuiResponseData += String.Format("<product label=\"{0}\" uri=\"{1}\" />", sugg.Item1.EncodeXMLString(), sugg.Item2.EncodeXMLString());
                        }
                        if (string.IsNullOrEmpty(suggestionTypes) || suggestionTypes.Contains("issues")) {
                            foreach (var sugg in _keui.SuggestIssuesForPrefix(prefix))
                                keuiResponseData += String.Format("<issue label=\"{0}\" uri=\"{1}\" />", sugg.Item1.EncodeXMLString(), sugg.Item2.EncodeXMLString());
                        }
                        if (string.IsNullOrEmpty(suggestionTypes) || suggestionTypes.Contains("sources"))
                        {
                            foreach (int fileTag in _keui.SuggestFilesForPrefix(prefix)) {
                                string fileName = _keui.MailData.GetTagName(fileTag);
                                string fileUri = _keui.MailData.GetTagIdStr(fileTag);
                                fileUri = _keui.MakeUriLong(fileUri);
                                keuiResponseData += String.Format("<file name=\"{0}\" uri=\"{1}\" tooltip=\"{2}\" />", fileName.EncodeXMLString(), fileUri.EncodeXMLString(), fileName.EncodeXMLString());
                            }
                            foreach (int moduleTag in _keui.SuggestModulesForPrefix(prefix)) {
                                int fileTag = _keui.MailData.GetParentTagId(moduleTag);
                                string fileName = fileTag != TagInfoBase.InvalidTagId ? _keui.MailData.GetTagName(fileTag) : "";
                                string moduleUri = _keui.MailData.GetTagIdStr(moduleTag);
                                moduleUri = _keui.MakeUriLong(moduleUri);
                                keuiResponseData += String.Format("<module name=\"{0}\" uri=\"{1}\" tooltip=\"{2}\" />", _keui.MailData.GetTagName(moduleTag).EncodeXMLString(), moduleUri.EncodeXMLString(), fileName.EncodeXMLString());
                            }
                            foreach (int methodTag in _keui.SuggestMethodsForPrefix(prefix)) {
                                int moduleTag = _keui.MailData.GetParentTagId(methodTag);
                                int fileTag = moduleTag != TagInfoBase.InvalidTagId ? _keui.MailData.GetParentTagId(moduleTag) : TagInfoBase.InvalidTagId;
                                string fileName = fileTag != TagInfoBase.InvalidTagId ? _keui.MailData.GetTagName(fileTag) : "";
                                string methodUri = _keui.MailData.GetTagIdStr(methodTag);
                                methodUri = _keui.MakeUriLong(methodUri);
                                keuiResponseData += String.Format("<method name=\"{0}\" uri=\"{1}\" tooltip=\"{2}\" />", _keui.MailData.GetTagName(methodTag).EncodeXMLString(), methodUri.EncodeXMLString(), fileName.EncodeXMLString());
                            }
                        }
                        keuiResponseData += "</suggestions>";
                    }
                    else if (requestType == "GetAnnotationOntologyRDF")
                    {
                        var queryNode = requestNode.SelectSingleNode("./s1:requestData/query");
                        bool includeComment = queryNode != null && (queryNode.GetAttributeValue("includeComment", 0) == 1);
                        bool includeLinksTo = queryNode != null && (queryNode.GetAttributeValue("includeLinksTo", 0) == 1);
                        keuiResponseData = _keui.GetAnnotationOntologyRDF(includeComment, includeLinksTo);
                        AddEvent("Returning Annotation Ontology RDF. Data contains " + (int)(keuiResponseData.Length / 1024) + "KB");
                    }
                    else
                        keuiResponseData = _keui.ProcessKEUIRequest(xmlDoc, requestType);

                    if (keuiResponseData == null) return;

                    // update the event name
                    UpdateEventMetaData(xmlDoc, _activeMQSettings.TopicNameKEUIPublishResponse);

                    // insert the return data
                    _keui.AddNewLines(eventDataNode, 8);
                    eventDataNode.AppendChild(xmlDoc.CreateTextNode(String.Format("<s1:keuiResponse>{0}</s1:keuiResponse>", keuiResponseData)));

                    string returnEvent = xmlDoc.DocumentNode.OuterHtml;

                    // publish it
                    StoreEventData(publishTopic, returnEvent);
                    using (var publisher = new ActiveMqHelper.TopicPublisher(AQSession, publishTopic))
                    {
                        publisher.SendMessage(returnEvent);
                    }
                    AddEvent("KEUI successfully published KEUI Response event on topic " + publishTopic);
                }
            }
            //catch (Apache.NMS.ActiveMQ.IOException ioe)
            //{
            //    DisposeActiveMQ();
            //    InitActiveMQ();
            //}
            catch (Exception ex)
            {
                AddEvent("Exception while processing KEUI request: " + ex.Message);
                GenLib.Log.LogService.LogException("Exception while processing KEUI request. message: " + message, ex);
            }
        }
コード例 #3
0
        void AQSubscriberTextToAnnotate_OnMessageReceived(string message)
        {
            try
            {
                lock (_mqLock)
                {
                    StoreEventData(_activeMQSettings.TopicNameTextToAnnotate, message);
                    IncreaseProcessedCount();

                    HtmlAgilityPack.XmlDocument xmlDoc = new HtmlAgilityPack.XmlDocument();
                    xmlDoc.LoadXml(message);

                    _keui.AnnotateTextToAnnotate(xmlDoc);
                    UpdateEventMetaData(xmlDoc, _activeMQSettings.TopicNameKEUIPublishTextToAnnotate);

                    // publish it
                    string annotatedMessage = xmlDoc.DocumentNode.OuterHtml;
                    StoreEventData(_activeMQSettings.TopicNameKEUIPublishTextToAnnotate, annotatedMessage);
                    using (var AQPublisherTextToAnnotate = new ActiveMqHelper.TopicPublisher(AQSession, _activeMQSettings.TopicNameKEUIPublishTextToAnnotate))
                    {
                        AQPublisherTextToAnnotate.SendMessage(annotatedMessage);
                    }
                }
            }
            catch (Exception ex)
            {
                AddEvent("Exception while annotating general text: " + ex.Message);
                GenLib.Log.LogService.LogException("Exception while annotating general text. message: " + message, ex);
            }
        }
コード例 #4
0
        void AQSubscriberIssueUpdate_OnMessageReceived(string message)
        {
            try
            {
                lock (_mqLock)
                {
                    StoreEventData(_activeMQSettings.TopicNameIssueUpdate, message);
                    IncreaseProcessedCount();

                    HtmlAgilityPack.XmlDocument xmlDoc = new HtmlAgilityPack.XmlDocument();
                    xmlDoc.LoadXml(message);

                    _keui.AnnotateIssueUpdate(xmlDoc);
                    bool ok = _keui.IndexIssueUpdate(xmlDoc);
                    if (!ok)
                        StoreEventData(_activeMQSettings.TopicNameIssueUpdate, message, true, "invalid_");
                    UpdateEventMetaData(xmlDoc, _activeMQSettings.TopicNameKEUIPublishBugComment);

                    // publish it
                    string annotatedMessage = xmlDoc.DocumentNode.OuterHtml;
                    StoreEventData(_activeMQSettings.TopicNameKEUIPublishBugComment, annotatedMessage);
                    using (var publisher = new ActiveMqHelper.TopicPublisher(AQSession, _activeMQSettings.TopicNameKEUIPublishBugComment))
                    {
                        publisher.SendMessage(annotatedMessage);
                    }
                }
            }
            catch (Exception ex)
            {
                AddEvent("Exception while annotating new bug comment: " + ex.Message);
                GenLib.Log.LogService.LogException("Exception while processing new bug comment. message: " + message, ex);
            }
        }
コード例 #5
0
 void SendRDFData(string rdfData)
 {
     try
     {
         rdfData = rdfData.TrimStart("<?xml version=\"1.0\"?>");
         rdfData = rdfData.Trim();
         Trace.WriteLine("Sending rdf data");
         string eventData = Defaults.BuildNewRDFData(rdfData);
         lock (_sendingLock)
         {
             using (var publisher = new ActiveMqHelper.TopicPublisher(AQSession, _activeMQSettings.TopicNameAnnotexPublishConceptNew))
             {
                 publisher.SendMessage(eventData);
             }
         }
     }
     catch (Exception ex)
     {
         Trace.WriteLine("Exception while posting a request: " + ex.Message);
     }
 }
コード例 #6
0
 void SendRequest(string request, string requestId, string requestType)
 {
     try
     {
         Trace.WriteLine("Sending request with id " + requestId);
         lock (_sendingLock)
         {
             if (requestType != null)
                 _sequenceIdToType[requestId] = requestType;
             using (var publisher = new ActiveMqHelper.TopicPublisher(AQSession, TopicNameKEUIRequest))
             {
                 publisher.SendMessage(request);
             }
         }
     }
     catch (Exception ex)
     {
         Trace.WriteLine("Exception while posting a request: " + ex.Message);
     }
 }
コード例 #7
0
        public void Init()
        {
            try {
                // first start the logging service
                try {
                    string logFolder = Path.Combine(_forumSettingsFolder, "Log");
                    if (!Directory.Exists(logFolder))
                        Directory.CreateDirectory(logFolder);
                    GenLib.Log.LogService.AddLogger(new GenLib.Log.FileLogger(logFolder, "events.txt"));
                }
                catch (Exception ex) { AddEvent("Unable to start the logging service. Error: " + ex.Message); }
                GenLib.Log.LogService.LogInfo("Forum Sensor is starting.");

                LoadSettings();

                IConnectionFactory factory = new ConnectionFactory(_activeMQSettings.BrokerUri);
                IConnection connection = factory.CreateConnection();
                connection.Start();
                AQSession = connection.CreateSession();

                lock (_publisherLock) {
                    AQPublisher = new ActiveMqHelper.TopicPublisher(AQSession, _activeMQSettings.TopicNameForumSensorPublishForumPost);
                }
                AddEvent("Publishing events on " + _activeMQSettings.TopicNameForumSensorPublishForumPost);
            }
            catch (Exception ex) {
                AddEvent("Unable to use ActiveMQ: " + ex.Message);
            }

            // start the web getter
            WebGetter = new AsyncWebGetter(NrOfThreads, QueueEmptyCallbackFunc);
            WebGetter.SetChromBrowserHeaders();

            // for some reason, KDE's forum has some protection that returns invalid forum data for some time at the beginning.
            // for this reason we first create a few requests and then also wait 10 sec. Using this approach we don't seem to get empty body errors
            foreach (var account in AccountInfoList) {
                for (int i = 0; i < NrOfThreads * 2; i++)
                    WebGetter.DownloadPageAsync(this, null, new SmallUri(account.Address), Foo);
            }
            Thread.Sleep(10000);
        }
コード例 #8
0
 public void Finish()
 {
     DisposeTimers();
     lock (_publisherLock) {
         if (AQPublisher != null)
             AQPublisher.Dispose();
         AQPublisher = null;
     }
     SaveSettings();
     WebGetter.Dispose();
 }