Ejemplo n.º 1
0
        // Refresh client data
        private static void SetApplicationData(WitConfiguration configuration, string serverToken, Action <string> onSetComplete)
        {
            // Already set in app server data
            string appID = GetAppID(configuration);

            if (!string.IsNullOrEmpty(appID))
            {
                string curToken = WitAuthUtility.GetAppServerToken(appID);
                if (string.Equals(curToken, serverToken))
                {
                    SetClientData(configuration, serverToken, onSetComplete);
                    return;
                }
            }
            // Perform a list app request to get app for token
            var listRequest = WitRequestFactory.ListAppsRequest(serverToken, 10000);

            PerformConfigRequest(configuration, listRequest, ApplyApplicationData, (error) =>
            {
                // Failed
                if (!string.IsNullOrEmpty(error))
                {
                    SetConfigServerTokenComplete(configuration, serverToken, error, onSetComplete);
                }
                // Find client token
                else
                {
                    SetClientData(configuration, serverToken, onSetComplete);
                }
            });
        }
Ejemplo n.º 2
0
 public void Initialize()
 {
     WitAuthUtility.InitEditorTokens();
     configuration = target as WitConfiguration;
     currentToken  = WitAuthUtility.GetAppServerToken(configuration);
     if (WitAuthUtility.IsServerTokenValid(currentToken) &&
         !string.IsNullOrEmpty(configuration?.clientAccessToken))
     {
         configuration?.UpdateData(() =>
         {
             EditorForegroundRunner.Run(() => EditorUtility.SetDirty(configuration));
         });
     }
 }
Ejemplo n.º 3
0
        private void RefreshAppData(string appId, string token = "")
        {
            var refreshToken = WitAuthUtility.GetAppServerToken(appId, token);

            if (string.IsNullOrEmpty(refreshToken) &&
                string.IsNullOrEmpty(appId) &&
                !string.IsNullOrEmpty(configuration?.application?.id))
            {
                refreshToken = WitAuthUtility.GetAppServerToken(configuration.application.id,
                                                                WitAuthUtility.ServerToken);
                appId = WitAuthUtility.GetAppId(refreshToken);
                if (string.IsNullOrEmpty(appId))
                {
                    UpdateTokenData(refreshToken, () =>
                    {
                        appId = WitAuthUtility.GetAppId(refreshToken);
                        if (appId == configuration.application.id)
                        {
                            configuration.FetchAppConfigFromServerToken(refreshToken, () =>
                            {
                                currentToken = refreshToken;
                                WitAuthUtility.SetAppServerToken(configuration.application.id, currentToken);
                                EditorUtility.SetDirty(configuration);
                                EditorForegroundRunner.Run(Repaint);
                                appConfigurationFoldout = false;
                            });
                        }
                    });
                    return;
                }

                if (appId == configuration.application.id)
                {
                    refreshToken = WitAuthUtility.ServerToken;
                }
            }

            if (currentToken != refreshToken)
            {
                currentToken = refreshToken;
            }

            configuration.FetchAppConfigFromServerToken(refreshToken, () =>
            {
                currentToken = refreshToken;
                EditorForegroundRunner.Run(Repaint);
                appConfigurationFoldout = false;
            });
        }
Ejemplo n.º 4
0
        private static void DoUpdateData(WitConfiguration configuration, Action onUpdateComplete)
        {
            EditorForegroundRunner.Run(() =>
            {
                if (!string.IsNullOrEmpty(
                        WitAuthUtility.GetAppServerToken(configuration.application.id)))
                {
                    var intentsRequest        = configuration.ListIntentsRequest();
                    intentsRequest.onResponse =
                        (r) => ListEntities(r, configuration, onUpdateComplete);

                    configuration.application?.UpdateData(intentsRequest.Request);
                }
            });
        }
Ejemplo n.º 5
0
        // Reload app data if needed
        private void ReloadAppData()
        {
            // Check for changes
            string checkName = "";
            string checkID   = "";

            if (configuration != null && configuration.application != null)
            {
                checkName = configuration.application.name;
                checkID   = configuration.application.id;
            }
            // Reset
            if (!string.Equals(_appName, checkName) || !string.Equals(_appID, checkID))
            {
                _appName     = checkName;
                _appID       = checkID;
                _serverToken = WitAuthUtility.GetAppServerToken(configuration);
            }
        }
Ejemplo n.º 6
0
        public void Initialize()
        {
            // Refresh configuration & auth tokens
            configuration = target as WitConfiguration;

            // Get app server token
            _serverToken = WitAuthUtility.GetAppServerToken(configuration);
            if (CanConfigurationRefresh(configuration) && WitConfigurationUtility.IsServerTokenValid(_serverToken))
            {
                // Get client token if needed
                _appID = WitConfigurationUtility.GetAppID(configuration);
                if (string.IsNullOrEmpty(_appID))
                {
                    configuration.SetServerToken(_serverToken);
                }
                // Refresh additional data
                else
                {
                    SafeRefresh();
                }
            }
        }