コード例 #1
0
ファイル: lambda.cs プロジェクト: mconnew/dotnet-api-docs
    static void Main()
    {
        //<SnippetInitWithLambda>
        lazyLargeObject = new Lazy <LargeObject>(() =>
        {
            LargeObject large = new LargeObject(Thread.CurrentThread.ManagedThreadId);
            // Perform additional initialization here.
            return(large);
        });
        //</SnippetInitWithLambda>

        Console.WriteLine(
            "\r\nLargeObject is not created until you access the Value property of the lazy" +
            "\r\ninitializer. Press Enter to create LargeObject.");
        Console.ReadLine();

        // Create and start 3 threads, each of which uses LargeObject.
        Thread[] threads = new Thread[3];
        for (int i = 0; i < 3; i++)
        {
            threads[i] = new Thread(ThreadProc);
            threads[i].Start();
        }

        // Wait for all 3 threads to finish.
        foreach (Thread t in threads)
        {
            t.Join();
        }

        Console.WriteLine("\r\nPress Enter to end the program");
        Console.ReadLine();
    }
コード例 #2
0
        /// <summary>
        /// Creates a new media object.
        /// </summary>
        /// <param name="media">The memory stream containing the media.</param>
        /// <param name="type">The media type.</param>
        /// <param name="rpu">A delegate of type <see cref="StatusMessageReportProgress"/> used to send messages back to the calling object.</param>
        /// <param name="caller">The calling object.</param>
        /// <returns>The id for the new media object.</returns>
        /// <remarks>Documented by Dev03, 2008-08-05</remarks>
        /// <remarks>Documented by Dev03, 2009-01-13</remarks>
        public int CreateMedia(Stream media, EMedia type, StatusMessageReportProgress rpu, object caller)
        {
            using (NpgsqlConnection conn = PostgreSQLConn.CreateConnection(Parent.CurrentUser))
            {
                NpgsqlTransaction tran = conn.BeginTransaction();

                LargeObjectManager lbm  = new LargeObjectManager(conn);
                int         noid        = lbm.Create(LargeObjectManager.READWRITE);
                LargeObject largeObject = lbm.Open(noid, LargeObjectManager.READWRITE);
                byte[]      buffer      = new byte[media.Length];
                media.Read(buffer, 0, (int)media.Length);
                BufferToLargeObject(buffer, largeObject, rpu, caller);
                largeObject.Close();

                int newId = 0;
                using (NpgsqlCommand cmd = conn.CreateCommand())
                {
                    cmd.CommandText = "INSERT INTO \"MediaContent\" (data, media_type) VALUES (:data, :type) RETURNING id;";
                    cmd.Parameters.Add("data", noid);
                    cmd.Parameters.Add("type", type.ToString());
                    newId = Convert.ToInt32(PostgreSQLConn.ExecuteScalar(cmd, Parent.CurrentUser));
                }
                tran.Commit();

                return(newId);
            }
        }
コード例 #3
0
    static void Main()
    {
        // The lazy initializer is created here. LargeObject is not created until the
        // ThreadProc method executes.
        lazyLargeObject = new Lazy <LargeObject>(InitLargeObject, false);

        // The following lines show how to use other constructors to achieve exactly the
        // same result as the previous line:
        //lazyLargeObject = new Lazy<LargeObject>(InitLargeObject, LazyThreadSafetyMode.None);


        Console.WriteLine(
            "\r\nLargeObject is not created until you access the Value property of the lazy" +
            "\r\ninitializer. Press Enter to create LargeObject (three tries).");
        Console.ReadLine();

        for (int i = 0; i < 3; i++)
        {
            try
            {
                LargeObject large = lazyLargeObject.Value;
                large.Data[11] = 89;
            }
            catch (ApplicationException aex)
            {
                Console.WriteLine("Exception: {0}", aex.Message);
            }
        }

        Console.WriteLine("\r\nPress Enter to end the program");
        Console.ReadLine();
    }
