public void WriteOutput(Stream o, UserVar u = null) { UserVar v = Output; if (OutType == OutputType.None) { return; } UserVar wr = (u != null && !u.IsNull()) ? u : new UserVar(o); if (!wr.IsNull()) { List <string> Out = new List <string>(); if (Output.Is(typeof(String[]))) { foreach (string s in Output.Get <string[]>()) { Out.Add(s); } } else if (Output.Is(typeof(String))) { Out.Add(Output.Get <string>()); } foreach (string a in Out) { Write(a, wr, u); } } }
public void Write(string f, UserVar v, UserVar ret = null) { FileInfo fi = null; if (IgnoreFileNames.Contains(f, StringComparer.InvariantCultureIgnoreCase)) { return; } try { fi = new FileInfo(f); } catch (Exception) { m.Error("Invalid file name"); return; } FileStream fil = null; UserVar wr = v; //MessageBox.Show(OutType.ToString()); if (OutType == OutputType.Write) { fil = fi.OpenWrite(); fil.SetLength(0); } if (OutType == OutputType.Append) { fil = (FileStream)fi.AppendText().BaseStream; } if (OutType == OutputType.Ret) { fil = fi.OpenWrite(); wr = ret == null ? new UserVar(new Null()) : ret; } if (v.Is(typeof(byte[]))) { byte[] bt = v.Get <byte[]>(); fil.Write(bt, 0, bt.Length); } else if (v.Is(typeof(string))) { byte[] bt = v.Get <string>().Select(a => (byte)a).ToArray(); fil.Write(bt, 0, bt.Length); } else if (v.Is(typeof(string[]))) { string[] s = v.Get <string[]>(); foreach (string str in s) { byte[] bt = str.Select(a => (byte)a).ToArray(); fil.Write(bt, 0, bt.Length); fil.WriteByte((byte)'\n'); } } else if (v.Is(typeof(MemoryStream))) { byte[] bt = v.Get <MemoryStream>().ToArray(); fil.Write(bt, 0, bt.Length); } else { byte[] bt = v.Get().ToString().Select(a => (byte)a).ToArray(); fil.Write(bt, 0, bt.Length); } fil.Flush(); fil.Close(); fil.Dispose(); fil = null; }