// creates global config and uploads it (async)
        private void UploadGlobalConfig(DelegateTransfer callback)
        {
            // latest update = uploaded version
            versions.LatestUpdate = ulVersion;

            // if uploaded version is a full version
            if (ulFullVersion)
            {
                // latest version = uploaded version
                versions.LatestFullVersion = ulVersion;
            }

            // add uploaded version to version list
            versions.Add(ulVersion, ulFullVersion);

            // save global config to local temp folder
            versions.Save(localPath + globalConfig);

            var file = new TransferFile(globalConfig);

            // try to upload new global config
            fileTransfer.UploadFileAsync(file, false, remotePath, localPath,
                                         delegate(FileTransferResult result)
            {
                callback(result == FileTransferResult.Success);
            });
        }
        // locks the server (async)
        private void LockServer(DelegateTransfer callback)
        {
            try
            {
                // create local lockfile
                if (!File.Exists(localPath + lockFile))
                {
                    File.Create(localPath + lockFile);
                }
            }
            catch (Exception e)
            {
                ErrorLog.Add(this, e.Message);
                callback(false);
                return;
            }

            // try to upload the lockfile
            TransferFile file = new TransferFile(lockFile);

            fileTransfer.UploadFileAsync(file, false, remotePath, localPath,
                                         delegate(FileTransferResult result)
            {
                serverLock = (result == FileTransferResult.Success);
                callback(serverLock);
            });
        }
        // downloads configs of latest updates and latest full version (async)
        private void DownloadVersionConfigs(DelegateTransfer callback)
        {
            List <string> updates     = versions.GetLatestUpdates();
            string        fullVersion = versions.LatestFullVersion;

            DownloadVersionConfigs(callback, updates, fullVersion);
        }
        // creates version config and uploads it (async)
        private void UploadVersionConfigs(DelegateTransfer callback)
        {
            var files = new List <TransferFile>();

            // check if version should be a full version
            if (ulFullVersion)
            {
                // create a new full version config and save it to temp folder
                var xmlFullVersion = new XmlFullVersion(ulFiles);
                xmlFullVersion.Save(localPath + fullVersionConfig);
                files.Add(new TransferFile(fullVersionConfig));
            }

            // create a new update config and save it to temp folder
            var xmlUpdate = new XmlUpdate(ulNewFiles, ulDeletedFiles);

            xmlUpdate.Save(localPath + updateConfig);
            files.Add(new TransferFile(updateConfig));

            Uri address = new Uri(remotePath + ulVersion + "/");

            // try to upload configs async
            fileTransfer.UploadFilesAsync(files, false, address, localPath,
                                          delegate(FileTransferResult result)
            {
                callback(result == FileTransferResult.Success);
            });
        }
 // downloads files (async)
 private void DownloadFiles(DelegateTransfer callback)
 {
     // try to download files async
     fileTransfer.DownloadFilesAsync(dlFiles, true, remotePath, dlLocalPath,
                                     delegate(FileTransferResult result)
     {
         callback(result == FileTransferResult.Success);
     });
 }
 // creates a remote directory for the new version (async)
 private void CreateDirectory(DelegateTransfer callback)
 {
     // try to create remote directory async
     fileTransfer.CreateDirectoryAsync(ulVersion, remotePath,
                                       delegate(FileTransferResult result)
     {
         callback(result == FileTransferResult.Success);
     });
 }
        // uploads files (async)
        private void UploadFiles(DelegateTransfer callback)
        {
            Uri address = new Uri(remotePath + ulVersion + "/");

            // try to upload files async
            fileTransfer.UploadFilesAsync(ulFiles, true, address, ulLocalPath,
                                          delegate(FileTransferResult result)
            {
                callback(result == FileTransferResult.Success);
            });
        }
