Exemplo n.º 1
0
        public void IdTest()
        {
            var obj = new TestClass();
            var id  = Clsid.Id(obj);

            Assert.That(id, Is.EqualTo(Guid.Parse("33209477-886F-4031-8C34-8ACA964F1B96")));
        }
Exemplo n.º 2
0
        /// <summary>
        /// Inserts or updates (when a row with the session exists) the byte array
        /// and returns the new session Guid if none is given or the row was not found
        /// </summary>
        /// <param name="type"></param>
        /// <param name="bytes"></param>
        /// <param name="session"></param>
        /// <returns></returns>
        public Guid SaveMain(Type type, byte[] bytes, Guid?session)
        {
            var query = from m in this.Main
                        where m.session == session
                        select m;
            var main = query.FirstOrDefault();

            if (main == null)
            {
                main = new Main();
                this.Main.Add(main);    // INSERT
            }
            main.clsid = Clsid.Id(type);
            main.main  = bytes;
            this.SaveChanges();
            return(main.session);  // get the new session guid set by the db on insert
        }
Exemplo n.º 3
0
        /// <summary>
        /// Returns the (unencrypted!) literal INSERT string of the loaded object
        /// for manually exporting session dumps.
        /// </summary>
        /// <param name="type"></param>
        /// <param name="bytes"></param>
        /// <returns>SQL INSERT string</returns>
        public string InsertSQL(Type type, byte[] bytes)
        {
            var clsid = Clsid.Id(type);
            // Let the future consumer SQL Server encode the string
            // representation of the byte[] Unlike EF6 use ADO.NET Core, as the
            // connection string is usable for both contexts.
            string hex   = String.Empty;
            var    query = "SELECT CONVERT(VARCHAR(MAX), @main, 1) AS [hex]";

            using (var conn = new SqlConnection(ConnectionString))
                using (var cmd = new SqlCommand(query, conn))
                {
                    conn.Open();
                    cmd.Parameters.AddWithValue("main", bytes);
                    hex = (string)cmd.ExecuteScalar();
                }
            // Format according to get copy-pasted into Management Studio
            return(String.Format("INSERT INTO Main (clsid, main) SELECT '{0}', {1}\n" +
                                 "SELECT session FROM Main WHERE mainid = @@IDENTITY\n",
                                 clsid, hex));
        }
Exemplo n.º 4
0
        public void MissingClsidTest()
        {
            var obj = new ClsidTest();

            Assert.That(() => Clsid.Id(obj), Throws.TypeOf <ArgumentException>());
        }