Пример #1
0
        public SimvaWindow(Rect aStartPos, GUIStyle aStyle,
                           params GUILayoutOption[] aOptions)
            : base(aStartPos, new GUIContent(TC.get("Simva.Title")), aStyle, aOptions)
        {
            ButtonContent = new GUIContent()
            {
                image = Resources.Load <Texture2D>("simva-icon"),
                text  = "Simva"
            };

            tabsManager = new TabsManager(this);
            simvaConf   = new SimvaConf();
            if (string.IsNullOrEmpty(simvaConf.Host))
            {
                Debug.LogWarning("No Simva Host!");
            }

            if (ProjectConfigData.existsKey("Simva.RefreshToken"))
            {
                Login();
            }

            if (linkStyle == null)
            {
                linkStyle           = new GUIStyle(GUI.skin.label);
                linkStyle.richText  = true;
                titleStyle          = new GUIStyle(GUI.skin.label);
                titleStyle.richText = true;
            }
        }
Пример #2
0
        private void Login()
        {
            SimvaConf.Local = new SimvaConf();
            var carga = new AsyncCompletionSource();

            Observable.FromCoroutine(() => LoadSimvaConf(SimvaConf.Local.LoadAsync(), carga)).Subscribe();

            isLogin = true;
            carga.Then(() =>
            {
                IAsyncOperation <SimvaApi <ITeachersApi> > loginCall = null;
                if (ProjectConfigData.existsKey("Simva.RefreshToken"))
                {
                    loginCall = SimvaApi <ITeachersApi> .Login(new AuthorizationInfo
                    {
                        ClientId     = "uadventure",
                        RefreshToken = ProjectConfigData.getProperty("Simva.RefreshToken")
                    });
                }
                else
                {
                    loginCall = SimvaApi <ITeachersApi> .Login(true);
                }

                loginCall.Then(simvaController =>
                {
                    this.simvaController = simvaController;
                    this.simvaConf       = simvaController.SimvaConf;
                    var apiClient        = ((TeachersApi)this.simvaController.Api).ApiClient;
                    apiClient.onAuthorizationInfoUpdate += auth =>
                    {
                        ProjectConfigData.setProperty("Simva.RefreshToken", auth.RefreshToken);
                    };
                    ProjectConfigData.setProperty("Simva.RefreshToken", apiClient.AuthorizationInfo.RefreshToken);
                    ProjectConfigData.storeToXML();
                })
                .Catch(error =>
                {
                    ProjectConfigData.setProperty("Simva.RefreshToken", null);
                    ProjectConfigData.storeToXML();
                    Controller.Instance.ShowErrorDialog("Simva.Login.Error.Title", "Simva.Login.Error.Message");
                })
                .Finally(() => isLogin = false);
            });
        }