Пример #1
0
        public void GetGooglePlayKey(Action <AsyncOperation> onGet, string authSignature)
        {
            var request = UnityWebRequest.Get(GetGoogleKeyResource() + k_GoogleKeyGetSuffix);

            var encodedAuthToken = ServicesUtils.Base64Encode((UnityConnect.instance.projectInfo.projectGUID + ":" + authSignature));

            request.SetRequestHeader("Authorization", $"Basic {encodedAuthToken}");

            var operation = request.SendWebRequest();

            operation.completed += onGet;
        }
            public override void EnterState()
            {
                LoadTemplateIntoScrollContainer(k_TemplatePath);

                var scrollContainer = provider.rootVisualElement.Q(className: k_ScrollContainerClass);

                scrollContainer.Add(ServicesUtils.SetupSupportedPlatformsBlock(GetSupportedPlatforms()));

                provider.UpdateServiceToggleAndDashboardLink(provider.serviceInstance.IsServiceEnabled());

                provider.HandlePermissionRestrictedControls();
            }
        void LoadConfigurationsFromCdn()
        {
            try
            {
                if (m_GetServicesUrlsRequest != null)
                {
                    try
                    {
                        m_GetServicesUrlsRequest.Abort();
                    }
                    catch (Exception)
                    {
                        // ignored, we try to abort (best effort) but no need to panic if it fails
                    }
                    m_GetServicesUrlsRequest.Dispose();
                    m_GetServicesUrlsRequest = null;
                }

                m_GetServicesUrlsRequest = new UnityWebRequest(string.Format(k_CdnConfigUrl, UnityConnect.instance.GetEnvironment()),
                                                               UnityWebRequest.kHttpVerbGET)
                {
                    downloadHandler = new DownloadHandlerBuffer()
                };
                m_GetServicesUrlsRequest.suppressErrorsToConsole = true;
                var operation = m_GetServicesUrlsRequest.SendWebRequest();
                operation.completed += asyncOperation =>
                {
                    try
                    {
                        if (ServicesUtils.IsUnityWebRequestReadyForJsonExtract(m_GetServicesUrlsRequest))
                        {
                            LoadJsonConfiguration(m_GetServicesUrlsRequest.downloadHandler.text);
                            BuildPaths();
                        }
                    }
                    catch (Exception)
                    {
                        //We fallback to hardcoded config
                        BuildPaths();
                    }
                    finally
                    {
                        m_GetServicesUrlsRequest?.Dispose();
                        m_GetServicesUrlsRequest = null;
                    }
                };
            }
            catch (Exception)
            {
                //We fallback to hardcoded config
                BuildPaths();
            }
        }
            protected void LoadTemplateIntoScrollContainer(string templatePath)
            {
                var generalTemplate = EditorGUIUtility.Load(templatePath) as VisualTreeAsset;
                var rootElement     = provider.rootVisualElement;

                if (rootElement != null)
                {
                    var scrollContainer = provider.rootVisualElement.Q(className: k_ScrollContainerClass);
                    scrollContainer.Clear();
                    scrollContainer.Add(generalTemplate.CloneTree().contentContainer);
                    ServicesUtils.TranslateStringsInTree(provider.rootVisualElement);
                }
            }
Пример #5
0
            protected void LoadScrollContainer()
            {
                var rootElement = provider.rootVisualElement;

                if (rootElement != null)
                {
                    var scrollContainer = provider.rootVisualElement.Q(className: k_ScrollContainerClass);
                    scrollContainer.Clear();
                    ServicesUtils.TranslateStringsInTree(provider.rootVisualElement);

                    provider.UpdateServiceToggleAndDashboardLink(provider.serviceInstance.IsServiceEnabled());
                }
            }
