Exemple #1
0
        public async Task <bool> SyncRouteIsNeedAsync(string routeId)
        {
            bool isNeed = false;

            TokenStoreService token     = new TokenStoreService();
            string            authToken = await token.GetAuthTokenAsync();

            if (!string.IsNullOrEmpty(authToken))
            {
                RoutesApiRequest api   = new RoutesApiRequest(_apiUrl, authToken);
                var routeServerVersion = await api.GetRouteVersion(routeId);

                if (routeServerVersion != null && api.LastHttpStatusCode == HttpStatusCode.OK)
                {
                    RouteManager routeManager = new RouteManager();
                    var          routeLocal   = routeManager.GetRouteById(routeId);
                    if (routeLocal != null)
                    {
                        isNeed = !routeLocal.ObjVerHash.Equals(routeServerVersion.ObjVerHash);
                    }
                    else
                    {
                        isNeed = true;
                    }
                }
                else
                {
                    isNeed = true;
                }
            }

            return(isNeed);
        }
        public async Task <string> TryGetGuestTokenAsync()
        {
            string token = string.Empty;

            ParameterManager par          = new ParameterManager();
            string           demoUsername = generateDemoUsername();

            par.Set("DemoUsername", demoUsername);

            AccountApiRequest apiRequest = new AccountApiRequest(_apiUrl);

            _username = demoUsername;
            _password = demoUsername;
            TokenResponse authData = await apiRequest.GetTokenAsync(_username, _password, true);

            if (!string.IsNullOrEmpty(authData?.Access_Token))
            {
                Analytics.TrackEvent("GetToken Demo", new Dictionary <string, string> {
                    { "Username", _username }
                });
                TokenStoreService tokenService = new TokenStoreService();
                bool setResultIsOk             = await tokenService.SetAuthDataAsync(authData.Access_Token, authData.UserId, string.Empty, string.Empty);

                if (setResultIsOk)
                {
                    token = authData.Access_Token;
                }
            }

            return(token);
        }
Exemple #3
0
        public async void StartDialog()
        {
            TokenStoreService tokenService  = new TokenStoreService();
            string            currentUserId = await tokenService.GetUserIdAsync();

            IsUserCanMakeLink = _vroute.CreatorId.Equals(currentUserId);
        }
