Exemple #1
0
        static void SavePreference()
        {
            ClientConfigData data = ClientConfig.Get().GetClientConfigData();

            data.SetPendingChangesOnSwitchAction(UserAction.None);
            ClientConfig.Get().Save(data);
        }
        internal static void JoinCloudServer(
            string cloudServer,
            string username,
            string accessToken)
        {
            SaveCloudServer.ToPlasticGuiConfig(cloudServer);
            SaveCloudServer.ToPlasticGuiConfigFile(
                cloudServer, GetPlasticConfigFileToSaveOrganization());
            SaveCloudServer.ToPlasticGuiConfigFile(
                cloudServer, GetGluonConfigFileToSaveOrganization());

            KnownServers.ServersFromCloud.InitializeForWindows(
                PlasticGuiConfig.Get().Configuration.DefaultCloudServer);

            CloudEditionWelcome.WriteToTokensConf(
                cloudServer, username, accessToken);

            if (sAutoLogin)
            {
                ClientConfigData clientConfigData = ConfigurationChecker.GetClientConfigData();
                clientConfigData.WorkspaceServer = cloudServer;
                clientConfigData.WorkingMode     = SEIDWorkingMode.SSOWorkingMode.ToString();
                clientConfigData.SecurityConfig  = username;
                ClientConfig.Get().Save(clientConfigData);

                GetWindow <PlasticWindow>().GetWelcomeView().autoLoginState = AutoLogin.State.OrganizationChoosed;
            }
        }
Exemple #3
0
        static void DoNewRepositoryButton(
            Action <RepositoryCreationData> createRepositoryAction,
            EditorWindow parentWindow,
            string repositoryName,
            string defaultServer)
        {
            string proposedRepositoryName = string.Empty;
            string proposedServer         = string.Empty;

            RepositorySpec repSpec = GetRepSpecFromName(repositoryName);

            if (repSpec != null)
            {
                proposedRepositoryName = repSpec.Name;
                proposedServer         = repSpec.Server;
            }

            RepositoryCreationData creationData = CreateRepositoryDialog.CreateRepository(
                parentWindow,
                proposedRepositoryName,
                proposedServer,
                defaultServer,
                ClientConfig.Get().GetWorkspaceServer());

            createRepositoryAction(creationData);
        }
        internal static void FromUnityAccessToken(
            string unityAccessToken,
            RepositorySpec repSpec,
            string projectPath)
        {
            CredentialsResponse response = PlasticScmRestApiClient.GetCredentials(
                PlasticWebApiUris.GetBaseUri(),
                unityAccessToken);

            if (response.Error != null)
            {
                UnityEngine.Debug.LogErrorFormat(
                    "Error getting credentials to download Cloud Project: {0} ({1})",
                    response.Error.Message,
                    response.Error.ErrorCode);

                return;
            }

            ClientConfigData configData = BuildClientConfigData(
                repSpec,
                projectPath,
                response);

            ClientConfig.Get().Save(configData);
        }
        static void InviteMemberButton_clicked(object obj)
        {
            WorkspaceInfo wkInfo = (WorkspaceInfo)obj;
            CurrentUserAdminCheckResponse response = null;

            IThreadWaiter waiter = ThreadWaiter.GetWaiter(50);

            waiter.Execute(
                /*threadOperationDelegate*/
                delegate
            {
                RepositorySpec repSpec = PlasticGui.Plastic.API.GetRepositorySpec(wkInfo);

                ServerProfile serverProfile =
                    CmConnection.Get().GetProfileManager().GetProfileForServer(repSpec.Server) ??
                    ClientConfig.Get().GetDefaultProfile();

                string authToken = CmConnection.Get()
                                   .BuildWebApiTokenForCloudEditionForProfileAndOrg(
                    serverProfile);

                response = WebRestApiClient.PlasticScm.IsUserAdmin(
                    ServerOrganizationParser.GetOrganizationFromServer(repSpec.Server),
                    authToken);
            },
                /*afterOperationDelegate*/
                delegate
            {
                if (waiter.Exception != null)
                {
                    ExceptionsHandler.LogException(
                        "IsUserAdmin",
                        waiter.Exception);
                    return;
                }

                if (response.Error != null)
                {
                    Debug.LogErrorFormat(
                        "Error checking if the user is the organization admin: {0}",
                        string.Format("Unable to get IsUserAdminResponse: {0} [code {1}]",
                                      response.Error.Message,
                                      response.Error.ErrorCode));

                    return;
                }

                if (response.IsCurrentUserAdmin)
                {
                    Application.OpenURL("https://www.plasticscm.com/dashboard/cloud/" +
                                        response.OrganizationName +
                                        "/users-and-groups");
                    return;
                }

                GuiMessage.ShowInformation(
                    PlasticLocalization.GetString(PlasticLocalization.Name.InviteMembersTitle),
                    PlasticLocalization.GetString(PlasticLocalization.Name.InviteMembersMessage));
            });
        }
