public void setClientCode(string clientCryptedPrivateNumber) { System.IO.TextWriter twr = System.IO.File.CreateText(System.Windows.Forms.Application.StartupPath + @"\client.lic"); twr.Write(this.getSCompared(clientCryptedPrivateNumber)); twr.Close(); twr.Dispose(); }
public void Dispose() { _writer.Flush(); if (_writer != null) { _writer.Dispose(); } }
protected virtual void Dispose(bool disposing) { if (_disposed) { return; } _textWriter.Dispose(); _disposed = true; }
/// <summary> /// Libera o <see cref="System.IO.TextWriter"/> associado. /// </summary> /// <param name="disposing"></param> protected virtual void Dispose(bool disposing) { if (disposing) { if (writer != null) { writer.Dispose(); } } }
void BreakDownLog() { logRefCount--; if (logRefCount == 0 && logWriter != null) { logWriter.Flush(); logWriter.Dispose(); logWriter = null; logHistory.Clear(); } }
private void EndSetWrite() { lock (_setLock) { if (_setWriter != null && _writeCount > 0) { _setWriter.EndWrite(); _setWriter.Dispose(); _setFileHandle.Dispose(); } } }
static void Main(string[] args) { using (System.IO.TextWriter w = System.IO.File.CreateText("texto.txt")) { for (int i = 0; i <= 1000; i++) { string num1 = Convert.ToString(i); w.WriteLine("Linha" + num1); } w.Dispose(); } }
/// <summary> /// /// </summary> public void Close() { if (_Writer != null) { _Writer.Flush(); _Writer.Close(); _Writer.Dispose(); _Writer = null; } _Indent = 0; _Cache.Clear(); }
public void ExtractAllFiles(string selpath, SimPe.Interfaces.Files.IPackedFileDescriptor[] pfds, SimPe.Packages.ExtractableFile package) { int excount = 0; int filecount = 0; string xml = ""; bool run = WaitingScreen.Running; if (!run) { WaitingScreen.Wait(); } try { xml += "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>" + Helper.lbr; xml += "<package type=\"" + ((uint)package.Header.IndexType).ToString() + "\">" + Helper.lbr; for (int i = 0; i < pfds.Length; i++) { System.Windows.Forms.Application.DoEvents(); Packages.PackedFileDescriptor fii = (Packages.PackedFileDescriptor)pfds[i]; Data.TypeAlias a = fii.TypeName; fii.Path = null; string path = System.IO.Path.Combine(selpath, fii.Path); fii.Filename = null; string name = System.IO.Path.Combine(path, fii.Filename); try { if (!System.IO.Directory.Exists(path)) { System.IO.Directory.CreateDirectory(path); } //make sure the sub xmls don't have a Filename fii.Path = ""; package.SavePackedFile(name, null, fii, true); fii.Path = null; xml += fii.GenerateXmlMetaInfo(); filecount++; } catch (Exception ex) { excount++; Helper.ExceptionMessage(Localization.Manager.GetString("errwritingfile") + " " + name, ex); if (excount >= 5) { if (Message.Show(Localization.Manager.GetString("ask000"), Localization.Manager.GetString("proceed"), System.Windows.Forms.MessageBoxButtons.YesNo) == System.Windows.Forms.DialogResult.Yes) { i = pfds.Length; } } } } //for i xml += "</package>" + Helper.lbr; System.IO.TextWriter tw = System.IO.File.CreateText(System.IO.Path.Combine(selpath, "package.xml")); try { tw.Write(xml); } catch (Exception ex) { Helper.ExceptionMessage(Localization.Manager.GetString("err001"), ex); } finally { tw.Close(); tw.Dispose(); tw = null; } } finally { if (!run) { WaitingScreen.Stop(); } } Message.Show(Localization.Manager.GetString("nfo000").Replace("{0}", filecount.ToString()), "Info", System.Windows.Forms.MessageBoxButtons.OK); }
public void Dispose() { _Writer?.Dispose(); }
void Run() { AddSemanticOperator(NoState, Neither, 0, NotApplic, "", "None", false); AddSemanticOperator(UnaryState, Neither, 0, NotApplic, "(", "PrecedenceGroupingParenthesis", false); // NB: // These two postfix operators materialize in the Binary State, however, they are unary operators! // This is reason for separate notion of state vs arity. AddSemanticOperator(BinaryState, Unary, 2, LeftRight, "++", "PostfixIncrement"); AddSemanticOperator(BinaryState, Unary, 2, LeftRight, "--", "PostfixDecrement"); AddSemanticOperator(BinaryState, Binary, 2, LeftRight, "(", "FunctionCall"); AddSemanticOperator(UnaryState, Neither, 0, NotApplic, ")", "EmptyArgumentList", false); AddSemanticOperator(BinaryState, Neither, 0, NotApplic, ")", "CloseParenOrArgList", false); AddSemanticOperator(BinaryState, Binary, 2, LeftRight, "[", "Subscript"); AddSemanticOperator(UnaryState, Neither, 0, NotApplic, "]", "EmptySubscript", false); AddSemanticOperator(BinaryState, Neither, 0, NotApplic, "]", "CloseSubscript", false); AddSemanticOperator(BinaryState, Binary, 2, LeftRight, ".", "Selection"); // binary but requires special parsing of right operand as member name AddSemanticOperator(BinaryState, Binary, 2, LeftRight, "->", "IndirectSelection"); // binary but required special parsing of right operand as member name AddSemanticOperator(UnaryState, Unary, 3, RightLeft, "++", "PrefixIncrement"); AddSemanticOperator(UnaryState, Unary, 3, RightLeft, "--", "PrefixDecrement"); AddSemanticOperator(UnaryState, Unary, 3, RightLeft, "+", "FixPoint"); AddSemanticOperator(UnaryState, Unary, 3, RightLeft, "-", "Negation"); AddSemanticOperator(UnaryState, Unary, 3, RightLeft, "!", "LogicalNot"); AddSemanticOperator(UnaryState, Unary, 3, RightLeft, "~", "BitwiseComplement"); AddSemanticOperator(UnaryState, Unary, 3, RightLeft, "*", "Indirection"); AddSemanticOperator(UnaryState, Unary, 3, RightLeft, "&", "AddressOf"); AddSemanticOperator(BinaryState, Binary, 4, LeftRight, ".*", "SelectionReference"); // binary but requires special parsing of right operand as member name AddSemanticOperator(BinaryState, Binary, 4, LeftRight, "->*", "IndirectSelectionReference"); // binary but required special parsing of right operand as member name AddSemanticOperator(BinaryState, Binary, 5, LeftRight, "*", "Multiplication"); AddSemanticOperator(BinaryState, Binary, 5, LeftRight, "/", "Division"); AddSemanticOperator(BinaryState, Binary, 5, LeftRight, "%", "Modulo"); AddSemanticOperator(BinaryState, Binary, 6, LeftRight, "+", "Addition"); AddSemanticOperator(BinaryState, Binary, 6, LeftRight, "-", "Subtraction"); AddSemanticOperator(BinaryState, Binary, 7, LeftRight, "<<", "BitwiseLeftShift"); AddSemanticOperator(BinaryState, Binary, 7, LeftRight, ">>", "BitwiseRightShift"); AddSemanticOperator(BinaryState, Binary, 8, LeftRight, "<=>", "Order"); AddSemanticOperator(BinaryState, Binary, 9, LeftRight, "<", "LessThan", true, "Relational"); AddSemanticOperator(BinaryState, Binary, 9, LeftRight, "<=", "LessOrEqual", true, "Relational"); AddSemanticOperator(BinaryState, Binary, 9, LeftRight, ">", "GreaterThan", true, "Relational"); AddSemanticOperator(BinaryState, Binary, 9, LeftRight, ">=", "GreaterOrEqual", true, "Relational"); AddSemanticOperator(BinaryState, Binary, 10, LeftRight, "==", "EqualEqual", true, "Relational"); AddSemanticOperator(BinaryState, Binary, 10, LeftRight, "!=", "NotEqual", true, "Relational"); AddSemanticOperator(BinaryState, Binary, 11, LeftRight, "&", "BitwiseAnd"); AddSemanticOperator(BinaryState, Binary, 12, LeftRight, "^", "BitwiseXor"); AddSemanticOperator(BinaryState, Binary, 13, LeftRight, "|", "BitwiseOr"); AddSemanticOperator(BinaryState, Binary, 14, LeftRight, "&&", "ShortCircutAnd"); AddSemanticOperator(BinaryState, Binary, 15, LeftRight, "||", "ShortCircutOr"); AddSemanticOperator(BinaryState, Binary, 16, RightLeft, "?", "TernaryTest", false); AddSemanticOperator(BinaryState, Ternary, 16, RightLeft, ":", "TernaryChoice"); AddSemanticOperator(BinaryState, Binary, 17, RightLeft, "=", "Assignment", true, "Assignment"); AddSemanticOperator(BinaryState, Binary, 17, RightLeft, "*=", "AssignmentMultiplication", true, "Assignment"); AddSemanticOperator(BinaryState, Binary, 17, RightLeft, "/=", "AssignmentDivision", true, "Assignment"); AddSemanticOperator(BinaryState, Binary, 17, RightLeft, "%=", "AssignmentModulo", true, "Assignment"); AddSemanticOperator(BinaryState, Binary, 17, RightLeft, "+=", "AssignmentAddition", true, "Assignment"); AddSemanticOperator(BinaryState, Binary, 17, RightLeft, "-=", "AssignmentSubtraction", true, "Assignment"); AddSemanticOperator(BinaryState, Binary, 17, RightLeft, "&=", "AssignmentBitwiseAnd", true, "Assignment"); AddSemanticOperator(BinaryState, Binary, 17, RightLeft, "^=", "AssignmentBitwiseXor", true, "Assignment"); AddSemanticOperator(BinaryState, Binary, 17, RightLeft, "|=", "AssignmentBitwiseOr", true, "Assignment"); AddSemanticOperator(BinaryState, Binary, 17, RightLeft, "<<=", "AssignmentBitwiseLeftShift", true, "Assignment"); AddSemanticOperator(BinaryState, Binary, 17, RightLeft, ">>=", "AssignmentBitwiseRightShift", true, "Assignment"); // We'll need two operators for this in our AST's, so we can tell the difference between // comma as an expression separator and comma as an argument separator after parsing. // Parsing removes ()'s and after parsing we'll still need to be able to differentiate // between a(x,y) which is a function call with two arguments, x and y, // and a((x,y)) which is a function call with one argument // (derived from the value of y after evalutating x) AddSemanticOperator(BinaryState, Binary, 18, LeftRight, ",", new [] { "ExpressionSeparator", "ArgumentSeparator" }); var namespacePath = "com.erikeidt.Draconum"; List <string> operators = new List <string> (); List <string> precedence = new List <string> (); List <string> arity = new List <string> (); List <string> treeNodes = new List <string> (); List <string> unaryOperators = new List <string> (); List <string> binaryOperators = new List <string> (); List <string> ternaryOperators = new List <string> (); List <Tuple <string, string> > unaryStateTokenSet = new List <Tuple <string, string> > (); List <Tuple <string, string> > binaryStateTokenSet = new List <Tuple <string, string> > (); foreach (var so in _semanticOperators) { foreach (var on in so.Names) { switch (so.Section) { case UnaryState: unaryStateTokenSet.Add(new Tuple <string, string> (so.Token, on)); break; case BinaryState: binaryStateTokenSet.Add(new Tuple <string, string> (so.Token, on)); break; } operators.Add(on); precedence.Add((so.Precedence * 2 + (so.Lr == RightLeft ? 0 : 1)).ToString()); if (so.HasTreeNodes) { treeNodes.Add("partial class " + on + "TreeNode : " + (so.BaseClass ?? so.Arity.ToString()) + "OperatorTreeNode {"); switch (so.Arity) { case Unary: arity.Add("1"); unaryOperators.Add("case " + on + ": " + "res = new " + on + "TreeNode ( op, arg ); break;"); treeNodes.Add("\tpublic " + on + "TreeNode ( Operator op, AbstractSyntaxTree arg ) : base ( op, arg ) { }"); break; case Binary: arity.Add("2"); binaryOperators.Add("case " + on + ": " + "res = new " + on + "TreeNode ( op, left, right ); break;"); treeNodes.Add("\tpublic " + on + "TreeNode ( Operator op, AbstractSyntaxTree left, AbstractSyntaxTree right ) : base ( op, left, right ) { }"); break; case Ternary: arity.Add("3"); ternaryOperators.Add("case " + on + ": " + "res = new " + on + "TreeNode ( op, pre, mid, post ); break;"); treeNodes.Add("\tpublic " + on + "TreeNode ( Operator op, AbstractSyntaxTree pre, AbstractSyntaxTree mid, AbstractSyntaxTree post ) : base ( op, pre, mid, post ) { }"); break; default: arity.Add("0"); break; } treeNodes.Add("}"); treeNodes.Add(null); } else { arity.Add("0"); } } } System.IO.TextWriter file = System.IO.File.CreateText(OutputFilePath + @"Operators.gen.cs"); SendStrings(file, "{0}", CopyrightText); file.WriteLine("namespace " + namespacePath + " {"); file.WriteLine("\tclass Operators {"); file.WriteLine("\t\tpublic enum Operator : byte {"); SendStrings(file, "\t\t\t{0},", operators); file.WriteLine("\t\t}"); file.WriteLine(); file.WriteLine("\t\tpublic static byte [] Precedence = {"); SendStrings(file, "\t\t\t{0},", precedence); file.WriteLine("\t\t};"); file.WriteLine(); file.WriteLine("\t\tpublic static byte [] Arity = {"); SendStrings(file, "\t\t\t{0},", arity); file.WriteLine("\t\t};"); file.WriteLine("\t}"); file.WriteLine("}"); file.Dispose(); file = System.IO.File.CreateText(OutputFilePath + @"ExpressionParser.gen.cs"); SendStrings(file, "{0}", CopyrightText); file.WriteLine(); file.WriteLine("namespace " + namespacePath + " {"); file.WriteLine("\tusing static Operators;"); file.WriteLine("\tusing static Operators.Operator;"); file.WriteLine(); file.WriteLine("\tpartial class ExpressionParser {"); file.WriteLine("\t\tpublic AbstractSyntaxTree BuildUnaryTreeNode ( Operator op )"); file.WriteLine("\t\t{"); file.WriteLine("\t\t\tvar arg = _operandStack.Pop ();"); file.WriteLine("\t\t\tvar res = (AbstractSyntaxTree) null;"); file.WriteLine("\t\t\tswitch ( op ) {"); SendStrings(file, "\t\t\t\t{0}", unaryOperators); file.WriteLine("\t\t\t}"); file.WriteLine("\t\t\treturn res;"); file.WriteLine("\t\t}"); file.WriteLine("\t\tpublic AbstractSyntaxTree BuildBinaryTreeNode ( Operator op )"); file.WriteLine("\t\t{"); file.WriteLine("\t\t\tvar right = _operandStack.Pop ();"); file.WriteLine("\t\t\tvar left = _operandStack.Pop ();"); file.WriteLine("\t\t\tvar res = (AbstractSyntaxTree) null;"); file.WriteLine("\t\t\tswitch ( op ) {"); SendStrings(file, "\t\t\t\t{0}", binaryOperators); file.WriteLine("\t\t\t}"); file.WriteLine("\t\t\treturn res;"); file.WriteLine("\t\t}"); file.WriteLine(); file.WriteLine("\t\tpublic AbstractSyntaxTree BuildTernaryTreeNode ( Operator op )"); file.WriteLine("\t\t{"); file.WriteLine("\t\t\tvar post = _operandStack.Pop ();"); file.WriteLine("\t\t\tvar mid = _operandStack.Pop ();"); file.WriteLine("\t\t\tvar pre = _operandStack.Pop ();"); file.WriteLine("\t\t\tvar res = (AbstractSyntaxTree) null;"); file.WriteLine("\t\t\tswitch ( op ) {"); SendStrings(file, "\t\t\t\t{0}", ternaryOperators); file.WriteLine("\t\t\t}"); file.WriteLine("\t\t\treturn res;"); file.WriteLine("\t\t}"); file.WriteLine("\t}"); file.WriteLine("}"); file.WriteLine(); file.WriteLine(); file.WriteLine("/*"); var soa = unaryStateTokenSet.ToArray(); Array.Sort(soa, TokenComparer); file.WriteLine("Unary State Tokens & Operators"); SendStrings(file, "\t\t{0}", Array.ConvertAll <Tuple <string, string>, string> (soa, x => x.Item1 + "\t" + x.Item2)); soa = binaryStateTokenSet.ToArray(); Array.Sort(soa, TokenComparer); file.WriteLine(); file.WriteLine("Binary State Tokens & Operators"); SendStrings(file, "\t\t{0}", Array.ConvertAll <Tuple <string, string>, string> (soa, x => x.Item1 + "\t" + x.Item2)); file.WriteLine("*/"); file.Dispose(); file = System.IO.File.CreateText(OutputFilePath + @"AbstractSyntaxTree.gen.cs"); SendStrings(file, "{0}", CopyrightText); file.WriteLine(); file.WriteLine("// ReSharper disable PartialTypeWithSinglePart"); file.WriteLine(); file.WriteLine("namespace " + namespacePath + " {"); file.WriteLine(" using static Operators;"); file.WriteLine(); SendStrings(file, "\t{0}", treeNodes); file.WriteLine("}"); file.Dispose(); }