Exemple #4
0
        async void RegisterCommandAsync()
        {
            if (!string.IsNullOrEmpty(_username) && !string.IsNullOrEmpty(_password) && !string.IsNullOrEmpty(_email))
            {
                if (_email.Contains("@") && _email.Contains("."))
                {
                    if (_password.Equals(_passwordConfirm))
                    {
                        using (UserDialogs.Instance.Loading(CommonResource.Login_RegistrationProcess, null, null, true, MaskType.Black))
                        {
                            AccountApiRequest apiRequest = new AccountApiRequest(_apiUrl);
                            Analytics.TrackEvent("Register user started", new Dictionary <string, string> {
                                { "Username", _username }
                            });
                            TokenResponse authData = await apiRequest.RegisterNewUserAsync(_username, _password, _email);

                            if (!string.IsNullOrEmpty(authData?.Access_Token))
                            {
                                Analytics.TrackEvent("Register new user done", new Dictionary <string, string> {
                                    { "Username", _username }
                                });
                                TokenStoreService tokenService = new TokenStoreService();
                                if (await tokenService.SetAuthDataAsync(authData.Access_Token, authData.UserId, _username, _email))
                                {
                                    ParameterManager par = new ParameterManager();
                                    par.Set("GuestMode", "0");
                                    Xamarin.Forms.MessagingCenter.Send <AuthResultMessage>(new AuthResultMessage()
                                    {
                                        IsAuthenticated = true, Username = _username
                                    }, string.Empty);
#if !DEBUG
                                    Xamarin.Forms.MessagingCenter.Send <SyncMessage>(new SyncMessage(), string.Empty);
#endif
                                    await Navigation.PopModalAsync();
                                }
                            }
                            else
                            {
                                Analytics.TrackEvent("Register new user error", new Dictionary <string, string> {
                                    { "Username", _username }
                                });
                                await Application.Current.MainPage.DisplayAlert(CommonResource.CommonMsg_Warning, CommonResource.Login_RegistrationError, "Ok");
                            }
                        }
                    }
                    else
                    {
                        await Application.Current.MainPage.DisplayAlert(CommonResource.CommonMsg_Warning, CommonResource.Login_EnterSamePasswords, "Ok");
                    }
                }
                else
                {
                    await Application.Current.MainPage.DisplayAlert(CommonResource.CommonMsg_Warning, CommonResource.Login_EnterCorrectEmail, "Ok");
                }
            }
            else
            {
                await Application.Current.MainPage.DisplayAlert(CommonResource.CommonMsg_Warning, CommonResource.Login_FillAllFields, "Ok");
            }
        }
        public async void StartDialog()
        {
            TokenStoreService tokenService = new TokenStoreService();

            _authToken = await tokenService.GetAuthTokenAsync();

            _userId = await tokenService.GetUserIdAsync();

            if (_isNewPoi)
            {
                PoiName         = _vpoint.Name;
                PoiDescription  = _vpoint.Description;
                _vpoi.Location  = new Xamarin.Forms.Maps.Position(_vpoint.Latitude, _vpoint.Longitude);
                _vpoi.CreatorId = _userId;
                if ((!string.IsNullOrEmpty(_vpoint.ImageMediaId) && _vpoint.ImageMediaType == MediaObjectTypeEnum.Image))
                {
                    PoiImage = ImagePathManager.GetMediaFilename(_vpoint.ImageMediaId, _vpoint.ImageMediaType, true);
                    string pathToImg = Path.Combine(ImagePathManager.GetPicturesDirectory(), _vpoi.ImgFilename);
                    if (File.Exists(pathToImg))
                    {
                        var bytes = File.ReadAllBytes(pathToImg);
                        _vpoi.ImgBase64 = Convert.ToBase64String(bytes);
                    }
                }
            }
        }
Exemple #6
0
        internal async Task <bool> UserCanShareAsync()
        {
            TokenStoreService tokenService = new TokenStoreService();
            string            userId       = await tokenService.GetUserIdAsync();

            return(userId.Equals(_vroute.CreatorId));
        }
        private async Task <string> getUserId()
        {
            TokenStoreService token   = new TokenStoreService();
            string            _userId = await token.GetUserIdAsync();

            return(_userId);
        }
        internal async Task <IEnumerable <ViewRoutePoint> > GetPointsForOverviewRouteAsync()
        {
            var resultPoints = new List <ViewRoutePoint>();
            IEnumerable <ViewRoute> routes;

            if (string.IsNullOrEmpty(_routeId))
            {
                TokenStoreService tokenService = new TokenStoreService();
                string            userId       = await tokenService.GetUserIdAsync();

                routes = _routeManager.GetRoutes(userId);
            }
            else
            {
                ViewRoute route      = _routeManager.GetViewRouteById(_routeId);
                var       routesList = new List <ViewRoute>();
                routesList.Add(route);
                routes = routesList;
            }
            foreach (var route in routes)
            {
                var points = _routePointManager.GetPointsByRouteId(route.RouteId);
                foreach (var point in points)
                {
                    resultPoints.Add(point);
                }
            }
            return(resultPoints);
        }
Exemple #9
0
        private async System.Threading.Tasks.Task <List <ViewUserInfo> > getUsersFromServerAsync(string textForSearch)
        {
            TokenStoreService token     = new TokenStoreService();
            string            authToken = await token.GetAuthTokenAsync();

            var usersApi = new UsersApiRequest(_apiUrl, authToken);

            return(await usersApi.SearchUsers(textForSearch));
        }
