Beispiel #1
0
        public static void putMemo(string message, string to, string from)
        {
            Memo memo = new Memo(message, from);

            using (MemoDbConnection conn = new MemoDbConnection())
            {
                conn.BeginTransaction();
                try {
                    using (MemoDbContext ctx = new MemoDbContext(conn.Connection, false))
                    {
                        ctx.Database.UseTransaction(conn.Transaction);

                        var q = from u in ctx.Users where
                            u.Username.Equals (to)
                            select u;

                        if (q.Count() != 1) {
                            conn.CommitTransaction();
                            return;
                        }
                        User toUser = q.First();

                        ctx.Memos.Add(memo);
                        toUser.Memos.Add(memo);
                        ctx.SaveChanges();
                    }
                    conn.CommitTransaction();
                }
                catch
                {
                    conn.RollbackTransaction();
                    throw;
                }
            }
        }
Beispiel #2
0
        static void Debug()
        {
            Console.WriteLine ("Debug");

            using (MemoDbConnection conn = new MemoDbConnection())
            {
                conn.BeginTransaction();
                try {
                    using (MemoDbContext ctx = new MemoDbContext(conn.Connection, false))
                    {
                        ctx.Database.Log = (string message) => { Console.WriteLine(message); };
                        ctx.Database.UseTransaction(conn.Transaction);

                        Memo testMemo = new Memo("Hello", "d");
                        User anon = new User {
                            Username = "******",
                            Password = "******",
                            LastOnline = DateTime.UtcNow
                        };
                        Peer peer = new Peer {
                            Address = new Uri("http://localhost:8088").ToString(),
                            MAC_AddressHash = "pass"
                        };

            //						ctx.Memos.Add(testMemo);
            //						ctx.Users.Add(anon);
            //						ctx.Peers.Add(peer);
            //						anon.Memos.Add(testMemo);
            //						ctx.SaveChanges();
                    }

                    conn.CommitTransaction();
                }
                catch
                {
                    conn.RollbackTransaction();
                    throw;
                }
            }

            try {
                NickManager.registerNick ("nickkk", "MAChashMD5");
                System.Console.WriteLine ("registration OK");
            } catch (Exception ex) {
                System.Console.WriteLine (ex.Message);
            }

            try {
                NickManager.refreshNick ("nickkk", "MAChashMD5");
                System.Console.WriteLine ("refresh OK");
            } catch (Exception ex) {
                System.Console.WriteLine (ex.Message);
            }

            try {
                NickManager.refreshNick ("nickkkkk", "MAChashMD5");
                System.Console.WriteLine ("refresh OK");
            } catch (Exception ex) {
                System.Console.WriteLine (ex.Message);
            }
            System.Console.WriteLine ();

            try {
                PeerManager.registerPeer("ddsgsgsdffcdsfg", new Uri ("http://localhost:53215") );
                System.Console.WriteLine ("peer registration OK");
            } catch (Exception ex) {
                System.Console.WriteLine (ex.Message);
            }
            System.Console.WriteLine ();

            try {
                MemoManager.putMemo("hali", "Anonymous", "d");
                MemoManager.putMemo("hali", "nickkk", "d");
                MemoManager.putMemo("hali", "nickkkkkkkkkk", "d");
                System.Console.WriteLine ("Memo added!");
            } catch (Exception ex) {
                System.Console.WriteLine (ex.Message);
            }
            System.Console.WriteLine ();
        }