コード例 #4
0
        /// <summary>
        /// Writes the media object to a stream.
        /// </summary>
        /// <param name="mediaId">The media id.</param>
        /// <param name="output">The output.</param>
        private void WriteMedia(int mediaId, Stream output)
        {
            using (NpgsqlConnection conn = FileHandlerHelpers.GetPgConnection())
            {
                int noid = 0;
                using (NpgsqlCommand cmd = conn.CreateCommand())
                {
                    cmd.CommandText = "SELECT data FROM \"MediaContent\" WHERE id=:id;";
                    cmd.Parameters.Add("id", mediaId);
                    noid = Convert.ToInt32(cmd.ExecuteScalar());
                }

                NpgsqlTransaction  tran        = conn.BeginTransaction();
                LargeObjectManager lbm         = new LargeObjectManager(conn);
                LargeObject        largeObject = lbm.Open(noid, LargeObjectManager.READWRITE);
                largeObject.Seek(0);
                int    size   = largeObject.Size();
                byte[] buffer = new byte[size];
                int    read   = 0;
                int    offset = 0;
                while (offset < size)
                {
                    read = largeObject.Read(buffer, offset, Math.Min(102400, size - offset));
                    output.Write(buffer, offset, read);
                    offset += 102400;
                }
                largeObject.Close();
                tran.Commit();
            }
        }
コード例 #5
0
ファイル: collect.cs プロジェクト: rendle-labs/coreclr
    private bool collectLargeObject(int gen)
    {
        numTests++;
        LargeObject lo;

        try {
            lo = new LargeObject(size, true);
        } catch (OutOfMemoryException) {
            Console.WriteLine("Large Memory Machine required");
            return(false);
        } catch (Exception e) {
            Console.WriteLine("Unexpected Exception:");
            Console.WriteLine(e);
            return(false);
        }
        lo = null;
        GC.Collect(gen);
        GC.WaitForPendingFinalizers();
        GC.Collect(gen);

        if (LargeObject.FinalizedCount > 0)
        {
            Console.WriteLine("collectLargeObject {0} passed", gen);
            return(true);
        }

        Console.WriteLine("collectLargeObject {0} failed", gen);
        return(false);
    }
コード例 #6
0
ファイル: gettotalmemory.cs プロジェクト: geoffkizer/coreclr
    public bool RunTests() {

        try {
            LargeObject lo = new LargeObject(size);
            long mem  = GC.GetTotalMemory(false);
            long delta = (long)(size*LargeObject.GB)/(long)10;

            if ( (mem - size*LargeObject.GB)> delta) {
                Console.WriteLine("{0} {1} {2}", mem, size*LargeObject.GB, delta);
                return false;
            }

            GC.KeepAlive(lo);

        } catch (OutOfMemoryException) {
            Console.WriteLine("Large Memory Machine required");
            return false;
        } catch (Exception e) {
            Console.WriteLine("Unexpected Exception:");
            Console.WriteLine(e);
            return false;
        }

        return true;

    }
コード例 #7
0
        /// <summary>
        /// Gets the extension stream.
        /// </summary>
        /// <param name="guid">The GUID.</param>
        /// <returns></returns>
        public Stream GetExtensionStream(Guid guid)
        {
            MemoryStream stream = null;

            using (NpgsqlConnection con = PostgreSQLConn.CreateConnection(Parent.CurrentUser))
            {
                int noid = 0;
                using (NpgsqlCommand cmd = con.CreateCommand())
                {
                    cmd.CommandText = "SELECT data FROM \"Extensions\" WHERE guid=:guid;";
                    cmd.Parameters.Add("guid", guid.ToString());
                    object obj = PostgreSQLConn.ExecuteScalar(cmd, Parent.CurrentUser);
                    if (obj == null || obj == DBNull.Value || !(obj as long?).HasValue)
                    {
                        return(stream);
                    }
                    noid = Convert.ToInt32((obj as long?).Value);
                }

                NpgsqlTransaction tran = con.BeginTransaction();
                try
                {
                    LargeObjectManager lbm         = new LargeObjectManager(con);
                    LargeObject        largeObject = lbm.Open(noid, LargeObjectManager.READWRITE);
                    byte[]             buffer      = LargeObjectToBuffer(largeObject);
                    stream = new MemoryStream(buffer);
                    largeObject.Close();
                }
                catch { }
                finally { tran.Commit(); }
            }
            return(stream);
        }
