Esempio n. 1
0
 private void RegisterLogHistoryEvent(int idUser, EventType eventType, int eventCode, string eventInfo, string Comment = null)
 {
     try
     {
         var idJournal = GetAuthJournalId();
         if (idJournal.HasValue)
         {
             AppCore.Get <JournalingManager>().RegisterEventForItem(
                 idJournal.Value,
                 new ItemKey(ItemTypeFactory.GetItemType <CoreDB.User>().IdItemType, idUser, ""),
                 eventType,
                 eventCode,
                 eventInfo,
                 Comment);
         }
     }
     catch (Exception ex)
     {
         var idJournal = GetAuthJournalId();
         if (idJournal.HasValue)
         {
             AppCore.Get <JournalingManager>().RegisterEvent(idJournal.Value, EventType.CriticalError, 0, "Ошибка регистрации события в журнал", null, null, ex);
         }
     }
 }
Esempio n. 2
0
    protected void OnItemsRequestedByFilterCondition_View(object source, ListEditItemsRequestedByFilterConditionEventArgs e)
    {
        BootstrapComboBox editor = source as BootstrapComboBox;

        editor.DataSource = ItemTypeFactory.GetItemSubTypes().Where(s => s.SubTypeDescription.Contains(e.Filter) ||
                                                                    s.SubTypeName.Contains(e.Filter) ||
                                                                    s.SubTypeID.ToString().Contains(e.Filter));
        editor.DataBind();
    }
Esempio n. 3
0
    protected void OnItemRequestedByValue_View(object source, ListEditItemRequestedByValueEventArgs e)
    {
        if (e.Value == null)
        {
            return;
        }
        int subTypeID            = (int)e.Value;
        BootstrapComboBox editor = source as BootstrapComboBox;

        editor.DataSource = ItemTypeFactory.GetItemSubTypes().Where(s => s.SubTypeID == subTypeID);
        editor.DataBind();
    }
Esempio n. 4
0
    protected void OnItemsRequestedByFilterCondition(object source, ListEditItemsRequestedByFilterConditionEventArgs e)
    {
        BootstrapComboBox editor = source as BootstrapComboBox;
        int            typeID    = GetCurrentItemTypeID();
        List <SubType> subTypes;

        if (typeID > -1)
        {
            subTypes = ItemTypeFactory.GetItemSubTypes().Where(s => s.TypeID == typeID && (s.SubTypeDescription.Contains(e.Filter) ||
                                                                                           s.SubTypeName.Contains(e.Filter) ||
                                                                                           s.SubTypeID.ToString().Contains(e.Filter))).ToList();
        }
        else
        {
            subTypes = ItemTypeFactory.GetItemSubTypes().Where(s => s.SubTypeDescription.Contains(e.Filter) ||
                                                               s.SubTypeName.Contains(e.Filter) ||
                                                               s.SubTypeID.ToString().Contains(e.Filter)).ToList();
        }
        editor.DataSource = subTypes;
        editor.DataBind();
    }
Esempio n. 5
0
    protected void OnItemRequestedByValue(object source, ListEditItemRequestedByValueEventArgs e)
    {
        if (e.Value == null)
        {
            return;
        }
        string            id     = e.Value.ToString();
        BootstrapComboBox editor = source as BootstrapComboBox;
        int            typeID    = GetCurrentItemTypeID();
        List <SubType> subTypes;

        if (typeID > -1)
        {
            subTypes = ItemTypeFactory.GetItemSubTypes().Where(s => s.TypeID == typeID && s.SubTypeID.ToString() == id).ToList();
        }
        else
        {
            subTypes = ItemTypeFactory.GetItemSubTypes().Where(s => s.TypeID == typeID).ToList();
        }
        editor.DataSource = subTypes;
        editor.DataBind();
    }
