Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions src/GOEddie.Dacpac.References/CustomData.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
using System.Collections.Generic;
using System.Linq;

namespace GOEddie.Dacpac.References
{
public class CustomData
{
private readonly Dictionary<string, Metadata> _items = new Dictionary<string, Metadata>();
public readonly string Category;
public readonly string Type;
public List<string> RequiredSqlCmdVars = new List<string>();

public CustomData(string category, string type)
{
Category = category;
Type = type;
}

public List<Metadata> Items
{
get { return _items.Values.ToList(); }
}

public void AddMetadata(string name, string value)
{
_items[name] = new Metadata(name, value);
}
}
}
10 changes: 10 additions & 0 deletions src/GOEddie.Dacpac.References/DacHacFactory.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
namespace GOEddie.Dacpac.References
{
public class DacHacFactory
{
public DacHacXml Build(string path)
{
return new DacHacXml(path);
}
}
}
57 changes: 57 additions & 0 deletions src/GOEddie.Dacpac.References/DacpacXml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
using System;
using System.IO;
using System.IO.Packaging;
using System.Text;

namespace GOEddie.Dacpac.References
{
public class DacHacXml : IDisposable
{
private readonly string _dacPath;
private Package _package;

public DacHacXml(string dacPath)
{
_dacPath = dacPath;
_package = Package.Open(dacPath, FileMode.Open, FileAccess.ReadWrite);
}

public void Dispose()
{
Close();
}

public string GetXml(string fileName)
{
var part = _package.GetPart(new Uri(string.Format("/{0}", fileName), UriKind.Relative));
var stream = part.GetStream();

return new StreamReader(stream).ReadToEnd();
}

public Stream GetStream(string fileName)
{
var part = _package.GetPart(new Uri(string.Format("/{0}", fileName), UriKind.Relative));
var stream = part.GetStream();
return stream;
}

public void SetXml(string fileName, string xml)
{
var part = _package.GetPart(new Uri(string.Format("/{0}", fileName), UriKind.Relative));
var stream = part.GetStream();

var bytes = Encoding.ASCII.GetBytes(xml);
stream.SetLength(bytes.Length);
stream.Write(bytes, 0, bytes.Length);

_package.Close();
_package = Package.Open(_dacPath, FileMode.Open, FileAccess.ReadWrite);
}

public void Close()
{
_package.Close();
}
}
}
62 changes: 62 additions & 0 deletions src/GOEddie.Dacpac.References/GOEddie.Dacpac.References.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
<?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>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{1622EB7A-0902-417C-9673-97BC13DC2DAF}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>GOEddie.Dacpac.References</RootNamespace>
<AssemblyName>GOEddie.Dacpac.References</AssemblyName>
<TargetFrameworkVersion>v4.5.1</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
</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>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
<Reference Include="WindowsBase" />
</ItemGroup>
<ItemGroup>
<Compile Include="CustomData.cs" />
<Compile Include="DacHacFactory.cs" />
<Compile Include="DacpacXml.cs" />
<Compile Include="HeaderWriter.cs" />
<Compile Include="Metadata.cs" />
<Compile Include="ModelChecksumWriter.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Reference.cs" />
<Compile Include="HeaderParser.cs" />
<Compile Include="ReferenceBuilder.cs" />
</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>
33 changes: 33 additions & 0 deletions src/GOEddie.Dacpac.References/GOEddie.Dacpac.References.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 2013
VisualStudioVersion = 12.0.31101.0
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GOEddie.Dacpac.References", "GOEddie.Dacpac.References.csproj", "{1622EB7A-0902-417C-9673-97BC13DC2DAF}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Tests", "Tests", "{4540CC1D-4176-43D4-98B4-85E1E875307D}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DacpacHeaderParser.Tests", "..\DacpacHeaderParser.Tests\DacpacHeaderParser.Tests.csproj", "{8F0270E8-951E-4338-A661-277EAD18E8D4}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{1622EB7A-0902-417C-9673-97BC13DC2DAF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{1622EB7A-0902-417C-9673-97BC13DC2DAF}.Debug|Any CPU.Build.0 = Debug|Any CPU
{1622EB7A-0902-417C-9673-97BC13DC2DAF}.Release|Any CPU.ActiveCfg = Release|Any CPU
{1622EB7A-0902-417C-9673-97BC13DC2DAF}.Release|Any CPU.Build.0 = Release|Any CPU
{8F0270E8-951E-4338-A661-277EAD18E8D4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{8F0270E8-951E-4338-A661-277EAD18E8D4}.Debug|Any CPU.Build.0 = Debug|Any CPU
{8F0270E8-951E-4338-A661-277EAD18E8D4}.Release|Any CPU.ActiveCfg = Release|Any CPU
{8F0270E8-951E-4338-A661-277EAD18E8D4}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{8F0270E8-951E-4338-A661-277EAD18E8D4} = {4540CC1D-4176-43D4-98B4-85E1E875307D}
EndGlobalSection
EndGlobal
56 changes: 56 additions & 0 deletions src/GOEddie.Dacpac.References/HeaderParser.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
using System.Collections.Generic;
using System.IO;
using System.Xml;

namespace GOEddie.Dacpac.References
{
public class HeaderParser
{
private readonly string _dacPacPath;

public HeaderParser(string dacPacPath)
{
_dacPacPath = dacPacPath;
}

public List<CustomData> GetCustomData()
{
var dac = new DacHacXml(_dacPacPath);
var xml = dac.GetXml("Model.xml");

var reader = XmlReader.Create(new StringReader(xml));
reader.MoveToContent();

var data = new List<CustomData>();
CustomData currentCustomData = null;

while (reader.Read())
{
if (reader.Name == "CustomData" && reader.NodeType == XmlNodeType.Element)
{
var cat = reader.GetAttribute("Category");
var type = reader.GetAttribute("Type");

currentCustomData = new CustomData(cat, type);
data.Add(currentCustomData);
}

if (reader.Name == "Metadata" && reader.NodeType == XmlNodeType.Element)
{
var name = reader.GetAttribute("Name");
var value = reader.GetAttribute("Value");

currentCustomData.AddMetadata(name, value);
}

if (reader.Name == "Header" && reader.NodeType == XmlNodeType.EndElement)
{
break; //gone too far
}
}
dac.Close();

return data;
}
}
}
Loading