/// <summary> /// Extended method for describing the node. It works more efficiently with strings /// and allows to describe a tree /// </summary> /// <param name="builder">Resulting string</param> /// <param name="node">Source node</param> /// <param name="level">Nesting level</param> public override void Describe(StringBuilder builder, Node node, int level) { if (node == null || builder == null) { return; } INodeDescriber describer = NodeDescriberFactory.GetDescriber(); Node firstChild = ((TwoChildrenNode)node).FirstChild; Node secondChild = ((TwoChildrenNode)node).SecondChild; this.AddIntent(builder, level); builder.Append($"new TwoChildrenNode(\"{node.Name}\""); if (firstChild != null) { builder.Append(",\n"); describer.Describe(builder, firstChild, level + 1); } if (secondChild != null) { builder.Append(",\n"); describer.Describe(builder, secondChild, level + 1); } builder.Append(")"); }
public Task WriteToFileAsync(Node node, string filePath) { NodeDescriber nd = new NodeDescriber(); Task t = Task.Factory.StartNew(() => { System.IO.File.WriteAllText(filePath, inodedes.Describe(node)); }); t.Wait(); return(t); }
public async Task WriteToFileAsync(Node node, string filePath) { var nodeDescriberText = _nodeDescriber.Describe(node); var encodedText = Encoding.Unicode.GetBytes(nodeDescriberText); using (var sourceStream = new FileStream(filePath, FileMode.Create, FileAccess.Write, FileShare.None, bufferSize: 4096, useAsync: true)) { await sourceStream.WriteAsync(encodedText, 0, encodedText.Length); }; }
public async Task WriteToFileAsync(Node node, string filePath) { var nodeDescription = _nodeDescriber.Describe(node); try { File.WriteAllText(filePath, nodeDescription); } catch (Exception e) { Console.WriteLine(e.ToString()); } }
public Task WriteToFileAsync(Node node, string filePath) { return(Task.Factory.StartNew(() => { INodeDescriber describer = NodeDescriberFactory.GetDescriber(); string text = describer.Describe(node); using (StreamWriter w = new StreamWriter(filePath)) { w.Write(text); } })); }
/// <summary> /// Extended method for describing the node. It works more efficiently with strings /// and allows to describe a tree /// </summary> /// <param name="builder">Resulting string</param> /// <param name="node">Source node</param> /// <param name="level">Nesting level</param> public void Describe(StringBuilder builder, Node node, int level) { if (node == null || builder == null) { return; } INodeDescriber describer = nodeToDescriber[node.GetType()]; if (describer == null) { throw new Exception("There is no describer for the node"); } describer.Describe(builder, node, level); }
public async Task WriteToFileAsync(Node node, string filePath) { try { //Todo: create file and folder if not exists if (!File.Exists(filePath)) { File.Create(filePath); } var txtResult = _nodeDescriber.Describe(node); //todo: clear the file before write using (StreamWriter outputFile = File.AppendText(filePath)) { await outputFile.WriteAsync(txtResult); } } catch (Exception ex) { throw ex; } }
public Task WriteToFileAsync(Node node, string filePath) { return(WriteToFileAsync(filePath, nodeDescriber.Describe(node))); }