private void go( vdFtpWorkUnit w, vdPlainGrid ug ) { var rows = new List<DataRow>(); foreach ( DataRow row in ug.G.GetSortedDataRows( true ) ) rows.Add( row ); foreach ( var row in rows ) if ( (bool)row.Cells[0].Value ) { go( w, row.Tag as string ); ug.G.DataRows.Remove( row ); } }
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() ); } }
private InProgress go( vdFtpWorkUnit w, string strPath ) { var skola = new PlataDM.Skola( null, 0 ); skola.Open( strPath ); var f = w.addFolder( skola.OrderNr ); var excludeThese = findFilesToExclude( skola ); foreach ( var strFullFN in Directory.GetFiles( skola.HomePath ) ) { var plainFileName = Path.GetFileName( strFullFN ).ToLower(); switch ( plainFileName ) { case "!fotoorder.emf": break; case "!order.plata": if ( skola.Verifierad ) goto default; f.AddLocalItem( strFullFN, string.Format( "!order_{0:yyyyMMddHHmmss}.plata", Global.Now ) ); break; default: if ( !excludeThese.Contains( plainFileName ) ) f.AddLocalItem( strFullFN, plainFileName ); break; } } var strZZLast = Path.Combine( skola.HomePath, "zzlast" ); Util.safeKillFile( strZZLast ); if ( skola.Verifierad ) f.AddLocalItem( strZZLast, "zzlast" ).FileType = vdFtpFileType.EndFileForOneFolder; var row = ugProgress.addRow(); row.Cells[0].Value = skola.OrderNr; row.Cells[1].Value = skola.Namn; row.Cells[2].Value = skola.Ort; row.EndEdit(); var ip = new InProgress(); f.Tag = ip; ip.Path = strPath; ip.Folder = f; ip.Row = row; ip.Work = w; ip.IsBackup = !skola.Verifierad; row.Tag = ip; _dicInProgress.Add( strPath, ip ); return ip; }
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; } }