Exemple #10
0
        private async void refreshListPostsCommandAsync()
        {
            IsRefreshing = true;
            TokenStoreService token  = new TokenStoreService();
            string            userId = await token.GetUserIdAsync();

            Routes = _routeManager.GetPostsOtherCreators(userId);
            NoPostsWarningIsVisible = Routes.Count() == 0;
            IsRefreshing            = false;
        }
        private async Task <bool> recognizeSpeechToText()
        {
            SyncServer syncRoute = new SyncServer();
            bool       synced    = !await syncRoute.SyncRouteIsNeedAsync(_vpoint.RouteId);

            if (!synced)
            {
                synced = await syncRoute.Sync(_vpoint.RouteId, false);
            }
            if (synced)
            {
                TokenStoreService tokenService = new TokenStoreService();
                string            authToken    = await tokenService.GetAuthTokenAsync();

                var audios = GetUnprocessedAudios();
                int index  = 0;
                int count  = audios.Count();
                SpeechToTextHelper speechToText   = new SpeechToTextHelper(authToken);
                string             oldDescription = _vpoint.Description;
                var sb = new StringBuilder();
                foreach (var audio in audios)
                {
                    string textResult = await speechToText.TryRecognizeAudioAsync(audio.RoutePointMediaObjectId);

                    if (speechToText.LastHttpStatusCode == HttpStatusCode.OK)
                    {
                        sb.AppendLine(string.IsNullOrEmpty(textResult) ? "Текст не распознан" : textResult);
                        ViewRoutePointMediaObject vMediaObject = new ViewRoutePointMediaObject();
                        vMediaObject.Load(audio.RoutePointMediaObjectId);
                        vMediaObject.Processed         = true;
                        vMediaObject.ProcessResultText = textResult;
                        vMediaObject.Save();
                    }
                    index++;
                    double percent = (double)index * 100 / (double)count / 100;
                    Xamarin.Forms.MessagingCenter.Send <SyncProgressImageLoadingMessage>(new SyncProgressImageLoadingMessage()
                    {
                        RouteId = _vpoint.RouteId, ProgressValue = percent
                    }, string.Empty);
                }
                string newDescription = sb.ToString();
                if (!string.IsNullOrEmpty(newDescription) && !oldDescription.Equals(newDescription))
                {
                    _vpoint.Description += Environment.NewLine + newDescription;
                    _vpoint.Version++;
                    _vpoint.Save();
                    Device.BeginInvokeOnMainThread(() =>
                    {
                        PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("Description"));
                    });
                }
            }
            return(!string.IsNullOrEmpty(_vpoint.Description));
        }
        private static async Task SendRequest(string routeId)
        {
            TokenStoreService tokenService = new TokenStoreService();
            string            _authToken   = await tokenService.GetAuthTokenAsync();

            if (!string.IsNullOrEmpty(_authToken))
            {
                var routesApi = new RoutesApiRequest(_apiUrl, _authToken);
                await routesApi.AddUserViewAsync(routeId);
            }
        }
        private async Task <bool> initApi()
        {
            TokenStoreService token      = new TokenStoreService();
            string            _authToken = await token.GetAuthTokenAsync();

            if (!string.IsNullOrEmpty(_authToken))
            {
                _routePointMediaObjectsApi = new RoutePointMediaObjectRequest(_apiUrl, _authToken);
            }

            return(!(_routePointMediaObjectsApi == null));
        }
Exemple #14
0
        private async void deleteDataAllAlbumsCommandAsync()
        {
            bool answerYesIsNo = await Application.Current.MainPage.DisplayAlert(CommonResource.CommonMsg_Warning, CommonResource.Albums_AreYourSureToDeleteLoadedRoutes, CommonResource.CommonMsg_No, CommonResource.CommonMsg_Yes);

            if (!answerYesIsNo) //порядок кнопок - хардкод, и непонятно, почему именно такой
            {
                TokenStoreService token  = new TokenStoreService();
                string            userId = await token.GetUserIdAsync();

                var routesForDelete = _routeManager.GetPostsOtherCreators(userId);
                _routeManager.DeleteRoutesDataFromStorage(routesForDelete);
                refreshListPostsCommandAsync();
            }
        }
