public CodeDefinitionViewModel CreateCodeDefinition(CodeType codeType) { var baseName = VariableNameGenerator.Generate(); var name = baseName + codeType switch { CodeType.Filter => "Filter", CodeType.Shared => "Shared", _ => throw new Exception($"The code type '{codeType}' is not supported.") }; var code = codeType switch { CodeType.Filter => RoslynProject.DefaultFilterCode, CodeType.Shared => RoslynProject.DefaultSharedCode, _ => throw new Exception($"The code type '{codeType}' is not supported.") }; var owner = _userIdService.User.Identity.Name; return(new CodeDefinitionViewModel(new CodeDefinition(owner: owner)) { CodeType = codeType, Code = code, Name = name, SampleRate = "1 s" }); }
public static string Generate() { var i = _random.Next(0, _randomWords.Data.Count); int j = i; while (j == i) { j = _random.Next(0, _randomWords.Data.Count); } var first = VariableNameGenerator.FirstCharToUpper(_randomWords.Data[i]); var second = VariableNameGenerator.FirstCharToUpper(_randomWords.Data[j]); return($"{first}{second}"); }