-
Notifications
You must be signed in to change notification settings - Fork 87
/
Helpfunctions.cs
144 lines (118 loc) · 3.47 KB
/
Helpfunctions.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
namespace HREngine.Bots
{
using System;
using System.Collections.Generic;
using System.IO;
using HREngine.API.Utilities;
/// <summary>
/// The helpfunctions.
/// </summary>
public class Helpfunctions
{
public static List<T> TakeList<T>(IEnumerable<T> source, int limit)
{
List<T> retlist = new List<T>();
int i = 0;
foreach (T item in source)
{
retlist.Add(item);
i++;
if (i >= limit) break;
}
return retlist;
}
public bool runningbot = false;
private static Helpfunctions instance;
public static Helpfunctions Instance
{
get
{
return instance ?? (instance = new Helpfunctions());
}
}
private Helpfunctions()
{
//System.IO.File.WriteAllText(Settings.Instance.logpath + Settings.Instance.logfile, "");
}
private bool writelogg = true;
public void loggonoff(bool onoff)
{
//writelogg = onoff;
}
public void createNewLoggfile()
{
//System.IO.File.WriteAllText(Settings.Instance.logpath + Settings.Instance.logfile, "");
}
public void logg(string s)
{
if (!writelogg) return;
try
{
using (StreamWriter sw = File.AppendText(Settings.Instance.logpath + Settings.Instance.logfile))
{
sw.WriteLine(s);
}
}
catch { }
//Console.WriteLine(s);
}
public DateTime UnixTimeStampToDateTime(int unixTimeStamp)
{
// Unix timestamp is seconds past epoch
System.DateTime dtDateTime = new DateTime(1970, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc);
dtDateTime = dtDateTime.AddSeconds(unixTimeStamp).ToLocalTime();
return dtDateTime;
}
public void ErrorLog(string s)
{
HREngine.API.Utilities.HRLog.Write(s);
//Console.WriteLine(s);
}
string sendbuffer = "";
public void resetBuffer()
{
this.sendbuffer = "";
}
public void writeToBuffer(string data)
{
this.sendbuffer += "\r\n" + data;
}
public void writeBufferToFile()
{
bool writed = true;
this.sendbuffer += "<EoF>";
while (writed)
{
try
{
System.IO.File.WriteAllText(Settings.Instance.path + "crrntbrd.txt", this.sendbuffer);
writed = false;
}
catch
{
writed = true;
}
}
this.sendbuffer = "";
}
public void writeBufferToActionFile()
{
bool writed = true;
this.sendbuffer += "<EoF>";
this.ErrorLog("write to action file: " + sendbuffer);
while (writed)
{
try
{
System.IO.File.WriteAllText(Settings.Instance.path + "actionstodo.txt", this.sendbuffer);
writed = false;
}
catch
{
writed = true;
}
}
this.sendbuffer = "";
}
}
}