public ActionTypePattern(NamePattern pattern, string keyword) { Pattern = pattern; Keyword = keyword; switch (pattern) { case NamePattern.StartWith: IsMatchFn = IsStartWithFn; GetActionGroupNameFn = GetStartWithActionGroupName; return; case NamePattern.EndWith: IsMatchFn = IsEndWithFn; GetActionGroupNameFn = GetEndWithActionGroupName; return; case NamePattern.Between: IsMatchFn = IsBetweenFn; GetActionGroupNameFn = GetBetweenActionGroupName; return; } IsMatchFn = IsContainFn; GetActionGroupNameFn = GetContainActionGroupName; }
public IEnumerable <IUser> Generate(string pattern, string domain, int count) { var boxes = new HashSet <string>(); var random = new Random(); for (var i = 1; i <= count; i++) { string fn, ln, mb; do { fn = _nameData.FirstNames[random.Next(_nameData.FirstNames.Length)]; ln = _nameData.LastNames[random.Next(_nameData.LastNames.Length)]; mb = new NamePattern(pattern).Format(fn, ln); } while (boxes.Contains(mb)); boxes.Add(mb); yield return(new User { FirstName = fn, LastName = ln, Mailbox = mb + "@" + domain }); } }
public static Option <MeshSet> TryCreate( FileInfo file, Paths paths, IEnumerable <FileInfo> meshes, ILogger logger) { var matcher = NamePattern.Match(file.Name); if (!matcher.Success || matcher.Groups[2].Value.ToLower() != "base") { return(None); } var key = matcher.Groups[1].Value; var meshSet = Try(new MeshSet(key, file, paths)); meshSet.ToEither().LeftAsEnumerable().Iter(e => { logger.LogError(e, "Failed to read mesh resource '{}'.", file.Path); }); var result = meshSet.ToOption(); result.Iter(m => meshes.Iter(m.TryAdd)); return(result); }
public void TryAdd(FileInfo file) { IEnumerable <Task> CreateTasks(FileInfo f) { if (f.Directory != File.Directory || f == File) { return(Lst <Task> .Empty); } var m = NamePattern.Match(f.Name); if (!m.Success || m.Groups[1].Value != Key) { return(Lst <Task> .Empty); } var key = m.Groups[2].Value; if (key.ToLower().StartsWith("morphs")) { Lst <string> shapes; using (var mesh = ResourceLoader.Load <ArrayMesh>(f.Path)) { shapes = mesh.GetBlendShapeNames().Freeze(); } string NormalizeName(string name) { const string prefix = "morphs_"; if (name.ToLower().StartsWith(prefix)) { return(name.Substring(prefix.Length)); } return(name); } return (from shape in shapes from surface in Surfaces select new BlendShapeTask(NormalizeName(shape), f, surface, shape, this)); } return(Surfaces.Map(s => new MorphedMeshTask(key, f, s, this)).Freeze()); } var newTasks = CreateTasks(file); _tasks = _tasks.Append(newTasks).Freeze(); }
/// <summary> /// Adds a new name for the arg. /// </summary> /// <param name="name">The name.</param> /// <param name="caseSensitive">Indicates whether the name is case-sensitive.</param> /// <returns>An instance to the same <see cref="Arg" />, to allow for a fluent syntax.</returns> public NamedObject AddName(string name, bool caseSensitive = false) { if (name is null) { throw new ArgumentNullException(nameof(name)); } if (!NamePattern.IsMatch(name)) { throw new ArgumentException(string.Format(Errors.Arg_Invalid_name, name), nameof(name)); } _names.Add(name, caseSensitive); return(this); }
public virtual void ProcessMessage(IProcessorMessage message) { if (message is UndoFileMessage) { UndoFileMessage msg = message as UndoFileMessage; DryRun = msg.DryRun; UndoFile = msg.UndoFile; } if (message is Message) { Pattern = new NamePattern((message as Message).Pattern); } }
public STFReader OpenSTF(string engFile) { try { string name = engFile; if (!NamePattern.StartsWith(".")) { int lp = name.LastIndexOf('.'); name = name.Substring(0, lp + 1); } name += NamePattern; return(new STFReader(name, false)); } catch { return(null); } }
/// <summary> /// Import exported file. Used by a fileWatcher. /// </summary> /// <param name="filePath"></param> private void ImportExportedAddIfPossible(string filePath) { var loadResult = ExtractExportedFileInExtractor(filePath); if (!loadResult.HasValue) { return; } bool alreadyExists = loadResult.Value; bool addedToLibrary = false; bool uniqueExtraction = _extractor.UniqueResults || (alreadyExists && _extractor.ValidResults); bool copyNameToClipboard = Properties.Settings.Default.copyNameToClipboardOnImportWhenAutoNameApplied && (Properties.Settings.Default.applyNamePatternOnAutoImportAlways || Properties.Settings.Default.applyNamePatternOnImportIfEmptyName || (!alreadyExists && Properties.Settings.Default.applyNamePatternOnAutoImportForNewCreatures) ); Species species = speciesSelector1.SelectedSpecies; Creature creature = null; if (uniqueExtraction && Properties.Settings.Default.OnAutoImportAddToLibrary) { creature = AddCreatureToCollection(true, goToLibraryTab: Properties.Settings.Default.AutoImportGotoLibraryAfterSuccess); SetMessageLabelText($"Successful {(alreadyExists ? "updated" : "added")} {creature.name} ({species.name}) of the exported file\n" + filePath, MessageBoxIcon.Information, filePath); addedToLibrary = true; } bool topLevels = false; bool newTopLevels = false; // give feedback in overlay string infoText; Color textColor; const int colorSaturation = 200; if (uniqueExtraction) { var sb = new StringBuilder(); sb.AppendLine($"{species.name} \"{creatureInfoInputExtractor.CreatureName}\" {(alreadyExists ? "updated in " : "added to")} the library."); if (addedToLibrary && copyNameToClipboard) { sb.AppendLine("Name copied to clipboard."); } for (int s = 0; s < values.Values.STATS_COUNT; s++) { int statIndex = values.Values.statsDisplayOrder[s]; if (!species.UsesStat(statIndex)) { continue; } sb.Append($"{Utils.StatName(statIndex, true, species.statNames)}: { _statIOs[statIndex].LevelWild} ({_statIOs[statIndex].BreedingValue})"); if (_statIOs[statIndex].TopLevel.HasFlag(LevelStatus.NewTopLevel)) { sb.Append($" {Loc.S("newTopLevel")}"); newTopLevels = true; } else if (_statIOs[statIndex].TopLevel.HasFlag(LevelStatus.TopLevel)) { sb.Append($" {Loc.S("topLevel")}"); topLevels = true; } sb.AppendLine(); } infoText = sb.ToString(); textColor = Color.FromArgb(colorSaturation, 255, colorSaturation); } else { infoText = $"Creature \"{creatureInfoInputExtractor.CreatureName}\" couldn't be extracted uniquely, manual level selection is necessary."; textColor = Color.FromArgb(255, colorSaturation, colorSaturation); } if (_overlay != null) { _overlay.SetInfoText(infoText, textColor); if (Properties.Settings.Default.DisplayInheritanceInOverlay && creature != null) { _overlay.SetInheritanceCreatures(creature, creature.Mother, creature.Father); } } if (addedToLibrary) { if (Properties.Settings.Default.DeleteAutoImportedFile) { FileService.TryDeleteFile(filePath); } else if (Properties.Settings.Default.MoveAutoImportedFileToSubFolder || Properties.Settings.Default.AutoImportedExportFileRename) { string newPath = Properties.Settings.Default.MoveAutoImportedFileToSubFolder ? (string.IsNullOrEmpty(Properties.Settings.Default.ImportExportedArchiveFolder) ? Path.Combine(Path.GetDirectoryName(filePath), "imported") : Properties.Settings.Default.ImportExportedArchiveFolder) : Path.GetDirectoryName(filePath); if (Properties.Settings.Default.MoveAutoImportedFileToSubFolder && !FileService.TryCreateDirectory(newPath, out string errorMessage)) { MessageBoxes.ShowMessageBox($"Subfolder\n{newPath}\ncould not be created.\n{errorMessage}"); return; } string namePattern = Properties.Settings.Default.AutoImportedExportFileRenamePattern; string newFileName = Properties.Settings.Default.AutoImportedExportFileRename && !string.IsNullOrWhiteSpace(namePattern) ? NamePattern.GenerateCreatureName(creature, _creatureCollection.creatures.Where(c => c.Species == speciesSelector1.SelectedSpecies).ToArray(), null, null, _customReplacingNamingPattern, false, -1, false, namePattern) : Path.GetFileName(filePath); // remove invalid characters var invalidCharacters = Path.GetInvalidFileNameChars(); foreach (var invalidChar in invalidCharacters) { newFileName = newFileName.Replace(invalidChar, '_'); } string newFileNameWithoutExtension = Path.GetFileNameWithoutExtension(newFileName); string newFileNameExtension = Path.GetExtension(newFileName); string newFilePath = Path.Combine(newPath, newFileName); int fileSuffix = 1; while (File.Exists(newFilePath)) { newFilePath = Path.Combine(newPath, $"{newFileNameWithoutExtension}_{++fileSuffix}{newFileNameExtension}"); } if (FileService.TryMoveFile(filePath, newFilePath)) { _librarySelectionInfoClickPath = newFilePath; } } } else if (!uniqueExtraction && copyNameToClipboard) { // extraction failed, user might expect the name of the new creature in the clipboard Clipboard.SetText("Automatic extraction was not possible"); } if (Properties.Settings.Default.PlaySoundOnAutoImport) { if (uniqueExtraction) { if (alreadyExists) { SoundFeedback.BeepSignal(SoundFeedback.FeedbackSounds.Indifferent); } if (newTopLevels) { SoundFeedback.BeepSignal(SoundFeedback.FeedbackSounds.Great); } else if (topLevels) { SoundFeedback.BeepSignal(SoundFeedback.FeedbackSounds.Good); } else { SoundFeedback.BeepSignal(SoundFeedback.FeedbackSounds.Success); } } else { SoundFeedback.BeepSignal(SoundFeedback.FeedbackSounds.Failure); } } }
public FilenameToTagProcessor(string pattern) { Pattern = new NamePattern(pattern); }