Example #8
0
        public bool RemoveDelegateTransfer(int Id)
        {
            DelegateTransfer delegatetranfer = GetDelegateTransferById(Id);

            if (delegatetranfer == null)
            {
                return(false);
            }
            _context.Remove(delegatetranfer);
            _context.SaveChanges();
            return(true);
        }
        // downloads global config file and checks new version (async)
        private void DownloadGlobalConfig(DelegateTransfer callback)
        {
            TransferFile file = new TransferFile(globalConfig);

            // try to download global config file
            fileTransfer.DownloadFileAsync(file, false, remotePath, localPath,
                                           delegate(FileTransferResult result)
            {
                if (result == FileTransferResult.Success)
                {
                    versions.Load(localPath + globalConfig);
                }

                // check new version number
                callback(versions.CheckNewVersionNr(ulVersion));
            });
        }
        // downloads version configs of wanted versions (async)
        private void DownloadVersionConfigs(DelegateTransfer callback, List <string> updates, string fullVersion)
        {
            var files = new List <TransferFile>();

            // create list with paths of version configs
            foreach (string update in updates)
            {
                files.Add(new TransferFile(update + "/" + updateConfig));
            }
            files.Add(new TransferFile(fullVersion + "/" + fullVersionConfig));

            // try to download the version configs async
            fileTransfer.DownloadFilesAsync(files, false, remotePath, localPath,
                                            delegate(FileTransferResult result)
            {
                callback(result == FileTransferResult.Success);
            });
        }
        // checks if server is locked (async)
        private void CheckLock(DelegateTransfer callback)
        {
            TransferFile file = new TransferFile(lockFile);

            // try to download lock file
            fileTransfer.DownloadFileAsync(file, false, remotePath, localPath,
                                           delegate(FileTransferResult result)
            {
                if (!exit)
                {
                    callback(result == FileTransferResult.Failure);
                }
                else
                {
                    FireExit();
                }
            });
        }
 // builds the list of files to transfer (async)
 private void BuildTransferList(DelegateTransfer callback, BuildTransferListAsync caller)
 {
     try
     {
         // calls wether BuildUploadList or BuildDownloadList async
         caller.BeginInvoke(
             delegate(IAsyncResult iar)
         {
             var c = (BuildTransferListAsync)iar.AsyncState;
             c.EndInvoke(iar);
             callback(true);
         }, caller);
     }
     catch (Exception e)
     {
         ErrorLog.Add(this, e.Message);
         callback(false);
     }
 }
 // creates a list of all local files (async)
 private void AnalyzeNewVersion(DelegateTransfer callback)
 {
     try
     {
         // call GetLocalFiles method async
         var caller = new GetLocalFilesAsync(GetLocalFiles);
         caller.BeginInvoke(ulLocalPath,
                            delegate(IAsyncResult iar)
         {
             var c        = (GetLocalFilesAsync)iar.AsyncState;
             ulLocalFiles = caller.EndInvoke(iar);
             callback(ulLocalFiles != null);
         }, caller);
     }
     catch (Exception e)
     {
         ErrorLog.Add(this, e.Message);
         callback(false);
     }
 }
Example #14
0
        public bool UpdateDelegateTransfer(int Id, DelegateTransfer delegateTransfer)
        {
            DelegateTransfer existdelegateTransfer = GetDelegateTransferById(Id);

            if (existdelegateTransfer == null)
            {
                return(false);
            }
            existdelegateTransfer.UserDelegateId  = delegateTransfer.UserDelegateId;
            existdelegateTransfer.Amount          = delegateTransfer.Amount;
            existdelegateTransfer.CurrencyId      = delegateTransfer.CurrencyId;
            existdelegateTransfer.Notes           = delegateTransfer.Notes;
            existdelegateTransfer.PaymentMethodId = delegateTransfer.PaymentMethodId;
            existdelegateTransfer.PurposeId       = delegateTransfer.PurposeId;
            existdelegateTransfer.TransferBankId  = delegateTransfer.TransferBankId;
            existdelegateTransfer.TransferDate    = delegateTransfer.TransferDate;
            _context.Update(existdelegateTransfer);
            _context.SaveChanges();

            return(true);
        }
