Bug into RestoreProgressEventArgs class

Discussion of open issues, suggestions and bugs regarding ADO.NET provider for PostgreSQL
Post Reply
Feneck91
Posts: 46
Joined: Mon 12 Aug 2013 13:52

Bug into RestoreProgressEventArgs class

Post by Feneck91 » Wed 22 Nov 2017 18:01

The RestoreProgressEventArgs class used when restoring a database has a Offset field in "int" type.
But, when the file that store the database is large, this field become negative (and I think goes back to 0 when too big).
A file size is in 'long' type (new FileInfo("c:\thefilepath").Length), my files are "14 328 263 466" bytes size !

I think, you should be use an long type for this field.

Best regards.

I post here a workaround for users : Ok,some comments are in french but this code is simple to understand...

Code: Select all

// Used to patch offset when computing % of internal database restauration
#define PATCH_ERROR_OFFSET_INT

        /// <summary>
        /// Using a BackgroundWorker for database restauration.
        /// </summary>
        private class InternalContext
        {
            /// <summary>
            /// Le BackgroundWorker quand exécuté en multi-thread.
            /// </summary>
            internal BackgroundWorker   BackgroudWorker             { get; set; }

#if PATCH_ERROR_OFFSET_INT
            /// <summary>
            /// Dernière valeur de l'offset, permet de gérer quand repasse supérieur à -int.MAX
            /// </summary>
            internal long               LastLongOffset              { get; set; } = 0;

            /// <summary>
            /// Dernière valeur de l'offset complet.
            /// </summary>
            internal long               CurrentLongOffset           { get; set; } = 0;
#endif

            /// <summary>
            /// Taille du fichier à importer.
            /// </summary>
            internal long               FileSize                    { get; set; } = 0;

            /// <summary>
            /// Dernier cacul de % de traitement.
            /// </summary>
            internal int                LastComputedPercent         { get; set; } = 0;

            /// <summary>
            /// Début du % de traitement (pas nécessairement de 0 à 100).
            /// </summary>
            internal int                StartIndexPercent           { get; set; } = 0;

            /// <summary>
            /// Fin du % de traitement (pas nécessairement de 0 à 100).
            /// </summary>
            internal int                StopIndexPercent            { get; set; } = 0;

            /// <summary>
            /// Différence entre stop et end percent, évite des calculs à chaque calcul de % de traitement.
            /// </summary>
            internal long               RangePercent                { get; set; } = 0;

            /// <summary>
            /// Ligne courante en cours d'exécution.
            /// </summary>
            internal int                CurrentLineExecute  { get; set; } = -1;

            /// <summary>
            /// Commande courante en cours d'exécution.
            /// </summary>
            internal String             CurrentCommandExecute { get; set; }
        }


        /// <summary>
        /// Contexte privé pour la restauration de la base de données.
        /// </summary>
        private InternalContext PrivateContext      { get; set; }


        /// <summary>
        /// Progression de la restauration.
        /// </summary>
        /// <param name="_oSender"></param>
        /// <param name="_evtRetoreProgressArg"></param>
        private void OnProgress(object _oSender, RestoreProgressEventArgs _evtRetoreProgressArg)
        {
            if (PrivateContext != null)
            {
                if (PrivateContext.FileSize != 0)
                {
#if PATCH_ERROR_OFFSET_INT
                    long lOffset = _evtRetoreProgressArg.Offset > 0
                        ? (long) _evtRetoreProgressArg.Offset
                        : (2 * (long) int.MaxValue) + (long) _evtRetoreProgressArg.Offset;

                    if (lOffset < PrivateContext.LastLongOffset)
                    {   // Ne doit faire que grandir, si devient plus petit, c'est que l'on a dépassé le int MAX
                        PrivateContext.CurrentLongOffset += 2 * (long) int.MaxValue;
                    }
                    PrivateContext.LastLongOffset = lOffset;
                    lOffset += PrivateContext.CurrentLongOffset;

                    int iPercent = (int) ((PrivateContext.RangePercent * lOffset) / PrivateContext.FileSize);
#else
                    int iPercent = (int) (((PrivateContext.RangePercent * _evtRetoreProgressArg.Offset) / PrivateContext.FileSize));
#endif
                    if (iPercent != PrivateContext.LastComputedPercent)
                    {
                        PrivateContext.LastComputedPercent = iPercent;
                        PrivateContext.BackgroudWorker.ReportProgress(iPercent + PrivateContext.StartIndexPercent);
                    }
                }
                PrivateContext.CurrentLineExecute    = _evtRetoreProgressArg.LineNumber;
                PrivateContext.CurrentCommandExecute = _evtRetoreProgressArg.Text;
            }
        }

Pinturiccio
Devart Team
Posts: 2192
Joined: Wed 02 Nov 2011 09:44

Re: Bug into RestoreProgressEventArgs class

Post by Pinturiccio » Wed 29 Nov 2017 15:33

We will investigate the possibility to change type of the Offset property from int to long and post here about the results as soon as possible.

Feneck91
Posts: 46
Joined: Mon 12 Aug 2013 13:52

Re: Bug into RestoreProgressEventArgs class

Post by Feneck91 » Thu 14 Dec 2017 09:13

Great, thanks for all. This case comes only when save / restore big databases.

Pinturiccio
Devart Team
Posts: 2192
Joined: Wed 02 Nov 2011 09:44

Re: Bug into RestoreProgressEventArgs class

Post by Pinturiccio » Fri 12 Jan 2018 10:08

We have changed the Offset and Length properties of the RestoreProgressEventArgs class from Int32 to Int64.

New build of dotConnect for PostgreSQL 7.10.1061 is available for download now!
It can be downloaded from http://www.devart.com/dotconnect/postgr ... nload.html (trial version) or from Customer Portal (for users with valid subscription only).
For more information, please refer to viewtopic.php?t=36447

Post Reply