Esempio n. 6
0
        /// <summary>
        /// Создает новый экземпляр сервиса.
        /// </summary>
        /// <param name="serviceName">Текстовое название сервиса.</param>
        /// <param name="serviceID">Уникальный идентификатор сервиса.</param>
        protected MessagingServiceBase(string serviceName, Guid serviceID)
        {
            var type = GetType();

            TasksOutcomingSend   = type.FullName + "_" + nameof(TasksOutcomingSend);
            TasksIncomingReceive = type.FullName + "_" + nameof(TasksIncomingReceive);
            TasksIncomingHandle  = type.FullName + "_" + nameof(TasksIncomingHandle);

            if (string.IsNullOrEmpty(serviceName))
            {
                throw new ArgumentNullException(nameof(serviceName));
            }
            if (serviceID == null)
            {
                throw new ArgumentNullException(nameof(serviceID));
            }

            ServiceID   = serviceID;
            ServiceName = serviceName;

            IdMessageType = ItemTypeFactory.GetItemType(typeof(TMessage)).IdItemType;
        }
Esempio n. 7
0
        public JsonResult NewsSave(Models.NewsSave model = null)
        {
            var answer = JsonAnswer <int>();

            try
            {
                if (ModelState.IsValid)
                {
                    using (var db = new DB.DataLayerContext())
                    {
                        DB.News data = null;
                        if (model.IdMaterial <= 0)
                        {
                            data = new DB.News()
                            {
                                date = DateTime.Now, user = AppCore.GetUserContextManager().GetCurrentUserContext().IdUser, status = true, Block = false
                            };
                            db.News.Add(data);
                        }
                        else
                        {
                            data = db.News.Where(x => x.id == model.IdMaterial).FirstOrDefault();
                            if (data == null)
                            {
                                throw new Exception("Указанная новость не найдена.");
                            }

                            if (data.Block)
                            {
                                if (AppCore.GetUserContextManager().GetCurrentUserContext().IsSuperuser)
                                {
                                    throw new Exception("Указанная новость удалена (сообщение для суперпользователя).");
                                }
                                else
                                {
                                    throw new Exception("Указанная новость не найдена.");
                                }
                            }
                        }

                        data.name       = model.NameMaterial;
                        data.text       = model.BodyFull;
                        data.short_text = model.BodyShort;

                        db.SaveChanges();

                        answer.Data = data.id;

                        var result = AppCore.Get <UrlManager>().Register(
                            Module,
                            data.id,
                            ItemTypeFactory.GetItemType(typeof(DB.News)).IdItemType,
                            nameof(ModuleController.ViewNews),
                            new List <ActionArgument>()
                        {
                            new ActionArgument()
                            {
                                ArgumentName = "IdNews", ArgumentValue = data.id
                            }
                        },
                            "news/" + UrlManager.Translate(data.name),
                            RoutingConstants.MAINKEY
                            );
                        if (!result.IsSuccess)
                        {
                            throw new Exception(result.Message);
                        }

                        answer.FromSuccess("Новость сохранена");
                    }
                }
            }
            catch (Exception ex)
            {
                answer.FromException(ex);
                Module.RegisterEvent(EventType.Error, "Ошибка сохранения новости", "Модель данных, переданная из формы:\r\n" + Newtonsoft.Json.JsonConvert.SerializeObject(model), null, ex);
            }

            return(ReturnJson(answer));
        }
Esempio n. 8
0
 protected void Page_Load(object sender, EventArgs e)
 {
     if (!IsPostBack && !IsCallback)
     {
         Session.Clear();
     }
     ((BootstrapGridViewComboBoxColumn)BootstrapGridView1.Columns["TypeID"]).PropertiesComboBox.DataSource = ItemTypeFactory.GetItemTypes();
     BootstrapGridView1.DataSource = objectDataSource1;
     BootstrapGridView1.DataBind();
 }