Пример #6
0
            void GetProjectInfoRequestOnCompleted(AsyncOperation obj)
            {
                if (m_Provider.m_GetProjectRequest == null)
                {
                    //If we lost our request reference, we can't risk doing anything.
                    return;
                }

                try
                {
                    if (ServicesUtils.IsUnityWebRequestReadyForJsonExtract(m_Provider.m_GetProjectRequest))
                    {
                        try
                        {
                            var jsonParser = new JSONParser(m_Provider.m_GetProjectRequest.downloadHandler.text);
                            var json       = jsonParser.Parse();
                            if (json.AsDict()[k_JsonNodeNameDisabled].AsBool())
                            {
                                NotificationManager.instance.Publish(
                                    Notification.Topic.BuildService,
                                    Notification.Severity.Error,
                                    L10n.Tr(k_MessageProjectStateMismatch));
                            }
                            else
                            {
                                var linksDict = json.AsDict()[k_JsonNodeNameLinks].AsDict();
                                m_CloudBuildApiOrgProjectUrl             = ServicesConfiguration.instance.GetCloudBuildApiUrl() + linksDict[k_JsonNodeNameSelf].AsDict()[k_JsonNodeNameHref].AsString();
                                m_CloudBuildApiOrgProjectBillingPlanUrl  = m_CloudBuildApiOrgProjectUrl + k_UrlSuffixBillingPlan;
                                m_CloudBuildApiOrgProjectBuildTargetsUrl = ServicesConfiguration.instance.GetCloudBuildApiUrl() + linksDict[k_JsonNodeNameListBuildTargets].AsDict()[k_JsonNodeNameHref].AsString();
                                m_CloudBuildApiOrgLatestBuilds           = ServicesConfiguration.instance.GetCloudBuildApiUrl() + linksDict[k_JsonNodeNameLatestBuilds].AsDict()[k_JsonNodeNameHref].AsString();
                                m_CloudBuildApiOrgLatestBuilds           = m_CloudBuildApiOrgLatestBuilds.Remove(m_CloudBuildApiOrgLatestBuilds.Length - 1, 1) + k_NumberOfBuildsToQuery;

                                GetProjectBillingPlan();
                            }
                        }
                        catch (Exception ex)
                        {
                            NotificationManager.instance.Publish(
                                Notification.Topic.BuildService,
                                Notification.Severity.Error,
                                L10n.Tr(k_MessageErrorForProjectData));
                            Debug.LogException(ex);
                        }
                    }
                }
                finally
                {
                    m_Provider.m_GetProjectRequest.Dispose();
                    m_Provider.m_GetProjectRequest = null;
                }
            }
Пример #7
0
            public override void EnterState()
            {
                var generalTemplate = EditorGUIUtility.Load(k_CollaborateDisabledUxmlPath) as VisualTreeAsset;
                var scrollContainer = provider.rootVisualElement.Q(null, k_ServiceScrollContainerClassName);

                scrollContainer.Clear();
                if (generalTemplate != null)
                {
                    var newVisual = generalTemplate.CloneTree().contentContainer;
                    ServicesUtils.TranslateStringsInTree(newVisual);
                    scrollContainer.Add(newVisual);
                }

                provider.HandlePermissionRestrictedControls();
            }
Пример #8
0
        public void SubmitGooglePlayKey(string submittedKey, Action <AsyncOperation> onSubmit, string authSignature)
        {
            var payload       = "{\"" + k_GoogleKeyJsonLabel + "\": \"" + submittedKey + "\"}";
            var uploadHandler = new UploadHandlerRaw(Encoding.UTF8.GetBytes(payload));
            var request       = new UnityWebRequest(GetGoogleKeyResource() + k_GoogleKeyPostSuffix,
                                                    UnityWebRequest.kHttpVerbPOST)
            {
                uploadHandler = uploadHandler
            };

            var encodedAuthToken = ServicesUtils.Base64Encode((UnityConnect.instance.projectInfo.projectGUID + ":" + authSignature));

            request.SetRequestHeader("Authorization", $"Basic {encodedAuthToken}");
            request.SetRequestHeader("Content-Type", "application/json;charset=UTF-8");
            var operation = request.SendWebRequest();

            operation.completed += onSubmit;
        }