コード例 #8
0
    public bool RunTests()
    {
        try {
            LargeObject lo = new LargeObject(size);

            GC.Collect();
            GC.WaitForPendingFinalizers();
            GC.Collect();

            if (lo == null)
            {
                return(false);
            }
            GC.KeepAlive(lo);
        } catch (OutOfMemoryException) {
            Console.WriteLine("Large Memory Machine required");
            return(false);
        } catch (Exception e) {
            Console.WriteLine("Unexpected Exception:");
            Console.WriteLine(e);
            return(false);
        }

        return(true);
    }
コード例 #9
0
ファイル: collect.cs プロジェクト: rendle-labs/coreclr
    private bool collectLargeObject(int gen) {
        numTests++;
        LargeObject lo;
        try {
            lo = new LargeObject(size, true);
        } catch (OutOfMemoryException) {
            Console.WriteLine("Large Memory Machine required");
            return false;
        } catch (Exception e) {
            Console.WriteLine("Unexpected Exception:");
            Console.WriteLine(e);
            return false;
        }
        lo = null;
        GC.Collect(gen);
        GC.WaitForPendingFinalizers();
        GC.Collect(gen);

        if (LargeObject.FinalizedCount>0) {
            Console.WriteLine("collectLargeObject {0} passed", gen);
            return true;
        }

        Console.WriteLine("collectLargeObject {0} failed", gen);
        return false;
    }
コード例 #10
0
        /// <summary>
        /// Updates the media.
        /// </summary>
        /// <param name="id">The id.</param>
        /// <param name="media">The media.</param>
        /// <remarks>Documented by Dev02, 2008-08-06</remarks>
        /// <remarks>Documented by Dev03, 2009-01-13</remarks>
        public void UpdateMedia(int id, Stream media)
        {
            using (NpgsqlConnection con = PostgreSQLConn.CreateConnection(Parent.CurrentUser))
            {
                NpgsqlTransaction tran = con.BeginTransaction();

                int noid;
                using (NpgsqlCommand cmd = con.CreateCommand())
                {
                    cmd.CommandText = "SELECT data FROM \"MediaContent\" WHERE id=:id";
                    cmd.Parameters.Add("id", id);
                    noid = Convert.ToInt32(PostgreSQLConn.ExecuteScalar(cmd, Parent.CurrentUser));
                }

                LargeObjectManager lbm = new LargeObjectManager(con);
                lbm.Delete(noid);

                noid = lbm.Create(LargeObjectManager.READWRITE);
                LargeObject largeObject = lbm.Open(noid, LargeObjectManager.READWRITE);
                byte[]      buffer      = new byte[media.Length];
                media.Read(buffer, 0, (int)media.Length);
                BufferToLargeObject(buffer, largeObject);
                largeObject.Close();

                using (NpgsqlCommand cmd = con.CreateCommand())
                {
                    cmd.CommandText = "UPDATE \"MediaContent\" SET data=:data WHERE id=:id";
                    cmd.Parameters.Add("id", id);
                    cmd.Parameters.Add("data", noid);
                    PostgreSQLConn.ExecuteNonQuery(cmd, Parent.CurrentUser);
                }

                tran.Commit();
            }
        }
