Skip to content
Permalink
Browse files

Upgrade to MVC4

  • Loading branch information...
mythz committed Nov 1, 2014
1 parent 963dcc0 commit 69870ac9b4394af2bd909a6c79c5f595cbf6ccf6
Showing 590 changed files with 47,336 additions and 34,608 deletions.
@@ -0,0 +1,26 @@
using System.Collections.Generic;
using ServiceStack;
using ServiceStack.Configuration;

namespace SocialBootstrapApi
{
public class AppConfig
{
public AppConfig(IAppSettings appSettings)
{
this.Env = appSettings.Get("Env", Env.Local);
this.EnableCdn = appSettings.Get("EnableCdn", false);
this.CdnPrefix = appSettings.Get("CdnPrefix", "");
this.AdminUserNames = appSettings.Get("AdminUserNames", new List<string>());
}

public Env Env { get; set; }
public bool EnableCdn { get; set; }
public string CdnPrefix { get; set; }
public List<string> AdminUserNames { get; set; }
public BundleOptions BundleOptions
{
get { return Env.In(Env.Local, Env.Dev) ? BundleOptions.Normal : BundleOptions.MinifiedAndCombined; }
}
}
}
@@ -22,7 +22,7 @@
/**
* ServiceStack's Social Bootstrap API MVC web project based on
* Features:
* - MVC3 Web Application
* - MVC4 Web Application
* - ServiceStack web services framework hosted from /api
* - Twitter's Open Source HTML5 Bootstrap template
* - jQuery + Underscore + Backbone + Bootstrap js libraries
@@ -37,25 +37,6 @@
namespace SocialBootstrapApi
{
//Hold App wide configuration you want to accessible by your services
public class AppConfig
{
public AppConfig(IAppSettings appSettings)
{
this.Env = appSettings.Get("Env", Env.Local);
this.EnableCdn = appSettings.Get("EnableCdn", false);
this.CdnPrefix = appSettings.Get("CdnPrefix", "");
this.AdminUserNames = appSettings.Get("AdminUserNames", new List<string>());
}

public Env Env { get; set; }
public bool EnableCdn { get; set; }
public string CdnPrefix { get; set; }
public List<string> AdminUserNames { get; set; }
public BundleOptions BundleOptions
{
get { return Env.In(Env.Local, Env.Dev) ? BundleOptions.Normal : BundleOptions.MinifiedAndCombined; }
}
}

public enum Env
{
@@ -0,0 +1,43 @@
using System.Web;
using System.Web.Optimization;

namespace SocialBootstrapApi
{
public class BundleConfig
{
// For more information on Bundling, visit http://go.microsoft.com/fwlink/?LinkId=254725
public static void RegisterBundles(BundleCollection bundles)
{
bundles.Add(new ScriptBundle("~/bundles/jquery").Include(
"~/Scripts/jquery-{version}.js"));

bundles.Add(new ScriptBundle("~/bundles/jqueryui").Include(
"~/Scripts/jquery-ui-{version}.js"));

bundles.Add(new ScriptBundle("~/bundles/jqueryval").Include(
"~/Scripts/jquery.unobtrusive*",
"~/Scripts/jquery.validate*"));

// Use the development version of Modernizr to develop with and learn from. Then, when you're
// ready for production, use the build tool at http://modernizr.com to pick only the tests you need.
bundles.Add(new ScriptBundle("~/bundles/modernizr").Include(
"~/Scripts/modernizr-*"));

bundles.Add(new StyleBundle("~/Content/css").Include("~/Content/site.css"));

bundles.Add(new StyleBundle("~/Content/themes/base/css").Include(
"~/Content/themes/base/jquery.ui.core.css",
"~/Content/themes/base/jquery.ui.resizable.css",
"~/Content/themes/base/jquery.ui.selectable.css",
"~/Content/themes/base/jquery.ui.accordion.css",
"~/Content/themes/base/jquery.ui.autocomplete.css",
"~/Content/themes/base/jquery.ui.button.css",
"~/Content/themes/base/jquery.ui.dialog.css",
"~/Content/themes/base/jquery.ui.slider.css",
"~/Content/themes/base/jquery.ui.tabs.css",
"~/Content/themes/base/jquery.ui.datepicker.css",
"~/Content/themes/base/jquery.ui.progressbar.css",
"~/Content/themes/base/jquery.ui.theme.css"));
}
}
}
@@ -0,0 +1,13 @@
using System.Web;
using System.Web.Mvc;

namespace SocialBootstrapApi
{
public class FilterConfig
{
public static void RegisterGlobalFilters(GlobalFilterCollection filters)
{
filters.Add(new HandleErrorAttribute());
}
}
}
@@ -0,0 +1,60 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Routing;
using ServiceStack;
using ServiceStack.Mvc;
using ServiceStack.Web;

namespace SocialBootstrapApi
{
public class RouteConfig
{
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("Content/{*pathInfo}");
routes.IgnoreRoute("api/{*pathInfo}");
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute("Forwarding", "auth/{*pathinfo}", new { controller = "Forwarding", action = "Index" });

routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);

routes.MapRoute("CatchAll", "{*url}",
new { controller = "Home", action = "Index" }
);
}
}


/// <summary>
/// Re-use existing AuthWebTests OAuth app config which have callbacks registered at:
/// http://localhost:11001/auth/{provider} instead of the expected path for MVC + SS:
/// http://localhost:11001/api/auth/{provider}
/// </summary>
public class ForwardingController : ServiceStackController
{
public ActionResult Index()
{
var response = ForwardRequestToServiceStack();
if (ServiceStackResponse.IsClosed) return new EmptyResult();

var httpResult = response as IHttpResult;
if (httpResult != null)
{
string redirectUrl;
if (httpResult.Headers.TryGetValue(HttpHeaders.Location, out redirectUrl))
{
return Redirect(redirectUrl);
}
}

return Redirect("/");
}
}
}
@@ -30,12 +30,14 @@ public static class Bundler
{
public static Func<bool> CachePaths = IsProduction;
public static Func<string, BundleOptions, string> DefaultUrlFilter = ProcessVirtualPathDefault;
public static Func<string, string> MapPathFallbackFn;
public static bool UseMvc;

static Bundler()
{
var mvcControllerExists = AppDomain.CurrentDomain.GetAssemblies().Any(x => x.GetType("System.Web.Mvc.Controller") != null);
UseMvc = mvcControllerExists;
MapPathFallbackFn = MapHostAbsolutePath;
}

// Logic to determine if the app is running in production or dev environment
@@ -47,7 +49,7 @@ public static bool IsProduction()
public static bool FileExists(string virtualPath)
{
if (!HostingEnvironment.IsHosted) return false;
var filePath = HostingEnvironment.MapPath(virtualPath);
var filePath = MapPath(virtualPath);
return File.Exists(filePath);
}

@@ -58,7 +60,7 @@ public static string TimestampString(string virtualPath)
{
if (HostingEnvironment.IsHosted)
{
var filePath = HostingEnvironment.MapPath(virtualPath);
var filePath = MapPath(virtualPath);
return Convert.ToString((File.GetLastWriteTimeUtc(filePath).Ticks - centuryBegin.Ticks) / 1000000000, 16);
}
}
@@ -197,7 +199,7 @@ public static MvcHtmlString Link(this HtmlHelper html, string rel, string href,
return MvcHtmlString.Empty;

if (href.StartsWith("~/"))
href = href.Replace("~/", VirtualPathUtility.ToAbsolute("~"));
href = href.Replace("~/", VirtualPathUtility.ToAbsolute("~/"));

var tag = new TagBuilder("link");
tag.MergeAttribute("rel", rel);
@@ -228,7 +230,7 @@ public static MvcHtmlString Img(this HtmlHelper html, string src, string alt, st
return MvcHtmlString.Empty;

if (src.StartsWith("~/"))
src = src.Replace("~/", VirtualPathUtility.ToAbsolute("~"));
src = src.Replace("~/", VirtualPathUtility.ToAbsolute("~/"));

var tag = new TagBuilder("img");

@@ -254,7 +256,7 @@ public static MvcHtmlString Js(this HtmlHelper html, string src, BundleOptions o
return MvcHtmlString.Empty;

if (src.StartsWith("~/"))
src = src.Replace("~/", VirtualPathUtility.ToAbsolute("~"));
src = src.Replace("~/", VirtualPathUtility.ToAbsolute("~/"));

var tag = new TagBuilder("script");
tag.MergeAttribute("type", "text/javascript");
@@ -285,7 +287,7 @@ public static MvcHtmlString RenderJsBundle(this HtmlHelper html, string bundlePa

return BundleCache.GetOrAdd(bundlePath, str =>
{
var filePath = HostingEnvironment.MapPath(bundlePath);
var filePath = MapPath(bundlePath);

var baseUrl = VirtualPathUtility.GetDirectory(bundlePath);

@@ -326,7 +328,7 @@ public static MvcHtmlString RenderCssBundle(this HtmlHelper html, string bundleP

return BundleCache.GetOrAdd(bundlePath, str =>
{
var filePath = HostingEnvironment.MapPath(bundlePath);
var filePath = MapPath(bundlePath);

var baseUrl = VirtualPathUtility.GetDirectory(bundlePath);

@@ -358,5 +360,34 @@ public static MvcHtmlString RenderCssBundle(this HtmlHelper html, string bundleP
return styles.ToString().ToMvcHtmlString();
});
}

public static string MapPath(string virtualPath)
{
return HostingEnvironment.MapPath(virtualPath)
?? (MapPathFallbackFn != null ? MapPathFallbackFn(virtualPath) : null); //Mono can return null
}

//From ServiceStack.PathUtils
private static string MapHostAbsolutePath(this string relativePath)
{
var mapPath = MapAbsolutePath(relativePath, string.Format("{0}..", Path.DirectorySeparatorChar));
return mapPath;
}

public static string MapAbsolutePath(string relativePath, string appendPartialPathModifier)
{
if (relativePath.StartsWith("~"))
{
var assemblyDirectoryPath = Path.GetDirectoryName(new Uri(typeof(Bundler).Assembly.EscapedCodeBase).LocalPath);

// Escape the assembly bin directory to the hostname directory
var hostDirectoryPath = appendPartialPathModifier != null
? assemblyDirectoryPath + appendPartialPathModifier
: assemblyDirectoryPath;

return Path.GetFullPath(relativePath.Replace("~", hostDirectoryPath));
}
return relativePath;
}
}
}
@@ -0,0 +1,61 @@
body {
font-size: .85em;
font-family: "Segoe UI", Verdana, Helvetica, Sans-Serif;
color: #232323;
background-color: #fff;
}

header, footer, nav, section {
display: block;
}


/* Styles for basic forms
-----------------------------------------------------------*/
fieldset {
border: 1px solid #ddd;
padding: 0 1.4em 1.4em 1.4em;
margin: 0 0 1.5em 0;
}

legend {
font-size: 1.2em;
font-weight: bold;
}

textarea {
min-height: 75px;
}

.editor-label {
margin: 1em 0 0 0;
}

.editor-field {
margin: 0.5em 0 0 0;
}


/* Styles for validation helpers
-----------------------------------------------------------*/
.field-validation-error {
color: #f00;
}

.field-validation-valid {
display: none;
}

.input-validation-error {
border: 1px solid #f00;
background-color: #fee;
}

.validation-summary-errors {
font-weight: bold;
color: #f00;
}

.validation-summary-valid {
display: none;
}
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

0 comments on commit 69870ac

Please sign in to comment.
You can’t perform that action at this time.