Пример #9
0
        protected override void ActivateAction(string searchContext)
        {
            // Must reset properties every time this is activated
            var mainTemplate = EditorGUIUtility.Load(k_CloudDiagCommonUxmlPath) as VisualTreeAsset;
            var newVisual    = mainTemplate.CloneTree().contentContainer;

            ServicesUtils.TranslateStringsInTree(newVisual);
            rootVisualElement.Add(newVisual);
            rootVisualElement.AddStyleSheetPath(ServicesUtils.StylesheetPath.servicesWindowCommon);
            rootVisualElement.AddStyleSheetPath(EditorGUIUtility.isProSkin ? ServicesUtils.StylesheetPath.servicesWindowDark : ServicesUtils.StylesheetPath.servicesWindowLight);
            rootVisualElement.AddStyleSheetPath(ServicesUtils.StylesheetPath.servicesCommon);
            rootVisualElement.AddStyleSheetPath(EditorGUIUtility.isProSkin ? ServicesUtils.StylesheetPath.servicesDark : ServicesUtils.StylesheetPath.servicesLight);

            // Setup the crash reporting UI
            SetupCrashDiag();
            // User Reporting is handled without specific states...
            SetupUserReport();

            // The Crash Reporting is done with the state machine
            // Make sure to reset the state machine
            m_CrashStateMachine.ClearCurrentState();

            // Make sure to activate the state machine to the current state...
            if (CrashService.instance.IsServiceEnabled())
            {
                m_CrashStateMachine.Initialize(m_EnabledState);
            }
            else
            {
                m_CrashStateMachine.Initialize(m_DisabledState);
            }

            // This is for the learn more button
            var learnMore = rootVisualElement.Q(k_LearnMoreLink);

            if (learnMore != null)
            {
                var clickable = new Clickable(() =>
                {
                    Application.OpenURL(ServicesConfiguration.instance.GetUnityCloudDiagnosticInfoUrl());
                });
                learnMore.AddManipulator(clickable);
            }
        }
            public override void EnterState()
            {
                LoadTemplateIntoScrollContainer(k_TemplatePath);

                m_ImportIapBlock  = provider.rootVisualElement.Q(k_ImportIapBlock);
                m_IapOptionsBlock = provider.rootVisualElement.Q(k_IapOptionsBlock);

                SetupWelcomeIapBlock();
                SetupImportIapBlock();
                SetupIapOptionsBlock();
                var scrollContainer = provider.rootVisualElement.Q(className: k_ScrollContainerClass);

                scrollContainer.Add(ServicesUtils.SetupSupportedPlatformsBlock(GetSupportedPlatforms()));
                provider.HandlePermissionRestrictedControls();

                // Prepare the package section and update the package information
                PreparePackageSection(provider.rootVisualElement);
                UpdatePackageInformation();
            }
Пример #11
0
        public void ClearValidationData(Action <AsyncOperation> onClear, string authSignature, out UnityWebRequest request)
        {
            var payload       = "{\"event\": \"" + k_JsonValueBasic + "\"}";
            var uploadHandler = new UploadHandlerRaw(Encoding.UTF8.GetBytes(payload));

            request = new UnityWebRequest(
                String.Format(AnalyticsConfiguration.instance.clearUrl, UnityConnect.instance.projectInfo.projectGUID),
                UnityWebRequest.kHttpVerbPOST)
            {
                uploadHandler = uploadHandler
            };

            var encodedAuthToken = ServicesUtils.Base64Encode((UnityConnect.instance.projectInfo.projectGUID + ":" + authSignature));

            request.SetRequestHeader("Authorization", $"Basic {encodedAuthToken}");
            request.SetRequestHeader("Content-Type", "application/json;charset=UTF-8");
            var operation = request.SendWebRequest();

            operation.completed += onClear;
        }
Пример #12
0
        protected override void ActivateAction(string searchContext)
        {
            // Must reset properties every time this is activated
            var mainTemplate = EditorGUIUtility.Load(k_AdsCommonUxmlPath) as VisualTreeAsset;
            var newVisual    = mainTemplate.CloneTree().contentContainer;

            ServicesUtils.TranslateStringsInTree(newVisual);
            rootVisualElement.Add(newVisual);

            // Make sure to activate the state machine to the current state...
            if (AdsService.instance.IsServiceEnabled())
            {
                m_StateMachine.Initialize(m_EnabledState);
            }
            else
            {
                m_StateMachine.Initialize(m_DisabledState);
            }

            // Register the events for enabling / disabling the service only once.
            RegisterEvent();

            // Moved the Go to dashboard link to the header title section.
            m_GoToDashboard = rootVisualElement.Q(k_GoToDashboardLinkName);
            if (m_GoToDashboard != null)
            {
                var clickable = new Clickable(() =>
                {
                    var adsDashboardUrl = ServicesConfiguration.instance.adsDashboardUrl;
                    EditorAnalytics.SendOpenDashboardForService(new OpenDashboardForService()
                    {
                        serviceName = AdsService.instance.name, url = adsDashboardUrl
                    });
                    Application.OpenURL(adsDashboardUrl);
                });
                m_GoToDashboard.AddManipulator(clickable);
            }

            m_MainServiceToggle = rootVisualElement.Q <Toggle>(className: k_ServiceToggleClassName);
            SetupServiceToggle(AdsService.instance);
        }
