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)); }
// POST api/SyncData/Sync /// <summary> /// Syncs data from client to the Cloud Store and Vice Versa /// </summary> /// <param name="noteStore"></param> /// <returns></returns> public async Task <HttpResponseMessage> SyncData([FromBody] NoteStore noteStore) { try { List <Notes> notesForClient = SyncServer.Sync(noteStore); return(Request.CreateResponse(HttpStatusCode.OK, notesForClient)); } catch (Exception ex) { return(Request.CreateResponse(HttpStatusCode.BadRequest)); } }
private static async Task startCommonSync(string routeId) { Console.WriteLine("SyncIntentService sync started"); SyncServer syncSrv = new SyncServer(); bool syncResult; if (string.IsNullOrEmpty(routeId)) { //syncResult = await syncSrv.Sync(); } else { syncResult = await syncSrv.Sync(routeId, true); } Console.WriteLine("SyncIntentService sync ended"); }
private static async Task startSync(string routeId) { Console.WriteLine("SyncIntentService sync started"); SyncServer syncSrv = new SyncServer(); bool syncResult = await syncSrv.Sync(routeId, true); /*if (string.IsNullOrEmpty(routeId)) * { * syncResult = await syncSrv.Sync(); * } * else * { * syncResult = await syncSrv.Sync(routeId); * }*/ Console.WriteLine($"SyncIntentService sync ended, result:{syncResult}"); }
private async Task startSyncRouteAsync(string routeId) { SyncServer syncSrv = new SyncServer(); await syncSrv.Sync(routeId, false).ContinueWith(result => { MainThread.BeginInvokeOnMainThread(() => { if (!result.Result) { UserDialogs.Instance.Alert(CommonResource.Sync_Error, CommonResource.CommonMsg_Warning, "Ok"); } else { UserDialogs.Instance.Alert(CommonResource.ShareRoute_Published, "", "Ok"); } }); }, TaskContinuationOptions.OnlyOnRanToCompletion); }
private async Task startSyncRouteAsync(string routeId) { SyncServer syncSrv = new SyncServer(); await syncSrv.Sync(routeId, false).ContinueWith(result => { MainThread.BeginInvokeOnMainThread(() => { if (!result.Result) { UserDialogs.Instance.Alert("Ошибка синхронизации", "Внимание", "Ok"); } else { UserDialogs.Instance.Alert("Альбом успешно опубликован", "Всё отлично!", "Ok"); } }); }, TaskContinuationOptions.OnlyOnRanToCompletion); }
private async Task syncRouteAsync(string routeId) { IsNeedSyncRoute = false; IsRefreshing = true; SyncServer syncSrv = new SyncServer(); await syncSrv.Sync(_vroute.Id, false).ContinueWith(result => { MainThread.BeginInvokeOnMainThread(() => { if (!result.Result) { IsNeedSyncRoute = true; UserDialogs.Instance.Alert("Ошибка синхронизации", "Внимание", "Ok"); } else { updatePoints(); } IsRefreshing = false; }); }, TaskContinuationOptions.OnlyOnRanToCompletion); }