protected override void RefreshValue() { using (Microsoft.CSharp.CSharpCodeProvider provider = new Microsoft.CSharp.CSharpCodeProvider()) { System.CodeDom.Compiler.CodeGeneratorOptions opts = new System.CodeDom.Compiler.CodeGeneratorOptions(); using (System.CodeDom.Compiler.IndentedTextWriter tw = new System.CodeDom.Compiler.IndentedTextWriter(new StringWriter(), opts.IndentString)) { tw.Write("using ("); if (UsingExpression != null) { provider.GenerateCodeFromExpression(UsingExpression, tw, opts); } tw.WriteLine(")"); tw.WriteLine("{"); tw.Indent++; if (Statements != null) { foreach (CodeStatement statement in Statements) { provider.GenerateCodeFromStatement(statement, tw, opts); } } tw.Indent--; tw.Write("}"); Value = tw.InnerWriter.ToString(); } } }
public static void PublicAndFriend(System.CodeDom.Compiler.IndentedTextWriter inWriter, System.Xml.XmlNamespaceManager nsmgr, System.Xml.XmlNode node) { Support.MakeRegion(inWriter, "Public and Friend Properties, Methods and Events"); System.Xml.XmlNode nodeTemp = node.SelectSingleNode("dbs:TableConstraints/dbs:PrimaryKey/dbs:PKField", nsmgr); string primaryKeyName = ""; System.Xml.XmlNode primaryKey; if (nodeTemp != null) { primaryKeyName = Utility.Tools.GetAttributeOrEmpty(nodeTemp, "Name"); } primaryKey = node.SelectSingleNode("dbs:TableColumns/dbs:TableColumn[@Name='" + primaryKeyName + "']", nsmgr); inWriter.WriteLine("public overloads void Fill( "); inWriter.Indent += 4; if (primaryKey != null) { inWriter.WriteLine(Utility.Tools.GetAttributeOrEmpty(primaryKey, "NETType") + primaryKeyName + ","); } inWriter.WriteLine("int UserID"); inWriter.Indent -= 4; Support.WriteLineAndIndent(inWriter, "{"); inWriter.Write(Utility.Tools.GetAttributeOrEmpty(node, "SingularName") + "DataAccessor.Fill( this, "); if (primaryKey != null) { inWriter.Write(primaryKeyName + ", "); } inWriter.WriteLine("UserID );"); Support.WriteLineAndOutdent(inWriter, "}"); Support.EndRegion(inWriter); }
private static void BaseClassImplementation(System.CodeDom.Compiler.IndentedTextWriter inWriter, System.Xml.XmlNamespaceManager nsmgr, System.Xml.XmlNode node) { Support.MakeRegion(inWriter, "Base Class Implementation"); System.Xml.XmlNode nodeTemp = node.SelectSingleNode("dbs:TableConstraints/dbs:PrimaryKey/dbs:PKField", nsmgr); string primaryKeyName = ""; System.Xml.XmlNode primaryKey; if (nodeTemp != null) { primaryKeyName = Utility.Tools.GetAttributeOrEmpty(nodeTemp, "Name"); } primaryKey = node.SelectSingleNode("dbs:TableColumns/dbs:TableColumn[@Name='" + primaryKeyName + "']", nsmgr); if (primaryKey != null) { if (Utility.Tools.GetAttributeOrEmpty(primaryKey, "IsAutoIncrement") == "1") { inWriter.WriteLine("internal void SetNewPrimaryKey()"); Support.WriteLineAndIndent(inWriter, "{"); inWriter.WriteLine(primaryKeyName + " = mNextPrimaryKey"); inWriter.WriteLine("mNextPrimaryKey --"); Support.WriteLineAndOutdent(inWriter, "}"); } } Support.EndRegion(inWriter); }
internal override void Write(System.CodeDom.Compiler.IndentedTextWriter writer, GmlFormatter formatter, bool semicolon) { writer.Write("do"); if (Body.Kind != StatementKind.Sequence && string.IsNullOrEmpty(formatter.Newline)) { writer.Write(" "); } writer.WriteLine(); if (Body.Kind != StatementKind.Sequence) { writer.Indent++; } Body.Write(writer, formatter); if (Body.Kind != StatementKind.Sequence) { writer.Indent--; } writer.Write(string.Concat("while", formatter.Padding, "(")); Expression.Write(writer, formatter); writer.Write(")"); if (semicolon) { writer.WriteLine(";"); } }
public void WriteAsYAML(System.CodeDom.Compiler.IndentedTextWriter TW) { TW.WriteLine("name : \"{0}\"", this.GetType().ToString()); TW.WriteLine("underlying_scheduler:"); TW.Indent += 1; UnderlyingScheduler.WriteAsYAML(TW); TW.Indent -= 1; }
public void WriteAsYAML(System.CodeDom.Compiler.IndentedTextWriter TW) { TW.WriteLine("sat_queries: {0}", SatQueries); TW.WriteLine("unsat_queries: {0}", UnsatQueries); TW.WriteLine("unknown_queries: {0}", UnknownQueries); TW.WriteLine("total_queries: {0}", TotalQueries); TW.WriteLine("total_run_time: {0}", TotalRunTime.TotalSeconds); }
/// <summary> /// /// </summary> /// <param name="output"></param> public override void MainHlsl(System.CodeDom.Compiler.IndentedTextWriter output) { // see http://en.wikipedia.org/wiki/Luma_(video) output.WriteLine("float luminance = dot(color.rgb, float3(0.2126, 0.7152, 0.0722));"); // The result is the interpolation between luminance and chromatic (rgb) image output.WriteLine("color.rgb = lerp(luminance.xxx, color.rgb, {0});", this._level.FullName); }
public void WriteAsYAML(System.CodeDom.Compiler.IndentedTextWriter TW) { TW.WriteLine("# Termination Counter ({0}) info", TheCountType.ToString()); foreach (var terminationTypeCounterPair in Counters) { TW.WriteLine("{0}: {1}", StripPrefix(terminationTypeCounterPair.Key.ToString()), terminationTypeCounterPair.Value.ToString()); } }
internal override void Write(System.CodeDom.Compiler.IndentedTextWriter writer, GmlFormatter formatter, bool semicolon) { writer.WriteLine("exit"); if (semicolon) { writer.WriteLine(";"); } }
/// <summary> /// Generates the HLSL body. /// </summary> /// <param name="output">The writer object for code generation.</param> public override void MainHlsl(System.CodeDom.Compiler.IndentedTextWriter output) { output.WriteLine("color.r *= {0};", _redRatio.FullName); output.WriteLine("color.g *= {0};", _greenRatio.FullName); output.WriteLine("color.b *= {0};", _blueRatio.FullName); }
public void GenerateCode(CodeDomGenerator.Language language) { switch (language) { case CodeDomGenerator.Language.CSharp: using (Microsoft.CSharp.CSharpCodeProvider provider = new Microsoft.CSharp.CSharpCodeProvider()) { System.CodeDom.Compiler.CodeGeneratorOptions opts = new System.CodeDom.Compiler.CodeGeneratorOptions(); using (System.CodeDom.Compiler.IndentedTextWriter tw = new System.CodeDom.Compiler.IndentedTextWriter(new StringWriter(), opts.IndentString)) { tw.WriteLine("do"); tw.WriteLine("{"); tw.Indent++; if (Statements != null) foreach (CodeStatement statement in Statements) { provider.GenerateCodeFromStatement(statement, tw, opts); } tw.Indent--; tw.Write("} while ("); if (TestExpression != null) provider.GenerateCodeFromExpression(TestExpression, tw, opts); tw.WriteLine(");"); Value = tw.InnerWriter.ToString(); } } break; case CodeDomGenerator.Language.VB: using (Microsoft.VisualBasic.VBCodeProvider provider = new Microsoft.VisualBasic.VBCodeProvider()) { System.CodeDom.Compiler.CodeGeneratorOptions opts = new System.CodeDom.Compiler.CodeGeneratorOptions(); using (System.CodeDom.Compiler.IndentedTextWriter tw = new System.CodeDom.Compiler.IndentedTextWriter(new StringWriter(), opts.IndentString)) { tw.WriteLine("Do"); tw.Indent++; if (Statements != null) foreach (CodeStatement statement in Statements) { provider.GenerateCodeFromStatement(statement, tw, opts); } tw.Indent--; tw.Write("Loop Until "); if (TestExpression != null) provider.GenerateCodeFromExpression(TestExpression, tw, opts); tw.WriteLine(); Value = tw.InnerWriter.ToString(); } } break; default: throw new NotImplementedException(language.ToString()); } }
private static void Constructors(System.CodeDom.Compiler.IndentedTextWriter inWriter, System.Xml.XmlNamespaceManager nsmgr, System.Xml.XmlNode node) { string singularName = Utility.Tools.GetAttributeOrEmpty(node, "SingularName"); Support.MakeRegion(inWriter, "Constructors"); inWriter.WriteLine("internal {0}( {1} {1} ) : base()", singularName, singularName + "Collection"); Support.WriteLineAndIndent(inWriter, "{"); inWriter.WriteLine("mCollection = " + singularName + "Collection"); Support.WriteLineAndOutdent(inWriter, "}"); Support.EndRegion(inWriter); }
internal override void Write(System.CodeDom.Compiler.IndentedTextWriter writer, GmlFormatter formatter, bool semicolon) { writer.Write(string.Concat("switch", formatter.Padding, "(")); Expression.Write(writer, formatter); writer.WriteLine(")"); writer.WriteLine("{"); writer.Indent++; foreach (var stmt in Statements) { stmt.Write(writer, formatter); } writer.Indent--; writer.WriteLine("}"); }
public void WriteAsYAML(System.CodeDom.Compiler.IndentedTextWriter TW, bool showConstraints) { TW.WriteLine("num_constraints: {0}", Count); if (!showConstraints) { return; } TW.WriteLine("constraints:"); TW.Indent += 1; if (InternalConstraints.Count == 0) { TW.WriteLine("[ ]"); } else { foreach (var e in InternalConstraints) { TW.WriteLine("-"); TW.Indent += 1; TW.WriteLine("origin: \"{0}\"", e.Origin); TW.WriteLine("expr: \"{0}\"", e.Condition); TW.WriteLine("num_used_variables: {0}", e.UsedVariables.Count); TW.WriteLine("num_used_uf: {0}", e.UsedUninterpretedFunctions.Count); TW.Indent -= 1; } } TW.Indent -= 1; }
private static void WriteMultiLineIndented(string toWrite) { string[] tokens = Regex.Split(toWrite, @"\r?\n|\r"); foreach (var str in tokens) { MyWriter.WriteLine(str); } }
internal override void Write(System.CodeDom.Compiler.IndentedTextWriter writer, GmlFormatter formatter, bool semicolon) { writer.Write(string.Concat("if", formatter.Padding, "(")); Expression.Write(writer, formatter); writer.WriteLine(")"); if (Body.Kind != StatementKind.Sequence) { writer.Indent++; } Body.Write(writer, formatter); if (Body.Kind != StatementKind.Sequence) { writer.Indent--; } if (Else != null && Else.Kind != StatementKind.Nop) { if (Else.Kind != StatementKind.Sequence) { writer.Indent++; } Else.Write(writer, formatter); if (Else.Kind != StatementKind.Sequence) { writer.Indent--; } } }
protected override void DoTask(Executor e, ExecutionState State) { string terminatationTypeName = null; if (State.TerminationType == null) { terminatationTypeName = "NonTerminated"; } else { terminatationTypeName = State.TerminationType.GetType().ToString(); } var path = Path.Combine(Directory, ((State.Id >= 0)?State.Id.ToString():"initial") + "-" + terminatationTypeName + ".yml"); using (var SW = new StreamWriter(path)) { using (var ITW = new System.CodeDom.Compiler.IndentedTextWriter(SW, " ")) { Console.WriteLine("Logging State {0} info to {1}", State.Id, path); ITW.WriteLine("# vim: set sw=1 ts=1 softtabstop=1:"); // Tell vim how to indent the YAML file. State.WriteAsYAML(ITW, ShowConstraints, ShowVariables); } } }
public void WriteAsYAML(System.CodeDom.Compiler.IndentedTextWriter TW) { double total = (ConstraintSetsReduced + ConstraintSetsLeftUnchanged); double reduceP = 100 * ((float)ConstraintSetsReduced) / total; double sameP = 100 * ((float)ConstraintSetsLeftUnchanged) / total; TW.WriteLine("{0}:", this.GetType().ToString()); TW.Indent += 1; TW.WriteLine("constraint_sets_reduced: {0} #({1}%)", ConstraintSetsReduced, reduceP); TW.WriteLine("constraint_sets_left_unchanged: {0} #({1}%)", ConstraintSetsLeftUnchanged, sameP); TW.WriteLine("constraint_set_reduction_time: {0}", TimeUsedToComputeReducedConstraintSet.TotalSeconds); TW.WriteLine("underlying_solver:"); TW.Indent += 1; UnderlyingSolverStats.WriteAsYAML(TW); TW.Indent -= 2; }
internal override void Write(System.CodeDom.Compiler.IndentedTextWriter writer, GmlFormatter formatter, bool semicolon) { writer.Write("return "); Expression.Write(writer, formatter); if (semicolon) { writer.WriteLine(";"); } }
internal override void Write(System.CodeDom.Compiler.IndentedTextWriter writer, GmlFormatter formatter, bool semicolon) { Lefthand.Write(writer, formatter); writer.Write(string.Format("{1}{0}{1}", Operator, formatter.Padding)); Expression.Write(writer, formatter); if (semicolon) { writer.WriteLine(";"); } }
public void XmlDocumentLoading() { string xml = "<customer id='1' pp:id='aba' xmlns='urn-kzu' xmlns:pp='urn-pepenamespace'><pp:order /><order id='1'>Chocolates</order></customer>"; XPathNavigator nav = new XPathDocument(new StringReader(xml)).CreateNavigator(); XmlReader reader = new XPathNavigatorReader(nav); //XmlReader reader = new XmlTextReader(new StringReader(xml)); //reader.MoveToContent(); //Console.WriteLine(reader.ReadOuterXml()); System.CodeDom.Compiler.IndentedTextWriter tw = new System.CodeDom.Compiler.IndentedTextWriter(Console.Out); while (reader.Read()) { tw.Indent = reader.Depth; tw.WriteLine("Name={0}, Type={1}", reader.Name, reader.NodeType); int count = reader.AttributeCount; //reader.MoveToFirstAttribute(); //for (int i = 0; i < count; i++) while (reader.MoveToNextAttribute()) { tw.Indent = reader.Depth; tw.Write("{0}=", reader.Name); reader.ReadAttributeValue(); tw.WriteLine(reader.Value); //reader.MoveToNextAttribute(); } } //reader = new DebuggingXmlTextReader(new XPathNavigatorReader(nav)); reader = new XPathNavigatorReader(nav); XmlDocument doc = new XmlDocument(nav.NameTable); doc.Load(reader); Assert.AreEqual("customer", doc.DocumentElement.LocalName); Assert.AreEqual("urn-kzu", doc.DocumentElement.NamespaceURI); Assert.AreEqual(4, doc.DocumentElement.Attributes.Count); Assert.AreEqual(2, doc.DocumentElement.ChildNodes.Count); }
internal override void Write(System.CodeDom.Compiler.IndentedTextWriter writer, JsFormatter formatter) { writer.WriteLine("{"); writer.Indent++; foreach (var js in Body) { js.Write(writer, formatter); } writer.Indent--; writer.Write("}"); }
public static void CollectionConstructors(System.CodeDom.Compiler.IndentedTextWriter inWriter, System.Xml.XmlNamespaceManager nsmgr, System.Xml.XmlNode node) { Support.MakeRegion(inWriter, "Constructors"); string className = Utility.Tools.GetAttributeOrEmpty(node, "SingularName") + "Collection"; inWriter.WriteLine("protected " + className + "() : base( \"" + className + "\" )"); Support.WriteLineAndIndent(inWriter, "{"); Support.WriteLineAndOutdent(inWriter, "}"); Support.EndRegion(inWriter); }
public void Dump() { System.CodeDom.Compiler.IndentedTextWriter indent = new System.CodeDom.Compiler.IndentedTextWriter(Console.Out); indent.WriteLine("--------"); foreach (IBlockLine line in (IEnumerable <IBlockLine>)lines) { if ((line is BlockInstruction) && ((BlockInstruction)line).Operation == BlockOperation.BeginScope) { indent.Indent++; } indent.WriteLine(line); if ((line is BlockInstruction) && ((BlockInstruction)line).Operation == BlockOperation.EndScope) { indent.Indent--; } } }
public static System.IO.Stream GetStream(string name, string fileName, string genDateTime, System.Xml.XmlNode nodeSelect) { System.Console.WriteLine("Test"); System.Console.ReadLine(); System.IO.MemoryStream stream = new System.IO.MemoryStream(); System.CodeDom.Compiler.IndentedTextWriter inWriter = new System.CodeDom.Compiler.IndentedTextWriter(new System.IO.StreamWriter(stream)); System.Xml.XmlNodeList nodeList; string singularName = Utility.Tools.GetAttributeOrEmpty(nodeSelect, "SingularName"); System.Xml.XmlNamespaceManager nsmgr = Utility.Tools.BuildNamespaceManager(nodeSelect.OwnerDocument, "dbs", false); Support.FileOpen(inWriter, "KADGen,System", fileName, genDateTime); inWriter.WriteLine(""); Support.WriteLineAndIndent(inWriter, "public class " + singularName + "Collection : CollectionBase"); CollectionConstructors(inWriter, nsmgr, nodeSelect); PublicAndFriend(inWriter, nsmgr, nodeSelect); Support.WriteLineAndOutdent(inWriter, "}"); inWriter.WriteLine(""); inWriter.WriteLine(""); Support.WriteLineAndIndent(inWriter, "public class " + singularName + " : RowBase"); ClassLevelDeclarations(inWriter, nsmgr, nodeSelect); Constructors(inWriter, nsmgr, nodeSelect); BaseClassImplementation(inWriter, nsmgr, nodeSelect); Support.MakeRegion(inWriter, "Field access properties"); nodeList = nodeSelect.SelectNodes("dbs:TableColumns/*", nsmgr); foreach (System.Xml.XmlNode nodeColumn in nodeList) { ColumnMethods(inWriter, nsmgr, nodeColumn); } Support.EndRegion(inWriter); Support.WriteLineAndIndent(inWriter, "End Class"); inWriter.Flush(); return(stream); }
public static void ClassLevelDeclarations(System.CodeDom.Compiler.IndentedTextWriter inWriter, System.Xml.XmlNamespaceManager nsmgr, System.Xml.XmlNode node) { System.Xml.XmlNodeList nodeList; string pre = ""; Support.MakeRegion(inWriter, "Class Level Declarations"); inWriter.WriteLine(string.Format("protected {0} mCollection;", Utility.Tools.GetAttributeOrEmpty(node, "SingularName"))); inWriter.WriteLine("private static int mNextPrimaryKey = -1;"); nodeList = node.SelectNodes("dbs:TableColumns/*", nsmgr); inWriter.WriteLine(""); foreach (System.Xml.XmlNode nodeSub in nodeList) { if (Utility.Tools.GetAttributeOrEmpty(nodeSub, "NETType").Length == 0) { pre = "// "; } inWriter.WriteLine(string.Format("{0}private {1} {2};", pre, Utility.Tools.GetAttributeOrEmpty(nodeSub, "NETType"), Utility.Tools.GetAttributeOrEmpty(nodeSub, "Name"))); } Support.EndRegion(inWriter); }
public void WriteAsYAML(System.CodeDom.Compiler.IndentedTextWriter TW) { TW.WriteLine("{0}:", this.GetType().ToString()); TW.Indent += 1; TW.WriteLine("solver_process_time: {0}", SolverProcessTime.TotalSeconds); TW.WriteLine("read_expr_time: {0}", ReadExprTime.TotalSeconds); TW.WriteLine("print_expr_time: {0}", PrintExprTime.TotalSeconds); TW.WriteLine("process_create_count: {0}", ProcessCreationCount); TW.WriteLine("timeout_count: {0}", TimeoutCount); TW.WriteLine("solver_replied_unknown_count: {0}", SolverRepliedUnknownCount); TW.Indent -= 1; }
internal override void Write(System.CodeDom.Compiler.IndentedTextWriter writer, GmlFormatter formatter, bool semicolon) { var indent = writer.Indent; if (indent != 0) { writer.Indent--; } writer.WriteLine("default:"); if (indent != 0) { writer.Indent++; } }
public void WriteAsYAML(System.CodeDom.Compiler.IndentedTextWriter TW, bool showVariables) { // Globals TW.WriteLine("num_globals: {0}", Globals.Count); if (showVariables) { TW.WriteLine("globals:"); TW.Indent += 1; if (Globals.Count == 0) { TW.WriteLine("{}"); // Emtpy dictionary } else { foreach (var pair in Globals) { TW.WriteLine("\"{0}\":", pair.Key.ToString()); TW.Indent += 1; TW.WriteLine("type: \"{0}\"", pair.Key.TypedIdent.Type); TW.WriteLine("expr: \"{0}\"", pair.Value); TW.Indent -= 1; } } TW.Indent -= 1; } // Stackframe int depth = Stack.Count; TW.WriteLine("stack_depth: {0}", depth); TW.WriteLine("stack:"); TW.Indent += 1; for (int index = depth - 1; index >= 0; --index) { TW.WriteLine("-"); TW.Indent += 1; Stack[index].WriteAsYAML(TW, showVariables); TW.Indent -= 1; } TW.Indent -= 1; }
public void WriteAsYAML(System.CodeDom.Compiler.IndentedTextWriter TW) { TW.WriteLine("name : \"{0}\"", this.GetType().ToString()); TW.WriteLine("constructs: {0}", this.Count); TW.WriteLine("requests: {0}", this.Requests); TW.WriteLine("variable_stacks: {0}", this.VariableStacks.Count); TW.WriteLine("havoc_stacks: {0}", this.HavocCmdStacks.Count); TW.WriteLine("modset_stacks: {0}", this.ModsetStacks.Count); }
public void WriteAsYAML(System.CodeDom.Compiler.IndentedTextWriter TW) { TW.WriteLine("#Executor statistics as YAML. Times are in seconds"); TW.WriteLine("prepare_time: {0}", PrepareTime.TotalSeconds); TW.WriteLine("run_time: {0}", RunTime.TotalSeconds); TW.WriteLine("instructions_executed: {0}", InstructionsExecuted); TW.WriteLine("num_forks: {0}", ForkCount); TW.WriteLine("termination_type: \"{0}\"", TerminationType.ToString()); }
static void Main(string[] args) { if (!args.Any()) { Console.Error.WriteLine("Needs a file as an argument"); return; } Debug.WriteLine("Input file is \"{0}\"", args.First()); var file = new StreamReader(args.First()); var levelstack = new Stack<int>(); // Parse mlst file List<Function> functions = new List<Function>(); List<string> @using = new List<string>(); @using.Add("JsonApi.Client"); @using.Add("JsonApi.Client.Classes"); @using.Add("JsonApi.Client.DataTypes"); @using.Add("System"); @using.Add("System.Collections.Generic"); @using.Add("System.Linq"); @using.Add("System.Text"); string @namespace = "JsonApi.Client.Extensions"; string @class = "CustomRequests"; Debug.WriteLine("Default imported namespaces: {0}", @using.Count); Debug.WriteLine("Default namespace: {0}", @namespace, null); // Yep, laziness found here. Debug.WriteLine("Default class: {0}", @class, null); string line = file.ReadLine().TrimEnd(); while (!file.EndOfStream) { Debug.WriteLine("Current line, expecting new function or compiler directive: Level {1} => {0}", line.Trim(), GetLevel(line)); if (string.IsNullOrWhiteSpace(line) || string.IsNullOrEmpty(line)) { Debug.WriteLine("Ignoring because empty."); line = file.ReadLine().TrimEnd(); continue; } if (line.StartsWith(".")) { // compiler command var lspl = line.Split(' '); var argline = string.Join(" ", lspl.Skip(1)); var argarray = lspl.Skip(1); Debug.WriteLine("Compiler command being processed: {0} (with {1} arguments)", lspl[0].ToLower().Substring(1), argarray.Count()); line = file.ReadLine().TrimEnd(); // for next processing, we should ignore that from now on. switch (lspl[0].ToLower().Substring(1)) { case "using": if ([email protected](argline, StringComparer.OrdinalIgnoreCase)) { Debug.WriteLine("Importing {0}", argline); @using.Add(argline); } else Console.Error.WriteLine("Warning: Tried adding \"using {0}\", but namespace has already been imported.", argline, null); break; case "namespace": Debug.WriteLine("Changing to namespace {0}", argline, null); @namespace = argline; break; case "class": Debug.WriteLine("Changing to class {0}", argline, null); @class = argline; break; } continue; } var cFunction = new Function(); cFunction.Name = line.Trim(); Debug.WriteLine("Generating new function: {0}", cFunction.Name, null); levelstack.Push(GetLevel(line)); // root level push line = file.ReadLine().TrimEnd(); while (line != null && !(line.TrimEnd() == "") && GetLevel(line) > levelstack.Peek()) { Debug.WriteLine("Current line, expecting new descriptive keyword: Level {1} => {0}", line.Trim(), GetLevel(line)); switch (line.Trim().ToLower()) { default: { Console.Error.WriteLine("Warning: Found unknown descriptive keyword \"{0}\", ignoring", line.Trim().ToLower(), null); line = file.ReadLine().TrimEnd(); } break; case "description": { Debug.WriteLine("Found description for {0}", cFunction.Name, null); if (!string.IsNullOrEmpty(cFunction.Description)) { throw new Exception(string.Format("Function \"{0}\" already contains a description. Can't define twice.", cFunction.Name)); } StringBuilder descriptionBuilder = new StringBuilder(); levelstack.Push(GetLevel(line)); // command level push while (GetLevel(line = file.ReadLine()) > levelstack.Peek()) { Debug.WriteLine("Adding 1 line to description"); descriptionBuilder.AppendLine(line.Trim()); } levelstack.Pop(); // command level pop cFunction.Description = descriptionBuilder.ToString().Trim(); Debug.WriteLine("Description: {0}", cFunction.Description, null); } break; case "arguments": { Debug.WriteLine("Found arguments for {0}", cFunction.Name, null); levelstack.Push(GetLevel(line)); // command level push line = file.ReadLine().TrimEnd(); while (GetLevel(line) > levelstack.Peek()) { var spl = line.Trim().Split(' '); var type = new DataType() { TypeName = spl[0] }; var name = string.Empty; if (spl.Length > 1) name = spl.Last(); else { name = "arg" + cFunction.Arguments.Count; } Debug.WriteLine("Adding argument {0} of type {1}", name, type.TypeName); StringBuilder descriptionBuilder = new StringBuilder(); levelstack.Push(GetLevel(line)); // argument level push while (GetLevel(line = file.ReadLine()) > levelstack.Peek()) { Debug.WriteLine("Adding 1 line to description"); descriptionBuilder.AppendLine(line.Trim()); } levelstack.Pop(); // argument level pop type.Description = descriptionBuilder.ToString().Trim(); cFunction.Arguments.Add(name, type); } levelstack.Pop(); // command level pop } break; case "return": case "returns": { var type = new DataType() { TypeName = (line = file.ReadLine()).Trim() }; Debug.WriteLine("Found return type {0}", type.TypeName, null); StringBuilder descriptionBuilder = new StringBuilder(); levelstack.Push(GetLevel(line)); // command level push while (GetLevel(line = file.ReadLine()) > levelstack.Peek()) descriptionBuilder.AppendLine(line.Trim()); levelstack.Pop(); // command level pop type.Description = descriptionBuilder.ToString().Trim(); cFunction.ReturnType = type; } break; } } levelstack.Pop(); // root level pop functions.Add(cFunction); } // using directives var stream = Console.OpenStandardOutput(); var streamwriter = new System.CodeDom.Compiler.IndentedTextWriter(new StreamWriter(stream)); foreach (string importedNamespace in @using) streamwriter.WriteLine("using {0};", importedNamespace); // Start namespace streamwriter.WriteLine("namespace {0}", @namespace); streamwriter.WriteLine("{"); streamwriter.Indent++; // Start class streamwriter.WriteLine("public static class {0}", @class); streamwriter.WriteLine("{"); streamwriter.Indent++; // Functions foreach (var function in functions) { // Fix return type if (function.ReturnType == null) function.ReturnType = new DataType() { TypeName = "void" }; if (function.ReturnType.TypeName.Equals("boolean", StringComparison.OrdinalIgnoreCase)) function.ReturnType.TypeName = "bool"; // Fix argument types foreach (var aName in function.Arguments.Keys) { var aVal = function.Arguments[aName]; if (aVal.TypeName.Equals("boolean", StringComparison.OrdinalIgnoreCase)) aVal.TypeName = "bool"; } // Request generation function foreach (string l in function.GetMetadataXml().Split(new[] { '\n' }, StringSplitOptions.RemoveEmptyEntries)) streamwriter.WriteLine("/// {0}", l.Trim(), null); streamwriter.Flush(); streamwriter.WriteLine("public static StandardAPIRequest {0}({1})", function.NormalizedName, function.GetParameterSignature()); streamwriter.Write("{ "); streamwriter.Write("return new StandardAPIRequest(\"{0}\"{1});", function.Name, function.Arguments.Count > 0 ? ", " + function.GetParameterPass() : ""); streamwriter.WriteLine(" }"); streamwriter.WriteLine(); streamwriter.Flush(); // Actual standard API request function foreach (string l in function.GetMetadataXml().Split(new[] { '\n' }, StringSplitOptions.RemoveEmptyEntries)) streamwriter.WriteLine("/// {0}", l.Trim(), null); streamwriter.Flush(); streamwriter.WriteLine("public static {2} {0}(this Client client{1})", function.NormalizedName, function.Arguments.Count > 0 ? ", " + function.GetParameterSignature() : "", function.ReturnType == null ? "void" : function.ReturnType.TypeName); streamwriter.Write("{ "); if(function.ReturnType != null && function.ReturnType.TypeName != "void") streamwriter.Write("return client.Request<{2}>({0}({1}));", function.NormalizedName, function.GetParameterPass(), function.ReturnType.TypeName); else streamwriter.Write("client.Request({0}({1}));", function.NormalizedName, function.GetParameterPass()); streamwriter.WriteLine(" }"); streamwriter.WriteLine(); streamwriter.Flush(); } // End class streamwriter.Indent--; streamwriter.WriteLine("}"); // End namespace streamwriter.Indent--; streamwriter.WriteLine("}"); // Finalize streamwriter.Flush(); streamwriter.Close(); streamwriter.Dispose(); }
public void XmlDocumentLoading() { string xml = "<customer id='1' pp:id='aba' xmlns='urn-kzu' xmlns:pp='urn-pepenamespace'><pp:order /><order id='1'>Chocolates</order></customer>"; XPathNavigator nav = new XPathDocument(new StringReader(xml)).CreateNavigator(); XmlReader reader = new XPathNavigatorReader(nav); //XmlReader reader = new XmlTextReader(new StringReader(xml)); //reader.MoveToContent(); //Console.WriteLine(reader.ReadOuterXml()); System.CodeDom.Compiler.IndentedTextWriter tw = new System.CodeDom.Compiler.IndentedTextWriter(Console.Out); while (reader.Read()) { tw.Indent = reader.Depth; tw.WriteLine("Name={0}, Type={1}", reader.Name, reader.NodeType); int count = reader.AttributeCount; //reader.MoveToFirstAttribute(); //for (int i = 0; i < count; i++) while (reader.MoveToNextAttribute()) { tw.Indent = reader.Depth; tw.Write("{0}=", reader.Name); reader.ReadAttributeValue(); tw.WriteLine(reader.Value); //reader.MoveToNextAttribute(); } } //reader = new DebuggingXmlTextReader(new XPathNavigatorReader(nav)); reader = new XPathNavigatorReader(nav); XmlDocument doc = new XmlDocument(nav.NameTable); doc.Load( reader ); Assert.AreEqual("customer", doc.DocumentElement.LocalName); Assert.AreEqual("urn-kzu", doc.DocumentElement.NamespaceURI); Assert.AreEqual(4, doc.DocumentElement.Attributes.Count); Assert.AreEqual(2, doc.DocumentElement.ChildNodes.Count); }
public void Dump() { System.CodeDom.Compiler.IndentedTextWriter indent = new System.CodeDom.Compiler.IndentedTextWriter(Console.Out); indent.WriteLine("--------"); foreach (IBlockLine line in (IEnumerable<IBlockLine>) lines) { if ((line is BlockInstruction) && ((BlockInstruction) line).Operation == BlockOperation.BeginScope) indent.Indent++; indent.WriteLine(line); if ((line is BlockInstruction) && ((BlockInstruction) line).Operation == BlockOperation.EndScope) indent.Indent--; } }
static int Main(string[] args) { if (args == null || !args.Any()) { NConfiguration.NConfigurationManager.Initialize(); Console.WriteLine(NConfiguration.NConfigurationManager.GetEnvironment()); } else if (!_validSwitches.Contains(args[0])) { PrintUsage(); return 1; } else if (args[0].StartsWith("-a")) { if (args.Length < 2) { PrintUsage(); return 1; } NConfiguration.NConfigurationManager.Initialize(); var key = args[1]; Console.WriteLine(NConfiguration.NConfigurationManager.GetAppSetting(key)); } else if (args[0].StartsWith("-c")) { if (args.Length < 2) { PrintUsage(); return 1; } NConfiguration.NConfigurationManager.Initialize(); var key = args[1]; Console.WriteLine(NConfiguration.NConfigurationManager.GetConnectionString(key)); } else if (args[0].StartsWith("-l")) { if (args.Length >= 2) { PrintUsage(); return 1; } Console.WriteLine("Key candidates for this PC"); var candidates = NConfiguration.NConfigurationManager.GetKeyCandidates(); foreach(var key in candidates) { Console.WriteLine("\t - {0}", key); } } else if (args[0].StartsWith("-e")) { if (args.Length >= 2) { PrintUsage(); return 1; } NConfiguration.NConfigurationManager.Initialize(); Console.WriteLine(NConfiguration.NConfigurationManager.GetEnvironment()); } else if (args[0].StartsWith("-v")) { var validationResults = NConfiguration.NConfigurationManager.ValidateAllConfigurations(); if (!validationResults.Any()) { Console.WriteLine("All the configuration files are in sync"); return 0; } using (var writer = new System.CodeDom.Compiler.IndentedTextWriter(Console.Error, " ")) { foreach (var validationResult in validationResults) { var color = Console.ForegroundColor; Console.ForegroundColor = ConsoleColor.Red; writer.WriteLine("{0} has the following misconfigurations:", validationResult.Key); Console.ForegroundColor = color; writer.Indent = 1; foreach (var validationMessage in validationResult.Value) { writer.WriteLine(validationMessage); } writer.Indent = 0; } } return 1; } return 0; }
public void GenerateCode(CodeDomGenerator.Language language) { switch (language) { case CodeDomGenerator.Language.CSharp: using (Microsoft.CSharp.CSharpCodeProvider provider = new Microsoft.CSharp.CSharpCodeProvider()) { System.CodeDom.Compiler.CodeGeneratorOptions opts = new System.CodeDom.Compiler.CodeGeneratorOptions(); using (System.CodeDom.Compiler.IndentedTextWriter tw = new System.CodeDom.Compiler.IndentedTextWriter(new StringWriter(), opts.IndentString)) { if (_params.Count != 1 || _params[0].Type != null) tw.Write("("); for (int i = 0; i < _params.Count; i++) { if (i > 0) tw.Write(", "); if (_params[i].Type != null) { provider.GenerateCodeFromExpression(new CodeTypeReferenceExpression(_params[i].Type), tw, opts); tw.Write(" "); } tw.Write(_params[i].Name); } if (_params.Count != 1 || _params[0].Type != null) tw.Write(")"); tw.WriteLine(" => "); tw.WriteLine("{"); tw.Indent++; foreach (CodeStatement statement in Statements) { provider.GenerateCodeFromStatement(statement, tw, opts); } tw.Indent--; tw.Write("}"); Value = tw.InnerWriter.ToString(); } } break; case CodeDomGenerator.Language.VB: using (Microsoft.VisualBasic.VBCodeProvider provider = new Microsoft.VisualBasic.VBCodeProvider()) { System.CodeDom.Compiler.CodeGeneratorOptions opts = new System.CodeDom.Compiler.CodeGeneratorOptions(); using (System.CodeDom.Compiler.IndentedTextWriter tw = new System.CodeDom.Compiler.IndentedTextWriter(new StringWriter(), opts.IndentString)) { throw new NotImplementedException(); //tw.Write("Function("); //for (int i = 0; i < _params.Count; i++) //{ // if (i > 0) // tw.Write(", "); // tw.Write(_params[i].Name); // if (_params[i].Type != null) // { // tw.Write(" As "); // provider.GenerateCodeFromExpression(new CodeTypeReferenceExpression(_params[i].Type), tw, opts); // } //} //tw.Write(") "); //provider.GenerateCodeFromExpression(Statements, tw, opts); //Value = tw.InnerWriter.ToString(); } } break; default: throw new NotImplementedException(language.ToString()); } }
public void GenerateCode(CodeDomGenerator.Language language) { switch (language) { case CodeDomGenerator.Language.CSharp: using (Microsoft.CSharp.CSharpCodeProvider provider = new Microsoft.CSharp.CSharpCodeProvider()) { System.CodeDom.Compiler.CodeGeneratorOptions opts = new System.CodeDom.Compiler.CodeGeneratorOptions(); using (System.CodeDom.Compiler.IndentedTextWriter tw = new System.CodeDom.Compiler.IndentedTextWriter(new StringWriter(), opts.IndentString)) { tw.Write("foreach ("); provider.GenerateCodeFromExpression(new CodeTypeReferenceExpression(IterationItemType), tw, opts); tw.Write(" {0} in ", provider.CreateValidIdentifier(IterationItemName)); provider.GenerateCodeFromExpression(IterExpression, tw, opts); tw.WriteLine(")"); tw.WriteLine("{"); tw.Indent++; if (Statements != null) foreach (CodeStatement statement in Statements) { provider.GenerateCodeFromStatement(statement, tw, opts); } tw.Indent--; tw.WriteLine("}"); Value = tw.InnerWriter.ToString(); } } break; case CodeDomGenerator.Language.VB: using (Microsoft.VisualBasic.VBCodeProvider provider = new Microsoft.VisualBasic.VBCodeProvider()) { System.CodeDom.Compiler.CodeGeneratorOptions opts = new System.CodeDom.Compiler.CodeGeneratorOptions(); using (System.CodeDom.Compiler.IndentedTextWriter tw = new System.CodeDom.Compiler.IndentedTextWriter(new StringWriter(), opts.IndentString)) { tw.Write("For Each {0} As ", provider.CreateValidIdentifier(IterationItemName)); provider.GenerateCodeFromExpression(new CodeTypeReferenceExpression(IterationItemType), tw, opts); tw.Write(" in "); provider.GenerateCodeFromExpression(IterExpression, tw, opts); tw.WriteLine(); tw.Indent++; if (Statements != null) foreach (CodeStatement statement in Statements) { provider.GenerateCodeFromStatement(statement, tw, opts); } tw.Indent--; tw.WriteLine("Next"); Value = tw.InnerWriter.ToString(); } } break; default: throw new NotImplementedException(language.ToString()); } }
public void GenerateCode(CodeDomGenerator.Language language) { switch (language) { case CodeDomGenerator.Language.CSharp: using (Microsoft.CSharp.CSharpCodeProvider provider = new Microsoft.CSharp.CSharpCodeProvider()) { System.CodeDom.Compiler.CodeGeneratorOptions opts = new System.CodeDom.Compiler.CodeGeneratorOptions(); using (System.CodeDom.Compiler.IndentedTextWriter tw = new System.CodeDom.Compiler.IndentedTextWriter(new StringWriter(), opts.IndentString)) { tw.Write("switch ("); if (SwitchExpression != null) provider.GenerateCodeFromExpression(SwitchExpression, tw, opts); tw.WriteLine(")"); tw.WriteLine("{"); tw.Indent++; foreach (CaseBlock c in m_cases) { if (c.Statements != null) { if (c.CaseExpression != null) { tw.Write("case "); provider.GenerateCodeFromExpression(c.CaseExpression, tw, opts); tw.WriteLine(":"); } else { tw.WriteLine("default:"); } tw.Indent++; foreach (CodeStatement stmt in c.Statements) { provider.GenerateCodeFromStatement(stmt, tw, opts); } tw.Indent--; } //else //{ // tw.Indent++; // tw.WriteLine("break;"); // tw.Indent--; //} } tw.Indent--; tw.WriteLine("}"); Value = tw.InnerWriter.ToString(); } } break; case CodeDomGenerator.Language.VB: using (Microsoft.VisualBasic.VBCodeProvider provider = new Microsoft.VisualBasic.VBCodeProvider()) { System.CodeDom.Compiler.CodeGeneratorOptions opts = new System.CodeDom.Compiler.CodeGeneratorOptions(); using (System.CodeDom.Compiler.IndentedTextWriter tw = new System.CodeDom.Compiler.IndentedTextWriter(new StringWriter(), opts.IndentString)) { tw.Write("Select Case "); if (SwitchExpression != null) provider.GenerateCodeFromExpression(SwitchExpression, tw, opts); tw.WriteLine(); tw.Indent++; foreach (CaseBlock c in m_cases) { if (c.Statements != null) { if (c.CaseExpression != null) { tw.Write("Case "); provider.GenerateCodeFromExpression(c.CaseExpression, tw, opts); tw.WriteLine(); } else { tw.WriteLine("Case Else"); } tw.Indent++; for (int i = 0; i < c.Statements.Length; i++) { CodeStatement stmt = c.Statements[i]; if (!(stmt is CodeExitSelectStatement) || i < c.Statements.Length-1) provider.GenerateCodeFromStatement(stmt, tw, opts); } tw.Indent--; } //else if (i < m_cases.Count - 1) //{ // tw.Indent++; // tw.WriteLine("Exit Select"); // tw.Indent--; //} } tw.Indent--; tw.WriteLine("End Select"); Value = tw.InnerWriter.ToString(); } } break; default: throw new NotImplementedException(language.ToString()); } }