Ejemplo n.º 1
0
        private bool download(
			string strFolderName,
			vdFtpItem item, 
			int nTimeoutSec )
        {
            _downloadStatus = DownloadStatus.InProgress;
            var w = _sync.getDownloadFiles();
            w.addFolder( strFolderName ).AddItem( item );
            w.run();
            vdUsr.vdOneShotTimer.start( 1000*nTimeoutSec, new EventHandler( timeout ), w );

            setMessage( "Hämtar fil från Viron...\r\n" );
            while ( _downloadStatus == DownloadStatus.InProgress )
                Application.DoEvents();
            return _downloadStatus == DownloadStatus.Complete;
        }
Ejemplo n.º 2
0
        private void callback(
			vdFtpWorkUnit unit,
			vdFtpTPStatus status,
			vdFtpFolder folder,
			vdFtpItem item,
			object data )
        {
            if ( InvokeRequired )
            {
                Invoke( _tp, unit, status, folder, item, data );
                return;
            }

            var ip = folder != null
                ? (InProgress)folder.Tag
                : null;

            try
            {
                switch ( status )
                {
                    case vdFtpTPStatus.Sync_FolderInfo:
                        {
                            var row = ip.Row;
                            row.Cells[3].Value = (int)(folder.TotalBytes / (1024 * 1024));
                            row.Cells[4].Value = 100.0 * folder.AlreadySyncedBytes / folder.TotalBytes;
                        }
                        break;

                    case vdFtpTPStatus.Sync_BeginFolder:
                        {
                            ip.TimeEstimator = new TimeEstimator( Global.Preferences.FTPSpeed * 1024 );
                            ip.TimeEstimator.Start( folder.TotalBytes - folder.AlreadySyncedBytes );
                            msg( "Påbörjar order {0}", folder.Name );
                            ip.Row.Font = new Font( ip.Row.Font.FontFamily, ip.Row.Font.Size + 1, FontStyle.Bold );
                            ip.Row.Cells[5].Value = Global.Now;
                        }
                        break;

                    case vdFtpTPStatus.Sync_BeginItem:
                        //msg( "Begin \"{0}\", {1} bytes", item.Name, item.Size );
                        break;

                    case vdFtpTPStatus.Sync_Progress:
                        ip.TimeEstimator.MakeProgress((int) data);
                            var row2 = (folder.Tag as InProgress).Row;
                            row2.BeginEdit();
                            row2.Cells[4].Value = 100.0 * (folder.TransferredBytes + folder.AlreadySyncedBytes) / folder.TotalBytes;
                        row2.Cells[6].Value = ip.TimeEstimator.EstimatedCompletionTime;
                            row2.EndEdit();
                        break;

                    case vdFtpTPStatus.Sync_VerifiedFolder:
                        {
                            msg( "Order {0} klar, kl {1:HH:mm}", folder.Name, Global.Now );
                            doneWithInProgress( ip, true );
                            activated();
                        }
                        break;

                    case vdFtpTPStatus.Sync_FolderVerificationFailed:
                        {
                            msg( "Order {0} misslyckades ({1}), försöker igen...", folder.Name, ip.Retries );
                            doneWithInProgress( ip, false );
                            if ( ip.Retries < 20 )
                            {
                                var w = _sync.getSync( true );
                                go( w, ip.Path ).Retries = ip.Retries + 1;
                                w.run();
                            }
                        }
                        break;

                    case vdFtpTPStatus.Error:
                    case vdFtpTPStatus.Sync_NotComplete:
                        {
                            if ( data is string )
                                msg( (string)data );
                            var w = _sync.getSync( true );
                            var stopThese = new List<InProgress>();
                            foreach ( var ip2 in _dicInProgress.Values )
                                if ( unit == ip2.Work )
                                    stopThese.Add( ip2 );
                            foreach ( var ip2 in stopThese )
                            {
                                doneWithInProgress( ip2, false );
                                if ( ip2.Retries<20 )
                                    go( w, ip2.Path ).Retries = ip2.Retries + 1;
                            }
                            w.run();
                        }
                        break;

                    case vdFtpTPStatus.Sync_Complete:
                        activated();
                        timer1.Stop();
                        break;

                }
            }
            catch ( Exception ex )
            {
                msg( ex.ToString() );
            }
        }
Ejemplo n.º 3
0
        private void callback( 
			vdFtpWorkUnit unit,
			vdFtpTPStatus status, 
			vdFtpFolder folder, 
			vdFtpItem item, 
			object data )
        {
            if ( this.InvokeRequired )
            {
                this.Invoke( _tp, unit, status, folder, item, data );
                return;
            }

            try
            {
                switch ( status )
                {
                    case vdFtpTPStatus.GetFolder_Complete:
                        if ( _strFtgFolder.CompareTo( folder.Name ) == 0 )
                            photographerFolderComplete( folder );
                        else if ( "_uppdateringar".CompareTo( folder.Name ) == 0 )
                            upgradeFolderComplete( folder );
                        else
                            standbylistFolderComplete( folder );
                        break;

                    case vdFtpTPStatus.DownloadFile_Complete:
                        if ( item.Name.StartsWith( "order_" ) )
                        {
                            _coof = new ContentOfOrderFile();
                            _coof.loadFromZipFile( data as MemoryStream );
                            _downloadStatus = _coof.getFileWithType( ContentOfOrderFile.FileType.OrderXml ) != null ?
                                DownloadStatus.Complete : DownloadStatus.Failed;
                        }
                        else if ( item.Name.StartsWith( "plata_" ) )
                        {
                            _upgrader = new Upgrader( data as MemoryStream );
                            _downloadStatus = DownloadStatus.Complete;
                        }
                        else if ( item.Name.EndsWith( ".pdf" ) )
                        {
                            string s =Path.Combine( Global.GetTempPath(), item.Name );
                            using ( Stream stream = new FileStream( s, FileMode.Create ) )
                                (data as MemoryStream).WriteTo( stream );
                        }
                        break;

                    case vdFtpTPStatus.DownloadFile_Begin:
                    case vdFtpTPStatus.DownloadFile_Progress:
                        txtProgress.Text = string.Format( "Hämtar... {0}%", 100*(int)data/item.Size );
                        break;

                    case vdFtpTPStatus.Error:
                        setMessage( data.ToString() );
                        _downloadStatus = DownloadStatus.Failed;
                        break;

                }
            }
            catch ( Exception ex )
            {
                setMessage( ex.ToString() );
                _downloadStatus = DownloadStatus.Failed;
            }
        }