コード例 #11
0
    LargeObject buildDesk()
    {
        LargeObject d = new LargeObject();

        d.hotspots = new List <Hotspot>();        //Nothing on top yet
        d.prefab   = desk;
        d.padding  = Absolute(d.prefab.rotation * new Vector3(0.15f, 0.0f, 0.0f));

        Hotspot main = new Hotspot();

        // Positioned determined by hand
        main.position  = new Vector3(0.11f, -0.1872f, -0.1f);
        main.direction = new Vector3(0, 0, 0);
        main.angle     = Quaternion.Euler(0, 180, 0);
        d.hotspots.Add(main);

        Hotspot accessory = new Hotspot();

        // Positioned determined by hand
        accessory.position  = new Vector3(0.06f, -0.1872f, 0.45f);
        accessory.direction = new Vector3(0, 0, 0);
        accessory.angle     = Quaternion.Euler(0, 0, 0);
        d.hotspots.Add(accessory);

        Hotspot small = new Hotspot();

        // Positioned determined by hand
        small.position  = new Vector3(0.06f, -0.1872f, -0.52f);
        small.direction = new Vector3(0, 0, 0);
        small.angle     = Quaternion.Euler(0, 00, 0);
        d.hotspots.Add(small);

        return(d);
    }
コード例 #12
0
    // Centers on half the topper's size in the direction of the hotspot.
    // Rotation is possibly inconsequential, provided that the prefabs have
    // been properly rotated to standing position.
    Vector3 SnapToHotspot(LargeObject bot, Transform top, int index, Quaternion rot)
    {
        Bounds bnds = GetBounds(top);

        bnds.center = rot * bnds.center;
        bnds.size   = RotatedBounds(bnds.size, rot.eulerAngles.y);

        Vector3 outvec = GetBounds(bot.instantiated).center + bot.instantiated.rotation * bot.hotspots[index].position +
                         ElemwiseProduct(bnds.size / 2, bot.hotspots[index].direction);

        outvec.y = YTop(bot.instantiated) + bnds.size.y / 2 + (bot.instantiated.rotation * bot.hotspots[index].position).y;
        outvec   = outvec - bnds.center;

        /*Debug.Log("Hotspot position " + bot.hotspots[index].position.ToString() +
         * "\nrotated hotspot position " + bot.instantiated.rotation*bot.hotspots[index].position +
         * "\nbot position " + bot.instantiated.position.ToString() +
         * "\nbot padding " + bot.padding.ToString() +
         * "\nbot direction " + bot.direction.ToString() +
         * "\nbot " + GetBounds(bot.instantiated).ToString() +
         * "\ntop " + GetBounds(top) +
         * "\nfinal output " + outvec.ToString());*/
        return(outvec);

        /* VERY VERY IMPORTANT
         * Prefabs must have their rotation on the X and Z axes set to have them stand upright.
         * Rotation on the Y axis will have to depend on the hotspot's direction.
         */
    }
コード例 #13
0
ファイル: getgeneration.cs プロジェクト: geoffkizer/coreclr
    private bool getGeneration() {
        numTests++;

        int gen = -1;

        try {
            LargeObject lo = new LargeObject(size);
            gen = GC.GetGeneration(lo);

        } catch (OutOfMemoryException) {
            Console.WriteLine("Large Memory Machine required");
            return false;
        } catch (Exception e) {
            Console.WriteLine("Unexpected Exception:");
            Console.WriteLine(e);
            return false;
        }

        if (gen==GC.MaxGeneration) {
            Console.WriteLine("getGeneration passed");
            return true;
        }

        Console.WriteLine(gen);
        Console.WriteLine("getGeneration failed");
        return false;
    }
コード例 #14
0
    private bool getGeneration()
    {
        numTests++;

        int gen = -1;

        try {
            LargeObject lo = new LargeObject(size);
            gen = GC.GetGeneration(lo);
        } catch (OutOfMemoryException) {
            Console.WriteLine("Large Memory Machine required");
            return(false);
        } catch (Exception e) {
            Console.WriteLine("Unexpected Exception:");
            Console.WriteLine(e);
            return(false);
        }

        if (gen == GC.MaxGeneration)
        {
            Console.WriteLine("getGeneration passed");
            return(true);
        }

        Console.WriteLine(gen);
        Console.WriteLine("getGeneration failed");
        return(false);
    }
