public void Run() { ProjectContextLoader.EnsureLoaded(Message); string actionsList = null; using (AppConfig.Change(ProjectContextLoader.WebConfigPath)) { dynamic pdb = Activator.CreateInstance("Lynicon", "Lynicon.Repositories.PreloadDb").Unwrap(); try { actionsList = (string)pdb.EnsureCoreDb(); } catch (Exception ex) { if (ex.Message.Contains("transient failure") || ex.Message.Contains("failed on Open")) { Message(new MessageEventArgs(new Exception("The database may not yet exist: please ensure it is created", ex))); } else { Message(new MessageEventArgs(ex)); } } } Message(new MessageEventArgs(MessageType.Output, "Initialised Successfully: " + (actionsList ?? "no actions taken"))); }
protected override void ProcessRecord() { var fileModel = ProjectContextLoader.GetItemFileModel(SendMessage, "Global.asax"); bool found = fileModel.FindLineContains("Application_Start()") && fileModel.FindLineIs("{"); if (found) { fileModel.InsertUniqueLineWithIndent("// Lynicon install inserted these 2 lines", useIndentAfter: true); fileModel.InsertUniqueLineWithIndent("LyniconConfig.RegisterModules();", useIndentAfter: true); fileModel.InsertUniqueLineWithIndent("LyniconConfig.InitialiseDataApi();", useIndentAfter: true); fileModel.InsertLineWithIndent(""); found = fileModel.FindLineContains("RouteConfig.RegisterRoutes("); if (fileModel.FindLineContains("BundleConfig.RegisterBundles(")) { found = true; } if (found) { fileModel.InsertLineWithIndent(""); fileModel.InsertUniqueLineWithIndent("// Lynicon install inserted this line"); fileModel.InsertUniqueLineWithIndent("LyniconConfig.Initialise();"); fileModel.InsertLineWithIndent(""); } } fileModel.Write(); var filtersFile = ProjectContextLoader.GetItemFileModel(SendMessage, "App_Start/FilterConfig.cs"); found = filtersFile.FindLineContains("using System.Web.Mvc;"); if (found) { filtersFile.InsertUniqueLineWithIndent("using Lynicon.Attributes;"); } found = filtersFile.FindLineContains("public static void RegisterGlobalFilters(") && filtersFile.FindLineIs("{"); if (found) { filtersFile.InsertLineWithIndent("// Lynicon install inserted these 2 lines", useIndentAfter: true); filtersFile.InsertLineWithIndent("filters.Add(new ProcessIncludesAttribute());", useIndentAfter: true); filtersFile.InsertLineWithIndent("filters.Add(new ProcessHtmlAttribute());", useIndentAfter: true); } filtersFile.Write(); WriteObject("Updated Global.asax.cs, FilterConfig.cs"); }
public void Run(string password) { ProjectContextLoader.InitialiseDataApi(Message); using (AppConfig.Change(ProjectContextLoader.WebConfigPath)) { try { Assembly lynicon = AppDomain.CurrentDomain.GetAssemblies().FirstOrDefault(a => a.GetName().Name.ToLower() == "lynicon"); Type secmType = lynicon.GetType("Lynicon.Membership.LyniconSecurityManager"); MethodInfo ensureAdminUser = secmType.GetMethod("EnsureAdminUser", BindingFlags.Public | BindingFlags.Static); ensureAdminUser.Invoke(null, new object[] { password }); } catch (Exception ex) { Message(new MessageEventArgs(ex)); } } Message(new MessageEventArgs(MessageType.Output, "Created admin user, username: administrator, email: [email protected], with supplied password")); }
/// <summary> /// Set up assembly resolution for the remote AppDomain allowing it to resolve the current /// assembly as well as those from the Visual Studio project whose output it is loading /// </summary> /// <param name="toolsAssemblyPath"></param> public void InitializeRemoteAssemblyResolution(string toolsAssemblyPath) { ProjectContextLoader.ToolsAssemblyPath = toolsAssemblyPath; ProjectContextLoader.SetupAssemblyResolution(); }