Example #15
0
        public int AddDelegateTransfer(DelegateTransfer delegateTransfer)
        {
            // Add RecruitmentQaid First
            var qaidId = RecruitmentQaid(delegateTransfer);
            //snadReceipt.VAT = 0;
            var getCurrentFinancialPeriodrec = _context.FinancialPeriods.Where(x => x.FinancialPeriodStatusId == (int)EnumHelper.FinancPeriodStatus.CURRENT).SingleOrDefault();

            if (getCurrentFinancialPeriodrec != null)
            {
                delegateTransfer.FinancialPeriodId = getCurrentFinancialPeriodrec.Id;
            }
            delegateTransfer.QaidNo = qaidId;

            _context.DelegateTransfers.Add(delegateTransfer);
            _context.SaveChanges();

            var existfordelegate = _context.UserDelegates.SingleOrDefault(x => x.Id == delegateTransfer.UserDelegateId);

            existfordelegate.TransferAmount = existfordelegate.TransferAmount + delegateTransfer.Amount;
            _context.Update(existfordelegate);
            _context.SaveChanges();

            return(delegateTransfer.Id);
        }
        // downloads global config file and checks new version (async)
        private void DownloadGlobalConfig(DelegateTransfer callback)
        {
            TransferFile file = new TransferFile(globalConfig);

            // try to download global config file
            fileTransfer.DownloadFileAsync(file, false, remotePath, localPath,
                delegate(FileTransferResult result)
                {
                    if (result == FileTransferResult.Success)
                        versions.Load(localPath + globalConfig);

                    // check new version number
                    callback(versions.CheckNewVersionNr(ulVersion));
                });
        }
 // downloads files (async)
 private void DownloadFiles(DelegateTransfer callback)
 {
     // try to download files async
     fileTransfer.DownloadFilesAsync(dlFiles, true, remotePath, dlLocalPath,
         delegate(FileTransferResult result)
         {
             callback(result == FileTransferResult.Success);
         });
 }
        // main download method
        private void Download(bool continueDownload)
        {
            // this method is called after every step of the download progress
            var callback = new DelegateTransfer(Download);

            // check if last step has been finished successfully
            if (continueDownload)
            {
                switch (dlStatus)
                {
                    case DownloadStatus.Start:
                        // step 1: download version configs
                        FireStatus(Strings.DownloadingConfigurationFiles);
                        dlStatus = DownloadStatus.DownloadVersionConfigs;
                        DownloadVersionConfigs(callback, dlUpdates, dlFullVersion);
                        break;
                    case DownloadStatus.DownloadVersionConfigs:
                        // step 2: build list of files to download
                        FireStatus(Strings.BuildingDownloadList);
                        dlStatus = DownloadStatus.BuildDownloadList;
                        BuildDownloadListAsync(callback);
                        break;
                    case DownloadStatus.BuildDownloadList:
                        // step 3: download remote files
                        FireStatus(Strings.DownloadingFiles);
                        dlStatus = DownloadStatus.DownloadFiles;
                        DownloadFiles(callback);
                        break;
                    case DownloadStatus.DownloadFiles:
                        // step 4: inform the gui
                        FireInformation(Strings.DownloadCompleted);
                        fileTransfer.ClearProgress();
                        ResetInterface();
                        break;
                }
            }
            // a step hasn't been finished successfully: download aborted
            else
            {
                // fire an event to inform the GUI about the error
                switch (dlStatus)
                {
                    case DownloadStatus.DownloadVersionConfigs:
                        FireWarning(Strings.UnableToDownloadConfigurationFiles);
                        break;
                    case DownloadStatus.BuildDownloadList:
                        FireWarning(Strings.UnableToBuildDownloadList);
                        break;
                    case DownloadStatus.DownloadFiles:
                        FireWarning(Strings.DownloadFailed);
                        fileTransfer.ClearProgress();
                        break;
                }

                if (exit)
                    // if program should quit, fire exit event
                    FireExit();
                else
                    // othewise restart (test settings & download global config)
                    Start();
            }
        }
 // creates a remote directory for the new version (async)
 private void CreateDirectory(DelegateTransfer callback)
 {
     // try to create remote directory async
     fileTransfer.CreateDirectoryAsync(ulVersion, remotePath,
         delegate(FileTransferResult result)
         {
             callback(result == FileTransferResult.Success);
         });
 }
        // checks if server is locked (async)
        private void CheckLock(DelegateTransfer callback)
        {
            TransferFile file = new TransferFile(lockFile);

            // try to download lock file
            fileTransfer.DownloadFileAsync(file, false, remotePath, localPath,
                delegate(FileTransferResult result)
                {
                    if (!exit)
                        callback(result == FileTransferResult.Failure);
                    else
                        FireExit();
                });
        }
 // builds the list of files do upload (async)
 private void BuildUploadListAsync(DelegateTransfer callback)
 {
     var caller = new BuildTransferListAsync(BuildUploadList);
     BuildTransferList(callback, caller);
 }
 // builds the list of files to transfer (async)
 private void BuildTransferList(DelegateTransfer callback, BuildTransferListAsync caller)
 {
     try
     {
         // calls wether BuildUploadList or BuildDownloadList async
         caller.BeginInvoke(
             delegate(IAsyncResult iar)
             {
                 var c = (BuildTransferListAsync)iar.AsyncState;
                 c.EndInvoke(iar);
                 callback(true);
             }, caller);
     }
     catch (Exception e)
     {
         ErrorLog.Add(this, e.Message);
         callback(false);
     }
 }
 // creates a list of all local files (async)
 private void AnalyzeNewVersion(DelegateTransfer callback)
 {
     try
     {
         // call GetLocalFiles method async
         var caller = new GetLocalFilesAsync(GetLocalFiles);
         caller.BeginInvoke(ulLocalPath,
             delegate(IAsyncResult iar)
             {
                 var c = (GetLocalFilesAsync)iar.AsyncState;
                 ulLocalFiles = caller.EndInvoke(iar);
                 callback(ulLocalFiles != null);
             }, caller);
     }
     catch (Exception e)
     {
         ErrorLog.Add(this, e.Message);
         callback(false);
     }
 }
        // creates version config and uploads it (async)
        private void UploadVersionConfigs(DelegateTransfer callback)
        {
            var files = new List<TransferFile>();

            // check if version should be a full version
            if (ulFullVersion)
            {
                // create a new full version config and save it to temp folder
                var xmlFullVersion = new XmlFullVersion(ulFiles);
                xmlFullVersion.Save(localPath + fullVersionConfig);
                files.Add(new TransferFile(fullVersionConfig));
            }

            // create a new update config and save it to temp folder
            var xmlUpdate = new XmlUpdate(ulNewFiles, ulDeletedFiles);
            xmlUpdate.Save(localPath + updateConfig);
            files.Add(new TransferFile(updateConfig));

            Uri address = new Uri(remotePath + ulVersion + "/");

            // try to upload configs async
            fileTransfer.UploadFilesAsync(files, false, address, localPath,
                delegate(FileTransferResult result)
                {
                    callback(result == FileTransferResult.Success);
                });
        }
        // creates global config and uploads it (async)
        private void UploadGlobalConfig(DelegateTransfer callback)
        {
            // latest update = uploaded version
            versions.LatestUpdate = ulVersion;

            // if uploaded version is a full version
            if (ulFullVersion)
                // latest version = uploaded version
                versions.LatestFullVersion = ulVersion;

            // add uploaded version to version list
            versions.Add(ulVersion, ulFullVersion);

            // save global config to local temp folder
            versions.Save(localPath + globalConfig);

            var file = new TransferFile(globalConfig);

            // try to upload new global config
            fileTransfer.UploadFileAsync(file, false, remotePath, localPath,
                delegate(FileTransferResult result)
                {
                    callback(result == FileTransferResult.Success);
                });
        }
        // uploads files (async)
        private void UploadFiles(DelegateTransfer callback)
        {
            Uri address = new Uri(remotePath + ulVersion + "/");

            // try to upload files async
            fileTransfer.UploadFilesAsync(ulFiles, true, address, ulLocalPath,
                delegate(FileTransferResult result)
                {
                    callback(result == FileTransferResult.Success);
                });
        }
        // main download method
        private void Download(bool continueDownload)
        {
            // this method is called after every step of the download progress
            var callback = new DelegateTransfer(Download);

            // check if last step has been finished successfully
            if (continueDownload)
            {
                switch (dlStatus)
                {
                case DownloadStatus.Start:
                    // step 1: download version configs
                    FireStatus(Strings.DownloadingConfigurationFiles);
                    dlStatus = DownloadStatus.DownloadVersionConfigs;
                    DownloadVersionConfigs(callback, dlUpdates, dlFullVersion);
                    break;

                case DownloadStatus.DownloadVersionConfigs:
                    // step 2: build list of files to download
                    FireStatus(Strings.BuildingDownloadList);
                    dlStatus = DownloadStatus.BuildDownloadList;
                    BuildDownloadListAsync(callback);
                    break;

                case DownloadStatus.BuildDownloadList:
                    // step 3: download remote files
                    FireStatus(Strings.DownloadingFiles);
                    dlStatus = DownloadStatus.DownloadFiles;
                    DownloadFiles(callback);
                    break;

                case DownloadStatus.DownloadFiles:
                    // step 4: inform the gui
                    FireInformation(Strings.DownloadCompleted);
                    fileTransfer.ClearProgress();
                    ResetInterface();
                    break;
                }
            }
            // a step hasn't been finished successfully: download aborted
            else
            {
                // fire an event to inform the GUI about the error
                switch (dlStatus)
                {
                case DownloadStatus.DownloadVersionConfigs:
                    FireWarning(Strings.UnableToDownloadConfigurationFiles);
                    break;

                case DownloadStatus.BuildDownloadList:
                    FireWarning(Strings.UnableToBuildDownloadList);
                    break;

                case DownloadStatus.DownloadFiles:
                    FireWarning(Strings.DownloadFailed);
                    fileTransfer.ClearProgress();
                    break;
                }

                if (exit)
                {
                    // if program should quit, fire exit event
                    FireExit();
                }
                else
                {
                    // othewise restart (test settings & download global config)
                    Start();
                }
            }
        }
        // locks the server (async)
        private void LockServer(DelegateTransfer callback)
        {
            try
            {
                // create local lockfile
                if (!File.Exists(localPath + lockFile))
                    File.Create(localPath + lockFile);
            }
            catch (Exception e)
            {
                ErrorLog.Add(this, e.Message);
                callback(false);
                return;
            }

            // try to upload the lockfile
            TransferFile file = new TransferFile(lockFile);
            fileTransfer.UploadFileAsync(file, false, remotePath, localPath,
                delegate(FileTransferResult result)
                {
                    serverLock = (result == FileTransferResult.Success);
                    callback(serverLock);
                });
        }
        // downloads version configs of wanted versions (async)
        private void DownloadVersionConfigs(DelegateTransfer callback, List<string> updates, string fullVersion)
        {
            var files = new List<TransferFile>();

            // create list with paths of version configs
            foreach (string update in updates)
                files.Add(new TransferFile(update + "/" + updateConfig));
            files.Add(new TransferFile(fullVersion + "/" + fullVersionConfig));

            // try to download the version configs async
            fileTransfer.DownloadFilesAsync(files, false, remotePath, localPath,
                delegate(FileTransferResult result)
                {
                    callback(result == FileTransferResult.Success);
                });
        }
        // builds the list of files do upload (async)
        private void BuildUploadListAsync(DelegateTransfer callback)
        {
            var caller = new BuildTransferListAsync(BuildUploadList);

            BuildTransferList(callback, caller);
        }
 // downloads configs of latest updates and latest full version (async)
 private void DownloadVersionConfigs(DelegateTransfer callback)
 {
     List<string> updates = versions.GetLatestUpdates();
     string fullVersion = versions.LatestFullVersion;
     DownloadVersionConfigs(callback, updates, fullVersion);
 }