Exemple #15
0
 public MakeNewRouteAutoViewModel()
 {
     GenerateNewRouteCommand       = new Command(generateNewRouteCommand);
     StartIndexGalleryCommand      = new Command(startIndexGalleryCommand);
     ShowPeriodChartCommand        = new Command(showPeriodChartCommand);
     ShowMinimalPeriodCommand      = new Command(showMinimalPeriodCommand);
     ShowImagesPreviewPointCommand = new Command(showImagesPreviewPointCommand);
     SaveRouteCommand         = new Command(saveRouteCommand);
     ChangeMonthPeriodCommand = new Command(changeMonthPeriodCommand);
     TapLinkCommand           = new Command <string>(tapLinkCommand);
     CloseWarningCommand      = new Command(closeWarningCommand);
     OpenSettingsCommand      = new Command(openSettingsCommand);
     TokenStoreService tokenService = new TokenStoreService();
 }
        public async Task <bool> UpdateFromServerAsync()
        {
            TokenStoreService tokenService = new TokenStoreService();
            var token = await tokenService.GetAuthTokenAsync();

            UsersApiRequest userApi = new UsersApiRequest(DefaultUrls.ApiUrl, token);
            var             user    = await userApi.GetUserAsync(_userId);

            if (userApi.LastHttpStatusCode.Equals(HttpStatusCode.OK))
            {
                user.Save();
                Load(_userId);
                return(true);
            }
            return(false);
        }
        private async Task updateUserInfo()
        {
            TokenStoreService tokenService = new TokenStoreService();

            _currentUserId = await tokenService.GetUserIdAsync();

            _currentUserToken = await tokenService.GetAuthTokenAsync();

            Username = await tokenService.GetUsernameAsync();

            Email = await tokenService.GetEmailAsync();

            UserRole = await tokenService.GetRoleAsync();

            UserImgUrl = await tokenService.GetImgUrlAsync();
        }
Exemple #18
0
        async void TryLoginCommandAsync()
        {
            if (!string.IsNullOrEmpty(_username) && !string.IsNullOrEmpty(_password))
            {
                using (UserDialogs.Instance.Loading(CommonResource.Login_AuthorizationProcess, null, null, true, MaskType.Black))
                {
                    AccountApiRequest apiRequest = new AccountApiRequest(_apiUrl);
                    Analytics.TrackEvent("GetToken started", new Dictionary <string, string> {
                        { "Username", _username }
                    });
                    TokenResponse authData = await apiRequest.GetTokenAsync(_username, _password);

                    if (!string.IsNullOrEmpty(authData?.Access_Token))
                    {
                        Analytics.TrackEvent("GetToken done", new Dictionary <string, string> {
                            { "Username", _username }
                        });
                        TokenStoreService tokenService = new TokenStoreService();
                        if (await tokenService.SetAuthDataAsync(authData.Access_Token, authData.UserId, _username, authData.Email))
                        {
                            ParameterManager par = new ParameterManager();
                            par.Set("GuestMode", "0");
                            Xamarin.Forms.MessagingCenter.Send <AuthResultMessage>(new AuthResultMessage()
                            {
                                IsAuthenticated = true, Username = _username
                            }, string.Empty);
#if !DEBUG
                            Xamarin.Forms.MessagingCenter.Send <SyncMessage>(new SyncMessage(), string.Empty);
#endif
                            await Navigation.PopModalAsync();
                        }
                    }
                    else
                    {
                        Analytics.TrackEvent("GetToken error", new Dictionary <string, string> {
                            { "Username", _username }
                        });
                        await Application.Current.MainPage.DisplayAlert(CommonResource.CommonMsg_Warning, CommonResource.Login_IncorrectLoginOrPassword, "Ok");
                    }
                }
            }
            else
            {
                await Application.Current.MainPage.DisplayAlert(CommonResource.CommonMsg_Warning, CommonResource.Login_FillLoginAndPassword, "Ok");
            }
        }
