From e47fa9b921b3721a9817a15779edd728d1fdcb83 Mon Sep 17 00:00:00 2001 From: Tommy Parnell Date: Fri, 30 May 2014 01:34:55 -0400 Subject: [PATCH] init commit --- .gitignore | 186 ++++++++++++++++++ .nuget/packages.config | 4 + .../Attributes/BaseAttribute.cs | 64 ++++++ .../Attributes/CssBundleTest.cs | 15 ++ .../Attributes/JavaScriptBundleTest.cs | 16 ++ .../BundlerTestAssemblyLoading.cs | 17 ++ .../BundlerTests.cs | 132 +++++++++++++ .../Exception/NoBundleFactoryExceptionTest.cs | 30 +++ .../Properties/AssemblyInfo.cs | 36 ++++ .../packages.config | 5 + .../tparnell.ContentBundling.UnitTest.csproj | 73 +++++++ .../Attributes/CssBundleAttribute.cs | 14 ++ .../Attributes/DefaultBundleAttribute.cs | 29 +++ .../Attributes/IBundleAttribute.cs | 14 ++ .../Attributes/JavaScriptBundleAttribute.cs | 14 ++ src/tparnell.ContentBundling/Bundler.cs | 104 ++++++++++ src/tparnell.ContentBundling/BundlerAsync.cs | 31 +++ .../Enum/AsyncLoading.cs | 10 + .../Enum/ContentType.cs | 8 + .../Exceptions/NoBundleFactoryException.cs | 17 ++ .../IBundlesFactory.cs | 10 + .../Properties/AssemblyInfo.cs | 36 ++++ .../tparnell.ContentBundling.csproj | 65 ++++++ tparnell.ContentBundling.sln | 42 ++++ 24 files changed, 972 insertions(+) create mode 100644 .gitignore create mode 100644 .nuget/packages.config create mode 100644 src/tparnell.ContentBundling.UnitTest/Attributes/BaseAttribute.cs create mode 100644 src/tparnell.ContentBundling.UnitTest/Attributes/CssBundleTest.cs create mode 100644 src/tparnell.ContentBundling.UnitTest/Attributes/JavaScriptBundleTest.cs create mode 100644 src/tparnell.ContentBundling.UnitTest/BundlerTestAssemblyLoading.cs create mode 100644 src/tparnell.ContentBundling.UnitTest/BundlerTests.cs create mode 100644 src/tparnell.ContentBundling.UnitTest/Exception/NoBundleFactoryExceptionTest.cs create mode 100644 src/tparnell.ContentBundling.UnitTest/Properties/AssemblyInfo.cs create mode 100644 src/tparnell.ContentBundling.UnitTest/packages.config create mode 100644 src/tparnell.ContentBundling.UnitTest/tparnell.ContentBundling.UnitTest.csproj create mode 100644 src/tparnell.ContentBundling/Attributes/CssBundleAttribute.cs create mode 100644 src/tparnell.ContentBundling/Attributes/DefaultBundleAttribute.cs create mode 100644 src/tparnell.ContentBundling/Attributes/IBundleAttribute.cs create mode 100644 src/tparnell.ContentBundling/Attributes/JavaScriptBundleAttribute.cs create mode 100644 src/tparnell.ContentBundling/Bundler.cs create mode 100644 src/tparnell.ContentBundling/BundlerAsync.cs create mode 100644 src/tparnell.ContentBundling/Enum/AsyncLoading.cs create mode 100644 src/tparnell.ContentBundling/Enum/ContentType.cs create mode 100644 src/tparnell.ContentBundling/Exceptions/NoBundleFactoryException.cs create mode 100644 src/tparnell.ContentBundling/IBundlesFactory.cs create mode 100644 src/tparnell.ContentBundling/Properties/AssemblyInfo.cs create mode 100644 src/tparnell.ContentBundling/tparnell.ContentBundling.csproj create mode 100644 tparnell.ContentBundling.sln diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..e57ca9e --- /dev/null +++ b/.gitignore @@ -0,0 +1,186 @@ +## Ignore Visual Studio temporary files, build results, and +## files generated by popular Visual Studio add-ons. + +# User-specific files +*.suo +*.user +*.sln.docstates + +# Build results +[Dd]ebug/ +[Dd]ebugPublic/ +[Rr]elease/ +[Rr]eleases/ +x64/ +build/ +bld/ +[Bb]in/ +[Oo]bj/ + +# Roslyn cache directories +*.ide/ + +# MSTest test Results +[Tt]est[Rr]esult*/ +[Bb]uild[Ll]og.* + +#NUNIT +*.VisualState.xml +TestResult.xml + +# Build Results of an ATL Project +[Dd]ebugPS/ +[Rr]eleasePS/ +dlldata.c + +*_i.c +*_p.c +*_i.h +*.ilk +*.meta +*.obj +*.pch +*.pdb +*.pgc +*.pgd +*.rsp +*.sbr +*.tlb +*.tli +*.tlh +*.tmp +*.tmp_proj +*.log +*.vspscc +*.vssscc +.builds +*.pidb +*.svclog +*.scc + +# Chutzpah Test files +_Chutzpah* + +# Visual C++ cache files +ipch/ +*.aps +*.ncb +*.opensdf +*.sdf +*.cachefile + +# Visual Studio profiler +*.psess +*.vsp +*.vspx + +# TFS 2012 Local Workspace +$tf/ + +# Guidance Automation Toolkit +*.gpState + +# ReSharper is a .NET coding add-in +_ReSharper*/ +*.[Rr]e[Ss]harper +*.DotSettings.user + +# JustCode is a .NET coding addin-in +.JustCode + +# TeamCity is a build add-in +_TeamCity* + +# DotCover is a Code Coverage Tool +*.dotCover + +# NCrunch +_NCrunch_* +.*crunch*.local.xml + +# MightyMoose +*.mm.* +AutoTest.Net/ + +# Web workbench (sass) +.sass-cache/ + +# Installshield output folder +[Ee]xpress/ + +# DocProject is a documentation generator add-in +DocProject/buildhelp/ +DocProject/Help/*.HxT +DocProject/Help/*.HxC +DocProject/Help/*.hhc +DocProject/Help/*.hhk +DocProject/Help/*.hhp +DocProject/Help/Html2 +DocProject/Help/html + +# Click-Once directory +publish/ + +# Publish Web Output +*.[Pp]ublish.xml +*.azurePubxml +## TODO: Comment the next line if you want to checkin your +## web deploy settings but do note that will include unencrypted +## passwords +*.pubxml + +# NuGet Packages +packages/* +*.nupkg +## TODO: If the tool you use requires repositories.config +## uncomment the next line +#!packages/repositories.config + +# Enable "build/" folder in the NuGet Packages folder since +# NuGet packages use it for MSBuild targets. +# This line needs to be after the ignore of the build folder +# (and the packages folder if the line above has been uncommented) +!packages/build/ + +# Windows Azure Build Output +csx/ +*.build.csdef +*.DotSettings +# Windows Store app package directory +AppPackages/ + +# Others +sql/ +*.Cache +ClientBin/ +[Ss]tyle[Cc]op.* +~$* +*~ +*.dbmdl +*.dbproj.schemaview +*.pfx +*.publishsettings +node_modules/ + +# RIA/Silverlight projects +Generated_Code/ + +# Backup & report files from converting an old project file +# to a newer Visual Studio version. Backup files are not needed, +# because we have git ;-) +_UpgradeReport_Files/ +Backup*/ +UpgradeLog*.XML +UpgradeLog*.htm + +# SQL Server files +*.mdf +*.ldf + +# Business Intelligence projects +*.rdl.data +*.bim.layout +*.bim_*.settings + +# Microsoft Fakes +FakesAssemblies/ \ No newline at end of file diff --git a/.nuget/packages.config b/.nuget/packages.config new file mode 100644 index 0000000..7025a72 --- /dev/null +++ b/.nuget/packages.config @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/src/tparnell.ContentBundling.UnitTest/Attributes/BaseAttribute.cs b/src/tparnell.ContentBundling.UnitTest/Attributes/BaseAttribute.cs new file mode 100644 index 0000000..e7520af --- /dev/null +++ b/src/tparnell.ContentBundling.UnitTest/Attributes/BaseAttribute.cs @@ -0,0 +1,64 @@ +using System; +using System.Linq; +using NUnit.Framework; +using tparnell.ContentBundling.Attributes; +using tparnell.ContentBundling.Enum; + +namespace tparnell.ContentBundling.UnitTest.Attributes +{ + [TestFixture] + public class BaseAttribute + { + [Test] + [ExpectedException(typeof(ArgumentNullException))] + public static void ConfirmEmptyBundleName() + { + var ts = new DefaultBundleAttribute("", "tst", ContentType.JavaScript, AsyncLoading.Async, "dsds"); + } + [Test] + [ExpectedException(typeof(ArgumentNullException))] + public static void ConfirmNullBundleName() + { + var ts = new DefaultBundleAttribute(null, "tst", ContentType.JavaScript, AsyncLoading.Async, "dsds"); + } + [Test] + [ExpectedException(typeof(ArgumentNullException))] + public static void ConfirmEmptyOutputURI() + { + var ts = new DefaultBundleAttribute("tst", "", ContentType.JavaScript, AsyncLoading.Async, "dsds"); + } + [Test] + [ExpectedException(typeof(ArgumentNullException))] + public static void ConfirmNullOutputURI() + { + var ts = new DefaultBundleAttribute("tst", null, ContentType.JavaScript, AsyncLoading.Async, "dsds"); + } + [Test] + [ExpectedException(typeof(ArgumentNullException))] + public static void ConfirmEmptyFilePath() + { + var ts = new DefaultBundleAttribute("tst", "ds", ContentType.JavaScript, AsyncLoading.Async, new string[]{}); + } + [Test] + public static void ConfirmBundleNameApplied() + { + var td = "tst"; + var ts = new DefaultBundleAttribute(td, "ds", ContentType.JavaScript, AsyncLoading.Async, new string[] { "tst"}); + Assert.IsTrue(string.Equals(ts.BundleName,td)); + } + [Test] + public static void ConfirmBundleOutputURIApplied() + { + var td = "tst"; + var ts = new DefaultBundleAttribute("TST", td, ContentType.JavaScript, AsyncLoading.Async, new string[] { "tst" }); + Assert.IsTrue(string.Equals(ts.OutputUri, td)); + } + [Test] + public static void ConfirmBundleFileURIApplied() + { + var td = "tst"; + var ts = new DefaultBundleAttribute("TST", "TDS", ContentType.JavaScript, AsyncLoading.Async, new[] { td }); + Assert.IsTrue(string.Equals(ts.Fileuri.FirstOrDefault(), td)); + } + } +} diff --git a/src/tparnell.ContentBundling.UnitTest/Attributes/CssBundleTest.cs b/src/tparnell.ContentBundling.UnitTest/Attributes/CssBundleTest.cs new file mode 100644 index 0000000..da56187 --- /dev/null +++ b/src/tparnell.ContentBundling.UnitTest/Attributes/CssBundleTest.cs @@ -0,0 +1,15 @@ +using NUnit.Framework; +using tparnell.ContentBundling.Attributes; + +namespace tparnell.ContentBundling.UnitTest.Attributes +{ + [TestFixture] + public class CssBundleTest + { + [Test] + public void CreateCssBundle() + { + var td = new CssBundleAttribute("test bundle", "~/d", "/"); + } + } +} diff --git a/src/tparnell.ContentBundling.UnitTest/Attributes/JavaScriptBundleTest.cs b/src/tparnell.ContentBundling.UnitTest/Attributes/JavaScriptBundleTest.cs new file mode 100644 index 0000000..2e8f6c3 --- /dev/null +++ b/src/tparnell.ContentBundling.UnitTest/Attributes/JavaScriptBundleTest.cs @@ -0,0 +1,16 @@ +using NUnit.Framework; +using tparnell.ContentBundling.Attributes; +using tparnell.ContentBundling.Enum; + +namespace tparnell.ContentBundling.UnitTest.Attributes +{ + [TestFixture] + public class JavaScriptBundleTest + { + [Test] + public void CreateJavaScriptBundleAttribute() + { + var td = new JavaScriptBundleAttribute("test bundle", "~/d",AsyncLoading.Async, "/"); + } + } +} diff --git a/src/tparnell.ContentBundling.UnitTest/BundlerTestAssemblyLoading.cs b/src/tparnell.ContentBundling.UnitTest/BundlerTestAssemblyLoading.cs new file mode 100644 index 0000000..ca846ab --- /dev/null +++ b/src/tparnell.ContentBundling.UnitTest/BundlerTestAssemblyLoading.cs @@ -0,0 +1,17 @@ +using System; +using NUnit.Framework; + +namespace tparnell.ContentBundling.UnitTest +{ + [TestFixture] + public class BundlerTestAssemblyLoading + { + [Test] + [ExpectedException(typeof(TypeAccessException))] + public void LoadFromAssembly() + { + new Bundler(false).ForceFactoryReloadFromAssembly(); + + } + } +} diff --git a/src/tparnell.ContentBundling.UnitTest/BundlerTests.cs b/src/tparnell.ContentBundling.UnitTest/BundlerTests.cs new file mode 100644 index 0000000..691c1de --- /dev/null +++ b/src/tparnell.ContentBundling.UnitTest/BundlerTests.cs @@ -0,0 +1,132 @@ +using System; +using System.Threading.Tasks; +using Moq; +using NUnit.Framework; +using tparnell.ContentBundling.Attributes; +using tparnell.ContentBundling.Enum; +using tparnell.ContentBundling.Exceptions; + +namespace tparnell.ContentBundling.UnitTest +{ + [TestFixture] + [JavaScriptBundle("awesome", "/", AsyncLoading.Async,"/")] + public class BundlerTests + { + [TearDown] + public void Teardown() + { + Bundler.BundleFactory = null; + + } + [Test] + [ExpectedException(typeof(NoBundleFactoryException))] + public void ConfirmThrownException() + { + + var td = new Bundler(false); + + try + { + var ts = Task.Run(() => td.Bundle()); + ts.Wait(); + } + catch (AggregateException e) + { + + throw e.InnerException; + } + + + } + [Test] + public void ConfirmBundleCollectionCreation() + { + + var td = new Bundler(false); + Assert.IsNotNull(Bundler.BundlesCreated); + } + + [Test] + public void MakeSureBundlesCreatedIsNotNull() + { + + if(Bundler.BundlesCreated == null) Assert.Fail(); + } + [Test] + public void SetPath() + { + var path = "awesomepath"; + var td = new Bundler(false).SetPath(path); + Assert.IsTrue(string.Equals(path, Bundler.RootPath)); + + } + [Test] + [ExpectedException(typeof(ArgumentNullException))] + public void PassNullFactory() + { + + var td = new Bundler(null,true); + + } + [Test] + public void ConfirmOverriddenFactory() + { + var refer = new Mock().Object; + var td = new Bundler(new Mock().Object, false); + var ts = new Bundler(refer, true); + Assert.IsTrue(refer == Bundler.BundleFactory); + + } + [Test] + public void ConfirmOverriddenFactoryFailed() + { + var refer = new Mock().Object; + var td = new Bundler(new Mock().Object, false); + var ts = new Bundler(refer, false); + Assert.IsFalse(refer == Bundler.BundleFactory); + + } + [Test] + public void ConfirmFactoryIsNotOverridentFromAssembly() + { + var refer = new Mock().Object; + var ts = new Bundler(refer, true); + var td = new Bundler(true); + Assert.IsTrue(refer == Bundler.BundleFactory); + + } + + [Test] + public void BundleIt() + { + var refer = new Mock(); + refer.Setup(x => x.BundleContent(It.IsAny(), It.IsAny())); + var ts = new Bundler(refer.Object); + var tsk = Task.Run(()=>ts.BundleAsync()); + tsk.Wait(); + refer.Verify(); + + } + + + [Test] + public void ForceDebug() + { + new Bundler(new Mock().Object, true); + var ts = Task.Run(async () => { await new Bundler().ForceDebugAsync(); }); + ts.Wait(); + Assert.IsTrue(Bundler.IsForceDebug); + var bs = Task.Run(async () => { await new Bundler().ClearForceDebugAsync(); }); + bs.Wait(); + + } + [Test] + public void ClearDebug() + { + new Bundler(new Mock().Object, true); + var td = Task.Run(async () => { await new Bundler().ClearForceDebugAsync(); }); + td.Wait(); + Assert.IsTrue(!Bundler.IsForceDebug ); + } + } +} diff --git a/src/tparnell.ContentBundling.UnitTest/Exception/NoBundleFactoryExceptionTest.cs b/src/tparnell.ContentBundling.UnitTest/Exception/NoBundleFactoryExceptionTest.cs new file mode 100644 index 0000000..cbe1fdb --- /dev/null +++ b/src/tparnell.ContentBundling.UnitTest/Exception/NoBundleFactoryExceptionTest.cs @@ -0,0 +1,30 @@ +using NUnit.Framework; +using tparnell.ContentBundling.Exceptions; + +namespace tparnell.ContentBundling.UnitTest.Exception +{ + [TestFixture] + public class NoBundleFactoryExceptionTest + { + [Test] + [ExpectedException(typeof(NoBundleFactoryException))] + public void CallException() + { + throw new NoBundleFactoryException(); + } + + [Test] + [ExpectedException(typeof(NoBundleFactoryException))] + public void CallExceptionWithMessage() + { + throw new NoBundleFactoryException("Test Message"); + } + + [Test] + [ExpectedException(typeof(NoBundleFactoryException))] + public void CallExceptionWithMessageAndInnerException() + { + throw new NoBundleFactoryException("Test Message", new NoBundleFactoryException()); + } + } +} diff --git a/src/tparnell.ContentBundling.UnitTest/Properties/AssemblyInfo.cs b/src/tparnell.ContentBundling.UnitTest/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..7a67fb5 --- /dev/null +++ b/src/tparnell.ContentBundling.UnitTest/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("tparnell.ContentBundling.UnitTest")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("tparnell.ContentBundling.UnitTest")] +[assembly: AssemblyCopyright("Copyright © 2014")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("e2d3d7ff-0779-451e-af0a-6c5f681dd8f7")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/src/tparnell.ContentBundling.UnitTest/packages.config b/src/tparnell.ContentBundling.UnitTest/packages.config new file mode 100644 index 0000000..5cd66f2 --- /dev/null +++ b/src/tparnell.ContentBundling.UnitTest/packages.config @@ -0,0 +1,5 @@ + + + + + \ No newline at end of file diff --git a/src/tparnell.ContentBundling.UnitTest/tparnell.ContentBundling.UnitTest.csproj b/src/tparnell.ContentBundling.UnitTest/tparnell.ContentBundling.UnitTest.csproj new file mode 100644 index 0000000..8e9958b --- /dev/null +++ b/src/tparnell.ContentBundling.UnitTest/tparnell.ContentBundling.UnitTest.csproj @@ -0,0 +1,73 @@ + + + + + Debug + AnyCPU + {85532C8E-1BFD-40B8-8E3A-1F7D46D24ED8} + Library + Properties + tparnell.ContentBundling.UnitTest + tparnell.ContentBundling.UnitTest + v4.5 + 512 + + + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + ..\..\packages\Moq.4.2.1402.2112\lib\net40\Moq.dll + + + ..\..\packages\NUnit.2.6.3\lib\nunit.framework.dll + + + + + + + + + + + + + + + + + + + + + + + + {eca4d0fd-3f56-4b8b-b9de-e671e38e351c} + tparnell.ContentBundling + + + + + \ No newline at end of file diff --git a/src/tparnell.ContentBundling/Attributes/CssBundleAttribute.cs b/src/tparnell.ContentBundling/Attributes/CssBundleAttribute.cs new file mode 100644 index 0000000..f3c3832 --- /dev/null +++ b/src/tparnell.ContentBundling/Attributes/CssBundleAttribute.cs @@ -0,0 +1,14 @@ +using System; +using tparnell.ContentBundling.Enum; + +namespace tparnell.ContentBundling.Attributes +{ + [AttributeUsage(AttributeTargets.Class, AllowMultiple = true)] + public sealed class CssBundleAttribute : DefaultBundleAttribute + { + public CssBundleAttribute(string bundleName, string outputUri, params string[] fileuri) + : base(bundleName, outputUri, ContentType.Css, AsyncLoading.Default, fileuri) + { + } + } +} \ No newline at end of file diff --git a/src/tparnell.ContentBundling/Attributes/DefaultBundleAttribute.cs b/src/tparnell.ContentBundling/Attributes/DefaultBundleAttribute.cs new file mode 100644 index 0000000..91d2884 --- /dev/null +++ b/src/tparnell.ContentBundling/Attributes/DefaultBundleAttribute.cs @@ -0,0 +1,29 @@ +using System; +using System.Collections.Generic; +using tparnell.ContentBundling.Enum; + +namespace tparnell.ContentBundling.Attributes +{ + [AttributeUsage(AttributeTargets.Class, AllowMultiple = true)] + public class DefaultBundleAttribute: Attribute, IBundleAttribute + { + public string BundleName { get; private set; } + public string OutputUri { get; private set; } + public ContentType Contenttype { get; private set; } + public IEnumerable Fileuri { get; private set; } + public AsyncLoading Async { get; private set; } + + public DefaultBundleAttribute(string bundleName, string outputUri, ContentType contenttype, AsyncLoading async, params string[] fileuri) + { + if(String.IsNullOrWhiteSpace(bundleName)) throw new ArgumentNullException("bundleName"); + if (String.IsNullOrWhiteSpace(outputUri)) throw new ArgumentNullException("outputUri"); + if (fileuri.Length < 1) throw new ArgumentNullException("fileuri"); + BundleName = bundleName; + OutputUri = outputUri; + Contenttype = contenttype; + Fileuri = fileuri; + Async = async; + } + } + +} \ No newline at end of file diff --git a/src/tparnell.ContentBundling/Attributes/IBundleAttribute.cs b/src/tparnell.ContentBundling/Attributes/IBundleAttribute.cs new file mode 100644 index 0000000..a685d30 --- /dev/null +++ b/src/tparnell.ContentBundling/Attributes/IBundleAttribute.cs @@ -0,0 +1,14 @@ +using System.Collections.Generic; +using tparnell.ContentBundling.Enum; + +namespace tparnell.ContentBundling.Attributes +{ + public interface IBundleAttribute + { + string BundleName { get; } + string OutputUri { get; } + ContentType Contenttype { get; } + IEnumerable Fileuri { get; } + AsyncLoading Async { get; } + } +} \ No newline at end of file diff --git a/src/tparnell.ContentBundling/Attributes/JavaScriptBundleAttribute.cs b/src/tparnell.ContentBundling/Attributes/JavaScriptBundleAttribute.cs new file mode 100644 index 0000000..3402cbb --- /dev/null +++ b/src/tparnell.ContentBundling/Attributes/JavaScriptBundleAttribute.cs @@ -0,0 +1,14 @@ +using System; +using tparnell.ContentBundling.Enum; + +namespace tparnell.ContentBundling.Attributes +{ + [AttributeUsage(AttributeTargets.Class, AllowMultiple = true)] + public sealed class JavaScriptBundleAttribute : DefaultBundleAttribute + { + public JavaScriptBundleAttribute(string bundleName, string outputUri, AsyncLoading async , params string[] fileuri) + : base(bundleName, outputUri, ContentType.JavaScript, async, fileuri) + { + } + } +} \ No newline at end of file diff --git a/src/tparnell.ContentBundling/Bundler.cs b/src/tparnell.ContentBundling/Bundler.cs new file mode 100644 index 0000000..1a03298 --- /dev/null +++ b/src/tparnell.ContentBundling/Bundler.cs @@ -0,0 +1,104 @@ +using System; +using System.Collections.Concurrent; +using System.Linq; +using tparnell.ContentBundling.Attributes; +using tparnell.ContentBundling.Exceptions; + +namespace tparnell.ContentBundling +{ + public partial class Bundler + { + public static bool IsForceDebug { get; private set; } + public static ConcurrentBag BundlesCreated { get; private set; } + public static string RootPath { get; set; } + public static IBundlesFactory BundleFactory { get; set; } + //empty constructor so we allways have a constructor that is paramterless + public Bundler(bool loadFactoryFromAssembly = true, bool overrideExisting = false) + { + if (BundleFactory != null && !overrideExisting) return; + if (loadFactoryFromAssembly) ForceFactoryReloadFromAssembly(); + } + public Bundler(IBundlesFactory factory, bool replaceExisting = true) + { + if(factory == null) throw new ArgumentNullException("factory"); + if (BundleFactory != null && !replaceExisting) return; + BundleFactory = factory; + } + + + static Bundler() + { + if (BundlesCreated == null) BundlesCreated = new ConcurrentBag(); + + } + + public void ForceFactoryReloadFromAssembly() + { + var assems = AppDomain.CurrentDomain.GetAssemblies(); + var types = assems.SelectMany(s => s.GetTypes()).FirstOrDefault(p => typeof(IBundlesFactory).IsAssignableFrom(p) && p.IsClass && !p.IsInterface); + if (types == null) throw new TypeAccessException(); + //lame excuse for dependancy injection, but for now it works + BundleFactory = (IBundlesFactory)Activator.CreateInstance(types); + + } + + public Bundler Bundle() + { + if (BundleFactory == null) throw new NoBundleFactoryException(); + var assems = AppDomain.CurrentDomain.GetAssemblies().Where(w => w.GetReferencedAssemblies().Any(r => r.Name.StartsWith("tparnell.ContentBundling", StringComparison.OrdinalIgnoreCase))); + //boy do I hate myself for doing this....Basically scan through loaded assemblies looking for bundles that should be built on app startup + assems.AsParallel().ForAll(x => x.GetTypes().ToList().Where(ds => (ds.GetCustomAttributes(typeof(IBundleAttribute), true)).Any()).AsParallel().ForAll( + dx => + { + Environment.CurrentDirectory = string.IsNullOrEmpty(RootPath) ? Environment.CurrentDirectory : RootPath; + var bundles = dx.GetCustomAttributes(typeof(IBundleAttribute), true).Select(a => (IBundleAttribute)a); + foreach (var bund in bundles) + { + var bundlename = bund != null ? bund.BundleName : "Unknown Bundle"; + BundlesCreated.Add(bundlename); + BundleFactory.BundleContent(bund, IsForceDebug); + } + })); + return this; + } + + #region RepositoryThings + + public Bundler SetPath(string path) + { + RootPath = path; + return this; + } + + /// + /// Force Debug + /// + /// Self + public Bundler ForceDebug() + { + IsForceDebug = true; + PurgeBundles(); + return Bundle(); + } + /// + /// Clear force debug + /// + /// self + public Bundler ClearForceDebug() + { + IsForceDebug = false; + PurgeBundles(); + return Bundle(); + } + + public Bundler PurgeBundles() + { + BundlesCreated = new ConcurrentBag(); + BundleFactory.RebuildCache(); + return this; + } + #endregion + + + } +} \ No newline at end of file diff --git a/src/tparnell.ContentBundling/BundlerAsync.cs b/src/tparnell.ContentBundling/BundlerAsync.cs new file mode 100644 index 0000000..78a4d5c --- /dev/null +++ b/src/tparnell.ContentBundling/BundlerAsync.cs @@ -0,0 +1,31 @@ +using System.Threading.Tasks; + +namespace tparnell.ContentBundling +{ + public partial class Bundler + { + + public async Task BundleAsync() + { + return await Task.Run(() => Bundle()); + } + + /// + /// Force Debug + /// + /// Self + public async Task ForceDebugAsync() + { + return await Task.Run(() => ForceDebug()); + } + /// + /// Clear force debug + /// + /// self + public async Task ClearForceDebugAsync() + { + return await Task.Run(() => ClearForceDebug()); + } + + } +} \ No newline at end of file diff --git a/src/tparnell.ContentBundling/Enum/AsyncLoading.cs b/src/tparnell.ContentBundling/Enum/AsyncLoading.cs new file mode 100644 index 0000000..b169089 --- /dev/null +++ b/src/tparnell.ContentBundling/Enum/AsyncLoading.cs @@ -0,0 +1,10 @@ +namespace tparnell.ContentBundling.Enum +{ + public enum AsyncLoading + { + None, + Defer, + Async, + Default + } +} diff --git a/src/tparnell.ContentBundling/Enum/ContentType.cs b/src/tparnell.ContentBundling/Enum/ContentType.cs new file mode 100644 index 0000000..907b0ce --- /dev/null +++ b/src/tparnell.ContentBundling/Enum/ContentType.cs @@ -0,0 +1,8 @@ +namespace tparnell.ContentBundling.Enum +{ + public enum ContentType + { + JavaScript, + Css + } +} \ No newline at end of file diff --git a/src/tparnell.ContentBundling/Exceptions/NoBundleFactoryException.cs b/src/tparnell.ContentBundling/Exceptions/NoBundleFactoryException.cs new file mode 100644 index 0000000..1828fd2 --- /dev/null +++ b/src/tparnell.ContentBundling/Exceptions/NoBundleFactoryException.cs @@ -0,0 +1,17 @@ +using System; + +namespace tparnell.ContentBundling.Exceptions +{ + [Serializable] + public sealed class NoBundleFactoryException : Exception + { + public NoBundleFactoryException() + :base("No Bundle Factory Loaded"){} + + + public NoBundleFactoryException(string message):base(message){} + + public NoBundleFactoryException(string message, Exception innerException) + :base(message,innerException){} + } +} diff --git a/src/tparnell.ContentBundling/IBundlesFactory.cs b/src/tparnell.ContentBundling/IBundlesFactory.cs new file mode 100644 index 0000000..84707fb --- /dev/null +++ b/src/tparnell.ContentBundling/IBundlesFactory.cs @@ -0,0 +1,10 @@ +using tparnell.ContentBundling.Attributes; + +namespace tparnell.ContentBundling +{ + public interface IBundlesFactory + { + void BundleContent(IBundleAttribute bundle, bool debug = false); + void RebuildCache(); + } +} diff --git a/src/tparnell.ContentBundling/Properties/AssemblyInfo.cs b/src/tparnell.ContentBundling/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..f7f9f23 --- /dev/null +++ b/src/tparnell.ContentBundling/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("tparnell.ContentBundling")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("tparnell.ContentBundling")] +[assembly: AssemblyCopyright("Copyright © 2014")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("d3a41748-a805-4e56-b65c-d63452456abc")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/src/tparnell.ContentBundling/tparnell.ContentBundling.csproj b/src/tparnell.ContentBundling/tparnell.ContentBundling.csproj new file mode 100644 index 0000000..b2fab44 --- /dev/null +++ b/src/tparnell.ContentBundling/tparnell.ContentBundling.csproj @@ -0,0 +1,65 @@ + + + + + Debug + AnyCPU + {ECA4D0FD-3F56-4B8B-B9DE-E671E38E351C} + Library + Properties + tparnell.ContentBundling + tparnell.ContentBundling + v4.5 + 512 + + + + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + false + + + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + false + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/tparnell.ContentBundling.sln b/tparnell.ContentBundling.sln new file mode 100644 index 0000000..2e39af7 --- /dev/null +++ b/tparnell.ContentBundling.sln @@ -0,0 +1,42 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 2012 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "tparnell.ContentBundling", "src\tparnell.ContentBundling\tparnell.ContentBundling.csproj", "{ECA4D0FD-3F56-4B8B-B9DE-E671E38E351C}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "tparnell.ContentBundling.UnitTest", "src\tparnell.ContentBundling.UnitTest\tparnell.ContentBundling.UnitTest.csproj", "{85532C8E-1BFD-40B8-8E3A-1F7D46D24ED8}" +EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = ".nuget", ".nuget", "{950EC3D1-E8C6-4B2A-9377-290824082C76}" + ProjectSection(SolutionItems) = preProject + .nuget\packages.config = .nuget\packages.config + EndProjectSection +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + NET4.0|Any CPU = NET4.0|Any CPU + NET4.5|Any CPU = NET4.5|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {ECA4D0FD-3F56-4B8B-B9DE-E671E38E351C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {ECA4D0FD-3F56-4B8B-B9DE-E671E38E351C}.Debug|Any CPU.Build.0 = Debug|Any CPU + {ECA4D0FD-3F56-4B8B-B9DE-E671E38E351C}.Debug|Any CPU.Deploy.0 = Debug|Any CPU + {ECA4D0FD-3F56-4B8B-B9DE-E671E38E351C}.NET4.0|Any CPU.ActiveCfg = Release|Any CPU + {ECA4D0FD-3F56-4B8B-B9DE-E671E38E351C}.NET4.0|Any CPU.Build.0 = Release|Any CPU + {ECA4D0FD-3F56-4B8B-B9DE-E671E38E351C}.NET4.5|Any CPU.ActiveCfg = Release|Any CPU + {ECA4D0FD-3F56-4B8B-B9DE-E671E38E351C}.NET4.5|Any CPU.Build.0 = Release|Any CPU + {ECA4D0FD-3F56-4B8B-B9DE-E671E38E351C}.Release|Any CPU.ActiveCfg = Release|Any CPU + {ECA4D0FD-3F56-4B8B-B9DE-E671E38E351C}.Release|Any CPU.Build.0 = Release|Any CPU + {85532C8E-1BFD-40B8-8E3A-1F7D46D24ED8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {85532C8E-1BFD-40B8-8E3A-1F7D46D24ED8}.Debug|Any CPU.Build.0 = Debug|Any CPU + {85532C8E-1BFD-40B8-8E3A-1F7D46D24ED8}.NET4.0|Any CPU.ActiveCfg = Release|Any CPU + {85532C8E-1BFD-40B8-8E3A-1F7D46D24ED8}.NET4.0|Any CPU.Build.0 = Release|Any CPU + {85532C8E-1BFD-40B8-8E3A-1F7D46D24ED8}.NET4.5|Any CPU.ActiveCfg = Release|Any CPU + {85532C8E-1BFD-40B8-8E3A-1F7D46D24ED8}.NET4.5|Any CPU.Build.0 = Release|Any CPU + {85532C8E-1BFD-40B8-8E3A-1F7D46D24ED8}.Release|Any CPU.ActiveCfg = Release|Any CPU + {85532C8E-1BFD-40B8-8E3A-1F7D46D24ED8}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal