Here are the examples of the csharp api System.Collections.Generic.List.ToArray() taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.
22147 Examples
19
Source : GaugeManager.Init.cs
with GNU Affero General Public License v3.0
from 0ceal0t
with GNU Affero General Public License v3.0
from 0ceal0t
private GaugeConfig[] AddMiscGauges(GaugeConfig[] configs, JobIds job, bool mp, float[] mpSegments, bool gcdRoll) {
var configList = new List<GaugeConfig>(configs);
var jobName = UIHelper.Localize(job);
if (mp) configList.Add(new GaugeMPConfig($"MP ({jobName})", GaugeVisualType.Bar, mpSegments, defaultDisabled:true));
if (gcdRoll) configList.Add(new GaugeRollingConfig($"GCD ({jobName})", GaugeVisualType.Bar));
return configList.ToArray();
}
19
Source : UIBuilder.Textures.cs
with GNU Affero General Public License v3.0
from 0ceal0t
with GNU Affero General Public License v3.0
from 0ceal0t
private void InitTextures() {
PluginLog.Log("LOADING TEXTURES");
var gaugeBuffLayout = new Dictionary<string, PartStruct[]>();
gaugeBuffLayout.Add("ui/uld/Parameter_Gauge.tex", new[] {
new PartStruct(0, 100, 160, 20), // GAUGE_BG_PART
new PartStruct(0, 0, 160, 20), // GAUGE_FRAME_PART
new PartStruct(10, 3, 10, 5), // GAUGE_SEPARATOR
new PartStruct(6, 40, 148, 20), // GAUGE_BAR_MAIN
});
gaugeBuffLayout.Add("ui/uld/JobHudNumBg.tex", new[] {
new PartStruct(0, 0, 60, 40), // GAUGE_TEXT_BLUR_PART
});
gaugeBuffLayout.Add("ui/uld/JobHudSimple_StackB.tex", new[] {
new PartStruct(0, 0, 32, 32), // ARROW_BG
new PartStruct(32, 0, 32, 32), // ARROW_FG
});
gaugeBuffLayout.Add("ui/uld/JobHudSimple_StackA.tex", new[] {
new PartStruct(0, 0, 32, 32), // DIAMOND_BG
new PartStruct(32, 0, 32, 32), // DIAMOND_FG
});
gaugeBuffLayout.Add("ui/uld/IconA_Frame.tex", new[] {
new PartStruct(252, 12, 47, 47), // BUFF_BORDER
new PartStruct(365, 4, 37, 37), // BUFF_OVERLAY
});
gaugeBuffLayout.Add("ui/uld/PartyListTargetBase.tex", new[] {
new PartStruct(112, 0, 48, 48) // BUFF_PARTYLIST
});
GaugeBuffreplacedets = UIHelper.LoadLayout(gaugeBuffLayout);
// ===================
var cdLayout = new Dictionary<string, PartStruct[]>();
cdLayout.Add("ui/uld/IconA_Frame.tex", new[] {
new PartStruct(0, 96, 48, 48), // CD_BORDER
new PartStruct(96, 0, 48, 48), // CD_DASH_START
new PartStruct(144, 0, 48, 48),
new PartStruct(192, 0, 48, 48),
new PartStruct(96, 48, 48, 48),
new PartStruct(144, 48, 48, 48),
new PartStruct(192, 48, 48, 48),
new PartStruct(96, 96, 48, 48),
});
Cooldownreplacedets = UIHelper.LoadLayout(cdLayout);
// ==================
List<PartStruct> cursorParts = new();
var cursorLayout = new Dictionary<string, PartStruct[]>();
for (int idx = 0; idx < 80; idx++) {
var row = idx % 9;
var column = (idx - row) / 9;
cursorParts.Add(new PartStruct((ushort)(44 * row), (ushort)(48 * column), 44, 46));
}
cursorLayout.Add("ui/uld/IconA_Recast2.tex", cursorParts.ToArray());
cursorLayout.Add("ui/uld/CursorLocation.tex", new[] {
new PartStruct(0, 0, 128, 128)
});
Cursorreplacedets = UIHelper.LoadLayout(cursorLayout);
}
19
Source : DBHelperMySQL.cs
with Apache License 2.0
from 0nise
with Apache License 2.0
from 0nise
public static string GetContent(string sql,List<MySqlParameter> parameter,string content)
{
string resultStr = "";
if (content == "" || "".Equals(content)|| content.Length == 0 || content == null) {
content = "\n【文章】";
}
MySqlConnection connection = new MySqlConnection(Constants.connectionStr);
try
{
connection.Open();
MySqlCommand mySqlCommand = new MySqlCommand(sql,connection);
// 添加参数
if (parameter.Count > 0)
{
mySqlCommand.Parameters.AddRange(parameter.ToArray());
}
// 提取数据
MySqlDataReader myDataReader = mySqlCommand.ExecuteReader();
while (myDataReader.Read()==true)
{
string tmpStr = content + myDataReader["replacedle"]+"\n"+ myDataReader["url"]+"\n";
resultStr += tmpStr;
}
myDataReader.Close();
}
catch (Exception e)
{
throw e;
}
finally {
connection.Close();
}
return resultStr;
}
19
Source : DBHelperMySQL.cs
with Apache License 2.0
from 0nise
with Apache License 2.0
from 0nise
private static string geClreplaced(string sql, List<MySqlParameter> parameter) {
string resultStr = "";
MySqlConnection connection = new MySqlConnection(Constants.connectionStr);
try
{
connection.Open();
MySqlCommand mySqlCommand = new MySqlCommand(sql, connection);
// 添加参数
if (parameter.Count > 0)
{
mySqlCommand.Parameters.AddRange(parameter.ToArray());
}
// 提取数据
MySqlDataReader myDataReader = mySqlCommand.ExecuteReader();
while (myDataReader.Read() == true)
{
string tmpStr = "\n【课程】" + myDataReader["clreplaced_name"] + "\n" + myDataReader["clreplaced_url"] + "\n";
resultStr += tmpStr;
}
myDataReader.Close();
}
catch (Exception e)
{
throw e;
}
finally
{
connection.Close();
}
return resultStr;
}
19
Source : DBHelperMySQL.cs
with Apache License 2.0
from 0nise
with Apache License 2.0
from 0nise
public static string GetContent(string sql, List<MySqlParameter> parameter, string content)
{
string resultStr = "";
if (content == "" || "".Equals(content) || content.Length == 0 || content == null)
{
content = "\n【文章】";
}
MySqlConnection connection = null;
try
{
connection = ConnectionPool.getPool().getConnection();
using (MySqlCommand mySqlCommand = new MySqlCommand(sql, connection))
{
// 添加参数
if (parameter.Count > 0)
{
mySqlCommand.Parameters.AddRange(parameter.ToArray());
}
// 提取数据
using (MySqlDataReader myDataReader = mySqlCommand.ExecuteReader())
{
while (myDataReader.Read() == true)
{
string tmpStr = content + myDataReader["replacedle"] + "\n" + myDataReader["url"] + "\n";
resultStr += tmpStr;
}
}
}
}
catch (Exception e)
{
throw e;
}
finally
{
if (connection != null)
{
connection.Close();
}
// 关闭数据库链接
ConnectionPool.getPool().closeConnection(connection);
}
return resultStr;
}
19
Source : DBHelperMySQL.cs
with Apache License 2.0
from 0nise
with Apache License 2.0
from 0nise
private static string geClreplaced(string sql, List<MySqlParameter> parameter)
{
string resultStr = "";
MySqlConnection connection = null;
try
{
connection = ConnectionPool.getPool().getConnection();
using (MySqlCommand mySqlCommand = new MySqlCommand(sql, connection))
{
// 添加参数
if (parameter.Count > 0)
{
mySqlCommand.Parameters.AddRange(parameter.ToArray());
}
// 提取数据
using (MySqlDataReader myDataReader = mySqlCommand.ExecuteReader())
{
while (myDataReader.Read() == true)
{
string tmpStr = "\n【课程】" + myDataReader["clreplaced_name"] + "\n" + myDataReader["clreplaced_url"] + "\n";
resultStr += tmpStr;
}
}
}
}
catch (Exception e)
{
throw e;
}
finally
{
if (connection != null)
{
connection.Close();
}
// 关闭数据库链接
ConnectionPool.getPool().closeConnection(connection);
}
return resultStr;
}
19
Source : DBHelperMySQL.cs
with Apache License 2.0
from 0nise
with Apache License 2.0
from 0nise
public static void addUserData(string qq, string content, string msg)
{
string sql = "INSERT INTO ichunqiu_user(id,user_qq,content,send_msg,create_date,update_date) VALUES(DEFAULT,@qq,@content,@msg,NOW(),NOW())";
var parameter = new List<MySqlParameter>();
parameter.Add(new MySqlParameter("@qq", qq));
parameter.Add(new MySqlParameter("@content", content));
parameter.Add(new MySqlParameter("@msg", msg));
MySqlConnection connection = null;
try
{
connection = ConnectionPool.getPool().getConnection();
// 链接为null就执行等待
while (connection == null)
{
}
using (MySqlCommand cmd = new MySqlCommand(sql,connection))
{
// 添加参数
if (parameter.Count > 0)
{
cmd.Parameters.AddRange(parameter.ToArray());
}
cmd.ExecuteNonQuery();
}
}
catch (Exception)
{
throw;
}
finally
{
if (connection != null)
{
connection.Close();
}
ConnectionPool.getPool().closeConnection(connection);
}
}
19
Source : CelesteNetServer.cs
with MIT License
from 0x0ade
with MIT License
from 0x0ade
public void Dispose() {
if (!IsAlive)
return;
Logger.Log(LogLevel.CRI, "main", "Shutdown");
IsAlive = false;
ModulesFSWatcher.Dispose();
lock (Modules) {
foreach (CelesteNetServerModuleWrapper wrapper in ModuleWrappers.ToArray()) {
wrapper.Unload();
}
}
Channels.Dispose();
TCPUDP.Dispose();
ConLock.Dispose();
UserData.Dispose();
Data.Dispose();
}
19
Source : Channels.cs
with MIT License
from 0x0ade
with MIT License
from 0x0ade
public void SendListTo(CelesteNetPlayerSession session) {
Channel own = session.Channel;
List<DataChannelList.Channel> channels;
lock (All) {
channels = new(All.Count);
foreach (Channel c in All) {
if (c.IsPrivate && c != own)
continue;
uint[] players;
using (c.Lock.R()) {
players = new uint[c.Players.Count];
int i = 0;
foreach (CelesteNetPlayerSession p in c.Players)
players[i++] = p.ID;
}
channels.Add(new DataChannelList.Channel {
Name = c.Name,
ID = c.ID,
Players = players
});
}
}
session.Con.Send(new DataChannelList {
List = channels.ToArray()
});
}
19
Source : SqliteUserData.cs
with MIT License
from 0x0ade
with MIT License
from 0x0ade
public override T[] LoadAll<T>() {
using UserDataBatchContext batch = OpenBatch();
string table = GetDataTable(typeof(T), false);
if (table.IsNullOrEmpty())
return Dummy<T>.EmptyArray;
using MiniCommand mini = new(this) {
SqliteOpenMode.ReadOnly,
@$"
SELECT format, value
FROM [{table}];
",
};
(SqliteConnection con, SqliteCommand cmd, SqliteDataReader reader) = mini.Read();
List<T> values = new();
while (reader.Read()) {
switch ((DataFormat) reader.GetInt32(0)) {
case DataFormat.MessagePack:
default: {
using Stream stream = reader.GetStream(1);
values.Add(MessagePackSerializer.Deserialize<T>(stream, MessagePackHelper.Options) ?? new());
break;
}
case DataFormat.Yaml: {
using Stream stream = reader.GetStream(1);
using StreamReader streamReader = new(stream);
values.Add(YamlHelper.Deserializer.Deserialize<T>(streamReader) ?? new());
break;
}
}
}
return values.ToArray();
}
19
Source : BuffManager.cs
with GNU Affero General Public License v3.0
from 0ceal0t
with GNU Affero General Public License v3.0
from 0ceal0t
public BuffConfig[] GetBuffConfigs(JobIds job, bool isLocalPlayer) {
var jobBuffs = JobToValue.TryGetValue(job, out var props) ? props : JobToValue[JobIds.OTHER];
if (!isLocalPlayer) return jobBuffs;
var combinedProps = new List<BuffConfig>();
combinedProps.AddRange(LocalPlayerConfigs);
combinedProps.AddRange(jobBuffs.Where(x => !x.IsPlayerOnly));
return combinedProps.ToArray();
}
19
Source : UiHelper.Data.cs
with GNU Affero General Public License v3.0
from 0ceal0t
with GNU Affero General Public License v3.0
from 0ceal0t
private static void SetupSheets() {
JobToString = new();
ItemToString = new();
ActionSheet = JobBars.DataManager.GetExcelSheet<Lumina.Excel.GeneratedSheets.Action>().Where(
x => !string.IsNullOrEmpty(x.Name) && (x.IsPlayerAction || x.ClreplacedJob.Value != null) && !x.IsPvP // weird conditions to catch things like enchanted RDM spells
);
foreach (var item in ActionSheet) {
var name = item.Name.ToString();
var attackType = item.ActionCategory.Value.Name.ToString();
var actionId = item.ActionCategory.Value.RowId;
if (item.Icon != 405 && item.Icon != 0) ActionToIcon[item.RowId] = item.Icon;
if (actionId == 2 || actionId == 3) { // spell or weaponskill
if (item.CooldownGroup != 58 && item.AdditionalCooldownGroup != 58) continue; // not actually a gcd
GCDs.Add(item.RowId);
}
}
List<StatusNameId> statusList = new();
StatusSheet = JobBars.DataManager.GetExcelSheet<Lumina.Excel.GeneratedSheets.Status>().Where(x => !string.IsNullOrEmpty(x.Name));
foreach (var item in StatusSheet) {
statusList.Add(new StatusNameId {
Name = item.Name,
Status = new Item {
Id = item.RowId,
Type = ItemType.Buff
}
});
}
StatusNames = statusList.ToArray();
JobSheet = JobBars.DataManager.GetExcelSheet<ClreplacedJob>().Where(x => x.Name != null);
}
19
Source : DBHelperMySQL.cs
with Apache License 2.0
from 0nise
with Apache License 2.0
from 0nise
public static bool isAdmin(string qq)
{
bool flag = false;
string sql = "SELECT qq FROM ichunqiu_admin WHERE qq = @qq";
var parameter = new List<MySqlParameter>
{
new MySqlParameter("@qq", qq)
};
MySqlConnection connection = null;
try
{
connection = ConnectionPool.getPool().getConnection();
while (connection == null)
{
}
using (MySqlCommand mySqlCommand = new MySqlCommand(sql, connection))
{
// 添加参数
if (parameter.Count > 0)
{
mySqlCommand.Parameters.AddRange(parameter.ToArray());
}
// 提取数据
using (MySqlDataReader myDataReader = mySqlCommand.ExecuteReader())
{
int count = 0;
while (myDataReader.Read() == true)
{
count++;
}
if (count > 0)
{
flag = true;
}
}
}
}
catch (Exception)
{
flag = false;
}
finally
{
if (connection != null)
{
connection.Close();
}
// 关闭数据库链接
ConnectionPool.getPool().closeConnection(connection);
}
return flag;
}
19
Source : DBHelperMySQL.cs
with Apache License 2.0
from 0nise
with Apache License 2.0
from 0nise
public static string getBlankMoney(string qq)
{
string sql = "SELECT user_money FROM ichunqiu_blank WHERE user_qq = @qq";
var parameter = new List<MySqlParameter>();
string userMoney = "";
parameter.Add(new MySqlParameter("@qq", qq));
MySqlConnection connection = null;
try
{
connection = ConnectionPool.getPool().getConnection();
while (connection == null)
{
}
using (MySqlCommand mySqlCommand = new MySqlCommand(sql, connection))
{
// 添加参数
if (parameter.Count > 0)
{
mySqlCommand.Parameters.AddRange(parameter.ToArray());
}
// 提取数据
using (MySqlDataReader myDataReader = mySqlCommand.ExecuteReader())
{
while (myDataReader.Read() == true)
{
userMoney = myDataReader["user_money"].ToString();
break;
}
}
}
}
catch (Exception e)
{
throw e;
}
finally
{
if (connection != null)
{
connection.Close();
}
// 关闭数据库链接
ConnectionPool.getPool().closeConnection(connection);
}
return userMoney;
}
19
Source : DBHelperMySQL.cs
with Apache License 2.0
from 0nise
with Apache License 2.0
from 0nise
public static string getBlankHistory(string qq)
{
string sql = "SELECT money,create_date FROM ichunqiu_blank_history WHERE user_qq = @qq AND operation = '0' ;";
var parameter = new List<MySqlParameter>();
string resultStr = "";
parameter.Add(new MySqlParameter("@qq", qq));
MySqlConnection connection = null;
try
{
connection = ConnectionPool.getPool().getConnection();
while (connection == null)
{
}
using (MySqlCommand mySqlCommand = new MySqlCommand(sql, connection))
{
// 添加参数
if (parameter.Count > 0)
{
mySqlCommand.Parameters.AddRange(parameter.ToArray());
}
// 提取数据
using (MySqlDataReader myDataReader = mySqlCommand.ExecuteReader())
{
while (myDataReader.Read() == true)
{
resultStr += myDataReader["money"].ToString() + "\t" + myDataReader["create_date"] + "\n";
}
}
}
}
catch (Exception e)
{
throw e;
}
finally
{
if (connection != null)
{
connection.Close();
}
// 关闭数据库链接
ConnectionPool.getPool().closeConnection(connection);
}
return resultStr;
}
19
Source : DBHelperMySQL.cs
with Apache License 2.0
from 0nise
with Apache License 2.0
from 0nise
public static bool exitsUser(string qq)
{
MySqlConnection connection = null;
bool resultFlag = false;
try
{
connection = ConnectionPool.getPool().getConnection();
// 链接为null就执行等待
while (connection == null)
{
}
string sql = "SELECT user_money FROM ichunqiu_blank WHERE user_qq = @qq";
var parameter = new List<MySqlParameter>();
parameter.Add(new MySqlParameter("@qq", qq));
using (MySqlCommand cmd = new MySqlCommand(sql, connection))
{
if (parameter.Count > 0)
{
cmd.Parameters.AddRange(parameter.ToArray());
}
using (MySqlDataReader myDataReader = cmd.ExecuteReader())
{
while (myDataReader.Read() == true)
{
resultFlag = true;
break;
}
}
}
}
catch (Exception)
{
throw;
}
finally
{
if (connection != null)
{
connection.Close();
}
// 关闭数据库链接
ConnectionPool.getPool().closeConnection(connection);
}
return resultFlag;
}
19
Source : DBHelperMySQL.cs
with Apache License 2.0
from 0nise
with Apache License 2.0
from 0nise
public static string getBlankMoney(string qq) {
string sql = "SELECT user_money FROM ichunqiu_blank WHERE user_qq = @qq";
var parameter = new List<MySqlParameter>();
string userMoney = "";
parameter.Add(new MySqlParameter("@qq",qq));
MySqlConnection connection = new MySqlConnection(Constants.connectionStr);
try
{
connection.Open();
MySqlCommand mySqlCommand = new MySqlCommand(sql, connection);
// 添加参数
if (parameter.Count > 0)
{
mySqlCommand.Parameters.AddRange(parameter.ToArray());
}
// 提取数据
MySqlDataReader myDataReader = mySqlCommand.ExecuteReader();
while (myDataReader.Read() == true)
{
userMoney = myDataReader["user_money"].ToString();
break;
}
myDataReader.Close();
}
catch (Exception e)
{
throw e;
}
finally
{
connection.Close();
}
return userMoney;
}
19
Source : DBHelperMySQL.cs
with Apache License 2.0
from 0nise
with Apache License 2.0
from 0nise
public static string getBlankHistory(string qq) {
string sql = "SELECT money,create_date FROM ichunqiu_blank_history WHERE user_qq = @qq";
var parameter = new List<MySqlParameter>();
string resultStr = "";
parameter.Add(new MySqlParameter("@qq", qq));
MySqlConnection connection = new MySqlConnection(Constants.connectionStr);
try
{
connection.Open();
MySqlCommand mySqlCommand = new MySqlCommand(sql, connection);
// 添加参数
if (parameter.Count > 0)
{
mySqlCommand.Parameters.AddRange(parameter.ToArray());
}
// 提取数据
MySqlDataReader myDataReader = mySqlCommand.ExecuteReader();
while (myDataReader.Read() == true)
{
resultStr += myDataReader["money"].ToString()+"\t"+ myDataReader["create_date"]+"\n";
}
myDataReader.Close();
}
catch (Exception e)
{
throw e;
}
finally
{
connection.Close();
}
return resultStr;
}
19
Source : DBHelperMySQL.cs
with Apache License 2.0
from 0nise
with Apache License 2.0
from 0nise
public static void addUserData(string qq,string content,string msg) {
string sql = "INSERT INTO ichunqiu_user(id,user_qq,content,send_msg,create_date,update_date) VALUES(DEFAULT,@qq,@content,@msg,NOW(),NOW())";
var parameter = new List<MySqlParameter>();
parameter.Add(new MySqlParameter("@qq", qq));
parameter.Add(new MySqlParameter("@content", content));
parameter.Add(new MySqlParameter("@msg", msg));
MySqlConnection connection = new MySqlConnection(Constants.connectionStr);
try
{
connection.Open();
MySqlCommand mySqlCommand = new MySqlCommand(sql, connection);
// 添加参数
if (parameter.Count > 0)
{
mySqlCommand.Parameters.AddRange(parameter.ToArray());
}
mySqlCommand.ExecuteNonQuery();
}
catch (Exception)
{
throw;
}
finally
{
connection.Close();
}
}
19
Source : DBHelperMySQL.cs
with Apache License 2.0
from 0nise
with Apache License 2.0
from 0nise
public static string updateBlank(string qq, decimal money,string operation)
{
string resultStr = "";
string sql = "UPDATE ichunqiu_blank SET user_money = user_money - @user_money WHERE user_qq =@qq ";
// 加钱
if ("1".Equals(operation))
{
sql = "UPDATE ichunqiu_blank SET user_money = user_money + @user_money WHERE user_qq =@qq ";
}
else
{
string tmpMoney = getBlankMoney(qq);
if (tmpMoney != null && tmpMoney.Length > 0)
{
if (Convert.ToDecimal(tmpMoney) < money)
{
return "提现金额必须小于存款金额。";
}
}
else
{
return "没有该作家!";
}
}
var parameter = new List<MySqlParameter>();
parameter.Add(new MySqlParameter("@user_money", money));
parameter.Add(new MySqlParameter("@qq", qq));
MySqlConnection connection = null;
try
{
connection = ConnectionPool.getPool().getConnection();
while (connection == null)
{
}
using (MySqlCommand mySqlCommand = new MySqlCommand(sql, connection))
{
// 添加参数
if (parameter.Count > 0)
{
mySqlCommand.Parameters.AddRange(parameter.ToArray());
}
// 提取数据
int count = mySqlCommand.ExecuteNonQuery();
// 执行数据插入
int flagCount = inserMoneyHistory(qq, money, operation);
if (count > 0 && flagCount > 0)
{
resultStr = "更新成功!";
}
else
{
resultStr = "更新失败!";
}
}
}
catch (Exception)
{
throw;
}
finally
{
if (connection != null)
{
connection.Close();
}
// 关闭数据库链接
ConnectionPool.getPool().closeConnection(connection);
}
return resultStr;
}
19
Source : DBHelperMySQL.cs
with Apache License 2.0
from 0nise
with Apache License 2.0
from 0nise
public static int inserMoneyHistory(string qq, decimal money,string operation)
{
string sql = "INSERT INTO ichunqiu_blank_history(id,user_qq,money,operation,create_date,update_date) VALUES(DEFAULT,@qq,@user_money,@operation,NOW(),NOW())";
var parameter = new List<MySqlParameter>();
int count = 0;
parameter.Add(new MySqlParameter("@user_money", money));
parameter.Add(new MySqlParameter("@qq", qq));
parameter.Add(new MySqlParameter("@operation", operation));
MySqlConnection connection = null;
try
{
connection = ConnectionPool.getPool().getConnection();
// 链接为null就执行等待
while (connection == null)
{
}
using (MySqlCommand mySqlCommand = new MySqlCommand(sql, connection))
{
// 添加参数
if (parameter.Count > 0)
{
mySqlCommand.Parameters.AddRange(parameter.ToArray());
}
// 提取数据
count = mySqlCommand.ExecuteNonQuery();
}
}
catch (Exception)
{
count = 0;
}
finally
{
if (connection != null)
{
connection.Close();
}
ConnectionPool.getPool().closeConnection(connection);
}
return count;
}
19
Source : DBHelperMySQL.cs
with Apache License 2.0
from 0nise
with Apache License 2.0
from 0nise
public static bool isAdmin(string qq) {
bool flag = false;
string sql = "SELECT qq FROM ichunqiu_admin WHERE qq = @qq";
var parameter = new List<MySqlParameter>
{
new MySqlParameter("@qq", qq)
};
MySqlConnection connection = new MySqlConnection(Constants.connectionStr);
try
{
connection.Open();
MySqlCommand mySqlCommand = new MySqlCommand(sql, connection);
// 添加参数
if (parameter.Count > 0)
{
mySqlCommand.Parameters.AddRange(parameter.ToArray());
}
// 提取数据
MySqlDataReader myDataReader = mySqlCommand.ExecuteReader();
int count = 0;
while (myDataReader.Read() == true)
{
count++;
}
if (count > 0)
{
flag = true;
}
myDataReader.Close();
}
catch (Exception)
{
flag = false;
}
finally
{
connection.Close();
}
return flag;
}
19
Source : DBHelperMySQL.cs
with Apache License 2.0
from 0nise
with Apache License 2.0
from 0nise
public static string updateBlank(string qq,decimal money) {
string sql = "UPDATE ichunqiu_blank SET user_money = user_money - @user_money WHERE user_qq =@qq ";
var parameter = new List<MySqlParameter>();
string resultStr = "";
parameter.Add(new MySqlParameter("@user_money", money));
parameter.Add(new MySqlParameter("@qq", qq));
MySqlConnection connection = new MySqlConnection(Constants.connectionStr);
try
{
connection.Open();
MySqlCommand mySqlCommand = new MySqlCommand(sql, connection);
// 添加参数
if (parameter.Count > 0)
{
mySqlCommand.Parameters.AddRange(parameter.ToArray());
}
// 提取数据
int count = mySqlCommand.ExecuteNonQuery();
int flagCount = inserMoneyHistory(qq,money);
if (count > 0 && flagCount > 0)
{
resultStr = "更新成功!";
}
else
{
resultStr = "更新失败!";
}
}
catch (Exception)
{
throw;
}
finally
{
connection.Close();
}
return resultStr;
}
19
Source : DBHelperMySQL.cs
with Apache License 2.0
from 0nise
with Apache License 2.0
from 0nise
public static int inserMoneyHistory(string qq,decimal money) {
string sql = "INSERT INTO ichunqiu_blank_history(id,user_qq,money,create_date,update_date) VALUES(DEFAULT,@qq,@user_money,NOW(),NOW())";
var parameter = new List<MySqlParameter>();
int count = 0;
parameter.Add(new MySqlParameter("@user_money", money));
parameter.Add(new MySqlParameter("@qq", qq));
MySqlConnection connection = new MySqlConnection(Constants.connectionStr);
try
{
connection.Open();
MySqlCommand mySqlCommand = new MySqlCommand(sql, connection);
// 添加参数
if (parameter.Count > 0)
{
mySqlCommand.Parameters.AddRange(parameter.ToArray());
}
// 提取数据
count = mySqlCommand.ExecuteNonQuery();
}
catch (Exception)
{
count = 0;
}
finally
{
connection.Close();
}
return count;
}
19
Source : DataUnparsed.cs
with MIT License
from 0x0ade
with MIT License
from 0x0ade
public override MetaTypeWrap[] WrapMeta(DataContext ctx) {
if (InnerMetaArray == null || InnerMetaStatus != InnerMetaArrayStatus) {
InnerMetaArray = InnerMeta.ToArray();
InnerMetaArrayStatus = InnerMetaStatus;
}
return InnerMetaArray;
}
19
Source : SqliteUserData.cs
with MIT License
from 0x0ade
with MIT License
from 0x0ade
public override T[] LoadRegistered<T>() {
using UserDataBatchContext batch = OpenBatch();
string table = GetDataTable(typeof(T), false);
if (table.IsNullOrEmpty())
return Dummy<T>.EmptyArray;
using MiniCommand mini = new(this) {
SqliteOpenMode.ReadOnly,
@$"
SELECT D.format, D.value
FROM [{table}] D
INNER JOIN meta M ON D.uid = M.uid
WHERE M.registered = 1;
",
};
(SqliteConnection con, SqliteCommand cmd, SqliteDataReader reader) = mini.Read();
List<T> values = new();
while (reader.Read()) {
switch ((DataFormat) reader.GetInt32(0)) {
case DataFormat.MessagePack:
default: {
using Stream stream = reader.GetStream(1);
values.Add(MessagePackSerializer.Deserialize<T>(stream, MessagePackHelper.Options) ?? new());
break;
}
case DataFormat.Yaml: {
using Stream stream = reader.GetStream(1);
using StreamReader streamReader = new(stream);
values.Add(YamlHelper.Deserializer.Deserialize<T>(streamReader) ?? new());
break;
}
}
}
return values.ToArray();
}
19
Source : patch_Program.cs
with MIT License
from 0x0ade
with MIT License
from 0x0ade
[STAThread]
public static void Main(string[] args) {
bool nothreading = true;
bool nomods = true;
Queue<string> argq = new Queue<string>(args);
while (argq.Count > 0) {
string arg = argq.Dequeue();
if (arg == "-debug")
Debugger.Launch();
else if (arg == "-yesthreading")
nothreading = false;
else if (arg == "-yesmods")
nomods = false;
}
List<string> argl = new List<string>(args);
argl.Add("<");
if (nothreading)
argl.Add("-nothreading");
if (nomods)
argl.Add("-nomods");
argl.Add(">");
args = argl.ToArray();
// Parse arguments again...
argq = new Queue<string>(args);
while (argq.Count > 0) {
string arg = argq.Dequeue();
if (arg == "-nomods")
// MonoMain.moddingEnabled = false skips ManagedContent.InitializeMods.
// InitializeMods calls ModLoader.LoadMods.
// LoadMods sets ModLoader.modHash.
// -nomods thus leaves ModLoader.modHash == null, which causes issues.
patch_ModLoader.DefaultModHash();
}
orig_Main(args);
}
19
Source : TableClassGenerator.cs
with MIT License
from 0x1000000
with MIT License
from 0x1000000
private PropertyDeclarationSyntax[] GenerateColumnProperties(TableModel table)
{
var result = new List<PropertyDeclarationSyntax>(table.Columns.Count);
foreach (var tableColumn in table.Columns)
{
var propertyDeclaration = GenerateColumnProperty(tableColumn: tableColumn);
result.Add(propertyDeclaration);
}
return result.ToArray();
}
19
Source : TableListClassGenerator.cs
with MIT License
from 0x1000000
with MIT License
from 0x1000000
private static MemberDeclarationSyntax[] GenerateMethods(IReadOnlyList<TableModel> tables, string tablePrefix)
{
var result = new List<MemberDeclarationSyntax>(tables.Count*2 + 2);
var identifierAliasType = SyntaxFactory.IdentifierName(nameof(Alias));
var arrayItems = tables.Select(t=> SyntaxFactory.IdentifierName(GetMethodName(t,tablePrefix)).Invoke(identifierAliasType.MemberAccess(nameof(Alias.Empty))));
var arrayType = SyntaxFactory.ArrayType(SyntaxFactory.IdentifierName(nameof(TableBase)),
new SyntaxList<ArrayRankSpecifierSyntax>(new[]
{
SyntaxFactory.ArrayRankSpecifier(SyntaxFactory.Token(SyntaxKind.OpenBracketToken),
new SeparatedSyntaxList<ExpressionSyntax>(),
SyntaxFactory.Token(SyntaxKind.CloseBracketToken))
}));
var array = SyntaxFactory.ArrayCreationExpression(
arrayType,
SyntaxFactory.InitializerExpression(SyntaxKind.ArrayInitializerExpression,
new SeparatedSyntaxList<ExpressionSyntax>().AddRange(arrayItems))
);
result.Add(
SyntaxFactory.MethodDeclaration(arrayType, "BuildAllTableList")
.WithModifiers(SyntaxHelpers.Modifiers(SyntaxKind.PublicKeyword, SyntaxKind.StaticKeyword))
.WithExpressionBody(SyntaxFactory.ArrowExpressionClause(
array
))
.WithSemicolonToken(SyntaxFactory.Token(SyntaxKind.SemicolonToken)));
foreach (var t in tables)
{
var aliasParamName = "alias";
result.Add(SyntaxFactory.MethodDeclaration(SyntaxFactory.ParseTypeName(t.Name), GetMethodName(t, tablePrefix))
.WithModifiers(SyntaxHelpers.Modifiers(SyntaxKind.PublicKeyword, SyntaxKind.StaticKeyword))
.AddParameterListParameters(SyntaxHelpers.FuncParameter(aliasParamName, nameof(Alias)))
.WithExpressionBody(SyntaxFactory.ArrowExpressionClause(
SyntaxFactory.ObjectCreationExpression(SyntaxFactory.ParseTypeName(t.Name),
SyntaxHelpers.ArgumentList(SyntaxFactory.IdentifierName(aliasParamName)),
null)))
.WithSemicolonToken(SyntaxFactory.Token(SyntaxKind.SemicolonToken)));
result.Add(SyntaxFactory.MethodDeclaration(SyntaxFactory.ParseTypeName(t.Name), GetMethodName(t, tablePrefix))
.WithModifiers(SyntaxHelpers.Modifiers(SyntaxKind.PublicKeyword, SyntaxKind.StaticKeyword))
.WithExpressionBody(SyntaxFactory.ArrowExpressionClause(
SyntaxFactory.ObjectCreationExpression(SyntaxFactory.ParseTypeName(t.Name),
SyntaxHelpers.ArgumentList(identifierAliasType.MemberAccess(nameof(Alias.Auto))),
null)))
.WithSemicolonToken(SyntaxFactory.Token(SyntaxKind.SemicolonToken)));
}
return result.ToArray();
static string GetMethodName(TableModel t, string tablePrefix)
{
var name = t.Name;
if (!string.IsNullOrEmpty(tablePrefix))
{
name = name.Substring(tablePrefix.Length);
}
return "Get" + name;
}
}
19
Source : XMLParser.cs
with GNU General Public License v3.0
from 0x2b00b1e5
with GNU General Public License v3.0
from 0x2b00b1e5
public static string[] FindByTag(string NodeName, XmlDoreplacedent doreplacedent)
{
XmlNodeList tags = doreplacedent.GetElementsByTagName(@NodeName);
// Check if nodes were found
if (tags.Count < 1)
{
// Return null if not found
return null;
}
else
{
List<string> l = new List<string>();
//Go though each found node and add it to the list
foreach(XmlNode n in tags)
{
l.Add(n.InnerText);
}
//Convert it to array, clear the list and return
string[] f = l.ToArray();
l.Clear();
return f;
}
}
19
Source : TableClassGenerator.cs
with MIT License
from 0x1000000
with MIT License
from 0x1000000
private static MemberDeclarationSyntax[] ConcatClreplacedMembers(ConstructorDeclarationSyntax empty, ConstructorDeclarationSyntax main, IReadOnlyList<PropertyDeclarationSyntax> properties)
{
var result = new List<MemberDeclarationSyntax>(2 + properties.Count)
{
empty, main
};
result.AddRange(properties);
return result.ToArray();
}
19
Source : Chromium.cs
with GNU General Public License v3.0
from 0xfd3
with GNU General Public License v3.0
from 0xfd3
private static List<Account> Accounts(string path, string browser, string table = "logins")
{
//Get all created profiles from browser path
List<string> loginDataFiles = GetAllProfiles(path);
List<Account> data = new List<Account>();
foreach (string loginFile in loginDataFiles.ToArray())
{
if (!File.Exists(loginFile))
continue;
SQLiteHandler SQLDatabase;
try
{
SQLDatabase = new SQLiteHandler(loginFile); //Open database with Sqlite
}
catch (System.Exception ex)
{
Console.WriteLine(ex.ToString());
continue;
}
if (!SQLDatabase.ReadTable(table))
continue;
for (int I = 0; I <= SQLDatabase.GetRowCount() - 1; I++)
{
try
{
//Get values with row number and column name
string host = SQLDatabase.GetValue(I, "origin_url");
string username = SQLDatabase.GetValue(I, "username_value");
string preplacedword = SQLDatabase.GetValue(I, "preplacedword_value");
if (preplacedword != null)
{
//check v80 preplacedword signature. its starting with v10 or v11
if (preplacedword.StartsWith("v10") || preplacedword.StartsWith("v11"))
{
//Local State file located in the parent folder of profile folder.
byte[] masterKey = GetMasterKey(Directory.GetParent(loginFile).Parent.FullName);
if (masterKey == null)
continue;
preplacedword = DecryptWithKey(Encoding.Default.GetBytes(preplacedword), masterKey);
}
else
preplacedword = Decrypt(preplacedword); //Old versions using UnprotectData for decryption without any key
}
else
continue;
if (!string.IsNullOrEmpty(host) && !string.IsNullOrEmpty(username) && !string.IsNullOrEmpty(preplacedword))
data.Add(new Account() { URL = host, UserName = username, Preplacedword = preplacedword, Application = browser });
}
catch (Exception ex)
{
Console.WriteLine(ex.ToString());
}
}
}
return data;
}
19
Source : VistaFileSaveDialog.cs
with GNU General Public License v3.0
from 0xC0000054
with GNU General Public License v3.0
from 0xC0000054
private NativeStructs.COMDLG_FILTERSPEC[] GetFilterItems()
{
List<NativeStructs.COMDLG_FILTERSPEC> filterItems = new List<NativeStructs.COMDLG_FILTERSPEC>();
if (!string.IsNullOrWhiteSpace(filter))
{
string[] splireplacedems = filter.Split('|');
// The split filter string array must contain an even number of items.
if ((splireplacedems.Length & 1) == 0)
{
for (int i = 0; i < splireplacedems.Length; i += 2)
{
NativeStructs.COMDLG_FILTERSPEC filterSpec = new NativeStructs.COMDLG_FILTERSPEC
{
pszName = splireplacedems[i],
pszSpec = splireplacedems[i + 1]
};
filterItems.Add(filterSpec);
}
}
}
return filterItems.ToArray();
}
19
Source : Program.cs
with MIT License
from 0xd4d
with MIT License
from 0xd4d
static DisasmJob[] GetJobs(DisasmInfo[] methods, string outputDir, FileOutputKind fileOutputKind, FilenameFormat filenameFormat, out string? baseDir) {
FilenameProvider filenameProvider;
var jobs = new List<DisasmJob>();
switch (fileOutputKind) {
case FileOutputKind.Stdout:
baseDir = null;
return new[] { new DisasmJob(() => (Console.Out, false), methods) };
case FileOutputKind.OneFile:
if (string.IsNullOrEmpty(outputDir))
throw new ApplicationException("Missing filename");
baseDir = Path.GetDirectoryName(outputDir);
return new[] { new DisasmJob(() => (File.CreateText(outputDir), true), methods) };
case FileOutputKind.OneFilePerType:
if (string.IsNullOrEmpty(outputDir))
throw new ApplicationException("Missing output dir");
baseDir = outputDir;
filenameProvider = new FilenameProvider(filenameFormat, baseDir, DASM_EXT);
var types = new Dictionary<uint, List<DisasmInfo>>();
foreach (var method in methods) {
if (!types.TryGetValue(method.TypeToken, out var typeMethods))
types.Add(method.TypeToken, typeMethods = new List<DisasmInfo>());
typeMethods.Add(method);
}
var allTypes = new List<List<DisasmInfo>>(types.Values);
allTypes.Sort((a, b) => StringComparer.Ordinal.Compare(a[0].TypeFullName, b[0].TypeFullName));
foreach (var typeMethods in allTypes) {
uint token = typeMethods[0].TypeToken;
var name = GetTypeName(typeMethods[0].TypeFullName);
var getTextWriter = CreateGetTextWriter(filenameProvider.GetFilename(token, name));
jobs.Add(new DisasmJob(getTextWriter, typeMethods.ToArray()));
}
return jobs.ToArray();
case FileOutputKind.OneFilePerMethod:
if (string.IsNullOrEmpty(outputDir))
throw new ApplicationException("Missing output dir");
baseDir = outputDir;
filenameProvider = new FilenameProvider(filenameFormat, baseDir, DASM_EXT);
foreach (var method in methods) {
uint token = method.MethodToken;
var name = method.MethodName.Replace('.', '_');
var getTextWriter = CreateGetTextWriter(filenameProvider.GetFilename(token, name));
jobs.Add(new DisasmJob(getTextWriter, new[] { method }));
}
return jobs.ToArray();
default:
throw new InvalidOperationException();
}
}
19
Source : Program.cs
with MIT License
from 0xd4d
with MIT License
from 0xd4d
static (int bitness, DisasmInfo[] methods, KnownSymbols knownSymbols) GetMethodsToDisreplacedemble(int pid, string moduleName, MemberFilter typeFilter, MemberFilter methodFilter, bool heapSearch) {
var methods = new List<DisasmInfo>();
var knownSymbols = new KnownSymbols();
int bitness;
using (var dataTarget = DataTarget.AttachToProcess(pid, 0, AttachFlag.Preplacedive)) {
if (dataTarget.ClrVersions.Count == 0)
throw new ApplicationException("Couldn't find CLR/CoreCLR");
if (dataTarget.ClrVersions.Count > 1)
throw new ApplicationException("Found more than one CLR/CoreCLR");
var clrInfo = dataTarget.ClrVersions[0];
var clrRuntime = clrInfo.CreateRuntime(clrInfo.LocalMatchingDac);
bitness = clrRuntime.PointerSize * 8;
// Per https://github.com/microsoft/clrmd/issues/303
dataTarget.DataReader.Flush();
var module = clrRuntime.Modules.FirstOrDefault(a =>
StringComparer.OrdinalIgnoreCase.Equals(a.Name, moduleName) ||
StringComparer.OrdinalIgnoreCase.Equals(Path.GetFileNameWithoutExtension(a.Name), moduleName) ||
StringComparer.OrdinalIgnoreCase.Equals(a.FileName, moduleName));
if (module is null)
throw new ApplicationException($"Couldn't find module '{moduleName}'");
module.Runtime.Flush();
foreach (var type in EnumerateTypes(module, heapSearch)) {
if (!typeFilter.IsMatch(type.Name, type.MetadataToken))
continue;
foreach (var method in type.Methods) {
if (!IsSameType(method.Type, type))
continue;
if (method.CompilationType == MethodCompilationType.None)
continue;
if (!methodFilter.IsMatch(method.Name, method.MetadataToken))
continue;
var disasmInfo = CreateDisasmInfo(dataTarget, method);
DecodeInstructions(knownSymbols, clrRuntime, disasmInfo);
methods.Add(disasmInfo);
}
}
}
return (bitness, methods.ToArray(), knownSymbols);
}
19
Source : Ext.cs
with GNU General Public License v3.0
from 1330-Studios
with GNU General Public License v3.0
from 1330-Studios
public static T[] Reversed<T>(this T[] reference) {
var bases = new List<T>();
for (int i = reference.Length - 1; i >= 0; i--)
bases.Add(reference[i]);
return bases.ToArray();
}
19
Source : ProxyGenerator.cs
with MIT License
from 1100100
with MIT License
from 1100100
private static MemberDeclarationSyntax[] GenerateMethods(Type type, string clreplacedName, string serviceName)
{
var typeAttr = type.GetCustomAttribute<ServiceRouteAttribute>();
var routePrefix = typeAttr == null ? $"{type.Namespace}/{type.Name}" : typeAttr.Route;
var methods = type.GetMethods().ToList();
var s = methods.Select(p => GenerateMethod(routePrefix, p, serviceName)).ToList();
s.Insert(0, GenerateConstructorDeclaration(clreplacedName));
return s.ToArray();
}
19
Source : Inline_Hook.cs
with Apache License 2.0
from 1694439208
with Apache License 2.0
from 1694439208
public static IntPtr InlineHook(int HookAddress, int Hooklen,
byte[] HookBytes0,int Callback,int CallbackOffset,
bool IsFront,int CallAddress,string name, Action<Methods.Register> func)
{
WeChetHook.DllcallBack dllcallBack = new WeChetHook.DllcallBack((de1, de2, ECX1, EAX1, EDX1, EBX1, ESP1, EBP1, ESI1, EDI1) => {
func(new Register
{
EAX = EAX1,
EBP = EBP1,
EBX = EBX1,
ECX = ECX1,
EDI = EDI1,
EDX = EDX1,
ESI = ESI1,
ESP = ESP1
});
});
int CallHandle = ComputeHash(name);
Methods.callBacks.Add(CallHandle, dllcallBack);
List<byte> byteSource1 = new List<byte>();
byteSource1.AddRange(new byte[] { 199, 134, 240, 2, 0, 0 });
byteSource1.AddRange(BitConverter.GetBytes(CallHandle));
byteSource1.AddRange(HookBytes0);
byte[] hookbytes = byteSource1.ToArray();
List<byte> byteSource = new List<byte>();
IntPtr ptr = NativeAPI.VirtualAlloc(0, 128, 4096, 64);
if (IsFront)
{
NativeAPI.WriteProcessMemory(-1, ptr, Add(new byte[] { 232 }, Inline_GetBuf(ptr, CallAddress)), 5, 0);
NativeAPI.WriteProcessMemory(-1, ptr + 5, hookbytes, hookbytes.Length, 0);
NativeAPI.WriteProcessMemory(-1, ptr + 5 + CallbackOffset, Inline_GetBuf(ptr + 5 + CallbackOffset - 1, Callback), 4, 0);
NativeAPI.WriteProcessMemory(-1, ptr + 5 + hookbytes.Length, Add(new byte[] { 233 }, Inline_GetBuf(ptr + 5 + HookBytes0.Length, HookAddress + Hooklen)), 5, 0);
}
else {
NativeAPI.WriteProcessMemory(-1, ptr, hookbytes, hookbytes.Length, 0);
NativeAPI.WriteProcessMemory(-1, ptr + CallbackOffset, Inline_GetBuf(ptr + CallbackOffset - 1, Callback), 4, 0);
NativeAPI.WriteProcessMemory(-1, ptr + hookbytes.Length,Add(new byte[] { 232 },Inline_GetBuf(ptr + hookbytes.Length, CallAddress)), Hooklen, 0);
NativeAPI.WriteProcessMemory(-1, ptr + Hooklen + hookbytes.Length, Add(new byte[] { 233 }, Inline_GetBuf(ptr + Hooklen + HookBytes0.Length, HookAddress + Hooklen)), 5, 0);
}
NativeAPI.WriteProcessMemory(-1, new IntPtr(HookAddress), Add(new byte[] { 233 }, Inline_GetBuf(HookAddress, ptr.ToInt32())), 5, 0);
for (int i = 0; i < Hooklen - 5; i++)
{
byteSource.Add(144);
}
byte[] ByteFill = byteSource.ToArray();
NativeAPI.WriteProcessMemory(-1, new IntPtr(HookAddress + 5), ByteFill, ByteFill.Length, 0);
return ptr;
}
19
Source : Inline_Hook.cs
with Apache License 2.0
from 1694439208
with Apache License 2.0
from 1694439208
public static IntPtr InlineHook(int HookAddress, int Hooklen,
byte[] HookBytes0, int Callback, int CallbackOffset,string name, Action<Methods.Register> func)
{
WeChetHook.DllcallBack dllcallBack = new WeChetHook.DllcallBack((de1, de2, ECX1, EAX1, EDX1, EBX1, ESP1, EBP1, ESI1, EDI1) => {
//int ECX, int EAX, int EDX, int EBX, int ESP, int EBP, int ESI, int EDI
func(new Register
{
EAX = EAX1,
EBP = EBP1,
EBX = EBX1,
ECX = ECX1,
EDI = EDI1,
EDX = EDX1,
ESI = ESI1,
ESP = ESP1
});
});
int CallHandle = ComputeHash(name);
System.Windows.Forms.MessageBox.Show("CallHandle:" + CallHandle.ToString());
Methods.callBacks.Add(CallHandle, dllcallBack);
List<byte> byteSource1 = new List<byte>();
byteSource1.AddRange(new byte[] { 199, 134, 240, 2, 0, 0 });
byteSource1.AddRange(BitConverter.GetBytes(CallHandle));//把标识指针绑定到寄存器我觉得不靠谱但是目前没啥问题
byteSource1.AddRange(HookBytes0);
byte[] hookbytes = byteSource1.ToArray();
List<byte> byteSource = new List<byte>();
IntPtr ptr = NativeAPI.VirtualAlloc(0, 128, 4096, 64);
NativeAPI.WriteProcessMemory(-1, ptr, hookbytes, hookbytes.Length, 0);
NativeAPI.WriteProcessMemory(-1, ptr + CallbackOffset, Inline_GetBuf(ptr + CallbackOffset - 1, Callback), 4, 0);
NativeAPI.WriteProcessMemory(-1, ptr + hookbytes.Length, Add(new byte[] { 233 }, Inline_GetBuf(ptr + hookbytes.Length, HookAddress+ Hooklen)), 5, 0);
NativeAPI.WriteProcessMemory(-1, new IntPtr(HookAddress), Add(new byte[] { 233 }, Inline_GetBuf(HookAddress, ptr.ToInt32())), 5, 0);
for (int i = 0; i < Hooklen - 5; i++)
{
byteSource.Add(144);
}
byte[] ByteFill = byteSource.ToArray();
NativeAPI.WriteProcessMemory(-1, new IntPtr(HookAddress + 5), ByteFill, ByteFill.Length, 0);
return ptr;
}
19
Source : CodeFirstProviderAbstract.cs
with MIT License
from 17MKH
with MIT License
from 17MKH
public virtual void InitData(IRepositoryManager repositoryManager)
{
if (!Options.InitData)
return;
if (Options.InitDataFilePath.IsNull() || !File.Exists(Options.InitDataFilePath))
{
_logger.LogDebug("初始化数据文件不存在");
return;
}
_logger.LogDebug("开始初始化数据");
var jsonHelper = new JsonHelper();
using var jsonReader = new StreamReader(Options.InitDataFilePath, Encoding.UTF8);
var str = jsonReader.ReadToEnd();
using var doc = JsonDoreplacedent.Parse(str);
var properties = doc.RootElement.EnumerateObject();
if (properties.Any())
{
foreach (var property in properties)
{
var enreplacedyDescriptor = Context.EnreplacedyDescriptors.FirstOrDefault(m => m.Name.EqualsIgnoreCase(property.Name));
if (enreplacedyDescriptor != null)
{
var list = (IList)jsonHelper.Deserialize(property.Value.ToString(),
typeof(List<>).MakeGenericType(enreplacedyDescriptor.EnreplacedyType));
var repositoryDescriptor = Context.RepositoryDescriptors.FirstOrDefault(m => m.EnreplacedyType == enreplacedyDescriptor.EnreplacedyType);
var repository = (IRepository)Service.BuildServiceProvider()
.GetService(repositoryDescriptor!.InterfaceType);
var tasks = new List<Task>();
foreach (var item in list)
{
tasks.Add(repository.Add(item));
}
Task.WaitAll(tasks.ToArray());
}
}
}
}
19
Source : Form1.cs
with Apache License 2.0
from 1694439208
with Apache License 2.0
from 1694439208
private void button5_Click(object sender, EventArgs e)
{
byte[] jmp_inst =
{
233,0,0,0,0,//JMP Address
};
int Method = NativeAPI.GetMethodPTR(typeof(WeChetHook), "Callback");
textBox3.Text = (3212659 + int.Parse(label1.Text)).ToString();
List<byte> byteSource = new List<byte>();
byteSource.AddRange(new byte[] { 199, 134, 236, 2, 0, 0 });//mov dword [esi+0x000002EC],
byteSource.AddRange(BitConverter.GetBytes(int.Parse(textBox3.Text) + 5));//0x00000000 把hook的后五个字节地址压进寄存器
byteSource.AddRange(jmp_inst);//让他跳到跳板函数
//这部分根据实际情况填写
byteSource.Add(185);//补充替换的汇编指令
byteSource.AddRange(BitConverter.GetBytes(int.Parse(label1.Text) + 19255272));//补充替换的汇编指令地址
//开始hook
Inline_Hook.InlineHook(int.Parse(textBox3.Text),5, byteSource.ToArray(), getInt(Method),11+10,"接收消息",(obj) =>{
StringBuilder sb = new StringBuilder();
sb.Append("接收消息:");
int a = 0x68;
//System.Windows.Forms.MessageBox.Show("esp:"+a.ToString());
try
{
if (obj.ESP == 0)
return;
int MsgPtr = NativeAPI.ReadMemoryValue(obj.ESP);
if (MsgPtr == 0)
return;
MsgPtr = NativeAPI.ReadMemoryValue(MsgPtr);
if (MsgPtr == 0)
return;
MsgPtr = NativeAPI.ReadMemoryValue(MsgPtr + 0x68);
if (MsgPtr == 0)
return;
int len = NativeAPI.lstrlenW(MsgPtr);
if (len == 0)
return;
sb.Append(NativeAPI.ReadMemoryStrValue(MsgPtr, len*2+2));
sb.Append("\r\n");
listBox1.Items.Add(sb.ToString());
}
catch (Exception es)
{
File.AppendAllText("error.txt", es.Message);
}
});
}
19
Source : Inline_Hook.cs
with Apache License 2.0
from 1694439208
with Apache License 2.0
from 1694439208
public static IntPtr InlineHook(int HookAddress, int Hooklen,int Callback)
{
List<byte> byteSource = new List<byte>();
NativeAPI.WriteProcessMemory(-1, new IntPtr(HookAddress), Add(new byte[] { 233 }, Inline_GetBuf(HookAddress, Callback)), 5, 0);
for (int i = 0; i < Hooklen - 5; i++)
{
byteSource.Add(144);
}
byte[] ByteFill = byteSource.ToArray();
NativeAPI.WriteProcessMemory(-1, new IntPtr(HookAddress + 5), ByteFill, ByteFill.Length, 0);
return IntPtr.Zero;
}
19
Source : VMFAdapter.cs
with MIT License
from 1upD
with MIT License
from 1upD
public NailsMap Import()
{
try {
// Reset adapter VMF
this._vmf = new VMF();
NailsMap map = new NailsMap();
List<string> lines = new List<string>();
using (StreamReader sr = new StreamReader(new FileStream(this._filename, FileMode.OpenOrCreate)))
{
while (!sr.EndOfStream)
{
lines.Add(sr.ReadLine());
}
}
VMF input_vmf = new VMF(lines.ToArray());
for (int blockIndex = 0; blockIndex < input_vmf.Body.Count; blockIndex++)
{
// Should this object be included when the VMF is output?
bool includeThisBlock = true;
// Get the next object from the VMF
var obj = input_vmf.Body[blockIndex];
try
{
// Try to cast to block
VMFParser.VBlock block = (VMFParser.VBlock)obj;
// If this block is an enreplacedy
if (block.Name == "enreplacedy")
{
var body = block.Body;
foreach (var innerObj in body) {
try
{
VMFParser.VProperty prop = (VMFParser.VProperty)innerObj;
// If this block is an instance
if (prop.Name == "clreplacedname" && prop.Value == "func_instance")
{
VProperty fileProperty = (VProperty)body.Where(p => p.Name == "file").ToList()[0];
var filePathParts = fileProperty.Value.Split('/');
// If this is a nails instance
if (filePathParts[0] == "Nails")
{
// Get position
VProperty originProperty = (VProperty)body.Where(p => p.Name == "origin").ToList()[0];
var originParts = originProperty.Value.Split(' ');
int x_pos = int.Parse(originParts[0]) / this._horizontal_scale;
int y_pos = int.Parse(originParts[1]) / this._horizontal_scale;
int z_pos = int.Parse(originParts[2]) / this._vertical_scale;
string style = filePathParts[1];
map.MarkLocation(style, x_pos, y_pos, z_pos);
// Remove this block from the vmf
includeThisBlock = false;
}
break;
}
} catch (InvalidCastException e)
{
log.Error("Invalid cast exception. VMF Object is not a VProperty.", e);
}
}
}
} catch(InvalidCastException e)
{
log.Error("Invalid cast exception. VMF object is not a VBlock.", e);
}
// If this object is not a Nails block, add it to the adapter's VMF to be output later
if (includeThisBlock)
{
this._vmf.Body.Add(obj);
}
}
return map;
} catch (Exception e)
{
log.Error("VMFAdapter.Import(): Caught exception: ", e);
log.Info(string.Format("Failed to read from VMF file: {0}", this._filename));
}
return null;
}
19
Source : Form1.cs
with MIT License
from 1y0n
with MIT License
from 1y0n
private byte[] Random_Key()
{
string t = "";
for (int i = 0; i < 23; i++)
{
RNGCryptoServiceProvider csp = new RNGCryptoServiceProvider();
byte[] byteCsp = new byte[23];
csp.GetBytes(byteCsp);
t = BitConverter.ToString(byteCsp);
}
string[] t_array = t.Split('-');
List<byte> key_list = new List<byte>();
foreach (string i in t_array)
{
key_list.Add(string_to_int(i));
}
return key_list.ToArray();
}
19
Source : WelcomeMessage.cs
with MIT License
from 1ZouLTReX1
with MIT License
from 1ZouLTReX1
public static byte[] Serialize(ushort newPlayerID)
{
List<byte> welcomePacket = new List<byte>();
// Send to the connected client his ID.
NetworkUtils.SerializeUshort(welcomePacket, newPlayerID);
NetworkUtils.SerializeUshort(welcomePacket, ServerSettings.tickRate);
return welcomePacket.ToArray();
}
19
Source : WorldState.cs
with MIT License
from 1ZouLTReX1
with MIT License
from 1ZouLTReX1
public static byte[] Serialize(WorldState ws)
{
List<byte> pkt = new List<byte>();
ws.AddBytesTo(pkt);
return pkt.ToArray();
}
19
Source : WorldState.cs
with MIT License
from 1ZouLTReX1
with MIT License
from 1ZouLTReX1
public static byte[] Serialize(ClientInput ci)
{
List<byte> pkt = new List<byte>();
ci.AddBytesTo(pkt);
return pkt.ToArray();
}
19
Source : Form1.cs
with MIT License
from 1y0n
with MIT License
from 1y0n
private string Handle_Payload()
{
//对用户输入的payload进行一些转换处理,方便下一步的加密
string raw_input = textBox1.Text.Trim().Replace("\r\n", "").Replace("\n", "").Replace("\r", ""); //支持多种linux win换行符
string payload_pattern_csharp = @"\{(.+?)\}";
string payload_pattern_c = @"=.*"";$";
string[] raw_payload_array;
if (Regex.IsMatch(raw_input, payload_pattern_c))
{
//c语言格式的shellcode,转成 csharp 格式
raw_input = raw_input.Replace("\"", "").Replace("\\", ",0").Replace(";", "").Replace("=", "{").Replace("{,", "{ ") + " }";
}
string raw_payload = Regex.Matches(raw_input, payload_pattern_csharp)[0].Value.Replace("{", "").Replace("}", "").Trim();
raw_payload = raw_payload.TrimStart(',');
raw_payload_array = raw_payload.Split(',');
List<byte> byte_payload_list = new List<byte>();
foreach (string i in raw_payload_array)
{
byte_payload_list.Add(string_to_int(i));
}
byte[] payload_result = byte_payload_list.ToArray();
//加密payload并转换为字符串,准备写入文件
byte[] encrypted_payload = Encrypter.Encrypt(KEY, payload_result);
string string_encrypted_payload = string.Join(",", encrypted_payload);
//MessageBox.Show(string_encrypted_payload);
return string_encrypted_payload;
}
19
Source : Program.cs
with MIT License
from 2881099
with MIT License
from 2881099
static void Main(string[] args)
{
RedisHelper.Initialization(new CSRedis.CSRedisClient("127.0.0.1:6379,asyncPipeline=true,preheat=100,poolsize=100"));
cli.Set("TestMGet_null1", "");
RedisHelper.Set("TestMGet_null1", "");
sedb.StringSet("TestMGet_string1", String);
ThreadPool.SetMinThreads(10001, 10001);
Stopwatch sw = new Stopwatch();
var tasks = new List<Task>();
var results = new ConcurrentQueue<string>();
cli.FlushDb();
while (results.TryDequeue(out var del)) ;
sw.Reset();
sw.Start();
for (var a = 0; a < 100000; a++)
{
var tmp = Guid.NewGuid().ToString();
sedb.StringSet(tmp, String);
var val = sedb.StringGet(tmp);
if (val != String) throw new Exception("not equal");
results.Enqueue(val);
}
sw.Stop();
Console.WriteLine("StackExchange(0-100000): " + sw.ElapsedMilliseconds + "ms results: " + results.Count);
tasks.Clear();
while (results.TryDequeue(out var del)) ;
cli.FlushDb();
sw.Reset();
sw.Start();
tasks = new List<Task>();
for (var a = 0; a < 100000; a++)
{
tasks.Add(Task.Run(() =>
{
var tmp = Guid.NewGuid().ToString();
sedb.StringSet(tmp, String);
var val = sedb.StringGet(tmp);
if (val != String) throw new Exception("not equal");
results.Enqueue(val);
}));
}
Task.WaitAll(tasks.ToArray());
sw.Stop();
Console.WriteLine("StackExchange(Task.WaitAll 100000): " + sw.ElapsedMilliseconds + "ms results: " + results.Count);
tasks.Clear();
while (results.TryDequeue(out var del)) ;
cli.FlushDb();
sw.Reset();
sw.Start();
Task.Run(async () =>
{
for (var a = 0; a < 100000; a++)
{
var tmp = Guid.NewGuid().ToString();
await sedb.StringSetAsync(tmp, String);
var val = await sedb.StringGetAsync(tmp);
if (val != String) throw new Exception("not equal");
results.Enqueue(val);
}
}).Wait();
sw.Stop();
Console.WriteLine("StackExchangeAsync(0-100000): " + sw.ElapsedMilliseconds + "ms results: " + results.Count);
tasks.Clear();
while (results.TryDequeue(out var del)) ;
cli.FlushDb();
sw.Reset();
sw.Start();
tasks = new List<Task>();
for (var a = 0; a < 100000; a++)
{
tasks.Add(Task.Run(async () =>
{
var tmp = Guid.NewGuid().ToString();
await sedb.StringSetAsync(tmp, String);
var val = await sedb.StringGetAsync(tmp);
if (val != String) throw new Exception("not equal");
results.Enqueue(val);
}));
}
Task.WaitAll(tasks.ToArray());
sw.Stop();
Console.WriteLine("StackExchangeAsync(Task.WaitAll 100000): " + sw.ElapsedMilliseconds + "ms results: " + results.Count + "\r\n");
tasks.Clear();
while (results.TryDequeue(out var del)) ;
cli.FlushDb();
sw.Reset();
sw.Start();
for (var a = 0; a < 100000; a++)
{
var tmp = Guid.NewGuid().ToString();
cli.Set(tmp, String);
var val = cli.Get(tmp);
if (val != String) throw new Exception("not equal");
results.Enqueue(val);
}
sw.Stop();
Console.WriteLine("FreeRedis(0-100000): " + sw.ElapsedMilliseconds + "ms results: " + results.Count);
tasks.Clear();
while (results.TryDequeue(out var del)) ;
cli.FlushDb();
sw.Reset();
sw.Start();
tasks = new List<Task>();
for (var a = 0; a < 100000; a++)
{
tasks.Add(Task.Run(() =>
{
var tmp = Guid.NewGuid().ToString();
cli.Set(tmp, String);
var val = cli.Get(tmp);
if (val != String) throw new Exception("not equal");
results.Enqueue(val);
}));
}
Task.WaitAll(tasks.ToArray());
sw.Stop();
Console.WriteLine("FreeRedis(Task.WaitAll 100000): " + sw.ElapsedMilliseconds + "ms results: " + results.Count);
tasks.Clear();
while (results.TryDequeue(out var del)) ;
cli.FlushDb();
sw.Reset();
sw.Start();
Task.Run(async () =>
{
for (var a = 0; a < 100000; a++)
{
var tmp = Guid.NewGuid().ToString();
await cli.SetAsync(tmp, String);
var val = await cli.GetAsync(tmp);
if (val != String) throw new Exception("not equal");
results.Enqueue(val);
}
}).Wait();
sw.Stop();
Console.WriteLine("FreeRedisAsync(0-100000): " + sw.ElapsedMilliseconds + "ms results: " + results.Count);
tasks.Clear();
while (results.TryDequeue(out var del)) ;
cli.FlushDb();
//FreeRedis.Internal.AsyncRedisSocket.sb.Clear();
//FreeRedis.Internal.AsyncRedisSocket.sw.Start();
sw.Reset();
sw.Start();
tasks = new List<Task>();
for (var a = 0; a < 100000; a++)
{
tasks.Add(Task.Run(async () =>
{
var tmp = Guid.NewGuid().ToString();
await cli.SetAsync(tmp, String);
var val = await cli.GetAsync(tmp);
if (val != String) throw new Exception("not equal");
results.Enqueue(val);
}));
}
Task.WaitAll(tasks.ToArray());
sw.Stop();
//var sbstr = FreeRedis.Internal.AsyncRedisSocket.sb.ToString()
//sbstr = sbstr + sbstr.Split("\r\n").Length + "条消息 ;
Console.WriteLine("FreeRedisAsync(Task.WaitAll 100000): " + sw.ElapsedMilliseconds + "ms results: " + results.Count);
tasks.Clear();
while (results.TryDequeue(out var del)) ;
cli.FlushDb();
sw.Reset();
sw.Start();
using (var pipe = cli.StartPipe())
{
for (var a = 0; a < 100000; a++)
{
var tmp = Guid.NewGuid().ToString();
pipe.Set(tmp, String);
var val = pipe.Get(tmp);
}
var vals = pipe.EndPipe();
for (var a = 1; a < 200000; a += 2)
{
var val = vals[a].ToString();
if (val != String) throw new Exception("not equal");
results.Enqueue(val);
}
}
sw.Stop();
Console.WriteLine("FreeRedisPipeline(0-100000): " + sw.ElapsedMilliseconds + "ms results: " + results.Count + "\r\n");
tasks.Clear();
while (results.TryDequeue(out var del)) ;
cli.FlushDb();
//sw.Reset();
//sw.Start();
//for (var a = 0; a < 100000; a++)
// cli.Call(new CommandPacket("SET").Input("TestMGet_string1").InputRaw(String));
//sw.Stop();
//Console.WriteLine("FreeRedis2: " + sw.ElapsedMilliseconds + "ms");
tasks.Clear();
while (results.TryDequeue(out var del)) ;
cli.FlushDb();
//sw.Reset();
//sw.Start();
//for (var a = 0; a < 100000; a++)
//{
// using (var rds = cli.GetTestRedisSocket())
// {
// var cmd = new CommandPacket("SET").Input("TestMGet_string1").InputRaw(String);
// rds.Write(cmd);
// cmd.Read<string>();
// }
//}
//sw.Stop();
//Console.WriteLine("FreeRedis4: " + sw.ElapsedMilliseconds + "ms");
tasks.Clear();
while (results.TryDequeue(out var del)) ;
cli.FlushDb();
sw.Reset();
sw.Start();
for (var a = 0; a < 100000; a++)
{
var tmp = Guid.NewGuid().ToString();
RedisHelper.Set(tmp, String);
var val = RedisHelper.Get(tmp);
if (val != String) throw new Exception("not equal");
results.Enqueue(val);
}
sw.Stop();
Console.WriteLine("CSRedisCore(0-100000): " + sw.ElapsedMilliseconds + "ms results: " + results.Count);
tasks.Clear();
while (results.TryDequeue(out var del)) ;
cli.FlushDb();
sw.Reset();
sw.Start();
tasks = new List<Task>();
for (var a = 0; a < 100000; a++)
{
tasks.Add(Task.Run(() =>
{
var tmp = Guid.NewGuid().ToString();
RedisHelper.Set(tmp, String);
var val = RedisHelper.Get(tmp);
if (val != String) throw new Exception("not equal");
results.Enqueue(val);
}));
}
Task.WaitAll(tasks.ToArray());
sw.Stop();
Console.WriteLine("CSRedisCore(Task.WaitAll 100000): " + sw.ElapsedMilliseconds + "ms results: " + results.Count);
tasks.Clear();
while (results.TryDequeue(out var del)) ;
cli.FlushDb();
sw.Reset();
sw.Start();
Task.Run(async () =>
{
for (var a = 0; a < 100000; a++)
{
var tmp = Guid.NewGuid().ToString();
await RedisHelper.SetAsync(tmp, String);
var val = await RedisHelper.GetAsync(tmp);
if (val != String) throw new Exception("not equal");
results.Enqueue(val);
}
}).Wait();
sw.Stop();
Console.WriteLine("CSRedisCoreAsync(0-100000): " + sw.ElapsedMilliseconds + "ms results: " + results.Count);
tasks.Clear();
while (results.TryDequeue(out var del)) ;
cli.FlushDb();
sw.Reset();
sw.Start();
tasks = new List<Task>();
for (var a = 0; a < 100000; a++)
{
tasks.Add(Task.Run(async () =>
{
var tmp = Guid.NewGuid().ToString();
await RedisHelper.SetAsync(tmp, String);
var val = await RedisHelper.GetAsync(tmp);
//if (val != String) throw new Exception("not equal");
results.Enqueue(val);
}));
}
Task.WaitAll(tasks.ToArray());
sw.Stop();
Console.WriteLine("CSRedisCoreAsync(Task.WaitAll 100000): " + sw.ElapsedMilliseconds + "ms results: " + results.Count + "\r\n");
tasks.Clear();
while (results.TryDequeue(out var del)) ;
cli.FlushDb();
}
19
Source : Program.cs
with MIT License
from 2881099
with MIT License
from 2881099
static void Main(string[] args)
{
sedb.StringSet("key1", (string)null);
var val111 = sedb.StringGet("key1");
RedisHelper.Initialization(new CSRedis.CSRedisClient("127.0.0.1:6379,asyncPipeline=true,preheat=100,poolsize=100"));
cli.Set("TestMGet_null1", "");
RedisHelper.Set("TestMGet_null1", "");
sedb.StringSet("TestMGet_string1", String);
ThreadPool.SetMinThreads(10001, 10001);
Stopwatch sw = new Stopwatch();
var tasks = new List<Task>();
var results = new ConcurrentQueue<string>();
cli.FlushDb();
results.Clear();
sw.Reset();
sw.Start();
for (var a = 0; a < 100000; a++)
{
var tmp = Guid.NewGuid().ToString();
sedb.StringSet(tmp, String);
var val = sedb.StringGet(tmp);
if (val != String) throw new Exception("not equal");
results.Enqueue(val);
}
sw.Stop();
Console.WriteLine("StackExchange(0-100000): " + sw.ElapsedMilliseconds + "ms results: " + results.Count);
tasks.Clear();
results.Clear();
cli.FlushDb();
sw.Reset();
sw.Start();
tasks = new List<Task>();
for (var a = 0; a < 100000; a++)
{
tasks.Add(Task.Run(() =>
{
var tmp = Guid.NewGuid().ToString();
sedb.StringSet(tmp, String);
var val = sedb.StringGet(tmp);
if (val != String) throw new Exception("not equal");
results.Enqueue(val);
}));
}
Task.WaitAll(tasks.ToArray());
sw.Stop();
Console.WriteLine("StackExchange(Task.WaitAll 100000): " + sw.ElapsedMilliseconds + "ms results: " + results.Count);
tasks.Clear();
results.Clear();
cli.FlushDb();
sw.Reset();
sw.Start();
Task.Run(async () =>
{
for (var a = 0; a < 100000; a++)
{
var tmp = Guid.NewGuid().ToString();
await sedb.StringSetAsync(tmp, String);
var val = await sedb.StringGetAsync(tmp);
if (val != String) throw new Exception("not equal");
results.Enqueue(val);
}
}).Wait();
sw.Stop();
Console.WriteLine("StackExchangeAsync(0-100000): " + sw.ElapsedMilliseconds + "ms results: " + results.Count);
tasks.Clear();
results.Clear();
cli.FlushDb();
sw.Reset();
sw.Start();
tasks = new List<Task>();
for (var a = 0; a < 100000; a++)
{
tasks.Add(Task.Run(async () =>
{
var tmp = Guid.NewGuid().ToString();
await sedb.StringSetAsync(tmp, String);
var val = await sedb.StringGetAsync(tmp);
if (val != String) throw new Exception("not equal");
results.Enqueue(val);
}));
}
Task.WaitAll(tasks.ToArray());
sw.Stop();
Console.WriteLine("StackExchangeAsync(Task.WaitAll 100000): " + sw.ElapsedMilliseconds + "ms results: " + results.Count + "\r\n");
tasks.Clear();
results.Clear();
cli.FlushDb();
sw.Reset();
sw.Start();
for (var a = 0; a < 100000; a++)
{
var tmp = Guid.NewGuid().ToString();
cli.Set(tmp, String);
var val = cli.Get(tmp);
if (val != String) throw new Exception("not equal");
results.Enqueue(val);
}
sw.Stop();
Console.WriteLine("FreeRedis(0-100000): " + sw.ElapsedMilliseconds + "ms results: " + results.Count);
tasks.Clear();
results.Clear();
cli.FlushDb();
sw.Reset();
sw.Start();
tasks = new List<Task>();
for (var a = 0; a < 100000; a++)
{
tasks.Add(Task.Run(() =>
{
var tmp = Guid.NewGuid().ToString();
cli.Set(tmp, String);
var val = cli.Get(tmp);
if (val != String) throw new Exception("not equal");
results.Enqueue(val);
}));
}
Task.WaitAll(tasks.ToArray());
sw.Stop();
Console.WriteLine("FreeRedis(Task.WaitAll 100000): " + sw.ElapsedMilliseconds + "ms results: " + results.Count);
tasks.Clear();
results.Clear();
cli.FlushDb();
//sw.Reset();
//sw.Start();
//Task.Run(async () =>
//{
// for (var a = 0; a < 100000; a++)
// {
// var tmp = Guid.NewGuid().ToString();
// await cli.SetAsync(tmp, String);
// var val = await cli.GetAsync(tmp);
// if (val != String) throw new Exception("not equal");
// results.Enqueue(val);
// }
//}).Wait();
//sw.Stop();
//Console.WriteLine("FreeRedisAsync(0-100000): " + sw.ElapsedMilliseconds + "ms results: " + results.Count);
//tasks.Clear();
//results.Clear();
//cli.FlushDb();
//FreeRedis.Internal.AsyncRedisSocket.sb.Clear();
//FreeRedis.Internal.AsyncRedisSocket.sw.Start();
//sw.Reset();
//sw.Start();
//tasks = new List<Task>();
//for (var a = 0; a < 100000; a++)
//{
// tasks.Add(Task.Run(async () =>
// {
// var tmp = Guid.NewGuid().ToString();
// await cli.SetAsync(tmp, String);
// var val = await cli.GetAsync(tmp);
// if (val != String) throw new Exception("not equal");
// results.Enqueue(val);
// }));
//}
//Task.WaitAll(tasks.ToArray());
//sw.Stop();
////var sbstr = FreeRedis.Internal.AsyncRedisSocket.sb.ToString()
////sbstr = sbstr + sbstr.Split("\r\n").Length + "条消息 ;
//Console.WriteLine("FreeRedisAsync(Task.WaitAll 100000): " + sw.ElapsedMilliseconds + "ms results: " + results.Count);
//tasks.Clear();
//results.Clear();
//cli.FlushDb();
sw.Reset();
sw.Start();
using (var pipe = cli.StartPipe())
{
for (var a = 0; a < 100000; a++)
{
var tmp = Guid.NewGuid().ToString();
pipe.Set(tmp, String);
var val = pipe.Get(tmp);
}
var vals = pipe.EndPipe();
for (var a = 1; a < 200000; a += 2)
{
var val = vals[a].ToString();
if (val != String) throw new Exception("not equal");
results.Enqueue(val);
}
}
sw.Stop();
Console.WriteLine("FreeRedisPipeline(0-100000): " + sw.ElapsedMilliseconds + "ms results: " + results.Count + "\r\n");
tasks.Clear();
results.Clear();
cli.FlushDb();
//sw.Reset();
//sw.Start();
//for (var a = 0; a < 100000; a++)
// cli.Call(new CommandPacket("SET").Input("TestMGet_string1").InputRaw(String));
//sw.Stop();
//Console.WriteLine("FreeRedis2: " + sw.ElapsedMilliseconds + "ms");
tasks.Clear();
results.Clear();
cli.FlushDb();
//sw.Reset();
//sw.Start();
//for (var a = 0; a < 100000; a++)
//{
// using (var rds = cli.GetTestRedisSocket())
// {
// var cmd = new CommandPacket("SET").Input("TestMGet_string1").InputRaw(String);
// rds.Write(cmd);
// cmd.Read<string>();
// }
//}
//sw.Stop();
//Console.WriteLine("FreeRedis4: " + sw.ElapsedMilliseconds + "ms");
tasks.Clear();
results.Clear();
cli.FlushDb();
sw.Reset();
sw.Start();
for (var a = 0; a < 100000; a++)
{
var tmp = Guid.NewGuid().ToString();
RedisHelper.Set(tmp, String);
var val = RedisHelper.Get(tmp);
if (val != String) throw new Exception("not equal");
results.Enqueue(val);
}
sw.Stop();
Console.WriteLine("CSRedisCore(0-100000): " + sw.ElapsedMilliseconds + "ms results: " + results.Count);
tasks.Clear();
results.Clear();
cli.FlushDb();
sw.Reset();
sw.Start();
tasks = new List<Task>();
for (var a = 0; a < 100000; a++)
{
tasks.Add(Task.Run(() =>
{
var tmp = Guid.NewGuid().ToString();
RedisHelper.Set(tmp, String);
var val = RedisHelper.Get(tmp);
if (val != String) throw new Exception("not equal");
results.Enqueue(val);
}));
}
Task.WaitAll(tasks.ToArray());
sw.Stop();
Console.WriteLine("CSRedisCore(Task.WaitAll 100000): " + sw.ElapsedMilliseconds + "ms results: " + results.Count);
tasks.Clear();
results.Clear();
cli.FlushDb();
sw.Reset();
sw.Start();
Task.Run(async () =>
{
for (var a = 0; a < 100000; a++)
{
var tmp = Guid.NewGuid().ToString();
await RedisHelper.SetAsync(tmp, String);
var val = await RedisHelper.GetAsync(tmp);
if (val != String) throw new Exception("not equal");
results.Enqueue(val);
}
}).Wait();
sw.Stop();
Console.WriteLine("CSRedisCoreAsync(0-100000): " + sw.ElapsedMilliseconds + "ms results: " + results.Count);
tasks.Clear();
results.Clear();
cli.FlushDb();
sw.Reset();
sw.Start();
tasks = new List<Task>();
for (var a = 0; a < 100000; a++)
{
tasks.Add(Task.Run(async () =>
{
var tmp = Guid.NewGuid().ToString();
await RedisHelper.SetAsync(tmp, String);
var val = await RedisHelper.GetAsync(tmp);
//if (val != String) throw new Exception("not equal");
results.Enqueue(val);
}));
}
Task.WaitAll(tasks.ToArray());
sw.Stop();
Console.WriteLine("CSRedisCoreAsync(Task.WaitAll 100000): " + sw.ElapsedMilliseconds + "ms results: " + results.Count + "\r\n");
tasks.Clear();
results.Clear();
cli.FlushDb();
}
See More Examples