internal static void FormatTextValueAfterKeyUp(IInputBox control, System.Windows.Forms.Keys key) { switch (control.InputType) { case InputTypes.NationalCode: if (KeyIsDigit(key)) { if (control.Text.Length == 3 && control.SelectionStart == 3) { control.SetText(control.Text + "-"); control.SelectionStart = 4; } else if (control.Text.Length == 10 && control.Text.Where(t => t == '-').Count() == 1 && control.SelectionStart == 10) { control.SetText(control.Text + "-"); control.SelectionStart = 11; } else if (control.Text.Length == 9 && control.Text.Where(t => t == '-').Count() == 0 && control.SelectionStart == 9) { control.SetText(control.Text.Substring(0, 3) + "-" + control.Text.Substring(3, 6) + "-"); control.SelectionStart = 11; } } break; } }
/// <inheritdoc/> public override void UIRenameFile(RenameFileEventArgs args) { if (args == null) { return; } // prompt IInputBox input = Far.Api.CreateInputBox(); input.EmptyEnabled = true; input.Title = "Rename"; input.Prompt = "New name"; input.History = "Copy"; input.Text = args.File.Name; if (!input.Show() || input.Text == args.File.Name) { args.Result = JobResult.Ignore; return; } // set new name and post it args.Parameter = input.Text; args.PostName = input.Text; // base base.UIRenameFile(args); }
public static void DoUpdateTest(IInputBox inputBox, KeyCode holdKey = KeyCode.None) { if (holdKey != KeyCode.None && !Input.GetKey(holdKey)) { return; } if (Input.GetKeyDown(KeyCode.Q)) { inputBox.Placeholder = $"Placeholder {Random.Range(0, 1000)}"; } if (Input.GetKeyDown(KeyCode.W)) { if (inputBox.CharacterLimit > 0) { inputBox.CharacterLimit = 0; } else { inputBox.CharacterLimit = 10; } } if (Input.GetKeyDown(KeyCode.E)) { inputBox.SelectionColor = new Color(Random.Range(0.25f, 0.75f), Random.Range(0.25f, 0.75f), Random.Range(0.25f, 0.75f)); } if (Input.GetKeyDown(KeyCode.R)) { inputBox.LineType += 1; if (inputBox.LineType > InputField.LineType.MultiLineNewline) { inputBox.LineType = 0; } } if (Input.GetKeyDown(KeyCode.T)) { inputBox.InputType += 1; if (inputBox.InputType > InputField.InputType.Password) { inputBox.InputType = 0; } } if (Input.GetKeyDown(KeyCode.Y)) { inputBox.KeyboardType += 1; if (inputBox.KeyboardType > TouchScreenKeyboardType.Search) { inputBox.KeyboardType = 0; } } if (Input.GetKeyDown(KeyCode.U)) { inputBox.ValidationType += 1; if (inputBox.ValidationType > InputField.CharacterValidation.EmailAddress) { inputBox.ValidationType = 0; } } }
private void UsersListView_CellContentClick(object sender, DataGridViewCellEventArgs e) { var senderGrid = (DataGridView)sender; if (senderGrid.Columns[e.ColumnIndex].Index == 2 && e.RowIndex >= 0) { string message = IInputBox.Show("Сообщение", "Введите ваше сообщение для " + UsersListView.Rows[e.RowIndex].Cells[1].Value); if (!string.IsNullOrEmpty(message)) { Program.SendMessage((int)UsersListView.Rows[e.RowIndex].Cells[0].Value, message); } } }
public LogFileViewModel(IInputBox inputBox) { InputBox = inputBox; FileStoreLocations = FileStorageLocations.Create(); OpenFileCommand = new DelegateCommand <FileInfo>(new Action <FileInfo>(fi => { FileText = DirectoryAccess.GetFileContent(fi.FullName); this.OnDisplayPopupWindow(FileText); OnPropertyChanged("FileText"); })); }
public static void Show(IList <IModuleEditor> editors, string helpTopic) { if (editors == null) { return; } IMenu menu = Far.Api.CreateMenu(); menu.AutoAssignHotkeys = true; menu.HelpTopic = helpTopic; menu.Title = Res.ModuleEditors; foreach (IModuleEditor it in editors) { menu.Add(Utility.FormatConfigMenu(it)).Data = it; } while (menu.Show()) { FarItem mi = menu.Items[menu.Selected]; IModuleEditor editor = (IModuleEditor)mi.Data; IInputBox ib = Far.Api.CreateInputBox(); ib.EmptyEnabled = true; ib.HelpTopic = helpTopic; ib.History = "Masks"; ib.Prompt = "Mask"; ib.Text = editor.Mask; ib.Title = editor.Name; if (!ib.Show()) { continue; } var mask = ConfigTool.ValidateMask(ib.Text); if (mask == null) { continue; } // set editor.Mask = mask; editor.Manager.SaveSettings(); } }
public static void Show(IList <IModuleManager> managers, string helpTopic) { if (managers == null) { return; } IMenu menu = Far.Api.CreateMenu(); menu.Title = "Module UI culture"; menu.HelpTopic = helpTopic; menu.AutoAssignHotkeys = true; int width = 0; { foreach (IModuleManager it in managers) { if (width < it.ModuleName.Length) { width = it.ModuleName.Length; } } } for (; ;) { menu.Items.Clear(); { foreach (IModuleManager it in managers) { menu.Add(string.Format(null, "{0} : {1}", it.ModuleName.PadRight(width), it.StoredUICulture)).Data = it; } } if (!menu.Show()) { return; } IModuleManager manager = (IModuleManager)menu.SelectedData; // show the input box IInputBox ib = Far.Api.CreateInputBox(); ib.Title = manager.ModuleName; ib.Prompt = "Culture name (empty = the Far culture)"; ib.Text = manager.StoredUICulture; ib.History = "Culture"; ib.HelpTopic = helpTopic; ib.EmptyEnabled = true; if (!ib.Show()) { continue; } // set the culture (even the same, to refresh) string cultureName = ib.Text.Trim(); CultureInfo ci; try { // get the culture by name, it may throw ci = CultureInfo.GetCultureInfo(cultureName); // save the name from the culture, not from a user manager.StoredUICulture = ci.Name; manager.SaveSettings(); // use the current Far culture instead of invariant if (ci.Name.Length == 0) { ci = Far.Api.GetCurrentUICulture(true); } // update the module manager.CurrentUICulture = ci; } catch (ArgumentException) { Far.Api.Message("Unknown culture name."); } } }
public static void Show(IList <IModuleCommand> commands, string helpTopic) { if (commands == null) { return; } IMenu menu = Far.Api.CreateMenu(); menu.AutoAssignHotkeys = true; menu.HelpTopic = helpTopic; menu.Title = Res.ModuleCommands; for (; ;) { int widthName = 9; // Name int widthPref = 6; // Prefix foreach (IModuleCommand it in commands) { if (widthName < it.Name.Length) { widthName = it.Name.Length; } if (widthPref < it.Prefix.Length) { widthPref = it.Prefix.Length; } } string format = "{0,-" + widthPref + "} : {1,-" + widthName + "} : {2}"; menu.Items.Clear(); menu.Add(string.Format(null, format, "Prefix", "Name", "Address")).Disabled = true; foreach (IModuleCommand it in commands) { menu.Add(string.Format(null, format, it.Prefix, it.Name, it.Manager.ModuleName + "\\" + it.Id)).Data = it; } if (!menu.Show()) { return; } FarItem mi = menu.Items[menu.Selected]; IModuleCommand command = (IModuleCommand)mi.Data; IInputBox ib = Far.Api.CreateInputBox(); ib.EmptyEnabled = true; ib.HelpTopic = helpTopic; ib.Prompt = "Prefix"; ib.Text = command.Prefix; ib.Title = command.Name; string prefix = null; while (ib.Show()) { prefix = ib.Text.Trim(); if (prefix.IndexOf(' ') >= 0 || prefix.IndexOf(':') >= 0) { Far.Api.Message("Prefix must not contain ' ' or ':'."); prefix = null; continue; } break; } if (prefix == null) { continue; } // reset command.Prefix = prefix; command.Manager.SaveSettings(); } }
public static string FormatTextValueWithInputType(IInputBox control, string value) { switch (control.InputType) { case InputBoxValidationHelper.InputTypes.AllCharacters: return(value); case InputBoxValidationHelper.InputTypes.Number: long numberValue; if (!long.TryParse(value, out numberValue)) { return(""); } return(value); case InputBoxValidationHelper.InputTypes.DecimalNumber: decimal decimalNumberValue; if (!decimal.TryParse(value, out decimalNumberValue)) { return(""); } return(value); case InputBoxValidationHelper.InputTypes.ShortInt: short shortValue; if (!short.TryParse(value, out shortValue)) { return(""); } return(value); case InputBoxValidationHelper.InputTypes.Int: int intValue; if (!int.TryParse(value, out intValue)) { return(""); } return(value); case InputBoxValidationHelper.InputTypes.LongInt: long longValue; if (!long.TryParse(value, out longValue)) { return(""); } return(value); case InputBoxValidationHelper.InputTypes.Float: float floatValue; if (!float.TryParse(value, out floatValue)) { return(""); } return(value); case InputBoxValidationHelper.InputTypes.Double: double doubleValue; if (!double.TryParse(value, out doubleValue)) { return(""); } return(value); case InputBoxValidationHelper.InputTypes.Decimal: decimal decimalValue; if (!decimal.TryParse(value, out decimalValue)) { return(""); } return(value); case InputBoxValidationHelper.InputTypes.PersianText: if (value.Where(t => !InputBoxValidationHelper.IsPersianChar(t)).Count() > 0) { return(""); } return(value); case InputBoxValidationHelper.InputTypes.EnglishText: if (value.Where(t => !InputBoxValidationHelper.IsEnglishChar(t)).Count() > 0) { return(""); } return(value); case InputBoxValidationHelper.InputTypes.Mobile: return(GetMobile(value)); case InputBoxValidationHelper.InputTypes.NationalCode: return(GetNationalCode(value)); case InputBoxValidationHelper.InputTypes.Email: if (!value.Contains('@')) { return(""); } return(value); default: throw new Exception(); } }
public static bool CheckValidation(IInputBox control, out string errorText) { switch (control.InputType) { case InputBoxValidationHelper.InputTypes.AllCharacters: break; case InputBoxValidationHelper.InputTypes.LongInt: case InputBoxValidationHelper.InputTypes.Number: if (!(control.LongValue.HasValue) && (!(control.Text == "" && control.AllowEmptyText))) { errorText = "مقدار عددی به صورت صحیح وارد نشده است"; return(false); } break; case InputBoxValidationHelper.InputTypes.Decimal: case InputBoxValidationHelper.InputTypes.DecimalNumber: if (!(control.DecimalValue.HasValue) && (!(control.Text == "" && control.AllowEmptyText))) { errorText = "مقدار اعشاری به صورت صحیح وارد نشده است"; return(false); } break; case InputBoxValidationHelper.InputTypes.ShortInt: if (!(control.ShortValue.HasValue) && (!(control.Text == "" && control.AllowEmptyText))) { errorText = "مقدار عددی به صورت صحیح وارد نشده است"; return(false); } break; case InputBoxValidationHelper.InputTypes.Int: if (!(control.IntValue.HasValue) && (!(control.Text == "" && control.AllowEmptyText))) { errorText = "مقدار عددی به صورت صحیح وارد نشده است"; return(false); } break; case InputBoxValidationHelper.InputTypes.Float: if (!(control.FloatValue.HasValue) && (!(control.Text == "" && control.AllowEmptyText))) { errorText = "مقدار اعشاری به صورت صحیح وارد نشده است"; return(false); } break; case InputBoxValidationHelper.InputTypes.Double: if (!(control.DoubleValue.HasValue) && (!(control.Text == "" && control.AllowEmptyText))) { errorText = "مقدار اعشاری به صورت صحیح وارد نشده است"; return(false); } break; case InputBoxValidationHelper.InputTypes.PersianText: foreach (char ch in control.Text) { if (!IsPersianChar(ch)) { errorText = "فقط باید حروف فارسی وارد کنید"; return(false); } } break; case InputBoxValidationHelper.InputTypes.EnglishText: foreach (char ch in control.Text) { if (!IsEnglishChar(ch)) { errorText = "فقط باید حروف انگلیسی وارد کنید"; return(false); } } break; case InputBoxValidationHelper.InputTypes.Mobile: if (!IsMobile(control.Text) && (!(control.Text == "" && control.AllowEmptyText))) { errorText = "شماره موبایل به صورت صحیح وارد نشده است"; return(false); } break; case InputBoxValidationHelper.InputTypes.NationalCode: if (!IsNationalCode(control.Text) && (!(control.Text == "" && control.AllowEmptyText))) { errorText = "کد ملی به صورت صحیح وارد نشده است"; return(false); } break; case InputBoxValidationHelper.InputTypes.Email: if (!control.Text.Contains('@') || control.Text.EndsWith("@")) { errorText = "ایمیل به صورت صحیح وارد نشده است"; return(false); } break; default: throw new Exception(); } if (control.Text.Length < control.MinLength && (!(control.Text == "" && control.AllowEmptyText))) { errorText = (string.Format("حداقل طول متن باید {0} حرف باشد", control.MinLength)); return(false); } if (control.Text.Length > control.MaxLength) { errorText = (string.Format("حداکثر طول متن باید {0} حرف باشد", control.MaxLength)); return(false); } if (control.MinValue.HasValue && (!(control.Text == "" && control.AllowEmptyText))) { if (control.FloatValue.Value < control.MinValue.Value) { errorText = (string.Format("مقدار وارد شده نباید از {0} کوچکتر باشد", control.MinValue.Value)); return(false); } } if (control.MaxValue.HasValue && (!(control.Text == "" && control.AllowEmptyText))) { if (control.FloatValue.Value > control.MaxValue.Value) { errorText = (string.Format("مقدار وارد شده نباید از {0} بزرگتر باشد", control.MaxValue.Value)); return(false); } } errorText = null; return(true); }
public static bool CheckKeyPressed(char keyChar, IInputBox control, out string errorText) { if (control.IllegalCharacters.Contains(keyChar)) { errorText = ("حروف " + string.Join <char>(",", control.IllegalCharacters.ToArray()) + " مجاز نیستند"); return(false); } else { switch (control.InputType) { case InputBoxValidationHelper.InputTypes.AllCharacters: break; case InputBoxValidationHelper.InputTypes.Number: if (!char.IsControl(keyChar) && !char.IsDigit(keyChar) && keyChar != CultureInfo.CurrentCulture.NumberFormat.NegativeSign[0]) { errorText = ("فقط عدد وارد کنید"); return(false); } else if (keyChar == CultureInfo.CurrentCulture.NumberFormat.NegativeSign[0] && control.SelectionStart != 0) { errorText = ("عدد را به صورت صحیح وارد کنید"); return(false); } break; case InputBoxValidationHelper.InputTypes.DecimalNumber: if (keyChar == CultureInfo.CurrentCulture.NumberFormat.NumberDecimalSeparator[0] && control.Text.Contains(CultureInfo.CurrentCulture.NumberFormat.NumberDecimalSeparator[0])) { errorText = ("عدد اعشاری را به صورت صحیح وارد کنید"); return(false); } else if (keyChar == CultureInfo.CurrentCulture.NumberFormat.NegativeSign[0] && control.SelectionStart != 0) { errorText = ("عدد را به صورت صحیح وارد کنید"); return(false); } else if (!char.IsControl(keyChar) && !char.IsDigit(keyChar) && keyChar != CultureInfo.CurrentCulture.NumberFormat.NumberDecimalSeparator[0] && keyChar != CultureInfo.CurrentCulture.NumberFormat.NegativeSign[0]) { errorText = ("فقط عدد وارد کنید"); return(false); } break; case InputBoxValidationHelper.InputTypes.PersianText: if (!char.IsControl(keyChar) && !InputBoxValidationHelper.IsPersianChar(keyChar)) { errorText = ("فقط حروف فارسی وارد کنید"); return(false); } break; case InputBoxValidationHelper.InputTypes.EnglishText: if (!char.IsControl(keyChar) && !InputBoxValidationHelper.IsEnglishChar(keyChar)) { errorText = ("فقط حروف انگلیسی وارد کنید"); return(false); } break; case InputBoxValidationHelper.InputTypes.ShortInt: if (!char.IsControl(keyChar) && !char.IsDigit(keyChar) && keyChar != CultureInfo.CurrentCulture.NumberFormat.NegativeSign[0]) { errorText = ("فقط عدد وارد کنید"); return(false); } else if (keyChar == CultureInfo.CurrentCulture.NumberFormat.NegativeSign[0] && control.SelectionStart != 0) { errorText = ("عدد را به صورت صحیح وارد کنید"); return(false); } else if (char.IsDigit(keyChar) || keyChar == CultureInfo.CurrentCulture.NumberFormat.NegativeSign[0]) { string text = control.GetNewText(keyChar); if (text == "-") { text = "-0"; } short t; if (!short.TryParse(text.Replace(CultureInfo.CurrentCulture.NumberFormat.NumberGroupSeparator[0].ToString(), ""), out t)) { errorText = (string.Format("محدوده عدد باید بین {0} و {1} باشد", short.MinValue.ToString(), short.MaxValue.ToString())); return(false); } } break; case InputBoxValidationHelper.InputTypes.Int: if (!char.IsControl(keyChar) && !char.IsDigit(keyChar) && keyChar != CultureInfo.CurrentCulture.NumberFormat.NegativeSign[0]) { errorText = ("فقط عدد وارد کنید"); return(false); } else if (keyChar == CultureInfo.CurrentCulture.NumberFormat.NegativeSign[0] && control.SelectionStart != 0) { errorText = ("عدد را به صورت صحیح وارد کنید"); return(false); } else if (char.IsDigit(keyChar) || keyChar == CultureInfo.CurrentCulture.NumberFormat.NegativeSign[0]) { string text = control.GetNewText(keyChar); if (text == "-") { text = "-0"; } int t; if (!int.TryParse(text.Replace(CultureInfo.CurrentCulture.NumberFormat.NumberGroupSeparator[0].ToString(), ""), out t)) { errorText = (string.Format("محدوده عدد باید بین {0} و {1} باشد", int.MinValue.ToString(), int.MaxValue.ToString())); return(false); } } break; case InputBoxValidationHelper.InputTypes.LongInt: if (!char.IsControl(keyChar) && !char.IsDigit(keyChar) && keyChar != CultureInfo.CurrentCulture.NumberFormat.NegativeSign[0]) { errorText = ("فقط عدد وارد کنید"); return(false); } else if (keyChar == CultureInfo.CurrentCulture.NumberFormat.NegativeSign[0] && control.SelectionStart != 0) { errorText = ("عدد را به صورت صحیح وارد کنید"); return(false); } else if (char.IsDigit(keyChar) || keyChar == CultureInfo.CurrentCulture.NumberFormat.NegativeSign[0]) { string text = control.GetNewText(keyChar); if (text == "-") { text = "-0"; } long t; if (!long.TryParse(text.Replace(CultureInfo.CurrentCulture.NumberFormat.NumberGroupSeparator[0].ToString(), ""), out t)) { errorText = (string.Format("محدوده عدد باید بین {0} و {1} باشد", long.MinValue.ToString(), long.MaxValue.ToString())); return(false); } } break; case InputBoxValidationHelper.InputTypes.Float: if (keyChar == CultureInfo.CurrentCulture.NumberFormat.NumberDecimalSeparator[0] && control.Text.Contains(CultureInfo.CurrentCulture.NumberFormat.NumberDecimalSeparator[0]) && keyChar != CultureInfo.CurrentCulture.NumberFormat.NegativeSign[0]) { errorText = ("عدد اعشاری را به صورت صحیح وارد کنید"); return(false); } else if (keyChar == CultureInfo.CurrentCulture.NumberFormat.NegativeSign[0] && control.SelectionStart != 0) { errorText = ("عدد را به صورت صحیح وارد کنید"); return(false); } else if (!char.IsControl(keyChar) && !char.IsDigit(keyChar) && keyChar != CultureInfo.CurrentCulture.NumberFormat.NumberDecimalSeparator[0]) { errorText = ("فقط عدد وارد کنید"); return(false); } else if (char.IsDigit(keyChar) || keyChar == CultureInfo.CurrentCulture.NumberFormat.NegativeSign[0]) { string text = control.GetNewText(keyChar); if (text == "-") { text = "-0"; } float t; if (!float.TryParse(text.Replace(CultureInfo.CurrentCulture.NumberFormat.NumberGroupSeparator[0].ToString(), ""), out t)) { errorText = (string.Format("محدوده عدد باید بین {0} و {1} باشد", float.MinValue.ToString(), float.MaxValue.ToString())); return(false); } } break; case InputBoxValidationHelper.InputTypes.Double: if (keyChar == CultureInfo.CurrentCulture.NumberFormat.NumberDecimalSeparator[0] && control.Text.Contains(CultureInfo.CurrentCulture.NumberFormat.NumberDecimalSeparator[0]) && keyChar != CultureInfo.CurrentCulture.NumberFormat.NegativeSign[0]) { errorText = ("عدد اعشاری را به صورت صحیح وارد کنید"); return(false); } else if (keyChar == CultureInfo.CurrentCulture.NumberFormat.NegativeSign[0] && control.SelectionStart != 0) { errorText = ("عدد را به صورت صحیح وارد کنید"); return(false); } else if (!char.IsControl(keyChar) && !char.IsDigit(keyChar) && keyChar != CultureInfo.CurrentCulture.NumberFormat.NumberDecimalSeparator[0]) { errorText = ("فقط عدد وارد کنید"); return(false); } else if (char.IsDigit(keyChar) || keyChar == CultureInfo.CurrentCulture.NumberFormat.NegativeSign[0]) { string text = control.GetNewText(keyChar); if (text == "-") { text = "-0"; } double t; if (!double.TryParse(text.Replace(CultureInfo.CurrentCulture.NumberFormat.NumberGroupSeparator[0].ToString(), ""), out t)) { errorText = (string.Format("محدوده عدد باید بین {0} و {1} باشد", double.MinValue.ToString(), double.MaxValue.ToString())); return(false); } } break; case InputBoxValidationHelper.InputTypes.Decimal: if (keyChar == CultureInfo.CurrentCulture.NumberFormat.NumberDecimalSeparator[0] && control.Text.Contains(CultureInfo.CurrentCulture.NumberFormat.NumberDecimalSeparator[0]) && keyChar != CultureInfo.CurrentCulture.NumberFormat.NegativeSign[0]) { errorText = ("عدد اعشاری را به صورت صحیح وارد کنید"); return(false); } else if (keyChar == CultureInfo.CurrentCulture.NumberFormat.NegativeSign[0] && control.SelectionStart != 0) { errorText = ("عدد را به صورت صحیح وارد کنید"); return(false); } else if (!char.IsControl(keyChar) && !char.IsDigit(keyChar) && keyChar != CultureInfo.CurrentCulture.NumberFormat.NumberDecimalSeparator[0]) { errorText = ("فقط عدد وارد کنید"); return(false); } else if (char.IsDigit(keyChar) || keyChar == CultureInfo.CurrentCulture.NumberFormat.NegativeSign[0]) { string text = control.GetNewText(keyChar); if (text == "-") { text = "-0"; } decimal t; if (!decimal.TryParse(text.Replace(CultureInfo.CurrentCulture.NumberFormat.NumberGroupSeparator[0].ToString(), ""), out t)) { errorText = (string.Format("محدوده عدد باید بین {0} و {1} باشد", decimal.MinValue.ToString(), decimal.MaxValue.ToString())); return(false); } } break; case InputBoxValidationHelper.InputTypes.Mobile: if (!char.IsControl(keyChar) && !char.IsDigit(keyChar)) { errorText = ("فقط عدد وارد کنید"); return(false); } else if (char.IsDigit(keyChar)) { if (control.SelectionStart == 0 && keyChar != '0') { errorText = ("شماره موبایل باید با 09 شروع شود"); return(false); } else if (control.SelectionStart == 1 && keyChar != '9') { errorText = ("شماره موبایل باید با 09 شروع شود"); return(false); } else { string text = control.GetNewText(keyChar); if (text.Length > 11) { errorText = ("شماره موبایل باید 11 رقمی باشد"); return(false); } } } break; case InputBoxValidationHelper.InputTypes.NationalCode: if (!char.IsControl(keyChar) && !char.IsDigit(keyChar)) { errorText = ("فقط عدد وارد کنید"); return(false); } else if (char.IsDigit(keyChar)) { //if (keyChar == '-' && (control.SelectionStart != 3 && control.SelectionStart != 10)) //{ // errorText = ("فقط عدد وارد کنید"); // return false; //} //else //{ string text = control.GetNewText(keyChar); if (text.Length > 12) { errorText = ("کد ملی نباید از 12 حرف بیشتر باشد"); return(false); } //} } break; case InputBoxValidationHelper.InputTypes.Email: break; default: throw new Exception(); } } errorText = null; return(true); }
private async void ProcessTmDbInfo() { try { IsBusy = true; BusyMessage = "Saving Config..."; SaveConfig(); if (string.IsNullOrWhiteSpace(Settings.Default.TMDbApiKey)) { // Prompt user for API key // Prompt from : https://github.com/ramer/IPrompt var prompt = IInputBox.Show("Enter your Movie Database API Key", "API Key Required"); if (string.IsNullOrWhiteSpace(prompt)) { IMessageBox.Show("The Movie Database Key is required for this service. Signup for the API key (free) at www.themoviedb.org"); return; } Settings.Default.TMDbApiKey = prompt; Settings.Default.Save(); } // API using nuget package -- code here; https://github.com/LordMike/TMDbLib var client = new TMDbClient(Settings.Default.TMDbApiKey); await client.AuthenticationRequestAutenticationTokenAsync(); // API permits only 40 calls per 10 seconds. using this nuget package to limit it to 35. var timeconstraint = TimeLimiter.GetFromMaxCountByInterval(35, TimeSpan.FromSeconds(10)); // loop over the folders and find the folders that dont have a metadata data file in them var foldersToProcess = _files.Where(x => !x.IsSelected && x.TheMovieDatabaseData == null).ToList(); for (var index = 0; index < foldersToProcess.Count; index++) { var f = foldersToProcess[index]; var folderName = f.LocalFolderPath.Substring(1, f.LocalFolderPath.Length - 1); if (folderName.Contains(DirectorySeperator)) { continue; } var name = f.SingleDirectoryName.GetNameBeforeYear(); if (name.EndsWith("-")) { name = name.Substring(0, name.Length - 1).Trim(); } if (Config.MovieOption) { // Currently dont support season info lookup. Just primary anme. if (f.SingleDirectoryName.ToLower().StartsWith("season")) { continue; } var year = f.SingleDirectoryName.GetYear(); if (year.HasValue) { BusyMessage = $"Searching For Movie [{index + 1} / {foldersToProcess.Count}] '{name}' ({year.Value})"; await timeconstraint.Perform(async() => { var result = await client.SearchMovieAsync(name, year: year.Value); if (result.TotalResults >= 1) { f.TheMovieDatabaseData = result.Results.OrderByDescending(x => x.VoteCount) .FirstOrDefault(); var json = JsonConvert.SerializeObject(f.TheMovieDatabaseData, Formatting.Indented); File.WriteAllText(f.TheMovieDatabaseFileName, json); } }); } } else if (Config.TvOption) { BusyMessage = $"Searching For Tv [{index + 1} / {foldersToProcess.Count}] '{name}')"; await timeconstraint.Perform(async() => { var result = await client.SearchTvShowAsync(name); if (result.TotalResults >= 1) { f.TheMovieDatabaseData = result.Results.OrderByDescending(x => x.VoteCount).FirstOrDefault(); var json = JsonConvert.SerializeObject(f.TheMovieDatabaseData, Formatting.Indented); File.WriteAllText(f.TheMovieDatabaseFileName, json); } }); } } } catch (TaskCanceledException t) { // Ignore, Task was canceled. } catch (Exception ex) { IMessageBox.Show(ex.Message); if (ex.Message.Contains("unauthorized")) { Settings.Default.TMDbApiKey = string.Empty; Settings.Default.Save(); } } finally { IsBusy = false; } }
private void btnIInputBox_Click(object sender, RoutedEventArgs e) { tblckResponse.Text = IInputBox.Show("Optional IInputBox text", "IInputBox Title", MessageBoxImage.Question, "default response").ToString(); }