Пример #13
0
        void SetupCrashDiag()
        {
            var crashDiagContainer = rootVisualElement.Q(className: k_CloudDiagCrashContainerClassName);

            if (crashDiagContainer == null)
            {
                return;
            }

            var generalTemplate = EditorGUIUtility.Load(k_CloudDiagCrashCommonUxmlPath) as VisualTreeAsset;

            if (generalTemplate != null)
            {
                var newVisual = generalTemplate.CloneTree().contentContainer;
                ServicesUtils.TranslateStringsInTree(newVisual);
                crashDiagContainer.Clear();
                crashDiagContainer.Add(newVisual);
                crashDiagContainer.Add(ServicesUtils.SetupSupportedPlatformsBlock(ServicesUtils.GetCloudDiagCrashSupportedPlatforms()));

                m_CrashServiceGoToDashboard = rootVisualElement.Q(k_CloudDiagCrashGoToDashboardName);
                if (m_CrashServiceGoToDashboard != null)
                {
                    var clickable = new Clickable(() =>
                    {
                        var dashboardUrl = ServicesConfiguration.instance.cloudDiagCrashesDashboardUrl;
                        EditorAnalytics.SendOpenDashboardForService(new OpenDashboardForService()
                        {
                            serviceName = CrashService.instance.name, url = dashboardUrl
                        });
                        Application.OpenURL(dashboardUrl);
                    });
                    m_CrashServiceGoToDashboard.AddManipulator(clickable);
                }

                m_CrashServiceToggle = rootVisualElement.Q <Toggle>(className: k_ServiceToggleClassName);
                SetupServiceToggle();
                RegisterEvent();
            }
        }
Пример #14
0
 void LoadConfigurationsFromCdn()
 {
     try
     {
         var getServicesUrlsRequest = new UnityWebRequest(string.Format(k_CdnConfigUrl, UnityConnect.instance.GetEnvironment()),
                                                          UnityWebRequest.kHttpVerbGET)
         {
             downloadHandler = new DownloadHandlerBuffer()
         };
         var operation = getServicesUrlsRequest.SendWebRequest();
         operation.completed += asyncOperation =>
         {
             try
             {
                 if (ServicesUtils.IsUnityWebRequestReadyForJsonExtract(getServicesUrlsRequest))
                 {
                     LoadJsonConfiguration(getServicesUrlsRequest.downloadHandler.text);
                     BuildPaths();
                 }
             }
             catch (Exception)
             {
                 //We fallback to local file config
                 BuildPaths();
             }
             finally
             {
                 getServicesUrlsRequest.Dispose();
             }
         };
     }
     catch (Exception)
     {
         //We fallback to local file config
         BuildPaths();
     }
 }
Пример #15
0
        void SetupCrashDiag()
        {
            var crashDiagContainer = rootVisualElement.Q(className: k_CloudDiagCrashContainerClassName);

            if (crashDiagContainer == null)
            {
                return;
            }

            var generalTemplate = EditorGUIUtility.Load(k_CloudDiagCrashCommonUxmlPath) as VisualTreeAsset;

            if (generalTemplate != null)
            {
                var newVisual = generalTemplate.CloneTree().contentContainer;
                ServicesUtils.TranslateStringsInTree(newVisual);
                crashDiagContainer.Clear();
                crashDiagContainer.Add(newVisual);
                crashDiagContainer.Add(ServicesUtils.SetupSupportedPlatformsBlock(ServicesUtils.GetCloudDiagCrashSupportedPlatforms()));

                m_CrashServiceGoToDashboard = rootVisualElement.Q(k_CloudDiagCrashGoToDashboardName);
                if (m_CrashServiceGoToDashboard != null)
                {
                    var clickable = new Clickable(() =>
                    {
                        ServicesConfiguration.instance.RequestBaseCloudDiagCrashesDashboardUrl(baseCloudDiagCrashesDashboardUrl =>
                        {
                            OpenDashboardOrgAndProjectIds(baseCloudDiagCrashesDashboardUrl);
                        });
                    });
                    m_CrashServiceGoToDashboard.AddManipulator(clickable);
                }

                m_CrashServiceToggle = rootVisualElement.Q <Toggle>(className: k_ServiceToggleClassName);
                SetupServiceToggle();
                RegisterEvent();
            }
        }
        void SetupService(VisualElement scrollContainer, VisualTreeAsset serviceTemplate, SingleService singleService)
        {
            scrollContainer.Add(serviceTemplate.CloneTree().contentContainer);
            var serviceIconAsset = EditorGUIUtility.Load(singleService.pathTowardIcon) as Texture2D;
            var serviceRoot      = scrollContainer[scrollContainer.childCount - 1];

            serviceRoot.name = singleService.name;

            var serviceTitle = serviceRoot.Q <TextElement>(className: k_ServiceTitleClassName);

            serviceTitle.text = singleService.title;
            serviceRoot.Q <TextElement>(className: k_ServiceDescriptionClassName).text = singleService.description;
            serviceRoot.Q(className: k_ServiceIconClassName).style.backgroundImage     = serviceIconAsset;

            Action openServiceSettingsLambda = () =>
            {
                ServicesUtils.OpenServicesProjectSettings(singleService);
            };

            m_ClickableByServiceName.Add(singleService.name, new Clickable(openServiceSettingsLambda));

            SetupServiceStatusLabel(serviceRoot, singleService);
            SetupPackageInstall(serviceRoot, singleService);
        }