コード例 #15
0
    public bool RunTests()
    {
        try {
            LargeObject lo    = new LargeObject(size);
            long        mem   = GC.GetTotalMemory(false);
            long        delta = (long)(size * LargeObject.MB) / (long)10;

            if ((mem - size * LargeObject.MB) > delta)
            {
                Console.WriteLine("{0} {1} {2}", mem, size * LargeObject.MB, delta);
                return(false);
            }

            GC.KeepAlive(lo);
        } catch (OutOfMemoryException) {
            Console.WriteLine("Large Memory Machine required");
            return(false);
        } catch (Exception e) {
            Console.WriteLine("Unexpected Exception:");
            Console.WriteLine(e);
            return(false);
        }

        return(true);
    }
コード例 #16
0
ファイル: example.cs プロジェクト: ruo2012/samples-1
    static void ThreadProc(object state)
    {
        // Wait for the signal.
        ManualResetEvent waitForStart = (ManualResetEvent)state;

        waitForStart.WaitOne();

        //<SnippetValueProp>
        LargeObject large = null;

        try
        {
            large = lazyLargeObject.Value;

            // The following line introduces an artificial delay to exaggerate the race condition.
            Thread.Sleep(5);

            // IMPORTANT: Lazy initialization is thread-safe, but it doesn't protect the
            //            object after creation. You must lock the object before accessing it,
            //            unless the type is thread safe. (LargeObject is not thread safe.)
            lock (large)
            {
                large.Data[0] = Thread.CurrentThread.ManagedThreadId;
                Console.WriteLine("LargeObject was initialized by thread {0}; last used by thread {1}.",
                                  large.InitializedBy, large.Data[0]);
            }
        }
        catch (ApplicationException ex)
        {
            Console.WriteLine("ApplicationException: {0}", ex.Message);
        }
        //</SnippetValueProp>
    }
コード例 #17
0
ファイル: example.cs プロジェクト: zhamppx97/dotnet-api-docs
    static void Main()
    {
        // The lazy initializer is created here. LargeObject is not created until the
        // ThreadProc method executes.
        //<SnippetNewLazy>
        lazyLargeObject = new Lazy <LargeObject>(false);

        // The following lines show how to use other constructors to achieve exactly the
        // same result as the previous line:
        //lazyLargeObject = new Lazy<LargeObject>(LazyThreadSafetyMode.None);
        //</SnippetNewLazy>

        Console.WriteLine(
            "\r\nLargeObject is not created until you access the Value property of the lazy" +
            "\r\ninitializer. Press Enter to create LargeObject.");
        Console.ReadLine();

        //<SnippetValueProp>
        LargeObject large = lazyLargeObject.Value;

        //</SnippetValueProp>

        large.Data[11] = 89;

        Console.WriteLine("\r\nPress Enter to end the program");
        Console.ReadLine();
    }
コード例 #18
0
ファイル: ConnectionTests.cs プロジェクト: zapov/Npgsql2
        public void NpgsqlErrorRepro1()
        {
            using (NpgsqlConnection connection = new NpgsqlConnection(TheConnectionString))
            {
                connection.Open();
                using (NpgsqlTransaction transaction = connection.BeginTransaction())
                {
                    LargeObjectManager largeObjectMgr = new LargeObjectManager(connection);
                    try
                    {
                        LargeObject largeObject = largeObjectMgr.Open(-1, LargeObjectManager.READWRITE);
                        transaction.Commit();
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.ToString());
                        // ignore the LO failure
                    }
                } // *1* sometimes it throws "System.NotSupportedException: This stream does not support seek operations"

                using (NpgsqlCommand command = connection.CreateCommand())
                {
                    command.CommandText = "SELECT * FROM pg_database";
                    using (NpgsqlDataReader reader = command.ExecuteReader())
                    {
                        Assert.IsTrue(reader.Read()); // *2* this fails if the initial connection is used
                    }
                }
            } // *3* sometimes it throws "System.NotSupportedException: This stream does not support seek operations"
        }
コード例 #19
0
    static LargeObject InitLargeObject()
    {
        LargeObject large = new LargeObject(Thread.CurrentThread.ManagedThreadId);

        // Perform additional initialization here.
        return(large);
    }
コード例 #20
0
        public LargeObject HandleLargeObject(LargeObject largeObject)
        {
            // A client invoked this method with a LargeObject
            Console.WriteLine("Received LargeObject. Returning it to the sender");

            // Return the LargeObject to the calling client
            return(largeObject);
        }