Exemple #6
0
        internal static void FromUnityAccessToken(
            string unityAccessToken,
            RepositorySpec repSpec,
            string projectPath)
        {
            CredentialsResponse response =
                PlasticScmRestApiClient.GetCredentials(unityAccessToken);

            if (response.Error != null)
            {
                UnityEngine.Debug.LogErrorFormat(
                    PlasticLocalization.GetString(PlasticLocalization.Name.ErrorGettingCredentialsCloudProject),
                    response.Error.Message,
                    response.Error.ErrorCode);

                return;
            }

            ClientConfigData configData = BuildClientConfigData(
                repSpec,
                projectPath,
                response);

            ClientConfig.Get().Save(configData);
        }
Exemple #7
0
 internal static string PathForApplicationPath(string path)
 {
     try
     {
         return(FindWorkspacePath(path, ClientConfig.Get().GetWkConfigDir()));
     }
     catch (NotConfiguredClientException)
     {
         return(null);
     }
 }
Exemple #8
0
        static void DoNewRepositoryButton(
            Action <RepositoryCreationData> createRepositoryAction,
            EditorWindow parentWindow,
            string repositoryName,
            string defaultServer)
        {
            RepositoryCreationData creationData = CreateRepositoryDialog.CreateRepository(
                parentWindow,
                GetServerFromRepositoryName(repositoryName),
                defaultServer,
                ClientConfig.Get().GetWorkspaceServer());

            createRepositoryAction(creationData);
        }
Exemple #9
0
        internal static AutoSetup.NewIncomingChangesUpdater BuildUpdaterFromMainForDeveloper(
            WorkspaceInfo wkInfo, CheckIncomingChanges.IUpdateIncomingChanges updateIncomingChanges)
        {
            if (!ClientConfig.Get().GetClientConfigData().IsIncomingChangesEnabled())
            {
                return(null);
            }

            AutoSetup.NewIncomingChangesUpdater updater = new AutoSetup.NewIncomingChangesUpdater(
                new UnityPlasticTimerBuilder(), updateIncomingChanges);

            updater.SetWorkspace(wkInfo);
            updater.Start();
            return(updater);
        }
Exemple #10
0
        static void InitLocalization()
        {
            string language = null;

            try
            {
                language = ClientConfig.Get().GetLanguage();
            }
            catch
            {
                language = string.Empty;
            }

            Localization.Init(language);
            PlasticLocalization.SetLanguage(language);
        }
Exemple #11
0
        static void DoNewRepositoryButton(
            Action <RepositoryCreationData> createRepositoryAction,
            EditorWindow parentWindow,
            string repository,
            string defaultServer)
        {
            RepositorySpec repSpec = new SpecGenerator().
                                     GenRepositorySpec(false, repository);

            RepositoryCreationData creationData = CreateRepositoryDialog.CreateRepository(
                parentWindow,
                repSpec.Server,
                defaultServer,
                ClientConfig.Get().GetWorkspaceServer());

            createRepositoryAction(creationData);
        }
Exemple #12
0
        internal static NewIncomingChangesUpdater BuildUpdaterForDeveloper(
            WorkspaceInfo wkInfo,
            CheckIncomingChanges.IAutoRefreshIncomingChangesView autoRefreshIncomingChangesView,
            CheckIncomingChanges.IUpdateIncomingChanges updateIncomingChanges)
        {
            if (!ClientConfig.Get().GetClientConfigData().IsIncomingChangesEnabled())
            {
                return(null);
            }

            NewIncomingChangesUpdater updater = new NewIncomingChangesUpdater(
                new UnityPlasticTimerBuilder(), updateIncomingChanges);

            updater.SetAutoRefreshIncomingChangesView(
                autoRefreshIncomingChangesView);

            updater.SetWorkspace(wkInfo);
            updater.Start();
            return(updater);
        }