Example #32
0
        public int RecruitmentQaid(DelegateTransfer delegateTransfer)
        {
            #region AddQaid
            // Add Qaid First
            RecruitmentQaid qaid = new RecruitmentQaid
            {
                QaidDate = DateTime.UtcNow.ToString("dd/MM/yyyy", CultureInfo.InvariantCulture),
                StatusId = (int)EnumHelper.RecruitmentQaidStatus.Open
            };
            var getCurrentFinancialPeriod = _context.FinancialPeriods.Where(x => x.FinancialPeriodStatusId == (int)EnumHelper.FinancPeriodStatus.CURRENT).SingleOrDefault();
            if (getCurrentFinancialPeriod != null)
            {
                qaid.FinancialPeriodId = getCurrentFinancialPeriod.Id;
            }
            qaid.TypeId = (int)EnumHelper.RecruitmentQaidTypes.Transfer;
            _context.RecruitmentQaids.Add(qaid);
            _context.SaveChanges();
            #endregion

            #region DEBIT
            var delegate_user = _context.UserDelegates.Where(x => x.Id == delegateTransfer.UserDelegateId).SingleOrDefault();
            if (delegate_user != null)
            {
                // Add RecruitmentQaidDetails  DEBIT
                RecruitmentQaidDetail detailDebit = new RecruitmentQaidDetail
                {
                    QaidId        = qaid.Id,
                    Debit         = delegateTransfer.Amount,
                    TypeId        = (int)EnumHelper.RecruitmentQaidDetailType.Debit,
                    AccountTreeId = delegate_user.AccountTreeId,
                    Note          = "حوالة"
                };
                _context.RecruitmentQaidDetails.Add(detailDebit);
                _context.SaveChanges();

                // change In AccountTree For Debit Account ----------------------------------------
                AccountTree existAcc = _context.AccountTrees.Where(x => x.Id == detailDebit.AccountTreeId).SingleOrDefault();
                if (existAcc != null)
                {
                    existAcc.Debit = existAcc.Debit + detailDebit.Debit;
                    _context.Update(existAcc);
                    _context.SaveChanges();
                }
            }
            #endregion

            #region CREDIT
            var paymentMethod = _context.PaymentMethods.Where(x => x.Id == delegateTransfer.PaymentMethodId).SingleOrDefault();
            if (paymentMethod != null)
            {
                // Add RecruitmentQaidDetails
                RecruitmentQaidDetail detailCredit = new RecruitmentQaidDetail
                {
                    QaidId        = qaid.Id,
                    Credit        = delegateTransfer.Amount,
                    TypeId        = (int)EnumHelper.RecruitmentQaidDetailType.Credit,
                    AccountTreeId = paymentMethod.AccountTreeId,
                    Note          = "حوالة"
                };
                _context.RecruitmentQaidDetails.Add(detailCredit);
                _context.SaveChanges();
                // change In AccountTree For Credit Account ---------------------------------------------
                AccountTree existAccCredit = _context.AccountTrees.Where(x => x.Id == detailCredit.AccountTreeId).SingleOrDefault();
                if (existAccCredit != null)
                {
                    existAccCredit.Credit = existAccCredit.Credit + detailCredit.Credit;
                    _context.Update(existAccCredit);
                    _context.SaveChanges();
                }
            }
            #endregion

            return(qaid.Id);
        }
        // main upload method
        private void Upload(bool continueUpload)
        {
            // this method is called after every step of the upload progress
            var callback = new DelegateTransfer(Upload);

            // check if last step has been finished successfully
            if (continueUpload)
            {
                // check status of the upload progress
                switch (ulStatus)
                {
                    case UploadStatus.Start:
                        // step 1: check if server is locked
                        FireStatus(Strings.Connecting);
                        ulStatus = UploadStatus.CheckLock;
                        CheckLock(callback); break;
                    case UploadStatus.CheckLock:
                        // step 2: lock the server
                        ulStatus = UploadStatus.LockServer;
                        LockServer(callback); break;
                    case UploadStatus.LockServer:
                        // step 3: download global config file
                        ulStatus = UploadStatus.DownloadGlobalConfig;
                        DownloadGlobalConfig(callback); break;
                    case UploadStatus.DownloadGlobalConfig:
                        // step 4: analyse local version (create local file list)
                        FireStatus(Strings.AnalysingNewVersion);
                        ulStatus = UploadStatus.AnalyseNewVersion;
                        AnalyzeNewVersion(callback); break;
                    case UploadStatus.AnalyseNewVersion:
                        // step 5: create remote directory
                        ulStatus = UploadStatus.CreateDirectory;
                        CreateDirectory(callback);
                        break;
                    case UploadStatus.CreateDirectory:
                        // step 6: check if there are versions on the server
                        if (versions.LatestVersion != null)
                        {
                            // step 7a: download all version configs
                            FireStatus(Strings.DownloadingConfigurationFiles);
                            ulStatus = UploadStatus.DownloadVersionConfigs;
                            DownloadVersionConfigs(callback);
                        }
                        else
                        {
                            // step 7b.1: upload local files
                            FireStatus(Strings.UploadingFiles);
                            ulStatus = UploadStatus.UploadFiles;
                            ulFiles = ulLocalFiles.Values.ToList<TransferFile>();
                            UploadFiles(callback);
                        }
                        break;
                    case UploadStatus.DownloadVersionConfigs:
                        // step 7b.2: build lists of files to upload and files to delete
                        FireStatus(Strings.BuildingConfiguration);
                        ulStatus = UploadStatus.BuildUploadList;
                        BuildUploadListAsync(callback); break;
                    case UploadStatus.BuildUploadList:
                        // step 7b.3: upload local files
                        FireStatus(Strings.UploadingFiles);
                        ulStatus = UploadStatus.UploadFiles;
                        UploadFiles(callback); break;
                    case UploadStatus.UploadFiles:
                        // step 8: upload new version config
                        ulStatus = UploadStatus.UploadVersionConfigs;
                        UploadVersionConfigs(callback); break;
                    case UploadStatus.UploadVersionConfigs:
                        // step 9: upload global config
                        ulStatus = UploadStatus.UploadGlobalConfig;
                        UploadGlobalConfig(callback); break;
                    case UploadStatus.UploadGlobalConfig:
                        // step 10: unlock server and inform the gui
                        FireInformation(Strings.UploadCompleted);
                        fileTransfer.ClearProgress();
                        UnlockServer();
                        ResetInterface(); break;
                }
            }
            // a step hasn't been finished successfully: upload aborted
            else
            {
                // fire an event to inform the GUI about the error
                switch (ulStatus)
                {
                    case UploadStatus.CheckLock:
                        FireWarning(Strings.CurrentlyLocked);
                        break;
                    case UploadStatus.LockServer:
                        FireError(Strings.UnableToLock);
                        break;
                    case UploadStatus.DownloadGlobalConfig:
                        FireWarning(Strings.VersionTooLow);
                        break;
                    case UploadStatus.AnalyseNewVersion:
                        FireError(Strings.UnableToAnalyzeNewVersion);
                        break;
                    case UploadStatus.CreateDirectory:
                        FireError(Strings.UnableToCreateRemoteDirectory);
                        break;
                    case UploadStatus.DownloadVersionConfigs:
                        FireError(Strings.UnableToDownloadConfigurationFiles);
                        break;
                    case UploadStatus.BuildUploadList:
                        FireError(Strings.UnableToBuildConfiguration);
                        break;
                    case UploadStatus.UploadFiles:
                    case UploadStatus.UploadVersionConfigs:
                    case UploadStatus.UploadGlobalConfig:
                        FireWarning(Strings.UploadFailed);
                        fileTransfer.ClearProgress();
                        break;
                }

                // if remote directory was created, delete it
                switch (ulStatus)
                {
                    case UploadStatus.DownloadVersionConfigs:
                    case UploadStatus.BuildUploadList:
                    case UploadStatus.UploadFiles:
                    case UploadStatus.UploadVersionConfigs:
                    case UploadStatus.UploadGlobalConfig:
                        FireStatus(Strings.CleaningUp);
                        DeleteRemoteDirectory();
                        break;
                }

                // unlock the server
                UnlockServer();

                if (exit)
                    // if program should quit, fire exit event
                    FireExit();
                else
                    // otherwise restart (test settings & download global config)
                    Start();
            }
        }
        // main upload method
        private void Upload(bool continueUpload)
        {
            // this method is called after every step of the upload progress
            var callback = new DelegateTransfer(Upload);

            // check if last step has been finished successfully
            if (continueUpload)
            {
                // check status of the upload progress
                switch (ulStatus)
                {
                case UploadStatus.Start:
                    // step 1: check if server is locked
                    FireStatus(Strings.Connecting);
                    ulStatus = UploadStatus.CheckLock;
                    CheckLock(callback); break;

                case UploadStatus.CheckLock:
                    // step 2: lock the server
                    ulStatus = UploadStatus.LockServer;
                    LockServer(callback); break;

                case UploadStatus.LockServer:
                    // step 3: download global config file
                    ulStatus = UploadStatus.DownloadGlobalConfig;
                    DownloadGlobalConfig(callback); break;

                case UploadStatus.DownloadGlobalConfig:
                    // step 4: analyse local version (create local file list)
                    FireStatus(Strings.AnalysingNewVersion);
                    ulStatus = UploadStatus.AnalyseNewVersion;
                    AnalyzeNewVersion(callback); break;

                case UploadStatus.AnalyseNewVersion:
                    // step 5: create remote directory
                    ulStatus = UploadStatus.CreateDirectory;
                    CreateDirectory(callback);
                    break;

                case UploadStatus.CreateDirectory:
                    // step 6: check if there are versions on the server
                    if (versions.LatestVersion != null)
                    {
                        // step 7a: download all version configs
                        FireStatus(Strings.DownloadingConfigurationFiles);
                        ulStatus = UploadStatus.DownloadVersionConfigs;
                        DownloadVersionConfigs(callback);
                    }
                    else
                    {
                        // step 7b.1: upload local files
                        FireStatus(Strings.UploadingFiles);
                        ulStatus = UploadStatus.UploadFiles;
                        ulFiles  = ulLocalFiles.Values.ToList <TransferFile>();
                        UploadFiles(callback);
                    }
                    break;

                case UploadStatus.DownloadVersionConfigs:
                    // step 7b.2: build lists of files to upload and files to delete
                    FireStatus(Strings.BuildingConfiguration);
                    ulStatus = UploadStatus.BuildUploadList;
                    BuildUploadListAsync(callback); break;

                case UploadStatus.BuildUploadList:
                    // step 7b.3: upload local files
                    FireStatus(Strings.UploadingFiles);
                    ulStatus = UploadStatus.UploadFiles;
                    UploadFiles(callback); break;

                case UploadStatus.UploadFiles:
                    // step 8: upload new version config
                    ulStatus = UploadStatus.UploadVersionConfigs;
                    UploadVersionConfigs(callback); break;

                case UploadStatus.UploadVersionConfigs:
                    // step 9: upload global config
                    ulStatus = UploadStatus.UploadGlobalConfig;
                    UploadGlobalConfig(callback); break;

                case UploadStatus.UploadGlobalConfig:
                    // step 10: unlock server and inform the gui
                    FireInformation(Strings.UploadCompleted);
                    fileTransfer.ClearProgress();
                    UnlockServer();
                    ResetInterface(); break;
                }
            }
            // a step hasn't been finished successfully: upload aborted
            else
            {
                // fire an event to inform the GUI about the error
                switch (ulStatus)
                {
                case UploadStatus.CheckLock:
                    FireWarning(Strings.CurrentlyLocked);
                    break;

                case UploadStatus.LockServer:
                    FireError(Strings.UnableToLock);
                    break;

                case UploadStatus.DownloadGlobalConfig:
                    FireWarning(Strings.VersionTooLow);
                    break;

                case UploadStatus.AnalyseNewVersion:
                    FireError(Strings.UnableToAnalyzeNewVersion);
                    break;

                case UploadStatus.CreateDirectory:
                    FireError(Strings.UnableToCreateRemoteDirectory);
                    break;

                case UploadStatus.DownloadVersionConfigs:
                    FireError(Strings.UnableToDownloadConfigurationFiles);
                    break;

                case UploadStatus.BuildUploadList:
                    FireError(Strings.UnableToBuildConfiguration);
                    break;

                case UploadStatus.UploadFiles:
                case UploadStatus.UploadVersionConfigs:
                case UploadStatus.UploadGlobalConfig:
                    FireWarning(Strings.UploadFailed);
                    fileTransfer.ClearProgress();
                    break;
                }

                // if remote directory was created, delete it
                switch (ulStatus)
                {
                case UploadStatus.DownloadVersionConfigs:
                case UploadStatus.BuildUploadList:
                case UploadStatus.UploadFiles:
                case UploadStatus.UploadVersionConfigs:
                case UploadStatus.UploadGlobalConfig:
                    FireStatus(Strings.CleaningUp);
                    DeleteRemoteDirectory();
                    break;
                }

                // unlock the server
                UnlockServer();

                if (exit)
                {
                    // if program should quit, fire exit event
                    FireExit();
                }
                else
                {
                    // otherwise restart (test settings & download global config)
                    Start();
                }
            }
        }