private void AddRequestFiles(RestRequest request, ListStructure files, TextStructure bodyFile) { var allFiles = new List <PostFileModel>(); if (bodyFile?.Value != null) { allFiles.Add(new PostFileModel(ParameterType.RequestBody.ToString(), bodyFile.Value.ToString(), null)); } if (files != null) { allFiles.AddRange(files.Value.Select(v => new PostFileModel(v.ToString()))); } foreach (var file in allFiles) { if (file.FormFieldName == ParameterType.RequestBody.ToString()) { AddBodyFileName(request, file); } else { request.AddFile(file.FormFieldName, file.FilePath, file.ContentType); } } }
public void Execute(Arguments arguments) { try { var result = SeleniumManager.CurrentWrapper.RunScript(arguments.Script.Value, arguments.Timeout.Value, arguments.WaitForNewWindow.Value); Structure resultStruct; if (arguments.ResultAsStructure.Value) { try { resultStruct = Scripter.Structures.CreateStructure(result, "", result?.GetType()); } catch { resultStruct = Scripter.Structures.CreateStructure(result, ""); } } else { resultStruct = new TextStructure(result != null ? result.ToString() : string.Empty, "", Scripter); } Scripter.Variables.SetVariableValue(arguments.Result.Value, resultStruct); } catch (Exception ex) { throw new ApplicationException($"Error occured while running javascript script: '{arguments.Script.Value}'. Message: {ex.Message}", ex); } }
private void AddRequestBody(RestRequest request, TextStructure bodyText) { if (bodyText?.Value != null) { request.AddParameter(ParameterType.RequestBody.ToString(), bodyText.Value, ParameterType.RequestBody); } }
public void Execute(Arguments arguments) { var sheetsManager = SheetsManager.CurrentSheet; var sheetName = arguments.SheetName.Value == "" ? sheetsManager.sheets[0].Properties.Title : arguments.SheetName.Value; var val = sheetsManager.GetValue(arguments.Range.Value, sheetName); ListStructure result = new ListStructure(new System.Collections.Generic.List <object>()); //string result=null; //var result = val. == null ? "" : val.Values[0][0].ToString(); if (val.ValueRanges[0].Values == null) { for (int i = 0; i < val.ValueRanges.Count; i++) { TextStructure tmp = new TextStructure(""); result.Value.Add(tmp); } Scripter.Variables.SetVariableValue(arguments.Result.Value, result); } else { for (int i = 0; i < val.ValueRanges.Count; i++) { // TextStructure tmp = new TextStructure(val.ValueRanges[i].Values[0][0].ToString()); result.Value.Add(val.ValueRanges[i].Values[0][0].ToString()); } Scripter.Variables.SetVariableValue(arguments.Result.Value, result); } }
public void Execute(Arguments arguments) { object col = null; try { int row = arguments.Row.Value; if (arguments.ColIndex != null) { col = arguments.ColIndex.Value; } else if (arguments.ColName != null) { col = arguments.ColName.Value; } else { throw new ArgumentException("One of the ColIndex or ColName arguments have to be set up."); } var result = new TextStructure(XlsxManager.CurrentXlsx.GetValue(row, col.ToString())); Scripter.Variables.SetVariableValue(arguments.Result.Value, result); } catch (Exception ex) { throw new ApplicationException($"Error occured while getting value from specified cell. Row: {arguments.Row.Value}. Column: '{col?.ToString()}'. Message: '{ex.Message}'", ex); } }
public void Execute(Arguments arguments) { try { List <object> args = new List <object>(); if (arguments.Args?.Value != null) { foreach (Structure arg in arguments.Args?.Value) { TextStructure tmpArgument = arg as TextStructure; if (tmpArgument != null) { args.Add(tmpArgument.Value); } } } //else //{ // args.Add(string.Empty); //} ExcelManager.CurrentExcel.RunMacro(arguments.Name.Value, args); } catch (Exception ex) { throw new ApplicationException($"Problem occured while running excel macro. Path: '{arguments.Name.Value}', Arguments count: '{arguments.Args?.Value?.Count ?? 0}'", ex); } }
bool RemoveTitle(TextStructure title) { return(IsAnexo(title.Text) || (IsNotGrade(title) && HasManyLowerCase(title.Text) || IsDataEmPautaJugamento(title.Text) )); }
string GenerateText(TextStructure s) { string prefix = ""; if (s.TextAlignment == TextAlignment.JUSTIFY) { return(s.Text.Replace("\t", "\n\t").TrimStart('\n')); } if (s.TextAlignment == TextAlignment.LEFT || s.TextAlignment == TextAlignment.UNKNOWN) { PdfReaderException.Warning("s.TextAlignment == TextAlignment.LEFT || s.TextAlignment == TextAlignment.UNKNOWN"); } if (s.TextAlignment == TextAlignment.CENTER) { prefix = "\t\t"; } if (s.TextAlignment == TextAlignment.RIGHT) { prefix = "\t\t\t\t"; } var lines = s.Text.Split('\n').Select(l => prefix + l); string text = String.Join("\n", lines); return(text); }
string GenerateText(TextStructure s) { string prefix = ""; if (s.TextAlignment == TextAlignment.LEFT || s.TextAlignment == TextAlignment.UNKNOWN) { PdfReaderException.Warning("s.TextAlignment == TextAlignment.LEFT || s.TextAlignment == TextAlignment.UNKNOWN"); } else if (s.TextAlignment == TextAlignment.JUSTIFY) { return(s.Text.Replace("\n\t", "\n\n\t")); } if (s.TextAlignment == TextAlignment.CENTER) { prefix = "\t\t"; } if (s.TextAlignment == TextAlignment.RIGHT) { prefix = "\t\t\t\t"; } string prefixTab(string lin) => (lin != "") ? prefix + lin : lin; var lines = s.Text.Split('\n').Select(prefixTab); string text = String.Join("\n", lines); return(text); }
public IEnumerable <TextStructure> ProcessParagraph(IEnumerable <TextLine> lineSet) { List <TextStructure> structures = new List <TextStructure>(); List <TextLine> lines = new List <TextLine>(); foreach (TextLine line in lineSet) { //If structure is empty, add the first line if (lines.Count == 0) { lines.Add(line); continue; } //If this line it is in the same structure, add it. Otherwise, it is other structure if (AreInSameStructure(lines[lines.Count - 1], line)) { lines.Add(line); } else { ExecutionStats.TextInfo infos = GetTextInfos(lines); TextStructure structure = new TextStructure() { FontName = infos.FontName, FontSize = infos.FontSize, FontStyle = infos.FontStyle, Text = GetText(lines), TextAlignment = GetParagraphTextAlignment(lines), Lines = lines, MarginLeft = lines[0].MarginLeft, MarginRight = lines[0].MarginRight }; structures.Add(structure); lines = new List <TextLine>() { line }; } } if (lines.Count > 0) { ExecutionStats.TextInfo infos = GetTextInfos(lines); TextStructure structure = new TextStructure() { FontName = infos.FontName, FontSize = infos.FontSize, FontStyle = infos.FontStyle, Text = GetText(lines), TextAlignment = GetParagraphTextAlignment(lines), Lines = lines, MarginLeft = lines[0].MarginLeft, MarginRight = lines[0].MarginRight }; structures.Add(structure); } return(structures); }
public Content(TextStructure structure, TipoDoConteudo type) { this.FontName = structure.FontName; this.FontSize = structure.FontSize; this.FontStyle = structure.FontStyle; this.Text = structure.Text; this.TextAlignment = structure.TextAlignment; this.ContentType = type; }
Func <TextStructure, bool> KeepTitle(TextStructure[] body) { // usa o sumario para definir o tamanho da fonte padrao if (_bodyCompare == null) { _bodyCompare = (body.Length > 0) ? body[0] : null; } return(title => KeepTitleCompareFonts(title, _bodyCompare)); }
bool CompatibleFonts(TextStructure title, TextStructure body) { if (body == null) { return(true); } bool titleHasLargerFonts = CompareStructureHieararchyIgnoreCase(title, body) > 0; return(titleHasLargerFonts); }
public async ValueTask <ActionResult <string> > GenerateTextValue( int length, TextStructure textStructure = TextStructure.Text, string?language = "en", int maxShouldContainErrors = 10, int maxShouldContainSlow = 10) { if (language == null) { language = "en"; } var shouldContain = new List <string>(); if (Profile.Type == ProfileType.User) { // Personalize text generation. var data = await _typingReportGerenator.GenerateStandardUserStatisticsAsync(Profile.ProfileId, language); shouldContain.AddRange(data.KeyPairs .Where(x => x.FromKey?.Length == 1 && x.ToKey.Length == 1) .OrderByDescending(x => x.MistakesToSuccessRatio) .Select(x => $"{x.FromKey}{x.ToKey}") .Take(maxShouldContainErrors)); shouldContain.AddRange(data.KeyPairs .Where(x => x.FromKey?.Length == 1 && x.ToKey.Length == 1) .OrderByDescending(x => x.AverageDelay) .Select(x => $"{x.FromKey}{x.ToKey}") .Take(maxShouldContainSlow)); } _logger.LogDebug("Generating text for user {ProfileId} containing {@Contains}.", ProfileId, shouldContain); //var textValue = await _textGenerator.GenerateTextAsync(new TextGenerationConfigurationDto(length, shouldContain, textType, language)); var config = Texts.TextGenerationConfiguration.SelfImprovement( new(language), textStructure: textStructure, shouldContain: shouldContain); var generatedText = await _textsClient.GenerateTextAsync(config, EndpointAuthentication.Service, default); var textValue = generatedText.Value; var textId = await _textRepository.NextIdAsync(); var configuration = new TextConfiguration( TextType.Generated, new Typing.TextGenerationConfiguration(length, shouldContain, config.GetTextGenerationType()), language); var text = new Text(textId, textValue, ProfileId, DateTime.UtcNow, false, configuration); await _textRepository.SaveAsync(text); return(Ok(textId)); }
bool IsImage(TextStructure structure) { string text = structure.Text; if (text.StartsWith("[[[") || text.StartsWith("\n[[[")) { if (text.Contains("[[[IMG") || text.Contains("[[[TABLE")) { return(true); } } return(false); }
public static Bitmap OpenImage(this TextStructure filePath) { try { using (var bitmap = new Bitmap(filePath.Value)) { return(Image.Clone(bitmap, PixelFormat.Format24bppRgb)); } } catch (Exception ex) { throw new Exception($"Could not open the image file '{filePath.Value}'. Message: {ex.Message}", ex); } }
public static object GetColumn(IntegerStructure columnIndex, TextStructure columnName, bool isColumnRequired = false) { if (columnIndex != null) { return(columnIndex.Value); } if (columnName != null) { return(columnName.Value); } if (isColumnRequired) { throw new ArgumentException("One of the ColIndex or ColName arguments have to be set up."); } return(null); }
IEnumerable <string> GetBody(TextStructure[] body) { TextStructure lastStructure = null; bool lastWasImage = false; foreach (var structure in body) { bool isImage = IsImage(structure); if (isImage) { string imgText = structure.Text.Trim('\n'); if (!lastWasImage) { yield return(""); } yield return(imgText); } else { //if (lastWasImage) // yield return ""; if (lastStructure != null) { yield return(""); } //if (lastStructure != null && lastStructure.TextAlignment != structure.TextAlignment) // yield return ""; yield return(GenerateText(structure)); lastStructure = structure; } lastWasImage = isImage; } }
int CompareStructureHieararchy(TextStructure a, TextStructure b) { // Font size int compareFontSize = CompareFontSize(a.FontSize, b.FontSize); if (compareFontSize != 0) { return(compareFontSize); } // Boldness int compareBoldness = CompareBoldness(a.FontStyle, b.FontStyle); if (compareBoldness != 0) { return(compareBoldness); } // Compare upper case? return(0); }
TextSegment Create(TextStructure[] titles, TextStructure[] body) { int total = titles.Length; int stop = titles .TakeWhile(KeepTitle) .Count(); if (total == stop) { _lastIgnored = null; return(new TextSegment() { Title = titles, Body = body }); } _lastIgnored = titles.Skip(stop).FirstOrDefault(); var titlesMovedToBody = titles.Skip(stop).ToArray(); int validatePortariaTitle = titles.Where(t => t.Text.StartsWith("PORTARIA")).Count(); if (validatePortariaTitle > 0) { PdfReaderException.Warning("validtitle inside the body"); } var newTitle = titles.Take(stop).ToArray(); var newBody = titlesMovedToBody.Concat(body).ToArray(); return(new TextSegment() { Title = newTitle, Body = newBody }); }
public void Execute(Arguments arguments) { AbbyyManager manager = AbbyyManager.Instance; int docID = arguments.DocumentID?.Value ?? manager.CurentDocumentCount; FineReaderDocument document = manager.GetDocument(docID); int row = 0; int column = 0; int rowOffset = 0; int columnOffset = 0; var position = arguments.Position.Value.Split(','); row = int.Parse(position[0]); column = int.Parse(position[1]); if (!string.IsNullOrEmpty(arguments.Offset?.Value)) { var positionOffset = arguments.Offset.Value.Split(','); rowOffset = int.Parse(positionOffset[0]); columnOffset = int.Parse(positionOffset[1]); } string cellTextValue = string.Empty; try { cellTextValue = document.Tables[arguments.TableIndex.Value - 1][row - 1 + rowOffset, column - 1 + columnOffset].Text ?? string.Empty; } catch { } TextStructure cellText = new TextStructure(cellTextValue); Scripter.Variables.SetVariableValue(arguments.Result.Value, cellText); }
int CompareStructureHieararchyIgnoreCase(TextStructure a, TextStructure b) { // Font size int compareFontSize = CompareFontSize(a.FontSize, b.FontSize); if (compareFontSize != 0) { return(compareFontSize); } // Boldness int compareBoldness = CompareBoldness(a.FontStyle, b.FontStyle); if (compareBoldness != 0) { return(compareBoldness); } return(0); //// Compare upper case //int compareUppercase = CompareUppercase(a.Text, b.Text); //return compareUppercase; }
public void Execute(Arguments arguments) { TextStructure cmdresult = new TextStructure(); try { String outData = "[]"; List <String> jsons = new List <string>(100); string ftl = "{}"; if (!String.IsNullOrWhiteSpace(arguments.filter.Value)) { ftl = arguments.filter.Value; } string sort = null; if (!String.IsNullOrWhiteSpace(arguments.sort.Value)) { sort = arguments.sort.Value; } int?skip = null; if (arguments.skip.Value > 0) { skip = arguments.skip.Value; } int?limit = null; if (arguments.limit.Value > 0) { limit = arguments.limit.Value; } var connectionString = MongoDBSettings.GetInstance().ConnectionString; var client = new MongoClient(connectionString); IMongoDatabase db = client.GetDatabase(MongoDBSettings.GetInstance().DatabaseName); var collection = db.GetCollection <BsonDocument>(arguments.collection.Value); var y = collection.Find(ftl).Skip(skip).Limit(limit).Sort(sort).ToListAsync(); y.Wait(); var jsonWriterSettings = new JsonWriterSettings { OutputMode = JsonOutputMode.Strict }; int count = y.Result.Count; if (count > 0) { StringBuilder sb = new StringBuilder(1024); sb.Append("[ "); for (int i = 0; i < count; i++) { sb.Append(y.Result[i].ToJson(jsonWriterSettings)); if (i != count - 1) { sb.Append(", "); } } sb.Append(" ]"); outData = sb.ToString(); } Scripter.Variables.SetVariableValue(arguments.Result.Value, new TextStructure(outData)); } catch (Exception exc) { throw new ApplicationException($"Error occured find command :" + exc.Message); } return; }
public TextSegment Create(List <TextSegment> _structures) { var titles = _structures[0].Title; var body = _structures[0].Body; var textSegment = _textSegment; int total = titles.Length; int stop = titles .TakeWhile(KeepTitle) .Count(); if (_lastIgnored != null && CompareStructureHieararchy(titles[0], _lastIgnored) <= 0) { stop = 0; } int shouldSplit = titles.TakeWhile(b => CompareStructureHieararchy(titles[0], b) >= 0).Count(); if (stop == 0 && shouldSplit < total) { var lastLines = titles.Take(shouldSplit); var newLines = titles.Skip(shouldSplit); textSegment.Body = textSegment.Body.Concat(lastLines).ToArray(); _textSegment = Create(newLines.ToArray(), body); return(_textSegment); } if (total == stop) { _lastIgnored = null; _textSegment = new TextSegment() { Title = titles, Body = body }; return(_textSegment); } _lastIgnored = titles.Skip(stop).FirstOrDefault(); var titlesMovedToBody = titles.Skip(stop).ToArray(); int validatePortariaTitle = titles.Where(t => t.Text.StartsWith("PORTARIA")).Count(); if (validatePortariaTitle > 0) { PdfReaderException.Warning("validtitle inside the body"); } var newTitle = titles.Take(stop).ToArray(); var newBody = titlesMovedToBody.Concat(body).ToArray(); _textSegment = new TextSegment() { Title = newTitle, Body = newBody }; return(_textSegment); }
bool IsNotGrade(TextStructure title) { return(!title.HasBackColor); }
//bool KeepTitleCompareFonts(TextStructure title, TextStructure body) => (!RemoveTitle(title)) && (CompatibleFonts(title,body)); bool KeepTitleCompareFonts(TextStructure title, TextStructure body) => (CompatibleFonts(title, body));
bool KeepTitle(TextStructure title) => !RemoveTitle(title);
internal void TypeText(TextStructure postvalue, MediumWriteArticlesCommand.Arguments arguments, TimeSpan value) { throw new NotImplementedException(); }
internal void TypeText(TextStructure posttitle, MediumStoriesCommand.Arguments arguments, TimeSpan value) { throw new NotImplementedException(); }