Exemple #13
0
        internal static void JoinOrganization(string organization, string username, string accessToken)
        {
            SaveCloudServer.ToPlasticGuiConfig(organization);
            SaveCloudServer.ToPlasticGuiConfigFile(
                organization, GetPlasticConfigFileToSaveOrganization());
            SaveCloudServer.ToPlasticGuiConfigFile(
                organization, GetGluonConfigFileToSaveOrganization());

            KnownServers.ServersFromCloud.InitializeForWindows(
                PlasticGuiConfig.Get().Configuration.DefaultCloudServer);

            CloudEditionWelcome.WriteToTokensConf(
                organization,
                username,
                accessToken);

            ClientConfigData clientConfigData = ClientConfig.Get().GetClientConfigData();

            clientConfigData.WorkspaceServer = organization;
            ClientConfig.Get().Save(clientConfigData);
        }
Exemple #14
0
        internal static GluonNewIncomingChangesUpdater BuildUpdaterForGluon(
            WorkspaceInfo wkInfo,
            GluonCheckIncomingChanges.IAutoRefreshIncomingChangesView autoRefreshIncomingChangesView,
            GluonCheckIncomingChanges.IUpdateIncomingChanges updateIncomingChanges,
            GluonCheckIncomingChanges.ICalculateIncomingChanges calculateIncomingChanges)
        {
            if (!ClientConfig.Get().GetClientConfigData().IsGluonIncomingChangesEnabled())
            {
                return(null);
            }

            GluonNewIncomingChangesUpdater updater = new GluonNewIncomingChangesUpdater(
                wkInfo,
                new UnityPlasticTimerBuilder(),
                updateIncomingChanges,
                autoRefreshIncomingChangesView,
                calculateIncomingChanges);

            updater.Start();
            return(updater);
        }
Exemple #15
0
        internal static bool NeedsConfiguration()
        {
            string plasticClientBinDir = PlasticInstallPath.GetClientBinDir();

            if (!string.IsNullOrEmpty(plasticClientBinDir))
            {
                SetupUnityEditionToken.FromPlasticInstallation(plasticClientBinDir);
            }

            if (ConfigurationChecker.NeedConfiguration())
            {
                return(true);
            }

            if (ClientConfig.Get().GetClientConfigData().WorkingMode == "SSOWorkingMode" &&
                !CmConnection.Get().IsAnyTokenConfigured())
            {
                return(true);
            }

            return(false);
        }
        static void InviteMemberButton_clicked(object obj)
        {
            RepositorySpec repSpec = (RepositorySpec)obj;

            string organizationName = ServerOrganizationParser.
                                      GetOrganizationFromServer(repSpec.Server);

            CurrentUserAdminCheckResponse response = null;

            IThreadWaiter waiter = ThreadWaiter.GetWaiter(50);

            waiter.Execute(
                /*threadOperationDelegate*/
                delegate
            {
                ServerProfile serverProfile = CmConnection.Get().
                                              GetProfileManager().GetProfileForServer(repSpec.Server);

                string authToken = serverProfile != null ?
                                   CmConnection.Get().
                                   BuildWebApiTokenForCloudEditionForUser(
                    serverProfile.Server,
                    serverProfile.GetSEIDWorkingMode(),
                    serverProfile.SecurityConfig):
                                   CmConnection.Get().
                                   BuildWebApiTokenForCloudEditionForUser(
                    repSpec.Server,
                    ClientConfig.Get().GetSEIDWorkingMode(),
                    ClientConfig.Get().GetSecurityConfig());

                if (string.IsNullOrEmpty(authToken))
                {
                    authToken = CmConnection.Get().
                                BuildWebApiTokenForCloudEditionDefaultUser();
                }

                if (string.IsNullOrEmpty(authToken))
                {
                    return;
                }

                response = WebRestApiClient.PlasticScm.IsUserAdmin(
                    organizationName,
                    authToken);
            },
                /*afterOperationDelegate*/
                delegate
            {
                if (waiter.Exception != null)
                {
                    ExceptionsHandler.LogException(
                        "IsUserAdmin",
                        waiter.Exception);

                    OpenCloudDashboardUsersGroupsUrl(organizationName);
                    return;
                }

                if (response == null)
                {
                    mLog.DebugFormat(
                        "Error checking if the user is the organization admin for {0}",
                        organizationName);

                    OpenCloudDashboardUsersGroupsUrl(organizationName);
                    return;
                }

                if (response.Error != null)
                {
                    mLog.DebugFormat(
                        "Error checking if the user is the organization admin: {0}",
                        string.Format("Unable to get IsUserAdminResponse: {0} [code {1}]",
                                      response.Error.Message,
                                      response.Error.ErrorCode));

                    OpenCloudDashboardUsersGroupsUrl(organizationName);
                    return;
                }

                if (response.IsCurrentUserAdmin)
                {
                    OpenCloudDashboardUsersGroupsUrl(response.OrganizationName);
                    return;
                }

                GuiMessage.ShowInformation(
                    PlasticLocalization.GetString(PlasticLocalization.Name.InviteMembersTitle),
                    PlasticLocalization.GetString(PlasticLocalization.Name.InviteMembersMessage));
            });
        }
