public void SendCodeContentsToServer(SourceCodeInfo sourceCode) { foreach (var sourceFile in sourceCode.SourceFiles) { RegisterFile(sourceFile); } }
public SourceCodeInfo GetSourceCodeInfo(string rootDir, string proName) { log.Debug(new { rootDir, proName }); var sourceCodeInfo = new SourceCodeInfo(rootDir); var fullProjPath = Path.Combine(rootDir, proName); List <string> csFiles = new List <string>() { }; try { log.Debug("Attempting to analyze CSPROJ and fetch code files"); csFiles = cSFilesLister.GetCSCodeFiles(fullProjPath); log.InfoFormat("Found {0} CS Code files in this project", csFiles.Count); log.Debug(csFiles.ToArray()); } catch (Exception e) { log.Error("Error in analyzing CSPROJ", e); } foreach (var item in csFiles) { sourceCodeInfo.AddCodeFile(item); } return(sourceCodeInfo); }
/// <summary> /// Initializes a new instance of the <see cref="SourceCodeViewModel"/> class. /// </summary> /// <param name="sourceCode">The source code.</param> /// <param name="className">Name of the class.</param> /// <param name="errorLine">The error line.</param> public SourceCodeViewModel(SourceCodeInfo sourceCode, string className, int errorLine) { SourceCodeInfo = sourceCode; ProcessName = className; ErrorLine = errorLine; Classes = new List<string>(); }
public DssInstructions Parse(SourceCodeInfo sourceInfo) { var instructions = new DssInstructions(); ParseInto(instructions, sourceInfo); return(instructions); }
public static DssInstructions ParseCode(string code) { var dssParser = new DssParser(); var sourceInfo = new SourceCodeInfo("TestCode", code); var instructions = dssParser.Parse(sourceInfo); return(instructions); }
void StoreProjectPaths(SourceCodeInfo sourceCodeInfo, int index) { var projectPaths = Directory.GetFiles(sourceCodeInfo.RootPath, "*.csproj", SearchOption.AllDirectories).Where(s => Regex.IsMatch(s, sourceCodeInfo.ProjectRegex)); IEnumerable <string> paths = projectPaths.Select(s1 => s1 + "|" + GetOutPutPath(s1)); sourceCodeInfo.Count = paths.Count(); Storage.WriteStrings(ProjectPaths, index + "_" + sourceCodeInfo.ProjectRegex, paths.ToArray()); }
public static void LoadLayout(this IApplication application, SourceCodeInfo code) { var parser = application.GetService <AGPMLParser>(); var componentTemplateProvider = application.GetService <ComponentTemplateProvider>(); var template = parser.ParseComponentTemplate(code); componentTemplateProvider.Add(template); }
public static Stylesheet CompileCode(string code) { var expressionExecutor = new ExpressionExecutor(); var dssParser = new DssParser(); var dssCompiler = new DssCompiler(expressionExecutor); var sourceInfo = new SourceCodeInfo("TestCode", code); var instructions = dssParser.Parse(sourceInfo); return(dssCompiler.Compile(instructions)); }
public void AddHooksToSourceCode(SourceCodeInfo sourceCodeInfo) { log.Info(new { sourceCodeInfo.BaseDirPath }); foreach (var sourceFile in sourceCodeInfo.SourceFiles) { var outText = hookInjectionPipeline.AddHooksToSourceFile(sourceFile); sourceFile.UpdateCodeContents(outText); } }
public void AddHooksToSourceCode(SourceCodeInfo sourceCodeInfo) { foreach (var sourceFile in sourceCodeInfo.SourceFiles) { string contents = sourceFile.GetCode(); string fileName = sourceFile.FilePath; string outText = hookInjectionPipeline.AddHooksToSourceFile(fileName, contents); sourceFile.UpdateCodeContents(outText); } }
public void InjectReference(SourceCodeInfo sourceCodeInfo, string projectFileName) { string prdata = sourceCodeInfo.GetContentsOfFileAtRoot(projectFileName); string prPath = @"/Users/rohan/code/codevine-recorder/CodeVineRecorder/CodeVineRecorder.csproj"; string replaceData = string.Format("<ItemGroup><ProjectReference Include=\"{0}\" /></ItemGroup></Project>", prPath); var replacedStr = prdata.Replace("</Project>", replaceData); sourceCodeInfo.SetContentsOfFileAtRoot(projectFileName, replacedStr); }
//[TestMethod] public void RegisterInRails() { SourceCodeInfo sourceCode = new SourceCodeInfo(GitTests.RepoPath); sourceCode.AddCodeFile("ClassA.cs"); sourceCode.AddCodeFile("ClassB.cs"); sourceCode.AddCodeFile("Program.cs"); CodeRegisterer codeRegisterer = new CodeRegisterer(); codeRegisterer.SendCodeContentsToServer(sourceCode); }
public void InjectReference(SourceCodeInfo sourceCodeInfo, string projectFileName) { string prdata = sourceCodeInfo.GetContentsOfFileAtRoot(projectFileName); if (prdata.Contains("CodeVineRecorder.dll")) { log.InfoFormat("Project {0} already contains the hooks, skipping injection of reference", projectFileName); return; } var replacedStr = ReplaceLastOccurrence(prdata, "</Project>", CODEVINE_REFERENCE_STR); sourceCodeInfo.SetContentsOfFileAtRoot(projectFileName, replacedStr); }
private static IStyle parseTestStyle() { var fileInfo = new PhysicalFileInfo(new System.IO.FileInfo(@"C:\Playground\AbsoluteGraphicsPlatform\tests\TestFiles\TestStyle1.dss")); var expressionExecutor = new ExpressionExecutor(); var dssParser = new DssParser(); var dssCompiler = new DssCompiler(expressionExecutor); var sourceInfo = new SourceCodeInfo(fileInfo); var instructions = dssParser.Parse(sourceInfo); var style = dssCompiler.Compile(instructions); return(style); }
public static IStyle GetStyle(string filename) { var fileProvider = IO.GetTestFileProvider(); var expressionExecutor = new ExpressionExecutor(); var dssParser = new DssParser(); var dssCompiler = new DssCompiler(expressionExecutor); var fileInfo = fileProvider.GetFileInfo(filename); var sourceInfo = new SourceCodeInfo(fileInfo); var instructions = dssParser.Parse(sourceInfo); var style = dssCompiler.Compile(instructions); return(style); }
public ComponentTemplate ParseComponentTemplate(SourceCodeInfo sourceInfo) { if (sourceInfo == null) { throw new ArgumentNullException(nameof(sourceInfo)); } var xml = new XmlDocument(); try { using (var stream = sourceInfo.GetStream()) xml.Load(stream); } catch (XmlException ex) { throw new AGPxException(ex.Message); } if (xml.DocumentElement.Name != componentTemplateTag) { throw new AGPxException($"All elements must be inserted into root element '{componentTemplateTag}'!"); } var namespaces = ParseNamespaces(xml); var componentName = xml.DocumentElement.Attributes["Name"]; if (componentName == null) { throw new AGPxException($"'{componentTemplateTag}' must have 'Name' attribute!"); } var rootComponentType = componentTypeResolver.FindComponentType(componentName.Value, namespaces); var rootTemplate = new ComponentTemplate(null, componentName.Value, rootComponentType); foreach (XmlNode node in xml.DocumentElement.ChildNodes) { rootTemplate.Templates.Add(ParseNode(rootTemplate, "default", node, namespaces)); } return(rootTemplate); }
public static ComponentTemplate ParseComponentTemplateCode(string code) { var appOptions = OptionsMocks.CreateApplicationOptions(); var propertySetter = new PropertySetter(appOptions); var dssParser = new DssParser(); var expressionExecutor = new ExpressionExecutor(); var componentTypeResolver = new ComponentTypeResolver(); var agpmlParser = new AGPMLParser(propertySetter, dssParser, expressionExecutor, componentTypeResolver); var sourceInfo = new SourceCodeInfo("TestCode", code); var template = agpmlParser.ParseComponentTemplate(sourceInfo); if (!ComponentTemplateProvider.ComponentTypes.Contains(template.ComponentType)) { ComponentTemplateProvider.Add(template); } return(template); }
public void ParseInto(DssInstructions dssInstructions, SourceCodeInfo sourceInfo) { if (sourceInfo == null) { throw new ArgumentNullException(nameof(sourceInfo)); } Internal.DssLexer lexer; using (var stream = sourceInfo.GetStream()) lexer = new Internal.DssLexer(new AntlrInputStream(stream)); var tokens = new CommonTokenStream(lexer); var parser = new Internal.DssParser(tokens); var errorListener = new ErrorListener(sourceInfo.SourceName); //parser.RemoveErrorListeners(); parser.AddErrorListener(errorListener); var listener = new StylesheetListener(sourceInfo.SourceName, dssInstructions); listener.EnterStylesheet(parser.stylesheet()); }
public void TestRegesteringProject() { SourceCodeInfo sourceCode = new SourceCodeInfo(GitTests.RepoPath); sourceCode.AddCodeFile("ClassA.cs"); var mock = new Mock <IMessageDispatcher>(); RedisMessage msg = new RedisMessage("", ""); mock.Setup(x => x.DispatchMessage(It.IsAny <RedisMessage>())).Callback((RedisMessage pmsg) => msg = pmsg); var codeHooks = new CodeHooks(mock.Object); CodeRegisterer codeRegisterer = new CodeRegisterer(codeHooks); codeRegisterer.SendCodeContentsToServer(sourceCode); mock.Verify(x => x.DispatchMessage(It.IsAny <RedisMessage>()), Times.AtLeast(1)); Assert.IsTrue(msg.GetKey().Contains("CODE_RUN_EVENTS")); Assert.IsTrue(msg.GetMessage().Contains("ADD_SOURCE_FILE")); Assert.IsTrue(msg.GetMessage().Contains("ClassA.cs")); Assert.IsTrue(msg.GetMessage().Contains("MethodA_1")); }
string SerializeSourceCodeInfo(SourceCodeInfo sourceCodeInfo) { return(sourceCodeInfo.RootPath + "|" + sourceCodeInfo.ProjectRegex + "+" + sourceCodeInfo.Count + ";"); }
/// <summary>Helper: Serialize into a MemoryStream and return its byte array</summary> public static byte[] SerializeToBytes(SourceCodeInfo instance) { using (var ms = new MemoryStream()) { Serialize(ms, instance); return ms.ToArray(); } }
/// <summary>Helper: Serialize with a varint length prefix</summary> public static void SerializeLengthDelimited(Stream stream, SourceCodeInfo instance) { var data = SerializeToBytes(instance); global::SilentOrbit.ProtocolBuffers.ProtocolParser.WriteUInt32(stream, (uint)data.Length); stream.Write(data, 0, data.Length); }
/// <summary>Serialize the instance into the stream</summary> public static void Serialize(Stream stream, SourceCodeInfo instance) { if (instance.LocationField != null) { foreach (var i1 in instance.LocationField) { // Key for field: 1, LengthDelimited stream.WriteByte(10); using (var ms1 = new MemoryStream()) { Google.protobuf.SourceCodeInfo.Location.Serialize(ms1, i1); // Length delimited byte array uint ms1Length = (uint)ms1.Length; global::SilentOrbit.ProtocolBuffers.ProtocolParser.WriteUInt32(stream, ms1Length); stream.Write(ms1.GetBuffer(), 0, (int)ms1Length); } } } }
/// <summary>Helper: create a new instance to deserializing into</summary> public static SourceCodeInfo DeserializeLengthDelimited(Stream stream) { SourceCodeInfo instance = new SourceCodeInfo(); DeserializeLengthDelimited(stream, instance); return instance; }
/// <summary>Helper: create a new instance to deserializing into</summary> public static SourceCodeInfo DeserializeLength(Stream stream, int length) { SourceCodeInfo instance = new SourceCodeInfo(); DeserializeLength(stream, length, instance); return instance; }
/// <summary>Helper: put the buffer into a MemoryStream and create a new instance to deserializing into</summary> public static SourceCodeInfo Deserialize(byte[] buffer) { SourceCodeInfo instance = new SourceCodeInfo(); using (var ms = new MemoryStream(buffer)) Deserialize(ms, instance); return instance; }
/// <summary>Helper: create a new instance to deserializing into</summary> public static SourceCodeInfo Deserialize(Stream stream) { SourceCodeInfo instance = new SourceCodeInfo(); Deserialize(stream, instance); return instance; }
/// <summary>Serialize the instance into the stream</summary> public static void Serialize(Stream stream, SourceCodeInfo instance) { var msField = global::SilentOrbit.ProtocolBuffers.ProtocolParser.Stack.Pop(); if (instance.LocationField != null) { foreach (var i1 in instance.LocationField) { // Key for field: 1, LengthDelimited stream.WriteByte(10); msField.SetLength(0); Google.Protobuf.SourceCodeInfo.Location.Serialize(msField, i1); // Length delimited byte array uint length1 = (uint)msField.Length; global::SilentOrbit.ProtocolBuffers.ProtocolParser.WriteUInt32(stream, length1); msField.WriteTo(stream); } } global::SilentOrbit.ProtocolBuffers.ProtocolParser.Stack.Push(msField); }
public SourceCodeInfo Resolve(ref string lines) { if (string.IsNullOrEmpty(lines)) { return(null); } HtmlDocument document = new HtmlDocument(); document.LoadHtml(lines); List <SourceCodeInfo> sources = new List <SourceCodeInfo>(); foreach (var node in document.DocumentNode.Descendants("sourcecode").ToList()) { SourceCodeInfo info = new SourceCodeInfo { Type = node.InnerText }; foreach (var remove in DebugInfoAttributes) { foreach (var attr in node.ChildAttributes(remove)) { if (!string.IsNullOrEmpty(attr.Value)) { info.Link = attr.Value; } } } node.Remove(); sources.Add(info); } foreach (var node in document.DocumentNode.Descendants("code").ToList()) { SourceCodeInfo info = new SourceCodeInfo { Type = node.InnerText }; foreach (var remove in DebugInfoAttributes) { foreach (var attr in node.ChildAttributes(remove)) { if (!string.IsNullOrEmpty(attr.Value)) { info.Link = attr.Value; } } } node.Remove(); sources.Add(info); } lines = document.DocumentNode.InnerHtml; if (sources.Any(s => !string.IsNullOrEmpty(s.Link))) { return(sources.FirstOrDefault(s => !string.IsNullOrEmpty(s.Link))); } return(sources.FirstOrDefault()); }