Trying to serialize and deserialize Json

UWPTest
Brian Lima 8 years ago
parent 18d659a6b9
commit 03b7fff6ce

File diff suppressed because it is too large Load Diff

@ -1,12 +1,15 @@
using System;
using Newtonsoft.Json;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Data;
using UWPHook.Properties;
namespace UWPHook
{
@ -15,6 +18,7 @@ namespace UWPHook
public GameModel()
{
games = new ObservableCollection<Game>();
var y = JsonConvert.DeserializeObject<GameModel>("games.json");
}
private ObservableCollection<Game> _games;
@ -25,19 +29,23 @@ namespace UWPHook
set { _games = value; }
}
public void Add(Game game)
{
this.games.Add(game);
}
public string game_alias { get; set; }
public string game_path { get; set; }
public void Store()
{
JsonSerializer serializer = new JsonSerializer();
using (StreamWriter sw = new StreamWriter(@"games.json")) {
using (JsonWriter writer = new JsonTextWriter(sw)){
serializer.Serialize(writer, _games);
}
}
}
}
public class Game:INotifyPropertyChanged
public class Game : INotifyPropertyChanged
{
private string _game_alias;
@ -55,7 +63,6 @@ namespace UWPHook
set { _game_path = value; }
}
public event PropertyChangedEventHandler PropertyChanged;
private void NotifyPropertyChanged(string Obj)
@ -65,6 +72,5 @@ namespace UWPHook
this.PropertyChanged(this, new PropertyChangedEventArgs(Obj));
}
}
}
}

@ -46,6 +46,7 @@ namespace UWPHook
private void addButton_Click(object sender, RoutedEventArgs e)
{
games.Store();
games.Add(new Game{ game_alias = alias_textBox.Text, game_path = path_textBox.Text });
}
}

@ -35,6 +35,10 @@
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="Newtonsoft.Json, Version=9.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>..\packages\Newtonsoft.Json.9.0.1\lib\net45\Newtonsoft.Json.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="System" />
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
@ -87,6 +91,10 @@
<Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
</EmbeddedResource>
<None Include="games.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="packages.config" />
<None Include="Properties\Settings.settings">
<Generator>SettingsSingleFileGenerator</Generator>
<LastGenOutput>Settings.Designer.cs</LastGenOutput>

File diff suppressed because it is too large Load Diff

Binary file not shown.

Binary file not shown.

@ -0,0 +1,15 @@
[
{
"game_alias": "teste",
"game_path": "teste"
},
{
"game_alias": "teste",
"game_path": "teste"
},
{
"game_alias": "teste",
"game_path": "teste"
}
]

@ -0,0 +1,3 @@
{
}

Binary file not shown.

@ -12,3 +12,6 @@ c:\users\brian\documents\visual studio 2015\Projects\UWPHook\UWPHook\obj\Debug\U
c:\users\brian\documents\visual studio 2015\Projects\UWPHook\UWPHook\obj\Debug\UWPHook.csproj.GenerateResource.Cache
c:\users\brian\documents\visual studio 2015\Projects\UWPHook\UWPHook\obj\Debug\UWPHook.exe
c:\users\brian\documents\visual studio 2015\Projects\UWPHook\UWPHook\obj\Debug\UWPHook.pdb
c:\users\brian\documents\visual studio 2015\Projects\UWPHook\UWPHook\bin\Debug\games.json
c:\users\brian\documents\visual studio 2015\Projects\UWPHook\UWPHook\bin\Debug\Newtonsoft.Json.dll
c:\users\brian\documents\visual studio 2015\Projects\UWPHook\UWPHook\bin\Debug\Newtonsoft.Json.xml

Binary file not shown.

Binary file not shown.

@ -13,7 +13,7 @@ c:\users\brian\documents\visual studio 2015\Projects\UWPHook\UWPHook\App.xaml
11151548125
6-470569544
131569487696
14-1541981460
MainWindow.xaml;
False

@ -13,7 +13,7 @@ c:\users\brian\documents\visual studio 2015\Projects\UWPHook\UWPHook\App.xaml
11151548125
10-1855892474
131569487696
14-1541981460
MainWindow.xaml;
False

