Skip to content

Commit

Permalink
Mass-refactoring, semantic & packaging
Browse files Browse the repository at this point in the history
  • Loading branch information
Stephan committed Apr 22, 2014
1 parent e9679ae commit 45a9c35
Show file tree
Hide file tree
Showing 34 changed files with 635 additions and 378 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,5 @@ pkg
packages
refs
*.snk
/build/Debug
/build/Release
4 changes: 3 additions & 1 deletion Zbu.ModelsBuilder.AspNet/ModelsBuilderAuthFilter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using System.Web.Http.Controllers;
using System.Web.Security;
using Umbraco.Core;
using Umbraco.Core.Configuration;
using Umbraco.Core.Models.Membership;

namespace Zbu.ModelsBuilder.AspNet
Expand Down Expand Up @@ -60,7 +61,8 @@ private static IUser Authenticate(HttpRequestMessage request)
var username = credentials[0];
var password = credentials[1];

var provider = Membership.Providers[umbraco.UmbracoSettings.DefaultBackofficeProvider];
var providerKey = UmbracoConfig.For.UmbracoSettings().Providers.DefaultBackOfficeUserProvider;
var provider = Membership.Providers[providerKey];
if (provider == null || !provider.ValidateUser(username, password))
return null;
var user = ApplicationContext.Current.Services.UserService.GetByUsername(username);
Expand Down
26 changes: 13 additions & 13 deletions Zbu.ModelsBuilder.AspNet/ModelsBuilderController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -91,27 +91,27 @@ public HttpResponseMessage BuildModels()
// return Request.CreateResponse(HttpStatusCode.OK, modelTypes, Configuration.Formatters.JsonFormatter);
//}