Exemple #19
0
        /*private async void OnLoginCompleteAsync(OAuthUser user, string errorMsg)
         * {
         *  if (user != null)
         *  {
         *      var taskRun = Task.Run(async () =>
         *      {
         *          try
         *          {
         *              var result = await TryToLoginServerWithOAuth(user);
         *          }
         *          catch (Exception e)
         *          {
         *              HandleError.Process("OAuthLogin", "OnLoginComplete", e, false);
         *          }
         *      });
         *  }
         *  else
         *  {
         *      await Application.Current.MainPage.DisplayAlert(CommonResource.CommonMsg_Warning, CommonResource.Login_AuthError, "Ok");
         *  }
         * }*/

        private async Task <bool> TryToLoginServerWithOAuth(OAuthUser oauthUser)
        {
            Username = oauthUser.Name;
            AccountApiRequest apiRequest = new AccountApiRequest(_apiUrl);

            Analytics.TrackEvent("Login OAuth user started", new Dictionary <string, string> {
                { "Username", _username }
            });
            //ToDo: надо добавить на сервер передачу и получение imgurl и роли!
            TokenResponse authData = await apiRequest.LoginByOAuthAsync(oauthUser.Name, oauthUser.Email, DeviceCulture.CurrentCulture.Name, oauthUser.ImgUrl.ToString(), oauthUser.Id, string.Empty);

            if (!string.IsNullOrEmpty(authData?.Access_Token))
            {
                Analytics.TrackEvent("Login OAuth done", new Dictionary <string, string> {
                    { "Username", _username }
                });
                TokenStoreService tokenService = new TokenStoreService();
                if (await tokenService.SetAuthDataAsync(authData.Access_Token, authData.UserId, _username, authData.Email, oauthUser.ImgUrl.ToString()))
                {
                    ParameterManager par = new ParameterManager();
                    par.Set("GuestMode", "0");
                    Xamarin.Forms.MessagingCenter.Send <AuthResultMessage>(new AuthResultMessage()
                    {
                        IsAuthenticated = true, Username = oauthUser.Name
                    }, string.Empty);
#if !DEBUG
                    Xamarin.Forms.MessagingCenter.Send <SyncMessage>(new SyncMessage(), string.Empty);
#endif
                    return(true);
                }
            }
            else
            {
                Analytics.TrackEvent("Login OAuth error", new Dictionary <string, string> {
                    { "Username", _username }
                });
                MainThread.BeginInvokeOnMainThread(() =>
                {
                    UserDialogs.Instance.Alert(CommonResource.Login_AuthError, CommonResource.CommonMsg_Warning, "Ок");
                });
            }
            return(false);
        }
        private async void openRoutePointDialogAsync()
        {
            if (string.IsNullOrEmpty(_vroute.Name))
            {
                await App.Current.MainPage.DisplayAlert(CommonResource.CommonMsg_Warning, CommonResource.NewRoute_NeedToFillNameRoute, "Ok");
            }
            else
            {
                Analytics.TrackEvent("Route created", new Dictionary <string, string> {
                    { "Route", _vroute.Name }
                });
                TokenStoreService tokenService = new TokenStoreService();
                _vroute.CreatorId = await tokenService.GetUserIdAsync();

                if (_vroute.Save())
                {
                    //MessagingCenter.Send<PageNavigationMessage>(new PageNavigationMessage() { PageToOpen = MainPages.Private }, string.Empty);
                    await Navigation.PushAsync(new RouteCreatedPage(_vroute.Id));
                }
            }
        }
