first commit
This commit is contained in:
@@ -0,0 +1,271 @@
|
||||
using System;
|
||||
using System.Threading;
|
||||
|
||||
using UnityEditor;
|
||||
|
||||
using Codice.Client.Common.EventTracking;
|
||||
using Codice.CM.Common;
|
||||
using Codice.LogWrapper;
|
||||
using PlasticGui;
|
||||
using PlasticGui.Help.Conditions;
|
||||
using PlasticGui.WebApi.Responses;
|
||||
using Unity.PlasticSCM.Editor.AssetUtils;
|
||||
using Unity.PlasticSCM.Editor.Configuration;
|
||||
using Unity.PlasticSCM.Editor.UI;
|
||||
using Unity.PlasticSCM.Editor.Views.CreateWorkspace;
|
||||
using Unity.PlasticSCM.Editor.WebApi;
|
||||
|
||||
namespace Unity.PlasticSCM.Editor.Hub.Operations
|
||||
{
|
||||
internal class CreateWorkspace
|
||||
{
|
||||
internal static void LaunchOperation(
|
||||
OperationParams parameters)
|
||||
{
|
||||
PlasticApp.InitializeIfNeeded();
|
||||
|
||||
CreateWorkspace createWorkspaceOperation =
|
||||
new CreateWorkspace();
|
||||
|
||||
createWorkspaceOperation.CreateWorkspaceOperation(
|
||||
parameters);
|
||||
}
|
||||
|
||||
internal static WorkspaceInfo CreateWorkspaceForRepSpec(
|
||||
RepositorySpec repositorySpec,
|
||||
string wkPath,
|
||||
ILog log)
|
||||
{
|
||||
CreateWorkspaceDialogUserAssistant assistant =
|
||||
CreateWorkspaceDialogUserAssistant.ForWkPathAndName(
|
||||
PlasticGuiConfig.Get().Configuration.DefaultWorkspaceRoot,
|
||||
PlasticGui.Plastic.API.GetAllWorkspacesArray());
|
||||
|
||||
assistant.RepositoryChanged(
|
||||
repositorySpec.ToString(),
|
||||
string.Empty,
|
||||
string.Empty);
|
||||
|
||||
WorkspaceInfo wkInfo = PlasticGui.Plastic.API.CreateWorkspace(
|
||||
wkPath,
|
||||
assistant.GetProposedWorkspaceName(),
|
||||
repositorySpec.ToString());
|
||||
|
||||
log.DebugFormat("Created workspace {0} on {1}",
|
||||
wkInfo.Name,
|
||||
wkInfo.ClientPath);
|
||||
|
||||
return wkInfo;
|
||||
}
|
||||
|
||||
void CreateWorkspaceOperation(
|
||||
OperationParams parameters)
|
||||
{
|
||||
RefreshAsset.BeforeLongAssetOperation();
|
||||
|
||||
try
|
||||
{
|
||||
ThreadPool.QueueUserWorkItem(
|
||||
CreateWorkspaceIfNeeded,
|
||||
parameters);
|
||||
|
||||
while (mStatus != Status.Finished)
|
||||
{
|
||||
if (mDisplayProgress)
|
||||
{
|
||||
DisplayProgress(
|
||||
mStatus, parameters.Repository);
|
||||
}
|
||||
|
||||
Thread.Sleep(150);
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
EditorUtility.ClearProgressBar();
|
||||
|
||||
RefreshAsset.AfterLongAssetOperation();
|
||||
|
||||
if (!mOperationFailed)
|
||||
{
|
||||
PlasticPlugin.Enable();
|
||||
ShowWindow.PlasticDisablingCollab();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void CreateWorkspaceIfNeeded(object state)
|
||||
{
|
||||
OperationParams parameters = (OperationParams)state;
|
||||
|
||||
try
|
||||
{
|
||||
if (FindWorkspace.HasWorkspace(parameters.WorkspaceFullPath))
|
||||
{
|
||||
// each domain reload, the package is reloaded.
|
||||
// way need to check if we already created it
|
||||
return;
|
||||
}
|
||||
|
||||
mDisplayProgress = true;
|
||||
|
||||
mStatus = Status.ConfiguringCredentials;
|
||||
|
||||
TokenExchangeResponse tokenExchangeResponse =
|
||||
AutoConfig.PlasticCredentials(
|
||||
parameters.AccessToken,
|
||||
parameters.RepositorySpec.Server);
|
||||
|
||||
if (tokenExchangeResponse.Error != null)
|
||||
{
|
||||
mOperationFailed = true;
|
||||
|
||||
LogTokenExchangeErrorInConsole(
|
||||
tokenExchangeResponse.Error);
|
||||
return;
|
||||
}
|
||||
|
||||
mStatus = Status.CreatingWorkspace;
|
||||
|
||||
TrackFeatureUseEvent.For(
|
||||
parameters.RepositorySpec, TrackFeatureUseEvent.
|
||||
Features.UnityPackage.CreateWorkspaceFromHub);
|
||||
|
||||
WorkspaceInfo wkInfo = CreateWorkspaceForRepSpec(
|
||||
parameters.RepositorySpec,
|
||||
parameters.WorkspaceFullPath,
|
||||
mLog);
|
||||
|
||||
mStatus = Status.PerformingInitialCheckin;
|
||||
|
||||
PerformInitialCheckinIfRepositoryIsEmpty(
|
||||
wkInfo, parameters.RepositorySpec,
|
||||
PlasticGui.Plastic.API, mLog);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
LogException(ex);
|
||||
LogExceptionErrorInConsole(ex);
|
||||
|
||||
mOperationFailed = true;
|
||||
}
|
||||
finally
|
||||
{
|
||||
mStatus = Status.Finished;
|
||||
}
|
||||
}
|
||||
|
||||
static void PerformInitialCheckinIfRepositoryIsEmpty(
|
||||
WorkspaceInfo wkInfo,
|
||||
RepositorySpec repositorySpec,
|
||||
IPlasticAPI plasticApi,
|
||||
ILog log)
|
||||
{
|
||||
try
|
||||
{
|
||||
bool isEmptyRepository = IsEmptyRepositoryCondition.
|
||||
Evaluate(wkInfo, repositorySpec, plasticApi);
|
||||
|
||||
if (!isEmptyRepository)
|
||||
return;
|
||||
|
||||
PerformInitialCheckin.PerformCheckinPackagesAndProjectSettingsFolders(
|
||||
wkInfo, false, plasticApi);
|
||||
|
||||
log.DebugFormat("Created initial checkin on repository '{0}'",
|
||||
repositorySpec.ToString());
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
// create the initial checkin if it's possible, otherwise
|
||||
// just log the exception (no error shown for the user)
|
||||
LogException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
static void DisplayProgress(
|
||||
Status status,
|
||||
string repository)
|
||||
{
|
||||
string progressMessage = GetProgressString(status);
|
||||
|
||||
float progressPercent = (int)status / (float)Status.Finished;
|
||||
|
||||
EditorUtility.DisplayProgressBar(
|
||||
string.Format("{0} {1}",
|
||||
PlasticLocalization.GetString(
|
||||
PlasticLocalization.Name.CreatingWorkspaceProgress),
|
||||
repository),
|
||||
progressMessage, progressPercent);
|
||||
}
|
||||
|
||||
static void LogTokenExchangeErrorInConsole(ErrorResponse.ErrorFields error)
|
||||
{
|
||||
UnityEngine.Debug.LogErrorFormat(
|
||||
PlasticLocalization.GetString(
|
||||
PlasticLocalization.Name.ErrorCreatingWorkspaceForProject),
|
||||
string.Format("Unable to get TokenExchangeResponse: {0} [code {1}]",
|
||||
error.Message, error.ErrorCode));
|
||||
}
|
||||
|
||||
static void LogExceptionErrorInConsole(Exception ex)
|
||||
{
|
||||
UnityEngine.Debug.LogErrorFormat(
|
||||
PlasticLocalization.GetString(
|
||||
PlasticLocalization.Name.ErrorCreatingWorkspaceForProject),
|
||||
ex.Message);
|
||||
}
|
||||
|
||||
static void LogException(Exception ex)
|
||||
{
|
||||
mLog.WarnFormat("Message: {0}", ex.Message);
|
||||
|
||||
mLog.DebugFormat(
|
||||
"StackTrace:{0}{1}",
|
||||
Environment.NewLine, ex.StackTrace);
|
||||
}
|
||||
|
||||
static string GetProgressString(Status status)
|
||||
{
|
||||
switch (status)
|
||||
{
|
||||
case Status.Starting:
|
||||
return PlasticLocalization.GetString(
|
||||
PlasticLocalization.Name.CreateWorkspaceProgressStarting);
|
||||
case Status.ConfiguringCredentials:
|
||||
return PlasticLocalization.GetString(
|
||||
PlasticLocalization.Name.CreateWorkspaceProgressConfiguringCredentials);
|
||||
case Status.CreatingWorkspace:
|
||||
return PlasticLocalization.GetString(
|
||||
PlasticLocalization.Name.CreateWorkspaceProgressCreatingWorkspace);
|
||||
case Status.PerformingInitialCheckin:
|
||||
return PlasticLocalization.GetString(
|
||||
PlasticLocalization.Name.CreateWorkspaceProgressPerformingInitialCheckin);
|
||||
case Status.Finished:
|
||||
return PlasticLocalization.GetString(
|
||||
PlasticLocalization.Name.CreateWorkspaceProgressFinished);
|
||||
}
|
||||
|
||||
return string.Empty;
|
||||
}
|
||||
|
||||
CreateWorkspace()
|
||||
{
|
||||
}
|
||||
|
||||
enum Status : int
|
||||
{
|
||||
Starting = 1,
|
||||
ConfiguringCredentials = 2,
|
||||
CreatingWorkspace = 3,
|
||||
PerformingInitialCheckin = 4,
|
||||
Finished = 5
|
||||
};
|
||||
|
||||
volatile Status mStatus = Status.Starting;
|
||||
volatile bool mOperationFailed = false;
|
||||
volatile bool mDisplayProgress;
|
||||
|
||||
static readonly ILog mLog = PlasticApp.GetLogger("CreateWorkspace");
|
||||
}
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: de7c5b4b6cb58e546b24137064ac9025
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,192 @@
|
||||
using System;
|
||||
using System.Threading;
|
||||
|
||||
using UnityEditor;
|
||||
|
||||
using Codice.Client.BaseCommands;
|
||||
using Codice.Client.Commands;
|
||||
using Codice.Client.Common.EventTracking;
|
||||
using Codice.CM.Common;
|
||||
using Codice.LogWrapper;
|
||||
using PlasticGui;
|
||||
using PlasticGui.WebApi.Responses;
|
||||
using PlasticGui.WorkspaceWindow;
|
||||
using PlasticGui.WorkspaceWindow.Update;
|
||||
using Unity.PlasticSCM.Editor.AssetUtils;
|
||||
using Unity.PlasticSCM.Editor.UI;
|
||||
using Unity.PlasticSCM.Editor.WebApi;
|
||||
using Unity.PlasticSCM.Editor.Configuration;
|
||||
|
||||
namespace Unity.PlasticSCM.Editor.Hub.Operations
|
||||
{
|
||||
internal class DownloadRepository
|
||||
{
|
||||
internal static void LaunchOperation(
|
||||
OperationParams parameters)
|
||||
{
|
||||
PlasticApp.InitializeIfNeeded();
|
||||
|
||||
DownloadRepository downloadOperation =
|
||||
new DownloadRepository();
|
||||
|
||||
downloadOperation.DownloadRepositoryOperation(
|
||||
parameters);
|
||||
}
|
||||
|
||||
void DownloadRepositoryOperation(
|
||||
OperationParams parameters)
|
||||
{
|
||||
RefreshAsset.BeforeLongAssetOperation();
|
||||
|
||||
try
|
||||
{
|
||||
BuildProgressSpeedAndRemainingTime.ProgressData progressData =
|
||||
new BuildProgressSpeedAndRemainingTime.ProgressData(DateTime.Now);
|
||||
|
||||
ThreadPool.QueueUserWorkItem(
|
||||
DownloadRepositoryToPathIfNeeded,
|
||||
parameters);
|
||||
|
||||
while (!mOperationFinished)
|
||||
{
|
||||
if (mDisplayProgress)
|
||||
{
|
||||
DisplayProgress(
|
||||
mUpdateNotifier.GetUpdateStatus(),
|
||||
progressData,
|
||||
parameters.Repository);
|
||||
}
|
||||
|
||||
Thread.Sleep(150);
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
EditorUtility.ClearProgressBar();
|
||||
|
||||
RefreshAsset.AfterLongAssetOperation();
|
||||
|
||||
if (!mOperationFailed)
|
||||
{
|
||||
PlasticPlugin.Enable();
|
||||
ShowWindow.PlasticDisablingCollab();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void DownloadRepositoryToPathIfNeeded(object state)
|
||||
{
|
||||
OperationParams parameters = (OperationParams)state;
|
||||
|
||||
try
|
||||
{
|
||||
if (FindWorkspace.HasWorkspace(parameters.WorkspaceFullPath))
|
||||
{
|
||||
// each domain reload, the package is reloaded.
|
||||
// way need to check if we already downloaded it
|
||||
return;
|
||||
}
|
||||
|
||||
mDisplayProgress = true;
|
||||
|
||||
TokenExchangeResponse tokenExchangeResponse =
|
||||
AutoConfig.PlasticCredentials(
|
||||
parameters.AccessToken,
|
||||
parameters.RepositorySpec.Server);
|
||||
|
||||
if (tokenExchangeResponse.Error != null)
|
||||
{
|
||||
mOperationFailed = true;
|
||||
|
||||
LogTokenExchangeErrorInConsole(
|
||||
tokenExchangeResponse.Error);
|
||||
return;
|
||||
}
|
||||
|
||||
TrackFeatureUseEvent.For(
|
||||
parameters.RepositorySpec, TrackFeatureUseEvent.
|
||||
Features.UnityPackage.DownloadRepositoryFromHub);
|
||||
|
||||
WorkspaceInfo wkInfo = CreateWorkspace.
|
||||
CreateWorkspaceForRepSpec(
|
||||
parameters.RepositorySpec,
|
||||
parameters.WorkspaceFullPath,
|
||||
mLog);
|
||||
|
||||
PlasticGui.Plastic.API.Update(
|
||||
wkInfo.ClientPath,
|
||||
UpdateFlags.None,
|
||||
null,
|
||||
mUpdateNotifier);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
LogException(ex);
|
||||
LogExceptionErrorInConsole(ex);
|
||||
|
||||
mOperationFailed = true;
|
||||
}
|
||||
finally
|
||||
{
|
||||
mOperationFinished = true;
|
||||
}
|
||||
}
|
||||
|
||||
static void DisplayProgress(
|
||||
UpdateOperationStatus status,
|
||||
BuildProgressSpeedAndRemainingTime.ProgressData progressData,
|
||||
string cloudRepository)
|
||||
{
|
||||
string totalProgressMessage = UpdateProgressRender.
|
||||
GetProgressString(status, progressData);
|
||||
|
||||
float totalProgressPercent = GetProgressBarPercent.
|
||||
ForTransfer(status.UpdatedSize, status.TotalSize) / 100f;
|
||||
|
||||
EditorUtility.DisplayProgressBar(
|
||||
string.Format("{0} {1}",
|
||||
PlasticLocalization.GetString(
|
||||
PlasticLocalization.Name.DownloadingProgress),
|
||||
cloudRepository),
|
||||
totalProgressMessage, totalProgressPercent);
|
||||
}
|
||||
|
||||
static void LogTokenExchangeErrorInConsole(ErrorResponse.ErrorFields error)
|
||||
{
|
||||
UnityEngine.Debug.LogErrorFormat(
|
||||
PlasticLocalization.GetString(
|
||||
PlasticLocalization.Name.ErrorDownloadingCloudProject),
|
||||
string.Format("Unable to get TokenExchangeResponse: {0} [code {1}]",
|
||||
error.Message, error.ErrorCode));
|
||||
}
|
||||
|
||||
static void LogExceptionErrorInConsole(Exception ex)
|
||||
{
|
||||
UnityEngine.Debug.LogErrorFormat(
|
||||
PlasticLocalization.GetString(
|
||||
PlasticLocalization.Name.ErrorDownloadingCloudProject),
|
||||
ex.Message);
|
||||
}
|
||||
|
||||
static void LogException(Exception ex)
|
||||
{
|
||||
mLog.WarnFormat("Message: {0}", ex.Message);
|
||||
|
||||
mLog.DebugFormat(
|
||||
"StackTrace:{0}{1}",
|
||||
Environment.NewLine, ex.StackTrace);
|
||||
}
|
||||
|
||||
DownloadRepository()
|
||||
{
|
||||
}
|
||||
|
||||
volatile bool mOperationFinished = false;
|
||||
volatile bool mOperationFailed = false;
|
||||
volatile bool mDisplayProgress;
|
||||
|
||||
UpdateNotifier mUpdateNotifier = new UpdateNotifier();
|
||||
|
||||
static readonly ILog mLog = PlasticApp.GetLogger("DownloadRepository");
|
||||
}
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 608efd4e185fb9440bb8550d98e20ca4
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,60 @@
|
||||
using System.IO;
|
||||
|
||||
using Codice.CM.Common;
|
||||
using PlasticGui.WebApi;
|
||||
|
||||
namespace Unity.PlasticSCM.Editor.Hub.Operations
|
||||
{
|
||||
internal class OperationParams
|
||||
{
|
||||
internal readonly string WorkspaceFullPath;
|
||||
internal readonly string Organization;
|
||||
internal readonly string Repository;
|
||||
internal readonly RepositorySpec RepositorySpec;
|
||||
internal readonly string AccessToken;
|
||||
|
||||
internal static OperationParams BuildFromCommand(
|
||||
ParseArguments.Command command,
|
||||
string unityAccessToken)
|
||||
{
|
||||
string workspaceFullPath = command.HasWorkspacePath() ?
|
||||
Path.GetFullPath(command.WorkspacePath) :
|
||||
Path.GetFullPath(command.ProjectPath);
|
||||
|
||||
return new OperationParams(
|
||||
workspaceFullPath,
|
||||
command.Organization,
|
||||
command.Repository,
|
||||
BuildRepositorySpec(
|
||||
command.Organization, command.Repository),
|
||||
unityAccessToken);
|
||||
}
|
||||
|
||||
static RepositorySpec BuildRepositorySpec(
|
||||
string organization,
|
||||
string repository)
|
||||
{
|
||||
string defaultCloudAlias = new PlasticWebRestApi()
|
||||
.GetDefaultCloudAlias();
|
||||
|
||||
return RepositorySpec.BuildFromNameAndResolvedServer(
|
||||
repository,
|
||||
CloudServer.BuildFullyQualifiedName(organization, defaultCloudAlias)
|
||||
);
|
||||
}
|
||||
|
||||
OperationParams(
|
||||
string workspaceFullPath,
|
||||
string organization,
|
||||
string repository,
|
||||
RepositorySpec repositorySpec,
|
||||
string accessToken)
|
||||
{
|
||||
WorkspaceFullPath = workspaceFullPath;
|
||||
Organization = organization;
|
||||
Repository = repository;
|
||||
RepositorySpec = repositorySpec;
|
||||
AccessToken = accessToken;
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 7985a2b6ab3fac849929b1e2d51fe9cf
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
Reference in New Issue
Block a user