示例#1
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() );
            }
        }
示例#2
0
        private void upgradeFolderComplete( vdFtpFolder folder )
        {
            if ( _downloadStatus==DownloadStatus.InProgress )
                return;
            var strBestVersion = AppSpecifics.Version;
            vdFtpItem itmFound = null;

            foreach ( var itm in folder.Items )
                if ( itm.Name.StartsWith( "plata_" ) )
                {
                    var strThatVersion = string.Format( "{0}-{1}-{2}",
                        itm.Name.Substring( 6, 4 ),
                        itm.Name.Substring( 10, 2 ),
                        itm.Name.Substring( 12, 2 ) );
                    if ( strThatVersion.CompareTo( strBestVersion ) > 0 )
                    {
                        strBestVersion = strThatVersion;
                        itmFound = itm;
                    }
                }
            if ( itmFound != null )
            {
                var strQ = string.Format( "Det finns en ny version av Plåta att hämta. Vill du göra det nu?" );
                if ( Global.askMsgBox( this, strQ, false ) != DialogResult.Yes )
                    return;
                if ( download( "_uppdateringar", itmFound, 120 ) )
                    if ( _upgrader!=null )
                        if ( _upgrader.run() )
                        {
                            FMain.theOneForm.endApp( false );
                            return;
                        }
                setMessage( string.Format( "Överföringsfel ({0})", _upgrader!=null ) );
            }
        }
示例#3
0
 private void photographerFolderComplete( vdFtpFolder folder )
 {
     ug.beginCleanFillup();
     foreach ( var itm in folder.Items )
     {
         var astr = System.Text.RegularExpressions.Regex.Split( itm.Name, @"^order_(\d{5,6})_(.+)\.zip$" );
         if ( astr.Length != 4 )
             continue;
         if ( !_fImport && _existingOrders.Contains( int.Parse( astr[1] ) ) )
             continue;
         var row = ug.addRow();
         row.Cells[0].Value = astr[2];
         row.Cells[1].Value = astr[1];
         row.Cells[2].Value = itm.Date;
         row.Tag = itm;
         row.EndEdit();
     }
     ug.endFillup();
     setMessage( null );
 }
示例#4
0
        private void standbylistFolderComplete( vdFtpFolder folder )
        {
            vdFtpWorkUnit w = null;
            vdFtpFolder f = null;

            var strTemp = Global.GetTempPath();

            foreach ( var itm in folder.Items )
            {
                if ( !itm.Name.EndsWith( ".pdf" ) )
                    continue;
                if ( File.Exists( Path.Combine( strTemp, itm.Name ) ) )
                    continue;

                if ( w == null )
                {
                    w = _sync.getDownloadFiles();
                    f = w.addFolder( folder.Name );
                }
                f.AddItem( itm );
            }
            if ( w!=null )
                w.run();
        }
示例#5
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;
            }
        }