Пример #17
0
        void SetupUserReport()
        {
            var userReportContainer = rootVisualElement.Q(className: k_CloudDiagUserReportContainerClassName);
            var generalTemplate     = EditorGUIUtility.Load(k_CloudDiagUserReportUxmlPath) as VisualTreeAsset;

            if ((generalTemplate != null) && (userReportContainer != null))
            {
                var newVisual = generalTemplate.CloneTree().contentContainer;
                ServicesUtils.TranslateStringsInTree(newVisual);
                userReportContainer.Clear();
                userReportContainer.Add(newVisual);
                userReportContainer.Add(ServicesUtils.SetupSupportedPlatformsBlock(ServicesUtils.GetCloudDiagUserReportSupportedPlatforms()));

                var downloadSdkButtonLink = rootVisualElement.Q(k_UserReportingDownloadSdk);
                if (downloadSdkButtonLink != null)
                {
                    var clickable = new Clickable(() =>
                    {
                        Application.OpenURL(ServicesConfiguration.instance.GetUnityCloudDiagnosticUserReportingSdkUrl());
                    });
                    downloadSdkButtonLink.AddManipulator(clickable);
                }
            }
        }
Пример #18
0
        /// <summary>
        /// To attach a project an existing project, we must collect all orgs the current user is a member of.
        /// In addition the current user may be a guest of a specific project, in which case we must also look at
        /// all projects to find organizations.
        /// </summary>
        /// <param name="organizationField"></param>
        /// <param name="projectIdField"></param>
        void LoadReuseOrganizationField(PopupField <string> organizationField, PopupField <string> projectIdField = null)
        {
            ServicesConfiguration.instance.RequestCurrentUserApiUrl(currentUserApiUrl =>
            {
                var getOrganizationsRequest = new UnityWebRequest(currentUserApiUrl + "?include=orgs,projects",
                                                                  UnityWebRequest.kHttpVerbGET)
                {
                    downloadHandler = new DownloadHandlerBuffer()
                };
                getOrganizationsRequest.suppressErrorsToConsole = true;
                getOrganizationsRequest.SetRequestHeader("AUTHORIZATION", $"Bearer {UnityConnect.instance.GetUserInfo().accessToken}");
                var operation        = getOrganizationsRequest.SendWebRequest();
                operation.completed += op =>
                {
                    try
                    {
                        if (ServicesUtils.IsUnityWebRequestReadyForJsonExtract(getOrganizationsRequest))
                        {
                            var jsonParser = new JSONParser(getOrganizationsRequest.downloadHandler.text);
                            var json       = jsonParser.Parse();
                            try
                            {
                                m_OrgIdByName.Clear();
                                var sortedOrganizationNames = new List <string>();
                                foreach (var rawOrg in json.AsDict()[k_JsonOrgsNodeName].AsList())
                                {
                                    var org = rawOrg.AsDict();
                                    if (k_AnyRoleFilter.Contains(org[k_JsonRoleNodeName].AsString()))
                                    {
                                        sortedOrganizationNames.Add(org[k_JsonNameNodeName].AsString());
                                        m_OrgIdByName.Add(org[k_JsonNameNodeName].AsString(), org[k_JsonIdNodeName].AsString());
                                    }
                                }

                                foreach (var rawProject in json.AsDict()[k_JsonProjectsNodeName].AsList())
                                {
                                    var project = rawProject.AsDict();
                                    if (!project[k_JsonArchivedNodeName].AsBool() &&
                                        !sortedOrganizationNames.Contains(project[k_JsonOrgNameNodeName].AsString()))
                                    {
                                        sortedOrganizationNames.Add(project[k_JsonOrgNameNodeName].AsString());
                                        m_OrgIdByName.Add(project[k_JsonOrgNameNodeName].AsString(), project[k_JsonOrgIdNodeName].AsString());
                                    }
                                }

                                sortedOrganizationNames.Sort();
                                var popUpChoices = new List <string> {
                                    L10n.Tr(k_SelectOrganizationText)
                                };
                                organizationField.SetEnabled(true);
                                popUpChoices.AddRange(sortedOrganizationNames);
                                organizationField.choices = popUpChoices;
                                organizationField.SetValueWithoutNotify(organizationField.choices[0]);
                                if (projectIdField != null)
                                {
                                    projectIdField.choices = new List <string> {
                                        L10n.Tr(k_SelectProjectText)
                                    };
                                    projectIdField.SetValueWithoutNotify(L10n.Tr(k_SelectProjectText));
                                    projectIdField.SetEnabled(false);
                                }
                            }
                            catch (Exception ex)
                            {
                                if (exceptionCallback != null)
                                {
                                    exceptionCallback.Invoke(ex);
                                }
                                else
                                {
                                    //If there is no exception callback, we have to at least log it
                                    Debug.LogException(ex);
                                }
                            }
                        }
                        else
                        {
                            var ex = new UnityConnectWebRequestException(L10n.Tr(k_CouldNotObtainOrganizationsMessage))
                            {
                                error           = getOrganizationsRequest.error,
                                method          = getOrganizationsRequest.method,
                                timeout         = getOrganizationsRequest.timeout,
                                url             = getOrganizationsRequest.url,
                                responseHeaders = getOrganizationsRequest.GetResponseHeaders(),
                                responseCode    = getOrganizationsRequest.responseCode,
                                isHttpError     = (getOrganizationsRequest.result == UnityWebRequest.Result.ProtocolError),
                                isNetworkError  = (getOrganizationsRequest.result == UnityWebRequest.Result.ConnectionError),
                            };
                            if (exceptionCallback != null)
                            {
                                exceptionCallback.Invoke(ex);
                            }
                            else
                            {
                                //If there is no exception callback, we have to at least log it
                                Debug.LogException(ex);
                            }
                        }
                    }
                    finally
                    {
                        getOrganizationsRequest.Dispose();
                    }
                };
            });
        }
