197 lines
7.3 KiB
C#
197 lines
7.3 KiB
C#
|
|
using System;
|
|||
|
|
using System.Globalization;
|
|||
|
|
using System.IO;
|
|||
|
|
using System.Linq;
|
|||
|
|
using System.Text.Json;
|
|||
|
|
using System.Threading.Tasks;
|
|||
|
|
using Kurs.Languages.Entities;
|
|||
|
|
using Kurs.Platform.Charts.Dto;
|
|||
|
|
using Kurs.Platform.Entities;
|
|||
|
|
using Kurs.Platform.ListForms;
|
|||
|
|
using Kurs.Platform.Seeds;
|
|||
|
|
using Kurs.Settings.Entities;
|
|||
|
|
using Microsoft.Extensions.Configuration;
|
|||
|
|
using Volo.Abp.Data;
|
|||
|
|
using Volo.Abp.DependencyInjection;
|
|||
|
|
using Volo.Abp.Domain.Repositories;
|
|||
|
|
|
|||
|
|
namespace Kurs.Platform.Data.Seeds;
|
|||
|
|
|
|||
|
|
public class PlatformDataSeeder : IDataSeedContributor, ITransientDependency
|
|||
|
|
{
|
|||
|
|
private readonly IRepository<Language, Guid> _languages;
|
|||
|
|
private readonly IRepository<LanguageKey, Guid> _languageKey;
|
|||
|
|
private readonly IRepository<LanguageText, Guid> _languagesText;
|
|||
|
|
private readonly IRepository<DataSource, Guid> _dataSources;
|
|||
|
|
private readonly IRepository<SettingDefinition, Guid> _settings;
|
|||
|
|
private readonly IRepository<Chart> _charts;
|
|||
|
|
|
|||
|
|
public PlatformDataSeeder(
|
|||
|
|
IRepository<Language, Guid> languages,
|
|||
|
|
IRepository<LanguageKey, Guid> languageKey,
|
|||
|
|
IRepository<LanguageText, Guid> languagesText,
|
|||
|
|
IRepository<DataSource, Guid> dataSource,
|
|||
|
|
IRepository<SettingDefinition, Guid> settings,
|
|||
|
|
IRepository<Chart> charts)
|
|||
|
|
{
|
|||
|
|
_languages = languages;
|
|||
|
|
_languageKey = languageKey;
|
|||
|
|
_languagesText = languagesText;
|
|||
|
|
_dataSources = dataSource;
|
|||
|
|
_settings = settings;
|
|||
|
|
_charts = charts;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
public async Task SeedAsync(DataSeedContext context)
|
|||
|
|
{
|
|||
|
|
var settings = await _settings.GetListAsync();
|
|||
|
|
var dataSources = await _dataSources.GetListAsync();
|
|||
|
|
var languages = await _languages.GetListAsync();
|
|||
|
|
var keys = await _languageKey.GetListAsync();
|
|||
|
|
var texts = await _languagesText.GetListAsync();
|
|||
|
|
var charts = await _charts.GetListAsync();
|
|||
|
|
|
|||
|
|
var configuration = new ConfigurationBuilder()
|
|||
|
|
.SetBasePath(Directory.GetCurrentDirectory())
|
|||
|
|
.AddJsonFile(Path.Combine("Seeds", "SeederData.json"))
|
|||
|
|
.AddJsonFile(Path.Combine("Seeds", $"SeederData.{Environment.GetEnvironmentVariable("DOTNET_ENVIRONMENT") ?? ""}.json"), true)
|
|||
|
|
.Build();
|
|||
|
|
var items = configuration.Get<SeederDto>();
|
|||
|
|
|
|||
|
|
foreach (var item in items.Charts)
|
|||
|
|
{
|
|||
|
|
if (!charts.Any(a => a.ChartCode == item.ChartCode))
|
|||
|
|
{
|
|||
|
|
await _charts.InsertAsync(new()
|
|||
|
|
{
|
|||
|
|
ChartCode = item.ChartCode,
|
|||
|
|
CultureName = item.CultureName,
|
|||
|
|
DataSourceCode = item.DataSourceCode,
|
|||
|
|
UserId = item.UserId,
|
|||
|
|
RoleId = item.RoleId,
|
|||
|
|
TitleJson = JsonSerializer.Serialize(new ChartTitleDto
|
|||
|
|
{
|
|||
|
|
Text = item.Title.Text,
|
|||
|
|
Subtitle = item.Title.Subtitle,
|
|||
|
|
}),
|
|||
|
|
DataSourceJson = JsonSerializer.Serialize(new ChartDataSourceDto
|
|||
|
|
{
|
|||
|
|
Query = item.DataSource.Query
|
|||
|
|
}),
|
|||
|
|
SeriesJson = JsonSerializer.Serialize(item.Series),
|
|||
|
|
CrosshairJson = JsonSerializer.Serialize(new ChartCrosshairDto()
|
|||
|
|
{
|
|||
|
|
Enabled = item.Crosshair.Enabled,
|
|||
|
|
Color = item.Crosshair.Color,
|
|||
|
|
DashStyle = item.Crosshair.DashStyle,
|
|||
|
|
HorizontalLine = new ChartCrosshairLineDto() { DashStyle = item.Crosshair.HorizontalLine.DashStyle }
|
|||
|
|
}),
|
|||
|
|
ArgumentAxisJson = JsonSerializer.Serialize(new ChartArgumentAxisDto()
|
|||
|
|
{
|
|||
|
|
Label = item.ArgumentAxis.Label
|
|||
|
|
}),
|
|||
|
|
SizeJson = JsonSerializer.Serialize(new ChartSizeDto
|
|||
|
|
{
|
|||
|
|
Width = item.Size.Width,
|
|||
|
|
Height = item.Size.Height
|
|||
|
|
}),
|
|||
|
|
PermissionJson = JsonSerializer.Serialize(new PermissionCrudDto
|
|||
|
|
{
|
|||
|
|
C = item.Permission.C,
|
|||
|
|
R = item.Permission.R,
|
|||
|
|
U = item.Permission.U,
|
|||
|
|
D = item.Permission.D
|
|||
|
|
}),
|
|||
|
|
});
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
foreach (var item in items.Settings)
|
|||
|
|
{
|
|||
|
|
if (!settings.Any(a => a.Code == item.Code))
|
|||
|
|
{
|
|||
|
|
await _settings.InsertAsync(new()
|
|||
|
|
{
|
|||
|
|
Code = item.Code,
|
|||
|
|
NameKey = item.NameKey,
|
|||
|
|
DescriptionKey = item.DescriptionKey,
|
|||
|
|
DefaultValue = item.DefaultValue.Replace("\r\n", Environment.NewLine),
|
|||
|
|
IsVisibleToClients = item.IsVisibleToClients,
|
|||
|
|
IsInherited = item.IsInherited,
|
|||
|
|
IsEncrypted = item.IsEncrypted,
|
|||
|
|
MainGroupKey = item.MainGroupKey,
|
|||
|
|
SubGroupKey = item.SubGroupKey,
|
|||
|
|
RequiredPermissionName = item.RequiredPermissionName,
|
|||
|
|
DataType = item.DataType,
|
|||
|
|
Providers = item.Providers,
|
|||
|
|
SelectOptions = item.SelectOptions,
|
|||
|
|
Order = item.Order
|
|||
|
|
});
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
foreach (var item in items.DataSources)
|
|||
|
|
{
|
|||
|
|
if (!dataSources.Any(a => a.Code == item.Code))
|
|||
|
|
{
|
|||
|
|
await _dataSources.InsertAsync(new()
|
|||
|
|
{
|
|||
|
|
Code = item.Code,
|
|||
|
|
DataSourceType = item.DataSourceType,
|
|||
|
|
ConnectionString = item.ConnectionString
|
|||
|
|
});
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
foreach (var item in items.Languages)
|
|||
|
|
{
|
|||
|
|
if (!languages.Any(a => a.CultureName == item.CultureName))
|
|||
|
|
{
|
|||
|
|
await _languages.InsertAsync(new()
|
|||
|
|
{
|
|||
|
|
CultureName = item.CultureName,
|
|||
|
|
UiCultureName = item.UiCultureName,
|
|||
|
|
DisplayName = item.DisplayName,
|
|||
|
|
IsEnabled = item.IsEnabled,
|
|||
|
|
TwoLetterISOLanguageName = new CultureInfo(item.CultureName).TwoLetterISOLanguageName,
|
|||
|
|
MultipleCultures = item.MultipleCultures,
|
|||
|
|
});
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
foreach (var item in items.LanguageTexts)
|
|||
|
|
{
|
|||
|
|
if (!keys.Any(a => a.Key == item.Key))
|
|||
|
|
{
|
|||
|
|
await _languageKey.InsertAsync(new()
|
|||
|
|
{
|
|||
|
|
Key = item.Key,
|
|||
|
|
ResourceName = item.ResourceName,
|
|||
|
|
});
|
|||
|
|
}
|
|||
|
|
if (!texts.Any(a => a.CultureName == "en" && a.Key == item.Key))
|
|||
|
|
{
|
|||
|
|
await _languagesText.InsertAsync(new()
|
|||
|
|
{
|
|||
|
|
CultureName = "en",
|
|||
|
|
Key = item.Key,
|
|||
|
|
Value = item.En,
|
|||
|
|
ResourceName = item.ResourceName,
|
|||
|
|
});
|
|||
|
|
}
|
|||
|
|
if (!texts.Any(a => a.CultureName == "tr" && a.Key == item.Key))
|
|||
|
|
{
|
|||
|
|
|
|||
|
|
await _languagesText.InsertAsync(new()
|
|||
|
|
{
|
|||
|
|
CultureName = "tr",
|
|||
|
|
Key = item.Key,
|
|||
|
|
Value = item.Tr,
|
|||
|
|
ResourceName = item.ResourceName,
|
|||
|
|
});
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|