1+ @implements IAsyncDisposable
12@inject IConfigurationSettingFactory ConfigurationSettingFactory
23@inject IConfigurationSettingRepository ConfigurationSettingRepository
4+ @inject IJSRuntime JS
35@inject IKeyValuePairJsonDecoder KeyValuePairJsonDecoder
6+ @inject IKeyValuePairJsonEncoder KeyValuePairJsonEncoder
47@page " /kvdata"
8+ @using System .Net
59@using System .Security .Cryptography
610@using System .Text
711@using System .Text .Json
2125 <EditForm class =" flex flex-col gap-10" Model =" @Model" OnSubmit =" @HandleSubmit" >
2226 @switch (Model?.Operation)
2327 {
28+ case ImportExportOperationInputRadioGroup .Operation .Export :
29+ <div class =" flex flex-col gap-3" >
30+ <ImportExportOperationInputRadioGroup @bind-Value =" @Model.Operation" name =" @nameof(Model.Operation)" />
31+
32+ <label class =" flex flex-row items-center" >
33+ <div class =" w-[200px]" >Target type </div >
34+ <div class =" flex-1 max-w-[600px]" >
35+ <ImportExportTargetTypeInputSelect @bind-Value =" @Model.TargetType" name =" @nameof(Model.TargetType)" />
36+ </div >
37+ </label >
38+ </div >
39+
40+ switch (Model .TargetType )
41+ {
42+ case ImportExportTargetTypeInputSelect .TargetType .ConfigurationFile :
43+ < div class = " flex flex-col gap-3" >
44+ < div class = " font-bold text-lg" > Export options < / div >
45+
46+ < label class = " flex flex-row items-center" >
47+ < div class = " w-[200px]" > File format < / div >
48+ < div class = " flex-1 max-w-[600px]" >
49+ < ImportExportFileFormatInputSelect @bind - Value = " @Model.FileFormat" name = " @nameof(Model.FileFormat)" / >
50+ < / div >
51+ < / label >
52+ < / div >
53+
54+ if (Model .FileFormat is not null )
55+ {
56+ < div class = " flex flex-col gap-3" >
57+ < div class = " font-bold text-lg" > Apply changes to key - values < / div >
58+
59+ < label class = " flex flex-row items-center" >
60+ < div class = " w-[200px]" > Separator < / div >
61+ < div class = " flex-1 max-w-[600px]" >
62+ < ImportExportSeparatorInputSelect @bind - Value = " @Model.Separator" name = " @nameof(Model.Separator)" / >
63+ < / div >
64+ < / label >
65+
66+ < label class = " flex flex-row items-center" >
67+ < div class = " w-[200px]" > Remove prefix < / div >
68+ < div class = " flex-1 max-w-[600px]" >
69+ < AzureInputText @bind - Value = " @Model.Prefix" name = " @nameof(Model.Prefix)" / >
70+ < / div >
71+ < / label >
72+ < / div >
73+
74+ < div >
75+ < AzureButton Appearance = " AzureButton.AzureAppearance.Primary" type = " submit" > Export < / AzureButton >
76+ < / div >
77+ }
78+
79+ break ;
80+ }
81+
82+ break ;
2483 case ImportExportOperationInputRadioGroup .Operation .Import :
2584 <div class =" flex flex-col gap-3" >
2685 <ImportExportOperationInputRadioGroup @bind-Value =" @Model.Operation" name =" @nameof(Model.Operation)" />
86145 < / div >
87146
88147 < div >
89- < AzureButton Appearance = " AzureButton.AzureAppearance.Primary" type = " submit" > @( Model . Operation switch { ImportExportOperationInputRadioGroup . Operation . Export => " Export " , ImportExportOperationInputRadioGroup . Operation . Import => " Import " , _ => throw new ArgumentOutOfRangeException () }) < / AzureButton >
148+ < AzureButton Appearance = " AzureButton.AzureAppearance.Primary" type = " submit" > Import < / AzureButton >
90149 < / div >
91150 }
92151
148207 < / div >
149208
150209 < div >
151- < AzureButton Appearance = " AzureButton.AzureAppearance.Primary" type = " submit" > @( Model . Operation switch { ImportExportOperationInputRadioGroup . Operation . Export => " Export " , ImportExportOperationInputRadioGroup . Operation . Import => " Import " , _ => throw new ArgumentOutOfRangeException () }) < / AzureButton >
210+ < AzureButton Appearance = " AzureButton.AzureAppearance.Primary" type = " submit" > Import < / AzureButton >
152211 < / div >
153212 }
154213
166225
167226 private ICollection <string ? > Labels { get ; } = [];
168227
228+ private IJSObjectReference ? Module { get ; set ; }
229+
230+ public async ValueTask DisposeAsync ()
231+ {
232+ if (Module is not null )
233+ {
234+ await Module .DisposeAsync ();
235+ }
236+ }
237+
238+ protected override async Task OnAfterRenderAsync (bool firstRender )
239+ {
240+ if (firstRender )
241+ {
242+ Module = await JS .InvokeAsync <IJSObjectReference >(" import" , " ./Components/Pages/ImportExport.razor.js" );
243+ }
244+ }
245+
169246 protected override void OnInitialized ()
170247 {
171248 Model ??= new InputModel ();
218295
219296 switch (Model ? .Operation )
220297 {
298+ case ImportExportOperationInputRadioGroup .Operation .Export :
299+ {
300+ switch (Model ? .TargetType )
301+ {
302+ case ImportExportTargetTypeInputSelect .TargetType .ConfigurationFile :
303+ {
304+ using var document = KeyValuePairJsonEncoder .Encode (await ConfigurationSettingRepository .Get ().Where (setting => setting is not FeatureFlagConfigurationSetting ).ToDictionaryAsync (setting => setting .Key , setting => setting .Value ), Model .Prefix , Model .Separator );
305+
306+ if (Module is not null )
307+ {
308+ await Module .InvokeVoidAsync (" download" , $" {Dns .GetHostName ()}-{DateTimeOffset .UtcNow : yyyy - MM - dd }.json" , Convert .ToBase64String (JsonSerializer .SerializeToUtf8Bytes (document )));
309+ }
310+
311+ Model = new InputModel ();
312+
313+ break ;
314+ }
315+ }
316+
317+ break ;
318+ }
221319 case ImportExportOperationInputRadioGroup .Operation .Import :
222320 {
223321 switch (Model ? .SourceType )
284382 destinationSetting .Etag = Convert .ToBase64String (SHA256 .HashData (Encoding .UTF8 .GetBytes (date .UtcDateTime .ToString (" yyyy-MM-dd HH:mm:ss" ))));
285383 destinationSetting .LastModified = date ;
286384 destinationSetting .ContentType = Model .ContentType ;
287- destinationSetting .Value = sourceValue ? . ToString () ;
385+ destinationSetting .Value = sourceValue ;
288386
289387 await ConfigurationSettingRepository .Update (destinationSetting );
290388 }
334432 public IBrowserFile ? SourceFile { get ; set ; }
335433
336434 public string ? SourceType { get ; set ; }
435+
436+ public string ? TargetType { get ; set ; }
337437 }
338438
339439}
0 commit comments