コード例 #21
0
    LargeObject buildCabinet()
    {
        LargeObject c = new LargeObject();

        c.hotspots = new List <Hotspot>();        //Nothing on top yet
        c.prefab   = cabinet;
        c.padding  = Absolute(c.prefab.rotation * new Vector3(0.2f, 0.0f, 0.0f));
        return(c);
    }
コード例 #22
0
    LargeObject buildFridge()
    {
        LargeObject f = new LargeObject();

        f.hotspots = new List <Hotspot>();        //Nothing on top yet
        f.prefab   = refrigerator;
        f.padding  = Absolute(f.prefab.rotation * new Vector3(0.15f, 0.0f, 0.0f));
        return(f);
    }
コード例 #23
0
 public int GetLargeObjectSize(int oid)
 {
     using (IDbTransaction transaction = BeginTransaction()) {
         int         result;
         LargeObject obj = Manager.Open(oid);
         result = obj.Size();
         obj.Close();
         return(result);
     }
 }
コード例 #24
0
    LargeObject buildTVArea()
    {
        LargeObject tv = new LargeObject();

        tv.hotspots = new List <Hotspot>();        //Nothing on top yet
        tv.prefab   = TV_area;
        tv.padding  = Absolute(tv.prefab.rotation * new Vector3(0.15f, 0.0f, 0.0f));

        return(tv);
    }
コード例 #25
0
    LargeObject buildDoor()
    {
        LargeObject d = new LargeObject();

        d.hotspots = new List <Hotspot>();        //Nothing on top yet
        d.prefab   = door;
        d.padding  = Absolute(d.prefab.rotation * new Vector3(0.15f, 0.0f, 0.0f));

        return(d);
    }
コード例 #26
0
    LargeObject buildBookcase()
    {
        LargeObject b = new LargeObject();

        b.hotspots = new List <Hotspot>();        //Nothing on top yet
        b.prefab   = bookcase;
        b.padding  = Absolute(b.prefab.rotation * new Vector3(0.0f, 0.0f, 0.0f));

        return(b);
    }
コード例 #27
0
 public DBFileStream(DBFile file, DB db)
 {
     try {
         transaction = db.dbcon.BeginTransaction();
         obj         = db.Manager.Open(file.file_id.Value);
     } catch {
         if (transaction != null)
         {
             transaction.Rollback();
             transaction = null;
         }
     }
 }
コード例 #28
0
        private readonly int chunkSize = 204800; //200 KB

        /// <summary>
        /// Writes the content of a buffer into a LargeObject.
        /// </summary>
        /// <param name="buffer">The buffer.</param>
        /// <param name="largeObject">The large object.</param>
        /// <remarks>Documented by Dev02, 2008-08-08</remarks>
        private void BufferToLargeObject(byte[] buffer, LargeObject largeObject)
        {
            largeObject.Seek(0);

            int offset = 0;
            int size   = buffer.Length;

            while (offset < size)
            {
                largeObject.Write(buffer, offset, Math.Min(chunkSize, size - offset));
                offset += chunkSize;
            }
        }
コード例 #29
0
        private void Dispose(bool disposing)
        {
            if (disposing)
            {
                if (LargeObject != null)
                {
                    LargeObject.Dispose();
                }
            }

            Encoding    = null;
            LargeObject = null;
        }
コード例 #30
0
    static void ThreadProc(object state)
    {
        LargeObject large = lazyLargeObject.Value;

        // IMPORTANT: Lazy initialization is thread-safe, but it doesn't protect the
        //            object after creation. You must lock the object before accessing it,
        //            unless the type is thread safe. (LargeObject is not thread safe.)
        lock (large)
        {
            large.Data[0] = Thread.CurrentThread.ManagedThreadId;
            Console.WriteLine("Initialized by thread {0}; last used by thread {1}.",
                              large.InitializedBy, large.Data[0]);
        }
    }
