public void SetUp() { originalDirectory = Environment.CurrentDirectory; var root = new Uri(typeof(BuildFixture).Assembly.CodeBase).LocalPath; while (!root.EndsWith("source") && !root.EndsWith("source\\")) { root = Path.GetFullPath(Path.Combine(root, "..\\")); } Environment.CurrentDirectory = Path.Combine(root, "Samples"); Clean("Sample.ConsoleApp\\bin"); Clean("Sample.WebApp\\bin"); Clean("Sample.WebAppWithSpec\\bin"); }
static void Main(string[] args) { CTHReader cth = new CTHReader(); if (ConfigurationManager.AppSettings["passwordPrompt"] == "true") { Console.WriteLine("Please provide user name to connect to the site:"); cth.UserName = Console.ReadLine(); Console.WriteLine("Please provide the password:"******"outputFilePrefix"]; string outputLocation = ConfigurationManager.AppSettings["outputLocation"]; string siteUrl = new Uri(ConfigurationManager.AppSettings["siteUrl"]).ToString(); if (siteUrl.EndsWith("/")) { siteUrl = siteUrl.Substring(0, siteUrl.Length - 1); } Console.WriteLine(cth.ProcessCTH(siteUrl, outputLocation, CTHReader.CTHQueryMode.CTHAndSiteColumns)); //doit(); //tidyUpXMLDoc(); //queryXMLProcess(); }
public static string GetLayoutHtml(CommonViewModel model, string page, IEnumerable<string> stylesheets, IEnumerable<string> scripts) { if (model == null) throw new ArgumentNullException("model"); if (page == null) throw new ArgumentNullException("page"); if (stylesheets == null) throw new ArgumentNullException("stylesheets"); if (scripts == null) throw new ArgumentNullException("scripts"); var applicationPath = new Uri(model.SiteUrl).AbsolutePath; if (applicationPath.EndsWith("/")) applicationPath = applicationPath.Substring(0, applicationPath.Length - 1); var pageUrl = "assets/app." + page + ".html"; var json = Newtonsoft.Json.JsonConvert.SerializeObject(model, Newtonsoft.Json.Formatting.None, new Newtonsoft.Json.JsonSerializerSettings() { ContractResolver = new Newtonsoft.Json.Serialization.CamelCasePropertyNamesContractResolver() }); var additionalStylesheets = BuildTags("<link href='{0}' rel='stylesheet'>", applicationPath, stylesheets); var additionalScripts = BuildTags("<script src='{0}'></script>", applicationPath, scripts); return LoadResourceString("Thinktecture.IdentityServer.Core.Views.Embedded.Assets.app.layout.html", new { siteName = model.SiteName, applicationPath, pageUrl, model = json, stylesheets = additionalStylesheets, scripts = additionalScripts }); }
private string MakeURLPretty(string url) { var lowURL = url.ToLower(); if (lowURL.StartsWith("http://www")) { // Everything's good. } else if (lowURL.StartsWith("http://")) { var s = url.Split(new string[] { "//" }, StringSplitOptions.None); url = s[0] + "//www." + s[1]; } else if (lowURL.StartsWith("www")) { url = "http://" + url; } else { url = "http://www." + url; } url = new Uri(url).ToString(); if (url.EndsWith("/")) { url = url.Substring(0, url.Length - 1); } return url; }
public DetergentHttpListener( string uriPrefix, string applicationPath, IDetergentHttpHandler detergentHttpHandler) { if (uriPrefix == null) throw new ArgumentNullException("uriPrefix"); if (applicationPath == null) throw new ArgumentNullException("applicationPath"); if (detergentHttpHandler == null) throw new ArgumentNullException("detergentHttpHandler"); this.uriPrefix = uriPrefix; this.applicationPath = applicationPath; this.detergentHttpHandler = detergentHttpHandler; httpListener = new HttpListener(); applicationRootUrl = new Uri(new Uri(uriPrefix), applicationPath).ToString(); if (false == applicationRootUrl.EndsWith("/", StringComparison.OrdinalIgnoreCase)) applicationRootUrl = applicationRootUrl + '/'; httpListener.Prefixes.Add(applicationRootUrl); DumpDiagnostics(); httpListener.Start(); IAsyncResult result = httpListener.BeginGetContext(WebRequestCallback, httpListener); }
public static string GetBaseUrl(this HttpRequestMessage request, string host = null) { if (host.IsMissing()) { host = "https://" + request.Headers.Host; } var baseUrl = new Uri(new Uri(host), request.GetRequestContext().VirtualPathRoot).AbsoluteUri; if (!baseUrl.EndsWith("/")) baseUrl += "/"; return baseUrl; }
public static string GetBaseUrl(this IDictionary<string, object> env, string host = null) { var ctx = new OwinContext(env); var request = ctx.Request; if (host.IsMissing()) { host = "https://" + request.Host.Value; } var baseUrl = new Uri(new Uri(host), ctx.Request.PathBase.Value).AbsoluteUri; if (!baseUrl.EndsWith("/")) baseUrl += "/"; return baseUrl; }
private static void WikiPageImplementation(Web web, string wikiPageLibraryName, string wikiPageName, out string wikiPageUrl, out List pageLibrary, out string newWikiPageUrl, out File currentPageFile, out string pathAndQuery) { if (string.IsNullOrEmpty(wikiPageLibraryName)) { throw (wikiPageLibraryName == null) ? new ArgumentNullException("wikiPageLibraryName") : new ArgumentException(CoreResources.Exception_Message_EmptyString_Arg, "wikiPageLibraryName"); } if (string.IsNullOrEmpty(wikiPageName)) { throw (wikiPageName == null) ? new ArgumentNullException("wikiPageName") : new ArgumentException(CoreResources.Exception_Message_EmptyString_Arg, "wikiPageName"); } wikiPageUrl = ""; pageLibrary = web.Lists.GetByTitle(wikiPageLibraryName); web.Context.Load(web, w => w.Url); web.Context.Load(pageLibrary.RootFolder, f => f.ServerRelativeUrl); web.Context.ExecuteQueryRetry(); var pageLibraryUrl = pageLibrary.RootFolder.ServerRelativeUrl; newWikiPageUrl = pageLibraryUrl + "/" + wikiPageName; currentPageFile = web.GetFileByServerRelativeUrl(newWikiPageUrl); web.Context.Load(currentPageFile, f => f.Exists); web.Context.ExecuteQueryRetry(); pathAndQuery = new Uri(web.Url).PathAndQuery; if (!pathAndQuery.EndsWith("/")) { pathAndQuery = pathAndQuery + "/"; } }
/// <summary> /// Creates the repository. /// </summary> /// <param name="repositoryName">Name of the repository.</param> /// <returns></returns> public static string CreateRepository(string repositoryName) { var sb = new StringBuilder(); var repoPath = HostSettingManager.Get(HostSettingNames.RepositoryRootPath) + repositoryName; var repoCheckoutPath = Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData) + Path.DirectorySeparatorChar + Guid.NewGuid().ToString(); var repoUrl = new Uri(repoPath).AbsoluteUri; if (!repoUrl.EndsWith("/")) repoUrl += "/"; try { Directory.CreateDirectory(repoPath); Directory.CreateDirectory(repoCheckoutPath); sb.AppendLine(RunCommand("svnadmin", "create \"" + repoPath + "\"")); sb.AppendLine(RunCommand("svn", "mkdir \"" + repoUrl + "trunk\" \"" + repoUrl + "branches\" \"" + repoUrl + "tags\" \"" + repoUrl + "trunk/doc\" \"" + repoUrl + "trunk/src\" -m \"Creating initial directories\"")); sb.AppendLine(); sb.AppendLine(RunCommand("svn", "checkout \"" + repoUrl + "\" \"" + repoCheckoutPath + "\"")); sb.AppendLine(); // Add Issue tracker properties var url = HostSettingManager.Get(HostSettingNames.DefaultUrl).Trim(); if (!url.EndsWith("/")) url += "/"; //\[?([A-Za-z]{3}-\d+)[\]:]{0,2}(\s((resolved)[,\s]+(fixed|invalid)?)|\s+(open|in progress)?)? //this regex locks up TortoiseSVN sb.AppendLine(RunCommand("svn", "propset -R bugtraq:logregex \"\\[?([A-Za-z]{3}-\\d+)\\]?.+\" \"" + repoCheckoutPath + "\"")); sb.AppendLine(); sb.AppendLine(RunCommand("svn", "propset -R bugtraq:label \"Issue Tracker Id:\" \"" + repoCheckoutPath + "\"")); sb.AppendLine(); sb.AppendLine(RunCommand("svn", "propset -R bugtraq:url \"" + url + "Issues/IssueDetail.aspx?id=%BUGID%\" \"" + repoCheckoutPath + "\"")); sb.AppendLine(); //sb.AppendLine(RunCommand("svn", "propset -R bugtraq:message \"Issue Tracker Id: %BUGID%\" \"" + repoCheckoutPath + "\"")); //sb.AppendLine(); sb.AppendLine(RunCommand("svn", "propset -R bugtraq:number \"false\" \"" + repoCheckoutPath + "\"")); sb.AppendLine(); sb.AppendLine(RunCommand("svn", "propset -R bugtraq:warnifnoissue \"false\" \"" + repoCheckoutPath + "\"")); sb.AppendLine(); sb.AppendLine(RunCommand("svn", "propset -R bugtraq:append \"false\" \"" + repoCheckoutPath + "\"")); sb.AppendLine(); sb.AppendLine(RunCommand("svn", "commit -m \"Added Issue Tracker properties to the repository\" \"" + repoCheckoutPath + "\"")); // Add post-commit for the integration. if (!repoPath.EndsWith(Path.DirectorySeparatorChar.ToString())) repoPath += Path.DirectorySeparatorChar; if (!String.IsNullOrEmpty(HostSettingManager.Get(HostSettingNames.SvnHookPath))) { using (var sw = File.CreateText(repoPath + "hooks" + Path.DirectorySeparatorChar + "post-commit.bat")) sw.WriteLine(HostSettingManager.Get(HostSettingNames.SvnHookPath) + @" post-commit %1 %2"); } return sb.ToString(); } catch (Exception ex) { if (Log.IsErrorEnabled) Log.Error("Subversion Repository Creation Error", ex); //TOOD: Localize throw; } finally { DeleteDirectory(repoCheckoutPath); } }
/// <summary> /// Adds the template reference to the IAssetReferenceService /// </summary> public override void Execute() { EnvDTE.DTE dte = (EnvDTE.DTE)GetService(typeof(EnvDTE.DTE)); IAssetReferenceService referenceService = (IAssetReferenceService)GetService(typeof(IAssetReferenceService)); object item = DteHelper.GetTarget(dte); if (item == null) { MessageBox.Show("There is no valid target to reference the template"); return; } templateFilename = new Uri(templateFilename).LocalPath; VsBoundReference vsTarget = null; if (item is Project) { vsTarget = new ProjectReference(templateFilename, (Project)item); } else if (item is Solution) { vsTarget = new SolutionReference(templateFilename, (Solution)item); } else if (item is ProjectItem) { vsTarget = new ProjectItemReference(templateFilename, (ProjectItem)item); } else if (item is EnvDTE80.SolutionFolder) { vsTarget = new ProjectReference(templateFilename, ((EnvDTE80.SolutionFolder)item).Parent); } if (item == null || vsTarget == null) { MessageBox.Show(string.Format( CultureInfo.CurrentCulture, "Target {0} specified for reference to asset {1} doesn't exist.", "target", templateFilename)); return; } if (!File.Exists(templateFilename) || !templateFilename.EndsWith(".vstemplate", StringComparison.InvariantCultureIgnoreCase)) { MessageBox.Show(string.Format( CultureInfo.CurrentCulture, "The filename specified for the template \"{0}\" does not exist.", templateFilename)); return; } newReference = new BoundTemplateReference(templateFilename, vsTarget); referenceService.Add(newReference); MessageBox.Show("The new reference was successfully added", "New Reference", MessageBoxButtons.OK, MessageBoxIcon.Information); }
/// <summary> /// Returns absolute path of a given directory, always /// ending with '/'. /// </summary> public static string NormalizeDirectoryPath(string path) { string absPath = new Uri(path).LocalPath; if (!absPath.EndsWith("\\")) { absPath += "\\"; } return absPath; }
/// <summary> /// Determines whether this instance can check the availability of the link on the specified service. /// </summary> /// <param name="url">The link to check.</param> /// <returns> /// <c>true</c> if this instance can check the specified service; otherwise, <c>false</c>. /// </returns> public override bool CanCheck(string url) { var host = new Uri(url).Host; return host.EndsWith("ul.to") || host.EndsWith("uploaded.to"); }
/// <summary> /// Determines whether this instance can check the availability of the link on the specified service. /// </summary> /// <param name="url">The link to check.</param> /// <returns> /// <c>true</c> if this instance can check the specified service; otherwise, <c>false</c>. /// </returns> public override bool CanCheck(string url) { var host = new Uri(url).Host; return host.EndsWith("fp.io") || host.EndsWith("filepost.com"); }
private bool IsWhitelisted(RemoteRequestEventArgs request) { var rr = c.getNode("remotereader"); var domain = new Uri(request.RemoteUrl).Host; if (rr == null || string.IsNullOrEmpty(domain)) return false; foreach (Node n in rr.childrenByName("allow")) { bool onlyWhenSigned = NameValueCollectionExtensions.Get(n.Attrs, "onlyWhenSigned", false); if (onlyWhenSigned && !request.SignedRequest) continue; bool hostMatches = false, regexMatches = false; string host = n.Attrs.Get("domain"); if (!string.IsNullOrEmpty(host)) { if (host.StartsWith("*.", StringComparison.OrdinalIgnoreCase)) hostMatches = domain.EndsWith(host.Substring(1), StringComparison.OrdinalIgnoreCase); else hostMatches = domain.Equals(host, StringComparison.OrdinalIgnoreCase); if (!hostMatches) continue;//If any filter doesn't match, skip rule } string regex = n.Attrs.Get("regex"); if (!string.IsNullOrEmpty(regex)) { var r = new Regex("^" + regex + "$", RegexOptions.CultureInvariant | RegexOptions.IgnoreCase | RegexOptions.Singleline); regexMatches = r.IsMatch(request.RemoteUrl); if (!regexMatches) continue;//If any filter doesn't match, skip rule } //If all specified filters match, allow the request. //This *is* supposed to be || not &&, because we already deal with non-matching filters via 'continue'. if (hostMatches || regexMatches) return true; } return false; }
/// <summary> /// Returns the correct root url /// </summary> /// <param name="req"></param> /// <param name="apiName"></param> /// <param name="apiVersion"></param> /// <returns></returns> protected static string GetRootUrl(HttpRequestMessage req, string apiName, string apiVersion) { var url = new Uri(req.RequestUri, req.GetRequestContext().VirtualPathRoot).ToString(); url = url.EndsWith("/") ? url.Substring(0, url.Length - 1) : url; return url; }
/// <summary> /// Builds the model. /// </summary> /// <param name="model">The model.</param> /// <param name="page">The page.</param> /// <param name="stylesheets">The stylesheets.</param> /// <param name="scripts">The scripts.</param> /// <returns></returns> /// <exception cref="System.ArgumentNullException"> /// model /// or /// stylesheets /// or /// scripts /// </exception> protected object BuildModel(CommonViewModel model, string page, IEnumerable<string> stylesheets, IEnumerable<string> scripts) { if (model == null) throw new ArgumentNullException("model"); if (stylesheets == null) throw new ArgumentNullException("stylesheets"); if (scripts == null) throw new ArgumentNullException("scripts"); var applicationPath = new Uri(model.SiteUrl).AbsolutePath; if (applicationPath.EndsWith("/")) applicationPath = applicationPath.Substring(0, applicationPath.Length - 1); var json = Newtonsoft.Json.JsonConvert.SerializeObject(model, Newtonsoft.Json.Formatting.None, settings); var additionalStylesheets = BuildTags("<link href='{0}' rel='stylesheet'>", applicationPath, stylesheets); var additionalScripts = BuildTags("<script src='{0}'></script>", applicationPath, scripts); return new { siteName = Microsoft.Security.Application.Encoder.HtmlEncode(model.SiteName), applicationPath, model = Microsoft.Security.Application.Encoder.HtmlEncode(json), page, stylesheets = additionalStylesheets, scripts = additionalScripts }; }
object BuildModel(CommonViewModel model, string page, ICollection<string> stylesheets, ICollection<string> scripts) { if (model == null) throw new ArgumentNullException("model"); if (stylesheets == null) throw new ArgumentNullException("stylesheets"); if (scripts == null) throw new ArgumentNullException("scripts"); var applicationPath = new Uri(model.SiteUrl).AbsolutePath; if (applicationPath.EndsWith("/")) applicationPath = applicationPath.Substring(0, applicationPath.Length - 1); var json = Newtonsoft.Json.JsonConvert.SerializeObject(model, Newtonsoft.Json.Formatting.None, new Newtonsoft.Json.JsonSerializerSettings() { ContractResolver = new Newtonsoft.Json.Serialization.CamelCasePropertyNamesContractResolver() } ); var additionalStylesheets = BuildTags("<link href='{0}' rel='stylesheet'>", applicationPath, stylesheets); var additionalScripts = BuildTags("<script src='{0}'></script>", applicationPath, scripts); return new { siteName = model.SiteName, applicationPath, model = json, page, stylesheets = additionalStylesheets, scripts = additionalScripts }; }