Beispiel #1
0
        public PluginHost()
        {
            XmlConfigurator.Configure();
            var sopWatch = Stopwatch.StartNew();

            log.Debug("Инициализация...");
            InitializeComponent();
            var rabbitmqConfig = RabbitmqConfigurationSection.GetConfiguration();

            processHostManager = new ProcessHostManager(rabbitmqConfig.HostName, rabbitmqConfig.UserName, rabbitmqConfig.Password);
            plugins            = new List <Plugin>();

            using (var dbContext = new OrationiDatabaseContext())
            {
                foreach (var requestCode in dbContext.RequestCodes)
                {
                    log.Debug($"Загрузка синхронного/асинхронного обработчиков для кода запроса \"{requestCode.Id}\"");
                    plugins.AddRange(new[] {
                        new Plugin
                        {
                            RequestCode = requestCode.Id,
                            IsSync      = true
                        },
                        new Plugin
                        {
                            RequestCode = requestCode.Id,
                            IsSync      = false
                        }
                    });
                }
            }
            sopWatch.Stop();
            log.Debug($"Инициализация выполнилась за {sopWatch.Elapsed.TotalSeconds} секунд");
        }
        public static void Execute(Guid assemblyId)
        {
            using (var dbContext = new OrationiDatabaseContext())
            {
                var pluginAssembly = dbContext.PluginAsseblies.FirstOrDefault(pa => pa.Id == assemblyId);
                if (pluginAssembly is null)
                {
                    throw new InvalidOperationException($"Не найдена сборка с Id - {assemblyId}");
                }

                var pluginAssemblyInfo = PluginAssemblyInfo.Create(pluginAssembly);

                if (!pluginAssemblyInfo.IsFolderExists)
                {
                    Directory.CreateDirectory(pluginAssemblyInfo.BaseFolder);
                }

                AppDomain.CurrentDomain.AppendPrivatePath(pluginAssemblyInfo.BaseFolder);

                var zipAssemblyPackage = $"{pluginAssemblyInfo.FullPath}.zip";

                using (var writer = new BinaryWriter(File.OpenWrite(zipAssemblyPackage)))
                {
                    writer.Write(pluginAssembly.Assembly, 0, pluginAssembly.Assembly.Length);
                }

                ZipFile.ExtractToDirectory(zipAssemblyPackage, pluginAssemblyInfo.BaseFolder);

                File.Delete(zipAssemblyPackage);
            }
        }
        public void СоответствиеМеждуMessageStatusCodesИMessageStatusCode()
        {
            using (var dbContext = new OrationiDatabaseContext())
            {
                var messageStatusCodes = dbContext
                                         .MessageStatusCodes
                                         .ToList();

                List <(string Name, int Value)> enumMessageStatusCodes = Enum
                                                                         .GetNames(typeof(MessageStatusCodes))
                                                                         .Select(n => (n, (int)Enum.Parse(typeof(MessageStatusCodes), n)))
                                                                         .ToList();

                Assert.AreEqual(messageStatusCodes.Count,
                                enumMessageStatusCodes.Count,
                                "В таблице MessageStatusCodes и в типе MessageStatusCodes должно быть одинаковое количество элементов");

                var errorEnumValues = new List <string>();

                foreach (var enumMessageStatusCode in enumMessageStatusCodes)
                {
                    if (!messageStatusCodes
                        .Any(wessc => wessc.Id == enumMessageStatusCode.Value && wessc.Name == enumMessageStatusCode.Name))
                    {
                        errorEnumValues.Add($"{enumMessageStatusCode.Name}({enumMessageStatusCode.Value})");
                    }
                }
                Assert.IsFalse(errorEnumValues.Any(), "В таблице MessageStatusCodes для следующих значений типа MessageStatusCodes: " +
                               $"{string.Join(", ", errorEnumValues)} не найдено соответствий");
            }
        }
Beispiel #4
0
        public ResponseGenerator(OrationiDatabaseContext context, Guid requestId)
        {
            if (context is null)
                throw new ArgumentNullException(nameof(context));

            _dbContext = context;
            _requestId = requestId;
        }