Exemple #17
0
        void InitializePlastic()
        {
            if (mForceToOpen)
            {
                mForceToOpen = false;
                return;
            }

            try
            {
                if (UnityConfigurationChecker.NeedsConfiguration())
                {
                    return;
                }

                mWkInfo = FindWorkspace.InfoForApplicationPath(
                    Application.dataPath, mPlasticAPI);

                if (mWkInfo == null)
                {
                    return;
                }

                AssetsProcessors.Enable(mPlasticAPI);

                mIsGluonMode = mPlasticAPI.IsGluonWorkspace(mWkInfo);

                mPingEventLoop.SetWorkspace(mWkInfo);
                mEventSenderRestApi.SetToken(BuildToken.FromServerProfile(
                                                 ClientConfig.Get().GetDefaultProfile()));

                InitializeNewIncomingChanges(mWkInfo, mIsGluonMode);

                ViewHost viewHost = new ViewHost();

                PlasticGui.WorkspaceWindow.PendingChanges.PendingChanges pendingChanges =
                    new PlasticGui.WorkspaceWindow.PendingChanges.PendingChanges(mWkInfo);

                mViewSwitcher = new ViewSwitcher(
                    mWkInfo,
                    viewHost,
                    mIsGluonMode,
                    pendingChanges,
                    mDeveloperNewIncomingChangesUpdater,
                    mGluonNewIncomingChangesUpdater,
                    mIncomingChangesNotificationPanel,
                    this);

                mPlasticClient = new PlasticGUIClient(
                    mWkInfo,
                    mViewSwitcher,
                    mViewSwitcher,
                    viewHost,
                    pendingChanges,
                    mDeveloperNewIncomingChangesUpdater,
                    mGluonNewIncomingChangesUpdater,
                    this,
                    new UnityPlasticGuiMessage(this));

                mViewSwitcher.SetPlasticGUIClient(mPlasticClient);
                mViewSwitcher.ShowInitialView();

                mLastUpdateTime = EditorApplication.timeSinceStartup;
            }
            catch (Exception ex)
            {
                mException = ex;

                ExceptionsHandler.HandleException("InitializePlastic", ex);
            }
        }
