public ActionResult Sitemap() { var sitemapProviderTypes = AppCore.GetQueryTypes().Where(x => typeof(ISitemapProvider).IsAssignableFrom(x)).ToList(); var providerList = sitemapProviderTypes.Select(x => { var p = new Design.Model.SitemapProvider() { NameProvider = "", TypeName = x.FullName, IsCreatedNormally = false }; try { var pp = AppCore.Create <ISitemapProvider>(x); p.NameProvider = pp.NameProvider; p.IsCreatedNormally = true; } catch (Exception ex) { p.TypeName = ex.ToString(); p.IsCreatedNormally = false; } return(p); }).ToList(); return(View("Sitemap.cshtml", new Design.Model.Sitemap() { ProviderList = providerList })); }
private void Execute() { try { var sitemapProviderTypes = AppCore.GetQueryTypes().Where(x => typeof(ISitemapProvider).IsAssignableFrom(x)).ToList(); var providerList = sitemapProviderTypes.Select(x => { try { return(AppCore.Create <ISitemapProvider>(x)); } catch { return(null); } }).Where(x => x != null).ToList(); var linksAll = providerList.SelectMany(x => x.GetItems() ?? new List <SitemapItem>()).ToList(); var module = AppCore.GetModulesManager().GetModule <ModuleSitemap>(); var code = WebUtils.RazorRenderHelper.RenderView(module, "SitemapXml.cshtml", linksAll); var path = System.IO.Path.Combine(OnUtils.LibraryEnumeratorFactory.LibraryDirectory, "data/sitemap.xml"); System.IO.File.WriteAllText(path, code); } catch (Exception ex) { this.RegisterEvent(Journaling.EventType.CriticalError, "Ошибка построения карты сайта", null, ex); } }
protected override void OnStarted() { try { using (var ctx = AppCore.Create <context>()) { var dd = ctx.Test. WithMetadataObjectProperties(). AsNoTracking(). Take(2). ToList(); var ddd = new Realty(); ctx.Test.Attach(ddd); } } catch (Exception ex) { } }
private void ExecuteInternal() { if (_isExecuting) { return; } try { _isExecuting = true; var sitemapProviderTypes = AppCore.GetQueryTypes().Where(x => typeof(ISitemapProvider).IsAssignableFrom(x)).ToList(); var providerList = sitemapProviderTypes.Select(x => { try { return(AppCore.Create <ISitemapProvider>(x)); } catch { return(null); } }).Where(x => x != null).ToList(); var linksAll = providerList.SelectMany(x => x.GetItems() ?? new List <SitemapItem>()).ToList(); var module = AppCore.GetModulesManager().GetModule <ModuleSitemap>(); var code = WebUtils.RazorRenderHelper.RenderView(module, "SitemapXml.cshtml", linksAll); var path = System.IO.Path.Combine(OnUtils.LibraryEnumeratorFactory.LibraryDirectory, "sitemap.xml"); System.IO.File.WriteAllText(path, code); } finally { _isExecuting = false; } }
/// <summary> /// Пересоздает текущий используемый список компонентов с учетом настроек. Рекомендуется к использованию в случае изменения настроек. /// </summary> /// <see cref="Core.Configuration.CoreConfiguration.MessagingServicesComponentsSettings"/> public void UpdateComponentsFromSettings() { lock (_activeComponentsSyncRoot) { if (_activeComponents != null) { _activeComponents.ForEach(x => { try { x.Stop(); } catch (Exception ex) { this.RegisterEvent(EventType.Error, "Ошибка при закрытии компонента", $"Возникла ошибка при выгрузке компонента типа '{x.GetType().FullName}'.", null, ex); } }); } _activeComponents = new List <IComponentTransient>(); var settings = AppCore.AppConfig.MessagingServicesComponentsSettings; if (settings != null) { var types = AppCore. GetQueryTypes(). Select(x => new { Type = x, Extracted = TypeHelpers.ExtractGenericType(x, typeof(MessagingServiceComponent <>)) }). Where(x => x.Extracted != null). Select(x => new { x.Type, MessageType = x.Extracted.GetGenericArguments()[0] }). ToList(); foreach (var setting in settings) { var type = types.FirstOrDefault(x => x.Type.FullName == setting.TypeFullName); if (type == null) { this.RegisterEvent(EventType.Error, "Ошибка при поиске компонента", $"Не найден тип компонента из настроек - '{setting.TypeFullName}'. Для стирания старых настроек следует зайти в настройку компонентов и сделать сохранение."); continue; } try { var allowed = true; var instance = AppCore.Create <IComponentTransient>(type.Type, component => { ((IInternal)component).SerializedSettings = setting.SettingsSerialized; allowed = ((IInternal)component).OnStartComponent(); }); if (allowed) { _activeComponents.Add(instance); } else { this.RegisterEvent(EventType.Error, "Отказ инициализации компонента", $"Компонент типа '{setting.TypeFullName}' ('{instance.GetType().FullName}') вернул отказ инициализации. См. журналы ошибок для поиска возможной информации."); } } catch (Exception ex) { this.RegisterEvent(EventType.Error, "Ошибка создания компонента", $"Во время создания и инициализации компонента типа '{setting.TypeFullName}' возникла неожиданная ошибка.", null, ex.InnerException); } } } } }
IEnumerable <IMigration> IFilteringMigrationSource.GetMigrations(Func <Type, bool> predicate) { var dbSchemaManagerConfigure = AppCore.Get <DbSchemaManagerConfigure>(); var dbSchemaItemTypes = AppCore.GetQueryTypes().Where(x => typeof(DbSchemaItem).IsAssignableFrom(x)); dbSchemaItemTypes = dbSchemaItemTypes.Where(predicate); var dbSchemaItemList = dbSchemaItemTypes.Select(x => AppCore.Create <DbSchemaItem>(x)).OrderBy(x => x is DbSchemaItem).ToList(); var moved = new Dictionary <object, int>(); for (int i = 0; i < dbSchemaItemList.Count; i++) { var item = dbSchemaItemList[i]; if (!(item is DbSchemaItem schemaItem)) { continue; } var dependsOn = schemaItem.SchemaItemTypeDependsOn; if (dependsOn.IsNullOrEmpty()) { continue; } int dependencyIndexMax = -1; foreach (var dependencyType in dependsOn) { var isFound = false; for (int j = 0; j < dbSchemaItemList.Count; j++) { var itemDependency = dbSchemaItemList[j]; if (itemDependency.GetType() == dependencyType) { isFound = true; dependencyIndexMax = Math.Max(j, dependencyIndexMax); break; } } if (!isFound) { throw new InvalidProgramException($"Не найдена зависимость '{dependencyType.FullName}' для миграции '{schemaItem.GetType().FullName}'."); } } if (dependencyIndexMax > i) { if (!moved.ContainsKey(item)) { moved[item] = 0; } if (moved[item] > dbSchemaItemList.Count * dbSchemaItemList.Count) { throw new InvalidProgramException($"Обнаружена циклическая зависимость типа '{item.GetType().FullName}' от некоторых других. Проверьте цепочку зависимости dependsOn."); } dbSchemaItemList.RemoveAt(i); dbSchemaItemList.Insert(dependencyIndexMax, item); moved[item]++; i = -1; } } var dbSchemaItemListFiltered = dbSchemaItemList.Where(x => x.GetType() == typeof(DbSchemaDefaultMigration) || x.GetType() == typeof(DbSchemaDefaultProfile) || dbSchemaManagerConfigure.FilterMigration(x)).ToList(); return(dbSchemaItemListFiltered); }