[System.Web.Http.HttpGet] // use the http one, not mvc, with api controllers!
[System.Web.Http.HttpPost] // use the http one, not mvc, with api controllers!
[ModelsBuilderAuthFilter("developer")] // have to use our own, non-cookie-based, auth
public HttpResponseMessage GetModels(IDictionary<string, string> ourFiles)
{
var umbraco = Application.GetApplication();
var modelTypes = umbraco.GetContentAndMediaTypes();
var typeModels = umbraco.GetContentAndMediaTypes();

var modelsNamespace = ourFiles["__META__"];
ourFiles.Remove("__META__");

var builder = new TextBuilder();
var builder = new TextBuilder(typeModels);
builder.Namespace = modelsNamespace;
var disco = new CodeDiscovery().Discover(ourFiles);
builder.Prepare(modelTypes, disco);
builder.Prepare(disco);

var models = new Dictionary<string, string>();
foreach (var modelType in modelTypes)
foreach (var typeModel in builder.GetModelsToGenerate())
{
var sb = new StringBuilder();
builder.Generate(sb, modelType);
models[modelType.Name] = sb.ToString();
builder.Generate(sb, typeModel);
models[typeModel.Name] = sb.ToString();
}

return Request.CreateResponse(HttpStatusCode.OK, models, Configuration.Formatters.JsonFormatter);
Expand All @@ -127,22 +127,22 @@ private static void GenerateModels(string appData)
File.Delete(file);

var umbraco = Application.GetApplication();
var modelTypes = umbraco.GetContentAndMediaTypes();
var typeModels = umbraco.GetContentAndMediaTypes();

var ns = ConfigurationManager.AppSettings["Zbu.ModelsBuilder.ModelsNamespace"];
if (string.IsNullOrWhiteSpace(ns)) ns = "Umbraco.Web.PublishedContentModels";

var builder = new TextBuilder();
var builder = new TextBuilder(typeModels);
builder.Namespace = ns;
var ourFiles = Directory.GetFiles(modelsDirectory, "*.cs").ToDictionary(x => x, File.ReadAllText);
var disco = new CodeDiscovery().Discover(ourFiles);
builder.Prepare(modelTypes, disco);
builder.Prepare(disco);

foreach (var modelType in modelTypes)
foreach (var typeModel in builder.GetModelsToGenerate())
{
var sb = new StringBuilder();
builder.Generate(sb, modelType);
var filename = Path.Combine(modelsDirectory, modelType.Name + ".generated.cs");
builder.Generate(sb, typeModel);
var filename = Path.Combine(modelsDirectory, typeModel.Name + ".generated.cs");
File.WriteAllText(filename, sb.ToString());
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,19 @@
<%@ Control Language="C#" AutoEventWireup="true" %>
<%@ Register TagPrefix="umb" Namespace="ClientDependency.Core.Controls" Assembly="ClientDependency.Core" %>

<umb:CssInclude runat="server" FilePath="propertypane/style.css" PathNameAlias="UmbracoClient" />
<script runat="server">
protected override void OnLoad(EventArgs e)
{
// <%@ Register TagPrefix="umb" Namespace="ClientDependency.Core.Controls" Assembly="ClientDependency.Core" %>
// <umb:CssInclude runat="server" FilePath="propertypane/style.css" PathNameAlias="UmbracoClient" />
var ver = Umbraco.Core.Configuration.UmbracoVersion.Current;
if (ver.Major >= 7) return;
var css = new ClientDependency.Core.Controls.CssInclude();
css.FilePath = "propertypane/style.css";
css.PathNameAlias = "UmbracoClient";
Page.Controls.Add(css);
}
</script>

<script type="text/javascript">
jQuery(document).ready(function () {
Expand Down Expand Up @@ -45,9 +57,12 @@
<div class="propertyItem">
<div class="dashboardWrapper">
<h2>Generate Models</h2>
<img class="dashboardIcon" alt="Umbraco" src="./dashboard/images/logo32x32.png">
<img class="dashboardIcon" alt="Umbraco" src="/UserControls/Zbu/ModelsBuilder/logo32x32.png">
<div id="generateModelsPane" style="min-height: 240px;">
<p>Click to generate models. Beware! It will restart the application.</p>
<p>Click to generate models.
<%=ConfigurationManager.AppSettings["Zbu.ModelsBuilder.AspNet.BuildModels"] == "true"
? "Beware! It will restart the application." : "" %>
</p>
<p>
<button id="generateModels">Generate</button>
</p>
Expand Down
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
90 changes: 68 additions & 22 deletions Zbu.ModelsBuilder.AspNet/Zbu.ModelsBuilder.AspNet.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
AND IN ADDITION MSBUILD DOES NOT SEEM TO FIND THE DEPENDENT ZIPLIB IF IT IS NOT IN THE SAME DIRECTORY...
<MSBuildUmbracoTasksPath>$(SolutionDir)\packages\MSBuild.Umbraco.Tasks.1.0\lib</MSBuildUmbracoTasksPath>
-->
<!-- AND I HAVE TO INITIALIZE SolutionDir HERE BECAUSE OTHERWISE NUGET CANT BUILD THE PKG -->
<SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\</SolutionDir>
<MSBuildUmbracoTasksPath>$(SolutionDir)\lib</MSBuildUmbracoTasksPath>
</PropertyGroup>
<Import Project="$(MSBuildUmbracoTasksPath)\MSBuild.Umbraco.Tasks.targets" />
Expand All @@ -22,6 +24,9 @@
<FileAlignment>512</FileAlignment>
<SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\</SolutionDir>
<RestorePackages>true</RestorePackages>
<!--
<BuildPackage>true</BuildPackage>
-->
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
Expand All @@ -41,20 +46,25 @@
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="businesslogic, Version=1.0.5051.28196, Culture=neutral, processorArchitecture=MSIL">
<Reference Include="businesslogic, Version=1.0.5212.27026, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\..\src\src\Umbraco.Web.UI\bin\businesslogic.dll</HintPath>
<HintPath>..\umbraco\businesslogic.dll</HintPath>
</Reference>
<Reference Include="ICSharpCode.SharpZipLib, Version=0.86.0.518, Culture=neutral, PublicKeyToken=1b03e6acf1164f73, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\packages\SharpZipLib.0.86.0\lib\20\ICSharpCode.SharpZipLib.dll</HintPath>
</Reference>
<Reference Include="interfaces">
<HintPath>..\..\..\src\src\Umbraco.Web.UI\bin\interfaces.dll</HintPath>
<Reference Include="interfaces, Version=1.0.5189.32661, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\umbraco\interfaces.dll</HintPath>
</Reference>
<Reference Include="MSBuild.Umbraco.Tasks">
<HintPath>..\packages\MSBuild.Umbraco.Tasks.1.0\lib\MSBuild.Umbraco.Tasks.dll</HintPath>
</Reference>
<Reference Include="Newtonsoft.Json, Version=4.5.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\umbraco\lib-7.1.2\Newtonsoft.Json.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Configuration" />
<Reference Include="System.Core" />
Expand All @@ -69,11 +79,13 @@
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
<Reference Include="umbraco">
<HintPath>..\..\..\src\src\Umbraco.Web.UI\bin\umbraco.dll</HintPath>
<Reference Include="umbraco, Version=1.0.5212.27029, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\umbraco\umbraco.dll</HintPath>
</Reference>
<Reference Include="Umbraco.Core">
<HintPath>..\..\..\src\src\Umbraco.Web.UI\bin\Umbraco.Core.dll</HintPath>
<Reference Include="Umbraco.Core, Version=1.0.5212.27025, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\umbraco\Umbraco.Core.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
Expand All @@ -98,24 +110,32 @@
</ProjectReference>
</ItemGroup>
<ItemGroup>
<Content Include="BuildModels.ascx">
<Content Include="UserControls\Zbu\ModelsBuilder\BuildModels.ascx">
<SubType>ASPXCodeBehind</SubType>
</Content>
<Content Include="package.xml">
<Content Include="UserControls\Zbu\ModelsBuilder\logo32x32.png" />
<None Include="build\NuSpecs\Zbu.ModelsBuilder.AspNet.nuspec" />
<None Include="package.xml">
<SubType>Designer</SubType>
</Content>
</None>
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Import Project="$(SolutionDir)\.nuget\NuGet.targets" Condition="Exists('$(SolutionDir)\.nuget\NuGet.targets')" />
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup>
<ErrorText>This project references NuGet package(s) that are missing on this computer. Enable NuGet Package Restore to download them. For more information, see <span class="skimlinks-unlinked">http://go.microsoft.com/fwlink/?LinkID=322105</span>. The missing file is {0}.</ErrorText>
</PropertyGroup>
<Error Condition="!Exists('$(SolutionDir)\.nuget\NuGet.targets')" Text="$([System.String]::Format('$(ErrorText)', '$(SolutionDir)\.nuget\NuGet.targets'))" />
</Target>
<!-- 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" DependsOnTargets="Package">
<Target Name="AfterBuild" DependsOnTargets="UmbracoPackage;NuGetPackage">
</Target>
<!-- PACKAGE -->
<!-- SEE TOP OF FILE... TRYING TO FIX THE MESS BUT IT DOES NOT WORK
Expand All @@ -125,26 +145,52 @@
</CreateProperty>
</Target>
-->
<Target Name="Package">
<Target Name="UmbracoPackage">
<GetAssemblyIdentity AssemblyFiles="$(OutputPath)Zbu.ModelsBuilder.dll">
<Output TaskParameter="Assemblies" ItemName="AssemblyInfos" />
</GetAssemblyIdentity>
<Message Importance="High" Text="Packaging version %(AssemblyInfos.Version)" />
<RemoveDir Directories="$(ProjectDir)pkg\$(Configuration)" Condition="Exists('$(ProjectDir)pkg\$(Configuration)')" />
<MakeDir Directories="$(ProjectDir)pkg\$(Configuration)" />
<Copy SourceFiles="$(ProjectDir)package.xml" DestinationFolder="$(ProjectDir)pkg\$(Configuration)" />
<ManifestUpdate ManifestFile="$(ProjectDir)pkg\$(Configuration)\package.xml" WorkingDirectory="$(ProjectDir)pkg\$(Configuration)" PackageVersion="%(AssemblyInfos.Version)" />
<Message Importance="High" Text="Packaging version %(AssemblyInfos.Version) into Umbraco package" />
<RemoveDir Directories="$(ProjectDir)pkg" Condition="Exists('$(ProjectDir)pkg')" />
<MakeDir Directories="$(ProjectDir)pkg" />
<Copy SourceFiles="$(ProjectDir)package.xml" DestinationFolder="$(ProjectDir)pkg" />
<ManifestUpdate ManifestFile="$(ProjectDir)pkg\package.xml" WorkingDirectory="$(ProjectDir)pkg" PackageVersion="%(AssemblyInfos.Version)" />
<ItemGroup>
<PackageFiles Include="$(ProjectDir)pkg\$(Configuration)\package.xml" />
<PackageFiles Include="$(ProjectDir)BuildModels.ascx" />
<PackageFiles Include="$(ProjectDir)pkg\package.xml" />
<PackageFiles Include="$(ProjectDir)UserControls\Zbu\ModelsBuilder\BuildModels.ascx" />
<PackageFiles Include="$(ProjectDir)UserControls\Zbu\ModelsBuilder\logo32x32.png" />
<PackageFiles Include="$(OutputPath)Microsoft.CodeAnalysis.dll" />
<PackageFiles Include="$(OutputPath)Microsoft.CodeAnalysis.CSharp.dll" />
<PackageFiles Include="$(OutputPath)System.Collections.Immutable.dll" />
<PackageFiles Include="$(OutputPath)Zbu.ModelsBuilder.dll" />
<PackageFiles Include="$(OutputPath)Zbu.ModelsBuilder.Umbraco.dll" />
<PackageFiles Include="$(OutputPath)Zbu.ModelsBuilder.AspNet.dll" />
<PackageFiles Include="$(OutputPath)System.Reflection.Metadata.dll" />
</ItemGroup>
<Package ManifestFile="$(ProjectDir)pkg\package.xml" WorkingDirectory="$(ProjectDir)pkg" OutputDirectory="$(ProjectDir)pkg" Files="@(PackageFiles)" />
<ItemGroup>
<PackageFilesToCopy Include="$(ProjectDir)pkg\*.zip" />
</ItemGroup>
<Copy SourceFiles="@(PackageFilesToCopy)" DestinationFolder="$(SolutionDir)build\$(Configuration)" />
<RemoveDir Directories="$(ProjectDir)pkg" />
</Target>
<!-- auto by NuGet: DependsOnTargets="BuildPackage" -->
<Target Name="NuGetPackage">
<GetAssemblyIdentity AssemblyFiles="$(OutputPath)Zbu.ModelsBuilder.dll">
<Output TaskParameter="Assemblies" ItemName="AssemblyInfos" />
</GetAssemblyIdentity>
<Message Importance="High" Text="Packaging version %(AssemblyInfos.Version) into NuGet package" />
<ItemGroup>
<NuGetFilesToDelete Include="$(ProjectDir)build\Packages\*.nupkg" />
</ItemGroup>
<Delete Files="@(NuGetFilesToDelete)" />
<PropertyGroup>
<!-- -symbols -->
<NuGetBuildCommand>$(NuGetCommand) pack "$(ProjectDir)build\NuSpecs\Zbu.ModelsBuilder.AspNet.nuspec" -Version "%(AssemblyInfos.Version)-pre" -Properties "Configuration=$(Configuration);Platform=$(Platform)" $(NonInteractiveSwitch) -OutputDirectory "$(ProjectDir)build\Packages"</NuGetBuildCommand>
</PropertyGroup>
<Exec Command="$(NuGetBuildCommand)" LogStandardErrorAsError="true" />
<ItemGroup>
<NuGetFilesToCopy Include="$(ProjectDir)build\Packages\*.nupkg" />
</ItemGroup>
<Package ManifestFile="$(ProjectDir)pkg\$(Configuration)\package.xml" WorkingDirectory="$(ProjectDir)pkg\$(Configuration)" OutputDirectory="$(ProjectDir)pkg\$(Configuration)" Files="@(PackageFiles)" />
<Delete Files="$(ProjectDir)pkg\$(Configuration)\package.xml" />
<Copy SourceFiles="@(NuGetFilesToCopy)" DestinationFolder="$(SolutionDir)build\$(Configuration)" />
</Target>
</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?xml version="1.0"?>
<package xmlns="http://schemas.microsoft.com/packaging/2011/08/nuspec.xsd">
<metadata>
<id>Zbu.ModelsBuilder.AspNet</id>
<!-- set -pre to indicate it's pre-release -->
<version>$version$-pre</version>
<title>ZpqrtBnk Umbraco ModelsBuilder ASP.NET Integration</title>
<authors>Pilotine - ZpqrtBnk</authors>
<owners>Pilotine - ZpqrtBnk</owners>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<description>ZpqrtBnk Umbraco ASP.NET tool for generating strongly typed IPublishedContent models.</description>
<copyright>Copyright © Pilotine - ZpqrtBnk 2013-2014</copyright>
<dependencies>
<dependency id="Microsoft.CodeAnalysis.CSharp" version="0.6.4033103-beta" />
</dependencies>
</metadata>
<files>
<!-- our dlls -->
<file src="..\..\bin\Release\Zbu.ModelsBuilder.dll" target="lib\Zbu.ModelsBuilder.dll" />
<file src="..\..\bin\Release\Zbu.ModelsBuilder.Umbraco.dll" target="lib\Zbu.ModelsBuilder.Umbraco.dll" />
<file src="..\..\bin\Release\Zbu.ModelsBuilder.AspNet.dll" target="lib\Zbu.ModelsBuilder.AspNet.dll" />

<!-- content for the dashboard -->
<file src="..\..\UserControls\Zbu\ModelsBuilder\BuildModels.ascx" target="content\UserControls\Zbu\ModelsBuilder\BuildModels.ascx" />
<file src="..\..\UserControls\Zbu\ModelsBuilder\logo32x32.png" target="content\UserControls\Zbu\ModelsBuilder\logo32x32.png" />

<!-- post-install script // we don't have one -->
<!--
<file src="tools\install.ps1" target="tools\install.ps1" />
-->
</files>
</package>
5 changes: 5 additions & 0 deletions Zbu.ModelsBuilder.AspNet/build/NuSpecs/tools/Install.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
param($rootPath, $toolsPath, $package, $project)

if ($project) {
# nothing...
}
28 changes: 22 additions & 6 deletions Zbu.ModelsBuilder.AspNet/package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,32 @@
<orgPath>/UserControls/Zbu/ModelsBuilder</orgPath>
<orgName>BuildModels.ascx</orgName>
</file>
<file>
<guid>Roslyn.Compilers.dll</guid>
<file>
<guid>logo32x32.png</guid>
<orgPath>/UserControls/Zbu/ModelsBuilder</orgPath>
<orgName>logo32x32.png</orgName>
</file>
<file>
<guid>Microsoft.CodeAnalysis.dll</guid>
<orgPath>/bin</orgPath>
<orgName>Roslyn.Compilers.dll</orgName>
<orgName>Microsoft.CodeAnalysis.dll</orgName>
</file>
<file>
<guid>Roslyn.Compilers.CSharp.dll</guid>
<guid>Microsoft.CodeAnalysis.CSharp.dll</guid>
<orgPath>/bin</orgPath>
<orgName>Roslyn.Compilers.CSharp.dll</orgName>
<orgName>Microsoft.CodeAnalysis.CSharp.dll</orgName>
</file>
<file>
<file>
<guid>System.Collections.Immutable.dll</guid>
<orgPath>/bin</orgPath>
<orgName>System.Collections.Immutable.dll</orgName>
</file>
<file>
<guid>System.Reflection.Metadata.dll</guid>
<orgPath>/bin</orgPath>
<orgName>System.Reflection.Metadata.dll</orgName>
</file>
<file>
<guid>Zbu.ModelsBuilder.dll</guid>
<orgPath>/bin</orgPath>
<orgName>Zbu.ModelsBuilder.dll</orgName>
Expand Down Expand Up @@ -80,5 +95,6 @@ But, time will come...]]></readme>
</tab>
</section>
</Action>
<Action runat="install" undo="true" alias="Zbu.ModelsBuilder.Umbraco.PackageActions.Configure" />
</Actions>
</umbPackage>
6 changes: 3 additions & 3 deletions Zbu.ModelsBuilder.CustomTool/CustomTool/ZbuModelsBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -188,10 +188,10 @@ public virtual int Generate(string wszInputFilePath,
VisualStudioHelper.AddGeneratedItem(vsitem, filename);
}

// FIXME - are we sure we want to do this?
// we need to generate something
var code = new StringBuilder();
new TextBuilder().WriteHeader(code);
code.Append("// ZpqrtBnk Umbraco ModelsBuilder");
new TextBuilder(new TypeModel[] { }).WriteHeader(code);
code.Append("// ZpqrtBnk Umbraco ModelsBuilder\n");
code.AppendFormat("// {0:yyyy-MM-ddTHH:mm:ssZ}", DateTime.UtcNow);

var data = Encoding.Default.GetBytes(code.ToString());
Expand Down
Loading

0 comments on commit 45a9c35

Please sign in to comment.