Пример #19
0
        void LoadProjectField(string organizationName, PopupField <string> projectIdField)
        {
            ServicesConfiguration.instance.RequestOrganizationProjectsApiUrl(m_OrgIdByName[organizationName], organizationProjectsApiUrl =>
            {
                var getProjectsRequest = new UnityWebRequest(organizationProjectsApiUrl,
                                                             UnityWebRequest.kHttpVerbGET)
                {
                    downloadHandler = new DownloadHandlerBuffer()
                };
                getProjectsRequest.suppressErrorsToConsole = true;
                getProjectsRequest.SetRequestHeader("AUTHORIZATION", $"Bearer {UnityConnect.instance.GetUserInfo().accessToken}");
                var operation        = getProjectsRequest.SendWebRequest();
                operation.completed += op =>
                {
                    try
                    {
                        if (ServicesUtils.IsUnityWebRequestReadyForJsonExtract(getProjectsRequest))
                        {
                            var jsonParser = new JSONParser(getProjectsRequest.downloadHandler.text);
                            var json       = jsonParser.Parse();
                            try
                            {
                                m_ProjectInfoByName = new Dictionary <string, ProjectInfoData>();

                                var jsonProjects = json.AsDict()[k_JsonProjectsNodeName].AsList();
                                foreach (var jsonProject in jsonProjects)
                                {
                                    if (!jsonProject.AsDict()[k_JsonArchivedNodeName].AsBool())
                                    {
                                        var projectInfo = ExtractProjectInfoFromJson(jsonProject);
                                        m_ProjectInfoByName.Add(projectInfo.name, projectInfo);
                                    }
                                }

                                var projectNames = new List <string> {
                                    L10n.Tr(k_SelectProjectText)
                                };
                                var sortedProjectNames = new List <string>(m_ProjectInfoByName.Keys);
                                sortedProjectNames.Sort();
                                projectNames.AddRange(sortedProjectNames);
                                projectIdField.choices = projectNames;
                                projectIdField.SetEnabled(true);
                            }
                            catch (Exception ex)
                            {
                                if (exceptionCallback != null)
                                {
                                    exceptionCallback.Invoke(ex);
                                }
                                else
                                {
                                    //If there is no exception callback, we have to at least log it
                                    Debug.LogException(ex);
                                }
                            }
                        }
                        else
                        {
                            var ex = new UnityConnectWebRequestException(L10n.Tr(k_CouldNotObtainProjectMessage))
                            {
                                error           = getProjectsRequest.error,
                                method          = getProjectsRequest.method,
                                timeout         = getProjectsRequest.timeout,
                                url             = getProjectsRequest.url,
                                responseHeaders = getProjectsRequest.GetResponseHeaders(),
                                responseCode    = getProjectsRequest.responseCode,
                                isHttpError     = (getProjectsRequest.result == UnityWebRequest.Result.ProtocolError),
                                isNetworkError  = (getProjectsRequest.result == UnityWebRequest.Result.ConnectionError),
                            };
                            if (exceptionCallback != null)
                            {
                                exceptionCallback.Invoke(ex);
                            }
                            else
                            {
                                //If there is no exception callback, we have to at least log it
                                Debug.LogException(ex);
                            }
                        }
                    }
                    finally
                    {
                        getProjectsRequest.Dispose();
                    }
                };
            });
        }