Beispiel #5
0
        /// <summary>
        /// Process all plugins in DB.
        /// </summary>
        /// <param name="processHostManager">RabbitMQ Instance</param>
        private static void MultipleRequestCodesProcessing(ProcessHostManager processHostManager)
        {
            List <(int RequestCode, bool IsSync)> plugins = plugins = new List <(int RequestCode, bool IsSync)>();

            using (var dbContext = new OrationiDatabaseContext())
            {
                foreach (var requestCode in dbContext.RequestCodes)
                {
                    plugins.AddRange(new[] { (requestCode.Id, true), (requestCode.Id, false) });
Beispiel #6
0
        public PipelineProcessor(IPipelineExecutionContext pipelineExecutionContext, WorkflowAction workflowAction)
        {
            _dbContext = new OrationiDatabaseContext();

            _pipelineExecutionContext = pipelineExecutionContext;
            _messageId  = pipelineExecutionContext.MessageId;
            _workflowId = workflowAction.WorkflowId;

            InitializeStepsDescriptions(workflowAction);
        }
        public static void Execute()
        {
            using (var dbContext = new OrationiDatabaseContext())
            {
                var assembliesIdList = dbContext
                                       .PluginAsseblies
                                       .Select(pa => pa.Id)
                                       .ToList();

                foreach (var assemblyId in assembliesIdList)
                {
                    Execute(assemblyId);
                }
            }
        }
Beispiel #8
0
        public static bool IsAuthorized <T>(
            OrationiDatabaseContext dbContext,
            string token,
            Guid messageId,
            out T response,
            out ExternalSystem externalSystem)
            where T : ResponseBase, new()
        {
            var message = dbContext.Messages.FirstOrDefault(m => m.Id == messageId);

            if (message is null)
            {
                response = new T
                {
                    IsError = true,
                    Error   = $"Request {messageId} not found"
                };
                externalSystem = null;
                return(false);
            }

            return(IsAuthorized <T>(dbContext, token, message.RequestCodeId, out response, out externalSystem));
        }
Beispiel #9
0
        public static bool IsAuthorized <T>(
            OrationiDatabaseContext dbContext,
            string token,
            int requestCode,
            out T response,
            out ExternalSystem externalSystem)
            where T : ResponseBase, new()
        {
            response = new T();

            var errorList = new List <string>();

            if (string.IsNullOrWhiteSpace(token))
            {
                errorList.Add($"Invalid token ({token}).");
            }

            externalSystem = dbContext
                             .ExternalSystems
                             .Where(extSys => extSys.Token == token)
                             .FirstOrDefault(extSys => extSys.RequestCodes.Any(rc => rc.Id == requestCode));

            if (externalSystem is null)
            {
                errorList.Add($" External system is not exists for token ({token}).");
            }

            if (errorList.Count == 0)
            {
                return(true);
            }

            response.IsError = true;
            response.Error   = string.Join(" ", errorList);

            return(false);
        }
Beispiel #10
0
 public static ICacheProvider Create(OrationiDatabaseContext dbContext)
 {
     return(new DatabaseCacheProvider(dbContext));
 }
 public MessagingController()
 {
     XmlConfigurator.Configure();
     _dbContext = new OrationiDatabaseContext();
 }
Beispiel #12
0
 public WorkflowProcessor(Guid messageId, int requestCode)
 {
     _messageId   = messageId;
     _requestCode = requestCode;
     _dbContext   = new OrationiDatabaseContext();
 }
Beispiel #13
0
 public MessagingService()
 {
     _dbContext = new OrationiDatabaseContext();
     XmlConfigurator.Configure();
 }
 public DatabaseCacheProvider(OrationiDatabaseContext dbContext)
 {
     _dbContext = dbContext;
 }
Beispiel #15
0
 public IncomingMessageProcessor(OrationiDatabaseContext dbContext, ExternalSystem externalSystem)
 {
     _dbContext      = dbContext;
     _externalSystem = externalSystem;
 }
Beispiel #16
0
 internal PipelineExecutionContext(IWorkflowExecutionContext workflowExecutionContext, OrationiDatabaseContext dbContext)
 {
     PipelineValues            = new Dictionary <string, object>();
     PluginStepSettings        = new Dictionary <string, object>();
     _workflowExecutionContext = workflowExecutionContext;
     _fileStores   = dbContext.FileStores;
     CacheProvider = CacheProviderFactory.Create(dbContext);
     RequestBody   = _workflowExecutionContext.MessageBody;
 }