Esempio n. 9
0
        void IMessagingServiceInternal.PrepareIncomingHandle(TimeSpan executeInterval)
        {
            if (AppCore.GetState() != CoreComponentState.Started)
            {
                return;
            }

            var type = GetType();

            if (!_executingFlags.TryLock(TasksIncomingHandle))
            {
                return;
            }
            _executingFlags.ReleaseLock(nameof(RegisterIncomingMessage));

            int messagesAll     = 0;
            int messagesHandled = 0;
            int messagesErrors  = 0;

            try
            {
                using (var db = new DB.DataContext())
                    using (var scope = db.CreateScope(TransactionScopeOption.Suppress))
                    {
                        var timeEnd = DateTimeOffset.Now.Add(executeInterval);
                        while (DateTimeOffset.Now < timeEnd)
                        {
                            var messages = GetMessages(db, true, 100, _incomingHandleQueueInfo);
                            if (messages.IsNullOrEmpty())
                            {
                                break;
                            }

                            messagesAll += messages.Count;

                            var components = GetComponents().
                                             OfType <IncomingMessageHandler <TMessage> >().
                                             Select(x => new
                            {
                                Component       = x,
                                IdTypeComponent = ItemTypeFactory.GetItemType(x.GetType())?.IdItemType
                            }).
                                             OrderBy(x => ((IPoolObjectOrdered)x.Component).OrderInPool).
                                             ToList();

                            foreach (var intermediateMessage in messages)
                            {
                                if (DateTimeOffset.Now >= timeEnd)
                                {
                                    break;
                                }

                                var componentsForMessage = components;
                                if (intermediateMessage.MessageSource.IdTypeComponent.HasValue)
                                {
                                    components = components.Where(x => x.IdTypeComponent.HasValue && x.IdTypeComponent == intermediateMessage.MessageSource.IdTypeComponent).ToList();
                                }

                                foreach (var componentInfo in components)
                                {
                                    try
                                    {
                                        var component       = componentInfo.Component;
                                        var messageInfo     = new MessageInfo <TMessage>(intermediateMessage);
                                        var componentResult = component.OnPrepare(messageInfo, this);
                                        if (componentResult != null)
                                        {
                                            intermediateMessage.MessageSource.DateChange = DateTime.Now;
                                            switch (componentResult.StateType)
                                            {
                                            case MessageStateType.Completed:
                                                intermediateMessage.MessageSource.StateType       = DB.MessageStateType.Complete;
                                                intermediateMessage.MessageSource.State           = null;
                                                intermediateMessage.MessageSource.IdTypeComponent = null;
                                                intermediateMessage.MessageSource.DateDelayed     = null;
                                                break;

                                            case MessageStateType.Delayed:
                                                intermediateMessage.MessageSource.StateType       = DB.MessageStateType.NotProcessed;
                                                intermediateMessage.MessageSource.State           = componentResult.State;
                                                intermediateMessage.MessageSource.IdTypeComponent = null;
                                                intermediateMessage.MessageSource.DateDelayed     = componentResult.DateDelayed;
                                                break;

                                            case MessageStateType.Repeat:
                                                intermediateMessage.MessageSource.StateType       = DB.MessageStateType.Repeat;
                                                intermediateMessage.MessageSource.State           = componentResult.State;
                                                intermediateMessage.MessageSource.IdTypeComponent = componentInfo.IdTypeComponent;
                                                intermediateMessage.MessageSource.DateDelayed     = componentResult.DateDelayed;
                                                break;

                                            case MessageStateType.Error:
                                                intermediateMessage.MessageSource.StateType       = DB.MessageStateType.Error;
                                                intermediateMessage.MessageSource.State           = componentResult.State;
                                                intermediateMessage.MessageSource.IdTypeComponent = null;
                                                intermediateMessage.MessageSource.DateDelayed     = null;
                                                break;
                                            }
                                            messagesHandled++;
                                            db.SaveChanges();
                                            break;
                                        }
                                    }
                                    catch
                                    {
                                        messagesErrors++;
                                        continue;
                                    }
                                }

                                _incomingHandleQueueInfo.IdQueueCurrent = intermediateMessage.MessageSource.IdQueue;
                            }
                        }
                        db.SaveChanges();
                        scope.Complete();
                    }
            }
            catch (Exception ex)
            {
                this.RegisterServiceState(ServiceStatus.RunningWithErrors, $"Сообщений получено для обработки - {messagesAll}. Обработано - {messagesHandled}. Ошибки обработки - {messagesErrors}.", ex);
            }
            finally
            {
                _executingFlags.ReleaseLock(TasksIncomingHandle);
            }
        }
