1
0
Fork 0
mirror of https://github.com/Nioux/AideDeJeu.git synced 2025-10-29 22:45:44 +00:00

Avant nuget

This commit is contained in:
Yan Maniez 2018-10-14 00:38:28 +02:00
parent a2cb2dbcda
commit ba0a5c1d41
14 changed files with 355 additions and 28 deletions

View file

@ -94,6 +94,9 @@
<AndroidAsset Include="Assets\LinLibertine_aZL.ttf" />
<AndroidAsset Include="Assets\LinLibertine_DR.ttf" />
<AndroidAsset Include="Assets\LinLibertine_I.ttf" />
<AndroidAsset Include="..\..\Data\database.db">
<Link>Assets\database.db</Link>
</AndroidAsset>
<None Include="Resources\AboutResources.txt" />
<None Include="Assets\AboutAssets.txt" />
</ItemGroup>

View file

@ -29,33 +29,36 @@ namespace AideDeJeu.Droid
public string GetDatabasePath(string databaseName)
{
var documentsDirectoryPath = System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal);
var path = Path.Combine(documentsDirectoryPath, databaseName);
string path = Environment.GetFolderPath(Environment.SpecialFolder.Personal);
string dbPath = Path.Combine(path, databaseName);
return dbPath;
//var documentsDirectoryPath = System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal);
//var path = Path.Combine(documentsDirectoryPath, databaseName);
// This is where we copy in our pre-created database
if (!File.Exists(path))
{
using (var inStream = Android.App.Application.Context.Assets.Open(databaseName))
{
using (var outStream = new FileStream(path, FileMode.Create))
{
inStream.CopyTo(outStream);
}
}
//using (var binaryReader = new BinaryReader(Android.App.Application.Context.Assets.Open(databaseName)))
//{
// using (var binaryWriter = new BinaryWriter(new FileStream(path, FileMode.Create)))
// {
// byte[] buffer = new byte[2048];
// int length = 0;
// while ((length = binaryReader.Read(buffer, 0, buffer.Length)) > 0)
// {
// binaryWriter.Write(buffer, 0, length);
// }
// }
//}
}
return path;
//// This is where we copy in our pre-created database
//if (!File.Exists(path))
//{
// using (var inStream = Android.App.Application.Context.Assets.Open(databaseName))
// {
// using (var outStream = new FileStream(path, FileMode.Create))
// {
// inStream.CopyTo(outStream);
// }
// }
// //using (var binaryReader = new BinaryReader(Android.App.Application.Context.Assets.Open(databaseName)))
// //{
// // using (var binaryWriter = new BinaryWriter(new FileStream(path, FileMode.Create)))
// // {
// // byte[] buffer = new byte[2048];
// // int length = 0;
// // while ((length = binaryReader.Read(buffer, 0, buffer.Length)) > 0)
// // {
// // binaryWriter.Write(buffer, 0, length);
// // }
// // }
// //}
//}
//return path;
}
}
}

View file

@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="System.ComponentModel.Annotations" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.2.1.0" newVersion="4.2.1.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>

View file

@ -109,6 +109,9 @@
<AppxManifest Include="Package.appxmanifest">
<SubType>Designer</SubType>
</AppxManifest>
<Content Include="..\..\Data\database.db">
<Link>database.db</Link>
</Content>
<None Include="AideDeJeu.UWP_StoreKey.pfx" />
<None Include="AideDeJeu.UWP_TemporaryKey.pfx" />
<Content Include="Assets\Fonts\LinLibertine_R.ttf" />

View file

@ -90,6 +90,9 @@
<ItemGroup>
<Compile Include="Main.cs" />
<Compile Include="AppDelegate.cs" />
<BundleResource Include="..\..\Data\database.db">
<Link>Resources\database.db</Link>
</BundleResource>
<None Include="Entitlements.plist" />
<None Include="Info.plist" />
<Compile Include="Properties\AssemblyInfo.cs" />

View file

@ -24,8 +24,9 @@ namespace AideDeJeu.Droid
public string GetDatabasePath(string databaseName)
{
var databasePath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "..", "Library", databaseName);
return databasePath;
return NSBundle.MainBundle.PathForResource("database", "db");
//var databasePath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "..", "Library", databaseName);
//return databasePath;
}
}
}

View file

