Ejemplo n.º 1
0
        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;
            }
        }
Ejemplo n.º 2
0
        public void StartTest(ScheduleOptionModel option)
        {
            var entityRepository    = ResolverFactory.Resolve <EntityRepository>();
            var attributeRepository = ResolverFactory.Resolve <AttributeRepository>();

            try
            {
                if (_running)
                {
                    ErrorLogger.Error("The workflow is running");
                    return;
                }
                _running = true;
                workingSchedules.SetSchedules(new List <ScheduleOptionModel> {
                    option
                });
                RegisterWorkflows();
                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}");
                }

                _host.Start();
                if (!_ranWorkflows.Contains(workflow.Id))
                {
                    _ranWorkflows.Add(workflow.Id);
                    if (workflow.IsGeneric)
                    {
                        _host.StartGenericWorkflow(workflow);
                    }
                    else
                    {
                        _host.StartWorkflow(workflow.Id);
                    }
                }
                else
                {
                    _host.ResumeWorkflow(workflow.Id);
                }
            }
            catch (Exception ex)
            {
                ErrorLogger.Error(ex, "Sync Service failed to run.");
                throw;
            }
            finally
            {
                entityRepository?.Dispose();
                attributeRepository?.Dispose();
            }
        }