Exemple #18
0
        void InitializePlastic()
        {
            if (mForceToOpen)
            {
                mForceToOpen = false;
                return;
            }

            try
            {
                if (UnityConfigurationChecker.NeedsConfiguration())
                {
                    return;
                }

                mWkInfo = FindWorkspace.InfoForApplicationPath(
                    Application.dataPath, mPlasticAPI);

                if (mWkInfo == null)
                {
                    AssetMenuItems.Disable();
                    return;
                }

                // SetupCloudProjectId.ForWorkspace(mWkInfo, mPlasticAPI);

                DisableVCSIfEnabled(mWkInfo.ClientPath);

                mIsGluonMode = mPlasticAPI.IsGluonWorkspace(mWkInfo);

                IAssetStatusCache assetStatusCache =
                    new AssetStatusCache(
                        mWkInfo,
                        mIsGluonMode,
                        RepaintProjectWindow);

                AssetsProcessors.Enable(
                    mPlasticAPI,
                    assetStatusCache);

                mPingEventLoop.SetWorkspace(mWkInfo);
                mEventSenderRestApi.SetToken(BuildToken.FromServerProfile(
                                                 ClientConfig.Get().GetDefaultProfile()));

                InitializeNewIncomingChanges(mWkInfo, mIsGluonMode);

                ViewHost viewHost = new ViewHost();

                PlasticGui.WorkspaceWindow.PendingChanges.PendingChanges pendingChanges =
                    new PlasticGui.WorkspaceWindow.PendingChanges.PendingChanges(mWkInfo);

                mViewSwitcher = new ViewSwitcher(
                    mWkInfo,
                    viewHost,
                    mIsGluonMode,
                    pendingChanges,
                    mDeveloperNewIncomingChangesUpdater,
                    mGluonNewIncomingChangesUpdater,
                    mIncomingChangesNotificationPanel,
                    assetStatusCache,
                    this);

                mPlasticClient = new PlasticGUIClient(
                    mWkInfo,
                    mViewSwitcher,
                    mViewSwitcher,
                    viewHost,
                    pendingChanges,
                    mDeveloperNewIncomingChangesUpdater,
                    mGluonNewIncomingChangesUpdater,
                    this,
                    new UnityPlasticGuiMessage(this));

                mViewSwitcher.SetPlasticGUIClient(mPlasticClient);
                mViewSwitcher.ShowInitialView();

                UnityStyles.Initialize(Repaint);

                AssetOperations.IAssetSelection inspectorAssetSelection =
                    new InspectorAssetSelection();

                AssetOperations.IAssetSelection projectViewAssetSelection =
                    new ProjectViewAssetSelection();

                AssetOperations inspectorAssetOperations =
                    new AssetOperations(
                        mWkInfo,
                        mPlasticClient,
                        mViewSwitcher,
                        mViewSwitcher,
                        viewHost,
                        mDeveloperNewIncomingChangesUpdater,
                        assetStatusCache,
                        mViewSwitcher,
                        mViewSwitcher,
                        this,
                        inspectorAssetSelection,
                        mIsGluonMode);

                AssetOperations projectViewAssetOperations =
                    new AssetOperations(
                        mWkInfo,
                        mPlasticClient,
                        mViewSwitcher,
                        mViewSwitcher,
                        viewHost,
                        mDeveloperNewIncomingChangesUpdater,
                        assetStatusCache,
                        mViewSwitcher,
                        mViewSwitcher,
                        this,
                        projectViewAssetSelection,
                        mIsGluonMode);

                AssetMenuItems.Enable(
                    projectViewAssetOperations,
                    assetStatusCache,
                    projectViewAssetSelection);

                DrawInspectorOperations.Enable(
                    inspectorAssetOperations,
                    assetStatusCache,
                    inspectorAssetSelection);

                DrawAssetOverlay.Initialize(
                    assetStatusCache,
                    RepaintProjectWindow);

                AutoCommitOperation.SetPlasticGUIClient(mPlasticClient);

                mLastUpdateTime = EditorApplication.timeSinceStartup;
            }
            catch (Exception ex)
            {
                mException = ex;

                ExceptionsHandler.HandleException("InitializePlastic", ex);
            }
        }
        void DownloadRepository(object state)
        {
            DownloadRepositoryParameters parameters = (DownloadRepositoryParameters)state;

            try
            {
                if (FindWorkspace.HasWorkspace(parameters.ProjectPath))
                {
                    // each domain reload, the package is reloaded.
                    // way need to check if we already downloaded it
                    return;
                }

                mDisplayProgress = true;

                IPlasticWebRestApi restApi           = new PlasticWebRestApi();
                string             defaultCloudAlias = restApi.GetDefaultCloudAlias();

                RepositorySpec repSpec = BuildRepSpec(
                    parameters.CloudRepository,
                    parameters.CloudOrganization,
                    defaultCloudAlias);

                // we just download a cloud project,
                // so let's assume we're going to use Cloud Edition
                SetupUnityEditionToken.CreateCloudEditionTokenIfNeeded();

                if (!ClientConfig.IsConfigured())
                {
                    AutoConfigClientConf.FromUnityAccessToken(
                        parameters.AccessToken,
                        repSpec.Server,
                        parameters.ProjectPath);
                }

                TokenExchangeResponse tokenExchangeResponse = WebRestApiClient.
                                                              PlasticScm.TokenExchange(parameters.AccessToken);

                if (tokenExchangeResponse.Error != null)
                {
                    mOperationFailed = true;

                    UnityEngine.Debug.LogErrorFormat(
                        PlasticLocalization.GetString(PlasticLocalization.Name.ErrorDownloadingCloudProject),
                        string.Format("Unable to get TokenExchangeResponse: {0} [code {1}]",
                                      tokenExchangeResponse.Error.Message,
                                      tokenExchangeResponse.Error.ErrorCode));
                    return;
                }

                CloudEditionWelcomeWindow.JoinCloudServer(
                    repSpec.Server,
                    tokenExchangeResponse.User,
                    tokenExchangeResponse.AccessToken);

                ClientConfigData clientConfigData = ClientConfig.Get().GetClientConfigData();
                clientConfigData.WorkspaceServer = repSpec.Server;
                ClientConfig.Get().Save(clientConfigData);

                WorkspaceInfo wkInfo = CreateWorkspace(
                    repSpec, parameters.ProjectPath);

                mLog.DebugFormat("Created workspace {0} on {1}",
                                 wkInfo.Name,
                                 wkInfo.ClientPath);

                PlasticGui.Plastic.API.Update(
                    wkInfo.ClientPath,
                    UpdateFlags.None,
                    null,
                    mUpdateNotifier);
            }
            catch (Exception ex)
            {
                LogException(ex);

                UnityEngine.Debug.LogErrorFormat(
                    PlasticLocalization.GetString(PlasticLocalization.Name.ErrorDownloadingCloudProject),
                    ex.Message);

                mOperationFailed = true;
            }
            finally
            {
                mOperationFinished = true;
            }
        }
        void DownloadRepository(object state)
        {
            DownloadRepositoryParameters parameters = (DownloadRepositoryParameters)state;

            try
            {
                IPlasticWebRestApi restApi           = new PlasticWebRestApi();
                string             defaultCloudAlias = restApi.GetDefaultCloudAlias();

                RepositorySpec repSpec = BuildRepSpec(
                    parameters.CloudRepository,
                    parameters.CloudOrganization,
                    defaultCloudAlias);

                // we just download a cloud project,
                // so let's assume we're going to use Cloud Edition
                SetupUnityEditionToken.CreateCloudEditionTokenIfNeeded();

                if (!ClientConfig.IsConfigured())
                {
                    AutoConfigClientConf.FromUnityAccessToken(
                        parameters.AccessToken,
                        repSpec,
                        parameters.ProjectPath);
                }

                if (WorkspaceExists(parameters.ProjectPath))
                {
                    // each domain reload, the package is reloaded.
                    // way need to check if we already downloaded it
                    return;
                }

                mDisplayProgress = true;

                WorkspaceInfo wkInfo = CreateWorkspace(
                    repSpec, parameters.ProjectPath);

                mLog.DebugFormat("Created workspace {0} on {1}",
                                 wkInfo.Name,
                                 wkInfo.ClientPath);

                AutoLogin autoLogin = new AutoLogin();
                autoLogin.ExchangeTokens(parameters.AccessToken);

                CloudEditionWelcomeWindow.JoinOrganization(parameters.CloudOrganization, AutoLogin.sAccessToken, AutoLogin.sUserName);

                ClientConfigData clientConfigData = ClientConfig.Get().GetClientConfigData();
                clientConfigData.WorkspaceServer = parameters.CloudOrganization;
                ClientConfig.Get().Save(clientConfigData);

                Plastic.API.Update(
                    wkInfo.ClientPath,
                    UpdateFlags.None,
                    null,
                    mUpdateNotifier);
            }
            catch (Exception ex)
            {
                LogException(ex);

                UnityEngine.Debug.LogErrorFormat(
                    PlasticLocalization.GetString(PlasticLocalization.Name.ErrorDownloadingCloudProject),
                    ex.Message);

                mOperationFailed = true;
            }
            finally
            {
                mOperationFinished = true;
            }
        }
Exemple #21
0
 internal static string PathForApplicationPath(string path)
 {
     return(FindWorkspacePath(
                path, ClientConfig.Get().GetWkConfigDir()));
 }