Пример #20
0
        void CreateOperationOnCompleted(AsyncOperation obj)
        {
            if (m_CurrentRequest == null)
            {
                //If we lost our m_CurrentRequest request reference, we can't risk doing anything.
                return;
            }

            if (ServicesUtils.IsUnityWebRequestReadyForJsonExtract(m_CurrentRequest))
            {
                var jsonParser = new JSONParser(m_CurrentRequest.downloadHandler.text);
                var json       = jsonParser.Parse();
                var abort      = false;
                try
                {
                    var projectInfo = ExtractProjectInfoFromJson(json);
                    try
                    {
                        ServicesRepository.DisableAllServices(shouldUpdateApiFlag: false);
                        //Only register before creation. Remove first in case it was already added.
                        //TODO: Review to avoid dependency on project refreshed
                        UnityConnect.instance.ProjectStateChanged -= OnProjectStateChangedAfterCreation;
                        UnityConnect.instance.ProjectStateChanged += OnProjectStateChangedAfterCreation;
                        BindProject(projectInfo);
                    }
                    catch (Exception ex)
                    {
                        if (exceptionCallback != null)
                        {
                            exceptionCallback.Invoke(ex);
                            abort = true;
                        }
                        else
                        {
                            //If there is no exception callback, we have to at least log it
                            Debug.LogException(ex);
                        }
                    }
                    if (!abort)
                    {
                        createButtonCallback?.Invoke(projectInfo);
                    }
                }
                finally
                {
                    m_CurrentRequest?.Dispose();
                    m_CurrentRequest = null;
                }
            }
            else if (m_CurrentRequest.responseCode == k_HttpStatusCodeUnprocessableEntity)
            {
                m_CurrentRequest?.Dispose();
                m_CurrentRequest = null;
                m_CreateIteration++;
                RequestCreateOperation();
            }
            else
            {
                try
                {
                    var ex = new UnityConnectWebRequestException(L10n.Tr(k_CouldNotCreateProjectMessage))
                    {
                        error           = m_CurrentRequest.error,
                        method          = m_CurrentRequest.method,
                        timeout         = m_CurrentRequest.timeout,
                        url             = m_CurrentRequest.url,
                        responseHeaders = m_CurrentRequest.GetResponseHeaders(),
                        responseCode    = m_CurrentRequest.responseCode,
                        isHttpError     = (m_CurrentRequest.result == UnityWebRequest.Result.ProtocolError),
                        isNetworkError  = (m_CurrentRequest.result == UnityWebRequest.Result.ConnectionError),
                    };
                    if (exceptionCallback != null)
                    {
                        exceptionCallback.Invoke(ex);
                    }
                    else
                    {
                        //If there is no exception callback, we have to at least log it
                        Debug.LogException(ex);
                    }
                }
                finally
                {
                    m_CurrentRequest?.Dispose();
                    m_CurrentRequest = null;
                }
            }
        }
