public static List <string> Run([HttpTrigger(AuthorizationLevel.Anonymous, "get", "post", Route = "PasswordGenerator/Word")] HttpRequest req, ILogger log, ExecutionContext executionContext) { log.LogInformation("PasswordGeneratorWord function processed a request."); WordConfig config = new WordConfig(); string body = req.ReadAsStringAsync().Result; if (!string.IsNullOrEmpty(body)) { // Deserialize config object from body config = JsonConvert.DeserializeObject <WordConfig>(body); } else { // Deserialize config object from parameters config = JsonConvert.DeserializeObject <WordConfig>(JsonConvert.SerializeObject(req.GetQueryParameterDictionary())); } List <string> passwords = new List <string>(); List <string> words = File.ReadAllLines(executionContext.FunctionAppDirectory + "/Data/PasswordGenerator/google-10000-english-no-swears.txt").ToList(); for (int i = 0; i < config.NumberOfPasswords; i++) { passwords.Add(Common.GenerateWordPassword(config, words)); } return(passwords); }
public IActionResult Index() { // Try and get cookies string wordConfigCookie = _httpContextAccessor.HttpContext.Request.Cookies["wordConfig"]; string stringConfigCookie = _httpContextAccessor.HttpContext.Request.Cookies["stringConfig"]; WordConfig wordConfig = new WordConfig(); if (!string.IsNullOrEmpty(wordConfigCookie)) { wordConfig = JsonConvert.DeserializeObject <WordConfig>(wordConfigCookie); } StringConfig stringConfig = new StringConfig(); if (!string.IsNullOrEmpty(stringConfigCookie)) { stringConfig = JsonConvert.DeserializeObject <StringConfig>(stringConfigCookie); } TempData.Put("WordConfig", wordConfig); TempData.Put("StringConfig", stringConfig); return(View("~/Views/Projects/PasswordGenerator/Index.cshtml")); }
public ConfigWindow(WordConfig wordsConfig, ImageConfig imageConfig, TagsCloudCreator tagsCloudProcessor, IServiceFactory <ITextFilter> filtersFactory, IServiceFactory <IWordConverter> convertersFactory, IServiceFactory <ITagsGenerator> tagsGeneratorFactory, IServiceFactory <IRectanglesLayouter> layouterFactory) { InitializeComponent(); this.wordsConfig = wordsConfig; this.imageConfig = imageConfig; this.tagsGeneratorFactory = tagsGeneratorFactory; this.layouterFactory = layouterFactory; this.tagsCloudProcessor = tagsCloudProcessor; this.filtersFactory = filtersFactory; this.convertersFactory = convertersFactory; colorDialog = new ColorDialog(); fontDialog = new FontDialog(); saveFileDialog = new SaveFileDialog(); saveFileDialog.Filter = "Изображение (*.png)||Изображение (*.jpg)||Изображение (*.bmp)|"; openFileDialog = new OpenFileDialog(); openFileDialog.Filter = "Текстовые файлы (*.txt)|"; widthNumeric = new NumericUpDown(); heightNumeric = new NumericUpDown(); tableLayoutPanel = new TableLayoutPanel(); tableLayoutPanel.Dock = DockStyle.Fill; tableLayoutPanel.AutoSize = true; Controls.Add(tableLayoutPanel); InitView(); }
public VirastarConfig() { CharConfiguration = new CharConfig(); WordConfiguration = new WordConfig(); WritingRuleConfiguration = new WritingRule(); IgnoreProcessConfiguration = new IgnoreProcessConfig(); SpellConfiguration = new SpellConfig(); }
public VirastarConfig(CharConfig charConfiguration, WordConfig wordConfiguration, WritingRule writingRuleConfiguration, IgnoreProcessConfig ignoreProcessConfiguration, SpellConfig spellConfiguration) { CharConfiguration = charConfiguration; WordConfiguration = wordConfiguration; WritingRuleConfiguration = writingRuleConfiguration; IgnoreProcessConfiguration = ignoreProcessConfiguration; SpellConfiguration = spellConfiguration; }
public void SetUp() { var path = TestContext.CurrentContext.TestDirectory; textPath = Path.Combine(path, "Resources", "text.txt"); imagePath = Path.Combine(path, "Resources", "test.png"); expectedImagePath = Path.Combine(path, "Resources", "expected.png"); tagsCloudCreator = container.GetService <TagsCloudCreator>(); wordsConfig = container.GetService <WordConfig>(); ConfigureWordsConfig(textPath); imageConfig = container.GetService <ImageConfig>(); ConfigureImageConfig(imagePath); }
public static string GenerateWordPassword(WordConfig config, List <string> baseWordList) { string password = ""; // Select all words of desired length List <string> filteredWordList = baseWordList.Where(x => x.Length >= config.WordLengthMin && x.Length <= config.WordLengthMax).ToList(); // Create random Random random = new Random(); // Select desired number of words List <string> finalWordList = filteredWordList.GetRandomElement(config.NumberOfWords).ToList(); //List<string> finalWordList = filteredWordList.Shuffle(random).Take(config.NumberOfWords).ToList(); // Update word casing if (config.CaseTransform == CaseTransform.Alternating) { for (int i = finalWordList.Count - 1; i >= 0; i--) { if (i % 2 == 0) { finalWordList[i] = finalWordList[i].ToLower(); } else { finalWordList[i] = finalWordList[i].ToUpper(); } } } else if (config.CaseTransform == CaseTransform.Capitalise) { finalWordList = finalWordList.Select(x => x.First().ToString().ToUpper() + x.Substring(1).ToLower()).ToList(); } else if (config.CaseTransform == CaseTransform.Invert) { finalWordList = finalWordList.Select(x => x.First().ToString().ToLower() + x.Substring(1).ToUpper()).ToList(); } else if (config.CaseTransform == CaseTransform.Lower) { finalWordList = finalWordList.Select(x => x.ToLower()).ToList(); } else if (config.CaseTransform == CaseTransform.None) { } else if (config.CaseTransform == CaseTransform.Random) { for (int i = finalWordList.Count - 1; i >= 0; i--) { if (random.Next(0, 2) == 0) { finalWordList[i] = finalWordList[i].ToLower(); } else { finalWordList[i] = finalWordList[i].ToUpper(); } } } else if (config.CaseTransform == CaseTransform.Upper) { finalWordList = finalWordList.Select(x => x.ToUpper()).ToList(); } // Get word seperator string seperator = ""; if (config.SeperatorAlphabet.Length > 0) { seperator = config.SeperatorAlphabet.ToArray().GetRandomElement(1).FirstOrDefault().ToString(); } // Padding string startPadding = ""; string endPadding = ""; // Number padding if (config.PaddingDigitsBefore > 0) { for (int i = 0; i < config.PaddingDigitsBefore; i++) { startPadding += Common.GetRandomInteger(0, 9).ToString(); } } if (config.PaddingDigitsAfter > 0) { for (int i = 0; i < config.PaddingDigitsAfter; i++) { endPadding += Common.GetRandomInteger(0, 9).ToString(); } } // Symbol padding if (config.PaddingType == Padding.Fixed) { char paddingCharacter = config.PaddingAlphabet.ToArray().GetRandomElement(1).FirstOrDefault(); if (config.PaddingCharactersBefore > 0) { startPadding = startPadding.PadLeft(config.PaddingDigitsBefore + config.PaddingCharactersBefore, paddingCharacter); } if (config.PaddingCharactersAfter > 0) { endPadding = endPadding.PadRight(config.PaddingDigitsAfter + config.PaddingCharactersAfter, paddingCharacter); } } else if (config.PaddingType == Padding.Adaptive) { char paddingCharacter = config.PaddingAlphabet.ToArray().GetRandomElement(1).FirstOrDefault(); int passwordLength = config.PaddingDigitsBefore + finalWordList.Sum(x => x.Length) + config.PaddingDigitsAfter + config.NumberOfWords; if (config.PadToLength > passwordLength) { endPadding = endPadding.PadRight(config.PadToLength - passwordLength, paddingCharacter); } } if (!string.IsNullOrEmpty(startPadding)) { finalWordList.Insert(0, startPadding); } if (!string.IsNullOrEmpty(endPadding)) { finalWordList.Add(endPadding); } password = string.Join(seperator, finalWordList); return(password); }
public ImageBuilder(ImageConfig imageConfig, WordConfig wordsConfig) { this.imageConfig = imageConfig; this.wordsConfig = wordsConfig; }
public TagsGenerator(IServiceFactory <IRectanglesLayouter> layouterFactory, WordConfig wordsConfig) { this.layouterFactory = layouterFactory; this.wordsConfig = wordsConfig; }
public string GetWordText(int wordID) { WordConfig config = GetConfig <WordConfig>(); return(config.GetWordByID(wordID, (int)MCurrentLanguage)); }
public ConvertersFactory(WordConfig wordsConfig) { this.wordsConfig = wordsConfig; }
public RectanglesLayoutersFactory(WordConfig wordsConfig) { this.wordsConfig = wordsConfig; }
public FiltersFactory(WordConfig wordsConfig) { this.wordsConfig = wordsConfig; }
public void WordMake() { if (this.templateName == null || this.templateName.Trim().Equals(string.Empty)) { this.Hint = "未找到对应的模板!"; return; } if (this.picName == null || this.picName.Trim().Equals(string.Empty)) { this.Hint = "必须指定图片产品!"; return; } if (this.outPath == null || this.outPath.Trim().Equals(string.Empty)) { this.Hint = "必须一个输出目录!"; return; } if (this.section == null || this.section.Trim().Equals(string.Empty)) { this.Hint = "必须指定产品期数!"; return; } if (this.signPeople == null || this.signPeople.Trim().Equals(string.Empty)) { this.Hint = "必须指定签发人!"; return; } if (this.prePeople == null || this.prePeople.Trim().Equals(string.Empty)) { this.Hint = "必须指定预报人!"; return; } try { int volume = int.Parse(this.section); volume++; ProductVolumeConfig con = new ProductVolumeConfig(); con.productVolume.WaterloggingVolume = volume; con.WriteConfigToFile(); } catch (Exception) { this.Hint = "请输入有效的产品期数数字!"; return; } string outFileYear = (DateTime.Now.Year % 100).ToString("00"); string outFileMonth = DateTime.Now.Month.ToString("00"); string outFileDay = DateTime.Now.Day.ToString("00"); string outFileHour = DateTime.Now.Hour.ToString("00"); string outFileName = this.outPath + "/zl" + outFileYear + outFileMonth + outFileDay + outFileHour; DateTime tomorrow = DateTime.Now.AddDays(1); WordConfig config = new WordConfig(this.templateName, outFileName); PicBookmark pbm = new PicBookmark(); pbm.PicFileName = this.picName; pbm.Bookmark = "图形产品"; /*pbm.ListTextBox = new List<TextBoxOnPic>(); * TextBoxOnPic titleText = new TextBoxOnPic * { * Left = 250, * Top = 364, * Width = 140, * Height = 21, * Bold = 1, * FontName = "宋体", * Size = 11, * Text = "全国渍涝风险气象预报图" }; * pbm.ListTextBox.Add(titleText); * TextBoxOnPic fromToText = new TextBoxOnPic * { * Left = 240, * Top = 390, * Width = 150, * Height = 19, * Bold = 0, * FontName = "宋体", * Size = 7, * Text = DateTime.Now.Year + "年" + outFileMonth + "月" + outFileDay + "日" + outFileHour + "时~" + tomorrow.Month.ToString("00") + "月" + tomorrow.Day.ToString("00") + "日" + outFileHour + "时" + }; + pbm.ListTextBox.Add(fromToText); + TextBoxOnPic pubText = new TextBoxOnPic + { + Left = 250, + Top = 420, + Width = 120, + Height = 19, + Bold = 0, + FontName = "宋体", + Size = 7, + Text = "中央气象台" + DateTime.Now.Month + "月" + DateTime.Now.Day + "日" + DateTime.Now.Hour + "时发布" + }; + pbm.ListTextBox.Add(pubText);*/ config.ListPicBookmark.Add(pbm); TextBookmark sign = new TextBookmark { Bookmark = "签发人", Text = this.signPeople }; config.ListTextBookmark.Add(sign); TextBookmark pre = new TextBookmark { Bookmark = "预报人", Text = this.prePeople }; config.ListTextBookmark.Add(pre); TextBookmark fromDay = new TextBookmark { Bookmark = "起始日", Text = DateTime.Now.Day.ToString() }; config.ListTextBookmark.Add(fromDay); TextBookmark fromHour = new TextBookmark { Bookmark = "起始时", Text = DateTime.Now.Hour.ToString() }; config.ListTextBookmark.Add(fromHour); TextBookmark fromMonth = new TextBookmark { Bookmark = "起始月", Text = DateTime.Now.Month.ToString() }; config.ListTextBookmark.Add(fromMonth); TextBookmark PubDay = new TextBookmark { Bookmark = "发布日", Text = DateTime.Now.Day.ToString() }; config.ListTextBookmark.Add(PubDay); TextBookmark PubHour = new TextBookmark { Bookmark = "发布时", Text = DateTime.Now.Hour.ToString() }; config.ListTextBookmark.Add(PubHour); TextBookmark PubMonth = new TextBookmark { Bookmark = "发布月", Text = DateTime.Now.Month.ToString() }; config.ListTextBookmark.Add(PubMonth); TextBookmark sect = new TextBookmark { Bookmark = "期数", Text = this.section }; config.ListTextBookmark.Add(sect); TextBookmark SectionYear = new TextBookmark { Bookmark = "期数年", Text = DateTime.Now.Year.ToString() }; config.ListTextBookmark.Add(SectionYear); TextBookmark TitleDay = new TextBookmark { Bookmark = "标题日", Text = DateTime.Now.Day.ToString() }; config.ListTextBookmark.Add(TitleDay); TextBookmark TitleHour = new TextBookmark { Bookmark = "标题时", Text = DateTime.Now.Hour.ToString() }; config.ListTextBookmark.Add(TitleHour); TextBookmark TitleMonth = new TextBookmark { Bookmark = "标题月", Text = DateTime.Now.Month.ToString() }; config.ListTextBookmark.Add(TitleMonth); TextBookmark TitleYear = new TextBookmark { Bookmark = "标题年", Text = DateTime.Now.Year.ToString() }; config.ListTextBookmark.Add(TitleYear); TextBookmark ToDay = new TextBookmark { Bookmark = "结束日", Text = tomorrow.Day.ToString() }; config.ListTextBookmark.Add(ToDay); TextBookmark ToHour = new TextBookmark { Bookmark = "结束时", Text = DateTime.Now.Hour.ToString() }; config.ListTextBookmark.Add(ToHour); TextBookmark ToMonth = new TextBookmark { Bookmark = "结束月", Text = tomorrow.Month.ToString() }; config.ListTextBookmark.Add(ToMonth); WordMaking.MakingViaConfig(config); this.Hint = "文字产品生成成功!"; this.Section = new ProductVolumeConfig().productVolume.WaterloggingVolume.ToString(); }
public TagsGeneratorFactory(WordConfig wordsConfig) { this.wordsConfig = wordsConfig; }
public ReadersFactory(WordConfig wordsConfig) { this.wordsConfig = wordsConfig; }