コード例 #31
0
ファイル: ConnectionTests.cs プロジェクト: zapov/Npgsql2
        public void NpgsqlErrorRepro2()
        {
            NpgsqlConnection connection = new NpgsqlConnection(TheConnectionString);

            connection.Open();
            NpgsqlTransaction  transaction    = connection.BeginTransaction();
            LargeObjectManager largeObjectMgr = new LargeObjectManager(connection);

            try
            {
                LargeObject largeObject = largeObjectMgr.Open(-1, LargeObjectManager.READWRITE);
                transaction.Commit();
            }
            catch
            {
                // ignore the LO failure
                try
                {
                    transaction.Dispose();
                }
                catch
                {
                    // ignore dispose failure
                }
                try
                {
                    connection.Dispose();
                }
                catch
                {
                    // ignore dispose failure
                }
            }

            using (connection = new NpgsqlConnection(TheConnectionString))
            {
                connection.Open();
                using (NpgsqlCommand command = connection.CreateCommand())
                {
                    command.CommandText = "SELECT * FROM pg_database";
                    using (NpgsqlDataReader reader = command.ExecuteReader())
                    {
                        Assert.IsTrue(reader.Read());
                        // *1* this fails if the connection for the pool happens to be the bad one from above
                        Assert.IsTrue(!String.IsNullOrEmpty((string)reader["datname"]));
                    }
                }
            }
        }
コード例 #32
0
ファイル: Program.cs プロジェクト: arthur-avetikyan/Tasks
        protected virtual void Dispose(bool disposing)
        {
            if (!_disposed)
            {
                return;
            }
            if (disposing)
            {
                _stream.Dispose();
            }

            // TODO: free unmanaged resources (unmanaged objects) and override finalizer
            // TODO: set large fields to null
            _large    = null;
            _disposed = true;
        }
コード例 #33
0
        /// <summary>
        /// modify a record
        /// </summary>
        public void modifyz_voluntarios(z_voluntarios myz_voluntarios, string foto)
        {
            CnxBase myBase = new CnxBase();
            string  reqSQL;

            reqSQL = "UPDATE z_voluntarios SET id_voluntario=" + myz_voluntarios.id_voluntario + ",id_compania=" + myz_voluntarios.id_compania + ",nombres='" + myz_voluntarios.nombres + "',apellidos='" + myz_voluntarios.apellidos + "',rut='" + myz_voluntarios.rut + "',direccion='" + myz_voluntarios.direccion + "',fecha_nacimiento='" + myz_voluntarios.fecha_nacimiento + "',ingreso='" + myz_voluntarios.ingreso + "',num_llamado=" + myz_voluntarios.num_llamado + ",comuna='" + myz_voluntarios.comuna + "',telefono='" + myz_voluntarios.telefono + "',celular='" + myz_voluntarios.celular + "' WHERE (id_voluntario=" + myz_voluntarios.id_voluntario + ")";


            try
            {
                NpgsqlConnection myConn = myBase.OpenConnection(myBase.cnxString);

                if (foto != null)
                {
                    NpgsqlTransaction  t   = myConn.BeginTransaction();
                    LargeObjectManager lbm = new LargeObjectManager(myConn);

                    int         noid = lbm.Create(LargeObjectManager.READWRITE);
                    LargeObject lo   = lbm.Open(noid, LargeObjectManager.READWRITE);

                    // eliminar antiguo
                    NpgsqlCommand comm = new NpgsqlCommand("select foto from z_voluntarios where id_voluntario=" + myz_voluntarios.id_voluntario, myConn);
                    comm.ExecuteScalar();

                    //lbm.Unlink(oid);

                    FileStream fs = File.OpenRead(foto);

                    byte[] buf = new byte[fs.Length];
                    fs.Read(buf, 0, (int)fs.Length);

                    lo.Write(buf);
                    lo.Close();
                    t.Commit();

                    reqSQL = "UPDATE z_voluntarios SET id_voluntario=" + myz_voluntarios.id_voluntario + ",id_compania=" + myz_voluntarios.id_compania + ",nombres='" + myz_voluntarios.nombres + "',apellidos='" + myz_voluntarios.apellidos + "',rut='" + myz_voluntarios.rut + "',direccion='" + myz_voluntarios.direccion + "',fecha_nacimiento='" + myz_voluntarios.fecha_nacimiento + "',ingreso='" + myz_voluntarios.ingreso + "',num_llamado=" + myz_voluntarios.num_llamado + ",comuna='" + myz_voluntarios.comuna + "',telefono='" + myz_voluntarios.telefono + "',celular='" + myz_voluntarios.celular + "', foto=" + noid + " WHERE (id_voluntario=" + myz_voluntarios.id_voluntario + ")";
                }

                NpgsqlCommand myCommand = new NpgsqlCommand(reqSQL, myConn);
                myCommand.ExecuteNonQuery();
                myBase.CloseConnection(myConn);
            }
            catch (Exception myErr)
            {
                throw (new Exception(myErr.ToString() + reqSQL));
            }
        }