@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Newtonsoft.Json" version="9.0.1" targetFramework="net461" />
</packages>

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

@ -0,0 +1,116 @@
param($installPath, $toolsPath, $package, $project)
# open json.net splash page on package install
# don't open if json.net is installed as a dependency
try
{
$url = "http://www.newtonsoft.com/json/install?version=" + $package.Version
$dte2 = Get-Interface $dte ([EnvDTE80.DTE2])
if ($dte2.ActiveWindow.Caption -eq "Package Manager Console")
{
# user is installing from VS NuGet console
# get reference to the window, the console host and the input history
# show webpage if "install-package newtonsoft.json" was last input
$consoleWindow = $(Get-VSComponentModel).GetService([NuGetConsole.IPowerConsoleWindow])
$props = $consoleWindow.GetType().GetProperties([System.Reflection.BindingFlags]::Instance -bor `
[System.Reflection.BindingFlags]::NonPublic)
$prop = $props | ? { $_.Name -eq "ActiveHostInfo" } | select -first 1
if ($prop -eq $null) { return }
$hostInfo = $prop.GetValue($consoleWindow)
if ($hostInfo -eq $null) { return }
$history = $hostInfo.WpfConsole.InputHistory.History
$lastCommand = $history | select -last 1
if ($lastCommand)
{
$lastCommand = $lastCommand.Trim().ToLower()
if ($lastCommand.StartsWith("install-package") -and $lastCommand.Contains("newtonsoft.json"))
{
$dte2.ItemOperations.Navigate($url) | Out-Null
}
}
}
else
{
# user is installing from VS NuGet dialog
# get reference to the window, then smart output console provider
# show webpage if messages in buffered console contains "installing...newtonsoft.json" in last operation
$instanceField = [NuGet.Dialog.PackageManagerWindow].GetField("CurrentInstance", [System.Reflection.BindingFlags]::Static -bor `
[System.Reflection.BindingFlags]::NonPublic)
$consoleField = [NuGet.Dialog.PackageManagerWindow].GetField("_smartOutputConsoleProvider", [System.Reflection.BindingFlags]::Instance -bor `
[System.Reflection.BindingFlags]::NonPublic)
if ($instanceField -eq $null -or $consoleField -eq $null) { return }
$instance = $instanceField.GetValue($null)
if ($instance -eq $null) { return }
$consoleProvider = $consoleField.GetValue($instance)
if ($consoleProvider -eq $null) { return }
$console = $consoleProvider.CreateOutputConsole($false)
$messagesField = $console.GetType().GetField("_messages", [System.Reflection.BindingFlags]::Instance -bor `
[System.Reflection.BindingFlags]::NonPublic)
if ($messagesField -eq $null) { return }
$messages = $messagesField.GetValue($console)
if ($messages -eq $null) { return }
$operations = $messages -split "=============================="
$lastOperation = $operations | select -last 1
if ($lastOperation)
{
$lastOperation = $lastOperation.ToLower()
$lines = $lastOperation -split "`r`n"
$installMatch = $lines | ? { $_.StartsWith("------- installing...newtonsoft.json ") } | select -first 1
if ($installMatch)
{
$dte2.ItemOperations.Navigate($url) | Out-Null
}
}
}
}
catch
{
try
{
$pmPane = $dte2.ToolWindows.OutputWindow.OutputWindowPanes.Item("Package Manager")
$selection = $pmPane.TextDocument.Selection
$selection.StartOfDocument($false)
$selection.EndOfDocument($true)
if ($selection.Text.StartsWith("Attempting to gather dependencies information for package 'Newtonsoft.Json." + $package.Version + "'"))
{
# don't show on upgrade
if (!$selection.Text.Contains("Removed package"))
{
$dte2.ItemOperations.Navigate($url) | Out-Null
}
}
}
catch
{
# stop potential errors from bubbling up
# worst case the splash page won't open
}
}
# still yolo
Loading…
Cancel
Save