Exemple #21
0
        private async void updateUrlCommandAsync()
        {
            TokenStoreService token      = new TokenStoreService();
            string            _authToken = await token.GetAuthTokenAsync();

            _routesApi = new RoutesApiRequest(_apiUrl, _authToken);
            var shortLinkRouteId = await _routesApi.GetShortLinkId(_routeId);

            if (!string.IsNullOrEmpty(shortLinkRouteId))
            {
                MakeLinkIsVisible   = false;
                UrlPresentationText = $"{_goshUrl}/routetimeline/{_routeId}";
                CaptionText         = _accessByLink;
            }
            else
            {
                MakeLinkIsVisible   = true;
                UrlPresentationText = "";
                CaptionText         = _makeLink;
            }
        }
        private async Task updatePoiStatusAsync()
        {
            if (!_newPoint)
            {
                TokenStoreService tokenService = new TokenStoreService();
                string            authToken    = await tokenService.GetAuthTokenAsync();

                PoiApiRequest poiApi = new PoiApiRequest(authToken);
                var           wsPoi  = await poiApi.GetPoiByRoutePointIdAsync(_vpoint.Id);

                if (poiApi.LastHttpStatusCode == HttpStatusCode.OK)
                {
                    _vPoi = new ViewPoi(wsPoi);
                    _vPoi.Save();
                    IsPoiExists = true;
                }
            }
            else
            {
                IsPoiExists = false;
            }
        }
        private async Task <bool> tryParseAndGetTrackAsync(string filename, string routeId)
        {
            RouteTracking     trackResponse    = new RouteTracking();
            TokenStoreService tokenService     = new TokenStoreService();
            string            currentUserToken = await tokenService.GetAuthTokenAsync();

            TrackRouteRequest sendTrackRequest = new TrackRouteRequest(currentUserToken);
            bool sendResult = await sendTrackRequest.SendTrackFileAsync(filename, routeId);

            if (sendResult)
            {
                trackResponse = await sendTrackRequest.GetTrackPlacesAsync(routeId);

                if (trackResponse.Places.Length > 0)
                {
                    var viewTrackPlaces = sendTrackRequest.GetViewTrackPlaces(trackResponse.Places);
                    _trackFileManager.SaveTrack(routeId, viewTrackPlaces);
                }
            }


            return(sendResult && trackResponse.Places.Length > 0);
        }
Exemple #24
0
        private async System.Threading.Tasks.Task <Tuple <bool, string> > SyncRoute(string routeId, bool loadOnlyPreview)
        {
            string errorMsg   = string.Empty;
            bool   syncResult = false;

            TokenStoreService token     = new TokenStoreService();
            string            authToken = await token.GetAuthTokenAsync();

            if (!string.IsNullOrEmpty(authToken))
            {
                SyncRoutes syncRoutes = new SyncRoutes(authToken);
                syncResult = await syncRoutes.Sync(routeId, loadOnlyPreview);

                if (syncRoutes.AuthRequired)
                {
                    Xamarin.Forms.MessagingCenter.Send <UIAlertMessage>(new UIAlertMessage()
                    {
                        Title = "Error", Message = "Error syncing server. Try to open feed."
                    }, string.Empty);
                }
            }
            return(new Tuple <bool, string>(syncResult, errorMsg));
        }
Exemple #25
0
        private async Task makeLink()
        {
            TokenStoreService token      = new TokenStoreService();
            string            _authToken = await token.GetAuthTokenAsync();

            _routesApi = new RoutesApiRequest(_apiUrl, _authToken);
            var makeResult = await _routesApi.CreateShortLinkIdAsync(_routeId);

            if (makeResult)
            {
                updateUrlCommandAsync();
                MessagingCenter.Send <UIToastMessage>(new UIToastMessage()
                {
                    Delay = 3, Message = CommonResource.MakeRouteLink_PublicReferenceCreated
                }, string.Empty);
            }
            else
            {
                MessagingCenter.Send <UIToastMessage>(new UIToastMessage()
                {
                    Delay = 3, Message = CommonResource.MakeRouteLink_ErrorWhileCreatedReference
                }, string.Empty);
            }
        }