private void ProcessPreMarkedWords(string content, MLEEntities db, int exampleID, int sentenceID, int entityID, List <ExampleCategory> exampleCategory, int?categoryForWords) { var doc = new HtmlAgilityPack.HtmlDocument(); doc.LoadHtml(content); var nodes = doc.DocumentNode.SelectNodes("//span"); if (nodes == null) { return; } foreach (var node in nodes) { var span_class = node.GetClasses().FirstOrDefault(); if (span_class != null) { var text = node.InnerText; var ec = exampleCategory.Select(x => x.Category.Subcategory).ToList(); var cfw = db.Category.Where(x => x.Id == categoryForWords.Value).Select(x => x.Subcategory).ToList(); var subcategory = db.Subcategory.FirstOrDefault(x => x.Name == span_class); if (subcategory != null) { var m = new Marked(); } } } }
/// <summary> /// Chunk the text message and return it as WeChat response. /// </summary> /// <param name="activity">Message activity from bot.</param> /// <param name="text">Text content need to be chunked.</param> /// <returns>Response message list.</returns> private static IList <IResponseMessageBase> GetFixedMessages(IMessageActivity activity, string text) { var responses = new List <IResponseMessageBase>(); if (string.IsNullOrEmpty(text)) { return(responses); } if (activity.TextFormat == TextFormatTypes.Markdown) { var marked = new Marked { Options = { Sanitize = false, Mangle = false, }, }; marked.Options.Renderer = new TextMarkdownRenderer(marked.Options); // Marked package will return additional new line in the end. text = marked.Parse(text).Trim(); } responses.Add(new TextResponse(activity.From.Id, activity.Recipient.Id, text)); return(responses); }
/////////////////////////////////////////////////////////////////////// // Listing 8-26 public int Run() { // Cleanup everything if (true) { GC.Collect(2, GCCollectionMode.Forced, blocking: true, compacting: true); } Normal normal = new Normal(); Pinned onlyPinned = new Pinned(); GCHandle handle = GCHandle.Alloc(onlyPinned, GCHandleType.Pinned); ObjectWithStatic obj = new ObjectWithStatic(); Console.WriteLine(ObjectWithStatic.StaticField); Marked strong = new Marked(); GCHandle strongHandle = GCHandle.Alloc(strong, GCHandleType.Normal); string literal = "Hello world!"; GCHandle literalHandle = GCHandle.Alloc(literal, GCHandleType.Normal); Console.ReadLine(); GC.KeepAlive(obj); handle.Free(); literalHandle.Free(); strongHandle.Free(); return(0); }
private static Inline FormatInlineTextRun(AdaptiveTextRun textRun, AdaptiveRenderContext context) { Marked marked = new Marked(); marked.Options.Renderer = new AdaptiveXamlMarkdownRenderer(); marked.Options.Mangle = false; marked.Options.Sanitize = true; // Handle Date/Time parsing string text = RendererUtilities.ApplyTextFunctions(textRun.Text, context.Lang); // Handle markdown string xaml = $"<Span xmlns=\"http://schemas.microsoft.com/winfx/2006/xaml/presentation\" xml:space=\"preserve\">{marked.Parse(text)}</Span>"; StringReader stringReader = new StringReader(xaml); XmlReader xmlReader = XmlReader.Create(stringReader); Span uiInlineElement = XamlReader.Load(xmlReader) as Span; uiInlineElement.Style = context.GetStyle($"Adaptive.{textRun.Type}"); uiInlineElement.FontFamily = new FontFamily(context.Config.GetFontFamily(textRun.FontStyle)); uiInlineElement.FontWeight = FontWeight.FromOpenTypeWeight(context.Config.GetFontWeight(textRun.FontStyle, textRun.Weight)); uiInlineElement.FontSize = context.Config.GetFontSize(textRun.FontStyle, textRun.Size); uiInlineElement.SetColor(textRun.Color, textRun.IsSubtle, context); return(uiInlineElement); }
public IActionResult EditThread(long id, string content) { var thread = DB.Threads .Where(x => x.Id == id) .SingleOrDefault(); if (thread == null) { return(Prompt(x => { x.Title = "资源没有找到"; x.Details = "您请求的资源没有找到,请返回重试!"; x.StatusCode = 404; })); } if (thread.UserId != User.Current.Id && !User.AnyRoles("Root, Master")) { return(Prompt(x => { x.Title = "权限不足"; x.Details = "您没有权限删除该主题"; x.StatusCode = 500; })); } thread.Content = content; DB.SaveChanges(); ForumHub.Clients.Group("Thread-" + thread.Id).OnThreadEdited(thread.Id); return(Content(Marked.Parse(content))); }
/// <summary> /// Metoda wywoływana w celu zaktualizowaniu zawartości tekstowej wpisu (Content), /// w oparciu o wartości posczególnych właściowości bieżącego obiektu. /// </summary> protected override void UpdateContent() { StringBuilder content = new StringBuilder(); content.Append(Format.ToString()); content.Append(": Marked="); content.Append(Marked.ToString()); content.Append(","); content.Append(GetFormattedTiming(TimingStart)); content.Append(","); content.Append(GetFormattedTiming(TimingEnd)); content.Append(","); content.Append(Style); content.Append(","); content.Append(Name); content.Append(","); content.Append(MarginL.ToString(marginFormat)); content.Append(","); content.Append(MarginR.ToString(marginFormat)); content.Append(","); content.Append(MarginV.ToString(marginFormat)); content.Append(","); content.Append(Effect); content.Append(","); content.Append(Text); Content = content.ToString(); }
public IActionResult Get() { var pullrequestEvents = _pullRequestEventRepository.GetAll(null, null); var viewModel = new List<PullRequestEventViewModel>(); var marked = new Marked(); foreach (var pullRequestEvent in pullrequestEvents) { var itemViewModel = new PullRequestEventViewModel() { Action = pullRequestEvent.Action, Body = marked.Parse(pullRequestEvent.Body), CreatedAt = pullRequestEvent.CreatedAt, Merged = pullRequestEvent.Merged, MergedAt = pullRequestEvent.MergedAt, MergedBy = pullRequestEvent.MergedBy, RepositoryName = pullRequestEvent.RepositoryName, Title = pullRequestEvent.Title, Id = pullRequestEvent.Id }; //itemViewModel.Team = new Models.TeamResponse() //{ // Id = pullRequestEvent.Team.Id, // Name = pullRequestEvent.Team.Name, //}; //if(pullRequestEvent.Team.ChildrenTeams != null) //{ // itemViewModel.Team.ChildrenTeam = new List<Models.TeamResponse>(); // foreach (var childTeam in pullRequestEvent.Team.ChildrenTeams) // { // var childTeamResponse = new Models.TeamResponse() // { // Id = childTeam.Id, // Name = childTeam.Name // }; // itemViewModel.Team.ChildrenTeam.Add(childTeamResponse); // } //} itemViewModel.Labels = new List<LabelDTO>(); foreach (var label in pullRequestEvent.Labels) { var labelDTO = new LabelDTO() { Color = label.Color, Name = label.Name }; itemViewModel.Labels.Add(labelDTO); } viewModel.Add(itemViewModel); } return Ok(viewModel); }
private static void GenerateSchemaExplorerPage(string header, Marked marked) { string[] elements = new string[] { "TextBlock", "Image", "Input.Text", "Input.Number", "Input.Date", "Input.Time", "Input.Toggle", "Input.ChoiceSet", "Container", "ColumnSet", "Column", "FactSet", "ImageSet",/* "ActionSet",*/ "Action.OpenUrl", "Action.Submit", "Action.Http", "Action.ShowCard" }; using (TextWriter writer = new StreamWriter(File.Open(@"..\..\..\..\..\website\wwwroot\explorer\index.html", FileMode.Create))) { writer.WriteLine(header.Replace("$PAGE$", "explorer")); // side bar writer.WriteLine("<div id=\"sidebar\" class=\"w3-sidebar w3-light-grey w3-hide-small w3-bar-block\">"); string firstLink = null; foreach (var element in elements) { var id = element.Replace(".", string.Empty); if (firstLink == null) { firstLink = id; } writer.WriteLine($"<a href=\"#{id}\" id='{id}Link' class=\"elementLink w3-bar-item w3-button\">{element}</a>"); } WriteLoadFirstLink(writer, firstLink); writer.WriteLine("</div>"); writer.WriteLine("<div class=\"w3-container content-sidebar maincontent\">"); foreach (var element in elements) { writer.WriteLine($"<div class='element' id='{element.Replace(".", String.Empty)}Content' style='display:none'>"); writer.WriteLine($"<h1>{element}</h1>"); string path = $@"..\..\..\..\..\website\wwwroot\explorer\markdown\{element}.md"; if (File.Exists(path)) { string markdown = File.ReadAllText(path); writer.WriteLine(marked.Parse(markdown)); } foreach (var file in Directory.GetFiles($@"..\..\..\..\..\website\wwwroot\explorer\cards", element + "*.json").Where(f => f.Contains(element + "."))) { var name = Path.GetFileNameWithoutExtension(file); writer.WriteLine($"<h2 onclick='toggleContent(\"{name}Content\")'>{name}</h2>"); writer.WriteLine($"<div id='{name}Content' style='display:block'>"); var json = File.ReadAllText(file, Encoding.UTF8); writer.WriteLine($"<div id='{name}Card' class='card' ></div>"); writer.WriteLine($"<a class='trymelink' target='_blank' href='/visualizer?card=/explorer/cards/{Path.GetFileName(file)}'>Try it Yourself »</a>"); writer.WriteLine($"</div><script>renderCard('{name}Card', {json});</script>"); } writer.WriteLine($"</div>"); } writer.WriteLine("</div>"); writer.WriteLine("</body></html>"); writer.Flush(); } }
public IActionResult PostEdit(string id, string newId, string content, string tags, bool isPage, string title, Guid?catalog) { var post = DB.Posts .Include(x => x.Tags) .Where(x => x.Url == id) .SingleOrDefault(); if (post == null) { return(Prompt(new Prompt { StatusCode = 404, Title = SR["Not Found"], Details = SR["The resources have not been found, please check your request."], RedirectUrl = Url.Link("default", new { controller = "Home", action = "Index" }), RedirectText = SR["Back to home"] })); } var summary = ""; var tmp = content.Split('\n'); if (tmp.Count() > 16) { for (var i = 0; i < 16; i++) { summary += tmp[i] + '\n'; } summary += $"\r\n[{SR["Read More"]} »](/post/{newId})"; } else { summary = content; } foreach (var t in post.Tags) { DB.PostTags.Remove(t); } post.Url = newId; post.Summary = summary; post.Title = title; post.Content = content; post.CatalogId = catalog; post.IsPage = isPage; if (!string.IsNullOrEmpty(tags)) { var _tags = tags.Split(','); foreach (var t in _tags) { post.Tags.Add(new PostTag { PostId = post.Id, Tag = t.Trim(' ') }); } } DB.SaveChanges(); return(Content(Marked.Parse(content))); }
private static TextBlock CreateControl(AdaptiveTextBlock textBlock, AdaptiveRenderContext context) { Marked marked = new Marked(); marked.Options.Renderer = new AdaptiveXamlMarkdownRenderer(); marked.Options.Mangle = false; marked.Options.Sanitize = true; string text = RendererUtilities.ApplyTextFunctions(textBlock.Text); // uiTextBlock.Text = textBlock.Text; string xaml = $"<TextBlock xmlns=\"http://schemas.microsoft.com/winfx/2006/xaml/presentation\">{marked.Parse(text)}</TextBlock>"; StringReader stringReader = new StringReader(xaml); XmlReader xmlReader = XmlReader.Create(stringReader); var uiTextBlock = (System.Windows.Controls.TextBlock)XamlReader.Load(xmlReader); uiTextBlock.Style = context.GetStyle($"Adaptive.{textBlock.Type}"); uiTextBlock.FontFamily = new FontFamily(context.Config.FontFamily); uiTextBlock.TextWrapping = TextWrapping.NoWrap; switch (textBlock.Weight) { case AdaptiveTextWeight.Bolder: uiTextBlock.FontWeight = FontWeight.FromOpenTypeWeight(700); break; case AdaptiveTextWeight.Lighter: uiTextBlock.FontWeight = FontWeight.FromOpenTypeWeight(300); break; case AdaptiveTextWeight.Default: default: uiTextBlock.FontWeight = FontWeight.FromOpenTypeWeight(400); break; } uiTextBlock.TextTrimming = TextTrimming.CharacterEllipsis; if (textBlock.HorizontalAlignment != AdaptiveHorizontalAlignment.Left) { System.Windows.HorizontalAlignment alignment; if (Enum.TryParse <System.Windows.HorizontalAlignment>(textBlock.HorizontalAlignment.ToString(), out alignment)) { uiTextBlock.HorizontalAlignment = alignment; } } if (textBlock.Wrap) { uiTextBlock.TextWrapping = TextWrapping.Wrap; } return(uiTextBlock); }
public static Sym FromMarked(Marked <int, bool> element) { if (element.Mark) { return(new SymDivs(1, element.Element, 0, 0)); } else { return(new SymLoose(element.Element)); } }
public static MarkedModel Map(Marked marked, IUrlHelper url) { return(new MarkedModel { Url = url.Link(Config.MarkedRoute, new { id = marked.MarkedId }), MarkedId = marked.MarkedId, SovaUserId = marked.SovaUserId, PostId = marked.PostId, Note = marked.Note, Date = marked.Date }); }
private static TextBlock CreateControl(AdaptiveTextBlock textBlock, AdaptiveRenderContext context) { Marked marked = new Marked(); marked.Options.Renderer = new AdaptiveXamlMarkdownRenderer(); marked.Options.Mangle = false; marked.Options.Sanitize = true; string text = RendererUtilities.ApplyTextFunctions(textBlock.Text, context.Lang); // uiTextBlock.Text = textBlock.Text; string xaml = $"<TextBlock xmlns=\"http://schemas.microsoft.com/winfx/2006/xaml/presentation\">{marked.Parse(text)}</TextBlock>"; StringReader stringReader = new StringReader(xaml); XmlReader xmlReader = XmlReader.Create(stringReader); var uiTextBlock = (System.Windows.Controls.TextBlock)XamlReader.Load(xmlReader); uiTextBlock.Style = context.GetStyle($"Adaptive.{textBlock.Type}"); uiTextBlock.TextWrapping = TextWrapping.NoWrap; uiTextBlock.FontFamily = new FontFamily(RendererUtil.GetFontFamilyFromList(context.Config.GetFontFamily(textBlock.FontType))); uiTextBlock.FontWeight = FontWeight.FromOpenTypeWeight(context.Config.GetFontWeight(textBlock.FontType, textBlock.Weight)); uiTextBlock.FontSize = context.Config.GetFontSize(textBlock.FontType, textBlock.Size); uiTextBlock.TextTrimming = TextTrimming.CharacterEllipsis; if (textBlock.Italic) { uiTextBlock.FontStyle = FontStyles.Italic; } if (textBlock.Strikethrough) { uiTextBlock.TextDecorations = TextDecorations.Strikethrough; } if (textBlock.HorizontalAlignment != AdaptiveHorizontalAlignment.Left) { System.Windows.TextAlignment alignment; if (Enum.TryParse <System.Windows.TextAlignment>(textBlock.HorizontalAlignment.ToString(), out alignment)) { uiTextBlock.TextAlignment = alignment; } } if (textBlock.Wrap) { uiTextBlock.TextWrapping = TextWrapping.Wrap; } return(uiTextBlock); }
public string Get(string file) { var path = Path.Combine(_env.WebRootPath, file.Replace("/", "\\")); Marked marked = new Marked(); marked.Options.Renderer = new CodeMarkdown(); var text = System.IO.File.ReadAllText(path); HttpContext.Response.ContentType = "text/html"; return(marked.Parse(text)); }
public static IEnumerable <HtmlTag> Convert(string markdown) { var marked = new Marked(); marked.Options.Mangle = false; marked.Options.Sanitize = true; marked.Options.XHtml = true; var rawXhtml = marked.Parse(markdown); var root = XElement.Parse($"<root>{rawXhtml}</root>"); return(root.Elements().Select(RawXhtmlToHtmlTag)); }
/// <summary> /// Funkcja haszująca. /// </summary> /// <returns></returns> public override int GetHashCode() { return(Format.GetHashCode() + Marked.GetHashCode() + Style.GetHashCode() + Name.GetHashCode() + MarginL.GetHashCode() + MarginR.GetHashCode() + MarginV.GetHashCode() + Effect.GetHashCode() + Text.GetHashCode() + base.GetHashCode()); }
static void Main(string[] args) { string header; using (Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream("GenerateSamples.Header.txt")) using (StreamReader reader = new StreamReader(stream)) { header = reader.ReadToEnd(); } Marked marked = new Marked(); GenerateSchemaExplorerPage(header, marked); GenerateSamplesPage(header); }
public IActionResult ThreadContent(long id) { var thread = DB.Threads .Where(x => x.Id == id) .Select(x => x.Content) .SingleOrDefault(); if (thread == null) { return(Content("")); } else { return(Content(Marked.Parse(thread))); } }
public string ReadFile(string path) { //reading file in try { string text = File.ReadAllText(path); var marked = new Marked(); var html = marked.Parse(text); return(html); } catch (Exception) { return("Tiedosto puuttuu"); } }
public static bool Save(string ExampleId, string SubcategoryId, string SentenceId, string EntityId) { var int_ExampleId = Convert.ToInt32(ExampleId); var int_SubcategoryId = Convert.ToInt32(SubcategoryId); using (var db = new MLEEntities()) { var Marked = new Marked() { ExampleId = int_ExampleId, SubcategoryId = int_SubcategoryId, }; db.Marked.Add(Marked); db.SaveChanges(); return(true); } }
/// <summary> /// Toggles the <see cref="MarkedState"/> of this tile and raises the <see cref="Marked"/> event. /// </summary> private void OnTileToggledMark() { // Toggle the marked state based on the current marked state if (MarkedState == TileMarkedState.Unmarked) { MarkedState = TileMarkedState.Flag; } else if (MarkedState == TileMarkedState.Flag) { MarkedState = TileMarkedState.QuestionMark; } else { MarkedState = TileMarkedState.Unmarked; } // And raise the event that the tile has been marked Marked?.Invoke(this, new TileMarkedEventArgs(MarkedState)); }
private void LoadMdPaths() { Marked marked = new Marked(); string path = AppDomain.CurrentDomain.BaseDirectory + "api.md"; string txt = File.ReadAllText(path); string[] lines = File.ReadAllLines(path); List <string> urls = new List <string>(); foreach (string line in lines) { if (line.Trim().StartsWith("http:")) { urls.Add(line.Trim()); } } string result = marked.Parse(txt); DataGrid1.ItemsSource = urls; }
public Sym Prepare(Marked <int, bool> element) => Sym.FromMarked(element);
public virtual void SetUp() { _marked = new Marked(); }
public async Task <bool> Update(Marked entity) { _db.MarkedList.Update(entity); return(await Save()); }
public async Task <bool> Delete(Marked entity) { _db.MarkedList.Remove(entity); return(await Save()); }
public async Task <bool> Create(Marked entity) { await _db.MarkedList.AddAsync(entity); return(await Save()); }
public void TossMarkedAt(int i) => Inbox.RemoveAt(Inbox.IndexOf(Marked.ElementAt(i)));
public static bool MarkEntity(string EntityId, string ExampleId, string SentenceId, string SubcategoryId, string InputText, bool isChecked) { var Int_EntityId = Convert.ToInt32(EntityId); var Int_ExampleId = Convert.ToInt32(ExampleId); var Int_SentenceId = Convert.ToInt32(SentenceId); var Int_SubcategoryId = Convert.ToInt32(SubcategoryId); var user = LoginHelper.GetUserId(); if (user == 0) { return(false); } using (var db = new MLEEntities()) { var catId = db.Subcategory.FirstOrDefault(x => x.Id == Int_SubcategoryId).CategoryId; var ExampleCategory = db.ExampleCategory.FirstOrDefault(x => x.ExampleId == Int_ExampleId && x.CategoryId == catId); if (ExampleCategory != null) { var ml = db.Marked.Include(x => x.Example.ExampleCategory).Where(x => x.ExampleId == Int_ExampleId /*&& x.SubcategoryId == Int_SubcategoryId*/ && x.EntityId == null && x.SentenceId == null).ToList(); if (ml.Count > 0) { var subs = db.Subcategory.Where(x => x.CategoryId == catId).Select(x => x.Id).ToList(); var _m = ml.Where(x => subs.Contains(x.SubcategoryId.Value)).ToList(); if (_m.Count > 0) { //var _ = ml.FirstOrDefault(x => x.SubcategoryId == Int_SubcategoryId); var m = _m.FirstOrDefault(); var typeId = m.Example.ExampleCategory.FirstOrDefault(x => x.CategoryId == catId).TypeId; var type = db.Type.FirstOrDefault(x => x.Id == typeId); if (type.HTML_name == "radio") { m.SubcategoryId = Int_SubcategoryId; db.SaveChanges(); } else if (type.HTML_name == "checkbox") { if (isChecked) { var _ = new Marked() { EntityId = null, ExampleId = Int_ExampleId, SentenceId = null, SubcategoryId = Int_SubcategoryId, UserId = user, Text = InputText }; db.Marked.Add(_); db.SaveChanges(); } else { m = _m.FirstOrDefault(x => x.SubcategoryId == Int_SubcategoryId); db.Marked.Remove(m); db.SaveChanges(); } } else if (type.HTML_name == "text") { m.Text = InputText; db.SaveChanges(); } } else { var _ = new Marked() { EntityId = null, ExampleId = Int_ExampleId, SentenceId = null, SubcategoryId = Int_SubcategoryId != 0 ? Int_SubcategoryId : (int?)null, UserId = user, Text = InputText }; db.Marked.Add(_); db.SaveChanges(); } } else { var _ = new Marked() { EntityId = null, ExampleId = Int_ExampleId, SentenceId = null, SubcategoryId = Int_SubcategoryId != 0 ? Int_SubcategoryId : (int?)null, UserId = user, Text = InputText }; db.Marked.Add(_); db.SaveChanges(); } return(false); } else { var ml = db.Marked.Include(x => x.Example.Type).Where(x => x.EntityId == Int_EntityId && x.ExampleId == Int_ExampleId && x.SentenceId == Int_SentenceId && x.UserId == user).ToList(); var ml_U = db.Marked.Include(x => x.Example.Type).FirstOrDefault(x => x.EntityId == Int_EntityId && x.ExampleId == Int_ExampleId && x.SentenceId == Int_SentenceId && x.UserId == null); if (ml.Count > 0) { var m = ml.FirstOrDefault(); var type = m.Example.Type; if (type.HTML_name == "radio") { if (m.SubcategoryId == Int_SubcategoryId) { // provjera ako je automatski unos if (ml_U == null) { db.Marked.Remove(m); } else { m.SubcategoryId = null; } } else { m.SubcategoryId = Int_SubcategoryId; } db.SaveChanges(); } else if (type.HTML_name == "checkbox") { if (isChecked) { var _ = new Marked() { EntityId = Int_EntityId, ExampleId = Int_ExampleId, SentenceId = Int_SentenceId, SubcategoryId = Int_SubcategoryId, UserId = user, Text = InputText }; db.Marked.Add(_); db.SaveChanges(); } else { m = ml.FirstOrDefault(x => x.SubcategoryId == Int_SubcategoryId); db.Marked.Remove(m); db.SaveChanges(); } } else if (type.HTML_name == "text") { m.Text = InputText; db.SaveChanges(); } } else { int?subcategory = Int_SubcategoryId; if (ml_U != null) { subcategory = null; } var _ = new Marked() { EntityId = Int_EntityId, ExampleId = Int_ExampleId, SentenceId = Int_SentenceId, SubcategoryId = subcategory != 0 ? subcategory : null, UserId = user, Text = InputText }; db.Marked.Add(_); db.SaveChanges(); } return(true); } } }
private async Task TokenizationAsync(FileHelper.Config config, List <FileHelper.FileProcess> fp) { var responseString = ""; int?ProjectID = null; int?CategoryForWords = null; int?TypeForWords = null; var ExampleCategory = new List <ExampleCategory>(); using (var db = new MLEEntities()) { var project = new Project(); project.Name = config.Project; project.PerPage = config.PerPage; project.Description = "Automatic upload (ZIP)"; project.DateCreated = DateTime.Now; project.Start_Date = DateTime.Now; project.StatusId = 3; project.IsActive = true; db.Project.Add(project); db.SaveChanges(); ProjectID = project.Id; ProcessCategory(db, config.LabelingScheme.ForWords, ref TypeForWords, ref CategoryForWords); foreach (var item in config.LabelingScheme.ForExample) { int?TypeForExample = 0, CategoryForExample = 0; ProcessCategory(db, item, ref TypeForExample, ref CategoryForExample); ExampleCategory.Add(new DB.ExampleCategory { TypeId = TypeForExample, CategoryId = CategoryForExample }); } } var counter = 0; var list = fp.Where(x => x.Name != "config.txt").OrderBy(x => x.Name.Length).ThenBy(c => c.Name).ToList(); foreach (var e in list) { counter++; var fname = e.Name; var file = fp.FirstOrDefault(x => x.Name == fname); //var path = Server.MapPath("/DataImport/export/" + e.FileName); if (file != null) { var content = POSTOptions(file.Text, false); var response = await client.PostAsync("http://tasservice.s11.novenaweb.info:7777/rest/break-to-sentences", content); //var response = await client.PostAsync("http://tasservice.s11.novenaweb.info:7777/rest/lemmatizes-sentence", content); responseString = await response.Content.ReadAsStringAsync(); if (responseString != "") { using (var db = new MLEEntities()) { var fileIsAlreadyInDB = db.Example.Where(x => x.FileName == fname && x.ProjectId == ProjectID).FirstOrDefault() != null ? true : false; if (!fileIsAlreadyInDB) { var er = JsonConvert.DeserializeObject <ExampleResponse>(responseString); var example = new Example { FileName = fname, //Content = t, Description = "Automatic upload (ZIP)", DateCreated = DateTime.Now, StatusId = 3, // U tijeku ProjectId = ProjectID, OrdinalNumber = counter, // Left sidebar TypeId = TypeForWords, CategoryId = CategoryForWords, }; db.Example.Attach(example); db.Example.Add(example); db.SaveChanges(); // Right sidebar - Fill Example Categories foreach (var item in ExampleCategory) { var ec = new ExampleCategory(); ec.ExampleId = example.Id; ec.CategoryId = item.CategoryId; ec.TypeId = item.TypeId; db.ExampleCategory.Add(ec); db.SaveChanges(); } string t = ""; int startIndex = 0; int endIndex = 0; for (int i = 0; i < er.BreakToSentencesRESTResult.Count(); i++) { t += "<span id='Content_" + example.Id + "_" + (i + 1) + "'>"; var doc = new HtmlAgilityPack.HtmlDocument(); doc.LoadHtml(er.BreakToSentencesRESTResult[i]); var nodes = doc.DocumentNode.SelectNodes("//span"); var c = POSTOptions(er.BreakToSentencesRESTResult[i], nodes.Count > 0 ? true : false); var r = await client.PostAsync("http://tasservice.s11.novenaweb.info:7777/rest/tokenize-sentence", c); var rs = await r.Content.ReadAsStringAsync(); var sr = JsonConvert.DeserializeObject <SentenceResponse>(rs); for (int j = 0; j < sr.TokenizeSentenceRESTResult.Count(); j++) { var exampleID = example.Id; var sentenceID = i + 1; var entityID = j + 1; var spaceBefore = "<span> </span>"; var spaceAfter = ""; var regex = new Regex(@"[^\w\s]"); int addon = 0; if (j == 0) { spaceBefore = ""; addon = 1; } if (regex.Matches(sr.TokenizeSentenceRESTResult[j]).Count == sr.TokenizeSentenceRESTResult[j].Length) { spaceBefore = ""; } if (j == sr.TokenizeSentenceRESTResult.Count() - 1) { spaceAfter = "<span> </span>"; } endIndex = startIndex + sr.TokenizeSentenceRESTResult[j].Length; var current_text = sr.TokenizeSentenceRESTResult[j]; var htmldoc = new HtmlAgilityPack.HtmlDocument(); htmldoc.LoadHtml(sr.TokenizeSentenceRESTResult[j]); var node = htmldoc.DocumentNode.SelectSingleNode("//span"); if (node != null) { current_text = node.InnerHtml; var _class = node.GetClasses().First(); //CategoryForWords var sc = db.Subcategory.FirstOrDefault(x => x.CategoryId == CategoryForWords && x.Name == _class); if (sc != null) { var m = new Marked() { ExampleId = exampleID, SentenceId = sentenceID, EntityId = entityID, SubcategoryId = sc.Id, UserId = null, Text = "" }; db.Marked.Add(m); db.SaveChanges(); } } t += spaceBefore + "<span id='Content_" + exampleID + "_" + sentenceID + "_" + entityID + "' data-startIndex='" + startIndex + "' data-endIndex='" + endIndex + "'>" + current_text + "</span>" + spaceAfter; var sb = spaceBefore == "<span> </span>" ? 1 : 0; var sa = spaceAfter == "<span> </span>" ? 1 : 0; // next start index startIndex = endIndex + sb + sa + addon; } t += "</span>"; } db.Example.Attach(example); example.Content = t; db.SaveChanges(); UploadSuccessful++; } else { UploadExists++; } } } else { UploadError++; } } else { UploadError++; } } }