override public String GetCommandLine(ref String ResultLine) { String S = null; if (CommandBlock == null) { S = ""; if (!String.IsNullOrWhiteSpace(Name)) { ResultLine = "CommandBlock '" + Name + "' is empty"; } else { ResultLine = "CommandBlock is empty"; } CommandBlockName = null; } else if (LinesRead == 0) { if (OutputTracelevel.HasFlag(TraceLevels.FunctionEnterLeave)) { ResultLine = "Reading from '" + Name + "'"; } } if (CommandBlock != null) { S = CommandBlock.GetFirst(); if (S == null) { S = ""; if (OutputTracelevel.HasFlag(TraceLevels.FunctionEnterLeave)) { if (!String.IsNullOrEmpty(ResultLine)) { ResultLine += "\n"; } //resultLine += "End of CommandBlock '" + name + "'"; ResultLine += "End of '" + Name + "'"; } CommandBlock = null; CommandBlockName = null; } else { LinesRead++; } } return(S); }
override public String GetCommandLine(ref String ResultLine) { const String DefaultCalculatorScriptsSubdir = "Calculator Scripts"; String S = null; if (FileReader == null && !String.IsNullOrWhiteSpace(FileNameStr)) { if (!File.Exists(FileNameStr) && !Path.HasExtension(FileNameStr)) { FileNameStr += ".cal"; } if (!File.Exists(FileNameStr) && String.Compare(Path.GetPathRoot(FileNameStr), DefaultCalculatorScriptsSubdir, true) != 0 && Directory.Exists(DefaultCalculatorScriptsSubdir)) { FileNameStr = DefaultCalculatorScriptsSubdir + @"\" + FileNameStr; } try { //FileReader = File.OpenText(FileNameStr); //Encoding FileEncoding = Encoding.UTF8; //Encoding FileEncoding = Encoding.ASCII; //Encoding FileEncoding = Encoding.UTF7; FileReader = new StreamReader(FileNameStr, Encoding.UTF7); if (OutputTracelevel.HasFlag(TraceLevels.FileEnterLeave)) { ResultLine = "Reading from file " + FileNameStr; } } catch (DirectoryNotFoundException e) { S = ""; ResultLine = "Directory not found. " + e.Message; FileNameStr = null; } catch (FileNotFoundException e) { S = ""; ResultLine = "File '" + e.FileName + "' not found"; FileNameStr = null; } } if (FileReader != null) { S = FileReader.ReadLine(); if (S == null) { S = ""; if (OutputTracelevel.HasFlag(TraceLevels.FileEnterLeave)) { ResultLine = "End of File '" + FileNameStr + "'"; } FileReader.Close(); FileReader = null; FileNameStr = null; } else { LinesRead++; } } return(S); }
public String ListIdentifiers(Boolean forceListContextName = false, Boolean listNamedItems = false, Boolean listSettings = false) { StringBuilder ListStringBuilder = new StringBuilder(); Boolean HasItemsToShow = listNamedItems && (NamedItems.Count > 0); Boolean ListContextName = forceListContextName | HasItemsToShow | listSettings; String ListStr; if (OuterContext != null) { ListStr = OuterContext.ListIdentifiers(ListContextName, listNamedItems, listSettings); ListStringBuilder.Append(ListStr); ListStringBuilder.AppendLine(); } if (ListContextName) { if (OuterContext != null) { ListStringBuilder.AppendLine(); } ListStringBuilder.Append($"{Name}:"); if (listSettings) { ListStringBuilder.AppendLine(); ListStringBuilder.AppendLine("Settings"); switch (OutputTracelevel) { case TraceLevels.Debug: ListStr = "Debug"; break; case TraceLevels.Low: ListStr = "Low"; break; case TraceLevels.Normal: ListStr = "Normal"; break; case TraceLevels.High: ListStr = "High"; break; default: ListStr = OutputTracelevel.ToString(); break; } ListStringBuilder.Append($"Tracelevel = {ListStr}"); ListStringBuilder.AppendLine(); switch (FormatProviderSource) { case FormatProviderKind.InvariantFormatProvider: ListStr = "Invariant"; break; case FormatProviderKind.DefaultFormatProvider: ListStr = "Default"; break; case FormatProviderKind.InheritedFormatProvider: ListStr = "Inherited"; break; default: ListStr = FormatProviderSource.ToString(); break; } ListStringBuilder.Append($"FormatProvider = {ListStr}"); } if (HasItemsToShow) { ListStringBuilder.AppendLine(); if (listSettings) { ListStringBuilder.AppendLine("Items"); } ListStr = NamedItems.ListItems(); ListStringBuilder.Append(ListStr); } } return(ListStringBuilder.ToString()); }