@ -4,6 +4,7 @@ using Markdig;
using Markdig.Parsers;
using Markdig.Syntax;
using Markdig.Syntax.Inlines;
using SQLite;
using System;
using System.Collections.Generic;
using System.Linq;
@ -11,6 +12,7 @@ using System.Reflection;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using Xamarin.Forms;
namespace AideDeJeu.ViewModels
{
@ -360,8 +362,60 @@ namespace AideDeJeu.ViewModels
}
}
public class TodoItemDatabase
{
readonly SQLiteAsyncConnection database;
public TodoItemDatabase(string dbPath)
{
database = new SQLiteAsyncConnection(dbPath);
database.CreateTableAsync<Item>().Wait();
}
public Task<List<Item>> GetItemsAsync()
{
return database.Table<Item>().ToListAsync();
}
public Task<List<Item>> GetItemsNotDoneAsync()
{
return database.QueryAsync<Item>("SELECT * FROM [Item]");
}
public Task<Item> GetItemAsync(string id)
{
return database.Table<Item>().Where(i => i.Id == id).FirstOrDefaultAsync();
}
public Task<int> SaveItemAsync(Item item)
{
if (!string.IsNullOrEmpty(item.Id))
{
return database.UpdateAsync(item);
}
else
{
return database.InsertAsync(item);
}
}
public Task<int> DeleteItemAsync(Item item)
{
return database.DeleteAsync(item);
}
}
public async Task<Item> GetItemFromDataAsync(string source, string anchor)
{
SQLiteAsyncConnection database;
var dbPath = DependencyService.Get<INativeAPI>().GetDatabasePath("database.db");
database = new SQLiteAsyncConnection(dbPath, SQLiteOpenFlags.ReadOnly);
return null;
var it = await database.Table<Item>().ToListAsync();
var id = $"{source}.md#{anchor}";
//await Task.Delay(3000);
if (!_AllItems.ContainsKey(id) && !_AllItems.ContainsKey(source))

View file

@ -6,6 +6,14 @@
<LangVersion>latest</LangVersion>
</PropertyGroup>
<ItemGroup>
<Content Include="..\..\Data\database.db" Link="database.db" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Xamarin.Forms" Version="3.2.0.871581" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\AideDeJeu\AideDeJeu.csproj" />
</ItemGroup>

View file

@ -0,0 +1,204 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Reflection;
using System.Threading;
using System.Threading.Tasks;
using Xamarin.Forms;
using Xamarin.Forms.Internals;
namespace Tests.Xamarin.Forms.Mocks
{
public static class MockForms
{
public static void Init()
{
Device.Info = new MockDeviceInfo();
Device.PlatformServices = new MockPlatformServices();
DependencyService.Register<MockResourcesProvider>();
DependencyService.Register<MockDeserializer>();
}
internal class MockPlatformServices : IPlatformServices
{
Action<Action> _invokeOnMainThread;
Action<Uri> _openUriAction;
Func<Uri, CancellationToken, Task<Stream>> _getStreamAsync;
public MockPlatformServices(Action<Action> invokeOnMainThread = null, Action<Uri> openUriAction = null, Func<Uri, CancellationToken, Task<Stream>> getStreamAsync = null)
{
_invokeOnMainThread = invokeOnMainThread;
_openUriAction = openUriAction;
_getStreamAsync = getStreamAsync;
}
public string GetMD5Hash(string input)
{
throw new NotImplementedException();
}
static int hex(int v)
{
if (v < 10)
return '0' + v;
return 'a' + v - 10;
}
public double GetNamedSize(NamedSize size, Type targetElement, bool useOldSizes)
{
switch (size)
{
case NamedSize.Default:
return 10;
case NamedSize.Micro:
return 4;
case NamedSize.Small:
return 8;
case NamedSize.Medium:
return 12;
case NamedSize.Large:
return 16;
default:
throw new ArgumentOutOfRangeException("size");
}
}
public void OpenUriAction(Uri uri)
{
if (_openUriAction != null)
_openUriAction(uri);
else
throw new NotImplementedException();
}
public bool IsInvokeRequired
{
get { return false; }
}
public string RuntimePlatform { get; set; }
public void BeginInvokeOnMainThread(Action action)
{
if (_invokeOnMainThread == null)
action();
else
_invokeOnMainThread(action);
}
public Ticker CreateTicker()
{
return new MockTicker();
}
public void StartTimer(TimeSpan interval, Func<bool> callback)
{
Timer timer = null;
TimerCallback onTimeout = o => BeginInvokeOnMainThread(() => {
if (callback())
return;
timer.Dispose();
});
timer = new Timer(onTimeout, null, interval, interval);
}
public Task<Stream> GetStreamAsync(Uri uri, CancellationToken cancellationToken)
{
if (_getStreamAsync == null)
throw new NotImplementedException();
return _getStreamAsync(uri, cancellationToken);
}
public Assembly[] GetAssemblies()
{
return new Assembly[0];
}
public IIsolatedStorageFile GetUserStoreForApplication()
{
throw new NotImplementedException();
}
public void QuitApplication()
{
//throw new NotImplementedException();
}
}
internal class MockDeserializer : IDeserializer
{
public Task<IDictionary<string, object>> DeserializePropertiesAsync()
{
return Task.FromResult<IDictionary<string, object>>(new Dictionary<string, object>());
}
public Task SerializePropertiesAsync(IDictionary<string, object> properties)
{
return Task.FromResult(false);
}
}
internal class MockResourcesProvider : ISystemResourcesProvider
{
public IResourceDictionary GetSystemResources()
{
var dictionary = new ResourceDictionary();
Style style;
style = new Style(typeof(Label));
dictionary[Device.Styles.BodyStyleKey] = style;
style = new Style(typeof(Label));
style.Setters.Add(Label.FontSizeProperty, 50);
dictionary[Device.Styles.TitleStyleKey] = style;
style = new Style(typeof(Label));
style.Setters.Add(Label.FontSizeProperty, 40);
dictionary[Device.Styles.SubtitleStyleKey] = style;
style = new Style(typeof(Label));
style.Setters.Add(Label.FontSizeProperty, 30);
dictionary[Device.Styles.CaptionStyleKey] = style;
style = new Style(typeof(Label));
style.Setters.Add(Label.FontSizeProperty, 20);
dictionary[Device.Styles.ListItemTextStyleKey] = style;
style = new Style(typeof(Label));
style.Setters.Add(Label.FontSizeProperty, 10);
dictionary[Device.Styles.ListItemDetailTextStyleKey] = style;
return dictionary;
}
}
internal class MockTicker : Ticker
{
bool _enabled;
protected override void EnableTimer()
{
_enabled = true;
while (_enabled)
{
SendSignals(16);
}
}
protected override void DisableTimer()
{
_enabled = false;
}
}
internal class MockDeviceInfo : DeviceInfo
{
public override Size PixelScreenSize => throw new NotImplementedException();
public override Size ScaledScreenSize => throw new NotImplementedException();
public override double ScalingFactor => throw new NotImplementedException();
}
}
}

View file

@ -0,0 +1,30 @@
using AideDeJeu.Tools;
using System.IO;
using System.Reflection;
[assembly: Xamarin.Forms.Dependency(typeof(AideDeJeu.Cmd.Version_CMD))]
namespace AideDeJeu.Cmd
{
public class Version_CMD : INativeAPI
{
public string GetVersion()
{
//Package package = Package.Current;
//PackageId packageId = package.Id;
//PackageVersion version = packageId.Version;
//return string.Format("{0}.{1}", version.Major, version.Minor);
return "";
}
public int GetBuild()
{
return 0;
}
public string GetDatabasePath(string databaseName)
{
return Path.Combine(Path.GetDirectoryName(Assembly.GetEntryAssembly().Location), databaseName);
}
}
}

View file

@ -290,6 +290,11 @@ namespace AideDeJeuCmd
static async Task Main(string[] args)
{
Tests.Xamarin.Forms.Mocks.MockForms.Init();
DependencyService.Register<INativeAPI, AideDeJeu.Cmd.Version_CMD>();
var store = new StoreViewModel();
await store.GetItemFromDataAsync("test", "truc");
return;
await ReorderSpellsAsync();
return;
string dataDir = @"..\..\..\..\..\Data\";

View file

@ -10,6 +10,7 @@
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.9.0" />
<PackageReference Include="MSTest.TestAdapter" Version="1.3.2" />
<PackageReference Include="MSTest.TestFramework" Version="1.3.2" />
<PackageReference Include="Xamarin.Forms" Version="3.2.0.871581" />
</ItemGroup>
<ItemGroup>

View file

@ -10,6 +10,7 @@
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.All" Version="2.1.5" />
<PackageReference Include="Xamarin.Forms" Version="3.2.0.871581" />
</ItemGroup>
<ItemGroup>

BIN
Data/database.db Normal file

Binary file not shown.