public static IW1Top WAssemblyUnit(this IW1Top w1Top, IGAssemblyUnit gAssemblyUnit, StringBuilder?sB = default, CancellationToken?ct = default) { ct?.ThrowIfCancellationRequested(); var path = Path.Combine(w1Top.BasePath, gAssemblyUnit.GRelativePath); var dirInfo = new DirectoryInfo(path); if (!dirInfo.Exists) { if (!(bool)w1Top.Force) { //ToDo: Log exception throw new Exception(message: $"Relative directory for Generated code does not exist (try force=true): {path}"); } else { try { dirInfo.Create(); } catch (System.IO.IOException e) { //ToDo: Log exception throw new Exception(message: $"Could not create relative directory for Generated code: {path}", innerException: e); } } } return(w1Top); }
public static IW1Top WCompilationUnit(this IW1Top w1Top, IGCompilationUnit gCompilationUnit, StringBuilder sB, CancellationToken?ct = default) { var pathToDir = Path.Combine(w1Top.BasePath, gCompilationUnit.GRelativePath); var pathToFile = Path.Combine(w1Top.BasePath, gCompilationUnit.GRelativePath, gCompilationUnit.GName + gCompilationUnit.GFileSuffix); var transformDictionary = gCompilationUnit.GPatternReplacement.GDictionary; IW1Top iW1Top; try { iW1Top = w1Top.WFile(pathToDir, pathToFile, transformDictionary, sB, ct); } catch (Exception e) { Console.WriteLine(e); // ToDo: better exception handling throw; } sB.Clear(); return(iW1Top); }
public static IR1Top RAssemblyGroup(this IR1Top r1Top, IEnumerable <IGAssemblyGroup> gAssemblyGroups, IW1Top w1Top) { foreach (var o in gAssemblyGroups) { r1Top.RAssemblyGroup(o, w1Top); } return(r1Top); }
public static IR1Top RCompilationUnit(this IR1Top r1Top, IDictionary <IPhilote <IGCompilationUnit>, IGCompilationUnit> gCompilationUnits, IW1Top w1Top) { foreach (var kvp in gCompilationUnits) { r1Top.RCompilationUnit(kvp.Value, w1Top); } return(r1Top); }
public static IR1Top RCompilationUnit(this IR1Top r1Top, IList <IGCompilationUnit> gCompilationUnits, IW1Top w1Top) { foreach (var o in gCompilationUnits) { r1Top.RCompilationUnit(o, w1Top); } return(r1Top); }
public static IR1Top RCompilationUnit(this IR1Top r1Top, IGCompilationUnit gCompilationUnit, IW1Top w1Top) { r1Top.Ct?.ThrowIfCancellationRequested(); r1Top.Sb.RenderCompilationUnitStringBuilder(gCompilationUnit, r1Top.Indent, r1Top.Eol, r1Top.Ct); if (gCompilationUnit.GUsingGroups.Any()) { r1Top.RUsingGroup(gCompilationUnit.GUsingGroups); } if (gCompilationUnit.GUsings.Any()) { foreach (var kvp in gCompilationUnit.GUsings) { r1Top.RUsing(kvp.Value); } } if (gCompilationUnit.GNamespaces.Any()) { foreach (var kvp in gCompilationUnit.GNamespaces) { r1Top.RNamespace(kvp.Value); } } w1Top.WCompilationUnit(gCompilationUnit, r1Top.Sb); return(r1Top); }
public static IR1Top RProjectUnit(this IR1Top r1Top, IDictionary <IPhilote <IGProjectUnit>, IGProjectUnit> gProjectUnits, IW1Top w1Top) { foreach (var kvp in gProjectUnits) { r1Top.RProjectUnit(kvp.Value, w1Top); } return(r1Top); }
public static IR1Top RProjectUnit(this IR1Top r1Top, IList <IGProjectUnit> gProjectUnits, IW1Top w1Top) { foreach (var o in gProjectUnits) { r1Top.RProjectUnit(o, w1Top); } return(r1Top); }
public static IR1Top RResourceUnit(this IR1Top r1Top, List <IGResourceUnit> gResourceUnits, IW1Top w1Top) { foreach (var o in gResourceUnits) { r1Top.RResourceUnit(o, w1Top); } return(r1Top); }
public static IW1Top WFile(this IW1Top w1Top, string pathToDirectory, string pathToFile, Dictionary <Regex, string> gDictionary, StringBuilder sB, CancellationToken?ct = default) { ct?.ThrowIfCancellationRequested(); bool testforidentity = true; // Move higher and make this an argument bool isIdentical = false; string transformedString = sB.ToString(); // ToDo: performance enhancement for large strings and many replacementss? byte[] transformedStringAsBytes; // ToDo: overall, rearchitect this so that constly operations are not performed unless necessary preconditions occur foreach (var kvp in gDictionary) { pathToDirectory = kvp.Key.Replace(pathToDirectory, kvp.Value); pathToFile = kvp.Key.Replace(pathToFile, kvp.Value); transformedString = kvp.Key.Replace(transformedString, kvp.Value); } var dirInfo = new DirectoryInfo(pathToDirectory); if (!dirInfo.Exists) { if (!(bool)w1Top.Force) { //ToDo: Log exception throw new Exception(message: $"Relative directory for Generated code does not exist (try force=true): {pathToDirectory}"); } else { try { dirInfo.Create(); } catch (System.IO.IOException e) { //ToDo: Log exception throw new Exception(message: $"Could not create relative directory for Generated code: {pathToDirectory}", innerException: e); } } } // ToDo: Implement a buffering scheme to reduce memory pressure transformedStringAsBytes = Encoding.UTF8.GetBytes(transformedString); // ToDo: specify encoding on a per-file basis var fileInfo = new FileInfo(pathToFile); FileStream fileStream; if (!fileInfo.Exists) { try { fileStream = new FileStream(pathToFile, FileMode.Create, FileAccess.Write, FileShare.Write, 0x4000, useAsync: false); } catch (Exception e) { Console.WriteLine(e); throw; } } else { if (testforidentity) { try { fileStream = new FileStream(pathToFile, FileMode.Open, FileAccess.Read, FileShare.Read, 0x4000, useAsync: false); } catch (Exception e) { Console.WriteLine(e); throw; } using (fileStream) { byte[] oldcontentsbytes; using (var ms = new MemoryStream()) { fileStream.CopyTo(ms); oldcontentsbytes = ms.ToArray(); } isIdentical = ((ReadOnlySpan <byte>)oldcontentsbytes).SequenceEqual((ReadOnlySpan <byte>)transformedStringAsBytes); } } else { try { fileStream = new FileStream(pathToFile, FileMode.Truncate, FileAccess.Write, FileShare.Write, 0x4000, useAsync: false); } catch (Exception e) { Console.WriteLine(e); throw; } } } if (!isIdentical) { try { fileStream = new FileStream(pathToFile, FileMode.Truncate, FileAccess.Write, FileShare.Write, 0x4000, useAsync: false); } catch (Exception e) { Console.WriteLine(e); throw; } using (fileStream) { var bytes = Encoding.UTF8.GetBytes(transformedString); try { fileStream.Write(transformedStringAsBytes, 0, bytes.Length); // ToDo: implement an async version that is thread-safe for parallel execution } catch (IOException e) { Console.WriteLine(e); throw; } } } sB.Clear(); return(w1Top); }
public static IR1Top RAssemblyUnit(this IR1Top r1Top, IDictionary <IPhilote <IGAssemblyUnit>, IGAssemblyUnit> gAssemblyUnits, IW1Top w1Top) { foreach (var kvp in gAssemblyUnits) { r1Top.RAssemblyUnit(kvp.Value, w1Top); } return(r1Top); }
public static IR1Top RAssemblyUnit(this IR1Top r1Top, List <IGAssemblyUnit> gAssemblyUnits, IW1Top w1Top) { foreach (var o in gAssemblyUnits) { r1Top.RAssemblyUnit(o, w1Top); } return(r1Top); }
public static IR1Top RAssemblyUnit(this IR1Top r1Top, IGAssemblyUnit gAssemblyUnit, IW1Top w1Top) { r1Top.Ct?.ThrowIfCancellationRequested(); // This primarly changes the path where the AssemblyUnits' child Units are written var _savepath = w1Top.BasePath; w1Top.WAssemblyUnit(gAssemblyUnit); w1Top.BasePath = Path.Combine(w1Top.BasePath, gAssemblyUnit.GRelativePath); if (gAssemblyUnit.GCompilationUnits.Any()) { foreach (var kvp in gAssemblyUnit.GCompilationUnits) { r1Top.RCompilationUnit(kvp.Value, w1Top); r1Top.Sb.Clear(); } } if (gAssemblyUnit.GPropertiesUnits.Any()) { foreach (var kvp in gAssemblyUnit.GPropertiesUnits) { //r1Top.RPropertiesUnit(kvp.Value,w1Top); r1Top.Sb.Clear(); } } if (gAssemblyUnit.GResourceUnits.Any()) { foreach (var kvp in gAssemblyUnit.GResourceUnits) { r1Top.RResourceUnit(kvp.Value, w1Top); r1Top.Sb.Clear(); } } r1Top.RProjectUnit(gAssemblyUnit.GProjectUnit, w1Top); // Change the Top path back to its state before the AssemblyUnit is rendered // DirectoryInfo assemblyParentPathDirectoryInfo = Directory.GetParent(w1Top.BasePath); //ToDo: re-architect to ensure the main path variable is restored, or, do assemblies and their paths on different thread-local data and async with throtleing and backpressure w1Top.BasePath = _savepath; return(r1Top); }
public static IR1Top RResourceUnit(this IR1Top r1Top, IDictionary <IPhilote <IGResourceUnit>, IGResourceUnit> gResourceUnits, IW1Top w1Top) { foreach (var kvp in gResourceUnits) { r1Top.RResourceUnit(kvp.Value, w1Top); } return(r1Top); }
public static IR1Top RAssemblyGroup(this IR1Top r1Top, IDictionary <IPhilote <IGAssemblyGroup>, IGAssemblyGroup> gAssemblyGroups, IW1Top w1Top) { foreach (var o in gAssemblyGroups) { r1Top.RAssemblyGroup(o.Value, w1Top); } return(r1Top); }
public static IR1Top RProjectUnit(this IR1Top r1Top, IGProjectUnit gProjectUnit, IW1Top w1Top) { r1Top.Ct?.ThrowIfCancellationRequested(); r1Top.Sb.RenderProjectUnitPreambleStringBuilder(gProjectUnit, r1Top.Indent, r1Top.Eol, r1Top.Ct); r1Top.Indent.Append(r1Top.IndentDelta); r1Top.Sb.Append(r1Top.Eol); r1Top.Sb.Append($"{r1Top.IndentDelta}{GProjectUnit.Header}{r1Top.Eol}"); if (gProjectUnit.GPropertyGroupInProjectUnits.Any()) { foreach (var kvp in gProjectUnit.GPropertyGroupInProjectUnits) { r1Top.RPropertyGroupInProjectUnit(kvp.Value); } } r1Top.Sb.Append(r1Top.Eol); if (gProjectUnit.GItemGroupInProjectUnits.Any()) { foreach (var kvp in gProjectUnit.GItemGroupInProjectUnits) { r1Top.RItemGroupInProjectUnit(kvp.Value); } } r1Top.Sb.Append(r1Top.Eol); if (gProjectUnit.GResourceUnits.Any()) { r1Top.Sb.Append($"{r1Top.Indent}<ItemGroup>{r1Top.Eol}"); foreach (var kvp in gProjectUnit.GResourceUnits) { r1Top.RResourceUnitInProjectUnit(kvp.Value); r1Top.Sb.Append(r1Top.Eol); } r1Top.Sb.Append($"{r1Top.Indent}</ItemGroup>{r1Top.Eol}"); } r1Top.Indent.ReplaceFirst(r1Top.IndentDelta, ""); r1Top.Sb.RenderProjectUnitPostambleStringBuilder(gProjectUnit, r1Top.Indent, r1Top.Eol, r1Top.Ct); r1Top.Sb.Append(r1Top.Eol); w1Top.WProjectUnit(gProjectUnit, r1Top.Sb); return(r1Top); }
public static IR1Top RAssemblyGroup(this IR1Top r1Top, IGAssemblyGroup gAssemblyGroup, IW1Top w1Top) { foreach (var o in gAssemblyGroup.GAssemblyUnits) { r1Top.RAssemblyUnit(o.Value, w1Top); } return(r1Top); }
public static IR1Top RResourceUnit(this IR1Top r1Top, IGResourceUnit gResourceUnit, IW1Top w1Top) { r1Top.Ct?.ThrowIfCancellationRequested(); StringBuilder localStringBuilder = new StringBuilder(); try { localStringBuilder.FetchFileAsStringBuilder("CResourceUnitPreambleTemplate.xml"); } catch (Exception e) { Console.WriteLine(e); // ToDo: better exception handling throw; } // ToDo: Figure out how to insert the header into the XML File Fetched as a template if (gResourceUnit.GResourceItems.Any()) { foreach (var kvp in gResourceUnit.GResourceItems) { localStringBuilder.RResourceItemStringBuilder(kvp.Value, r1Top.Eol, r1Top.Ct); } } localStringBuilder.Append($"</root>{r1Top.Eol}"); r1Top.Sb.Append(localStringBuilder); w1Top.WResourceUnit(gResourceUnit, r1Top.Sb); r1Top.Sb.Clear(); return(r1Top); }