Esempio n. 10
0
        void IMessagingServiceInternal.PrepareIncomingReceive(TimeSpan executeInterval)
        {
            if (AppCore.GetState() != CoreComponentState.Started)
            {
                return;
            }

            var type = GetType();

            if (!_executingFlags.TryLock(TasksIncomingReceive))
            {
                return;
            }

            int messagesReceived = 0;

            try
            {
                using (var db = new DB.DataContext())
                {
                    var components = GetComponents().
                                     OfType <IncomingMessageReceiver <TMessage> >().
                                     Select(x => new
                    {
                        Component       = x,
                        IdTypeComponent = ItemTypeFactory.GetItemType(x.GetType())?.IdItemType
                    }).
                                     OrderBy(x => ((IPoolObjectOrdered)x.Component).OrderInPool).
                                     ToList();

                    var timeEnd = DateTimeOffset.Now.Add(executeInterval);

                    using (var scope = db.CreateScope(TransactionScopeOption.Suppress)) // Здесь Suppress вместо RequiresNew, т.к. весь процесс отправки занимает много времени и блокировать таблицу нельзя.
                    {
                        foreach (var componentInfo in components)
                        {
                            try
                            {
                                var messages = componentInfo.Component.OnReceive(this);
                                if (messages != null && messages.Count > 0)
                                {
                                    int countAdded = 0;
                                    foreach (var message in messages)
                                    {
                                        if (message == null)
                                        {
                                            continue;
                                        }

                                        var stateType = DB.MessageStateType.NotProcessed;
                                        if (message.IsComplete)
                                        {
                                            stateType = DB.MessageStateType.Complete;
                                        }
                                        if (message.IsError)
                                        {
                                            stateType = DB.MessageStateType.Error;
                                        }

                                        var mess = new DB.MessageQueue()
                                        {
                                            IdMessageType = IdMessageType,
                                            Direction     = true,
                                            State         = message.State,
                                            StateType     = stateType,
                                            DateCreate    = DateTime.Now,
                                            DateDelayed   = message.DateDelayed,
                                            MessageInfo   = Newtonsoft.Json.JsonConvert.SerializeObject(message.Message),
                                        };

                                        db.MessageQueue.Add(mess);
                                        countAdded++;
                                        messagesReceived++;

                                        if (countAdded >= 50)
                                        {
                                            db.SaveChanges();
                                            countAdded = 0;
                                        }
                                    }

                                    db.SaveChanges();
                                }
                            }
                            catch (Exception ex)
                            {
                                this.RegisterServiceEvent(Journaling.EventType.Error, $"Ошибка вызова '{nameof(componentInfo.Component.OnReceive)}'", $"Ошибка вызова '{nameof(componentInfo.Component.OnReceive)}' для компонента '{componentInfo?.Component?.GetType()?.FullName}'.", ex);
                                continue;
                            }

                            try
                            {
                                while (true)
                                {
                                    var message = componentInfo.Component.OnBeginReceive(this);
                                    if (message == null)
                                    {
                                        break;
                                    }

                                    DB.MessageQueue queueMessage = null;

                                    var queueState = DB.MessageStateType.NotProcessed;
                                    if (message.IsComplete)
                                    {
                                        queueState = DB.MessageStateType.Complete;
                                    }
                                    if (message.IsError)
                                    {
                                        queueState = DB.MessageStateType.Error;
                                    }

                                    try
                                    {
                                        var mess = new DB.MessageQueue()
                                        {
                                            IdMessageType = IdMessageType,
                                            Direction     = true,
                                            State         = message.State,
                                            StateType     = DB.MessageStateType.IntermediateAdded,
                                            DateCreate    = DateTime.Now,
                                            DateDelayed   = message.DateDelayed,
                                            MessageInfo   = Newtonsoft.Json.JsonConvert.SerializeObject(message.Message),
                                        };

                                        db.MessageQueue.Add(mess);
                                        db.SaveChanges();

                                        queueMessage = mess;
                                    }
                                    catch (Exception ex)
                                    {
                                        this.RegisterServiceEvent(Journaling.EventType.Error, $"Ошибка регистрации сообщения после '{nameof(componentInfo.Component.OnBeginReceive)}'", $"Ошибка регистрации сообщения после вызова '{nameof(componentInfo.Component.OnBeginReceive)}' для компонента '{componentInfo?.Component?.GetType()?.FullName}'.", ex);
                                        try
                                        {
                                            componentInfo.Component.OnEndReceive(false, message, this);
                                        }
                                        catch (Exception ex2)
                                        {
                                            this.RegisterServiceEvent(Journaling.EventType.Error, $"Ошибка вызова '{nameof(componentInfo.Component.OnBeginReceive)}'", $"Ошибка вызова '{nameof(componentInfo.Component.OnBeginReceive)}' для компонента '{componentInfo?.Component?.GetType()?.FullName}' после ошибки регистрации сообщения.", ex2);
                                        }
                                        continue;
                                    }

                                    try
                                    {
                                        var endReceiveResult = componentInfo.Component.OnEndReceive(true, message, this);
                                        if (endReceiveResult)
                                        {
                                            queueMessage.StateType = queueState;
                                        }
                                        else
                                        {
                                            db.MessageQueue.Remove(queueMessage);
                                        }
                                        db.SaveChanges();
                                    }
                                    catch (Exception ex)
                                    {
                                        this.RegisterServiceEvent(Journaling.EventType.Error, $"Ошибка вызова '{nameof(componentInfo.Component.OnBeginReceive)}'", $"Ошибка вызова '{nameof(componentInfo.Component.OnBeginReceive)}' для компонента '{componentInfo?.Component?.GetType()?.FullName}' после успешной регистрации сообщения.", ex);
                                    }

                                    if (DateTimeOffset.Now >= timeEnd)
                                    {
                                        break;
                                    }
                                }
                            }
                            catch (Exception ex)
                            {
                                this.RegisterServiceEvent(Journaling.EventType.Error, $"Ошибка вызова '{nameof(componentInfo.Component.OnBeginReceive)}'", $"Ошибка вызова '{nameof(componentInfo.Component.OnBeginReceive)}' для компонента '{componentInfo?.Component?.GetType()?.FullName}'.", ex);
                                continue;
                            }
                        }
                        db.SaveChanges();
                        scope.Complete();
                    }
                }

                if (messagesReceived > 0)
                {
                    this.RegisterServiceState(ServiceStatus.RunningIdeal, $"Сообщений получено - {messagesReceived}.");
                }

                var service = AppCore.Get <Monitor>().GetService(ServiceID);
                if (service != null && (DateTime.Now - service.LastDateEvent).TotalHours >= 1)
                {
                    this.RegisterServiceState(ServiceStatus.RunningIdeal, $"Сообщений нет, сервис работает без ошибок.");
                }
            }
            catch (Exception ex)
            {
                this.RegisterServiceState(ServiceStatus.RunningWithErrors, $"Сообщений получено - {messagesReceived}.", ex);
            }
            finally
            {
                _executingFlags.ReleaseLock(TasksIncomingReceive);
            }
        }
