Skip to content

Commit

Permalink
working on lp5/6.
Browse files Browse the repository at this point in the history
  • Loading branch information
Ronnie Overby committed Apr 13, 2020
1 parent 3deee43 commit 6b1ea72
Show file tree
Hide file tree
Showing 5 changed files with 82 additions and 14 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Expand Up @@ -353,3 +353,5 @@ healthchecksdb
MigrationBackup/

# End of https://www.gitignore.io/api/visualstudio
/Overby.LINQPad.FileDriver.lpx
/Overby.LINQPad.FileDriver.lpx6
17 changes: 12 additions & 5 deletions DynamicDriver.cs
Expand Up @@ -9,6 +9,7 @@
using System.Reflection;
using System.Security.Cryptography;
using System.Text.RegularExpressions;
using System.Xml;
using static LINQPad.Extensibility.DataContext.ExplorerIcon;
using static LINQPad.Extensibility.DataContext.ExplorerItemKind;
using static Overby.LINQPad.FileDriver.ValueTyper;
Expand Down Expand Up @@ -140,10 +141,12 @@ string GenerateFileProperty()
{{
get
{{
using var streamReader = new StreamReader({nameSpace}.FilePaths.{fileClassName});
var csvRecords = Overby.Extensions.Text.CsvParsingExtensions.ReadCsvWithHeader(streamReader);
foreach(var record in csvRecords)
yield return {nameSpace}.RecordTypes.{fileClassName}.Create(record);
using(var streamReader = new StreamReader({nameSpace}.FilePaths.{fileClassName}))
{{
var csvRecords = Overby.Extensions.Text.CsvParsingExtensions.ReadCsvWithHeader(streamReader);
foreach(var record in csvRecords)
yield return {nameSpace}.RecordTypes.{fileClassName}.Create(record);
}}
}}
}}";
}
Expand Down Expand Up @@ -245,13 +248,17 @@ static void Compile(string cSharpSourceCode, string outputFile)
// .NET Framework - here's how to get the basic Framework assemblies:
new[]
{
typeof (int).Assembly.Location, // mscorlib
typeof (int).Assembly.Location, // mscorlib
typeof (Uri).Assembly.Location, // System
typeof (XmlConvert).Assembly.Location, // System.Xml
typeof (Enumerable).Assembly.Location, // System.Core
typeof (DataSet).Assembly.Location // System.Data
};
#endif





