本文整理汇总了C#中db.Database.Dispose方法的典型用法代码示例。如果您正苦于以下问题:C# Database.Dispose方法的具体用法?C# Database.Dispose怎么用?C# Database.Dispose使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类db.Database
的用法示例。
在下文中一共展示了Database.Dispose方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: HandleRequest
public void HandleRequest(HttpListenerContext context)
{
NameValueCollection query;
using (var rdr = new StreamReader(context.Request.InputStream))
query = HttpUtility.ParseQueryString(rdr.ReadToEnd());
using (var db = new Database())
{
Account acc = db.Verify(query["guid"], query["password"]);
if (acc == null)
{
byte[] status = Encoding.UTF8.GetBytes("<Error>Wrong Username or Password</Error>");
context.Response.OutputStream.Write(status, 0, status.Length);
}
else
{
var serializer = new XmlSerializer(acc.GetType(),
new XmlRootAttribute(acc.GetType().Name) {Namespace = ""});
var xws = new XmlWriterSettings();
xws.OmitXmlDeclaration = true;
xws.Encoding = Encoding.UTF8;
XmlWriter xtw = XmlWriter.Create(context.Response.OutputStream, xws);
serializer.Serialize(xtw, acc, acc.Namespaces);
}
db.Dispose();
}
}
示例2: HandleRequest
public void HandleRequest(HttpListenerContext context)
{
NameValueCollection query;
using (var rdr = new StreamReader(context.Request.InputStream))
query = HttpUtility.ParseQueryString(rdr.ReadToEnd());
using (var db = new Database())
{
List<ServerItem> filteredServers = null;
Account a = db.Verify(query["guid"], query["password"]);
if (a != null)
{
if (a.Banned)
{
filteredServers = YoureBanned();
}
else
{
filteredServers = GetServersForRank(a.Rank);
}
}
else
{
filteredServers = GetServersForRank(0);
}
var chrs = new Chars
{
Characters = new List<Char>(),
NextCharId = 2,
MaxNumChars = 1,
Account = db.Verify(query["guid"], query["password"]),
Servers = filteredServers
};
Account dvh = null;
if (chrs.Account != null)
{
db.GetCharData(chrs.Account, chrs);
db.LoadCharacters(chrs.Account, chrs);
chrs.News = db.GetNews(chrs.Account);
dvh = chrs.Account;
}
else
{
chrs.Account = Database.CreateGuestAccount(query["guid"]);
chrs.News = db.GetNews(null);
}
var ms = new MemoryStream();
var serializer = new XmlSerializer(chrs.GetType(),
new XmlRootAttribute(chrs.GetType().Name) {Namespace = ""});
var xws = new XmlWriterSettings();
xws.OmitXmlDeclaration = true;
xws.Encoding = Encoding.UTF8;
XmlWriter xtw = XmlWriter.Create(context.Response.OutputStream, xws);
serializer.Serialize(xtw, chrs, chrs.Namespaces);
db.Dispose();
}
}
示例3: HandleRequest
public void HandleRequest(HttpListenerContext context)
{
NameValueCollection query;
using (var rdr = new StreamReader(context.Request.InputStream))
query = HttpUtility.ParseQueryString(rdr.ReadToEnd());
using (var db = new Database())
{
Account acc = db.Verify(query["guid"], query["password"]);
byte[] status;
if (acc == null)
{
status = Encoding.UTF8.GetBytes("<Error>Bad login</Error>");
}
else
{
MySqlCommand cmd = db.CreateQuery();
cmd.CommandText = "UPDATE accounts SET password=SHA1(@password) WHERE [email protected];";
cmd.Parameters.AddWithValue("@accId", acc.AccountId);
cmd.Parameters.AddWithValue("@password", query["newPassword"]);
if (cmd.ExecuteNonQuery() > 0)
status = Encoding.UTF8.GetBytes("<Success />");
else
status = Encoding.UTF8.GetBytes("<Error>Internal error</Error>");
}
context.Response.OutputStream.Write(status, 0, status.Length);
db.Dispose();
}
}
示例4: HandleRequest
public void HandleRequest(HttpListenerContext context)
{
NameValueCollection query;
using (var rdr = new StreamReader(context.Request.InputStream))
query = HttpUtility.ParseQueryString(rdr.ReadToEnd());
using (var db = new Database())
{
Account acc = db.GetAccount(int.Parse(query["accountId"]));
Char chr = db.LoadCharacter(acc, int.Parse(query["charId"]));
MySqlCommand cmd = db.CreateQuery();
cmd.CommandText = @"SELECT time, killer, firstBorn FROM death WHERE [email protected] AND [email protected];";
cmd.Parameters.AddWithValue("@accId", query["accountId"]);
cmd.Parameters.AddWithValue("@charId", query["charId"]);
int time;
string killer;
bool firstBorn;
using (MySqlDataReader rdr = cmd.ExecuteReader())
{
rdr.Read();
time = Database.DateTimeToUnixTimestamp(rdr.GetDateTime("time"));
killer = rdr.GetString("killer");
firstBorn = rdr.GetBoolean("firstBorn");
}
db.Dispose();
using (var wtr = new StreamWriter(context.Response.OutputStream))
wtr.Write(chr.FameStats.Serialize(acc, chr, time, killer, firstBorn));
}
}
示例5: HandleRequest
public void HandleRequest(HttpListenerContext context)
{
NameValueCollection query;
using (var rdr = new StreamReader(context.Request.InputStream))
query = HttpUtility.ParseQueryString(rdr.ReadToEnd());
using (var db = new Database())
{
Account acc = db.Verify(query["guid"], query["password"]);
byte[] status;
if (acc == null)
status = Encoding.UTF8.GetBytes("<Error>Bad login</Error>");
else
{
try
{
status = Encoding.UTF8.GetBytes(db.GetGuildBoard(acc));
}
catch (Exception e)
{
status = Encoding.UTF8.GetBytes("<Error>" + e.Message + "</Error>");
}
}
context.Response.OutputStream.Write(status, 0, status.Length);
db.Dispose();
}
}
示例6: HandleRequest
public void HandleRequest(HttpListenerContext context)
{
string status;
using (var db = new Database())
{
NameValueCollection query = HttpUtility.ParseQueryString(context.Request.Url.Query);
MySqlCommand cmd = db.CreateQuery();
cmd.CommandText = "SELECT id FROM accounts WHERE [email protected]";
cmd.Parameters.AddWithValue("@uuid", query["guid"]);
object id = cmd.ExecuteScalar();
if (id != null)
{
try
{
//int amount = int.Parse(query["jwt"]);
//cmd = db.CreateQuery();
//cmd.CommandText = "UPDATE stats SET credits = credits + @amount WHERE [email protected]";
//cmd.Parameters.AddWithValue("@accId", (int)id);
//cmd.Parameters.AddWithValue("@amount", amount);
//int result = cmd.ExecuteNonQuery();
//if (result > 0)
// status = "Ya done...";
//else
// status = "Internal error :(";
status = "Yeah... We kind of fixed this...";
}
catch
{
status = "Yeah... We kind of fixed this...";
}
}
else
{
status = "Yeah... We kind of fixed this...";
}
db.Dispose();
}
byte[] res = Encoding.UTF8.GetBytes(
@"<html>
<head>
<title>Nope</title>
<script>window.close();</script>
</head>
<body style='background: #333333'>
<h1 style='color: #EEEEEE; text-align: center'>
" + status + @"
</h1>
</body>
</html>");
context.Response.OutputStream.Write(res, 0, res.Length);
}
示例7: HandleRequest
public void HandleRequest(HttpListenerContext context)
{
NameValueCollection query;
using (var rdr = new StreamReader(context.Request.InputStream))
query = HttpUtility.ParseQueryString(rdr.ReadToEnd());
using (var db = new Database())
{
byte[] status;
if (!IsValidUsername(query["newGUID"]))
status = Encoding.UTF8.GetBytes("<Error>Invalid Username</Error>");
if (db.HasUuid(query["guid"]) &&
db.Verify(query["guid"], "") != null)
{
if (db.HasUuid(query["newGUID"]))
status = Encoding.UTF8.GetBytes("<Error>Username is already taken!</Error>");
else
{
MySqlCommand cmd = db.CreateQuery();
cmd.CommandText =
"UPDATE accounts SET [email protected], [email protected], password=SHA1(@password), guest=FALSE WHERE [email protected], [email protected];";
cmd.Parameters.AddWithValue("@uuid", query["guid"]);
cmd.Parameters.AddWithValue("@newUuid", query["newGUID"]);
cmd.Parameters.AddWithValue("@password", query["newPassword"]);
if (cmd.ExecuteNonQuery() > 0)
status = Encoding.UTF8.GetBytes("<Success />");
else
status = Encoding.UTF8.GetBytes("<Error>Internal Error</Error>");
}
}
else
{
if (db.Register(query["newGUID"], query["newPassword"], false) != null)
status = Encoding.UTF8.GetBytes("<Success />");
else
status = Encoding.UTF8.GetBytes("<Error>Internal Error</Error>");
}
context.Response.OutputStream.Write(status, 0, status.Length);
db.Dispose();
}
}
示例8: HandleRequest
public void HandleRequest(HttpListenerContext context)
{
NameValueCollection query;
using (var rdr = new StreamReader(context.Request.InputStream))
query = HttpUtility.ParseQueryString(rdr.ReadToEnd());
using (var db = new Database())
{
Account acc = db.Verify(query["guid"], query["password"]);
byte[] status;
if (acc == null)
{
status = Encoding.UTF8.GetBytes("<Error>Bad login</Error>");
}
else
{
MySqlCommand cmd = db.CreateQuery();
object exescala;
cmd.CommandText = "SELECT COUNT(name) FROM accounts WHERE [email protected];";
cmd.Parameters.AddWithValue("@name", query["name"]);
exescala = cmd.ExecuteScalar();
if (int.Parse(exescala.ToString()) > 0)
status = Encoding.UTF8.GetBytes("<Error>Duplicated name</Error>");
else
{
cmd = db.CreateQuery();
cmd.CommandText = "UPDATE accounts SET [email protected], namechosen=TRUE WHERE [email protected];";
cmd.Parameters.AddWithValue("@accId", acc.AccountId);
cmd.Parameters.AddWithValue("@name", query["name"]);
if (cmd.ExecuteNonQuery() != 0)
status = Encoding.UTF8.GetBytes("<Success />");
else
status = Encoding.UTF8.GetBytes("<Error>Internal error</Error>");
}
}
context.Response.OutputStream.Write(status, 0, status.Length);
db.Dispose();
}
}
示例9: Main
static void Main(string[] args)
{
XmlConfigurator.ConfigureAndWatch(new FileInfo("log4net.config"));
Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;
Thread.CurrentThread.Name = "Entry";
using (Settings = new SimpleSettings("wServer"))
{
var db = new Database(Settings.GetValue("conn"));
RealmManager manager = new RealmManager(
Settings.GetValue<int>("maxClient", "100"),
Settings.GetValue<int>("tps", "20"),
db);
manager.Initialize();
manager.Run();
Server server = new Server(manager, 2050);
PolicyServer policy = new PolicyServer();
Console.CancelKeyPress += (sender, e) => e.Cancel = true;
policy.Start();
server.Start();
log.Info("Server initialized.");
while (Console.ReadKey(true).Key != ConsoleKey.Escape) ;
log.Info("Terminating...");
server.Stop();
policy.Stop();
manager.Stop();
db.Dispose();
log.Info("Server terminated.");
}
}
示例10: Execute
public void Execute(Player player, string[] args)
{
try
{
if (args.Length == 0)
{
player.SendHelp("Use /gold <amount>");
}
else
{
using (var db = new Database())
{
player.Credits = db.UpdateCredit(player.Client.Account, int.Parse(args[0]));
player.UpdateCount++;
db.Dispose();
}
}
}
catch
{
player.SendError("Error");
}
}
示例11: Player
public Player(ClientProcessor psr)
: base((short) psr.Character.ObjectType, psr.Random)
{
this.psr = psr;
statsMgr = new StatsManager(this);
nName = psr.Account.Name;
AccountId = psr.Account.AccountId;
if (psr.Account.Tag != "")
{
Name = "[" + psr.Account.Tag + "] " + psr.Account.Name;
}
else
{
Name = psr.Account.Name;
}
Level = psr.Character.Level;
Experience = psr.Character.Exp;
ExperienceGoal = GetExpGoal(psr.Character.Level);
if (psr.Account.Name == "Lucifer" || psr.Account.Name == "Luciferus" || psr.Account.Name == "Amaymon")
Stars = 666;
else if (psr.Account.Rank > 2)
Stars = 100;
else if (psr.Account.Rank > 1)
Stars = 95;
else
Stars = GetStars(); //Temporary (until pub server)
Texture1 = psr.Character.Tex1;
Texture2 = psr.Character.Tex2;
Credits = psr.Account.Credits;
zTokens = psr.Account.zTokens;
NameChosen = psr.Account.NameChosen;
CurrentFame = psr.Account.Stats.Fame;
Fame = psr.Character.CurrentFame;
var state = psr.Account.Stats.ClassStates.SingleOrDefault(_ => _.ObjectType == ObjectType);
FameGoal = GetFameGoal(state != null ? state.BestFame : 0);
Glowing = false;
Guild = psr.Account.Guild.Name;
GuildRank = psr.Account.Guild.Rank;
if (psr.Character.HitPoints <= 0)
{
HP = psr.Character.MaxHitPoints;
psr.Character.HitPoints = psr.Character.MaxHitPoints;
}
else
HP = psr.Character.HitPoints;
MP = psr.Character.MagicPoints;
ConditionEffects = 0;
OxygenBar = 100;
Decision = 0;
price = new Prices();
Locked = psr.Account.Locked ?? new List<int>();
Ignored = psr.Account.Ignored ?? new List<int>();
try
{
using (var dbx = new Database())
{
Locked = dbx.GetLockeds(AccountId);
Ignored = dbx.GetIgnoreds(AccountId);
dbx.Dispose();
}
}
catch
{
}
Inventory =
psr.Character.Equipment.Select(
_ => _ == -1 ? null : (XmlDatas.ItemDescs.ContainsKey(_) ? XmlDatas.ItemDescs[_] : null)).ToArray();
SlotTypes = Utils.FromCommaSepString32(XmlDatas.TypeToElement[ObjectType].Element("SlotTypes").Value);
Stats = new[]
{
psr.Character.MaxHitPoints,
psr.Character.MaxMagicPoints,
psr.Character.Attack,
psr.Character.Defense,
psr.Character.Speed,
psr.Character.HpRegen,
psr.Character.MpRegen,
psr.Character.Dexterity
};
Pet = null;
}
示例12: Save
public void Save()
{
try
{
if (Database != null)
{
if (Character != null)
{
Player.SaveToCharacter();
if (Player.Owner.Id != -6)
Database.SaveCharacter(Account, Character);
}
Database.Dispose();
Database = null;
}
else
{
Database = new Database();
if (Character != null)
{
Player.SaveToCharacter();
if (Player.Owner.Id != -6)
Database.SaveCharacter(Account, Character);
}
Database.Dispose();
Database = null;
}
}
catch
{
}
}
示例13: Save
public void Save()
{
try
{
if (db != null)
{
if (character != null)
{
entity.SaveToCharacter();
if (entity.Owner.Id != -6)
db.SaveCharacter(account, character);
}
db.Dispose();
db = null;
}
else
{
db = new Database();
if (character != null)
{
entity.SaveToCharacter();
if (entity.Owner.Id != -6)
db.SaveCharacter(account, character);
}
db.Dispose();
db = null;
}
}
catch
{
}
}
示例14: TextBoxButton
public void TextBoxButton(TextBoxButtonPacket pkt)
{
var type = pkt.Type;
if (type == "test")
{
psr.SendPacket(new TextBoxPacket
{
Button1 = "Yes",
Button2 = "No",
Message = "Do you want to enter the testing arena?",
Title = "Testing Arena Confirmation",
Type = "EnterTestArena"
});
}
if (type == "NewClient")
{
psr.Disconnect();
}
if (type == "DecideArena")
{
if (pkt.Button == 1)
{
psr.SendPacket(new TextBoxPacket
{
Button1 = "Enter",
Button2 = "Cancel",
Message = "Host an arena at the price of x fame?",
Title = "Arena Host Confirmation",
Type = "EnterArena2"
});
}
else
{
psr.SendPacket(new TextBoxPacket
{
Button1 = "Enter",
Button2 = "Cancel",
Message = "Enter the arena solo at the price of 150 fame?",
Title = "Solo Arena Confirmation",
Type = "EnterArena1"
});
}
}
if (type == "EnterTestArena")
{
if (pkt.Button == 1)
{
if (Client.Account.Stats.Fame >= 150)
{
/*RealmManager.PlayerWorldMapping.TryAdd(this.AccountId, Owner);
psr.Reconnect(new ReconnectPacket()
{
Host = "",
Port = 2050,
GameId = world.Id,
Name = world.Name,
Key = Empty<byte>.Array,
});
*/
}
else
{
SendHelp("Not Enough Fame");
}
}
else
{
SendInfo("Cancelled entering arena.");
}
}
if (type == "EnterArena1")
{
if (pkt.Button == 1)
{
if (Client.Account.Stats.Fame >= 50)
{
using (var db = new Database())
{
db.UpdateFame(psr.Account, -50);
db.Dispose();
}
var world = RealmManager.GetWorld(World.NEXUS_ID);
var fworld = false;
foreach (var i in RealmManager.Worlds)
if (i.Value is BattleArenaMap)
if ((i.Value as BattleArenaMap).Joinable)
{
world = i.Value;
fworld = true;
break;
}
if (!fworld)
world = RealmManager.AddWorld(new BattleArenaMap());
psr.Reconnect(new ReconnectPacket
{
Host = "",
Port = 2050,
//.........这里部分代码省略.........
示例15: TickLoop
public void TickLoop()
{
log.Info("Database loop started.");
do
{
//First finish every db query
if (Manager.Terminating)
{
bool empty = true;
foreach (var i in pendings)
{
if (i.Count > 0)
{
empty = false;
break;
}
}
if (empty) break;
}
foreach (ConcurrentQueue<Action<Database>> i in pendings)
{
Action<Database> callback;
while (i.TryDequeue(out callback))
{
try
{
Database db = new Database(Program.Settings.GetValue("conn"));
callback(db);
db.Dispose();
}
catch (Exception ex)
{
log.Error(ex);
}
}
}
} while (true);
log.Info("Database loop stopped.");
}