internal static string GetProgressString( CreateWorkspaceFromCollab.Progress status, BuildProgressSpeedAndRemainingTime.ProgressData progressData, DateTime now, double smoothingFactor, string updateProgressCalculatingMessage, string updateProgressSingularMessage, string updateProgressPluralMessage, string remainingMessage) { if (status.CurrentStatus == CreateWorkspaceFromCollab.Progress.Status.Starting) { return(updateProgressCalculatingMessage); } progressData.StartTimerIfNotStarted(now); string updatedSize; string totalSize; GetFormattedSizes.ForTransfer( status.ProcessedSize, status.TotalSize, out updatedSize, out totalSize); string details = string.Format( status.TotalFiles == 1 ? updateProgressSingularMessage : updateProgressPluralMessage, updatedSize, totalSize, status.ProcessedFiles, status.TotalFiles, BuildProgressSpeedAndRemainingTime.ForTransfer( progressData, now, status.TotalSize, status.ProcessedSize, smoothingFactor, remainingMessage)); return(details); }
static void UpdateProgress(string wkPath, CreateWorkspaceFromCollab.Progress progress, ProgressControlsForMigration progressControls, BuildProgressSpeedAndRemainingTime.ProgressData progressData) { string header = MigrationProgressRender.FixNotificationPath( wkPath, progress.CurrentFile); string message = MigrationProgressRender.GetProgressString( progress, progressData, DateTime.Now, 0.05, "Calculating...", "Converted {0} of {1}bytes ({2} of 1 file){4}", "Converted {0} of {1}bytes ({2} of {3} files {4})", "remaining"); float percent = GetProgressBarPercent.ForTransfer( progress.ProcessedSize, progress.TotalSize) / 100f; progressControls.ShowProgress(header, message, percent); }
void LaunchMigration( string unityAccessToken, string projectPath, string organizationName, RepId repId, long changesetId, long branchId, Action afterWorkspaceMigratedAction, ProgressControlsForMigration progressControls) { string serverName = string.Format( "{0}@cloud", organizationName); TokenExchangeResponse tokenExchangeResponse = null; mWorkspaceInfo = null; CreateWorkspaceFromCollab.Progress progress = new CreateWorkspaceFromCollab.Progress(); BuildProgressSpeedAndRemainingTime.ProgressData progressData = new BuildProgressSpeedAndRemainingTime.ProgressData(DateTime.Now); IThreadWaiter waiter = ThreadWaiter.GetWaiter(10); waiter.Execute( /*threadOperationDelegate*/ delegate { tokenExchangeResponse = AutoConfig.PlasticCredentials( unityAccessToken, serverName, projectPath); if (tokenExchangeResponse.Error != null) { return; } RepositoryInfo repInfo = new BaseCommandsImpl(). GetRepositoryInfo(repId, serverName); if (repInfo == null) { return; } repInfo.SetExplicitServer(serverName); mWorkspaceInfo = CreateWorkspaceFromCollab.Create( projectPath, repInfo.Name, repInfo, changesetId, branchId, progress); }, /*afterOperationDelegate*/ delegate { progressControls.HideProgress(); if (waiter.Exception != null) { DisplayException(progressControls, waiter.Exception); TrackWorkspaceMigrationFinishedFailureEvent(mWorkspaceInfo); return; } if (tokenExchangeResponse.Error != null) { mLog.ErrorFormat( "Unable to get TokenExchangeResponse: {0} [code {1}]", tokenExchangeResponse.Error.Message, tokenExchangeResponse.Error.ErrorCode); } if (tokenExchangeResponse.Error != null || mWorkspaceInfo == null) { progressControls.ShowError( "Failed to convert your workspace to Plastic SCM"); TrackWorkspaceMigrationFinishedFailureEvent(mWorkspaceInfo); return; } progressControls.ShowSuccess( "Your workspace has been successfully converted to Plastic SCM"); mIsMigrationCompleted = true; TrackFeatureUseEvent.For( PlasticGui.Plastic.API.GetRepositorySpec(mWorkspaceInfo), TrackFeatureUseEvent.Features.WorkspaceMigrationFinishedSuccess); afterWorkspaceMigratedAction(); }, /*timerTickDelegate*/ delegate { UpdateProgress(projectPath, progress, progressControls, progressData); }); }
void LaunchMigration( string unityAccessToken, string projectPath, string organizationName, RepId repId, long changesetId, long branchId, Action afterWorkspaceMigratedAction, ProgressControlsForMigration progressControls) { string serverName = string.Format( "{0}@cloud", organizationName); TokenExchangeResponse tokenExchangeResponse = null; mWorkspaceInfo = null; CreateWorkspaceFromCollab.Progress progress = new CreateWorkspaceFromCollab.Progress(); BuildProgressSpeedAndRemainingTime.ProgressData progressData = new BuildProgressSpeedAndRemainingTime.ProgressData(DateTime.Now); IThreadWaiter waiter = ThreadWaiter.GetWaiter(10); waiter.Execute( /*threadOperationDelegate*/ delegate { // we just migrate a cloud project, // so let's assume we're going to use Cloud Edition SetupUnityEditionToken.CreateCloudEditionTokenIfNeeded(); if (!ClientConfig.IsConfigured()) { AutoConfigClientConf.FromUnityAccessToken( unityAccessToken, serverName, projectPath); } tokenExchangeResponse = WebRestApiClient. PlasticScm.TokenExchange(unityAccessToken); if (tokenExchangeResponse.Error != null) { return; } CloudEditionWelcomeWindow.JoinCloudServer( serverName, tokenExchangeResponse.User, tokenExchangeResponse.AccessToken); RepositoryInfo repInfo = new BaseCommandsImpl(). GetRepositoryInfo(repId, serverName); if (repInfo == null) { return; } repInfo.SetExplicitServer(serverName); mWorkspaceInfo = CreateWorkspaceFromCollab.Create( projectPath, repInfo.Name, repInfo, changesetId, branchId, progress); }, /*afterOperationDelegate*/ delegate { progressControls.HideProgress(); if (waiter.Exception != null) { DisplayException(progressControls, waiter.Exception); return; } if (tokenExchangeResponse.Error != null) { mLog.ErrorFormat( "Unable to get TokenExchangeResponse: {0} [code {1}]", tokenExchangeResponse.Error.Message, tokenExchangeResponse.Error.ErrorCode); } if (tokenExchangeResponse.Error != null || mWorkspaceInfo == null) { progressControls.ShowError( "Failed to convert your workspace to Plastic SCM"); return; } progressControls.ShowSuccess( "Your workspace has been successfully converted to Plastic SCM"); mIsMigrationCompleted = true; afterWorkspaceMigratedAction(); }, /*timerTickDelegate*/ delegate { UpdateProgress(projectPath, progress, progressControls, progressData); }); }