コード例 #34
0
ファイル: suppressfinalize.cs プロジェクト: CheneyWu/coreclr
    public bool RunTests() {

        LargeObject lo;
        try {
            lo = new LargeObject(size, true);
            GC.SuppressFinalize(lo);
        } catch (OutOfMemoryException) {
            Console.WriteLine("Large Memory Machine required");
            return false;
        } catch (Exception e) {
            Console.WriteLine("Unexpected Exception:");
            Console.WriteLine(e);
            return false;
        }
        lo = null;
        GC.Collect();
        GC.WaitForPendingFinalizers();
        GC.Collect();

        return (LargeObject.FinalizedCount==0);
    }
コード例 #35
0
ファイル: keepalive.cs プロジェクト: geoffkizer/coreclr
    public bool RunTests() {

       try {
            LargeObject lo = new LargeObject(size);

            GC.Collect();
            GC.WaitForPendingFinalizers();
            GC.Collect();

            if (lo == null)
                return false;
            GC.KeepAlive(lo);

        } catch (OutOfMemoryException) {
            Console.WriteLine("Large Memory Machine required");
            return false;
        } catch (Exception e) {
            Console.WriteLine("Unexpected Exception:");
            Console.WriteLine(e);
            return false;
        }

        return true;
    }
コード例 #36
0
 public void DestroyLargeObject() {
     lo = null;
 }
コード例 #37
0
 public void CreateLargeObject() {
     lo = new LargeObject(size, true);
     GC.ReRegisterForFinalize(lo);
 }
コード例 #38
0
ファイル: collect.cs プロジェクト: CheneyWu/coreclr
 public void CreateLargeObject() {
     lo = new LargeObject(size, true);
 }
コード例 #39
0
ファイル: ObjectStore.cs プロジェクト: prepare/deveeldb
        private void CompleteObject(LargeObject obj)
        {
            // Get the blob reference id (reference to the fixed record list).
            long refId = obj.Id.Id;

            lock (fixedList) {
                // Update the record in the fixed list.
                IArea block = fixedList.GetRecord(refId);

                // Record the position
                int recordPos = block.Position;
                // Read the information in the fixed record
                int status = block.ReadInt4();
                // Assert that the status is open
                if (status != 0)
                    throw new IOException("Assertion failed: record is not open.");

                int refCount = block.ReadInt4();
                long size = block.ReadInt8();
                long currentSize = block.ReadInt8();
                long pageCount = block.ReadInt8();

                try {
                    store.LockForWrite();

                    block.Position = recordPos;
                    block.WriteInt4(1);				// Status
                    block.WriteInt4(0);				// Reference Count
                    block.WriteInt8(obj.CurrentSize);	// Final Size
                    block.WriteInt8(obj.CurrentSize);
                    block.WriteInt8(pageCount);		// Page Count
                    block.Flush();
                } finally {
                    store.UnlockForWrite();
                }
            }

            // Now the object has been finalized so change the state of the object
            obj.MarkComplete();
        }
コード例 #40
0
#pragma warning restore 0414

    public LargeException(uint size) {
        lo = new LargeObject(size);
    }