/// <summary> /// Download lang model /// </summary> /// <param name="sourceLangCode"></param> private async void DownloadModel(String sourceLangCode) { MLLocalTranslatorModel model = new MLLocalTranslatorModel.Factory(sourceLangCode).Create(); MLModelDownloadStrategy downloadStrategy = new MLModelDownloadStrategy.Factory() .NeedWifi() // It is recommended that you download the package in a Wi-Fi environment. .Create(); Task downloadModelTask = manager.DownloadModelAsync(model, downloadStrategy); try { await downloadModelTask; if (downloadModelTask.IsCompleted) { // Delete success. this.DisplaySuccess("Download success.", true); } else { // Delete failure. Log.Debug(Tag, " Download failure."); } } catch (Exception e) { // Operation failure. DisplayFailure(e); } }
/// <summary> /// Delete lang model /// </summary> /// <param name="langCode"></param> private async void DeleteModel(string langCode) { MLLocalTranslatorModel model = new MLLocalTranslatorModel.Factory(langCode).Create(); Task deleteModelTask = manager.DeleteModelAsync(model); try { await deleteModelTask; if (deleteModelTask.IsCompleted) { // Delete success. this.DisplaySuccess("Delete success.", true); } else { // Delete failure. Log.Debug(Tag, " Delete failure."); } } catch (Exception e) { // Operation failure. DisplayFailure(e); } }