public void CopyFile(string source, string destination) { StackTrace st = new StackTrace(true); Path origin = null; foreach (var sf in st.GetFrames()) { var sourceFile = sf.GetFileName(); if (String.IsNullOrEmpty(sourceFile)) { continue; } var testOrigin = Path.Get(sourceFile).Parent.Combine(source); if (testOrigin.Exists) { origin = testOrigin; break; } } if (origin == null) { throw new FileNotFoundException("File not found: " + source); } var target = _tempSite.Combine(destination); Directory.CreateDirectory(target.DirectoryName); File.Copy(origin, target); }
public static Path GetRelativePath(this Path path, Path basePath) { if (path.Equals(basePath)) { return(Path.Get(".")); } if (path.Parent.Equals(basePath)) { return(path.FileName); } return(path.Parent.GetRelativePath(basePath).Combine(path.FileName)); }
public void Initialize(string templateName, string virtualDirectory, DynamicCompilationOption dynamicCompilationOption) { var stopwatch = new Stopwatch(); stopwatch.Start(); var baseDir = Path.Get(AppDomain.CurrentDomain.BaseDirectory); _tempSite = _orchardTemp.Combine(System.IO.Path.GetRandomFileName()); try { _tempSite.Delete(); } catch { } // Trying the two known relative paths to the Orchard.Web directory. // The second one is for the target "spec" in orchard.proj. _orchardWebPath = baseDir; while (!_orchardWebPath.Combine("Orchard.proj").Exists&& _orchardWebPath.Parent != null) { _orchardWebPath = _orchardWebPath.Parent; } _orchardWebPath = _orchardWebPath.Combine("src").Combine("Orchard.Web"); Log("Initialization of ASP.NET host for template web site \"{0}\":", templateName); Log(" Source location: \"{0}\"", _orchardWebPath); Log(" Temporary location: \"{0}\"", _tempSite); _knownModules = _orchardWebPath.Combine("Modules").Directories.Where(d => d.Combine("module.txt").Exists).Select(d => d.FileName).ToList(); //foreach (var filename in _knownModules) // Log("Available Module: \"{0}\"", filename); _knownThemes = _orchardWebPath.Combine("Themes").Directories.Where(d => d.Combine("theme.txt").Exists).Select(d => d.FileName).ToList(); //foreach (var filename in _knownThemes) // Log("Available Theme: \"{0}\"", filename); _knownBinAssemblies = _orchardWebPath.Combine("bin").GetFiles("*.dll").Select(f => f.FileNameWithoutExtension); //foreach (var filename in _knownBinAssemblies) // Log("Assembly in ~/bin: \"{0}\"", filename); Log("Copy files from template \"{0}\"", templateName); baseDir.Combine("Hosting").Combine(templateName) .DeepCopy(_tempSite); if (dynamicCompilationOption != DynamicCompilationOption.Enabled) { var sourceConfig = baseDir.Combine("Hosting").Combine("TemplateConfigs"); var siteConfig = _tempSite.Combine("Config"); switch (dynamicCompilationOption) { case DynamicCompilationOption.Disabled: File.Copy(sourceConfig.Combine("DisableDynamicCompilation.HostComponents.config"), siteConfig.Combine("HostComponents.config")); break; case DynamicCompilationOption.Force: File.Copy(sourceConfig.Combine("ForceDynamicCompilation.HostComponents.config"), siteConfig.Combine("HostComponents.config")); break; } } Log("Copy binaries of the \"Orchard.Web\" project"); _orchardWebPath.Combine("bin") .ShallowCopy("*.dll", _tempSite.Combine("bin")) .ShallowCopy("*.pdb", _tempSite.Combine("bin")); Log("Copy SqlCe native binaries"); if (_orchardWebPath.Combine("bin").Combine("x86").IsDirectory) { _orchardWebPath.Combine("bin").Combine("x86") .DeepCopy("*.*", _tempSite.Combine("bin").Combine("x86")); } if (_orchardWebPath.Combine("bin").Combine("amd64").IsDirectory) { _orchardWebPath.Combine("bin").Combine("amd64") .DeepCopy("*.*", _tempSite.Combine("bin").Combine("amd64")); } // Copy binaries of this project, so that remote execution of lambda // can be achieved through serialization to the ASP.NET appdomain // (see Execute(Action) method) Log("Copy Orchard.Specflow test project binaries"); baseDir.ShallowCopy( path => IsSpecFlowTestAssembly(path) && !_tempSite.Combine("bin").Combine(path.FileName).Exists, _tempSite.Combine("bin")); Log("Copy Orchard recipes"); _orchardWebPath.Combine("Modules").Combine("Orchard.Setup").Combine("Recipes").DeepCopy("*.xml", _tempSite.Combine("Modules").Combine("Orchard.Setup").Combine("Recipes")); StartAspNetHost(virtualDirectory); Log("ASP.NET host initialization completed in {0} sec", stopwatch.Elapsed.TotalSeconds); }