123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417 |
- using System;
-
- using UnityEditor;
- using UnityEngine;
-
- using Codice.Client.BaseCommands;
- using Codice.Client.BaseCommands.Sync;
- using Codice.Client.Common.EventTracking;
- using Codice.Client.Common.Threading;
- using Codice.CM.Common;
- using Codice.LogWrapper;
- using CodiceApp.EventTracking;
- using PlasticGui;
- using PlasticGui.WorkspaceWindow;
- using Unity.PlasticSCM.Editor.UI;
- using Unity.PlasticSCM.Editor.UI.Progress;
- using Unity.PlasticSCM.Editor.WebApi;
- using Unity.PlasticSCM.Editor.Configuration;
-
- namespace Unity.PlasticSCM.Editor.CollabMigration
- {
- internal class MigrationDialog : PlasticDialog
- {
- protected override Rect DefaultRect
- {
- get
- {
- var baseRect = base.DefaultRect;
- return new Rect(baseRect.x, baseRect.y, 710, 260);
- }
- }
-
- protected override string GetTitle()
- {
- return "Upgrade your Collaborate project to Unity Version Control";
- }
-
- //TODO: localize the strings
- protected override void OnModalGUI()
- {
- GUILayout.BeginHorizontal();
-
- DoIconArea();
-
- GUILayout.Space(20);
-
- DoContentArea();
-
- GUILayout.EndHorizontal();
-
- DoButtonsArea();
-
- mProgressControls.UpdateDeterminateProgress(this);
- }
-
- internal static bool Show(
- EditorWindow parentWindow,
- string unityAccessToken,
- string projectPath,
- string user,
- string organizationName,
- RepId repId,
- long changesetId,
- long branchId,
- Action afterWorkspaceMigratedAction)
- {
- MigrationDialog dialog = Create(
- unityAccessToken,
- projectPath,
- user,
- organizationName,
- repId,
- changesetId,
- branchId,
- afterWorkspaceMigratedAction,
- new ProgressControlsForMigration());
-
- return dialog.RunModal(parentWindow) == ResponseType.Ok;
- }
-
- void DoIconArea()
- {
- GUILayout.BeginVertical();
-
- GUILayout.Space(30);
-
- Rect iconRect = GUILayoutUtility.GetRect(
- GUIContent.none, EditorStyles.label,
- GUILayout.Width(60), GUILayout.Height(60));
-
- GUI.DrawTexture(
- iconRect,
- Images.GetPlasticIcon(),
- ScaleMode.ScaleToFit);
-
- GUILayout.EndVertical();
- }
-
- void DoContentArea()
- {
- GUILayout.BeginVertical();
-
- Title("Upgrade your Collaborate project to Unity Version Control");
-
- GUILayout.Space(20);
-
- Paragraph("Your Unity project has been upgraded (from Collaborate) to Unity Version Control free" +
- " of charge by your administrator. Your local workspace will now be converted to a" +
- " Unity Version Control workspace in just a few minutes. Select “Migrate” to start the conversion process.");
-
- DrawProgressForMigration.For(
- mProgressControls.ProgressData);
-
- GUILayout.Space(40);
-
- GUILayout.EndVertical();
- }
-
- //TODO: localize the strings
- void DoButtonsArea()
- {
- using (new EditorGUILayout.HorizontalScope())
- {
- GUILayout.FlexibleSpace();
-
- if (Application.platform == RuntimePlatform.WindowsEditor)
- {
- DoOkButton();
- DoCloseButton();
- return;
- }
-
- DoCloseButton();
- DoOkButton();
- }
- }
-
- void DoOkButton()
- {
- if (mIsMigrationCompleted)
- {
- DoOpenPlasticButton();
- return;
- }
-
- DoMigrateButton();
- }
-
- void DoCloseButton()
- {
- GUI.enabled = !mProgressControls.ProgressData.IsOperationRunning;
-
- if (NormalButton(PlasticLocalization.GetString(
- PlasticLocalization.Name.CloseButton)))
- {
- if (mIsMigrationCompleted)
- TrackFeatureUseEvent.For(
- PlasticGui.Plastic.API.GetRepositorySpec(mWorkspaceInfo),
- TrackFeatureUseEvent.Features.CloseDialogAfterWorkspaceMigration);
- else
- TrackFeatureUseEvent.For(
- GetEventCloudOrganizationInfo(),
- TrackFeatureUseEvent.Features.DoNotMigrateWorkspace);
-
- CloseButtonAction();
- }
-
- GUI.enabled = true;
- }
-
- void DoOpenPlasticButton()
- {
- if (!NormalButton("Open Unity Version Control"))
- return;
-
- TrackFeatureUseEvent.For(
- PlasticGui.Plastic.API.GetRepositorySpec(mWorkspaceInfo),
- TrackFeatureUseEvent.Features.OpenPlasticAfterWorkspaceMigration);
-
- ((IPlasticDialogCloser)this).CloseDialog();
- ShowWindow.Plastic();
- }
-
- EventCloudOrganizationInfo GetEventCloudOrganizationInfo()
- {
- return new EventCloudOrganizationInfo()
- {
- Name = mOrganizationName,
- ServerType = EventCloudOrganizationInfo.GetServerType(true),
- User = mUser
- };
- }
-
- void DoMigrateButton()
- {
- GUI.enabled = !mProgressControls.ProgressData.IsOperationRunning;
-
- if (NormalButton("Migrate"))
- {
- if (EditorUtility.DisplayDialog(
- "Collab migration to Unity Version Control",
- "Are you sure to start the migration process?",
- PlasticLocalization.GetString(PlasticLocalization.Name.YesButton),
- PlasticLocalization.GetString(PlasticLocalization.Name.NoButton)))
- {
- TrackFeatureUseEvent.For(
- GetEventCloudOrganizationInfo(),
- TrackFeatureUseEvent.Features.MigrateWorkspace);
-
- LaunchMigration(
- mUnityAccessToken, mProjectPath,
- mOrganizationName, mRepId,
- mChangesetId, mBranchId,
- mAfterWorkspaceMigratedAction,
- mProgressControls);
- }
- else
- {
- TrackFeatureUseEvent.For(
- GetEventCloudOrganizationInfo(),
- TrackFeatureUseEvent.Features.DoNotMigrateWorkspace);
- }
- }
-
- GUI.enabled = true;
- }
-
- 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 Unity Version Control");
- TrackWorkspaceMigrationFinishedFailureEvent(mWorkspaceInfo);
- return;
- }
-
- progressControls.ShowSuccess(
- "Your workspace has been successfully converted to Unity Version Control");
-
- mIsMigrationCompleted = true;
-
- TrackFeatureUseEvent.For(
- PlasticGui.Plastic.API.GetRepositorySpec(mWorkspaceInfo),
- TrackFeatureUseEvent.Features.WorkspaceMigrationFinishedSuccess);
-
- afterWorkspaceMigratedAction();
- },
- /*timerTickDelegate*/
- delegate
- {
- UpdateProgress(projectPath, progress, progressControls, progressData);
- });
- }
-
- void TrackWorkspaceMigrationFinishedFailureEvent(WorkspaceInfo wkInfo)
- {
- if (wkInfo == null)
- {
- TrackFeatureUseEvent.For(
- GetEventCloudOrganizationInfo(),
- TrackFeatureUseEvent.Features.WorkspaceMigrationFinishedFailure);
- return;
- }
-
- TrackFeatureUseEvent.For(
- PlasticGui.Plastic.API.GetRepositorySpec(wkInfo),
- TrackFeatureUseEvent.Features.WorkspaceMigrationFinishedFailure);
- }
-
- static void DisplayException(
- ProgressControlsForMigration progressControls,
- Exception ex)
- {
- ExceptionsHandler.LogException(
- "MigrationDialog", ex);
-
- progressControls.ShowError(
- ExceptionsHandler.GetCorrectExceptionMessage(ex));
- }
-
- static MigrationDialog Create(
- string unityAccessToken,
- string projectPath,
- string user,
- string organizationName,
- RepId repId,
- long changesetId,
- long branchId,
- Action afterWorkspaceMigratedAction,
- ProgressControlsForMigration progressControls)
- {
- var instance = CreateInstance<MigrationDialog>();
- instance.IsResizable = false;
- instance.mUnityAccessToken = unityAccessToken;
- instance.mProjectPath = projectPath;
- instance.mUser = user;
- instance.mOrganizationName = organizationName;
- instance.mRepId = repId;
- instance.mChangesetId = changesetId;
- instance.mBranchId = branchId;
- instance.mAfterWorkspaceMigratedAction = afterWorkspaceMigratedAction;
- instance.mProgressControls = progressControls;
- instance.mEscapeKeyAction = instance.CloseButtonAction;
- return instance;
- }
-
- bool mIsMigrationCompleted;
-
- ProgressControlsForMigration mProgressControls;
- Action mAfterWorkspaceMigratedAction;
- long mChangesetId;
- long mBranchId;
- RepId mRepId;
- string mOrganizationName;
- string mUser;
- string mProjectPath;
- string mUnityAccessToken;
- WorkspaceInfo mWorkspaceInfo;
-
- static readonly ILog mLog = PlasticApp.GetLogger("MigrationDialog");
- }
- }
|