public PropertyMap(SourceDetails details) { this.details = details; }
public String Convert(String source, SourceDetails details) { if(details.Type == SourceType.ANNOTATION) { Pattern pattern = Pattern.compile("^(\\s+)public\\s+class\\s+[a-zA-Z]+.*$"); List<String> lines = stripLines(source); StringWriter writer = new StringWriter(); Map<String, String> attributes = details.getAttributes(); for(String line : lines) { Matcher matcher = pattern.matcher(line); if(matcher.matches()) { String indent = matcher.group(1); writer.append(line); writer.append("\n"); for(String attribute : attributes.keySet()){ String type = attributes.get(attribute); writer.append(indent); writer.append(" private "); writer.append(type); writer.append(" "); writer.append(attribute); writer.append(";\n"); } } else { writer.append(line); writer.append("\n"); } } return writer.ToString(); } return source; }
public String Convert(String source, SourceDetails details) { return source.replaceAll("\r\n", "\n").replaceAll("\r", "\n"); }
public String Convert(String source, SourceDetails details) { Pattern pattern = Pattern.compile("^(\\s+)public\\s+(.*)\\s+([a-zA-Z]+)\\(\\)\\s+default\\s+.+;.*$"); List<String> lines = stripLines(source); StringWriter writer = new StringWriter(); for(String line : lines) { Matcher matcher = pattern.matcher(line); if(matcher.matches()) { String indent = matcher.group(1); String type = matcher.group(2); String method = matcher.group(3); String attribute = method.toLowerCase(); details.AddAttribute(type, attribute); writer.append(indent); writer.append("public "); writer.append(type); writer.append(" "); writer.append(ConvertMethod(method, MethodType.NORMAL)); writer.append(" {\n"); writer.append(indent); writer.append(" get {\n"); writer.append(indent); writer.append(" return ").append(attribute).append(";\n"); writer.append(indent); writer.append(" }\n"); writer.append(indent); writer.append(" set {\n"); writer.append(indent); writer.append(" ").append(attribute).append(" = value;\n"); writer.append(indent); writer.append(" }\n"); writer.append(indent); writer.append("}\n"); } else { writer.append(line); writer.append("\n"); } } return writer.ToString(); }
/// <summary> /// HTTP request. /// Instantiate the object using an HttpListenerContext. /// </summary> /// <param name="ctx">HttpListenerContext.</param> public HttpRequest(HttpListenerContext ctx) { if (ctx == null) { throw new ArgumentNullException(nameof(ctx)); } if (ctx.Request == null) { throw new ArgumentNullException(nameof(ctx.Request)); } ListenerContext = ctx; Keepalive = ctx.Request.KeepAlive; ContentLength = ctx.Request.ContentLength64; Useragent = ctx.Request.UserAgent; ContentType = ctx.Request.ContentType; _Uri = new Uri(ctx.Request.Url.ToString().Trim()); ThreadId = Thread.CurrentThread.ManagedThreadId; TimestampUtc = DateTime.Now.ToUniversalTime(); ProtocolVersion = "HTTP/" + ctx.Request.ProtocolVersion.ToString(); Source = new SourceDetails(ctx.Request.RemoteEndPoint.Address.ToString(), ctx.Request.RemoteEndPoint.Port); Destination = new DestinationDetails(ctx.Request.LocalEndPoint.Address.ToString(), ctx.Request.LocalEndPoint.Port, _Uri.Host); Method = (HttpMethod)Enum.Parse(typeof(HttpMethod), ctx.Request.HttpMethod, true); Url = new UrlDetails(ctx.Request.Url.ToString().Trim(), ctx.Request.RawUrl.ToString().Trim()); Query = new QueryDetails(Url.Full); Headers = new Dictionary <string, string>(); for (int i = 0; i < ctx.Request.Headers.Count; i++) { string key = ctx.Request.Headers.GetKey(i); string val = ctx.Request.Headers.Get(i); Headers = AddToDict(key, val, Headers); } foreach (KeyValuePair <string, string> curr in Headers) { if (String.IsNullOrEmpty(curr.Key)) { continue; } if (String.IsNullOrEmpty(curr.Value)) { continue; } if (curr.Key.ToLower().Equals("transfer-encoding")) { if (curr.Value.ToLower().Contains("chunked")) { ChunkedTransfer = true; } if (curr.Value.ToLower().Contains("gzip")) { Gzip = true; } if (curr.Value.ToLower().Contains("deflate")) { Deflate = true; } } } Data = ctx.Request.InputStream; }
public String Convert(String source, SourceDetails details) { Pattern withAttributes = Pattern.compile("(\\s+)@([a-zA-Z]+)\\((.*)\\).*"); Pattern withoutAttributes = Pattern.compile("(\\s+)@([a-zA-Z]+).*"); List<String> lines = stripLines(source); StringWriter writer = new StringWriter(); for(String line : lines) { Matcher with = withAttributes.matcher(line); if(with.matches()) { String indent = with.group(1); String name = with.group(2); String signature = with.group(3); writer.append(indent); writer.append("["); writer.append(name); if(signature != null && !signature.equals("")) { writer.append("("); String[] attributes = signature.split("\\s*,\\s*"); String separator = ""; for(String attribute : attributes) { writer.append(separator); writer.append(ConvertMethod(attribute, MethodType.NORMAL)); separator = ", "; } writer.append(")"); } writer.append("]\n"); } else { Matcher without = withoutAttributes.matcher(line); if(without.matches()) { String indent = without.group(1); String name = without.group(2); writer.append(indent); writer.append("["); writer.append(name); writer.append("]\n"); } else { writer.append(line); writer.append("\n"); } } } return writer.ToString(); }
public void PopulateFrom(SourceDetails details, String field, Map<String, String> substitutes) { List<MethodSignature> methods = details.Methods; for(MethodSignature originalMethod : details.Methods) { if(originalMethod.type == MethodType.GET) { substitutes.put(originalMethod.name+"\\(\\)", ConvertMethod(originalMethod.name, originalMethod.type)); } else if(originalMethod.type == MethodType.SET) { substitutes.put(originalMethod.name+"\\([a-zA-Z\\s]+\\)", ConvertMethod(originalMethod.name, originalMethod.type) + " = "+originalMethod.value); } else { substitutes.put(originalMethod.name+"\\(", ConvertMethod(originalMethod.name, MethodType.NORMAL)+"\\("); } } if(field != null && !field.equals("")) { for(MethodSignature originalMethod : methods) { String originalToken = String.format("%s.%s", field, originalMethod.name); if(originalMethod.type == MethodType.GET) { String token = String.format("%s.%s", field, ConvertMethod(originalMethod.name, originalMethod.type)); substitutes.put(originalToken+"\\(\\)", token); } else if(originalMethod.type == MethodType.SET) { String token = String.format("%s.%s = %s", field, ConvertMethod(originalMethod.name, originalMethod.type), originalMethod.value); substitutes.put(originalToken+"\\([a-zA-Z\\s]+\\)", token); } else { String token = String.format("%s.%s\\(", field, ConvertMethod(originalMethod.name, MethodType.NORMAL)); substitutes.put(originalToken+"\\(", token); } } } }
public String Convert(String source, SourceDetails details) { Pattern pattern = Pattern.compile("^import\\s+([a-zA-Z\\.]*)\\s*;.*$"); List<String> lines = stripLines(source); StringWriter writer = new StringWriter(); for(String line : lines) { Matcher matcher = pattern.matcher(line); if(matcher.matches()) { String importClass = matcher.group(1); details.AddImport(importClass); } else { writer.append(line); writer.append("\n"); } } return writer.ToString(); }
public String Convert(String source, SourceDetails details) { Pattern pattern = Pattern.compile("^(.+) class (.+)\\: System.Attribute { List<String> lines = stripLines(source); StringWriter writer = new StringWriter(); for(String line : lines) { Matcher matcher = pattern.matcher(line); if(matcher.matches()) { String start = matcher.group(1); String type = matcher.group(2); writer.append(start); writer.append(" class "); writer.append(type); writer.append(": System.Attribute {\n"); } else { writer.append(line); writer.append("\n"); } } return writer.ToString(); }
public Map<String, String> calculateSubstututions(SourceDetails details, SourceProject project) { Map<String, String> substitutes = new HashMap<String, String>(); for(String field : details.getFields().keySet()) { String type = details.getFields().get(field); SourceDetails fieldDetails = project.GetDetails(type); if(fieldDetails != null) { PopulateFrom(fieldDetails, field, substitutes); } } PopulateFrom(details, null, substitutes); return substitutes; }
public void License(SourceDetails details, Iterator<String> lines, StringWriter writer, String line) { Pattern comment = Pattern.compile("^(\\s*)\\*.*$"); writer.append(line.replaceAll("\\/\\*", "//")); writer.append("\n"); while(lines.hasNext()) { String nextLine = lines.next(); nextLine = nextLine.substring(1); if(nextLine.matches("^\\s*\\*\\/")) { writer.append(nextLine.replaceAll("\\*\\/", "//")); writer.append("\n"); return; } Matcher matcher = comment.matcher(nextLine); if(matcher.matches()) { if(nextLine.matches(".*\\.java.*")) { nextLine = nextLine.replaceAll("\\.java", ".cs"); } writer.append(matcher.group(1)); writer.append(nextLine.replaceAll("^\\s*\\*", "//")); writer.append("\n"); }else { throw new IllegalStateException("Comment does not end well '" + nextLine+"' in file "+details.Source.getCanonicalPath()); } } }
public String Convert(String source, SourceDetails details) { List<String> lines = stripLines(source); Iterator<String> iterator = lines.iterator(); StringWriter writer = new StringWriter(); bool licenseDone = false; while(iterator.hasNext()) { String line = iterator.next(); if(!licenseDone && line.matches("\\s*\\/\\*")) { writer.append("#region License\n"); License(details, iterator, writer, line); writer.append("#endregion\n"); licenseDone = true; } else { if(!line.matches("^\\s*$")) { licenseDone = true; // no license found } writer.append(line); writer.append("\n"); } } return writer.ToString(); }
public String Convert(String source, SourceDetails details) { List<String> lines = stripLines(source); Iterator<String> iterator = lines.iterator(); StringWriter writer = new StringWriter(); while(iterator.hasNext()) { String line = iterator.next(); if(line.matches("\\s*\\/\\*\\*")) { Comment(iterator, writer, line); } else { writer.append(line); writer.append("\n"); } } return writer.ToString(); }
public String Convert(String source, SourceDetails details) { List<String> lines = stripLines(source); for(String line : lines) { if(line.matches("^import.*")) { line = line.trim(); for(String importName : USING.keySet()) { if(line.matches(importName)) { importName = USING.get(importName); details.AddUsing(importName); break; } } } } return source; }
public abstract String Convert(String source, SourceDetails details, SourceProject project);
public String Convert(String source, SourceDetails details) { Pattern pattern = Pattern.compile("^package\\s+([a-zA-Z\\.]*)\\s*;.*"); List<String> lines = stripLines(source); StringWriter writer = new StringWriter(); bool importsDone = false; for(String line : lines) { if(!importsDone) { Matcher matcher = pattern.matcher(line); if(matcher.matches()) { String packageName = matcher.group(1); writer.append("\n#region Using directives\n"); for(String using : details.Using) { writer.append(using); writer.append("\n"); } writer.append("\n#endregion\n"); details.Package = packageName; importsDone = true; } } writer.append(line); writer.append("\n"); } return writer.ToString(); }
public String Convert(String source, SourceDetails details, SourceProject project) { List<String> lines = stripLines(source); Map<String, String> substitutions = calculateSubstututions(details, project); StringWriter writer = new StringWriter(); for(String line : lines) { for(String substitute : substitutions.keySet()) { line = line.replaceAll(substitute, substitutions.get(substitute)); } writer.append(line); writer.append("\n"); } return writer.ToString(); }
public String Convert(String source, SourceDetails details) { List<String> lines = stripLines(source); StringWriter writer = new StringWriter(); String indent = ""; for(String line : lines) { line = line.replaceAll("\\s*$", ""); writer.append(indent); if(indent == null || indent.equals("")){ for(String packageName : NAMESPACE.keySet()) { if(line.matches(packageName + ".*")) { indent = INDENT; line = NAMESPACE.get(packageName); break; } } } writer.append(line); writer.append("\n"); } writer.append("}"); return writer.ToString(); }
public String Convert(String source, SourceDetails details, SourceProject project) { if(details.Type == SourceType.INTERFACE) { Pattern pattern = Pattern.compile("^(\\s+)public\\s+(.*\\)\\s*;.*$)"); List<String> lines = stripLines(source); StringWriter writer = new StringWriter(); for(String line : lines) { Matcher matcher = pattern.matcher(line); if(matcher.matches()) { String indent = matcher.group(1); String remainder = matcher.group(2); writer.append(indent); writer.append(remainder); writer.append("\n"); } else { writer.append(line); writer.append("\n"); } } return writer.ToString(); } return source; }
private void Build() { #region Initial-Values TimestampUtc = DateTime.Now.ToUniversalTime(); Source = new SourceDetails(Common.IpFromIpPort(_IpPort), Common.PortFromIpPort(_IpPort)); ThreadId = Thread.CurrentThread.ManagedThreadId; #endregion #region Convert-to-String-List string[] headers = _RequestHeader.Split(new string[] { "\r\n", "\n" }, StringSplitOptions.RemoveEmptyEntries); #endregion #region Process-Each-Line for (int i = 0; i < headers.Length; i++) { if (i == 0) { #region First-Line string[] requestLine = headers[i].Trim().Trim('\0').Split(' '); if (requestLine.Length < 3) { throw new ArgumentException("Request line does not contain at least three parts (method, raw URL, protocol/version)."); } Method = (HttpMethod)Enum.Parse(typeof(HttpMethod), requestLine[0], true); Url = new UrlDetails(requestLine[1]); Query = new QueryDetails(requestLine[1]); ProtocolVersion = requestLine[2]; #endregion } else { #region Subsequent-Line string[] headerLine = headers[i].Split(':'); if (headerLine.Length == 2) { string key = headerLine[0].Trim(); string val = headerLine[1].Trim(); if (String.IsNullOrEmpty(key)) { continue; } string keyEval = key.ToLower(); if (keyEval.Equals("keep-alive")) { Keepalive = Convert.ToBoolean(val); } else if (keyEval.Equals("user-agent")) { Useragent = val; } else if (keyEval.Equals("content-length")) { ContentLength = Convert.ToInt32(val); } else if (keyEval.Equals("content-type")) { ContentType = val; } Headers = Common.AddToDict(key, val, Headers); } #endregion } } #endregion #region Payload _DataStream = _Stream; #endregion }
public void ScanResourceInstance(fm3.Resource resource, string source) { SourceDetails sourceDetail; if (!Sources.ContainsKey(source)) { sourceDetail = new SourceDetails() { Source = source, ResourceName = resource.TypeName, InstanceCount = 1 }; Sources.Add(source, sourceDetail); } else { sourceDetail = Sources[source]; sourceDetail.InstanceCount++; } this.ResourceName = resource.TypeName; // Prepare the property list from the Structure Definition if (!_properties.ContainsKey(ResourceName)) { var sourceSD = new Hl7.Fhir.Specification.Source.ZipSource(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "specification.zip")); var instSD = sourceSD.ResolveByUri("http://hl7.org/fhir/StructureDefinition/" + resource.TypeName) as fm3.StructureDefinition; if (instSD == null) { Console.WriteLine($"Unable to load the StructureDefinition for {resource.TypeName}"); return; } foreach (var ed in instSD.Differential.Element) { if (!_properties.ContainsKey(ed.Path)) { _properties.Add(ed.Path, new ResultItem() { PropertyName = ed.Path, UsageCount = 0, FromStructureDef = true }); } } } if (_properties.ContainsKey(ResourceName)) { _properties[ResourceName].UsageCount++; } // Now process this actual instance var results = stu3.Hl7.Fhir.FhirPath.ElementNavFhirExtensions.Select(resource, "descendants().element_def_path()"); foreach (var item in results) { if (item is fm3.FhirString str) { string pname = $"{str.Value}"; if (_properties.ContainsKey(pname)) { _properties[pname].UsageCount++; } else { // don't count props not in the differential // _properties.Add(pname, new ResultItem() { PropertyName = pname, UsageCount = 1 }); } } } }