private async Task <bool> TrainModel(bool showinlist) { for (int i = 0; i < model_num; i++) { await LUISGen.TrainModelRequest(LUISGen.appIds[i]); bool result = false; int times = 0; while (result) { result = await LUISGen.TrainModelStatus(LUISGen.appIds[i]); await Task.Delay(2000); if (times++ > 20) { return(false); } } await LUISGen.PublishModelRequest(LUISGen.appIds[i]); if (showinlist) { this.listView.Items.Add(new ModelListViewItem { modelName = LUISGen.appNames[i], appId = LUISGen.appIds[i] }); } this.progressbar.Value++; } return(true); }
public static bool ReadAccountStringsFromKey() { RegistryKey rk = Registry.CurrentUser; RegistryKey sk1 = rk.OpenSubKey(subregKey); if (sk1 == null) { return(false); } else { try { azure_storage_account = (string)sk1.GetValue(KeyName_account); azure_storgae_subkey = (string)sk1.GetValue(KeyName_subkey); azure_storage_table = (string)sk1.GetValue(KeyName_domain); LUIS_subkey = (string)sk1.GetValue(KeyName_LUIS_subkey); model_num = (int)sk1.GetValue(KeyName_modelcount); if (model_num > 0) { LUISGen.initModelVar(model_num) ; for (int i = 0; i < model_num; i++) { LUISGen.appIds[i] = (string)sk1.GetValue(string.Format(KeyName_model_key, i)); LUISGen.appNames[i] = (string)sk1.GetValue(string.Format(KeyName_model_name, i)); } } } catch (Exception e) { return(false); } return(true); } }
private async void start_Click(object sender, RoutedEventArgs e) { Button btn = (Button)sender; btn.IsEnabled = false; account.IsEnabled = false; pickfile.IsEnabled = false; bool training_only = false; if (model_num > 0) { string message = "You have models generated. Yes = Re-generate models, No = train/publish models only "; string caption = "Models Generated"; MessageBoxButton buttons = MessageBoxButton.YesNoCancel; MessageBoxResult result; result = MessageBox.Show(message, caption, buttons); if (result == MessageBoxResult.No) { this.progressbar.Maximum = model_num; this.progressbar.Value = 0; status.Content = "Training Models ..."; bool r = await TrainModel(false); if (r) { status.Content = "Model Training Completed"; } else { status.Content = "Model Training Failed"; } this.progressbar.Value = 0; training_only = true; } else if (result == MessageBoxResult.Yes) { training_only = false; } else //Cancel the op { training_only = true; } } if (!training_only) { LUISGen.progBar = this.progressbar; LUISGen.progBar.Value = 0; status.Content = "Creating Model ..."; model_num = await LUISGen.GenerateModels(m_dtCSV); this.listView.Items.Clear(); bool result = await TrainModel(true); if (result) { status.Content = "Model Creation Completed"; } else { status.Content = "Model Creation Failed"; } WriteAccountStringsToKey(); } btn.IsEnabled = true; copy.IsEnabled = true; account.IsEnabled = true; pickfile.IsEnabled = true; }