// Adds assemblies with relative paths into the XAP file private static void AddAssemblies(ZipArchive zip, string dir, IList <Uri> assemblyLocations) { foreach (Uri uri in assemblyLocations) { if (IsPathRooted(uri)) { continue; } string targetPath = uri.OriginalString; string localPath = Path.Combine(dir, targetPath); if (!File.Exists(localPath)) { localPath = Chiron.TryGetAssemblyPath(targetPath); if (localPath == null) { throw new ApplicationException("Could not find assembly: " + uri); } } zip.CopyFromFile(localPath, targetPath); // Copy PDBs if available string pdbPath = Path.ChangeExtension(localPath, ".pdb"); string pdbTarget = Path.ChangeExtension(targetPath, ".pdb"); if (File.Exists(pdbPath)) { zip.CopyFromFile(pdbPath, pdbTarget); } } }
bool TryProcessAssemblyRequest(HttpSocket s, string uri) { if (Chiron.UrlPrefix == "") { return(false); } int slash = uri.LastIndexOf('/'); if (slash == -1) { return(false); } // must start with URL prefix if (string.Compare(uri.Substring(0, slash + 1), Chiron.UrlPrefix, StringComparison.OrdinalIgnoreCase) != 0) { return(false); } uri = uri.Substring(slash + 1); // must end with DLL or PDB if (string.Compare(Path.GetExtension(uri), ".dll", StringComparison.OrdinalIgnoreCase) != 0 && string.Compare(Path.GetExtension(uri), ".pdb", StringComparison.OrdinalIgnoreCase) != 0) { return(false); } // get mime type string mimeType = HttpSocket.GetMimeType(uri); if (string.IsNullOrEmpty(mimeType)) { s.WriteErrorResponse(403); return(true); } // see if the file exists in the assembly reference path string path = Chiron.TryGetAssemblyPath(uri); if (path == null) { return(false); } // read the file byte[] body = null; try { body = File.ReadAllBytes(path); } catch (Exception ex) { s.WriteErrorResponse(500, ex.Message + "\r\n" + ex.StackTrace); return(true); } // write the response s.WriteResponse(200, string.Format("Content-type: {0}\r\n", mimeType), body, false); return(true); }
void ProcessRequest(HttpSocket s) { HttpRequestData r = null; string path = null; // reply to unreadable requests if (!s.TryReadRequest(out r)) { s.WriteErrorResponse(400, "Unparsable bad request"); } // deny non-GET requests else if (r.Method != "GET") { s.WriteErrorResponse(405, "Method other than GET"); } // process special commands else if (TryProcessSpecialCommand(s, r.Uri)) { // done } // deny requests that cannot be mapped to disk else if (!TryMapUri(r.Uri, out path)) { s.WriteErrorResponse(404, "URI cannot be mapped to disk"); } // process file requests else if (TryProcessFileRequest(s, r.Uri, path)) { // done } // process directory requests else if (TryProcessDirectoryRequest(s, r.Uri, path)) { // done } // process XAP requests else if (TryProcessXapRequest(s, path)) { // done } // process XAP listing requests else if (TryProcessXapListingRequest(s, r.Uri, path)) { // done } // process requests for files contained in Chiron's localAssemblyPath else if (TryProcessBuildRequest(s, r.Uri)) { // done } else { // not found s.WriteErrorResponse(404, "Resource not found"); } Chiron.Log(s.StatusCode, (r != null && r.Uri != null ? r.Uri : "[unknown]"), s.BytesSent, s.Message); }
public string GetContextAssemblyName() { return(AssemblyName.GetAssemblyName(Chiron.TryGetAssemblyPath(Assemblies[0])).FullName); }