当前位置: 首页>>代码示例>>C#>>正文


C# Database.Dispose方法代码示例

本文整理汇总了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();
            }
        }
开发者ID:RiiggedMPGH,项目名称:Owl-Realms-Source,代码行数:28,代码来源:verify.cs

示例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();
            }
        }
开发者ID:RiiggedMPGH,项目名称:Owl-Realms-Source,代码行数:60,代码来源:list.cs

示例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();
            }
        }
开发者ID:RiiggedMPGH,项目名称:Owl-Realms-Source,代码行数:29,代码来源:changePassword.cs

示例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));
            }
        }
开发者ID:RoxyLalonde,项目名称:Phoenix-Realms,代码行数:29,代码来源:fame.cs

示例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();
            }
        }
开发者ID:RoxyLalonde,项目名称:Phoenix-Realms,代码行数:27,代码来源:getBoard.cs

示例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);
        }
开发者ID:RoxyLalonde,项目名称:Phoenix-Realms,代码行数:54,代码来源:add.cs

示例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();
            }
        }
开发者ID:RiiggedMPGH,项目名称:Owl-Realms-Source,代码行数:42,代码来源:register.cs

示例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();
            }
        }
开发者ID:RoxyLalonde,项目名称:Phoenix-Realms,代码行数:39,代码来源:setName.cs

示例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.");
            }
        }
开发者ID:Jankos132,项目名称:Server-Source,代码行数:37,代码来源:Program.cs

示例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");
     }
 }
开发者ID:RoxyLalonde,项目名称:Phoenix-Realms,代码行数:23,代码来源:AdminCommands.cs

示例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;
        }
开发者ID:RoxyLalonde,项目名称:Phoenix-Realms,代码行数:86,代码来源:Player.cs

示例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
     {
     }
 }
开发者ID:BlackRayquaza,项目名称:PhoenixRealms,代码行数:32,代码来源:ClientProcessor.cs

示例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
     {
     }
 }
开发者ID:RoxyLalonde,项目名称:Phoenix-Realms,代码行数:32,代码来源:ClientProcessor.cs

示例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,
//.........这里部分代码省略.........
开发者ID:RiiggedMPGH,项目名称:Owl-Realms-Source,代码行数:101,代码来源:Player.Button.cs

示例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.");
        }
开发者ID:Club559,项目名称:Travs-Domain-Server,代码行数:40,代码来源:DatabaseTicker.cs


注:本文中的db.Database.Dispose方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。