assembliesToReference = assembliesToReference.Concat(new[] {
typeof(CsvRecord).Assembly.Location,
Expand Down
21 changes: 14 additions & 7 deletions Overby.LINQPad.FileDriver.csproj
@@ -1,12 +1,12 @@
<Project Sdk="Microsoft.NET.Sdk.WindowsDesktop">

<PropertyGroup>
<TargetFrameworks>netcoreapp3.0</TargetFrameworks>
<!--<TargetFrameworks>netcoreapp3.0;net46</TargetFrameworks>-->
<!--<TargetFrameworks>netcoreapp3.0</TargetFrameworks>-->
<TargetFrameworks>netcoreapp3.0;net46</TargetFrameworks>
<UseWpf>true</UseWpf>
<AssemblyName>Overby.LINQPad.FileDriver</AssemblyName>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<PackageTags>linqpad-driver</PackageTags>
<PackageTags>linqpaddriver</PackageTags>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
</PropertyGroup>

Expand All @@ -16,6 +16,7 @@

<ItemGroup>
<PackageReference Include="LINQPad.Reference" Version="1.*" />
<PackageReference Include="System.ValueTuple" Version="4.5.0" />
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'net46'">
Expand All @@ -39,13 +40,19 @@
<Folder Include="linqpad-samples\\" />
</ItemGroup>

<ItemGroup>
<ItemGroup Condition="'$(TargetFramework)' == 'netcoreapp3.0'">
<Reference Include="Overby.Extensions.Text">
<HintPath>..\Overby.Extensions.CSV\Overby.Extensions.CSV\bin\Release\netstandard1.3\Overby.Extensions.Text.dll</HintPath>
</Reference>
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'net46'">
<Reference Include="Overby.Extensions.Text">
<HintPath>..\Overby.Extensions.CSV\Overby.Extensions.CSV\bin\Release\netstandard2.1\Overby.Extensions.Text.dll</HintPath>
<HintPath>..\Overby.Extensions.CSV\Overby.Extensions.CSV\bin\Release\net46\Overby.Extensions.Text.dll</HintPath>
</Reference>
</ItemGroup>
</ItemGroup>

<Target Name="PostBuild1" AfterTargets="PostBuildEvent" Condition="'$(TargetFramework)' == 'netcoreapp3.0'">
<Target Name="PostBuild1" AfterTargets="PostBuildEvent" Condition="'$(TargetFramework)' == 'netcoreapp3.0'">
<Exec Command="xcopy /i/y/s &quot;$(TargetDir)*.*&quot; &quot;%25LocalAppData%25\\LINQPad\\Drivers\\DataContext\\NetCore\\$(TargetName)&quot;" />
</Target>

Expand Down
7 changes: 5 additions & 2 deletions ValueTyper.cs
Expand Up @@ -139,7 +139,7 @@ static class ValueTyper
// determine best types

var parsedTypesCopy = parsedTypes
.ToDictionary(p => p.Key, p => p.Value.ToHashSet());
.ToDictionary(p => p.Key, p => new HashSet<ParsedType>(p.Value));


var finalTypes = parsedTypes
Expand Down Expand Up @@ -223,7 +223,10 @@ bool WidestTypeMapped(out BestType best, ParsedType[] possibles, ParsedType[] ac
bool WidestTypeMapAll(out BestType best, ParsedType mapAllTo, params ParsedType[] possibles)
{
var actuals = new ParsedType[possibles.Length];
Array.Fill(actuals, mapAllTo);

for (int i = 0; i < actuals.Length; i++)
actuals[i] = mapAllTo;

return WidestTypeMapped(out best, possibles, actuals);
}

Expand Down
49 changes: 49 additions & 0 deletions create lpx.linq
@@ -0,0 +1,49 @@
<Query Kind="Program">
<Namespace>System.IO.Compression</Namespace>
</Query>

void Main()
{
CreateLPX();
CreateLPX6();
}

void CreateLPX()
{
var queryFolder = new FileInfo(Util.CurrentQueryPath).DirectoryName;

var net46Dir = new DirectoryInfo(
Path.Combine(queryFolder, "bin", "Release", "net46"));

var lpxFile = Path.Combine(queryFolder, "Overby.LINQPad.FileDriver.lpx");

File.Delete(lpxFile);
ZipFile.CreateFromDirectory(net46Dir.FullName, lpxFile);

using var fs = File.Open(lpxFile, FileMode.Open, FileAccess.ReadWrite, FileShare.None);
using var za = new ZipArchive(fs, ZipArchiveMode.Update);
var headerEntry = za.CreateEntry("header.xml");
using var manstream = headerEntry.Open();
using var manwriter = new StreamWriter(manstream);

manwriter.WriteLine(
$@"<?xml version=""1.0"" encoding=""utf-8"" ?>
<DataContextDriver>
<MainAssembly>Overby.LINQPad.FileDriver.dll</MainAssembly>
<SupportUri>http://ronn.io</SupportUri>
</DataContextDriver>");
}

void CreateLPX6()
{
var queryFolder = new FileInfo(Util.CurrentQueryPath).DirectoryName;

var net46Dir = new DirectoryInfo(
Path.Combine(queryFolder, "bin", "Release", "netcoreapp3.0"));

var lpxFile = Path.Combine(queryFolder, "Overby.LINQPad.FileDriver.lpx6");

File.Delete(lpxFile);
ZipFile.CreateFromDirectory(net46Dir.FullName, lpxFile);
}

0 comments on commit 6b1ea72

Please sign in to comment.