Skip to content

Commit

Permalink
Link files into plat-specific libs to enable targetting WP8 in the core
Browse files Browse the repository at this point in the history
  • Loading branch information
Oren Novotny committed Nov 29, 2012
1 parent 1126f5d commit a5f02a4
Show file tree
Hide file tree
Showing 16 changed files with 114 additions and 26 deletions.
2 changes: 2 additions & 0 deletions MetroLog.NetCore/IWinRTLogManager.cs
Expand Up @@ -10,5 +10,7 @@ namespace MetroLog
public interface IWinRTLogManager : ILogManager
{
Task<IStorageFile> GetCompressedLogFile();
Task ShareLogFile(string title, string description);

}
}
2 changes: 2 additions & 0 deletions MetroLog.NetCore/LazyFlushManager.cs
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions MetroLog.NetCore/LogConfigurator.cs
Expand Up @@ -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;
}
Expand Down
50 changes: 50 additions & 0 deletions MetroLog.NetCore/LogManager.cs
Expand Up @@ -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
Expand Down Expand Up @@ -38,5 +40,53 @@ public async Task<IStorageFile> GetCompressedLogFile()

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!");
}
}
}
12 changes: 12 additions & 0 deletions MetroLog.NetCore/MetroLog.NetCore.csproj
Expand Up @@ -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>
Expand Down
10 changes: 5 additions & 5 deletions MetroLog.NetCore/ZipFile.cs
Expand Up @@ -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('\\', '/');

Expand All @@ -44,12 +44,12 @@ private static async Task DoCreateFromDirectory(IStorageFolder source, Stream de
}


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");

Expand Down
4 changes: 2 additions & 2 deletions MetroLog.NetFx/FileTarget.cs
Expand Up @@ -30,7 +30,7 @@ public string PathUnderAppData
}
}

protected override async Task<Stream> GetCompressedLogsInternal()
protected override Task<Stream> GetCompressedLogsInternal()
{
var ms = new MemoryStream();

Expand All @@ -44,7 +44,7 @@ protected override async Task<Stream> GetCompressedLogsInternal()

ms.Position = 0;

return ms;
return Task.FromResult<Stream>(ms);
}

protected FileTarget(Layout layout) : base(layout)
Expand Down
1 change: 1 addition & 0 deletions MetroLog.NetFx/LogConfigurator.cs
Expand Up @@ -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;
}
Expand Down
13 changes: 13 additions & 0 deletions MetroLog.NetFx/MetroLog.NetFx.csproj
Expand Up @@ -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>
Expand Down
6 changes: 3 additions & 3 deletions MetroLog.nuspec
Expand Up @@ -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>
Expand All @@ -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" />
Expand Down
4 changes: 3 additions & 1 deletion MetroLog.sln.DotSettings
@@ -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>
2 changes: 1 addition & 1 deletion MetroLog/Internal/LogConfiguratorBase.cs
Expand Up @@ -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;
}
Expand Down
8 changes: 2 additions & 6 deletions MetroLog/MetroLog.csproj
Expand Up @@ -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>
Expand Down Expand Up @@ -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" />
Expand Down
2 changes: 1 addition & 1 deletion MetroLog/Strings.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Win8Sample/LogSamplePage.xaml
Expand Up @@ -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" />
Expand Down
22 changes: 15 additions & 7 deletions Win8Sample/LogSamplePage.xaml.cs
Expand Up @@ -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)
{
Expand Down Expand Up @@ -214,8 +209,21 @@ private async void HandleReadSQLiteValues(object sender, RoutedEventArgs e)
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.