private static Assembly CurrentDomain_AssemblyResolve(object sender, ResolveEventArgs args) { // log.Info(args.Details()); var name = new AssemblyName(args.Name).Name; var fileName = name + ".dll"; var path = hagenDirectory.CatDir(fileName); if (path.IsFile) { goto found; } if (args.RequestingAssembly != null) { path = new LPath(args.RequestingAssembly.Location).Sibling(fileName); if (path.IsFile) { goto found; } } return(null); found: log.Info(path); return(Assembly.LoadFile(path)); }
static internal IList <IPlugin3> GetPlugins(Context context, LPath mainProgramDirectory) { var pluginDirectories = new List <LPath>(); try { pluginDirectories.AddRange(mainProgramDirectory.CatDir("plugin").GetDirectories().ToList()); } catch { } try { var pluginDirectoriesDevelopment = mainProgramDirectory.Parent.Parent.GetDirectories() .Where(_ => _.FileName.Contains("plugin") && !_.FileName.Contains("Test") && !_.FileName.Equals("hagen.plugin")) .Select(_ => _.CatDir("bin")) .Where(_ => _.IsDirectory); pluginDirectories.AddRange(pluginDirectoriesDevelopment); } catch { } log.Info(pluginDirectories.ListFormat()); return(pluginDirectories.SelectMany(_ => LoadPluginDirectory(context, _, mainProgramDirectory)) .Where(_ => _ != null).ToList()); }
public static void CreateFromTemplate(this ITextTransform transform, LPath source, LPath destination) { // Console.WriteLine("{0} -> {1}", source, destination); if (source.IsFile) { destination.EnsureParentDirectoryExists(); if (IsBinaryFile(source)) { source.CopyFile(destination); } else { using (var w = destination.WriteText()) using (var r = source.ReadText()) { transform.Transform(r, w); } } } else { foreach (var i in source.Info.GetChildren()) { transform.CreateFromTemplate(i.FullName, destination.CatDir(transform.Transform(i.Name))); } } }
static LPath CreateMeetingMinutesMarkdownFile(AppointmentItem selectedAppointment) { var chpRoot = new LPath(@"C:\src\chp"); var mdFile = chpRoot.CatDir( "doc", "meetings", $"{selectedAppointment.Start:yyyy-MM-dd} {Sidi.IO.LPath.GetValidFilename(selectedAppointment.Subject)}", "Readme.md"); if (!mdFile.Exists) { mdFile.EnsureParentDirectoryExists(); mdFile.WriteAllText(GetMarkdown(selectedAppointment)); } return(mdFile); }
public void Merge(PathList pathList) { var directories = pathList.Where(x => x.IsDirectory).ToList(); LPath root = directories.First().Parent; foreach (var d in directories) { var temp = GetNonExistingPath(d.Parent.CatDir(LPath.GetRandomFileName())); d.Move(temp); foreach (var c in temp.GetChildren()) { var dest = GetNonExistingPath(root.CatDir(c.FileName)); c.Move(dest); } } }
void Flatten(Operation op, LPath directory) { if (!directory.IsDirectory) { return; } var files = Find.AllFiles(directory) .Select(x => x.FullName).ToList(); foreach (var source in files) { var destination = GetNonExistingPath(directory.CatDir(source.FileName)); source.Move(destination); } op.DeleteEmptyDirectories(directory); }
// assembly loading scheme for plugins: // - first try to load assembly from main hagen directory // - if not found, load from plugin directory static Assembly LoadPluginAssembly(LPath assemblyPath, LPath hagenDirectory) { ResolveEventHandler loader = (s, e) => { log.Info(e.Details()); var name = new AssemblyName(e.Name).Name; var path = hagenDirectory.CatDir(name + ".dll"); log.Info(path); return(Assembly.LoadFile(path)); }; PluginProvider2.hagenDirectory = hagenDirectory; AppDomain.CurrentDomain.AssemblyResolve += CurrentDomain_AssemblyResolve; try { return(Assembly.LoadFile(assemblyPath)); } finally { } }
static async Task Init(LPath destination, string Product, string Company, LPath templateDirectory) { if (destination == null) { throw new ArgumentNullException(nameof(destination)); } if (string.IsNullOrEmpty(Product)) { throw new ArgumentException("message", nameof(Product)); } if (Company == null) { throw new ArgumentNullException(nameof(Company)); } var source = templateDirectory.CatDir("ConsoleExe"); log.InfoFormat("Create project from template {0} in {1}", source, destination); if (!source.IsDirectory) { throw new ArgumentOutOfRangeException(nameof(source), source, "not a directory"); } destination.EnsureDirectoryExists(); if (destination.Children.Any()) { throw new Exception("Cannot create project in non-empty directory"); } var d = new Dictionary <string, string> { { "ProductNamePlaceHolder", Product }, { "CompanyNamePlaceHolder", Company }, { "CopyrightMessagePlaceHolder", String.Format("Copyright {0} by {1}", DateTime.Now.Year, Company) }, { "LicenseHeader", @"This file is part of _ProductName_. ProductNamePlaceHolder is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. ProductNamePlaceHolder is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with hagen. If not, see <http://www.gnu.org/licenses/>. " } }; d["CommentHeader"] = String.Format("{0}\r\n{1}\r\n", d["CopyrightMessagePlaceHolder"], d["LicenseHeader"]); foreach (var k in new[] { "99890FA4-3413-4B88-9561-F16DB96C2F64", "4BFAC30D-938A-404A-9C35-ABD085D3C19D" }) { d[k] = Guid.NewGuid().ToString(); } var transform = new DictionaryTransform(d); transform.CreateFromTemplate(source, destination); destination.Parent.CatDir("packages").EnsureDirectoryExists(); var sn = new ConsoleTool(@"C:\Program Files (x86)\Microsoft SDKs\Windows\v10.0A\bin\NETFX 4.6.1 Tools\sn.exe") { WorkingDirectory = destination }; await sn.Run("-k", "key.snk"); var nuget = new ConsoleTool("nuget") { WorkingDirectory = destination }; await nuget.Run("update", LPath.GetValidFilename(d["ProductNamePlaceHolder"]) + ".sln"); var git = new ConsoleTool("git.exe") { WorkingDirectory = destination }; await git.Run("init"); await git.Run("add", "."); await git.Run("commit", ".", "-m", "Initial version"); var cmd = new ConsoleTool("cmd.exe") { WorkingDirectory = destination }; await cmd.Run("/c", "build.cmd test"); }