Esempio n. 11
0
        void IMessagingServiceInternal.PrepareOutcoming(TimeSpan executeInterval)
        {
            if (AppCore.GetState() != CoreComponentState.Started)
            {
                return;
            }

            var type = GetType();

            if (!_executingFlags.TryLock(TasksOutcomingSend))
            {
                return;
            }
            _executingFlags.ReleaseLock(nameof(RegisterOutcomingMessage));

            int messagesAll    = 0;
            int messagesSent   = 0;
            int messagesErrors = 0;

            try
            {
                using (var db = new DB.DataContext())
                    using (var scope = db.CreateScope(TransactionScopeOption.Suppress)) // Здесь Suppress вместо RequiresNew, т.к. весь процесс отправки занимает много времени и блокировать таблицу нельзя.
                    {
                        var timeEnd = DateTimeOffset.Now.Add(executeInterval);
                        while (DateTimeOffset.Now < timeEnd)
                        {
                            var messages = GetMessages(db, false, 100, _outcomingQueueInfo);
                            if (messages.IsNullOrEmpty())
                            {
                                break;
                            }
                            messagesAll += messages.Count;

                            OnBeforeExecuteOutcoming(messagesAll);

                            var processedMessages = new List <IntermediateStateMessage <TMessage> >();

                            var time = new MeasureTime();
                            foreach (var intermediateMessage in messages)
                            {
                                if (DateTimeOffset.Now >= timeEnd)
                                {
                                    break;
                                }

                                if (intermediateMessage.MessageSource.StateType == DB.MessageStateType.Error)
                                {
                                    processedMessages.Add(intermediateMessage);
                                    continue;
                                }

                                var components = GetComponents().
                                                 OfType <OutcomingMessageSender <TMessage> >().
                                                 Select(x => new
                                {
                                    Component       = x,
                                    IdTypeComponent = ItemTypeFactory.GetItemType(x.GetType())?.IdItemType
                                }).
                                                 OrderBy(x => ((IPoolObjectOrdered)x.Component).OrderInPool).
                                                 ToList();

                                if (intermediateMessage.MessageSource.IdTypeComponent.HasValue)
                                {
                                    components = components.Where(x => x.IdTypeComponent.HasValue && x.IdTypeComponent == intermediateMessage.MessageSource.IdTypeComponent).ToList();
                                }

                                foreach (var componentInfo in components)
                                {
                                    try
                                    {
                                        var component       = componentInfo.Component;
                                        var messageInfo     = new MessageInfo <TMessage>(intermediateMessage);
                                        var componentResult = component.OnSend(messageInfo, this);
                                        if (componentResult != null)
                                        {
                                            intermediateMessage.MessageSource.DateChange = DateTime.Now;
                                            switch (componentResult.StateType)
                                            {
                                            case MessageStateType.Completed:
                                                intermediateMessage.MessageSource.StateType       = DB.MessageStateType.Complete;
                                                intermediateMessage.MessageSource.State           = null;
                                                intermediateMessage.MessageSource.IdTypeComponent = null;
                                                intermediateMessage.MessageSource.DateDelayed     = null;
                                                break;

                                            case MessageStateType.Delayed:
                                                intermediateMessage.MessageSource.StateType       = DB.MessageStateType.NotProcessed;
                                                intermediateMessage.MessageSource.State           = componentResult.State;
                                                intermediateMessage.MessageSource.IdTypeComponent = null;
                                                intermediateMessage.MessageSource.DateDelayed     = componentResult.DateDelayed;
                                                break;

                                            case MessageStateType.Repeat:
                                                intermediateMessage.MessageSource.StateType       = DB.MessageStateType.Repeat;
                                                intermediateMessage.MessageSource.State           = componentResult.State;
                                                intermediateMessage.MessageSource.IdTypeComponent = componentInfo.IdTypeComponent;
                                                intermediateMessage.MessageSource.DateDelayed     = componentResult.DateDelayed;
                                                break;

                                            case MessageStateType.Error:
                                                intermediateMessage.MessageSource.StateType       = DB.MessageStateType.Error;
                                                intermediateMessage.MessageSource.State           = componentResult.State;
                                                intermediateMessage.MessageSource.IdTypeComponent = null;
                                                intermediateMessage.MessageSource.DateDelayed     = componentResult.DateDelayed;
                                                break;
                                            }
                                            messagesSent++;
                                            processedMessages.Add(intermediateMessage);
                                            break;
                                        }
                                    }
                                    catch
                                    {
                                        messagesErrors++;
                                        continue;
                                    }
                                }

                                _outcomingQueueInfo.IdQueueCurrent = intermediateMessage.MessageSource.IdQueue;

                                if (time.Calculate(false).TotalSeconds >= 3)
                                {
                                    db.SaveChanges();
                                    processedMessages.Clear();
                                    time.Start();
                                }
                            }

                            if (processedMessages.Count > 0)
                            {
                                db.SaveChanges();
                            }
                        }

                        db.SaveChanges();
                        scope.Complete();
                    }
            }
            catch (Exception ex)
            {
                this.RegisterServiceState(ServiceStatus.RunningWithErrors, $"Сообщений получено для отправки - {messagesAll}. Отправлено - {messagesSent}. Ошибки отправки - {messagesErrors}.", ex);
            }
            finally
            {
                _executingFlags.ReleaseLock(TasksOutcomingSend);
            }
        }
