GIT: perform LF normalization
This commit is contained in:
@@ -1,70 +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");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
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");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,17 +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;
|
||||
}
|
||||
}
|
||||
}
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,63 +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();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
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();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,140 +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();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
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();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,58 +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
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
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
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+51
-51
@@ -1,51 +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
|
||||
}
|
||||
}
|
||||
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
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,71 +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);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,13 +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
|
||||
{
|
||||
}
|
||||
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
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -1,34 +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);
|
||||
}
|
||||
}
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user