Пример #21
0
            public override void EnterState()
            {
                //If we haven't received new bound info, fetch them
                var generalTemplate = EditorGUIUtility.Load(k_CollaborateEnabledUxmlPath) as VisualTreeAsset;
                var scrollContainer = provider.rootVisualElement.Q(null, k_ServiceScrollContainerClassName);
                var newVisual       = generalTemplate.CloneTree().contentContainer;

                ServicesUtils.TranslateStringsInTree(newVisual);
                scrollContainer.Clear();
                scrollContainer.Add(newVisual);

                m_CollabPublishSection = scrollContainer.Q(k_CollabPublishSection);
                m_CollabHistorySection = scrollContainer.Q(k_CollabHistorySection);
                // Don't show the Publish and History section by default
                if (m_CollabHistorySection != null)
                {
                    m_CollabHistorySection.style.display = DisplayStyle.None;
                }
                if (m_CollabPublishSection != null)
                {
                    m_CollabPublishSection.style.display = DisplayStyle.None;
                }

                var openHistory = provider.rootVisualElement.Q(k_OpenHistoryLink) as Button;

                if (openHistory != null)
                {
                    openHistory.clicked += () =>
                    {
                        if (Collab.ShowHistoryWindow != null)
                        {
                            Collab.ShowHistoryWindow();
                        }
                    };
                }

                Button openChangesLinkBtn = provider.rootVisualElement.Q(k_OpenChangesLink) as Button;

                if (openChangesLinkBtn != null)
                {
                    openChangesLinkBtn.clicked += () =>
                    {
                        if (Collab.ShowChangesWindow != null)
                        {
                            Collab.ShowChangesWindow();
                        }
                    };
                }

                var gotoWebDashboard = scrollContainer.Q(k_GoToWebDashboardLink);

                if (gotoWebDashboard != null)
                {
                    var clickable = new Clickable(() =>
                    {
                        ServicesConfiguration.instance.RequestBaseCloudUsageDashboardUrl(baseCloudUsageDashboardUrl =>
                        {
                            provider.OpenDashboardOrgAndProjectIds(baseCloudUsageDashboardUrl);
                        });
                    });
                    gotoWebDashboard.AddManipulator(clickable);
                }
                // Prepare the package section and update the package information
                PreparePackageSection(scrollContainer);
                UpdatePackageInformation();

                provider.HandlePermissionRestrictedControls();
            }
        void LoadWindow()
        {
            rootVisualElement.Clear();

            var mainTemplate = EditorGUIUtility.Load(k_ServicesWindowUxmlPath) as VisualTreeAsset;

            rootVisualElement.AddStyleSheetPath(ServicesUtils.StylesheetPath.servicesWindowCommon);
            rootVisualElement.AddStyleSheetPath(EditorGUIUtility.isProSkin ? ServicesUtils.StylesheetPath.servicesWindowDark : ServicesUtils.StylesheetPath.servicesWindowLight);

            mainTemplate.CloneTree(rootVisualElement, new Dictionary <string, VisualElement>(), null);
            notificationSubscriber = new UIElementsNotificationSubscriber(rootVisualElement);
            notificationSubscriber.Subscribe(
                Notification.Topic.AdsService,
                Notification.Topic.AnalyticsService,
                Notification.Topic.BuildService,
                Notification.Topic.CollabService,
                Notification.Topic.CoppaCompliance,
                Notification.Topic.CrashService,
                Notification.Topic.ProjectBind,
                Notification.Topic.PurchasingService
                );

            rootVisualElement.Q <Button>(k_ProjectSettingsBtnName).clicked += () =>
            {
                ServicesUtils.OpenServicesProjectSettings(GeneralProjectSettings.generalProjectSettingsPath, typeof(GeneralProjectSettings).Name);
            };

            var dashboardClickable = new Clickable(() =>
            {
                if (!ServicesConfiguration.instance.pathsReady)
                {
                    NotificationManager.instance.Publish(Notification.Topic.ProjectBind, Notification.Severity.Error, L10n.Tr(k_ConnectionFailedMessage));
                }
                else if (UnityConnect.instance.projectInfo.projectBound)
                {
                    EditorAnalytics.SendOpenDashboardForService(new ServicesProjectSettings.OpenDashboardForService()
                    {
                        serviceName    = k_WindowTitle,
                        url            = ServicesConfiguration.instance.baseDashboardUrl,
                        organizationId = UnityConnect.instance.projectInfo.organizationId,
                        projectId      = UnityConnect.instance.projectInfo.projectId
                    });
                    Application.OpenURL(ServicesConfiguration.instance.GetCurrentProjectDashboardUrl());
                }
                else
                {
                    NotificationManager.instance.Publish(Notification.Topic.ProjectBind, Notification.Severity.Warning, L10n.Tr(k_ProjectNotBoundMessage));
                    ServicesUtils.OpenServicesProjectSettings(GeneralProjectSettings.generalProjectSettingsPath, typeof(GeneralProjectSettings).Name);
                }
            });

            rootVisualElement.Q(k_DashboardLinkName).AddManipulator(dashboardClickable);

            m_SortedServices = new SortedList <string, SingleService>();
            bool needProjectListOfPackage = false;

            foreach (var service in ServicesRepository.GetServices())
            {
                m_SortedServices.Add(service.title, service);
                if (service.isPackage && service.packageId != null)
                {
                    needProjectListOfPackage = true;
                }
            }
            // Only launch the listing if a service really needs the packages list...
            m_PackageCollection = null;
            if (needProjectListOfPackage)
            {
                m_ListRequestOfPackage    = Client.List();
                EditorApplication.update += ListingCurrentPackageProgress;
            }
            else
            {
                FinalizeServiceSetup();
            }
        }