public override void GetContent(CompilerContext context, ParseTreeNode parseNode) { #region Get the optional type list if (parseNode.ChildNodes[1].HasChildNodes()) { _TypesToDump = ((parseNode.ChildNodes[1].ChildNodes[1].AstNode as TypeListNode).Types).Select(tlnode => tlnode.TypeName).ToList(); } #endregion _DumpType = (parseNode.ChildNodes[2].AstNode as DumpTypeNode).DumpType; _DumpFormat = (parseNode.ChildNodes[3].AstNode as DumpFormatNode).DumpFormat; _DumpableGrammar = context.Compiler.Language.Grammar as IDumpable; if (_DumpableGrammar == null) { throw new GraphDBException(new Error_NotADumpableGrammar(context.Compiler.Language.Grammar.GetType().ToString())); } if (parseNode.ChildNodes[4].HasChildNodes()) { _DumpDestination = parseNode.ChildNodes[4].ChildNodes[1].Token.ValueString; } }
public static void DumpToFile(this IDumpable dumpable, System.IO.StreamWriter file) { foreach (var currentString in dumpable.Dump()) { file.WriteLine(currentString); } }
private static IEnumerable <IDumpable> GetMembersRecursive(IDumpable dumpable) { yield return(dumpable); if (dumpable is DebugIndent indent) { foreach (var member in indent.Members) { foreach (var submember in GetMembersRecursive(member)) { yield return(submember); } } } if (dumpable is DebugBytecodeReader reader) { foreach (var member in reader.LocalMembers) { foreach (var submember in GetMembersRecursive(member)) { yield return(submember); } } } yield break; }
public static void Register(IDumpable dumper) { if (dumper != null) { DumpableMgr._list.Add(dumper); } }
public static void DumpToConsole(this IDumpable dumpable) { foreach (var currentString in dumpable.Dump()) { Console.WriteLine(currentString); } }
public void Init(ParsingContext context, ParseTreeNode parseNode) { #region Get the optional type list if (HasChildNodes(parseNode.ChildNodes[1])) { _TypesToDump = ((parseNode.ChildNodes[1].ChildNodes[1].AstNode as VertexTypeListNode).Types) .Select(tlnode => tlnode.TypeName).ToList(); } #endregion _DumpType = (parseNode.ChildNodes[2].AstNode as DumpTypeNode).DumpType; _DumpFormat = (parseNode.ChildNodes[3].AstNode as DumpFormatNode).DumpFormat; _DumpableGrammar = context.Parser.Language.Grammar as IDumpable; if (_DumpableGrammar == null) { throw new NotADumpableGrammarException(context.Parser.Language.Grammar.GetType().ToString(), ""); } if (HasChildNodes(parseNode.ChildNodes[4])) { _DumpDestination = parseNode.ChildNodes[4].ChildNodes[1].Token.ValueString; } }
public string Dump(string tag) { StringBuilder stringBuilder = new StringBuilder(); ISessionService service = Services.GetService <ISessionService>(); Diagnostics.Assert(service != null); if (this.InjectTestDesync) { Random random = new Random((int)DateTime.Now.Ticks); stringBuilder.AppendFormat("TEST_DESYNC_TOKEN = {0:x8}\r\n", random.Next()); } IDumpable dumpable = this.Game as IDumpable; dumpable.DumpAsText(stringBuilder, string.Empty); MD5 md = MD5.Create(); byte[] source = md.ComputeHash(Encoding.UTF8.GetBytes(stringBuilder.ToString())); string text = source.Aggregate(string.Empty, (string current, byte b) => current + b.ToString("x2")); string text2 = string.Empty; if (service.Session.SteamIDUser != Steamworks.SteamID.Zero) { text2 = Steamworks.SteamAPI.SteamFriends.GetFriendPersonaName(service.Session.SteamIDUser); text2 = text2.Replace(' ', '-'); char[] invalidFileNameChars = System.IO.Path.GetInvalidFileNameChars(); text2 = invalidFileNameChars.Aggregate(text2, (string current, char invalidChar) => current.Replace(invalidChar, '#')); } string path = string.Format("{0:D3}_{2}_{3}_0x{1}.dump", new object[] { this.Turn, text, tag, text2 }); string text3 = System.IO.Path.Combine(global::Application.DumpFilesDirectory, path); if (!Directory.Exists(global::Application.DumpFilesDirectory)) { Directory.CreateDirectory(global::Application.DumpFilesDirectory); } using (StreamWriter streamWriter = new StreamWriter(text3)) { streamWriter.Write(stringBuilder); } string key = string.Format("{0:D3}{1}", this.Turn, tag); if (!this.dumps.ContainsKey(key)) { this.dumps.Add(key, text3); } else { this.dumps[key] = text3; } Diagnostics.Log("[Dump] " + text3); return(text); }
private void AddMember(IDumpable member) { if (Indents.Count > 0) { Indents.Peek().Members.Add(member); } else { LocalMembers.Add(member); } AllMembers.Add(member); }
public virtual void WriteTo(TextWriter writer) { IDumpable dumpable = this.Value as IDumpable; if (dumpable != null) { dumpable.WriteTo(writer); } else { writer.WriteLine(this.Value); } }
private IEnumerable <IVertexView> Export(IDumpable myGrammar, IGraphDB myGraphDB, IGraphQL myGraphQL, SecurityToken mySecurityToken, Int64 myTransactionToken, IEnumerable <IVertexType> myVertexTypes, IEnumerable <IEdgeType> myEdgeTypes, DumpTypes myDumpType) { var dumpReadout = new Dictionary <String, Object>(); #region dump gddl if ((myDumpType & DumpTypes.GDDL) == DumpTypes.GDDL) { var graphDDL = myGrammar.ExportGraphDDL(DumpFormats.GQL, myVertexTypes, myEdgeTypes); if (graphDDL == null) { throw new ExportFailedException(myDumpType.ToString(), ""); } dumpReadout.Add("GDDL", new ListCollectionWrapper(graphDDL)); Write(DumpTypes.GDDL, graphDDL); } #endregion #region dump gdml if ((myDumpType & DumpTypes.GDML) == DumpTypes.GDML) { var graphDML = myGrammar.ExportGraphDML(DumpFormats.GQL, myVertexTypes, mySecurityToken, myTransactionToken); if (graphDML == null) { throw new ExportFailedException(myDumpType.ToString(), ""); } dumpReadout.Add("GDML", new ListCollectionWrapper(graphDML)); Write(DumpTypes.GDML, graphDML); } #endregion return(new IVertexView[] { new VertexView(dumpReadout, null) }); }
/// <summary> /// And this method can dump the result of a query /// </summary> /// <param name="queryResult"></param> internal static void Dump( QueryResult queryResult ) { LOGs.WriteLine( LogMessageType.MSG_SQL, "QueryResult: 查询结果开始:" ); foreach ( DataObject dataObject in queryResult ) { IDumpable dumpable = dataObject as IDumpable; if ( dumpable != null ) dumpable.Dump( Console.Out ); else LOGs.WriteLine( LogMessageType.MSG_SQL, "{0}, ID = {1}", dataObject.GetType().BaseType.Name, dataObject.ID ); } LOGs.WriteLine( LogMessageType.MSG_SQL, "QueryResult: 查询结果结束." ); }
public IEnumerable <IVertexView> Export(string destination, IDumpable myGrammar, IGraphDB myGraphDB, IGraphQL myGraphQL, SecurityToken mySecurityToken, Int64 myTransactionToken, IEnumerable <String> myVertexTypes, IEnumerable <String> myEdgeTypes, DumpTypes myDumpType) { _Destination = destination; try { #region Open destination OpenStream(destination); #endregion #region Start export using the AGraphDBExport implementation return(Export(myGrammar, myGraphDB, myGraphQL, mySecurityToken, myTransactionToken, GetVertexTypes(myGraphDB, mySecurityToken, myTransactionToken, myVertexTypes), GetEdgeTypes(myGraphDB, mySecurityToken, myTransactionToken, myEdgeTypes), myDumpType)); #endregion } finally { #region Close destination CloseStream(); #endregion } }
public override Exceptional Export(DBContext myDBContext, IDumpable myGrammar, IEnumerable<TypeManagement.GraphDBType> myTypes, DumpTypes myDumpType, VerbosityTypes verbosityType = VerbosityTypes.Errors) { var dumpReadout = new Dictionary<String, Object>(); if ((myDumpType & DumpTypes.GDDL) == DumpTypes.GDDL) { var graphDDL = myGrammar.ExportGraphDDL(DumpFormats.GQL, myDBContext, myTypes); if (!graphDDL.Success()) { return new Exceptional(graphDDL); } //dumpReadout.Add("GDDL", graphDDL.Value); var writeResult = Write(DumpTypes.GDDL, graphDDL.Value); if (!writeResult.Success()) { return writeResult; } } if ((myDumpType & DumpTypes.GDML) == DumpTypes.GDML) { var graphDML = myGrammar.ExportGraphDML(DumpFormats.GQL, myDBContext, myTypes); if (!graphDML.Success()) { return new Exceptional(graphDML); } //dumpReadout.Add("GDML", _GraphDML.Value); var writeResult = Write(DumpTypes.GDML, graphDML.Value); if (!writeResult.Success()) { return writeResult; } } return Exceptional.OK; }
public void Init(ParsingContext context, ParseTreeNode parseNode) { #region Get the optional type list if (HasChildNodes(parseNode.ChildNodes[1])) { _TypesToDump = ((parseNode.ChildNodes[1].ChildNodes[1].AstNode as VertexTypeListNode).Types) .Select(tlnode => tlnode.TypeName).ToList(); } #endregion _DumpType = (parseNode.ChildNodes[2].AstNode as DumpTypeNode).DumpType; _DumpFormat = (parseNode.ChildNodes[3].AstNode as DumpFormatNode).DumpFormat; _DumpableGrammar = context.Parser.Language.Grammar as IDumpable; if (_DumpableGrammar == null) throw new NotADumpableGrammarException(context.Parser.Language.Grammar.GetType().ToString(), ""); if (HasChildNodes(parseNode.ChildNodes[4])) _DumpDestination = parseNode.ChildNodes[4].ChildNodes[1].Token.ValueString; }
public QueryResult Export(String destination, DBContext myDBContext, IDumpable myGrammar, IEnumerable<String> myTypes, DumpTypes myDumpType, VerbosityTypes verbosityType = VerbosityTypes.Errors) { _Destination = destination; #region Open destination var openStreamResult = OpenStream(destination); if (!openStreamResult.Success()) { return new QueryResult(openStreamResult); } #endregion #region Start export using the AGraphDBImport implementation var result = Export(myDBContext, myGrammar, GetTypes(myDBContext, myTypes), myDumpType, verbosityType); #endregion #region Close destination var closeStreamResult = CloseStream(); if (!closeStreamResult.Success()) { return new QueryResult(openStreamResult); } #endregion if (!result.Success()) { return new QueryResult(result); } return new QueryResult(new List<Vertex>() { new Vertex(_DumpReadout) }); }
public string ComputeChecksum() { string result = string.Empty; ISessionService service = Services.GetService <ISessionService>(); Diagnostics.Assert(service != null); using (MemoryStream memoryStream = new MemoryStream()) { using (BinaryWriter binaryWriter = new BinaryWriter(memoryStream)) { if (this.InjectTestDesync) { Random random = new Random((int)DateTime.Now.Ticks); binaryWriter.Write(random.Next()); } IDumpable dumpable = this.Game as IDumpable; binaryWriter.Write(dumpable.DumpAsBytes()); MD5 md = MD5.Create(); byte[] source = md.ComputeHash(memoryStream.ToArray()); result = source.Aggregate(string.Empty, (string current, byte b) => current + b.ToString("x2")); } } return(result); }
private QueryResult Export(IDumpable myGrammar, IGraphDB myGraphDB, IGraphQL myGraphQL, SecurityToken mySecurityToken, TransactionToken myTransactionToken, IEnumerable<IVertexType> myTypes, DumpTypes myDumpType) { var dumpReadout = new Dictionary<String, Object>(); ASonesException error = null; #region dump gddl if ((myDumpType & DumpTypes.GDDL) == DumpTypes.GDDL) { var graphDDL = myGrammar.ExportGraphDDL(DumpFormats.GQL, myTypes); if (graphDDL == null) { throw new ExportFailedException(myDumpType.ToString(), ""); } dumpReadout.Add("GDDL", new ListCollectionWrapper(graphDDL)); try { Write(DumpTypes.GDDL, graphDDL); } catch (ASonesException e) { error = e; } } #endregion #region dump gdml if ((myDumpType & DumpTypes.GDML) == DumpTypes.GDML) { var graphDML = myGrammar.ExportGraphDML(DumpFormats.GQL, myTypes, mySecurityToken, myTransactionToken); if (graphDML == null) { throw new ExportFailedException(myDumpType.ToString(), ""); } dumpReadout.Add("GDML", new ListCollectionWrapper(graphDML)); try { Write(DumpTypes.GDML, graphDML); } catch (ASonesException e) { error = e; } } #endregion return new QueryResult("", ExportFormat, 0L, ResultType.Successful, new List<IVertexView> { new VertexView(dumpReadout, null) }, error); }
public abstract Exceptional Export(DBContext myDBContext, IDumpable myGrammar, IEnumerable<GraphDBType> myTypes, DumpTypes myDumpType, VerbosityTypes verbosityType = VerbosityTypes.Errors);
public static void Unregister(IDumpable dumper) { DumpableMgr._list.RemoveAll((IDumpable x) => x == dumper); }
public void WriteField(string name, IDumpable value) { this.WriteField(name, value, true); }
public void WriteField(string name, IDumpable value, bool writeNewLine) { this.OpenObject(name); value.Dump(this); this.CloseObject(writeNewLine); }
public void WriteField(string name, ICollection value) { this.OpenObject(name); foreach (object obj in (IEnumerable)value) { IDumpable dumpable = obj as IDumpable; if (dumpable != null) { this.WriteField("item", dumpable, false); } else if (obj is byte[]) { this.WriteField("item", (byte[])obj, false); } else if (obj is byte) { this.WriteField("item", (byte)obj, false); } else if (obj is ushort) { this.WriteField("item", (ushort)obj, false); } else if (obj is short) { this.WriteField("item", (short)obj, false); } else if (obj is uint) { this.WriteField("item", (uint)obj, false); } else if (obj is int) { this.WriteField("item", (int)obj, false); } else if (obj is ulong) { this.WriteField("item", (ulong)obj, false); } else if (obj is long) { this.WriteField("item", (long)obj, false); } else if (obj is float) { this.WriteField("item", (float)obj, false); } else if (obj is double) { this.WriteField("item", (double)obj, false); } else { if (!(obj is string)) { throw new ArgumentException(); } this.WriteField("item", (string)obj, false); } this.WriteLine(","); } this.CloseObject(); }
public QueryResult Export(string destination, IDumpable myGrammar, IGraphDB myGraphDB, IGraphQL myGraphQL, SecurityToken mySecurityToken, TransactionToken myTransactionToken, IEnumerable<String> myTypes, DumpTypes myDumpType) { _Destination = destination; ASonesException error = null; #region Open destination try { OpenStream(destination); } catch (ASonesException e) { error = e; } #endregion #region Start export using the AGraphDBExport implementation var result = Export(myGrammar, myGraphDB, myGraphQL, mySecurityToken, myTransactionToken, GetTypes(ref myGraphDB, ref mySecurityToken, ref myTransactionToken, myTypes), myDumpType); #endregion #region Close destination try { CloseStream(); } catch (ASonesException e) { error = e; } #endregion if(error != null) return new QueryResult("", ExportFormat, 0L, ResultType.Failed, result.Vertices, error); else return new QueryResult("", ExportFormat, 0L, result.TypeOfResult, result.Vertices); }
/// <summary> /// Dumps the IR object to a file. /// </summary> /// <param name="dumpable">The IR object to dump.</param> /// <param name="fileName">The target file name to write to.</param> public static void DumpToFile(this IDumpable dumpable, string fileName) { using var stream = new StreamWriter(fileName, false); dumpable.Dump(stream); }
/// <summary> /// Dumps the IR object to the console error output. /// </summary> /// <param name="dumpable">The IR object to dump.</param> public static void DumpToError(this IDumpable dumpable) => dumpable.Dump(Console.Error);
/// <summary> /// Dumps the IR object to the console output. /// </summary> /// <param name="dumpable">The IR object to dump.</param> public static void DumpToConsole(this IDumpable dumpable) => dumpable.Dump(Console.Out);
private IEnumerable<IVertexView> Export(IDumpable myGrammar, IGraphDB myGraphDB, IGraphQL myGraphQL, SecurityToken mySecurityToken, Int64 myTransactionToken, IEnumerable<IVertexType> myVertexTypes, IEnumerable<IEdgeType> myEdgeTypes, DumpTypes myDumpType) { var dumpReadout = new Dictionary<String, Object>(); #region dump gddl if ((myDumpType & DumpTypes.GDDL) == DumpTypes.GDDL) { var graphDDL = myGrammar.ExportGraphDDL(DumpFormats.GQL, myVertexTypes, myEdgeTypes); if (graphDDL == null) { throw new ExportFailedException(myDumpType.ToString(), ""); } dumpReadout.Add("GDDL", new ListCollectionWrapper(graphDDL)); Write(DumpTypes.GDDL, graphDDL); } #endregion #region dump gdml if ((myDumpType & DumpTypes.GDML) == DumpTypes.GDML) { var graphDML = myGrammar.ExportGraphDML(DumpFormats.GQL, myVertexTypes, mySecurityToken, myTransactionToken); if (graphDML == null) { throw new ExportFailedException(myDumpType.ToString(), ""); } dumpReadout.Add("GDML", new ListCollectionWrapper(graphDML)); Write(DumpTypes.GDML, graphDML); } #endregion return new IVertexView[] { new VertexView(dumpReadout, null) }; }
public IEnumerable<IVertexView> Export(string destination, IDumpable myGrammar, IGraphDB myGraphDB, IGraphQL myGraphQL, SecurityToken mySecurityToken, Int64 myTransactionToken, IEnumerable<String> myVertexTypes, IEnumerable<String> myEdgeTypes, DumpTypes myDumpType) { _Destination = destination; try { #region Open destination OpenStream(destination); #endregion #region Start export using the AGraphDBExport implementation return Export(myGrammar, myGraphDB, myGraphQL, mySecurityToken, myTransactionToken, GetVertexTypes(myGraphDB, mySecurityToken, myTransactionToken, myVertexTypes), GetEdgeTypes(myGraphDB, mySecurityToken, myTransactionToken, myEdgeTypes), myDumpType); #endregion } finally { #region Close destination CloseStream(); #endregion } }