Version 4: Upgrade to VS 2017

This commit is contained in:
ClemensF 2017-08-04 21:38:58 +02:00
parent 2aafe32e00
commit ec47f225b3
142 changed files with 1828 additions and 18384 deletions

View file

@ -1,37 +1,69 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<MinimumVisualStudioVersion>12.0</MinimumVisualStudioVersion>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{C7BF2B18-CC74-430B-BCB2-600304EFA3D8}</ProjectGuid>
<ProjectGuid>{3FF37D40-F770-45B2-95DD-7A84093E1425}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>MapControl.Caching</RootNamespace>
<AssemblyName>FileDbCache.WinRT</AssemblyName>
<AssemblyName>FileDbCache.UWP</AssemblyName>
<DefaultLanguage>en-US</DefaultLanguage>
<TargetPlatformIdentifier>UAP</TargetPlatformIdentifier>
<TargetPlatformVersion>10.0.10240.0</TargetPlatformVersion>
<TargetPlatformMinVersion>10.0.10240.0</TargetPlatformMinVersion>
<MinimumVisualStudioVersion>14</MinimumVisualStudioVersion>
<FileAlignment>512</FileAlignment>
<ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
<TargetFrameworkProfile>Profile32</TargetFrameworkProfile>
<TargetFrameworkVersion>v4.6</TargetFrameworkVersion>
<ProjectTypeGuids>{A5A43C5B-DE2A-4C0C-9213-0A381AF9435A};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
<RuntimeIdentifiers>win10-arm;win10-arm-aot;win10-x86;win10-x86-aot;win10-x64;win10-x64-aot</RuntimeIdentifiers>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<OutputPath>..\bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE;NETFX_CORE;WINDOWS_UWP</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<GenerateLibraryLayout>true</GenerateLibraryLayout>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugType>none</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<OutputPath>..\bin\Release\</OutputPath>
<DefineConstants>TRACE;NETFX_CORE;WINDOWS_UWP</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<GenerateLibraryLayout>true</GenerateLibraryLayout>
</PropertyGroup>
<ItemGroup>
<!-- A reference to the entire .Net Framework and Windows SDK are automatically included -->
<None Include="..\..\MapControl.snk">
<Link>MapControl.snk</Link>
</None>
<None Include="project.json" />
</ItemGroup>
<ItemGroup>
<Compile Include="FileDbCache.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<EmbeddedResource Include="Properties\FileDbCache.UWP.rd.xml" />
</ItemGroup>
<ItemGroup>
<Reference Include="FileDbPcl">
<HintPath>..\FileDb\FileDbPcl.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\MapControl\UWP\MapControl.UWP.csproj">
<Project>{951bc5d2-d653-42d9-9a91-21dc50de0182}</Project>
<Name>MapControl.UWP</Name>
</ProjectReference>
</ItemGroup>
<PropertyGroup Condition=" '$(VisualStudioVersion)' == '' or '$(VisualStudioVersion)' &lt; '14.0' ">
<VisualStudioVersion>14.0</VisualStudioVersion>
</PropertyGroup>
<PropertyGroup>
<SignAssembly>true</SignAssembly>
@ -39,31 +71,7 @@
<PropertyGroup>
<AssemblyOriginatorKeyFile>..\..\MapControl.snk</AssemblyOriginatorKeyFile>
</PropertyGroup>
<ItemGroup>
<TargetPlatform Include="WindowsPhoneApp, Version=8.1" />
<TargetPlatform Include="Windows, Version=8.1" />
</ItemGroup>
<ItemGroup>
<Compile Include="FileDbCache.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<None Include="..\..\MapControl.snk">
<Link>MapControl.snk</Link>
</None>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\MapControl\WinRT\MapControl.WinRT.csproj">
<Project>{63cefdf7-5170-43b6-86f8-5c4a383a1615}</Project>
<Name>MapControl.WinRT</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<Reference Include="FileDbPcl">
<HintPath>..\FileDb\FileDbPcl.dll</HintPath>
</Reference>
</ItemGroup>
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\Portable\$(TargetFrameworkVersion)\Microsoft.Portable.CSharp.targets" />
<Import Project="$(MSBuildExtensionsPath)\Microsoft\WindowsXaml\v$(VisualStudioVersion)\Microsoft.Windows.UI.Xaml.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">

View file

@ -18,35 +18,33 @@ namespace MapControl.Caching
/// IImageCache implementation based on FileDb, a free and simple No-SQL database by EzTools Software.
/// See http://www.eztools-software.com/tools/filedb/.
/// </summary>
public class FileDbCache : IImageCache, IDisposable
public sealed class FileDbCache : IImageCache, IDisposable
{
private const string keyField = "Key";
private const string valueField = "Value";
private const string expiresField = "Expires";
private readonly FileDb fileDb = new FileDb { AutoFlush = true, AutoCleanThreshold = -1 };
private readonly FileDb fileDb = new FileDb();
private readonly StorageFolder folder;
private readonly string name;
private readonly string fileName;
public FileDbCache(string name = null, StorageFolder folder = null)
public FileDbCache(StorageFolder folder, string fileName = "TileCache.fdb", bool autoFlush = true, int autoCleanThreshold = -1)
{
if (string.IsNullOrEmpty(name))
{
name = TileImageLoader.DefaultCacheName;
}
if (string.IsNullOrEmpty(Path.GetExtension(name)))
{
name += ".fdb";
}
if (folder == null)
{
folder = TileImageLoader.DefaultCacheFolder;
throw new ArgumentNullException("The parameter folder must not be null.");
}
if (string.IsNullOrEmpty(fileName))
{
throw new ArgumentNullException("The parameter fileName must not be null.");
}
this.folder = folder;
this.name = name;
this.fileName = fileName;
fileDb.AutoFlush = autoFlush;
fileDb.AutoCleanThreshold = autoCleanThreshold;
Application.Current.Resuming += async (s, e) => await Open();
Application.Current.Suspending += (s, e) => Close();
@ -73,7 +71,7 @@ namespace MapControl.Caching
}
}
public async Task<ImageCacheItem> GetAsync(string key)
public Task<ImageCacheItem> GetAsync(string key)
{
if (key == null)
{
@ -85,10 +83,10 @@ namespace MapControl.Caching
return null;
}
return await Task.Run(() => Get(key));
return Task.Run(() => Get(key));
}
public async Task SetAsync(string key, IBuffer buffer, DateTime expiration)
public Task SetAsync(string key, IBuffer buffer, DateTime expiration)
{
if (key == null)
{
@ -100,16 +98,19 @@ namespace MapControl.Caching
throw new ArgumentNullException("The parameter buffer must not be null.");
}
if (fileDb.IsOpen)
return Task.Run(async () =>
{
var bytes = buffer.ToArray();
var ok = await Task.Run(() => AddOrUpdateRecord(key, bytes, expiration));
if (!ok && (await RepairDatabase()))
if (fileDb.IsOpen)
{
await Task.Run(() => AddOrUpdateRecord(key, bytes, expiration));
var bytes = buffer.ToArray();
var ok = AddOrUpdateRecord(key, bytes, expiration);
if (!ok && (await RepairDatabase()))
{
AddOrUpdateRecord(key, bytes, expiration);
}
}
}
});
}
private async Task Open()
@ -118,20 +119,18 @@ namespace MapControl.Caching
{
try
{
var file = await folder.GetFileAsync(name);
var file = await folder.GetFileAsync(fileName);
var stream = await file.OpenAsync(FileAccessMode.ReadWrite);
fileDb.Open(stream.AsStream());
Debug.WriteLine("FileDbCache: Opened database with {0} cached items in {1}", fileDb.NumRecords, file.Path);
Clean();
return;
}
catch
{
await CreateDatabase();
}
await CreateDatabase();
}
}
@ -147,7 +146,7 @@ namespace MapControl.Caching
{
Close();
var file = await folder.CreateFileAsync(name, CreationCollisionOption.ReplaceExisting);
var file = await folder.CreateFileAsync(fileName, CreationCollisionOption.ReplaceExisting);
var stream = await file.OpenAsync(FileAccessMode.ReadWrite);
fileDb.Create(stream.AsStream(), new Field[]
@ -179,7 +178,7 @@ namespace MapControl.Caching
}
catch (Exception ex)
{
Debug.WriteLine("FileDbCache: Creating database {0}: {1}", Path.Combine(folder.Path, name), ex.Message);
Debug.WriteLine("FileDbCache: Creating database {0}: {1}", Path.Combine(folder.Path, fileName), ex.Message);
}
return false;

View file

@ -1,14 +1,14 @@
using System.Reflection;
using System.Runtime.InteropServices;
[assembly: AssemblyTitle("XAML Map Control FileDbCache (WinRT)")]
[assembly: AssemblyTitle("XAML Map Control FileDbCache for UWP")]
[assembly: AssemblyDescription("IImageCache implementation based on EzTools FileDb")]
[assembly: AssemblyProduct("XAML Map Control")]
[assembly: AssemblyCompany("Clemens Fischer")]
[assembly: AssemblyCopyright("© 2017 Clemens Fischer")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyVersion("3.4.1")]
[assembly: AssemblyFileVersion("3.4.1")]
[assembly: AssemblyVersion("4.0.0")]
[assembly: AssemblyFileVersion("4.0.0")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCulture("")]
[assembly: ComVisible(false)]

View file

@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<Directives xmlns="http://schemas.microsoft.com/netfx/2013/01/metadata">
<Library Name="FileDbCache.UWP">
</Library>
</Directives>

View file

@ -0,0 +1,16 @@
{
"dependencies": {
"Microsoft.NETCore.UniversalWindowsPlatform": "5.1.0"
},
"frameworks": {
"uap10.0": {}
},
"runtimes": {
"win10-arm": {},
"win10-arm-aot": {},
"win10-x86": {},
"win10-x86-aot": {},
"win10-x64": {},
"win10-x64-aot": {}
}
}

View file

@ -1,11 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProductVersion>8.0.30703</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{EF44F661-B98A-4676-927F-85D138F82300}</ProjectGuid>
<ProjectGuid>{AD1CB53E-7AA4-4EC0-B901-B4E0E2665133}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>MapControl.Caching</RootNamespace>
@ -18,20 +17,18 @@
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<OutputPath>..\bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>none</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<OutputPath>..\bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
<PropertyGroup>
<SignAssembly>true</SignAssembly>
@ -40,12 +37,10 @@
<AssemblyOriginatorKeyFile>..\..\MapControl.snk</AssemblyOriginatorKeyFile>
</PropertyGroup>
<ItemGroup>
<Reference Include="FileDb, Version=5.0.1.0, Culture=neutral, PublicKeyToken=ba3f58a0e60cd01d, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<Reference Include="FileDb">
<HintPath>..\FileDb\FileDb.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Runtime.Caching" />
</ItemGroup>
<ItemGroup>
@ -57,7 +52,6 @@
<Link>MapControl.snk</Link>
</None>
</ItemGroup>
<ItemGroup />
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.

View file

@ -2,14 +2,13 @@
// © 2017 Clemens Fischer
// Licensed under the Microsoft Public License (Ms-PL)
using FileDbNs;
using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Runtime.Caching;
using FileDbNs;
namespace MapControl.Caching
{
@ -17,71 +16,37 @@ namespace MapControl.Caching
/// ObjectCache implementation based on FileDb, a free and simple No-SQL database by EzTools Software.
/// See http://www.eztools-software.com/tools/filedb/.
/// </summary>
public class FileDbCache : ObjectCache, IDisposable
public sealed class FileDbCache : ObjectCache, IDisposable
{
private const string keyField = "Key";
private const string valueField = "Value";
private const string expiresField = "Expires";
private readonly FileDb fileDb = new FileDb { AutoFlush = true, AutoCleanThreshold = -1 };
private readonly string name;
private readonly string path;
private readonly FileDb fileDb = new FileDb();
private readonly string dbPath;
public FileDbCache(string name, NameValueCollection config)
: this(name, config["folder"])
public FileDbCache(string path, bool autoFlush = true, int autoCleanThreshold = -1)
{
var autoFlush = config["autoFlush"];
var autoCleanThreshold = config["autoCleanThreshold"];
if (autoFlush != null)
if (string.IsNullOrEmpty(path))
{
try
{
fileDb.AutoFlush = bool.Parse(autoFlush);
}
catch (Exception ex)
{
throw new ArgumentException("The configuration parameter autoFlush must be a boolean value.", ex);
}
throw new ArgumentException("The parameter path must not be null or empty.");
}
if (autoCleanThreshold != null)
{
try
{
fileDb.AutoCleanThreshold = int.Parse(autoCleanThreshold);
}
catch (Exception ex)
{
throw new ArgumentException("The configuration parameter autoCleanThreshold must be an integer value.", ex);
}
}
}
public FileDbCache(string name, string folder)
{
if (string.IsNullOrEmpty(name))
{
throw new ArgumentException("The parameter name must not be null or empty.");
}
if (string.IsNullOrEmpty(folder))
{
throw new ArgumentException("The parameter folder must not be null or empty.");
}
this.name = name;
path = Path.Combine(folder, name);
if (string.IsNullOrEmpty(Path.GetExtension(path)))
{
path += ".fdb";
path = Path.Combine(path, "TileCache.fdb");
}
dbPath = path;
fileDb.AutoFlush = autoFlush;
fileDb.AutoCleanThreshold = autoCleanThreshold;
try
{
fileDb.Open(path, false);
Debug.WriteLine("FileDbCache: Opened database with {0} cached items in {1}", fileDb.NumRecords, path);
fileDb.Open(dbPath, false);
Debug.WriteLine("FileDbCache: Opened database with {0} cached items in {1}", fileDb.NumRecords, dbPath);
Clean();
}
@ -93,21 +58,9 @@ namespace MapControl.Caching
AppDomain.CurrentDomain.ProcessExit += (s, e) => Close();
}
public bool AutoFlush
{
get { return fileDb.AutoFlush; }
set { fileDb.AutoFlush = value; }
}
public int AutoCleanThreshold
{
get { return fileDb.AutoCleanThreshold; }
set { fileDb.AutoCleanThreshold = value; }
}
public override string Name
{
get { return name; }
get { return string.Empty; }
}
public override DefaultCacheCapabilities DefaultCacheCapabilities
@ -357,23 +310,23 @@ namespace MapControl.Caching
{
Close();
if (File.Exists(path))
if (File.Exists(dbPath))
{
File.Delete(path);
File.Delete(dbPath);
}
else
{
Directory.CreateDirectory(Path.GetDirectoryName(path));
Directory.CreateDirectory(Path.GetDirectoryName(dbPath));
}
fileDb.Create(path, new Field[]
fileDb.Create(dbPath, new Field[]
{
new Field(keyField, DataTypeEnum.String) { IsPrimaryKey = true },
new Field(valueField, DataTypeEnum.Byte) { IsArray = true },
new Field(expiresField, DataTypeEnum.DateTime)
});
Debug.WriteLine("FileDbCache: Created database " + path);
Debug.WriteLine("FileDbCache: Created database " + dbPath);
}
private bool RepairDatabase()
@ -395,7 +348,7 @@ namespace MapControl.Caching
}
catch (Exception ex)
{
Debug.WriteLine("FileDbCache: Failed creating database {0}: {1}", path, ex.Message);
Debug.WriteLine("FileDbCache: Failed creating database {0}: {1}", dbPath, ex.Message);
}
return false;

View file

@ -1,14 +1,14 @@
using System.Reflection;
using System.Runtime.InteropServices;
[assembly: AssemblyTitle("XAML Map Control FileDbCache (WPF)")]
[assembly: AssemblyTitle("XAML Map Control FileDbCache for WPF")]
[assembly: AssemblyDescription("ObjectCache implementation based on EzTools FileDb")]
[assembly: AssemblyProduct("XAML Map Control")]
[assembly: AssemblyCompany("Clemens Fischer")]
[assembly: AssemblyCopyright("© 2017 Clemens Fischer")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyVersion("3.4.1")]
[assembly: AssemblyFileVersion("3.4.1")]
[assembly: AssemblyVersion("4.0.0")]
[assembly: AssemblyFileVersion("4.0.0")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCulture("")]
[assembly: ComVisible(false)]

View file

@ -1,64 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProductVersion>8.0.30703</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{86470440-FEE2-4120-AF5A-3762FB9C536F}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>MapControl.Caching</RootNamespace>
<AssemblyName>ImageFileCache.WPF</AssemblyName>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<TargetFrameworkProfile />
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>none</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
<PropertyGroup>
<SignAssembly>true</SignAssembly>
</PropertyGroup>
<PropertyGroup>
<AssemblyOriginatorKeyFile>..\..\MapControl.snk</AssemblyOriginatorKeyFile>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Runtime.Caching" />
</ItemGroup>
<ItemGroup>
<Compile Include="ImageFileCache.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<None Include="..\..\MapControl.snk">
<Link>MapControl.snk</Link>
</None>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>

View file

@ -1,290 +0,0 @@
// XAML Map Control - https://github.com/ClemensFischer/XAML-Map-Control
// © 2017 Clemens Fischer
// Licensed under the Microsoft Public License (Ms-PL)
using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Runtime.Caching;
using System.Security.AccessControl;
using System.Security.Principal;
namespace MapControl.Caching
{
/// <summary>
/// ObjectCache implementation based on local image files.
/// The only valid data type for cached values is byte[].
/// </summary>
public class ImageFileCache : ObjectCache
{
private static readonly Tuple<string, byte[]>[] imageFileTypes = new Tuple<string, byte[]>[]
{
new Tuple<string, byte[]>(".png", new byte[] { 0x89, 0x50, 0x4E, 0x47, 0x0D, 0x0A, 0x1A, 0x0A }),
new Tuple<string, byte[]>(".jpg", new byte[] { 0xFF, 0xD8, 0xFF }),
new Tuple<string, byte[]>(".bmp", new byte[] { 0x42, 0x4D }),
new Tuple<string, byte[]>(".gif", new byte[] { 0x47, 0x49, 0x46 }),
new Tuple<string, byte[]>(".tif", new byte[] { 0x49, 0x49, 0x2A, 0x00 }),
new Tuple<string, byte[]>(".tif", new byte[] { 0x4D, 0x4D, 0x00, 0x2A }),
new Tuple<string, byte[]>(".bin", new byte[] { }),
};
private static readonly FileSystemAccessRule fullControlRule = new FileSystemAccessRule(
new SecurityIdentifier(WellKnownSidType.BuiltinUsersSid, null),
FileSystemRights.FullControl, AccessControlType.Allow);
private readonly MemoryCache memoryCache = MemoryCache.Default;
private readonly string name;
private readonly string rootFolder;
public ImageFileCache(string name, NameValueCollection config)
: this(name, config["folder"])
{
}
public ImageFileCache(string name, string folder)
{
if (string.IsNullOrEmpty(name))
{
throw new ArgumentException("The parameter name must not be null or empty.");
}
if (string.IsNullOrEmpty(folder))
{
throw new ArgumentException("The parameter folder must not be null or empty.");
}
this.name = name;
rootFolder = Path.Combine(folder, name);
Directory.CreateDirectory(rootFolder);
Debug.WriteLine("Created ImageFileCache in " + rootFolder);
}
public override string Name
{
get { return name; }
}
public override DefaultCacheCapabilities DefaultCacheCapabilities
{
get { return DefaultCacheCapabilities.None; }
}
public override object this[string key]
{
get { return Get(key); }
set { Set(key, value, null); }
}
protected override IEnumerator<KeyValuePair<string, object>> GetEnumerator()
{
throw new NotSupportedException("ImageFileCache does not support the ability to enumerate items.");
}
public override CacheEntryChangeMonitor CreateCacheEntryChangeMonitor(IEnumerable<string> keys, string regionName = null)
{
throw new NotSupportedException("ImageFileCache does not support the ability to create change monitors.");
}
public override long GetCount(string regionName = null)
{
throw new NotSupportedException("ImageFileCache does not support the ability to count items.");
}
public override bool Contains(string key, string regionName = null)
{
if (key == null)
{
throw new ArgumentNullException("The parameter key must not be null.");
}
if (regionName != null)
{
throw new NotSupportedException("The parameter regionName must be null.");
}
return memoryCache.Contains(key) || FindFile(key) != null;
}
public override object Get(string key, string regionName = null)
{
if (key == null)
{
throw new ArgumentNullException("The parameter key must not be null.");
}
if (regionName != null)
{
throw new NotSupportedException("The parameter regionName must be null.");
}
var buffer = memoryCache.Get(key) as byte[];
if (buffer == null)
{
var path = FindFile(key);
if (path != null)
{
try
{
//Debug.WriteLine("ImageFileCache: Reading " + path);
buffer = File.ReadAllBytes(path);
memoryCache.Set(key, buffer, new CacheItemPolicy());
}
catch (Exception ex)
{
Debug.WriteLine("ImageFileCache: Failed reading {0}: {1}", path, ex.Message);
}
}
}
return buffer;
}
public override CacheItem GetCacheItem(string key, string regionName = null)
{
var value = Get(key, regionName);
return value != null ? new CacheItem(key, value) : null;
}
public override IDictionary<string, object> GetValues(IEnumerable<string> keys, string regionName = null)
{
return keys.ToDictionary(key => key, key => Get(key, regionName));
}
public override void Set(string key, object value, CacheItemPolicy policy, string regionName = null)
{
if (key == null)
{
throw new ArgumentNullException("The parameter key must not be null.");
}
if (regionName != null)
{
throw new NotSupportedException("The parameter regionName must be null.");
}
var buffer = value as byte[];
if (buffer == null || buffer.Length == 0)
{
throw new NotSupportedException("The parameter value must be a non-empty byte array.");
}
memoryCache.Set(key, buffer, policy);
var path = Path.Combine(rootFolder, key)
+ imageFileTypes.First(t => t.Item2.SequenceEqual(buffer.Take(t.Item2.Length))).Item1;
try
{
//Debug.WriteLine("ImageFileCache: Writing {0}, Expires {1}", path, policy.AbsoluteExpiration.DateTime.ToLocalTime());
Directory.CreateDirectory(Path.GetDirectoryName(path));
File.WriteAllBytes(path, buffer);
var fileSecurity = File.GetAccessControl(path);
fileSecurity.AddAccessRule(fullControlRule);
File.SetAccessControl(path, fileSecurity);
}
catch (Exception ex)
{
Debug.WriteLine("ImageFileCache: Failed writing {0}: {1}", path, ex.Message);
}
}
public override void Set(string key, object value, DateTimeOffset absoluteExpiration, string regionName = null)
{
Set(key, value, new CacheItemPolicy { AbsoluteExpiration = absoluteExpiration }, regionName);
}
public override void Set(CacheItem item, CacheItemPolicy policy)
{
Set(item.Key, item.Value, policy, item.RegionName);
}
public override object AddOrGetExisting(string key, object value, CacheItemPolicy policy, string regionName = null)
{
var oldValue = Get(key, regionName);
Set(key, value, policy);
return oldValue;
}
public override object AddOrGetExisting(string key, object value, DateTimeOffset absoluteExpiration, string regionName = null)
{
return AddOrGetExisting(key, value, new CacheItemPolicy { AbsoluteExpiration = absoluteExpiration }, regionName);
}
public override CacheItem AddOrGetExisting(CacheItem item, CacheItemPolicy policy)
{
var oldItem = GetCacheItem(item.Key, item.RegionName);
Set(item, policy);
return oldItem;
}
public override object Remove(string key, string regionName = null)
{
if (key == null)
{
throw new ArgumentNullException("The parameter key must not be null.");
}
if (regionName != null)
{
throw new NotSupportedException("The parameter regionName must be null.");
}
memoryCache.Remove(key);
var path = FindFile(key);
if (path != null)
{
try
{
File.Delete(path);
}
catch (Exception ex)
{
Debug.WriteLine("ImageFileCache: Failed removing {0}: {1}", path, ex.Message);
}
}
return null;
}
private string FindFile(string key)
{
var path = Path.Combine(rootFolder, key);
try
{
if (!string.IsNullOrEmpty(Path.GetExtension(path)))
{
return path;
}
string folderName = Path.GetDirectoryName(path);
if (Directory.Exists(folderName))
{
return Directory.EnumerateFiles(folderName, Path.GetFileName(path) + ".*").FirstOrDefault();
}
}
catch (Exception ex)
{
Debug.WriteLine("ImageFileCache: Failed finding {0}: {1}", path, ex.Message);
}
return null;
}
}
}

View file

@ -1,14 +0,0 @@
using System.Reflection;
using System.Runtime.InteropServices;
[assembly: AssemblyTitle("XAML Map Control ImageFileCache (WPF)")]
[assembly: AssemblyDescription("ObjectCache implementation based on local image files")]
[assembly: AssemblyProduct("XAML Map Control")]
[assembly: AssemblyCompany("Clemens Fischer")]
[assembly: AssemblyCopyright("© 2017 Clemens Fischer")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyVersion("3.4.1")]
[assembly: AssemblyFileVersion("3.4.1")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCulture("")]
[assembly: ComVisible(false)]

View file

@ -1,66 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<MinimumVisualStudioVersion>12.0</MinimumVisualStudioVersion>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{F789647E-96F7-43E3-A895-FA3FE8D01260}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>MapControl.Caching</RootNamespace>
<AssemblyName>ImageFileCache.WinRT</AssemblyName>
<DefaultLanguage>en-US</DefaultLanguage>
<FileAlignment>512</FileAlignment>
<ProjectTypeGuids>{BC8A1FFA-BEE3-4634-8014-F334798102B3};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
<TargetPlatformIdentifier>Windows</TargetPlatformIdentifier>
<TargetPlatformVersion>8.1</TargetPlatformVersion>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE;NETFX_CORE;WINDOWS_APP</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>none</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE;NETFX_CORE;WINDOWS_APP</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup>
<SignAssembly>true</SignAssembly>
</PropertyGroup>
<PropertyGroup>
<AssemblyOriginatorKeyFile>..\..\MapControl.snk</AssemblyOriginatorKeyFile>
</PropertyGroup>
<ItemGroup>
<!-- A reference to the entire .NET Framework is automatically included -->
<None Include="..\..\MapControl.snk">
<Link>MapControl.snk</Link>
</None>
</ItemGroup>
<ItemGroup>
<Compile Include="ImageFileCache.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\MapControl\WinRT\MapControl.WinRT.csproj">
<Project>{63cefdf7-5170-43b6-86f8-5c4a383a1615}</Project>
<Name>MapControl.WinRT</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildExtensionsPath)\Microsoft\WindowsXaml\v$(VisualStudioVersion)\Microsoft.Windows.UI.Xaml.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>

View file

@ -1,93 +0,0 @@
// XAML Map Control - https://github.com/ClemensFischer/XAML-Map-Control
// © 2017 Clemens Fischer
// Licensed under the Microsoft Public License (Ms-PL)
using System;
using System.Diagnostics;
using System.Threading.Tasks;
using Windows.Storage;
using Windows.Storage.Streams;
namespace MapControl.Caching
{
public class ImageFileCache : IImageCache
{
private readonly string name;
private StorageFolder rootFolder;
public ImageFileCache(string name = null, StorageFolder folder = null)
{
if (string.IsNullOrEmpty(name))
{
name = TileImageLoader.DefaultCacheName;
}
if (folder == null)
{
folder = TileImageLoader.DefaultCacheFolder;
}
this.name = name;
folder.CreateFolderAsync(name, CreationCollisionOption.OpenIfExists).Completed = (o, s) =>
{
rootFolder = o.GetResults();
Debug.WriteLine("Created ImageFileCache in " + rootFolder.Path);
};
}
public virtual async Task<ImageCacheItem> GetAsync(string key)
{
var item = await rootFolder.TryGetItemAsync(key);
if (item != null && item.IsOfType(StorageItemTypes.File))
{
var file = (StorageFile)item;
//Debug.WriteLine("ImageFileCache: Reading " + file.Path);
try
{
return new ImageCacheItem
{
Buffer = await FileIO.ReadBufferAsync(file),
Expiration = (await file.Properties.GetImagePropertiesAsync()).DateTaken.UtcDateTime
};
}
catch (Exception ex)
{
Debug.WriteLine("ImageFileCache: Reading {0}: {1}", file.Path, ex.Message);
}
}
return null;
}
public virtual async Task SetAsync(string key, IBuffer buffer, DateTime expiration)
{
try
{
var names = key.Split('\\');
var folder = rootFolder;
for (int i = 0; i < names.Length - 1; i++)
{
folder = await folder.CreateFolderAsync(names[i], CreationCollisionOption.OpenIfExists);
}
var file = await folder.CreateFileAsync(names[names.Length - 1], CreationCollisionOption.ReplaceExisting);
//Debug.WriteLine("ImageFileCache: Writing {0}, Expires {1}", file.Path, expiration.ToLocalTime());
await FileIO.WriteBufferAsync(file, buffer);
// Store expiration date in ImageProperties.DateTaken
var properties = await file.Properties.GetImagePropertiesAsync();
properties.DateTaken = expiration;
await properties.SavePropertiesAsync();
}
catch (Exception ex)
{
Debug.WriteLine("ImageFileCache: Writing {0}\\{1}: {2}", rootFolder.Path, key, ex.Message);
}
}
}
}

View file

@ -1,14 +0,0 @@
using System.Reflection;
using System.Runtime.InteropServices;
[assembly: AssemblyTitle("XAML Map Control ImageFileCache (WinRT)")]
[assembly: AssemblyDescription("IImageCache implementation based on local image files")]
[assembly: AssemblyProduct("XAML Map Control")]
[assembly: AssemblyCompany("Clemens Fischer")]
[assembly: AssemblyCopyright("© 2017 Clemens Fischer")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyVersion("3.4.1")]
[assembly: AssemblyFileVersion("3.4.1")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCulture("")]
[assembly: ComVisible(false)]