public IndexResult UpdateGeneralIndex(GeneralDTO general, ICollection <GeneralField> changedFields) { if (general.GeneralID == null) { return(new IndexResult()); } IEnumerable <IDocumentIndex> indexes = _documentIndexProvider.GetOrCreateDocumentIndexes(_pluginContext.AccountName, DocumentIndexTypeToken.Entity, DocumentIndexTypeToken.EntityProject, DocumentIndexTypeToken.EntityType); if (!indexes.Any(i => changedFields.Any(f => i.Type.IsBelongedToIndexFields(f) || i.Type.IsBelongedToDocumentFields(f)))) { return(new IndexResult()); } IDocumentIndex entityIndex = _documentIndexProvider.GetOrCreateDocumentIndex(_pluginContext.AccountName, DocumentIndexTypeToken.Entity); var document = entityIndex.FindDocumentByName <EntityDocument>(EntityDocument.CreateName(general.GeneralID)); if (document == null) { _log.Error(string.Format("CANNOT PROCESS UPDATE '{0}UpdatedMessage' FOR ENTITY #{1} - '{2}'. ENTITY WAS NOT ADDED DURING PROFILE INITIALIZATION OR ENTITY CREATION !!!", general.EntityTypeName, general.GeneralID.GetValueOrDefault(), general.Name)); return(new IndexResult()); } if (changedFields.Any(f => entityIndex.Type.IsBelongedToDocumentFields(f))) { document.ProjectId = _documentIdFactory.CreateProjectId(general.ParentProjectID.GetValueOrDefault()); document.EntityTypeId = _documentIdFactory.CreateEntityTypeId(general.EntityTypeID.GetValueOrDefault()); entityIndex.SaveDocument(document, false); _log.Debug(string.Format("Updated {0} #{1} - '{2}':{3}{4}", general.EntityTypeName, general.GeneralID.GetValueOrDefault(), general.Name, changedFields.Contains(GeneralField.ParentProjectID) ? string.Format(" Project - {0};", string.Join(",", general.ParentProjectName)) : string.Empty, changedFields.Contains(GeneralField.EntityTypeID) ? string.Format(" EntityType - {0};", string.Join(",", general.EntityTypeName)) : string.Empty)); } if (changedFields.Any(f => entityIndex.Type.IsBelongedToIndexFields(f))) { var text = _textOperations.Prepare(string.Format("{0} {1} ", general.Name, general.Description ?? string.Empty)); var indexResult = entityIndex.Update(document.FileName, text); _log.Debug(string.Format("Updated {0} #{1} - '{2}':{3}{4}", general.EntityTypeName, general.GeneralID.GetValueOrDefault(), general.Name, indexResult.WordsAdded.Any() ? string.Format(" added words - {0};", string.Join(",", indexResult.WordsAdded.Keys)) : " NO WORDS ADDED;", indexResult.WordsRemoved.Any() ? string.Format(" removed words - {0};", string.Join(",", indexResult.WordsRemoved)) : " NO WORDS REMOVED;")); } IDocumentIndex entityProjectIndex = _documentIndexProvider.GetOrCreateDocumentIndex(_pluginContext.AccountName, DocumentIndexTypeToken.EntityProject); if (changedFields.Any(f => entityProjectIndex.Type.IsBelongedToIndexFields(f)) && document.DocNumber >= 0) { entityProjectIndex.Update(document.DocNumber, general.ParentProjectID.HasValue ? _documentIdFactory.EncodeProjectId(general.ParentProjectID.Value) : string.Empty); _localBus.SendLocal(new GeneralProjectChangedLocalMessage { GeneralId = general.GeneralID.Value, ProjectId = general.ParentProjectID }); } IDocumentIndex entityTypeIndex = _documentIndexProvider.GetOrCreateDocumentIndex(_pluginContext.AccountName, DocumentIndexTypeToken.EntityType); if (changedFields.Any(f => entityTypeIndex.Type.IsBelongedToIndexFields(f)) && document.DocNumber >= 0) { entityTypeIndex.Index(document.DocNumber, general.EntityTypeName); } return(new IndexResult { DocNumber = document.DocNumber }); }
public void Handle(TickMessage message) { if (!ConfigHelper.GetWorkItemsState()) { return; } if (!IsSourceControlEnabled()) { var tpBus = ObjectFactory.GetInstance <TpBus>(); tpBus.DoNotContinueDispatchingCurrentMessageToHandlers(); } if (!IsSynchronizationEnabled()) { _logger.Info("Work items synchronization disabled"); return; } _logger.Info("Syncronize work items"); var messages = GetTargetWorkItemsMessages(message.LastSyncDate); messages.ForEach(msg => _bus.SendLocal(msg)); }
public void Handle(TickMessage tickMessage) { _log.Info("Downloading uids from email server..."); using (var client = ObjectFactory.GetInstance <IEmailClient>()) { client.Connect(); client.Login(); var uids = GetNewUids(client); _messageUidRepository.AddRange(uids.ToArray()); Debug.Assert(uids != null, "uids != null"); var lastIndex = 0; while (true) { var uidsPack = uids.Skip(lastIndex).Take(_messagePackSize.Value).ToArray(); if (!uidsPack.Any()) { break; } lastIndex += _messagePackSize.Value; _localBus.SendLocal(new EmailUidsRetrievedMessage { Uids = uidsPack }); } client.Disconnect(); } }
private void SendLocal(IEnumerable <RevisionInfo> revisions) { var messages = revisions.Select(x => new NewRevisionDetectedLocalMessage { Revision = x }); messages.ForEach(x => _bus.SendLocal(x)); }
private void PushAttachmentsToTp(int?tpBugId, BugzillaBug bug, List <LocalStoredAttachment> attachments) { _logger.InfoFormat("Processing attachments. Bug: {0}", bug.ToString()); _localBus.SendLocal(new PushAttachmentsToTpCommandInternal { LocalStoredAttachments = attachments.ToArray(), GeneralId = tpBugId }); }
private void ProcessChangedBugIds(int[] changedIds) { FailedSyncDates.Clear(); var lastIndex = 0; var bugIdsChunk = changedIds.Skip(lastIndex).Take(_bugChunkSize.Value).ToArray(); while (bugIdsChunk.Any()) { _bus.SendLocal(new ImportBugsChunk { ThirdPartyBugsIds = bugIdsChunk }); lastIndex += _bugChunkSize.Value; bugIdsChunk = changedIds.Skip(lastIndex).Take(_bugChunkSize.Value).ToArray(); } }
public bool ReadNextEmailMessage(string[] uids) { while (uids != null && _index < uids.Length) { var uid = uids[_index++]; // 1. Download email message from the server. var mailBeeMailMessage = DoDownloadMailMessage(uid); if (mailBeeMailMessage == null) { continue; } // 2. Mark downloaded message as read, do not download it the next time. var messageUid = MarkAsRead(uid); // Copy MailBee message to System.Net.Mail message. System.Net.Mail.MailMessage mailMessage; try { mailMessage = ConvertToNetMailMessage(mailBeeMailMessage); } catch (Exception e) { //Just skip this message _log.Error(String.Format("Error parsing message."), e); return(true); } // If incoming message has incorrect date MailBee may throw exception. var sentDate = SqlDateTime.MinValue.Value; try { if (mailBeeMailMessage.Date != DateTime.MinValue) { sentDate = mailBeeMailMessage.Date; } } catch { } var emailReceivedMessage = new EmailReceivedMessage { Mail = ConvertToDto(mailMessage, messageUid, sentDate) }; _localBus.SendLocal(emailReceivedMessage); return(true); } _client.Disconnect(); return(false); }
private void CreateBugsInTargetProcess(bugCollection bugCollection) { var bugs = bugCollection.Cast <bug>().ToList(); foreach (var bug in bugs) { _bus.SendLocal(new ImportBugToTargetProcessCommand <BugzillaBug> { ThirdPartyBug = new BugzillaBug(bug) }); } }
public void Handle(RevisionCreatedLocalMessage message) { _logger.InfoFormat("Parsing comment. Revision ID: {0}", message.Dto.SourceControlID); var commentParser = new CommentParser(); var actions = commentParser.ParseAssignToEntityAction(message.Dto); var actionParamFiller = new ActionParameterFillerVisitor(message.Dto); foreach (var action in actions) { action.Execute(actionParamFiller, x => _bus.SendLocal(action), _logger); } }
public void Handle(SyncNowMessage message) { var logger = ObjectFactory.GetInstance <ILogManager>().GetLogger(GetType()); logger.Info("SyncNowMessage received"); var lastSyncDates = _storage.Get <LastSyncDate>(); var lastSyncDate = lastSyncDates.FirstOrDefault(); _localBus.SendLocal(lastSyncDate != null ? new TickMessage(lastSyncDate.Value) : new TickMessage(null)); logger.Info("TickMessage sent"); lastSyncDates.ReplaceWith(new LastSyncDate(CurrentDate.Value)); }
public PluginCommandResponseMessage Execute(string args) { if (_pluginContext.ProfileName.IsEmpty) { throw new ApplicationException("'SyncNow' command should be executed for concrete profile only."); } if (_profileCollection[_pluginContext.ProfileName].IsNull) { throw new ApplicationException(string.Format("No profile with name '{0}' was found.", _pluginContext.ProfileName.Value)); } _localBus.SendLocal(new SyncNowMessage()); ObjectFactory.GetInstance <ILogManager>().GetLogger(GetType()).Info("SyncNowMessage sent"); return(new PluginCommandResponseMessage { PluginCommandStatus = PluginCommandStatus.Succeed }); }
private string OnExecute(string args) { var profile = _storageRepository.GetProfile <TestRunImportPluginProfile>(); _log.InfoFormat("Started synchronizing at {0}", DateTime.Now); if (!string.IsNullOrEmpty(args) && profile.FrameworkType == FrameworkTypes.FrameworkTypes.Selenium) { using (var reader = new StringReader(args)) { try { var result = _resultsReaderFactory.GetResolver(profile, reader).GetTestRunImportResults(); _log.InfoFormat("{0} items for import detected in resutls source", result.Count == 0 ? "No" : result.Count.ToString()); if (result.Count > 0) { _localBus.SendLocal(new TestRunImportResultDetectedLocalMessage { TestRunImportInfo = new TestRunImportInfo { TestRunImportResults = result.ToArray() } }); } } catch (ApplicationException) { throw; } catch (Exception ex) { throw new ApplicationException( string.Format("Could not read file \"{0}\": {1}", profile.ResultsFilePath, ex.Message), ex); } } } //return new PluginCommandResponseMessage { ResponseData = string.Empty, PluginCommandStatus = PluginCommandStatus.Succeed }; return(string.Empty); }
public void Handle(TickMessage message) { var profile = _storageRepository.GetProfile<TestRunImportPluginProfile>(); if (profile.FrameworkType == FrameworkTypes.FrameworkTypes.Selenium && profile.PostResultsToRemoteUrl) { return; } try { _log.InfoFormat("Started synchronizing at {0}", DateTime.Now); var lastModifyResults = _storageRepository.Get<LastModifyResult>(); var lastModifyResult = lastModifyResults.Empty() ? new LastModifyResult() : lastModifyResults.Single(); var jenkinsHudsonLastCompletedBuildNumber = profile.FrameworkType == FrameworkTypes.FrameworkTypes.JenkinsHudson ? GetJenkinsHudsonLastCompletedBuildNumber(profile) : null; if (profile.FrameworkType == FrameworkTypes.FrameworkTypes.JenkinsHudson && (jenkinsHudsonLastCompletedBuildNumber == null || string.CompareOrdinal(lastModifyResult.ETagHeader, jenkinsHudsonLastCompletedBuildNumber) == 0)) { _log.Info("No new modification of results source detected"); return; } var uri = profile.FrameworkType == FrameworkTypes.FrameworkTypes.JenkinsHudson ? new Uri(string.Format("{0}/lastCompletedBuild/testReport/api/xml", profile.ResultsFilePath.TrimEnd(new[] { '/', '\\' }))) : new Uri(profile.ResultsFilePath); var factoryResult = _streamFactory.OpenStreamIfModified(uri, lastModifyResult, profile.PassiveMode); _log.InfoFormat("{0} modification of results source detected", factoryResult == null ? "No new" : "New"); if (factoryResult != null) { if (profile.FrameworkType == FrameworkTypes.FrameworkTypes.JenkinsHudson) { factoryResult.LastModifyResult.ETagHeader = jenkinsHudsonLastCompletedBuildNumber; } lastModifyResults.Clear(); lastModifyResults.Add(factoryResult.LastModifyResult); using (factoryResult.Stream) { using (var reader = new StreamReader(factoryResult.Stream)) { try { var result = _resultsReaderFactory.GetResolver(profile, reader).GetTestRunImportResults(); _log.InfoFormat("{0} items for import detected in resutls source", result.Count == 0 ? "No" : result.Count.ToString(CultureInfo.InvariantCulture)); if (result.Count > 0) { _localBus.SendLocal(new TestRunImportResultDetectedLocalMessage { TestRunImportInfo = new TestRunImportInfo { TestRunImportResults = result.ToArray() } }); } } catch (ApplicationException) { throw; } catch (XmlException ex) { throw new ApplicationException("Error parsing results XML file", ex); } catch (Exception ex) { throw new ApplicationException("Error importing results XML file", ex); } } } } } catch (UriFormatException ex) { _log.Error(ex.Message); throw new ApplicationException(string.Format("Specified path has invalid format. {0}", ex.Message), ex); } catch (ApplicationException ex) { _log.Error(ex.Message); throw; } catch (Exception ex) { _log.ErrorFormat("Could not read file \"{0}\": {1}", profile.ResultsFilePath, ex.Message); throw new ApplicationException( string.Format("Could not read file \"{0}\": {1}", profile.ResultsFilePath, ex.Message), ex); } }
private PluginCommandResponseMessage OnExecute() { var resultMessage = new PluginCommandResponseMessage { ResponseData = string.Empty, PluginCommandStatus = PluginCommandStatus.Succeed }; var profile = _storageRepository.GetProfile <TestRunImportPluginProfile>(); if (profile.FrameworkType == FrameworkTypes.FrameworkTypes.Selenium && profile.PostResultsToRemoteUrl) { return(resultMessage); } try { var uri = new Uri(profile.ResultsFilePath); var factoryResult = _streamFactory.OpenStreamIfModified(uri, new LastModifyResult(), profile.PassiveMode); if (factoryResult != null) { _storageRepository.Get <LastModifyResult>().Clear(); _storageRepository.Get <LastModifyResult>().Add(factoryResult.LastModifyResult); using (factoryResult.Stream) { using (var reader = new StreamReader(factoryResult.Stream)) { try { var result = _resultsReaderFactory.GetResolver(profile, reader).GetTestRunImportResults(); if (result.Count > 0) { _localBus.SendLocal(new TestRunImportResultDetectedLocalMessage { TestRunImportInfo = new TestRunImportInfo { TestRunImportResults = result.ToArray() } }); } } catch (ApplicationException ex) { resultMessage.ResponseData = ex.Message; resultMessage.PluginCommandStatus = PluginCommandStatus.Error; } catch (XmlException ex) { resultMessage.ResponseData = string.Format("Error parsing results XML file; {0}", ex.Message); resultMessage.PluginCommandStatus = PluginCommandStatus.Error; } catch (Exception ex) { resultMessage.ResponseData = string.Format("Error parsing results XML file; {0}", ex.Message); resultMessage.PluginCommandStatus = PluginCommandStatus.Error; } } } } } catch (UriFormatException ex) { resultMessage.ResponseData = string.Format("Specified path has invalid format. {0}", ex.Message); resultMessage.PluginCommandStatus = PluginCommandStatus.Error; } catch (ApplicationException ex) { resultMessage.ResponseData = string.Format("Specified path has invalid format. {0}", ex.Message); resultMessage.PluginCommandStatus = PluginCommandStatus.Error; } catch (Exception ex) { resultMessage.ResponseData = string.Format("Could not read file \"{0}\": {1}", profile.ResultsFilePath, ex.Message); resultMessage.PluginCommandStatus = PluginCommandStatus.Error; } return(resultMessage); }