public static async Task <object> ParseAsync(IParseManager parseManager) { var pageInfo = parseManager.PageInfo; var contextInfo = parseManager.ContextInfo; var listInfo = await ListInfo.GetListInfoAsync(parseManager, ParseType.Content); var dataSource = await GetContentsDataSourceAsync(parseManager, listInfo); if (parseManager.ContextInfo.IsStlEntity) { return(ParseEntity(dataSource)); } var innerHtml = await ParseAsync(parseManager, listInfo, dataSource); var parsedContent = string.Empty; if (pageInfo.EditMode == EditMode.Visual) { var elementId = StringUtils.GetElementId(); var attributes = new NameValueCollection(); VisualUtility.AddEditableToAttributes(attributes, elementId, contextInfo.ElementName); parsedContent = @$ "<div {TranslateUtils.ToAttributesString(attributes)}>{innerHtml}</div>"; VisualUtility.AddEditableToPage(pageInfo, elementId, contextInfo, parsedContent); } else { parsedContent = innerHtml; } return(parsedContent); }
private static async Task <string> ParseAsync(IParseManager parseManager, NameValueCollection attributes) { var pageInfo = parseManager.PageInfo; var contextInfo = parseManager.ContextInfo; var parsedContent = string.Empty; if (!string.IsNullOrEmpty(contextInfo.InnerHtml)) { var innerBuilder = new StringBuilder(contextInfo.InnerHtml); await parseManager.ParseInnerContentAsync(innerBuilder); parsedContent = innerBuilder.ToString(); } if (pageInfo.EditMode == EditMode.Visual) { var editable = VisualUtility.GetEditable(pageInfo, contextInfo); var editableAttributes = VisualUtility.GetEditableAttributes(editable); foreach (var key in editableAttributes.AllKeys) { attributes[key] = editableAttributes[key]; } attributes["id"] = editable.Id; attributes["contenteditable"] = "true"; } return(@$ "<div {TranslateUtils.ToAttributesString(attributes)}>{parsedContent}</div>"); }
public static async Task <object> ParseAsync(IParseManager parseManager) { var pageInfo = parseManager.PageInfo; var contextInfo = parseManager.ContextInfo; var listInfo = await ListInfo.GetListInfoAsync(parseManager, ParseType.Content); var dataSource = await GetContentsDataSourceAsync(parseManager, listInfo); if (parseManager.ContextInfo.IsStlEntity) { return(ParseEntity(dataSource)); } var parsedContent = await ParseAsync(parseManager, listInfo, dataSource); if (pageInfo.EditMode == EditMode.Visual) { var editable = VisualUtility.GetEditable(pageInfo, contextInfo); var editableAttributes = VisualUtility.GetEditableAttributes(editable); return(@$ "<div {TranslateUtils.ToAttributesString(editableAttributes)}>{parsedContent}</div>"); } return(parsedContent); }
private void createThumbnail() { if (!SelectedItem.HasValue) { return; } try { var oldLink = this.newLinks.KeyValues .Select(x => x.Value) .FirstOrDefault(link => link.Version == SelectedVersion); thumbnailManagementService.CreateAndLinkThumbnail(SelectedItem.Value, fs => { var ratio = ViewportControl.ActualHeight / ViewportControl.ActualWidth; var res = 400; var source = VisualUtility.CreateBitmap(ViewportControl, res, res * ratio); BitmapEncoder encoder = new PngBitmapEncoder(); encoder.Frames.Add(BitmapFrame.Create(source)); encoder.Save(fs); fs.Close(); }, out var file, out var link, oldLink); this.newLinks.AddOrUpdate(link.Apply()); } catch (Exception ex) { notificationCenter.CreateSingleTaskJob(out var proc, "thumbnail creation failed"); proc.Title = "exception: "; proc.Details = ex.ToString(); } }
internal void UpdatePosition(VEMap map) { if (provider == null) { if (this.ContentTemplate != null) { DependencyObject depObj = VisualUtility.GetChildByType(this, typeof(ILocationProvider)); provider = depObj as ILocationProvider; } if (provider == null && this.Content != null) { provider = this.Content as ILocationProvider; } if (provider == null) { return; } } Canvas.SetZIndex(this, provider.GetZIndex()); Point?position = provider.UpdatePosition(map); if (!position.HasValue) { Canvas.SetLeft(this, -10000); Canvas.SetTop(this, -10000); return; } Canvas.SetLeft(this, position.Value.X); Canvas.SetTop(this, position.Value.Y); }
private static async Task <string> ParseAsync(IParseManager parseManager, NameValueCollection attributes) { var pageInfo = parseManager.PageInfo; var contextInfo = parseManager.ContextInfo; var innerHtml = string.Empty; if (!string.IsNullOrEmpty(contextInfo.InnerHtml)) { var innerBuilder = new StringBuilder(contextInfo.InnerHtml); await parseManager.ParseInnerContentAsync(innerBuilder); innerHtml = innerBuilder.ToString(); } var parsedContent = string.Empty; if (pageInfo.EditMode == EditMode.Visual) { var elementId = StringUtils.GetElementId(); VisualUtility.AddEditableToAttributes(attributes, elementId, contextInfo.ElementName); parsedContent = GetParsedContent(attributes, innerHtml); VisualUtility.AddEditableToPage(pageInfo, elementId, contextInfo, parsedContent); } else { parsedContent = GetParsedContent(attributes, innerHtml); } return(parsedContent); }
public static void RegisterEvents(FrameworkElement root) { Window window = VisualUtility.FindVisualParent <Window>(root); if (window == null) { throw new ArgumentException("Cannot register events without a window in the visual tree"); } TouchHandler handler = new TouchHandler(window); handler.TouchDown += TouchDown; handler.TouchMove += TouchMove; handler.TouchUp += TouchUp; }
private static void PreviewMouseWheel(object sender, MouseWheelEventArgs e) { if (!(sender is DataGrid dataGrid)) { return; } bool shiftWheelScrollsHorizontally = GetShiftWheelScrollsHorizontally(dataGrid); if (shiftWheelScrollsHorizontally) { if (Keyboard.Modifiers == ModifierKeys.Shift) { var childScrollViewer = VisualUtility.GetVisualChildCollection <ScrollViewer>(dataGrid).FirstOrDefault(); // scroll by 6 lines for (int i = 6; i > 0; --i) { if (e.Delta < 0) { childScrollViewer?.LineLeft(); } else { childScrollViewer?.LineRight(); } } e.Handled = true; return; } } bool ignoreScroll = GetIgnoreScroll(dataGrid); if (ignoreScroll) { var e2 = new MouseWheelEventArgs(e.MouseDevice, e.Timestamp, e.Delta) { RoutedEvent = UIElement.MouseWheelEvent }; dataGrid.RaiseEvent(e2); e.Handled = true; return; } }
private static async Task <string> ParseAsync(IParseManager parseManager, NameValueCollection attributes) { var pageInfo = parseManager.PageInfo; var contextInfo = parseManager.ContextInfo; var innerHtml = string.Empty; if (!string.IsNullOrEmpty(contextInfo.InnerHtml)) { var innerBuilder = new StringBuilder(contextInfo.InnerHtml); await parseManager.ParseInnerContentAsync(innerBuilder); innerHtml = innerBuilder.ToString(); } if (pageInfo.EditMode == EditMode.Visual) { VisualUtility.AddEditableToPage(pageInfo, contextInfo, attributes, innerHtml); } return(@$ "<div {TranslateUtils.ToAttributesString(attributes)}>{innerHtml}</div>"); }
private static async Task <object> ParseAsync(IParseManager parseManager, NameValueCollection attributes, bool isGetPicUrlFromAttribute, string channelIndex, string channelName, int upLevel, int topLevel, string type, int no, bool isOriginal, bool isClearTags, string src, string altSrc) { var databaseManager = parseManager.DatabaseManager; var pageInfo = parseManager.PageInfo; var contextInfo = parseManager.ContextInfo; var contentId = 0; if (!isGetPicUrlFromAttribute) { contentId = contextInfo.ContentId; } var contextType = contextInfo.ContextType; var picUrl = string.Empty; if (!string.IsNullOrEmpty(src)) { picUrl = src; } else { if (contextType == ParseType.Undefined) { contextType = contentId != 0 ? ParseType.Content : ParseType.Channel; } if (contextType == ParseType.Content) { var contentInfo = await parseManager.GetContentAsync(); if (isOriginal) { if (contentInfo != null && contentInfo.ReferenceId > 0 && contentInfo.SourceId > 0) { var targetChannelId = contentInfo.SourceId; var targetSiteId = await databaseManager.ChannelRepository.GetSiteIdAsync(targetChannelId); var targetSite = await databaseManager.SiteRepository.GetAsync(targetSiteId); var targetNodeInfo = await databaseManager.ChannelRepository.GetAsync(targetChannelId); var targetContentInfo = await databaseManager.ContentRepository.GetAsync(targetSite, targetNodeInfo, contentInfo.ReferenceId); if (targetContentInfo != null && targetContentInfo.ChannelId > 0) { contentInfo = targetContentInfo; } } } if (contentInfo == null) { contentInfo = await databaseManager.ContentRepository.GetAsync(pageInfo.Site, contextInfo.ChannelId, contentId); } if (contentInfo != null) { if (no <= 1) { picUrl = contentInfo.Get <string>(type); } else { var extendName = ColumnsManager.GetExtendName(type, no - 1); picUrl = contentInfo.Get <string>(extendName); } } } else if (contextType == ParseType.Channel) //获取栏目图片 { var dataManager = new StlDataManager(parseManager.DatabaseManager); var channelId = await dataManager.GetChannelIdByLevelAsync(pageInfo.SiteId, contextInfo.ChannelId, upLevel, topLevel); channelId = await dataManager.GetChannelIdByChannelIdOrChannelIndexOrChannelNameAsync( pageInfo.SiteId, channelId, channelIndex, channelName); var channel = await databaseManager.ChannelRepository.GetAsync(channelId); if (no <= 1) { picUrl = channel.Get <string>(type); } else { var extendName = ColumnsManager.GetExtendName(type, no - 1); picUrl = channel.Get <string>(extendName); } } else if (contextType == ParseType.Each) { picUrl = contextInfo.ItemContainer.EachItem.Value as string; } } if (string.IsNullOrEmpty(picUrl)) { picUrl = altSrc; } if (string.IsNullOrEmpty(picUrl)) { return(string.Empty); } var extension = PathUtils.GetExtension(picUrl); if (FileUtils.IsFlash(extension)) { return(await StlPdf.ParseAsync(parseManager)); } if (FileUtils.IsPlayer(extension)) { return(await StlPlayer.ParseAsync(parseManager)); } picUrl = await parseManager.PathManager.ParseSiteUrlAsync(pageInfo.Site, picUrl, pageInfo.IsLocal); if (isClearTags || contextInfo.IsStlEntity) { return(picUrl); } attributes["src"] = picUrl; var parsedContent = string.Empty; if (pageInfo.EditMode == EditMode.Visual) { var elementId = StringUtils.GetElementId(); VisualUtility.AddEditableToAttributes(attributes, elementId, contextInfo.ElementName); parsedContent = GetParsedContent(attributes); VisualUtility.AddEditableToPage(pageInfo, elementId, contextInfo, parsedContent); } else { parsedContent = GetParsedContent(attributes); } return(parsedContent); }
private static async Task <string> ParseAsync(IParseManager parseManager, string channelIndex, string channelName, int upLevel, int topLevel, bool removeTarget, string href, string queryString, string host, string target, NameValueCollection attributes) { var databaseManager = parseManager.DatabaseManager; var pageInfo = parseManager.PageInfo; var contextInfo = parseManager.ContextInfo; var htmlId = attributes["id"]; if (!string.IsNullOrEmpty(htmlId) && !string.IsNullOrEmpty(contextInfo.ContainerClientId)) { htmlId = contextInfo.ContainerClientId + "_" + htmlId; } if (!string.IsNullOrEmpty(htmlId)) { attributes["id"] = htmlId; } var innerHtml = string.Empty; var url = string.Empty; var onclick = string.Empty; if (!string.IsNullOrEmpty(href)) { url = await parseManager.PathManager.ParseSiteUrlAsync(pageInfo.Site, href, pageInfo.IsLocal); var innerBuilder = new StringBuilder(contextInfo.InnerHtml); await parseManager.ParseInnerContentAsync(innerBuilder); innerHtml = innerBuilder.ToString(); } else { if (contextInfo.ContextType == ParseType.Undefined) { contextInfo.ContextType = contextInfo.ContentId != 0 ? ParseType.Content : ParseType.Channel; } if (contextInfo.ContextType == ParseType.Content) //获取内容Url { var contentInfo = await parseManager.GetContentAsync(); if (contentInfo != null) { url = await parseManager.PathManager.GetContentUrlAsync(pageInfo.Site, contentInfo, pageInfo.IsLocal); } else { var nodeInfo = await databaseManager.ChannelRepository.GetAsync(contextInfo.ChannelId); url = await parseManager.PathManager.GetContentUrlAsync(pageInfo.Site, nodeInfo, contextInfo.ContentId, pageInfo.IsLocal); } if (string.IsNullOrEmpty(contextInfo.InnerHtml)) { var title = contentInfo?.Title; title = ContentUtility.FormatTitle( contentInfo?.Get <string>("BackgroundContentAttribute.TitleFormatString"), title); if (pageInfo.Site.IsContentTitleBreakLine) { title = title.Replace(" ", string.Empty); } innerHtml = title; } else { var innerBuilder = new StringBuilder(contextInfo.InnerHtml); await parseManager.ParseInnerContentAsync(innerBuilder); innerHtml = innerBuilder.ToString(); } if (string.IsNullOrEmpty(target) && !string.IsNullOrEmpty(contentInfo?.LinkUrl)) { attributes["target"] = "_blank"; } } else if (contextInfo.ContextType == ParseType.Channel) //获取栏目Url { var dataManager = new StlDataManager(parseManager.DatabaseManager); contextInfo.ChannelId = await dataManager.GetChannelIdByLevelAsync(pageInfo.SiteId, contextInfo.ChannelId, upLevel, topLevel); contextInfo.ChannelId = await databaseManager.ChannelRepository.GetChannelIdAsync(pageInfo.SiteId, contextInfo.ChannelId, channelIndex, channelName); var channel = await databaseManager.ChannelRepository.GetAsync(contextInfo.ChannelId); url = await parseManager.PathManager.GetChannelUrlAsync(pageInfo.Site, channel, pageInfo.IsLocal); if (string.IsNullOrWhiteSpace(contextInfo.InnerHtml)) { innerHtml = channel.ChannelName; } else { var innerBuilder = new StringBuilder(contextInfo.InnerHtml); await parseManager.ParseInnerContentAsync(innerBuilder); innerHtml = innerBuilder.ToString(); } if (string.IsNullOrEmpty(target) && !string.IsNullOrEmpty(channel.LinkUrl)) { attributes["target"] = "_blank"; } } } if (url.Equals(PageUtils.UnClickableUrl)) { removeTarget = true; } else { if (!string.IsNullOrEmpty(host)) { url = PageUtils.AddProtocolToUrl(url, host); } if (!string.IsNullOrEmpty(queryString)) { url = PageUtils.AddQueryString(url, queryString); } } attributes["href"] = url; if (!string.IsNullOrEmpty(onclick)) { attributes["onclick"] = onclick; } if (removeTarget) { attributes["target"] = string.Empty; } // 如果是实体标签,则只返回url if (contextInfo.IsStlEntity) { return(url); } if (pageInfo.EditMode == EditMode.Visual) { VisualUtility.AddEditableToPage(pageInfo, contextInfo, attributes, innerHtml); } return($@"<a {TranslateUtils.ToAttributesString(attributes)}>{innerHtml}</a>"); }