Permalink
Browse files

Release development (#379)

* Fix local build issue when PP path contains a space

* Allow T4 templates to be transformed outside of Visual Studio

Change `GetCurrentProject()`, `GetProjectPath()`, `GetDataDirectory()`, and `GetConfigPath()` methods  to detect if `EnvDTE.Project` is `null` (which happens if transformation happens outside of Visual Studio) and use alternative means of getting their information.

This makes PetaPoco's templates compatible with [TextTransform.exe](https://msdn.microsoft.com/en-us/library/bb126245.aspx) and [TransformOnBuild](https://github.com/clariuslabs/TransformOnBuild) NuGet package.

* Scope table generation by specified schema to prevent name collisions (#366)

* introduced lock block when accessing static _converters object in PocoData (#376)
  • Loading branch information...
pleb committed Mar 21, 2017
1 parent ae56138 commit d597a80c1070e32de388ffb690607d2495227606
@@ -4,7 +4,8 @@
<StartArguments>/?</StartArguments>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|AnyCPU'">
<StartArguments>-o:PetaPoco.cs Database.cs -r *.cs -x:Properties\*.cs</StartArguments>
<StartWorkingDirectory>C:\b\dev\Source\petapoco\PetaPoco\</StartWorkingDirectory>
<StartArguments>"C:\Projects\Open Source\PetaPoco\PetaPoco\\"</StartArguments>
<StartWorkingDirectory>
</StartWorkingDirectory>
</PropertyGroup>
</Project>
View
@@ -19,6 +19,7 @@ public class PocoData
{
private static Cache<Type, PocoData> _pocoDatas = new Cache<Type, PocoData>();
private static List<Func<object, object>> _converters = new List<Func<object, object>>();
private static object _converterLock = new object();
private static MethodInfo fnGetValue = typeof(IDataRecord).GetMethod("GetValue", new Type[] {typeof(int)});
private static MethodInfo fnIsDBNull = typeof(IDataRecord).GetMethod("IsDBNull");
private static FieldInfo fldConverters = typeof(PocoData).GetField("_converters", BindingFlags.Static | BindingFlags.GetField | BindingFlags.NonPublic);
@@ -313,8 +314,13 @@ private static void AddConverterToStack(ILGenerator il, Func<object, object> con
if (converter != null)
{
// Add the converter
int converterIndex = _converters.Count;
_converters.Add(converter);
int converterIndex;
lock (_converterLock)
{
converterIndex = _converters.Count;
_converters.Add(converter);
}
// Generate IL to push the converter onto the stack
il.Emit(OpCodes.Ldsfld, fldConverters);
View
@@ -121,17 +121,11 @@
<Service Include="{508349B6-6B84-4DF5-91F0-309BEEBAD82D}" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<PropertyGroup>
<PostBuildEvent Condition="!$(DefineConstants.Contains('SKIP_POST_BUILD'))">
"$(SolutionDir)Tools\PetaPoco.Cs.Joiner.exe" -o:"$(SolutionDir)\Output\PetaPoco.cs" "$(ProjectDir)\Database.cs" -r *.cs -x:"$(ProjectDir)\Properties\*.cs"
COPY "$(ProjectDir)T4 Templates\*" "$(SolutionDir)Output\"
</PostBuildEvent>
</PropertyGroup>
<PropertyGroup>
<PostBuildEvent>
"$(ProjectDir)..\Tools\PetaPoco.Cs.Joiner.exe" $(ProjectDir)
"$(ProjectDir)..\Tools\PetaPoco.Cs.Joiner.exe" "$(ProjectDir)\"
COPY "$(ProjectDir)T4 Templates\*" "$(ProjectDir)..\Output\"
</PostBuildEvent>
</PostBuildEvent>
</PropertyGroup>
<!-- 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.
@@ -1,4 +1,5 @@
<#@ template language="C#v3.5" hostspecific="True" #>
<#@ template language="C#" hostspecific="True" #>
<#@ output extension=".cs" #>
<#@ assembly name="EnvDTE" #>
<#@ assembly name="System.Core.dll" #>
<#@ assembly name="System.Data" #>
@@ -282,49 +283,99 @@ public string ProviderName
public EnvDTE.Project GetCurrentProject() {
IServiceProvider _ServiceProvider = (IServiceProvider)Host;
if (_ServiceProvider == null)
throw new Exception("Host property returned unexpected value (null)");
IServiceProvider _ServiceProvider = Host as IServiceProvider;
if (_ServiceProvider == null)
return null;
EnvDTE.DTE dte = (EnvDTE.DTE)_ServiceProvider.GetService(typeof(EnvDTE.DTE));
if (dte == null)
throw new Exception("Unable to retrieve EnvDTE.DTE");
EnvDTE.DTE dte = _ServiceProvider.GetService(typeof(EnvDTE.DTE)) as EnvDTE.DTE;
if (dte == null)
return null;
Array activeSolutionProjects = (Array)dte.ActiveSolutionProjects;
if (activeSolutionProjects == null)
throw new Exception("DTE.ActiveSolutionProjects returned null");
Array activeSolutionProjects = dte.ActiveSolutionProjects as Array;
if (activeSolutionProjects == null)
return null;
EnvDTE.Project dteProject = (EnvDTE.Project)activeSolutionProjects.GetValue(0);
if (dteProject == null)
throw new Exception("DTE.ActiveSolutionProjects[0] returned null");
EnvDTE.Project dteProject = activeSolutionProjects.GetValue(0) as EnvDTE.Project;
if (dteProject == null)
return null;
return dteProject;
return dteProject;
}
private string GetProjectPath()
{
EnvDTE.Project project = GetCurrentProject();
System.IO.FileInfo info = new System.IO.FileInfo(project.FullName);
return info.Directory.FullName;
EnvDTE.Project project = GetCurrentProject();
if (project != null)
{
System.IO.FileInfo info = new System.IO.FileInfo(project.FullName);
return info.Directory.FullName;
}
else
{
string currentDir = System.IO.Path.GetDirectoryName(Host.TemplateFile);
return GetProjectPath(currentDir);
}
}
private string GetProjectPath(string startingSearchDir)
{
string[] projFiles = Directory.GetFiles(startingSearchDir, "*.csproj");
if (projFiles.Length != 0)
{
System.IO.FileInfo projectFileInfo = new System.IO.FileInfo(projFiles[0]);
return projectFileInfo.Directory.FullName;
}
else
{
var parentDir = Directory.GetParent(startingSearchDir);
if (parentDir != null)
{
return GetProjectPath(parentDir.FullName);
}
}
return string.Empty;
}
private string GetConfigPath()
{
EnvDTE.Project project = GetCurrentProject();
foreach (EnvDTE.ProjectItem item in project.ProjectItems)
{
// if it is the app.config file, then open it up
if (item.Name.Equals("App.config",StringComparison.InvariantCultureIgnoreCase) || item.Name.Equals("Web.config",StringComparison.InvariantCultureIgnoreCase))
return GetProjectPath() + "\\" + item.Name;
}
return String.Empty;
EnvDTE.Project project = GetCurrentProject();
if (project != null)
{
foreach (EnvDTE.ProjectItem item in project.ProjectItems)
{
// if it is the app.config file, then open it up
if (item.Name.Equals("App.config",StringComparison.InvariantCultureIgnoreCase) || item.Name.Equals("Web.config",StringComparison.InvariantCultureIgnoreCase))
return GetProjectPath() + "\\" + item.Name;
}
}
else
{
string projectDir = GetProjectPath();
var configFiles = Directory.GetFiles(projectDir, "*.config");
foreach (var configFile in configFiles)
{
if (configFile.EndsWith("App.config", StringComparison.OrdinalIgnoreCase) ||
configFile.EndsWith("Web.config", StringComparison.OrdinalIgnoreCase))
{
return configFile;
}
}
}
return String.Empty;
}
public string GetDataDirectory()
{
EnvDTE.Project project=GetCurrentProject();
return System.IO.Path.GetDirectoryName(project.FileName)+"\\App_Data\\";
EnvDTE.Project project=GetCurrentProject();
if (project != null)
{
return System.IO.Path.GetDirectoryName(project.FileName)+"\\App_Data\\";
}
else
{
return GetProjectPath() + "\\App_Data\\";
}
}
static string zap_password(string connectionString)
@@ -938,6 +989,11 @@ class PostGreSqlSchemaReader : SchemaReader
p.Value=tbl.Name;
cmd.Parameters.Add(p);
var s = cmd.CreateParameter();
s.ParameterName = "@tableSchema";
s.Value=tbl.Schema;
cmd.Parameters.Add(s);
var result=new List<Column>();
using (IDataReader rdr=cmd.ExecuteReader())
{
@@ -1045,7 +1101,7 @@ class PostGreSqlSchemaReader : SchemaReader
const string COLUMN_SQL=@"
SELECT column_name, is_nullable, udt_name, column_default
FROM information_schema.columns
WHERE table_name=@tableName;
WHERE table_name=@tableName and table_schema = @tableSchema;
";
}

0 comments on commit d597a80

Please sign in to comment.