Esempio n. 12
0
        public virtual ActionResult RoutingModule(int IdModule)
        {
            if (IdModule <= 0)
            {
                throw new Exception("Не указан идентификатор модуля.");
            }
            var module = AppCore.GetModulesManager().GetModule(IdModule);

            if (module == null)
            {
                throw new Exception($"Не получилось найти модуль с указанным идентификатором {IdModule}.");
            }

            var model = new Model.RoutingModule()
            {
                Module = (IModuleCore)module
            };

            using (var db = new UnitOfWork <Routing, RoutingType>())// Module.CreateUnitOfWork())
            {
                model.RoutingTypes = db.Repo2.OrderBy(x => x.NameTranslationType).Select(x => new SelectListItem()
                {
                    Value = x.IdTranslationType.ToString(), Text = x.NameTranslationType
                }).ToList();

                var moduleActionAttributeType  = typeof(ModuleActionAttribute);
                var moduleActionGetDisplayName = new Func <ActionDescriptor, string>(action =>
                {
                    var attr = action.GetCustomAttributes(moduleActionAttributeType, true).OfType <ModuleActionAttribute>().FirstOrDefault();
                    if (attr != null)
                    {
                        if (!string.IsNullOrEmpty(attr.Caption))
                        {
                            return(attr.Caption);
                        }
                    }

                    return(action.ActionName);
                });

                var modulesActions = AppCore.GetModulesManager().GetModules().OfType <IModuleCore>().Select(x => new
                {
                    Module          = x,
                    UserDescriptor  = x.ControllerUser() != null ? new ReflectedControllerDescriptor(x.ControllerUser()) : null,
                    AdminDescriptor = x.ControllerAdmin() != null ? new ReflectedControllerDescriptor(x.ControllerAdmin()) : null,
                }).Select(x => new
                {
                    x.Module,
                    UserActions  = x.UserDescriptor != null ? x.UserDescriptor.GetCanonicalActions().Where(y => y.IsDefined(moduleActionAttributeType, true)).ToDictionary(y => y.ActionName, y => "Общее: " + moduleActionGetDisplayName(y)) : new Dictionary <string, string>(),
                    AdminActions = x.AdminDescriptor != null ? x.AdminDescriptor.GetCanonicalActions().Where(y => y.IsDefined(moduleActionAttributeType, true)).ToDictionary(y => y.ActionName, y => "Администрирование: " + moduleActionGetDisplayName(y)) : new Dictionary <string, string>(),
                }).ToDictionary(x => x.Module, x => x.UserActions.Merge(x.AdminActions).OrderBy(y => y.Value).ToDictionary(y => y.Key, y => y.Value));

                model.ModulesActions = modulesActions.
                                       Select(x => new { Group = new SelectListGroup()
                                                         {
                                                             Name = x.Key.Caption
                                                         }, Items = x.Value, Module = x.Key }).
                                       SelectMany(x => x.Items.Select(y => new SelectListItem()
                {
                    Text = y.Value, Value = $"{x.Module.IdModule}_{y.Key}", Group = x.Group
                })).ToList();

                model.Routes = db.Repo1
                               .Where(x => x.IdModule == module.ID)
                               .OrderBy(x => x.IdRoutingType)
                               .ToList()
                               .Select(x => new { Route = x, Item = ItemTypeFactory.GetItemOfType(x.IdItemType, x.IdItem) })
                               .Select(x => new Model.RouteInfo()
                {
                    Route = x.Route, ItemName = x.Route.IdItem > 0 ? (x.Item != null ? x.Item.ToString() : "Не найден") : "Без объекта"
                })
                               .ToList();
            }

            return(View("routing_module.cshtml", model));
        }