/// ------------------------------------------------------------------------------------ /// <summary> /// Executes in two distinct scenarios. /// 1. If disposing is true, the method has been called directly /// or indirectly by a user's code via the Dispose method. /// Both managed and unmanaged resources can be disposed. /// 2. If disposing is false, the method has been called by the /// runtime from inside the finalizer and you should not reference (access) /// other managed objects, as they already have been garbage collected. /// Only unmanaged resources can be disposed. /// </summary> /// <param name="disposing"><c>true</c> to release both managed and unmanaged resources; /// <c>false</c> to release only unmanaged resources.</param> /// <remarks> /// If any exceptions are thrown, that is fine. /// If the method is being done in a finalizer, it will be ignored. /// If it is thrown by client code calling Dispose, /// it needs to be handled by fixing the bug. /// If subclasses override this method, they should call the base implementation. /// </remarks> /// ------------------------------------------------------------------------------------ protected virtual void Dispose(bool disposing) { System.Diagnostics.Debug.WriteLineIf(!disposing, "****** Missing Dispose() call for " + GetType().Name + ". ****** "); // Must not be run more than once. if (m_isDisposed) { return; } if (disposing) { WriteEvent("Logger shutting down"); // Dispose managed resources here. if (m_out != null) { m_out.InnerWriter.Dispose(); m_out.Dispose(); } } // Dispose unmanaged resources here, whether disposing is true or false. m_out = null; m_isDisposed = true; }
public void Dispose() { headerText.InnerWriter.Dispose(); cppText.InnerWriter.Dispose(); headerText?.Dispose(); cppText?.Dispose(); }
protected override void EndProcessing() { base.BeginProcessing(); try { try { if (Provider == null) { _provider.Dispose(); } } finally { if (Writer == null) { try { try { _indentedWriter.Flush(); _writer.Flush(); _writer.ToString(); } finally { _indentedWriter.Dispose(); } } finally { _writer.Dispose(); } } else if (!(Writer is IndentedTextWriter)) { try { _indentedWriter.Flush(); } finally { _indentedWriter.Dispose(); } } } } catch (Exception exc) { WriteError(new ErrorRecord(exc, "WriterCloseError", ErrorCategory.CloseError, null)); } }
/// <summary> /// アンマネージ リソースの解放およびリセットに関連付けられているアプリケーション定義のタスクを実行します。 /// </summary> /// <param name="disposing"> /// メソッドが <see cref="TypeScriptWriter.Dispose()" /> から呼び出された場合は <c>true</c>。その他の場合は <c>false</c>。 /// </param> protected virtual void Dispose(bool disposing) { if (IsDisposed) { return; } IsDisposed = true; if (disposing) { if (_Writer != _BaseWriter) { _Writer.Dispose(); } if (!_LeaveOpen) { _BaseWriter.Dispose(); } } }
public void Obfuscate() { Usings(); Writer.WriteLine($"namespace {_context.NameSpace}"); Writer.WriteLine("{"); Writer.Indent++; Writer.WriteLine($"public partial class {_context.ClassName}"); Writer.WriteLine("{"); Writer.Indent++; foreach (var literal in ParseLiterals(_context)) { WriteLiteral(literal); } Writer.Indent--; Writer.WriteLine("}"); Writer.Indent--; Writer.WriteLine("}"); Writer.Flush(); Writer.Dispose(); }
public void CloseWriter() { _Writer.InnerWriter.Dispose(); _Writer.Dispose(); }
public static void Build() { //scale of sizes of views and fonts from original iosMath examples const double scale = 1.5; const double viewHeightExtraScale = 1.25; var sb = new StringBuilder(); string text; using (var client = new WebClient()) text = client.DownloadString( @"https://raw.githubusercontent.com/kostub/iosMath/master/iosMathExample/example/ViewController.m"); text = Regex.Split(text, @"\[self setHeight:\d+ forView:contentView\];|- \(void\)didReceiveMemoryWarning")[1]; var regex = new Regex(@"(?# )self\.(?<label>(?:demoLabels|labels)\[\d+\] = )\[self createMathLabel:(?# )@(?<latex>(?:""[^""]*?""\s+)+?)withHeight:(?<height>\d+)\];|(?# )self\.(?<colorTarget>(?:demoLabels|labels)\[\d+\])\.backgroundColor = (?# )\[UIColor colorWithHue:(?<hue>\d+(?:\.\d+)?) (?# )saturation:(?<saturation>\d+(?:\.\d+)?) (?# )brightness:(?<brightness>\d+(?:\.\d+)?) alpha:(?<alpha>\d+(?:\.\d+)?)\];|(?# )self\.(?<sizeTarget>(?:demoLabels|labels)\[\d+\])\.fontSize = (?# )(?<size>\d+(?:\.\d+)?);|(?# )self\.(?<alignTarget>(?:demoLabels|labels)\[\d+\])\.textAlignment = (?# )kMTTextAlignment(?<align>\w+);|(?# )self\.(?<insetsTarget>(?:demoLabels|labels)\[\d+\])\.contentInsets = (?# )UIEdgeInsetsMake\(?<insets>([\d\s,]+)\);|(?# )self\.(?<styleTarget>(?:demoLabels|labels)\[\d+\])\.labelMode = (?# )kMTMathUILabelMode(?<style>\w+);|(?# )\n\s+//(?<comment>.+)", RegexOptions.Compiled); var writer = new IndentedTextWriter(new StringWriter(sb), " ") { Indent = 0, NewLine = Environment.NewLine } .AppendLine("//Do not modify this file directly. Instead, modify this at") .AppendLine("//CSharpMath\\CSharpMath.Playground\\iosMathDemo\\ToFormsMoreExamples.cs and re-generate") .AppendLine("//this file by executing the method in that file in the CSharpMath.Utils project.") .AppendLine() .AppendLine("using CSharpMath.Atom;") .AppendLine("using CSharpMath.Rendering.FrontEnd;") .AppendLine("using System.Collections.Generic;") .AppendLine("using System.Collections.ObjectModel;") .AppendLine("using System.Linq;") .AppendLine("using Color = Xamarin.Forms.Color;") .AppendLine() .AppendLine("namespace CSharpMath.Forms.Example {") .Indent() .AppendLine("[System.Diagnostics.DebuggerNonUserCode, System.Runtime.CompilerServices.CompilerGenerated]") .AppendLine("public static class MoreExamples {") .Indent() .AppendLine("public static ReadOnlyCollection<MathView> Views { get; }") .AppendLine("static MoreExamples() {") .Indent() .AppendLine("var demoLabels = new Dictionary<byte, MathView>();") .AppendLine("var labels = new Dictionary<byte, MathView>();"); foreach (var m in regex.Matches(text).AsEnumerable()) { if (!string.IsNullOrEmpty(m.Groups["label"].Value)) { writer .Append(m.Groups["label"].Value) .AppendLine("new MathView {") .Indent() .Append("LaTeX = @\"") .Append(new StringBuilder(m.Groups["latex"].Value) .Replace("\\\n ", "\n ") .Replace("\n ", Environment.NewLine + ' ') .Replace(@"\\", @"\") .Replace("\"", "").ToString().TrimEnd()) .AppendLine("\",") .Append("HeightRequest = ") .Append(int.Parse(m.Groups["height"].Value, System.Globalization.NumberFormatInfo.InvariantInfo) * scale * viewHeightExtraScale) .AppendLine(",") .Append("FontSize = ") .Append(15 * scale) .AppendLine("f") .Unindent() .AppendLine("};"); } else if (!string.IsNullOrEmpty(m.Groups["colorTarget"].Value)) { writer.Append(m.Groups["colorTarget"].Value) .Append(".BackgroundColor = Color.FromHsla(") .Append(m.Groups["hue"].Value) .Append(", ") .Append(m.Groups["saturation"].Value) .Append(", ") .Append(m.Groups["brightness"].Value) .Append(", ") .Append(m.Groups["alpha"].Value) .AppendLine(");"); } else if (!string.IsNullOrEmpty(m.Groups["sizeTarget"].Value)) { writer.Append(m.Groups["sizeTarget"].Value) .Append(".FontSize = ") .Append(m.Groups["size"].Value) .AppendLine(";"); } else if (!string.IsNullOrEmpty(m.Groups["alignTarget"].Value)) { writer.Append(m.Groups["alignTarget"].Value) .Append(".TextAlignment = TextAlignment.") .Append(m.Groups["align"].Value) .AppendLine(";"); } else if (!string.IsNullOrEmpty(m.Groups["insetsTarget"].Value)) { writer.Append(m.Groups["insetsTarget"].Value) .Append(".Padding = new Thickness(") .Append(m.Groups["insets"].Value) .AppendLine(");"); } else if (!string.IsNullOrEmpty(m.Groups["styleTarget"].Value)) { writer.Append(m.Groups["styleTarget"].Value) .Append(".LineStyle = LineStyle.") .Append(m.Groups["style"].Value) .AppendLine(";"); } else if (!string.IsNullOrEmpty(m.Groups["comment"].Value)) { writer.AppendLine() .Append(@"// ") .AppendLine(m.Groups["comment"].Value); } } writer.AppendLine() .Append("Views = demoLabels.Concat(labels)") .AppendLine(".Select(p => p.Value).ToList().AsReadOnly();") .Unindent() .AppendLine("}") .Unindent() .AppendLine("}") .Unindent() .AppendLine("}") .Unindent(); if (writer.Indent != 0) { throw new InvalidOperationException("Indents are not balanced."); } File.WriteAllText(Paths.iosMathExamplesFile, sb.ToString()); writer.Dispose(); }
public override string ToString() { var thisTState = this as TNFAState; bool firstOnStack = ToStringStack.Count == 0; if (ToStringStack.Contains(thisTState)) { return(string.Format("* ({0})", this.StateValue)); } ToStringStack.Add(thisTState); try { MemoryStream ms = new MemoryStream(); TextWriter tw = new StreamWriter(ms); IndentedTextWriter itw = new IndentedTextWriter(tw); itw.Indent++; if (this.OutTransitions != null && this.OutTransitions.Count > 0) { if (this.IsEdge) { itw.Write("<END>"); itw.WriteLine(); } foreach (var item in this.OutTransitions) { foreach (var subItem in item.Value) { string current = subItem.ToString(); string[] currentLines = current.Split(new string[] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries); itw.Write("{0}", item.Key); for (int i = 0; i < currentLines.Length; i++) { string line = currentLines[i]; if (subItem.IsEdge) { itw.Write("->{{{0}}}", subItem.StateValue); } else { itw.Write("->[{0}]", subItem.StateValue); } itw.Write(line.TrimStart()); itw.WriteLine(); } } } } else { itw.Write("<END>"); itw.WriteLine(); } itw.Indent--; itw.Flush(); TextReader sr = new StreamReader(ms); ms.Seek(0, SeekOrigin.Begin); string result = " " + sr.ReadToEnd(); itw.Close(); tw.Close(); sr.Close(); sr.Dispose(); tw.Dispose(); ms.Close(); ms.Dispose(); itw.Dispose(); if (firstOnStack) { result = string.Format("Regular State Count: {0}\r\n {{Start {1}}}", this.CountStates().ToString(), this.StateValue) + "\r\n" + result; } return(result); } finally { if (firstOnStack) { ToStringStack.Clear(); } } }
public void Dispose() { _indentWriter.Flush(); _indentWriter.Dispose(); }
public void Dispose() { _writer.Dispose(); }
public void Write(KScriptParser parser) { Out("About KScript"); Out("-----------------------------------------------"); Out($"Version: {Assembly.GetExecutingAssembly().GetName().Version.ToString()}"); Out("Supported Commands:"); IEnumerable <Type> q = from t in Assembly.GetExecutingAssembly().GetTypes() where t.IsClass && typeof(KScriptObject).IsAssignableFrom(t) && t.Namespace.StartsWith(KScript.Global.GlobalIdentifiers.ASSEMBLY_PATH) select t; IndentedTextWriter indentedTextWriter = new IndentedTextWriter(Console.Out) { Indent = 2 }; foreach (Type t in q.ToList()) { bool HideClass = t.GetCustomAttributes <KScriptHideObject>().Any(); bool HasNoInnerObjects = t.GetCustomAttributes <KScriptNoInnerObjects>().Any(); if (!HideClass) { indentedTextWriter.Indent = 0; indentedTextWriter.WriteLine(); for (int i = 0; i < Console.WindowWidth; i++) { indentedTextWriter.Write("="); } indentedTextWriter.WriteLine(); if (!HasNoInnerObjects) { indentedTextWriter.Write("< " + t.Name + " > ... </ " + t.Name + " >\n"); } else { indentedTextWriter.Write("< " + t.Name + " />\n"); } indentedTextWriter.Indent = 1; indentedTextWriter.WriteLine(); indentedTextWriter.WriteLine("[ Usage ] "); indentedTextWriter.Indent = 2; indentedTextWriter.WriteLine("Object Contents: " + (HasNoInnerObjects ? "Does not require inner elements or content." : "Inner elements or content are required.") + "\n"); indentedTextWriter.WriteLine(string.Format(parser.GetScriptObject(t).UsageInformation())); indentedTextWriter.WriteLine(); IEnumerable <PropertyInfo> properties = t.GetProperties().Where(p => p.CanWrite); int index = 0; if (properties.Any(p => p.GetCustomAttributes <KScriptProperty>().Any())) { indentedTextWriter.Indent = 1; indentedTextWriter.WriteLine("[ Arguments ]"); } foreach (PropertyInfo p in properties) { IEnumerable <KScriptProperty> Properties = p.GetCustomAttributes <KScriptProperty>(false); foreach (KScriptProperty prop in Properties) { indentedTextWriter.Indent = 2; indentedTextWriter.WriteLine("[" + ++index + "] - " + p.Name + (prop.IsRequired() ? " (required)" : "")); indentedTextWriter.Indent = 3; indentedTextWriter.WriteLine(prop.ToString()); IEnumerable <KScriptExample> Examples = p.GetCustomAttributes <KScriptExample>(false); int example_count = 0; if (Examples.Any()) { indentedTextWriter.WriteLine("[ Examples ]"); foreach (KScriptExample example in Examples) { indentedTextWriter.Indent = 4; indentedTextWriter.WriteLine(++example_count + " - " + example.ToString()); } } KScriptAcceptedOptions Accepted_Value = p.GetCustomAttribute <KScriptAcceptedOptions>(false); if (Accepted_Value != null) { indentedTextWriter.Indent = 3; indentedTextWriter.WriteLine("[ Accepted Values ]"); int val_count = 0; foreach (string item in Accepted_Value.GetValues()) { indentedTextWriter.Indent = 4; indentedTextWriter.WriteLine(++val_count + " - " + item); } } } } indentedTextWriter.WriteLine(); } } indentedTextWriter.Dispose(); Out(); Out(); }
public void Dispose() { baseWriter.Dispose(); Writer.Dispose(); }
public void Dispose() { Writer.Dispose(); }
/// <inheritdoc /> public void Dispose() { _writer.Dispose(); _indentedWriter.Dispose(); }