initial source commit
This commit is contained in:
@@ -0,0 +1,17 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<configuration>
|
||||
<configSections>
|
||||
<!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
|
||||
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
|
||||
</configSections>
|
||||
<entityFramework>
|
||||
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework">
|
||||
<parameters>
|
||||
<parameter value="Data Source=.\SQLEXPRESS; Integrated Security=True; MultipleActiveResultSets=True" />
|
||||
</parameters>
|
||||
</defaultConnectionFactory>
|
||||
</entityFramework>
|
||||
<startup>
|
||||
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
|
||||
</startup>
|
||||
</configuration>
|
||||
@@ -0,0 +1,36 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Web.Mvc;
|
||||
using Disco.Services.Plugins;
|
||||
|
||||
namespace Disco.Web.Extensions
|
||||
{
|
||||
public static class DiscoPluginDefinitionExtensions
|
||||
{
|
||||
public static List<SelectListItem> ToSelectListItems(this IEnumerable<PluginFeatureManifest> PluginFeatureDefinitions, PluginFeatureManifest SelectedItem)
|
||||
{
|
||||
string selectedId = default(string);
|
||||
|
||||
if (SelectedItem != null)
|
||||
selectedId = SelectedItem.Id;
|
||||
|
||||
return PluginFeatureDefinitions.ToSelectListItems(selectedId);
|
||||
}
|
||||
|
||||
public static List<SelectListItem> ToSelectListItems(this IEnumerable<PluginFeatureManifest> PluginDefinitions, string SelectedId = null, bool IncludeInstructionFirst = false, string InstructionMessage = "Select a Plugin")
|
||||
{
|
||||
var selectItems = default(List<SelectListItem>);
|
||||
if (SelectedId == null)
|
||||
selectItems = PluginDefinitions.Select(wpd => new SelectListItem { Value = wpd.Id, Text = wpd.Name }).ToList();
|
||||
else
|
||||
selectItems = PluginDefinitions.Select(wpd => new SelectListItem { Value = wpd.Id, Text = wpd.Name, Selected = (SelectedId.Equals(wpd.Id)) }).ToList();
|
||||
|
||||
if (IncludeInstructionFirst)
|
||||
selectItems.Insert(0, new SelectListItem() { Value = String.Empty, Text = String.Format("<{0}>", InstructionMessage), Selected = String.IsNullOrEmpty(SelectedId) });
|
||||
|
||||
return selectItems;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Web.Mvc;
|
||||
using Disco.Models.BI.Config;
|
||||
|
||||
namespace Disco.Web.Extensions
|
||||
{
|
||||
public static class OrganisationAddressExtensions
|
||||
{
|
||||
public static List<SelectListItem> ToSelectListItems(this IEnumerable<OrganisationAddress> organisationAddressess, OrganisationAddress SelectedItem)
|
||||
{
|
||||
int? selectedId = default(int?);
|
||||
|
||||
if (SelectedItem != null)
|
||||
selectedId = SelectedItem.Id;
|
||||
|
||||
return organisationAddressess.ToSelectListItems(selectedId);
|
||||
}
|
||||
|
||||
public static List<SelectListItem> ToSelectListItems(this IEnumerable<OrganisationAddress> organisationAddressess, int? SelectedId = null, bool IncludeInstructionFirst = false, string InstructionMessage = "Select an Address")
|
||||
{
|
||||
var selectItems = default(List<SelectListItem>);
|
||||
if (!SelectedId.HasValue)
|
||||
selectItems = organisationAddressess.Select(wpd => new SelectListItem { Value = wpd.Id.Value.ToString(), Text = string.Format("{0} ({1})", wpd.Name, wpd.ShortName) }).ToList();
|
||||
else
|
||||
selectItems = organisationAddressess.Select(wpd => new SelectListItem { Value = wpd.Id.Value.ToString(), Text = string.Format("{0} ({1})", wpd.Name, wpd.ShortName), Selected = (SelectedId.Equals(wpd.Id)) }).ToList();
|
||||
|
||||
if (IncludeInstructionFirst)
|
||||
selectItems.Insert(0, new SelectListItem() { Value = String.Empty, Text = String.Format("<{0}>", InstructionMessage), Selected = !SelectedId.HasValue });
|
||||
|
||||
return selectItems;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace Disco.Web.Extensions
|
||||
{
|
||||
public static class UtilityExtensions
|
||||
{
|
||||
public static string ToJavascriptDate(this DateTime d)
|
||||
{
|
||||
return string.Format("new Date({0}, {1}, {2}, {3}, {4}, {5})", d.Year, d.Month - 1, d.Day, d.Hour, d.Minute, d.Second);
|
||||
}
|
||||
public static string ToJavascriptDate(this DateTime? d, DateTime? DefaultDate = null)
|
||||
{
|
||||
if (d.HasValue)
|
||||
{
|
||||
return ToJavascriptDate(d.Value);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (DefaultDate.HasValue)
|
||||
return ToJavascriptDate(DefaultDate.Value);
|
||||
else
|
||||
return "null";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Web.Mvc;
|
||||
using Disco.Models.Repository;
|
||||
|
||||
namespace Disco.Web.Extensions
|
||||
{
|
||||
public static class DeviceBatchExtensions
|
||||
{
|
||||
|
||||
public static List<SelectListItem> ToSelectListItems(this IEnumerable<DeviceBatch> deviceBatches, int? SelectedId = null, bool IncludeNoBatchItem = true)
|
||||
{
|
||||
var items = deviceBatches.Select(db => new SelectListItem() { Value = db.Id.ToString(), Text = db.Name }).ToList();
|
||||
|
||||
if (SelectedId.HasValue)
|
||||
{
|
||||
string selectedIdString = SelectedId.Value.ToString();
|
||||
var selectedItem = items.Where(i => i.Value == selectedIdString).FirstOrDefault();
|
||||
if (selectedItem != null)
|
||||
selectedItem.Selected = true;
|
||||
}
|
||||
|
||||
if (IncludeNoBatchItem)
|
||||
items.Insert(0, new SelectListItem() { Value = string.Empty, Text = "Unknown", Selected = !SelectedId.HasValue });
|
||||
|
||||
return items;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Web.Mvc;
|
||||
using Disco.Models.Repository;
|
||||
|
||||
namespace Disco.Web.Extensions
|
||||
{
|
||||
public static class DeviceModelExtensions
|
||||
{
|
||||
|
||||
public static List<SelectListItem> ToSelectListItems(this IEnumerable<DeviceModel> deviceModels, int? SelectedId = null, bool IncludeNoModelItem = false)
|
||||
{
|
||||
var items = deviceModels.Select(db => new SelectListItem() { Value = db.Id.ToString(), Text = db.Description }).ToList();
|
||||
|
||||
if (SelectedId.HasValue)
|
||||
{
|
||||
string selectedIdString = SelectedId.Value.ToString();
|
||||
var selectedItem = items.Where(i => i.Value == selectedIdString).FirstOrDefault();
|
||||
if (selectedItem != null)
|
||||
selectedItem.Selected = true;
|
||||
}
|
||||
|
||||
if (IncludeNoModelItem)
|
||||
items.Insert(0, new SelectListItem() { Value = string.Empty, Text = "Unknown", Selected = !SelectedId.HasValue });
|
||||
|
||||
return items;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Web.Mvc;
|
||||
using Disco.Models.Repository;
|
||||
|
||||
namespace Disco.Web.Extensions
|
||||
{
|
||||
public static class DeviceProfileExtensions
|
||||
{
|
||||
public static IEnumerable<SelectListItem> ToSelectListItems(this IEnumerable<DeviceProfile> deviceProfiles, DeviceProfile SelectedDeviceProfile = null)
|
||||
{
|
||||
var selectedId = 1;
|
||||
|
||||
if (SelectedDeviceProfile != null)
|
||||
selectedId = SelectedDeviceProfile.Id;
|
||||
|
||||
return deviceProfiles.ToSelectListItems(selectedId);
|
||||
}
|
||||
public static IEnumerable<SelectListItem> ToSelectListItems(this IEnumerable<DeviceProfile> deviceProfiles, int SelectedDeviceProfileId = 1)
|
||||
{
|
||||
return deviceProfiles.Select(dp => new SelectListItem()
|
||||
{
|
||||
Value = dp.Id.ToString(),
|
||||
Text = dp.ToString(),
|
||||
Selected = (dp.Id == SelectedDeviceProfileId)
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Web.Mvc;
|
||||
using Disco.Models.Repository;
|
||||
|
||||
namespace Disco.Web.Extensions
|
||||
{
|
||||
public static class DocumentTemplateExtensions
|
||||
{
|
||||
public static IEnumerable<SelectListItem> ToSelectListItems(this IEnumerable<DocumentTemplate> documentTemplates, string SelectedId = null)
|
||||
{
|
||||
if (SelectedId == null)
|
||||
return documentTemplates.Select(dt => new SelectListItem { Value = dt.Id, Text = dt.Description }).ToList();
|
||||
else
|
||||
return documentTemplates.Select(dt => new SelectListItem { Value = dt.Id, Text = dt.Description, Selected = (SelectedId == dt.Id) }).ToList();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Web.Mvc;
|
||||
using Disco.Models.Repository;
|
||||
|
||||
namespace Disco.Web.Extensions
|
||||
{
|
||||
public static class JobSubTypeExtensions
|
||||
{
|
||||
public static List<SelectListItem> ToSelectListItems(this IEnumerable<JobSubType> jobSubTypes, List<JobSubType> SelectedItems)
|
||||
{
|
||||
List<string> selectedIds = default(List<string>);
|
||||
|
||||
if (SelectedItems != null)
|
||||
selectedIds = SelectedItems.Select(i => string.Format("{0}_{1}", i.JobTypeId, i.Id)).ToList();
|
||||
|
||||
return jobSubTypes.ToSelectListItems(selectedIds);
|
||||
}
|
||||
|
||||
public static List<SelectListItem> ToSelectListItems(this IEnumerable<JobSubType> jobSubTypes, List<string> SelectedIds = null)
|
||||
{
|
||||
if (SelectedIds == null)
|
||||
return jobSubTypes.Select(jst => new SelectListItem { Value = string.Format("{0}_{1}", jst.JobTypeId, jst.Id), Text = jst.Description }).ToList();
|
||||
else
|
||||
return jobSubTypes.Select(jst => new SelectListItem { Value = string.Format("{0}_{1}", jst.JobTypeId, jst.Id), Text = jst.Description, Selected = (SelectedIds.Contains(string.Format("{0}_{1}", jst.JobTypeId, jst.Id))) }).ToList();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using Disco.Models.Repository;
|
||||
using System.Web.Mvc;
|
||||
|
||||
namespace Disco.Web.Extensions
|
||||
{
|
||||
public static class JobTypeExtensions
|
||||
{
|
||||
public static List<SelectListItem> ToSelectListItems(this IEnumerable<JobType> jobTypes, JobType SelectedItem)
|
||||
{
|
||||
string selectedId = default(string);
|
||||
|
||||
if (SelectedItem != null)
|
||||
selectedId = SelectedItem.Id;
|
||||
|
||||
return jobTypes.ToSelectListItems(selectedId);
|
||||
}
|
||||
|
||||
public static List<SelectListItem> ToSelectListItems(this IEnumerable<JobType> jobTypes, string SelectedId = null)
|
||||
{
|
||||
if (SelectedId == null)
|
||||
return jobTypes.Select(jt => new SelectListItem { Value = jt.Id, Text = jt.Description }).ToList();
|
||||
else
|
||||
return jobTypes.Select(jt => new SelectListItem { Value = jt.Id, Text = jt.Description, Selected = (SelectedId == jt.Id) }).ToList();
|
||||
}
|
||||
|
||||
public static List<SelectListItem> ToSelectListItems(this IEnumerable<JobType> jobTypes, List<JobType> SelectedItems)
|
||||
{
|
||||
List<string> selectedIds = default(List<string>);
|
||||
|
||||
if (SelectedItems != null)
|
||||
selectedIds = SelectedItems.Select(i => i.Id).ToList();
|
||||
|
||||
return jobTypes.ToSelectListItems(selectedIds);
|
||||
}
|
||||
|
||||
public static List<SelectListItem> ToSelectListItems(this IEnumerable<JobType> jobTypes, List<string> SelectedIds = null)
|
||||
{
|
||||
if (SelectedIds == null)
|
||||
return jobTypes.Select(jt => new SelectListItem { Value = jt.Id, Text = jt.Description }).ToList();
|
||||
else
|
||||
return jobTypes.Select(jt => new SelectListItem { Value = jt.Id, Text = jt.Description, Selected = (SelectedIds.Contains(jt.Id)) }).ToList();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,147 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||
<ProductVersion>8.0.30703</ProductVersion>
|
||||
<SchemaVersion>2.0</SchemaVersion>
|
||||
<ProjectGuid>{C433EFBA-8608-4451-874B-AF32C8536792}</ProjectGuid>
|
||||
<OutputType>Library</OutputType>
|
||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<RootNamespace>Disco.Web.Extensions</RootNamespace>
|
||||
<AssemblyName>Disco.Web.Extensions</AssemblyName>
|
||||
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
<TargetFrameworkProfile />
|
||||
</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>
|
||||
<Prefer32Bit>false</Prefer32Bit>
|
||||
</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>
|
||||
<Prefer32Bit>false</Prefer32Bit>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="dotless.Core">
|
||||
<HintPath>..\packages\dotless.1.3.0.5\lib\dotless.Core.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="EntityFramework">
|
||||
<HintPath>..\packages\EntityFramework.5.0.0\lib\net45\EntityFramework.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Microsoft.Web.Infrastructure, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
|
||||
<Private>True</Private>
|
||||
<HintPath>..\packages\Microsoft.Web.Infrastructure.1.0.0.0\lib\net40\Microsoft.Web.Infrastructure.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Newtonsoft.Json, Version=4.5.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
<HintPath>..\packages\Newtonsoft.Json.4.5.9\lib\net40\Newtonsoft.Json.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.ComponentModel.DataAnnotations" />
|
||||
<Reference Include="System.Core" />
|
||||
<Reference Include="System.Data.Entity" />
|
||||
<Reference Include="System.Web" />
|
||||
<Reference Include="System.Web.Helpers, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
|
||||
<Private>True</Private>
|
||||
<HintPath>..\packages\Microsoft.AspNet.WebPages.2.0.20710.0\lib\net40\System.Web.Helpers.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System.Web.Mvc, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
|
||||
<Private>True</Private>
|
||||
<HintPath>..\packages\Microsoft.AspNet.Mvc.4.0.20710.0\lib\net40\System.Web.Mvc.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System.Web.Razor, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
|
||||
<Private>True</Private>
|
||||
<HintPath>..\packages\Microsoft.AspNet.Razor.2.0.20710.0\lib\net40\System.Web.Razor.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System.Web.WebPages, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
|
||||
<Private>True</Private>
|
||||
<HintPath>..\packages\Microsoft.AspNet.WebPages.2.0.20710.0\lib\net40\System.Web.WebPages.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System.Web.WebPages.Deployment, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
|
||||
<Private>True</Private>
|
||||
<HintPath>..\packages\Microsoft.AspNet.WebPages.2.0.20710.0\lib\net40\System.Web.WebPages.Deployment.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System.Web.WebPages.Razor, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
|
||||
<Private>True</Private>
|
||||
<HintPath>..\packages\Microsoft.AspNet.WebPages.2.0.20710.0\lib\net40\System.Web.WebPages.Razor.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System.Xml.Linq" />
|
||||
<Reference Include="System.Data.DataSetExtensions" />
|
||||
<Reference Include="Microsoft.CSharp" />
|
||||
<Reference Include="System.Data" />
|
||||
<Reference Include="System.Xml" />
|
||||
<Reference Include="WebActivator">
|
||||
<HintPath>..\packages\WebActivator.1.5.2\lib\net40\WebActivator.dll</HintPath>
|
||||
</Reference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="BIModelExtensions\OrganisationAddressExtensions.cs" />
|
||||
<Compile Include="BIModelExtensions\UtilityExtensions.cs" />
|
||||
<Compile Include="BIModelExtensions\DiscoPluginDefinitionExtensions.cs" />
|
||||
<Compile Include="DataModelExtension\DeviceBatchExtensions.cs" />
|
||||
<Compile Include="DataModelExtension\DeviceModelExtensions.cs" />
|
||||
<Compile Include="DataModelExtension\DeviceProfileExtensions.cs" />
|
||||
<Compile Include="DataModelExtension\DocumentTemplateExtensions.cs" />
|
||||
<Compile Include="DataModelExtension\JobSubTypeExtensions.cs" />
|
||||
<Compile Include="DataModelExtension\JobTypeExtensions.cs" />
|
||||
<Compile Include="MvcExtensions\Bundles\Bundle.cs" />
|
||||
<Compile Include="MvcExtensions\Bundles\BundleExtensions.cs" />
|
||||
<Compile Include="MvcExtensions\Bundles\BundleHandler.cs" />
|
||||
<Compile Include="MvcExtensions\Bundles\BundleModule.cs" />
|
||||
<Compile Include="MvcExtensions\Bundles\BundleTable.cs" />
|
||||
<Compile Include="MvcExtensions\dbAdminController.cs" />
|
||||
<Compile Include="MvcExtensions\dbController.cs" />
|
||||
<Compile Include="MvcExtensions\JsonNet\JsonNetResult.cs" />
|
||||
<Compile Include="MvcExtensions\PartialCompiled\PartialCompiledHtmlExtensions.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="MvcExtensions\XmlResult.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Disco.BI\Disco.BI.csproj">
|
||||
<Project>{095E6F94-3C34-47AE-BB83-46203535E0F6}</Project>
|
||||
<Name>Disco.BI</Name>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\Disco.Data\Disco.Data.csproj">
|
||||
<Project>{85A6BD19-2C64-4746-8F2C-A68A86E8C2D7}</Project>
|
||||
<Name>Disco.Data</Name>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\Disco.Models\Disco.Models.csproj">
|
||||
<Project>{FBC05512-FCCA-4B16-9E76-8C413C5DE6C9}</Project>
|
||||
<Name>Disco.Models</Name>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\Disco.Services\Disco.Services.csproj">
|
||||
<Project>{B80A737F-BD6A-4986-9182-DD7B932BD950}</Project>
|
||||
<Name>Disco.Services</Name>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="App.config" />
|
||||
<None Include="packages.config" />
|
||||
</ItemGroup>
|
||||
<ItemGroup />
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
<ProjectExtensions>
|
||||
<VisualStudio>
|
||||
<UserProperties BuildVersion_StartDate="2001/1/1" BuildVersion_UseGlobalSettings="True" BuildVersion_DetectChanges="False" BuildVersion_BuildAction="ReBuild" />
|
||||
</VisualStudio>
|
||||
</ProjectExtensions>
|
||||
<!-- 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>
|
||||
@@ -0,0 +1,134 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Security.Cryptography;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Web;
|
||||
|
||||
namespace Disco.Web.Extensions.MvcExtensions.Bundles
|
||||
{
|
||||
public class Bundle
|
||||
{
|
||||
private DateTime? _FileLastModified { get; set; }
|
||||
private string _FileHash { get; set; }
|
||||
private string _VersionUrl { get; set; }
|
||||
|
||||
public string Url { get; private set; }
|
||||
public string File { get; private set; }
|
||||
public string FileHash
|
||||
{
|
||||
get
|
||||
{
|
||||
#if DEBUG
|
||||
UpdateFileHash();
|
||||
#endif
|
||||
return _FileHash;
|
||||
}
|
||||
}
|
||||
public string ContentType { get; private set; }
|
||||
public string VersionUrl
|
||||
{
|
||||
get
|
||||
{
|
||||
#if DEBUG
|
||||
return string.Format("{0}?v={1}", this.Url, this.FileHash);
|
||||
#else
|
||||
return _VersionUrl;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
public Bundle(string Url, string File)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(Url))
|
||||
throw new ArgumentNullException("Url");
|
||||
if (string.IsNullOrWhiteSpace(File))
|
||||
throw new ArgumentNullException("File");
|
||||
|
||||
Uri fileUri;
|
||||
if (!Uri.TryCreate(File, UriKind.Absolute, out fileUri))
|
||||
{
|
||||
File = HttpContext.Current.Server.MapPath(File);
|
||||
}
|
||||
|
||||
var fileInfo = new FileInfo(File);
|
||||
|
||||
if (!fileInfo.Exists)
|
||||
throw new FileNotFoundException(string.Format("Not Found: {0}", File), File);
|
||||
|
||||
this.Url = Url;
|
||||
this.File = File;
|
||||
|
||||
switch (fileInfo.Extension.ToLower())
|
||||
{
|
||||
case ".css":
|
||||
this.ContentType = "text/css";
|
||||
break;
|
||||
case ".js":
|
||||
this.ContentType = "text/javascript";
|
||||
break;
|
||||
default:
|
||||
throw new ArgumentException("Unsupported Bundle File Extension");
|
||||
}
|
||||
|
||||
// Write File Hash
|
||||
if (fileInfo.Length > 0)
|
||||
UpdateFileHash();
|
||||
else
|
||||
this._FileHash = string.Empty;
|
||||
|
||||
//this.Version = fileInfo.LastWriteTimeUtc.Ticks;
|
||||
|
||||
this._VersionUrl = string.Format("{0}?v={1}", this.Url, this.FileHash);
|
||||
}
|
||||
|
||||
private void UpdateFileHash()
|
||||
{
|
||||
if (System.IO.File.Exists(this.File))
|
||||
{
|
||||
var fileLastModified = System.IO.File.GetLastWriteTimeUtc(this.File);
|
||||
if (!this._FileLastModified.HasValue || this._FileLastModified.Value != fileLastModified)
|
||||
{
|
||||
this._FileLastModified = fileLastModified;
|
||||
var fileBytes = System.IO.File.ReadAllBytes(this.File);
|
||||
if (fileBytes.Length > 0)
|
||||
{
|
||||
using (SHA256 sha = SHA256.Create())
|
||||
{
|
||||
byte[] hash = sha.ComputeHash(fileBytes);
|
||||
this._FileHash = HttpServerUtility.UrlTokenEncode(hash);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// Already Updated
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
this._FileHash = string.Empty;
|
||||
}
|
||||
|
||||
internal void ProcessRequest(HttpContext context)
|
||||
{
|
||||
// Write Content Type
|
||||
context.Response.ContentType = this.ContentType;
|
||||
|
||||
// Write Headers
|
||||
var cache = context.Response.Cache;
|
||||
cache.SetCacheability(HttpCacheability.Public);
|
||||
cache.SetOmitVaryStar(true);
|
||||
cache.SetExpires(DateTime.Now.AddYears(1));
|
||||
cache.SetValidUntilExpires(true);
|
||||
cache.SetLastModified(DateTime.Now);
|
||||
cache.VaryByHeaders["User-Agent"] = true;
|
||||
|
||||
// Write File
|
||||
context.Response.WriteFile(this.File);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Web;
|
||||
using System.Web.Mvc;
|
||||
using Disco.Web.Extensions.MvcExtensions.Bundles;
|
||||
|
||||
namespace Disco.Web.Extensions
|
||||
{
|
||||
public static class BundleExtensions
|
||||
{
|
||||
public static void BundleDeferred(this HtmlHelper htmlHelper, string BundleUrl)
|
||||
{
|
||||
// Ensure 'App-Relative' Url:
|
||||
BundleUrl = BundleUrl.StartsWith("~/") ? BundleUrl : (BundleUrl.StartsWith("/") ? string.Concat("~", BundleUrl) : string.Concat("~/", BundleUrl));
|
||||
|
||||
var deferredBundles = default(List<string>);
|
||||
deferredBundles = htmlHelper.ViewContext.HttpContext.Items["Bundles.Deferred"] as List<string>;
|
||||
if (deferredBundles == null)
|
||||
{
|
||||
deferredBundles = new List<string>();
|
||||
htmlHelper.ViewContext.HttpContext.Items["Bundles.Deferred"] = deferredBundles;
|
||||
}
|
||||
if (!deferredBundles.Contains(BundleUrl))
|
||||
deferredBundles.Add(BundleUrl);
|
||||
}
|
||||
public static HtmlString BundleRenderDeferred(this HtmlHelper htmlHelper)
|
||||
{
|
||||
var deferredBundles = default(List<string>);
|
||||
deferredBundles = htmlHelper.ViewContext.HttpContext.Items["Bundles.Deferred"] as List<string>;
|
||||
|
||||
if (deferredBundles != null)
|
||||
{
|
||||
StringBuilder bundleUrls = new StringBuilder();
|
||||
deferredBundles.Reverse();
|
||||
foreach (string bundleUrl in deferredBundles)
|
||||
{
|
||||
bundleUrls.AppendLine(BundleTable.ResolveBundleHtmlElement(bundleUrl));
|
||||
}
|
||||
return new HtmlString(bundleUrls.ToString());
|
||||
}
|
||||
else
|
||||
{
|
||||
return new HtmlString(string.Empty);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Web;
|
||||
|
||||
namespace Disco.Web.Extensions.MvcExtensions.Bundles
|
||||
{
|
||||
internal sealed class BundleHandler : IHttpHandler
|
||||
{
|
||||
public Bundle RequestBundle { get; private set; }
|
||||
public string BundleVirtualPath { get; private set; }
|
||||
|
||||
public BundleHandler(Bundle requestBundle, string bundleVirtualPath)
|
||||
{
|
||||
this.RequestBundle = requestBundle;
|
||||
this.BundleVirtualPath = bundleVirtualPath;
|
||||
}
|
||||
|
||||
public bool IsReusable
|
||||
{
|
||||
get { return false; }
|
||||
}
|
||||
|
||||
public void ProcessRequest(HttpContext context)
|
||||
{
|
||||
context.Response.Clear();
|
||||
|
||||
if (!string.IsNullOrEmpty(context.Request.Headers["If-Modified-Since"]))
|
||||
context.Response.StatusCode = 0x130;
|
||||
else
|
||||
this.RequestBundle.ProcessRequest(context);
|
||||
}
|
||||
|
||||
internal static bool RemapHandlerForBundleRequests(HttpApplication app)
|
||||
{
|
||||
var context = app.Context;
|
||||
|
||||
string bundleUrlFromContext = context.Request.AppRelativeCurrentExecutionFilePath + context.Request.PathInfo;
|
||||
var bundle = BundleTable.GetBundleFor(bundleUrlFromContext);
|
||||
|
||||
if (bundle != null)
|
||||
{
|
||||
context.RemapHandler(new BundleHandler(bundle, bundleUrlFromContext));
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Web;
|
||||
using Microsoft.Web.Infrastructure.DynamicModuleHelper;
|
||||
|
||||
[assembly: WebActivator.PreApplicationStartMethod(typeof(Disco.Web.Extensions.MvcExtensions.Bundles.BundleModule), "PreApplicationStart")]
|
||||
|
||||
namespace Disco.Web.Extensions.MvcExtensions.Bundles
|
||||
{
|
||||
public class BundleModule :IHttpModule
|
||||
{
|
||||
public void Init(HttpApplication context)
|
||||
{
|
||||
context.PostResolveRequestCache += new EventHandler(this.OnApplicationPostResolveRequestCache);
|
||||
}
|
||||
|
||||
private void OnApplicationPostResolveRequestCache(object sender, EventArgs e)
|
||||
{
|
||||
HttpApplication app = (HttpApplication)sender;
|
||||
if (BundleTable.Count > 0)
|
||||
{
|
||||
BundleHandler.RemapHandlerForBundleRequests(app);
|
||||
}
|
||||
}
|
||||
|
||||
private static bool _startWasCalled;
|
||||
public static void PreApplicationStart()
|
||||
{
|
||||
if (!_startWasCalled)
|
||||
{
|
||||
_startWasCalled = true;
|
||||
DynamicModuleUtility.RegisterModule(typeof(BundleModule));
|
||||
}
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
// Dispose Nothing
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Web;
|
||||
|
||||
namespace Disco.Web.Extensions.MvcExtensions.Bundles
|
||||
{
|
||||
public static class BundleTable
|
||||
{
|
||||
private static Dictionary<string, Bundle> _bundles;
|
||||
|
||||
static BundleTable()
|
||||
{
|
||||
_bundles = new Dictionary<string, Bundle>();
|
||||
}
|
||||
|
||||
public static void Add(Bundle Bundle)
|
||||
{
|
||||
_bundles[Bundle.Url] = Bundle;
|
||||
}
|
||||
|
||||
public static int Count
|
||||
{
|
||||
get
|
||||
{
|
||||
return _bundles.Count;
|
||||
}
|
||||
}
|
||||
|
||||
internal static Bundle GetBundleFor(string Url)
|
||||
{
|
||||
if (_bundles.ContainsKey(Url))
|
||||
{
|
||||
return _bundles[Url];
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static string ResolveBundleUrl(string BundleUrl)
|
||||
{
|
||||
var bundle = GetBundleFor(BundleUrl);
|
||||
|
||||
if (bundle == null)
|
||||
throw new ArgumentException(string.Format("Unknown Bundle Url: {0}", BundleUrl), "BundleUrl");
|
||||
|
||||
return VirtualPathUtility.ToAbsolute(bundle.VersionUrl);
|
||||
}
|
||||
public static string ResolveBundleHtmlElement(string BundleUrl)
|
||||
{
|
||||
var bundle = GetBundleFor(BundleUrl);
|
||||
|
||||
if (bundle == null)
|
||||
throw new ArgumentException(string.Format("Unknown Bundle Url: {0}", BundleUrl), "BundleUrl");
|
||||
|
||||
var bundleUrl = VirtualPathUtility.ToAbsolute(bundle.VersionUrl);
|
||||
|
||||
switch (bundle.ContentType)
|
||||
{
|
||||
case "text/css":
|
||||
return string.Format("<link href=\"{0}\" rel=\"stylesheet\" type=\"text/css\" />", bundleUrl);
|
||||
case "text/javascript":
|
||||
return string.Format("<script src=\"{0}\" type=\"text/javascript\"></script>", bundleUrl);
|
||||
default:
|
||||
throw new ArgumentException("Unsupported Bundle Content Type", "BundleUrl");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Web.Optimization;
|
||||
|
||||
namespace Disco.Web.Extensions.MvcExtensions.Bundles
|
||||
{
|
||||
public class BundleUnordered : IBundleOrderer
|
||||
{
|
||||
public IEnumerable<System.IO.FileInfo> OrderFiles(BundleContext context, IEnumerable<System.IO.FileInfo> files)
|
||||
{
|
||||
return files;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Web.Optimization;
|
||||
using System.IO;
|
||||
|
||||
namespace Disco.Web.Extensions.MvcExtensions.Bundles
|
||||
{
|
||||
public class JsJoin : IBundleTransform
|
||||
{
|
||||
internal static string JsContentType;
|
||||
static JsJoin()
|
||||
{
|
||||
JsContentType = "text/javascript";
|
||||
}
|
||||
|
||||
public void Process(BundleContext context, BundleResponse response)
|
||||
{
|
||||
if (context == null)
|
||||
throw new ArgumentNullException("context");
|
||||
if (response == null)
|
||||
throw new ArgumentNullException("response");
|
||||
|
||||
// Not Needed - the new Transforms pipeline has already loaded the content
|
||||
//if (!context.EnableInstrumentation && string.IsNullOrEmpty(response.Content))
|
||||
//{
|
||||
// try
|
||||
// {
|
||||
// StringBuilder bundleContent = new StringBuilder();
|
||||
// foreach (FileInfo file in response.Files)
|
||||
// {
|
||||
// string fileContent = File.ReadAllText(file.FullName);
|
||||
|
||||
// bundleContent.AppendLine(fileContent);
|
||||
// }
|
||||
|
||||
// response.Content = bundleContent.ToString();
|
||||
// }
|
||||
// catch (Exception ex)
|
||||
// {
|
||||
// GenerateErrorResponse(response, new string[] { ex.GetType().Name, ex.Message, ex.StackTrace });
|
||||
// }
|
||||
//}
|
||||
|
||||
response.ContentType = JsContentType;
|
||||
}
|
||||
|
||||
internal static void GenerateErrorResponse(BundleResponse bundle, ICollection<string> errors)
|
||||
{
|
||||
StringBuilder builder = new StringBuilder();
|
||||
builder.Append("/* ");
|
||||
builder.Append("Bundle creation failed [JsJoin].").Append("\r\n");
|
||||
foreach (string str in errors)
|
||||
{
|
||||
builder.Append(str).Append("\r\n");
|
||||
}
|
||||
builder.Append(" */\r\n");
|
||||
bundle.Content = builder.ToString();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,140 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.IO;
|
||||
using System.Web;
|
||||
using dotless.Core;
|
||||
using dotless.Core.configuration;
|
||||
using System.Web.Optimization;
|
||||
|
||||
namespace Disco.Web.Extensions.MvcExtensions.Bundles
|
||||
{
|
||||
public class LessCompile : IBundleTransform
|
||||
{
|
||||
internal static string CssContentType;
|
||||
internal static readonly ILessEngine Instance;
|
||||
|
||||
static LessCompile()
|
||||
{
|
||||
CssContentType = "text/css";
|
||||
Instance = new EngineFactory(new DotlessConfiguration()
|
||||
{
|
||||
CacheEnabled = false,
|
||||
MinifyOutput = true
|
||||
}).GetEngine();
|
||||
}
|
||||
|
||||
public void Process(BundleContext context, BundleResponse response)
|
||||
{
|
||||
if (context == null)
|
||||
throw new ArgumentNullException("context");
|
||||
if (response == null)
|
||||
throw new ArgumentNullException("response");
|
||||
|
||||
if (!context.EnableInstrumentation)
|
||||
{
|
||||
|
||||
try
|
||||
{
|
||||
StringBuilder bundleContent = new StringBuilder();
|
||||
Uri appRootPath = new Uri(HttpContext.Current.Request.PhysicalApplicationPath);
|
||||
|
||||
var restoreEnvironmentCurrentDirectory = Environment.CurrentDirectory;
|
||||
|
||||
foreach (FileInfo file in response.Files)
|
||||
{
|
||||
string fileContent = File.ReadAllText(file.FullName);
|
||||
Uri fileRootPath = new Uri(file.DirectoryName + "/");
|
||||
|
||||
// Less Compile
|
||||
|
||||
Environment.CurrentDirectory = file.DirectoryName;
|
||||
fileContent = Instance.TransformToCss(fileContent, file.FullName);
|
||||
|
||||
// Embed Images
|
||||
fileContent = EmbedCssImages(fileContent, fileRootPath, appRootPath);
|
||||
bundleContent.Append(fileContent);
|
||||
}
|
||||
|
||||
if (!Environment.CurrentDirectory.Equals(restoreEnvironmentCurrentDirectory))
|
||||
Environment.CurrentDirectory = restoreEnvironmentCurrentDirectory;
|
||||
|
||||
response.Content = bundleContent.ToString();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
GenerateErrorResponse(response, new string[] { ex.GetType().Name, ex.Message, ex.StackTrace });
|
||||
}
|
||||
}
|
||||
response.ContentType = CssContentType;
|
||||
}
|
||||
|
||||
private static string EmbedCssImages(string cssContent, Uri fileRootPath, Uri appRootPath)
|
||||
{
|
||||
return Regex.Replace(cssContent, "url\\((.*?)\\)", m =>
|
||||
{
|
||||
var cssFilename = m.Groups[1].Value.Trim(new char[] { '\'', '"' });
|
||||
Uri fileUri;
|
||||
if (cssFilename.StartsWith("/"))
|
||||
fileUri = new Uri(appRootPath, cssFilename);
|
||||
else
|
||||
fileUri = new Uri(fileRootPath, cssFilename);
|
||||
if (File.Exists(fileUri.LocalPath))
|
||||
{
|
||||
var fileInfo = new FileInfo(fileUri.LocalPath);
|
||||
// Ensure File is < 250kb
|
||||
if (fileInfo.Length < 256000)
|
||||
{
|
||||
string contentType = null;
|
||||
switch (fileInfo.Extension)
|
||||
{
|
||||
case ".png":
|
||||
contentType = "image/png";
|
||||
break;
|
||||
case ".gif":
|
||||
contentType = "image/gif";
|
||||
break;
|
||||
case ".jpg":
|
||||
case ".jpeg":
|
||||
contentType = "image/jpeg";
|
||||
break;
|
||||
default:
|
||||
return m.Value;
|
||||
}
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.Append("url(data:");
|
||||
sb.Append(contentType);
|
||||
sb.Append(";base64,");
|
||||
sb.Append(Convert.ToBase64String(File.ReadAllBytes(fileInfo.FullName)));
|
||||
sb.Append(")");
|
||||
return sb.ToString();
|
||||
}
|
||||
else
|
||||
{
|
||||
return string.Format("url(/{0})", appRootPath.MakeRelativeUri(fileUri).ToString());
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new FileNotFoundException(string.Format("Unable to embed css image, file not found: '{0}' at '{1}'", cssFilename, fileUri.AbsolutePath), cssFilename);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
internal static void GenerateErrorResponse(BundleResponse bundle, ICollection<string> errors)
|
||||
{
|
||||
StringBuilder builder = new StringBuilder();
|
||||
builder.Append("/* ");
|
||||
builder.Append("Bundle creation failed [LessCompile].").Append("\r\n");
|
||||
foreach (string str in errors)
|
||||
{
|
||||
builder.Append(str).Append("\r\n");
|
||||
}
|
||||
builder.Append(" */\r\n");
|
||||
bundle.Content = builder.ToString();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Web.Mvc;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace Disco.Web.Extensions
|
||||
{
|
||||
public class JsonNetResult : JsonResult
|
||||
{
|
||||
public override void ExecuteResult(ControllerContext context)
|
||||
{
|
||||
if (context == null)
|
||||
throw new ArgumentNullException("context");
|
||||
|
||||
var response = context.HttpContext.Response;
|
||||
|
||||
response.ContentType = !string.IsNullOrEmpty(ContentType) ? ContentType : "application/json";
|
||||
|
||||
if (ContentEncoding != null)
|
||||
response.ContentEncoding = ContentEncoding;
|
||||
|
||||
if (Data == null)
|
||||
return;
|
||||
|
||||
var serializedObject = JsonConvert.SerializeObject(Data, Formatting.Indented);
|
||||
|
||||
response.Write(serializedObject);
|
||||
}
|
||||
}
|
||||
|
||||
public static class JsonNetExtensions
|
||||
{
|
||||
public static JsonNetResult JsonNet(this Controller controller, object Data, JsonRequestBehavior JsonRequestBehavior)
|
||||
{
|
||||
return JsonNet(controller, Data, null, null, JsonRequestBehavior);
|
||||
}
|
||||
public static JsonNetResult JsonNet(this Controller controller, object Data, string ContentType, JsonRequestBehavior JsonRequestBehavior)
|
||||
{
|
||||
return JsonNet(controller, Data, ContentType, null, JsonRequestBehavior);
|
||||
}
|
||||
public static JsonNetResult JsonNet(this Controller controller, object Data, Encoding ContentEncoding, JsonRequestBehavior JsonRequestBehavior)
|
||||
{
|
||||
return JsonNet(controller, Data, null, ContentEncoding, JsonRequestBehavior);
|
||||
}
|
||||
public static JsonNetResult JsonNet(this Controller controller, object Data, string ContentType, Encoding ContentEncoding, JsonRequestBehavior JsonRequestBehavior)
|
||||
{
|
||||
return new JsonNetResult()
|
||||
{
|
||||
Data = Data,
|
||||
ContentType = ContentType,
|
||||
ContentEncoding = ContentEncoding,
|
||||
JsonRequestBehavior = JsonRequestBehavior
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Web.Mvc;
|
||||
using System.Web;
|
||||
using System.Web.WebPages;
|
||||
using System.IO;
|
||||
using System.Globalization;
|
||||
|
||||
namespace Disco.Web.Extensions
|
||||
{
|
||||
public static class PartialCompiledHtmlExtensions
|
||||
{
|
||||
#region Render Compiled Views
|
||||
private static void RenderPartialCompiledInternal(this HtmlHelper htmlHelper, Type viewType, object model, TextWriter writer)
|
||||
{
|
||||
if (writer == null)
|
||||
throw new ArgumentNullException("writer");
|
||||
WebViewPage page = Activator.CreateInstance(viewType) as WebViewPage;
|
||||
if (page == null)
|
||||
throw new InvalidOperationException("Invalid View Type");
|
||||
page.ViewContext = htmlHelper.ViewContext;
|
||||
page.ViewData = new ViewDataDictionary(model);
|
||||
page.InitHelpers();
|
||||
HttpContextBase httpContext = htmlHelper.ViewContext.HttpContext;
|
||||
page.ExecutePageHierarchy(new WebPageContext(httpContext, null, model), writer, null);
|
||||
}
|
||||
public static void RenderPartialCompiled(this HtmlHelper htmlHelper, Type viewType)
|
||||
{
|
||||
RenderPartialCompiled(htmlHelper, viewType, null);
|
||||
}
|
||||
public static void RenderPartialCompiled(this HtmlHelper htmlHelper, Type viewType, object model)
|
||||
{
|
||||
htmlHelper.RenderPartialCompiledInternal(viewType, model, htmlHelper.ViewContext.Writer);
|
||||
}
|
||||
public static MvcHtmlString PartialCompiled(this HtmlHelper htmlHelper, Type viewType)
|
||||
{
|
||||
return PartialCompiled(htmlHelper, viewType, null);
|
||||
}
|
||||
public static MvcHtmlString PartialCompiled(this HtmlHelper htmlHelper, Type viewType, object model)
|
||||
{
|
||||
using (StringWriter writer = new StringWriter(CultureInfo.CurrentCulture))
|
||||
{
|
||||
htmlHelper.RenderPartialCompiledInternal(viewType, model, writer);
|
||||
return MvcHtmlString.Create(writer.ToString());
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Web;
|
||||
using System.Web.Mvc;
|
||||
using System.Xml.Serialization;
|
||||
|
||||
namespace Disco.Web.Extensions
|
||||
{
|
||||
/// <summary>
|
||||
/// Action result that serializes the specified object into XML and outputs it to the response stream.
|
||||
/// <example>
|
||||
/// <![CDATA[
|
||||
/// public XmlResult AsXml() {
|
||||
/// List<Person> people = _peopleService.GetPeople();
|
||||
/// return new XmlResult(people);
|
||||
/// }
|
||||
/// ]]>
|
||||
/// </example>
|
||||
/// </summary>
|
||||
public class XmlResult : ActionResult
|
||||
{
|
||||
private object _objectToSerialize;
|
||||
private XmlAttributeOverrides _xmlAttribueOverrides;
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new instance of the XmlResult class.
|
||||
/// </summary>
|
||||
/// <param name="objectToSerialize">The object to serialize to XML.</param>
|
||||
public XmlResult(object objectToSerialize)
|
||||
{
|
||||
_objectToSerialize = objectToSerialize;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new instance of the XMLResult class.
|
||||
/// </summary>
|
||||
/// <param name="objectToSerialize">The object to serialize to XML.</param>
|
||||
/// <param name="xmlAttributeOverrides"></param>
|
||||
public XmlResult(object objectToSerialize, XmlAttributeOverrides xmlAttributeOverrides)
|
||||
{
|
||||
_objectToSerialize = objectToSerialize;
|
||||
_xmlAttribueOverrides = xmlAttributeOverrides;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The object to be serialized to XML.
|
||||
/// </summary>
|
||||
public object ObjectToSerialize
|
||||
{
|
||||
get { return _objectToSerialize; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Serialises the object that was passed into the constructor to XML and writes the corresponding XML to the result stream.
|
||||
/// </summary>
|
||||
/// <param name="context">The controller context for the current request.</param>
|
||||
public override void ExecuteResult(ControllerContext context)
|
||||
{
|
||||
if (_objectToSerialize != null)
|
||||
{
|
||||
var xs = (_xmlAttribueOverrides == null) ?
|
||||
new XmlSerializer(_objectToSerialize.GetType()) :
|
||||
new XmlSerializer(_objectToSerialize.GetType(), _xmlAttribueOverrides);
|
||||
context.HttpContext.Response.ContentType = "text/xml";
|
||||
xs.Serialize(context.HttpContext.Response.Output, _objectToSerialize);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Web;
|
||||
using System.Web.Mvc;
|
||||
|
||||
namespace Disco.Web
|
||||
{
|
||||
[Authorize(Roles = "Admin")]
|
||||
public class dbAdminController : dbController
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Web;
|
||||
using System.Web.Mvc;
|
||||
using Disco.Data.Repository;
|
||||
|
||||
namespace Disco.Web
|
||||
{
|
||||
[OutputCache(Duration = 0, Location = System.Web.UI.OutputCacheLocation.None)]
|
||||
public class dbController : Controller
|
||||
{
|
||||
protected DiscoDataContext dbContext;
|
||||
|
||||
protected override void OnActionExecuting(ActionExecutingContext filterContext)
|
||||
{
|
||||
this.dbContext = new DiscoDataContext();
|
||||
this.dbContext.Configuration.LazyLoadingEnabled = false;
|
||||
|
||||
base.OnActionExecuting(filterContext);
|
||||
}
|
||||
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (this.dbContext != null)
|
||||
{
|
||||
this.dbContext.Dispose();
|
||||
this.dbContext = null;
|
||||
}
|
||||
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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("Disco.Web.Extensions")]
|
||||
[assembly: AssemblyDescription("")]
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCompany("")]
|
||||
[assembly: AssemblyProduct("Disco.Web.Extensions")]
|
||||
[assembly: AssemblyCopyright("Copyright © 2012")]
|
||||
[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("a673b3dc-88d3-4df6-827f-cef274c5470c")]
|
||||
|
||||
// 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.2.0131.2002")]
|
||||
[assembly: AssemblyFileVersion("1.2.0131.2002")]
|
||||
@@ -0,0 +1,11 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<packages>
|
||||
<package id="dotless" version="1.3.0.5" targetFramework="net45" />
|
||||
<package id="EntityFramework" version="5.0.0" targetFramework="net45" />
|
||||
<package id="Microsoft.AspNet.Mvc" version="4.0.20710.0" targetFramework="net45" />
|
||||
<package id="Microsoft.AspNet.Razor" version="2.0.20710.0" targetFramework="net45" />
|
||||
<package id="Microsoft.AspNet.WebPages" version="2.0.20710.0" targetFramework="net45" />
|
||||
<package id="Microsoft.Web.Infrastructure" version="1.0.0.0" targetFramework="net45" />
|
||||
<package id="Newtonsoft.Json" version="4.5.9" targetFramework="net45" />
|
||||
<package id="WebActivator" version="1.5.2" targetFramework="net45" />
|
||||
</packages>
|
||||
Reference in New Issue
Block a user