Commit 4e22790c authored by Rene Hampölz's avatar Rene Hampölz 💻

Fix json parser, code cleanup

parent 2e6fe03f
......@@ -30,7 +30,7 @@
ShowTitleBar="False"
ShowInTaskbar="False">
<Grid>
<Image HorizontalAlignment="Left" Margin="35,35,0,35" Width="200" Source="Assets\favicon.png"/>
<Image x:Name="Image" HorizontalAlignment="Left" Margin="35,35,0,35" Width="200" Source="Assets\favicon.png"/>
<TextBlock HorizontalAlignment="Left" Margin="260,30,0,0" TextWrapping="Wrap" Text="{x:Static local:App.Name}" VerticalAlignment="Top" FontSize="36" FontWeight="Bold"/>
<TextBlock Margin="260,90,0,10" TextWrapping="WrapWithOverflow" FontSize="14" xml:space="preserve" HorizontalAlignment="Left" Width="466"><Hyperlink Foreground="White" Click="Website_Click"><TextBlock Text="{x:Static local:App.Name}"/></Hyperlink> wird entwickelt und gestaltet von <Hyperlink Foreground="White" Click="DeveloperWebsite_Click"><TextBlock Text="{x:Static local:App.Developer}"/></Hyperlink>.<LineBreak/><LineBreak/>Dieses Projekt benutzt das <Hyperlink Foreground="White" Click="MainProgramm_Click">Main Programm</Hyperlink> von <Hyperlink Foreground="White" Click="RHUtensils_Click">RH Utensils</Hyperlink>, für ein vereinfachtes Account Management, für eine vereinfachte Update auslieferung und für eine einfache darstellung des Programmes.<LineBreak/><LineBreak/>Weitere Informationen zum Source Code sowie zur Lizenzierung findest du<LineBreak/> fürs Main Programm auf der <Hyperlink Foreground="White" Click="MainProgramm_Click">GitLab Seite</Hyperlink> von RH Utensils<LineBreak/> für <TextBlock Text="{x:Static local:App.Name}"/> auf unserer <Hyperlink Foreground="White" Click="SourceCode_Click">Projekt Seite</Hyperlink><LineBreak/><LineBreak/>Main Programm Copyright © <TextBlock Text="{Binding Source={x:Static sys:DateTime.Now}, StringFormat=yyyy}"/> <Hyperlink Foreground="White" Click="HampisProjekte_Click">Hampis Projekte</Hyperlink><LineBreak/><TextBlock Text="{x:Static local:App.Name}"/> Copyright © <TextBlock Text="{Binding Source={x:Static sys:DateTime.Now}, StringFormat=yyyy}"/> <Hyperlink Foreground="White" Click="Copyright_Click"><TextBlock Text="{x:Static local:App.Copyright}"/></Hyperlink></TextBlock>
</Grid>
......
using MahApps.Metro.Controls;
using System;
using System.Windows;
using System.Windows.Media.Imaging;
namespace Main
{
......@@ -8,6 +10,18 @@ namespace Main
public About()
{
InitializeComponent();
if (App.Favicon != "")
{
try
{
Image.Source = new BitmapImage(new Uri(App.Favicon));
}
catch
{
}
}
}
private void Website_Click(object sender, RoutedEventArgs e)
......
using Auth0.OidcClient;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using RestSharp;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Windows;
namespace Main.Functions
{
......@@ -28,9 +23,7 @@ namespace Main.Functions
request.AddParameter("application/json", "{\"grant_type\":\"client_credentials\",\"client_id\": \"" + App.Auth0APIClientId + "\",\"client_secret\": \"" + App.Auth0APIClientSecret + "\",\"audience\": \"https://" + App.Auth0Domain + "/api/v2/\"}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
dynamic api = JObject.Parse(response.Content);
return api.access_token;
return Json.ConvertToString(response.Content, "access_token");
}
public static string GetTokenType()
......@@ -41,20 +34,27 @@ namespace Main.Functions
request.AddParameter("application/json", "{\"grant_type\":\"client_credentials\",\"client_id\": \"" + App.Auth0APIClientId + "\",\"client_secret\": \"" + App.Auth0APIClientSecret + "\",\"audience\": \"https://" + App.Auth0Domain + "/api/v2/\"}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
dynamic api = JObject.Parse(response.Content);
return api.token_type;
return Json.ConvertToString(response.Content, "token_type");
}
public static String ReadMetadata()
{
String AppName = App.Name.Replace(" ", "_");
var client = new RestClient("https://" + App.Auth0Domain + "/api/v2/users/" + User_ID);
var request = new RestRequest(Method.GET);
request.AddHeader("authorization", GetTokenType() + " " + GetToken());
IRestResponse response = client.Execute(request);
dynamic api = JObject.Parse(client.Execute(request).Content);
return api.app_metadata.ToString();
try
{
return Json.ConvertToString(Json.ConvertToString(response.Content, "app_metadata"), AppName);
}
catch
{
return Json.ConvertToString(response.Content, "app_metadata");
}
}
public static void SetMetadata(String jsonData)
......@@ -66,25 +66,13 @@ namespace Main.Functions
try
{
//
//Convert String Lists to jsonData
//
////String[] Parameter;
////String[] Value;
////var Data = new Dictionary<String, String>();
////for (int i = 0; i != Parameter.Length; ++i)
////{
//// Data[Parameter[i]] = Value[i];
////}
////String jsonData = JsonConvert.SerializeObject(Data);
String AppName = App.Name.Replace(" ", "_");
var client = new RestClient("https://" + App.Auth0Domain + "/api/v2/users/" + User_ID);
var request = new RestRequest(Method.PATCH);
request.AddHeader("content-type", "application/json");
request.AddHeader("authorization", GetTokenType()+ " " + GetToken());
request.AddParameter("application/json", "{\"app_metadata\": {\"" + App.Name + "\": " + jsonData + "}}", ParameterType.RequestBody);
request.AddParameter("application/json", "{\"app_metadata\": {\"" + AppName + "\": " + jsonData + "}}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
}
catch
......
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
namespace Main.Functions
{
class Json
{
public static String ConvertToJson(String[] Parameter, String[] Value)
{
var Data = new Dictionary<String, String>();
for (int i = 0; i != Parameter.Length; ++i)
{
Data[Parameter[i]] = Value[i];
}
return JsonConvert.SerializeObject(Data);
}
public static String ConvertToString(String Json, String Parameter)
{
JObject JsonData = JObject.Parse(Json);
return JsonData[Parameter].ToString();
}
}
}
......@@ -100,7 +100,9 @@ namespace Main
String[] Parameter = { "Test1","Test2" };
String[] Value = { "Test1_Value", "Test2_Value" };
Functions.Account.SetMetadata(Functions.Account.ReadMetadata());
Functions.Account.SetMetadata(Functions.Json.ConvertToJson(Parameter, Value));
MessageBox.Show(Functions.Json.ConvertToString(Functions.Account.ReadMetadata(), "Test1"));
if (Application.Current.MainWindow is MainWindow MW)
{
......
......@@ -262,6 +262,7 @@
</Compile>
<Compile Include="Functions\Account.cs" />
<Compile Include="Functions\Encryption.cs" />
<Compile Include="Functions\Json.cs" />
<Compile Include="Login.xaml.cs">
<DependentUpon>Login.xaml</DependentUpon>
</Compile>
......
No preview for this file type
#pragma checksum "..\..\About.xaml" "{ff1816ec-aa5e-4d10-87f7-6f4963833460}" "995CC9FA4345E35A50C2E109C7BFBC169BA1CFE8"
#pragma checksum "..\..\About.xaml" "{ff1816ec-aa5e-4d10-87f7-6f4963833460}" "193353D673389D0CBDF660BE9263B569D0EA232E"
//------------------------------------------------------------------------------
// <auto-generated>
// Dieser Code wurde von einem Tool generiert.
......@@ -47,6 +47,14 @@ namespace Main {
/// </summary>
public partial class About : MahApps.Metro.Controls.MetroWindow, System.Windows.Markup.IComponentConnector {
#line 33 "..\..\About.xaml"
[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1823:AvoidUnusedPrivateFields")]
internal System.Windows.Controls.Image Image;
#line default
#line hidden
private bool _contentLoaded;
/// <summary>
......@@ -78,6 +86,9 @@ namespace Main {
switch (connectionId)
{
case 1:
this.Image = ((System.Windows.Controls.Image)(target));
return;
case 2:
#line 35 "..\..\About.xaml"
((System.Windows.Documents.Hyperlink)(target)).Click += new System.Windows.RoutedEventHandler(this.Website_Click);
......@@ -85,7 +96,7 @@ namespace Main {
#line default
#line hidden
return;
case 2:
case 3:
#line 35 "..\..\About.xaml"
((System.Windows.Documents.Hyperlink)(target)).Click += new System.Windows.RoutedEventHandler(this.DeveloperWebsite_Click);
......@@ -93,7 +104,7 @@ namespace Main {
#line default
#line hidden
return;
case 3:
case 4:
#line 35 "..\..\About.xaml"
((System.Windows.Documents.Hyperlink)(target)).Click += new System.Windows.RoutedEventHandler(this.MainProgramm_Click);
......@@ -101,7 +112,7 @@ namespace Main {
#line default
#line hidden
return;
case 4:
case 5:
#line 35 "..\..\About.xaml"
((System.Windows.Documents.Hyperlink)(target)).Click += new System.Windows.RoutedEventHandler(this.RHUtensils_Click);
......@@ -109,7 +120,7 @@ namespace Main {
#line default
#line hidden
return;
case 5:
case 6:
#line 35 "..\..\About.xaml"
((System.Windows.Documents.Hyperlink)(target)).Click += new System.Windows.RoutedEventHandler(this.MainProgramm_Click);
......@@ -117,7 +128,7 @@ namespace Main {
#line default
#line hidden
return;
case 6:
case 7:
#line 35 "..\..\About.xaml"
((System.Windows.Documents.Hyperlink)(target)).Click += new System.Windows.RoutedEventHandler(this.SourceCode_Click);
......@@ -125,7 +136,7 @@ namespace Main {
#line default
#line hidden
return;
case 7:
case 8:
#line 35 "..\..\About.xaml"
((System.Windows.Documents.Hyperlink)(target)).Click += new System.Windows.RoutedEventHandler(this.HampisProjekte_Click);
......@@ -133,7 +144,7 @@ namespace Main {
#line default
#line hidden
return;
case 8:
case 9:
#line 35 "..\..\About.xaml"
((System.Windows.Documents.Hyperlink)(target)).Click += new System.Windows.RoutedEventHandler(this.Copyright_Click);
......
#pragma checksum "..\..\About.xaml" "{ff1816ec-aa5e-4d10-87f7-6f4963833460}" "995CC9FA4345E35A50C2E109C7BFBC169BA1CFE8"
#pragma checksum "..\..\About.xaml" "{ff1816ec-aa5e-4d10-87f7-6f4963833460}" "193353D673389D0CBDF660BE9263B569D0EA232E"
//------------------------------------------------------------------------------
// <auto-generated>
// Dieser Code wurde von einem Tool generiert.
......@@ -47,6 +47,14 @@ namespace Main {
/// </summary>
public partial class About : MahApps.Metro.Controls.MetroWindow, System.Windows.Markup.IComponentConnector {
#line 33 "..\..\About.xaml"
[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1823:AvoidUnusedPrivateFields")]
internal System.Windows.Controls.Image Image;
#line default
#line hidden
private bool _contentLoaded;
/// <summary>
......@@ -78,6 +86,9 @@ namespace Main {
switch (connectionId)
{
case 1:
this.Image = ((System.Windows.Controls.Image)(target));
return;
case 2:
#line 35 "..\..\About.xaml"
((System.Windows.Documents.Hyperlink)(target)).Click += new System.Windows.RoutedEventHandler(this.Website_Click);
......@@ -85,7 +96,7 @@ namespace Main {
#line default
#line hidden
return;
case 2:
case 3:
#line 35 "..\..\About.xaml"
((System.Windows.Documents.Hyperlink)(target)).Click += new System.Windows.RoutedEventHandler(this.DeveloperWebsite_Click);
......@@ -93,7 +104,7 @@ namespace Main {
#line default
#line hidden
return;
case 3:
case 4:
#line 35 "..\..\About.xaml"
((System.Windows.Documents.Hyperlink)(target)).Click += new System.Windows.RoutedEventHandler(this.MainProgramm_Click);
......@@ -101,7 +112,7 @@ namespace Main {
#line default
#line hidden
return;
case 4:
case 5:
#line 35 "..\..\About.xaml"
((System.Windows.Documents.Hyperlink)(target)).Click += new System.Windows.RoutedEventHandler(this.RHUtensils_Click);
......@@ -109,7 +120,7 @@ namespace Main {
#line default
#line hidden
return;
case 5:
case 6:
#line 35 "..\..\About.xaml"
((System.Windows.Documents.Hyperlink)(target)).Click += new System.Windows.RoutedEventHandler(this.MainProgramm_Click);
......@@ -117,7 +128,7 @@ namespace Main {
#line default
#line hidden
return;
case 6:
case 7:
#line 35 "..\..\About.xaml"
((System.Windows.Documents.Hyperlink)(target)).Click += new System.Windows.RoutedEventHandler(this.SourceCode_Click);
......@@ -125,7 +136,7 @@ namespace Main {
#line default
#line hidden
return;
case 7:
case 8:
#line 35 "..\..\About.xaml"
((System.Windows.Documents.Hyperlink)(target)).Click += new System.Windows.RoutedEventHandler(this.HampisProjekte_Click);
......@@ -133,7 +144,7 @@ namespace Main {
#line default
#line hidden
return;
case 8:
case 9:
#line 35 "..\..\About.xaml"
((System.Windows.Documents.Hyperlink)(target)).Click += new System.Windows.RoutedEventHandler(this.Copyright_Click);
......
dd92e90dcb9401804f51d23151160b84fcb6c5f2
8325edb3bc48dd86837e429746e98b133c794d31
......@@ -12,7 +12,7 @@ DEBUG;TRACE
E:\Hampis Cloud\Hampis Projekte\Projekte\RH Utensils\Programme\Windows Desktop\Main\App.xaml
5-1849868725
16-1095453
17-1547685184
156363998945
About.xaml;Login.xaml;Error.xaml;MainWindow.xaml;Menu.xaml;
......
......@@ -12,7 +12,7 @@ DEBUG;TRACE
E:\Hampis Cloud\Hampis Projekte\Projekte\RH Utensils\Programme\Windows Desktop\Main\App.xaml
5-1849868725
20-156450205
21-1703039936
156363998945
About.xaml;Login.xaml;Error.xaml;MainWindow.xaml;Menu.xaml;
......

FE:\Hampis Cloud\Hampis Projekte\Projekte\RH Utensils\Programme\Windows Desktop\Main\App.xaml;;
FE:\Hampis Cloud\Hampis Projekte\Projekte\RH Utensils\Programme\Windows Desktop\Main\About.xaml;;
FE:\Hampis Cloud\Hampis Projekte\Projekte\RH Utensils\Programme\Windows Desktop\Main\Login.xaml;;
FE:\Hampis Cloud\Hampis Projekte\Projekte\RH Utensils\Programme\Windows Desktop\Main\Error.xaml;;
FE:\Hampis Cloud\Hampis Projekte\Projekte\RH Utensils\Programme\Windows Desktop\Main\MainWindow.xaml;;
FE:\Hampis Cloud\Hampis Projekte\Projekte\RH Utensils\Programme\Windows Desktop\Main\Menu.xaml;;
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment