Permalink
Browse files

Link files into plat-specific libs to enable targetting WP8 in the core

  • Loading branch information...
1 parent 1126f5d commit a5f02a4cc31fe31fb65f46450953d5b8393ccc9a @onovotny committed Nov 29, 2012
@@ -10,5 +10,7 @@ namespace MetroLog
public interface IWinRTLogManager : ILogManager
{
Task<IStorageFile> GetCompressedLogFile();
+ Task ShareLogFile(string title, string description);
+
}
}
@@ -57,8 +57,10 @@ static LazyFlushManager()
Owners = new Dictionary<ILogManager, LazyFlushManager>();
// only if we have an application...
+#pragma warning disable 436
if(LoggingEnvironment.XamlApplicationState == XamlApplicationState.Available)
Application.Current.Suspending += Current_Suspending;
+#pragma warning restore 436
}
private static async void Current_Suspending(object sender, Windows.ApplicationModel.SuspendingEventArgs e)
@@ -14,6 +14,7 @@ public override LoggingConfiguration CreateDefaultSettings()
{
var def = base.CreateDefaultSettings();
def.AddTarget(LogLevel.Error, LogLevel.Fatal, new FileSnapshotTarget());
+ def.AddTarget(LogLevel.Trace, LogLevel.Fatal, new EtwTarget());
return def;
}
@@ -6,6 +6,8 @@
using System.Text;
using System.Threading.Tasks;
using MetroLog.Internal;
+using Windows.ApplicationModel.DataTransfer;
+using Windows.Foundation;
using Windows.Storage;
namespace MetroLog
@@ -38,5 +40,53 @@ public LogManager(LoggingConfiguration configuration) : base(configuration)
return null;
}
+
+ public Task ShareLogFile(string title, string description)
+ {
+ var dtm = DataTransferManager.GetForCurrentView();
+
+ var tcs = new TaskCompletionSource<object>();
+ TypedEventHandler<DataTransferManager, DataRequestedEventArgs> handler = null;
+ handler = async (sender, args) =>
+ {
+ args.Request.Data.Properties.Title = title;
+ args.Request.Data.Properties.Description = description;
+
+ var deferral = args.Request.GetDeferral();
+
+ try
+ {
+ var file = await GetCompressedLogFile();
+
+ args.Request.Data.SetStorageItems(new[] { file });
+
+ tcs.SetResult(true);
+ }
+ catch (Exception ex)
+ {
+ tcs.SetException(ex);
+ }
+ finally
+ {
+ deferral.Complete();
+
+ dtm.DataRequested -= handler;
+ }
+ };
+
+ dtm.DataRequested += handler;
+ //dtm.DataRequested += dtm_DataRequested;
+ DataTransferManager.ShowShareUI();
+
+// return tcs.Task;
+
+ return Task.FromResult(true);
+ }
+
+ void dtm_DataRequested(DataTransferManager sender, DataRequestedEventArgs args)
+ {
+ args.Request.Data.Properties.Title = "Foobar";
+ args.Request.Data.SetText("Yay!");
+ }
}
}
@@ -109,6 +109,18 @@
</ProjectReference>
</ItemGroup>
<ItemGroup>
+ <Compile Include="..\MetroLog\Targets\EtwTarget.cs">
+ <Link>Targets\EtwTarget.cs</Link>
+ </Compile>
+ <Compile Include="..\MetroLog\Targets\HttpClientEventHandler.cs">
+ <Link>Targets\HttpClientEventHandler.cs</Link>
+ </Compile>
+ <Compile Include="..\MetroLog\Targets\JsonPostTarget.cs">
+ <Link>Targets\JsonPostTarget.cs</Link>
+ </Compile>
+ <Compile Include="..\MetroLog\Targets\JsonPostWrapper.cs">
+ <Link>Targets\JsonPostWrapper.cs</Link>
+ </Compile>
<Compile Include="..\SharedAssemblyInfo.cs">
<Link>Properties\SharedAssemblyInfo.cs</Link>
</Compile>
@@ -19,15 +19,15 @@ public static Task CreateFromDirectory(IStorageFolder source, Stream destination
private static async Task DoCreateFromDirectory(IStorageFolder source, Stream destinationArchive, CompressionLevel? compressionLevel, Encoding entryNameEncoding)
{
- var notCreated = true;
+ // var notCreated = true;
var fullName = source.Path;
- using (var destination = await Open(destinationArchive, ZipArchiveMode.Create, entryNameEncoding))
+ using (var destination = Open(destinationArchive, ZipArchiveMode.Create, entryNameEncoding))
{
foreach (var item in await source.GetStorageItemsRecursive())
{
- notCreated = false;
+ // notCreated = false;
var length = item.Path.Length - fullName.Length;
var entryName = item.Path.Substring(fullName.Length, length).TrimStart('\\', '/');
@@ -44,12 +44,12 @@ public static Task CreateFromDirectory(IStorageFolder source, Stream destination
}
- public static Task<ZipArchive> OpenRead(Stream archive)
+ public static ZipArchive OpenRead(Stream archive)
{
return Open(archive, ZipArchiveMode.Read);
}
- public static async Task<ZipArchive> Open(Stream archive, ZipArchiveMode mode, Encoding entryNameEncoding = null)
+ public static ZipArchive Open(Stream archive, ZipArchiveMode mode, Encoding entryNameEncoding = null)
{
if (archive == null) throw new ArgumentNullException("archive");
@@ -30,7 +30,7 @@ public string PathUnderAppData
}
}
- protected override async Task<Stream> GetCompressedLogsInternal()
+ protected override Task<Stream> GetCompressedLogsInternal()
{
var ms = new MemoryStream();
@@ -44,7 +44,7 @@ public string PathUnderAppData
ms.Position = 0;
- return ms;
+ return Task.FromResult<Stream>(ms);
}
protected FileTarget(Layout layout) : base(layout)
@@ -16,6 +16,7 @@ public override LoggingConfiguration CreateDefaultSettings()
{
var def = base.CreateDefaultSettings();
def.AddTarget(LogLevel.Trace, LogLevel.Fatal, new TraceTarget());
+ def.AddTarget(LogLevel.Trace, LogLevel.Fatal, new EtwTarget());
return def;
}
@@ -40,13 +40,26 @@
<Reference Include="System.Core" />
<Reference Include="System.IO.Compression" />
<Reference Include="System.IO.Compression.FileSystem" />
+ <Reference Include="System.Net.Http" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
+ <Compile Include="..\MetroLog\Targets\EtwTarget.cs">
+ <Link>Targets\EtwTarget.cs</Link>
+ </Compile>
+ <Compile Include="..\MetroLog\Targets\HttpClientEventHandler.cs">
+ <Link>Targets\HttpClientEventHandler.cs</Link>
+ </Compile>
+ <Compile Include="..\MetroLog\Targets\JsonPostTarget.cs">
+ <Link>Targets\JsonPostTarget.cs</Link>
+ </Compile>
+ <Compile Include="..\MetroLog\Targets\JsonPostWrapper.cs">
+ <Link>Targets\JsonPostWrapper.cs</Link>
+ </Compile>
<Compile Include="..\SharedAssemblyInfo.cs">
<Link>Properties\SharedAssemblyInfo.cs</Link>
</Compile>
View
@@ -2,7 +2,7 @@
<package xmlns="http://schemas.microsoft.com/packaging/2011/08/nuspec.xsd">
<metadata>
<id>MetroLog</id>
- <version>0.7.7</version>
+ <version>0.8.0</version>
<title>MetroLog Lightweight Logging for Portable and WinJS</title>
<authors>Matt Baxter-Reynolds,Oren Novotny</authors>
<owners>onovotny</owners>
@@ -29,8 +29,8 @@ This version targets .NET 4.5,.NET Core 4.5 (Windows Store apps) and WinJS</desc
<file src="MetroLog.NetCore\bin\Release\MetroLog.NetCore.pdb" target="lib\netcore45\MetroLog.NetCore.pdb" />
<file src="MetroLog.NetCore\bin\Release\MetroLog.NetCore.pri" target="lib\netcore45\MetroLog.NetCore.pri" />
<file src="MetroLog\bin\Release\MetroLog.pdb" target="lib\netcore45\MetroLog.pdb" />
- <file src="MetroLog\bin\Release\MetroLog.dll" target="lib\portable-net45+win8\MetroLog.dll" />
- <file src="MetroLog\bin\Release\MetroLog.pdb" target="lib\portable-net45+win8\MetroLog.pdb" />
+ <file src="MetroLog\bin\Release\MetroLog.dll" target="lib\portable-net45+wp8+win8\MetroLog.dll" />
+ <file src="MetroLog\bin\Release\MetroLog.pdb" target="lib\portable-net45+wp8+win8\MetroLog.pdb" />
<file src="MetroLog.WinRT\bin\Release\MetroLog.WinRT.pdb" target="lib\netcore45\MetroLog.WinRT.pdb" />
<file src="MetroLog.WinRT\bin\Release\MetroLog.WinRT.pri" target="lib\netcore45\MetroLog.WinRT.pri" />
<file src="MetroLog.WinRT\bin\Release\MetroLog.WinRT.winmd" target="lib\netcore45\MetroLog.WinRT.winmd" />
View
@@ -1,3 +1,5 @@
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=CheckNamespace/@EntryIndexedValue">DO_NOT_SHOW</s:String>
- <s:String x:Key="/Default/CodeStyle/CSharpUsing/KeepImports/=System_002EThreading_002ETasks/@EntryIndexedValue">System.Threading.Tasks</s:String></wpf:ResourceDictionary>
+ <s:String x:Key="/Default/CodeStyle/CSharpUsing/KeepImports/=System_002EThreading_002ETasks/@EntryIndexedValue">System.Threading.Tasks</s:String>
+ <s:String x:Key="/Default/FilterSettingsManager/AttributeFilterXml/@EntryValue">&lt;data /&gt;</s:String>
+ <s:String x:Key="/Default/FilterSettingsManager/CoverageFilterXml/@EntryValue">&lt;data&gt;&lt;IncludeFilters /&gt;&lt;ExcludeFilters /&gt;&lt;/data&gt;</s:String></wpf:ResourceDictionary>
@@ -14,7 +14,7 @@ public virtual LoggingConfiguration CreateDefaultSettings()
// default logging config...
var configuration = new LoggingConfiguration();
configuration.AddTarget(LogLevel.Trace, LogLevel.Fatal, new DebugTarget());
- configuration.AddTarget(LogLevel.Trace, LogLevel.Fatal, new EtwTarget());
+ //configuration.AddTarget(LogLevel.Trace, LogLevel.Fatal, new EtwTarget());
return configuration;
}
View
@@ -15,10 +15,10 @@
<FileAlignment>512</FileAlignment>
<ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
- <TargetFrameworkProfile>Profile7</TargetFrameworkProfile>
+ <TargetFrameworkProfile>Profile78</TargetFrameworkProfile>
<SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\</SolutionDir>
<RestorePackages>true</RestorePackages>
- <MinimumVisualStudioVersion>11.0</MinimumVisualStudioVersion>
+ <MinimumVisualStudioVersion>10.0</MinimumVisualStudioVersion>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
@@ -147,14 +147,10 @@
<Compile Include="Targets\AsyncTarget.cs" />
<Compile Include="Targets\BufferedTarget.cs" />
<Compile Include="Targets\DebugTarget.cs" />
- <Compile Include="Targets\EtwTarget.cs" />
<Compile Include="Targets\FileCreationMode.cs" />
<Compile Include="Targets\FileNamingParameters.cs" />
<Compile Include="Targets\FileTargetBase.cs" />
<Compile Include="Targets\FileTimestampMode.cs" />
- <Compile Include="Targets\HttpClientEventHandler.cs" />
- <Compile Include="Targets\JsonPostTarget.cs" />
- <Compile Include="Targets\JsonPostWrapper.cs" />
<Compile Include="Targets\LogReadQuery.cs" />
<Compile Include="Targets\SyncTarget.cs" />
<Compile Include="Targets\TargetBinding.cs" />

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
@@ -48,6 +48,7 @@
<Button Content="Crash/Fatal" Margin="0,30,0,0" Click="HandleFatal"></Button>
<Button Content="Register FileStreamingTarget" Margin="0,30,0,0" Click="HandleRegisterStreamingTarget" x:Name="buttonFileStreaming"></Button>
<Button Content="Register JsonPostTarget" Click="HandleRegisterJsonPostTarget" x:Name="buttonJsonPost"/>
+ <Button Content="Share Logs" Click="ShareLogs" x:Name="shareLogsButton" />
<StackPanel Orientation="Horizontal">
<Button Content="Register SQLiteTarget" Click="HandleRegisterSQLiteTarget" x:Name="buttonSQLite"/>
<Button Content="Read SQLite Entries" Click="HandleReadSQLiteValues" x:Name="buttonReadSQLite" IsEnabled="false" />
@@ -48,15 +48,10 @@ public LogSamplePage()
// you could even add Log as a property your LayoutAwarePage class...
- // setup...
- this.SetupSharing();
+
}
- private void SetupSharing()
- {
- var manager = DataTransferManager.GetForCurrentView();
- manager.DataRequested += manager_DataRequested;
- }
+
void manager_DataRequested(DataTransferManager sender, DataRequestedEventArgs args)
{
@@ -214,8 +209,21 @@ private LoggingConfiguration CreateNewSettings()
await this.FileToShare.DeleteAsync();
this.FileToShare = file;
+
+ var manager = DataTransferManager.GetForCurrentView();
+ manager.DataRequested += manager_DataRequested;
+
// share...
DataTransferManager.ShowShareUI();
+
+ manager.DataRequested -= manager_DataRequested;
+ }
+
+ private async void ShareLogs(object sender, RoutedEventArgs e)
+ {
+ var lm = (IWinRTLogManager)LogManagerFactory.DefaultLogManager;
+
+ await lm.ShareLogFile("Win 8 Sample app", "The description");
}
}
}

0 comments on commit a5f02a4

Please sign in to comment.