Permalink
Browse files

[+] T4MVC added

  • Loading branch information...
artiomchi committed Apr 27, 2012
1 parent d7605db commit ff4403f2483a18bd4f6380994242d221a19dfe0e
@@ -39,6 +39,10 @@
<Reference Include="EntityFramework">
<HintPath>..\packages\EntityFramework.5.0.0-beta2\lib\net45\EntityFramework.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.4\lib\net40\Newtonsoft.Json.dll</HintPath>
+ </Reference>
<Reference Include="SimpleInjector">
<HintPath>..\packages\SimpleInjector.1.4.0.12049\lib\net35\SimpleInjector.dll</HintPath>
</Reference>
@@ -4,6 +4,7 @@
using System.Collections.Generic;
using System.Linq;
using EventsCalendar.Model;
+ using Newtonsoft.Json.Linq;
public class RedditRepository
{
@@ -41,5 +42,31 @@ public IEnumerable<Post> GetTopPosts()
};
return post;
};
+
+ public OperationStatus TestCredentials(string login, string password)
+ {
+ try
+ {
+ var session = com.reddit.api.User.Login(login, password);
+ return new OperationStatus { Status = true };
+ }
+ catch (com.reddit.api.RedditException ex)
+ {
+ var obj = JObject.Parse(ex.Message);
+ var error = "Unknown error";
+
+ var json = obj["json"];
+ if (json != null)
+ {
+ var errors = json["errors"];
+ if (errors != null && errors.HasValues)
+ {
+ error = errors[0][1].ToString();
+ }
+ }
+
+ return new OperationStatus { Status = false, Message = error };
+ }
+ }
}
}
@@ -102,7 +102,7 @@ public T GetValue<T>(String name, T defaultValue = default(T))
return defaultValue;
}
- public void SetValue(string name, Object valueObj, bool dirtyWrite = false)
+ public static void SetValue(string name, Object valueObj, bool dirtyWrite = false)
{
var value = Convert.ToString(valueObj);
using (var db = new CalendarDbContext())
@@ -114,7 +114,7 @@ public void SetValue(string name, Object valueObj, bool dirtyWrite = false)
db.SaveChanges();
}
- if (prop.Value != this[name] && prop.Value != value && !dirtyWrite)
+ if (prop.Value != Default[name] && prop.Value != value && !dirtyWrite)
{
UpdateSettings();
throw new ApplicationException("Value has changed to something else, while you didn't know!");
@@ -127,8 +127,8 @@ public void SetValue(string name, Object valueObj, bool dirtyWrite = false)
public static class Reddit
{
- public static string BotLogin { get { return Default["Reddit.BotLogin"]; } }
- public static string BotPassword { get { return Default["Reddit.BotPassword"]; } }
+ public static string BotLogin { get { return Default["Reddit.BotLogin"]; } set { SetValue("Reddit.BotLogin", value); } }
+ public static string BotPassword { get { return Default["Reddit.BotPassword"]; } set { SetValue("Reddit.BotPassword", value); } }
}
public static class GoogleAPI
@@ -4,5 +4,6 @@
<package id="DotNetOpenAuth.Core" version="4.0.1.12097" />
<package id="DotNetOpenAuth.OAuth2.Core" version="0.23.0-draft3" />
<package id="EntityFramework" version="5.0.0-beta2" />
+ <package id="Newtonsoft.Json" version="4.5.4" />
<package id="SimpleInjector" version="1.4.0.12049" />
</packages>
@@ -0,0 +1,109 @@
+// <auto-generated />
+// This file was generated by a T4 template.
+// Don't change it directly as your change would get overwritten. Instead, make changes
+// to the .tt file (i.e. the T4 template) and save it to regenerate this file.
+
+// Make sure the compiler doesn't complain about missing Xml comments
+#pragma warning disable 1591
+#region T4MVC
+
+using System;
+using System.Diagnostics;
+using System.CodeDom.Compiler;
+using System.Collections.Generic;
+using System.Linq;
+using System.Runtime.CompilerServices;
+using System.Web;
+using System.Web.Hosting;
+using System.Web.Mvc;
+using System.Web.Mvc.Ajax;
+using System.Web.Mvc.Html;
+using System.Web.Routing;
+using T4MVC;
+namespace EventsCalendar.Web.Areas.Admin.Controllers {
+ public partial class CalendarController {
+ [GeneratedCode("T4MVC", "2.0"), DebuggerNonUserCode]
+ public CalendarController() { }
+
+ [GeneratedCode("T4MVC", "2.0"), DebuggerNonUserCode]
+ protected CalendarController(Dummy d) { }
+
+ [GeneratedCode("T4MVC", "2.0"), DebuggerNonUserCode]
+ protected RedirectToRouteResult RedirectToAction(ActionResult result) {
+ var callInfo = result.GetT4MVCResult();
+ return RedirectToRoute(callInfo.RouteValueDictionary);
+ }
+
+ [GeneratedCode("T4MVC", "2.0"), DebuggerNonUserCode]
+ protected RedirectToRouteResult RedirectToActionPermanent(ActionResult result) {
+ var callInfo = result.GetT4MVCResult();
+ return RedirectToRoutePermanent(callInfo.RouteValueDictionary);
+ }
+
+
+ [GeneratedCode("T4MVC", "2.0"), DebuggerNonUserCode]
+ public CalendarController Actions { get { return MVC.Admin.Calendar; } }
+ [GeneratedCode("T4MVC", "2.0")]
+ public readonly string Area = "Admin";
+ [GeneratedCode("T4MVC", "2.0")]
+ public readonly string Name = "Calendar";
+ [GeneratedCode("T4MVC", "2.0")]
+ public const string NameConst = "Calendar";
+
+ static readonly ActionNamesClass s_actions = new ActionNamesClass();
+ [GeneratedCode("T4MVC", "2.0"), DebuggerNonUserCode]
+ public ActionNamesClass ActionNames { get { return s_actions; } }
+ [GeneratedCode("T4MVC", "2.0"), DebuggerNonUserCode]
+ public class ActionNamesClass {
+ public readonly string Index = "Index";
+ public readonly string Authorize = "Authorize";
+ }
+
+ [GeneratedCode("T4MVC", "2.0"), DebuggerNonUserCode]
+ public class ActionNameConstants {
+ public const string Index = "Index";
+ public const string Authorize = "Authorize";
+ }
+
+
+ static readonly ActionParamsClass_Authorize s_params_Authorize = new ActionParamsClass_Authorize();
+ [GeneratedCode("T4MVC", "2.0"), DebuggerNonUserCode]
+ public ActionParamsClass_Authorize AuthorizeParams { get { return s_params_Authorize; } }
+ [GeneratedCode("T4MVC", "2.0"), DebuggerNonUserCode]
+ public class ActionParamsClass_Authorize {
+ public readonly string code = "code";
+ }
+ static readonly ViewNames s_views = new ViewNames();
+ [GeneratedCode("T4MVC", "2.0"), DebuggerNonUserCode]
+ public ViewNames Views { get { return s_views; } }
+ [GeneratedCode("T4MVC", "2.0"), DebuggerNonUserCode]
+ public class ViewNames {
+ public readonly string Index = "~/Areas/Admin/Views/Calendar/Index.cshtml";
+ }
+ }
+
+ [GeneratedCode("T4MVC", "2.0"), DebuggerNonUserCode]
+ public class T4MVC_CalendarController: EventsCalendar.Web.Areas.Admin.Controllers.CalendarController {
+ public T4MVC_CalendarController() : base(Dummy.Instance) { }
+
+ public override System.Web.Mvc.ActionResult Index() {
+ var callInfo = new T4MVC_ActionResult(Area, Name, ActionNames.Index);
+ return callInfo;
+ }
+
+ public override System.Web.Mvc.ActionResult Authorize(string code) {
+ var callInfo = new T4MVC_ActionResult(Area, Name, ActionNames.Authorize);
+ callInfo.RouteValueDictionary.Add("code", code);
+ return callInfo;
+ }
+
+ public override System.Web.Mvc.ActionResult Authorize() {
+ var callInfo = new T4MVC_ActionResult(Area, Name, ActionNames.Authorize);
+ return callInfo;
+ }
+
+ }
+}
+
+#endregion T4MVC
+#pragma warning restore 1591
@@ -0,0 +1,96 @@
+// <auto-generated />
+// This file was generated by a T4 template.
+// Don't change it directly as your change would get overwritten. Instead, make changes
+// to the .tt file (i.e. the T4 template) and save it to regenerate this file.
+
+// Make sure the compiler doesn't complain about missing Xml comments
+#pragma warning disable 1591
+#region T4MVC
+
+using System;
+using System.Diagnostics;
+using System.CodeDom.Compiler;
+using System.Collections.Generic;
+using System.Linq;
+using System.Runtime.CompilerServices;
+using System.Web;
+using System.Web.Hosting;
+using System.Web.Mvc;
+using System.Web.Mvc.Ajax;
+using System.Web.Mvc.Html;
+using System.Web.Routing;
+using T4MVC;
+namespace EventsCalendar.Web.Areas.Admin.Controllers {
+ public partial class RedditController {
+ [GeneratedCode("T4MVC", "2.0"), DebuggerNonUserCode]
+ public RedditController() { }
+
+ [GeneratedCode("T4MVC", "2.0"), DebuggerNonUserCode]
+ protected RedditController(Dummy d) { }
+
+ [GeneratedCode("T4MVC", "2.0"), DebuggerNonUserCode]
+ protected RedirectToRouteResult RedirectToAction(ActionResult result) {
+ var callInfo = result.GetT4MVCResult();
+ return RedirectToRoute(callInfo.RouteValueDictionary);
+ }
+
+ [GeneratedCode("T4MVC", "2.0"), DebuggerNonUserCode]
+ protected RedirectToRouteResult RedirectToActionPermanent(ActionResult result) {
+ var callInfo = result.GetT4MVCResult();
+ return RedirectToRoutePermanent(callInfo.RouteValueDictionary);
+ }
+
+
+ [GeneratedCode("T4MVC", "2.0"), DebuggerNonUserCode]
+ public RedditController Actions { get { return MVC.Admin.Reddit; } }
+ [GeneratedCode("T4MVC", "2.0")]
+ public readonly string Area = "Admin";
+ [GeneratedCode("T4MVC", "2.0")]
+ public readonly string Name = "Reddit";
+ [GeneratedCode("T4MVC", "2.0")]
+ public const string NameConst = "Reddit";
+
+ static readonly ActionNamesClass s_actions = new ActionNamesClass();
+ [GeneratedCode("T4MVC", "2.0"), DebuggerNonUserCode]
+ public ActionNamesClass ActionNames { get { return s_actions; } }
+ [GeneratedCode("T4MVC", "2.0"), DebuggerNonUserCode]
+ public class ActionNamesClass {
+ public readonly string Index = "Index";
+ public readonly string TestCredentials = "TestCredentials";
+ }
+
+ [GeneratedCode("T4MVC", "2.0"), DebuggerNonUserCode]
+ public class ActionNameConstants {
+ public const string Index = "Index";
+ public const string TestCredentials = "TestCredentials";
+ }
+
+
+ static readonly ViewNames s_views = new ViewNames();
+ [GeneratedCode("T4MVC", "2.0"), DebuggerNonUserCode]
+ public ViewNames Views { get { return s_views; } }
+ [GeneratedCode("T4MVC", "2.0"), DebuggerNonUserCode]
+ public class ViewNames {
+ public readonly string Index = "~/Areas/Admin/Views/Reddit/Index.cshtml";
+ }
+ }
+
+ [GeneratedCode("T4MVC", "2.0"), DebuggerNonUserCode]
+ public class T4MVC_RedditController: EventsCalendar.Web.Areas.Admin.Controllers.RedditController {
+ public T4MVC_RedditController() : base(Dummy.Instance) { }
+
+ public override System.Web.Mvc.ActionResult Index() {
+ var callInfo = new T4MVC_ActionResult(Area, Name, ActionNames.Index);
+ return callInfo;
+ }
+
+ public override System.Web.Mvc.ActionResult TestCredentials() {
+ var callInfo = new T4MVC_ActionResult(Area, Name, ActionNames.TestCredentials);
+ return callInfo;
+ }
+
+ }
+}
+
+#endregion T4MVC
+#pragma warning restore 1591
@@ -0,0 +1,37 @@
+// <auto-generated />
+// This file was generated by a T4 template.
+// Don't change it directly as your change would get overwritten. Instead, make changes
+// to the .tt file (i.e. the T4 template) and save it to regenerate this file.
+
+// Make sure the compiler doesn't complain about missing Xml comments
+#pragma warning disable 1591
+#region T4MVC
+
+using System;
+using System.Diagnostics;
+using System.CodeDom.Compiler;
+using System.Collections.Generic;
+using System.Linq;
+using System.Runtime.CompilerServices;
+using System.Web;
+using System.Web.Hosting;
+using System.Web.Mvc;
+using System.Web.Mvc.Ajax;
+using System.Web.Mvc.Html;
+using System.Web.Routing;
+using T4MVC;
+namespace T4MVC.Admin {
+ public class SharedController {
+
+ static readonly ViewNames s_views = new ViewNames();
+ [GeneratedCode("T4MVC", "2.0"), DebuggerNonUserCode]
+ public ViewNames Views { get { return s_views; } }
+ [GeneratedCode("T4MVC", "2.0"), DebuggerNonUserCode]
+ public class ViewNames {
+ }
+ }
+
+}
+
+#endregion T4MVC
+#pragma warning restore 1591
@@ -16,7 +16,7 @@
namespace EventsCalendar.Web.Areas.Admin.Controllers
{
- public class CalendarController : Controller
+ public partial class CalendarController : Controller
{
protected override void Initialize(System.Web.Routing.RequestContext requestContext)
{
@@ -62,7 +62,7 @@ private IAuthorizationState GetAuthorization(WebServerClient client)
//
// GET: /Admin/Calendar
- public ActionResult Index()
+ public virtual ActionResult Index()
{
var model = new IndexModel
{
@@ -86,20 +86,20 @@ public ActionResult Index()
//
// GET: /Admin/Calendar/Authorize
- public ActionResult Authorize(String code)
+ public virtual ActionResult Authorize(String code)
{
if (!String.IsNullOrEmpty(code))
{
var oldState = _authenticator.State;
_authenticator.LoadAccessToken();
}
- return RedirectToAction("Index");
+ return RedirectToAction(Actions.Index());
}
//
// GET: /Admin/Calendar/Authorize
[HttpPost]
- public ActionResult Authorize()
+ public virtual ActionResult Authorize()
{
_userRepository.ResetCalendarAuthorization(SettingsRepository.Reddit.BotLogin);
string scope = CalendarService.Scopes.Calendar.GetStringValue();
Oops, something went wrong.

0 comments on commit ff4403f

Please sign in to comment.