-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #714 from JoshYuen/dump-pokemon-stats
Dump pokemon stats to file
- Loading branch information
Showing
7 changed files
with
96 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
#region using directives | ||
|
||
using System; | ||
using System.IO; | ||
using PoGo.NecroBot.Logic; | ||
using PoGo.NecroBot.Logic.State; | ||
|
||
#endregion | ||
|
||
namespace PoGo.NecroBot.Logic.DataDumper | ||
{ | ||
public static class Dumper | ||
{ | ||
private static IDumper _dumper; | ||
private static string _subPath; | ||
|
||
/// <summary> | ||
/// This is used for dumping contents to a file stored in the Logs folder. | ||
/// </summary> | ||
/// <param name="data">Dumps the string data to the file</param> | ||
/// <param name="filename">Filename to be used for naming the file.</param> | ||
private static void DumpToFile(Session ctx, string data, string filename) | ||
{ | ||
string path = Path.Combine(ctx.LogicSettings.ProfilePath,"Dumps",$"NecroBot-{filename}-{DateTime.Today.ToString("yyyy-MM-dd")}-{DateTime.Now.ToString("HH")}.txt"); | ||
|
||
using ( | ||
var dumpFile = | ||
File.AppendText(path) | ||
) | ||
{ | ||
dumpFile.WriteLine(data); | ||
dumpFile.Flush(); | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// Set the dumper. | ||
/// </summary> | ||
/// <param name="dumper"></param> | ||
public static void SetDumper(IDumper dumper, string subPath = "") | ||
{ | ||
_dumper = dumper; | ||
_subPath = subPath; | ||
} | ||
|
||
/// <summary> | ||
/// Clears the specified dumpfile. | ||
/// </summary> | ||
/// <param name="filename">File to clear/param> | ||
public static void ClearDumpFile(Session ctx, string filename) | ||
{ | ||
string path = Path.Combine(ctx.LogicSettings.ProfilePath,"Dumps",$"NecroBot-{filename}-{DateTime.Today.ToString("yyyy-MM-dd")}-{DateTime.Now.ToString("HH")}.txt"); | ||
// Clears all contents of a file first if overwrite is true | ||
File.WriteAllText(path, string.Empty); | ||
} | ||
|
||
/// <summary> | ||
/// Dumps data to a file | ||
/// </summary> | ||
/// <param name="data">Dumps the string data to the file</param> | ||
/// <param name="filename">Filename to be used for naming the file.</param> | ||
public static void Dump(Session ctx, string data, string filename) | ||
{ | ||
string uniqueFileName = $"{filename}"; | ||
|
||
DumpToFile(ctx, data, uniqueFileName); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
#region using directives | ||
|
||
using System; | ||
|
||
#endregion | ||
|
||
namespace PoGo.NecroBot.Logic.DataDumper | ||
{ | ||
public interface IDumper | ||
{ | ||
/// <summary> | ||
/// Dump specific data. | ||
/// </summary> | ||
/// <param name="data">The data to dump.</param> | ||
/// <param name="filename">File to dump to</param> | ||
void Dump(string data, string filename); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters