public void StartTest(ScheduleOptionModel option) { try { if (_running) { _errorLogger.Error("The workflow is running"); return; } _running = true; RegisterWorkflows(workflowMode); var workflow = workflows.FirstOrDefault(w => w.Id == option.WorkflowId) as IBaseWorkflow; IIndexModel indexModel = option.TargetEntityType == EntityType.Entity ? entityRepository.GetById(option.TargetEntityId.ToString()) as IIndexModel : attributeRepository.GetById(option.TargetEntityId.ToString()); if (indexModel == null) { throw new Exception($"Could not find Index with ID: {option.TargetEntityId}, Name: {option.TargetEntityName}, Type: {option.TargetEntityType}"); } workflow.SetIndex(indexModel); _host.Start(); _host.StartWorkflow(workflow.Id, workflow.Version, null); } catch (Exception ex) { _errorLogger.Error(ex, "Sync Service failed to run."); throw; } }
private string GetAttributeMessage(QueueItemModel item, out IIndexModel indexModel, out IndexItemModel itemModel) { var attributeModel = attributeRepository.GetById(item.TargetEntityId.ToString()); var entityModel = entityRepository.GetById(attributeModel.EntityId.ToString()); var entityOptions = entityRepository.LoadOptions(entityModel.Id.ToString(), new List <string> { "Indexer" }); var attributeOptions = attributeRepository.LoadOptions(attributeModel.Id.ToString(), new List <string> { "Indexer" }); var attributeItemModel = attributeRepository.GetIndexedItemById(attributeModel, item.TargetItemId); var entityItemModel = entityRepository.GetIndexedItemBySourceId(entityModel, attributeItemModel.GetSourceId()); itemModel = attributeItemModel; var entityReporterMappingOption = entityOptions.FirstOrDefault(o => o.Key == "indexer_reporter_columns"); var entityReporterMappingColumns = !string.IsNullOrWhiteSpace(entityReporterMappingOption?.Value) ? JsonConvert.DeserializeObject <List <ReporterColumnMapping> >(entityReporterMappingOption.Value) : new List <ReporterColumnMapping> { new ReporterColumnMapping { SourceName = "Value", MappingName = "Name", Key = true, Value = true } }; var attributeReporterMappingOption = attributeOptions.FirstOrDefault(o => o.Key == "indexer_reporter_columns"); var attributeReporterMappingColumns = !string.IsNullOrWhiteSpace(attributeReporterMappingOption?.Value) ? JsonConvert.DeserializeObject <List <ReporterColumnMapping> >(attributeReporterMappingOption.Value) : new List <ReporterColumnMapping> { new ReporterColumnMapping { SourceName = "Value", MappingName = "Name", Key = true, Value = true } }; var keys = entityReporterMappingColumns.Where(r => r.Key) .Select(r => $@"_{r.MappingName}_: {entityItemModel.GetValue(r.SourceName)?.ToString() ?? "(empty)"}"); var vals = attributeReporterMappingColumns.Where(r => r.Value) .Select(r => $@"_{r.MappingName}_: {attributeItemModel.GetValue(r.SourceName)?.ToString() ?? "(empty)"}"); if (attributeReporterMappingColumns.Count == 1) { vals = attributeReporterMappingColumns.Where(r => r.Value) .Select(r => $@"{attributeItemModel.GetValue(r.SourceName)?.ToString() ?? "(empty)"}"); } var executed = item.ExecutedAt.UnixTimeToTime().ToString("G"); var executedIn = item.ExecutedAt - item.ExecuteAt; indexModel = attributeModel; return($@"*{indexModel.Name}* ({string.Join(", ", keys)}): {vals} {executed} in {executedIn} second(s)"); }
public IActionResult PullAttributeData(string id, [FromBody] object nextToken = null) { var attribute = attributeRepository.GetById(id); var entity = entityRepository.GetById(attribute.EntityId.ToString()); var sourceConnection = connectionRepository.GetById(attribute.SourceConnectionId.ToString()); var puller = _attributePullers.FirstOrDefault(p => p.IsImplemented(attribute.SourceProcessorId, entity.SourceProcessorId, sourceConnection.ProviderId)); puller.SetIndex(attribute); var data = puller.PullNext(nextToken); return(Ok(data)); }
public IActionResult Update(string id, [FromBody] CreateAttributeViewModel model) { try { var attributeModel = attributeRepository.GetById(id); var state = attributeModel.State; if (model.Enabled) { state = (state | EntityState.Disabled) ^ EntityState.Disabled; } else { state = state | EntityState.Disabled; } var result = attributeRepository.Update(id, new { model.Name, model.Description, model.SourceConnectionId, model.DestinationConnectionId, model.EntityId, model.SourceProcessorId, model.DestinationProcessorId, State = state }); if (model.Options != null && model.Options.Count() > 0) { attributeRepository.LinkOptions(id, model.Options); } transaction.Commit(); return(Ok(result)); } catch { transaction.Rollback(); throw; } }
public CharacterAttribute GetById(long id) { return(_attributeRepository.GetById(id)); }
public override async Task Invoke(IStepExecutionContext context = null) { var executeAt = DateTime.Now.ToUnixTimestamp(); var firstQueuedItem = entityRepository.GetCurrentQueuedItems(); if (firstQueuedItem == null) { return; } IIndexModel indexModel = null; IndexItemModel itemModel = null; IIndexer indexer = null; IPusher pusher = null; IEnumerable <OptionItem> options = null; if (firstQueuedItem.TargetEntityType == EntityType.Entity) { indexModel = entityRepository.GetById(firstQueuedItem.TargetEntityId.ToString()); options = entityRepository.LoadOptions(indexModel.Id.ToString()).Select(o => new OptionItem { Name = o.Key, Value = o.Value }); var sourceConnection = connectionRepository.GetById(indexModel.SourceConnectionId.ToString()); var destinationConnection = connectionRepository.GetById(indexModel.DestinationConnectionId.ToString()); indexer = entityIndexers.FirstOrDefault(i => i.IsImplemented(indexModel.SourceProcessorId, sourceConnection.ProviderId)); pusher = entityPushers.FirstOrDefault(p => p.IsImplemented(indexModel.DestinationProcessorId, destinationConnection.ProviderId)); } else { var attributeModel = attributeRepository.GetById(firstQueuedItem.TargetEntityId.ToString()); indexModel = attributeModel; var entityModel = entityRepository.GetById(attributeModel.EntityId.ToString()); options = attributeRepository.LoadOptions(attributeModel.Id.ToString()).Select(o => new OptionItem { Name = o.Key, Value = o.Value }); var sourceConnection = connectionRepository.GetById(attributeModel.SourceConnectionId.ToString()); var destinationConnection = connectionRepository.GetById(attributeModel.DestinationConnectionId.ToString()); indexer = attributeIndexers.FirstOrDefault(i => i.IsImplemented(attributeModel.SourceProcessorId, entityModel.SourceProcessorId, sourceConnection.ProviderId)); pusher = attributePushers.FirstOrDefault(p => p.IsImplemented(attributeModel.DestinationProcessorId, entityModel.DestinationProcessorId, destinationConnection.ProviderId)); } indexer.SetIndex(indexModel); indexer.SetOptions(options); pusher.SetIndex(indexModel); pusher.SetOptions(options); pusherManager.SetIndex(indexModel); pusherManager.OnReport(s => Logger.Information(s)); pusherManager.SetIndexer(indexer); pusherManager.SetPusher(pusher); try { itemModel = entityRepository.GetIndexedItemById(indexModel, firstQueuedItem.TargetItemId.ToString()); var pushState = await pusherManager.PushItem(itemModel); var queueItemStatus = firstQueuedItem.Status == PushState.None ? PushState.Success : firstQueuedItem.Status; var messageId = messageRepository.Create(new { Message = string.Join("\n", pusherManager.GetReportMessages()), CreatedAt = DateTime.Now.ToUnixTimestamp(), MessageType = MessageType.Information, Status = MessageStatus.None }); queueItemStatus = queueItemStatus & pushState; if ((pushState & PushState.Success) <= 0) { queueItemStatus = (queueItemStatus | PushState.Success) ^ (PushState.Success); } queueItemRepository.Update(firstQueuedItem.Id.ToString(), new { UpdatedAt = DateTime.Now.ToUnixTimestamp(), ExecuteAt = executeAt, ExecutedAt = DateTime.Now.ToUnixTimestamp(), MessageId = messageId, Status = queueItemStatus }); } catch (Exception ex) { var messages = $@"Queue item (Id: {firstQueuedItem.Id}) failed to run. Addtional information: ```{JsonConvert.SerializeObject(indexModel, Formatting.Indented)}``` Progress: ```{string.Join("\n - ", pusherManager.GetReportMessages())}``` Exception: ```{ex}```"; var messageId = messageRepository.Create(new { Message = messages, CreatedAt = DateTime.Now.ToUnixTimestamp(), MessageType = MessageType.Error, Status = MessageStatus.None }); queueItemRepository.Update(firstQueuedItem.Id.ToString(), new { UpdatedAt = DateTime.Now.ToUnixTimestamp(), ExecuteAt = executeAt, ExecutedAt = DateTime.Now.ToUnixTimestamp(), MessageId = messageId, Status = (firstQueuedItem.Status | PushState.UnexpectedError | PushState.Failed | PushState.Success) ^ PushState.Success, // remove success }); throw; } }