コード例 #1
0
        // 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();
                }
            }
        }