private bool InsertSmartContentFromLiveClipboard(ContentSourceInfo contentSource, XmlDocument lcDocument) { SmartContentSource smartSource = contentSource.Instance as SmartContentSource; if (smartSource == null) { Trace.Fail("Unexpected failure to get live clipboard content-source!"); return(false); } // create the smart content IExtensionData extensionData = _contentSourceSite.CreateExtensionData(Guid.NewGuid().ToString()); ISmartContent smartContent = new SmartContent(extensionData); if (smartSource.CreateContentFromLiveClipboard(EditorContext.FrameWindow, lcDocument, smartContent) == DialogResult.OK) { // generate html and insert it string content = smartSource.GenerateEditorHtml(smartContent, _contentSourceSite); if (content != null) { _contentSourceSite.InsertContent(contentSource.Id, content, extensionData); return(true); } else { return(false); } } else { return(false); } }
internal void refreshableContentTimer_Tick(object sender, EventArgs e) { if (_extensionDataList.Count == 0) { _refreshableContentTimer.Stop(); return; } // Find only the smart content that is still inside the html IExtensionData extensionData = _extensionDataList.GetExtensionDataWithMinCallback(); if (extensionData == null) { _refreshableContentTimer.Stop(); Trace.Fail("RefreshableContentManager tick without any extensionData with a callback."); return; } Debug.Assert(extensionData.RefreshCallBack != null, "GetExtensionDataWithMinCallback returned an extensionData without a callback time"); extensionData.RefreshCallBack = null; IExtensionData[] missingExentinsionData = ((IContentSourceSite)_editor).UpdateContent(new IExtensionData[] { extensionData }); if (missingExentinsionData.Length == 0) { return; } Debug.Assert(missingExentinsionData.Length == 1, "Only one IExtensionData was supposed to update, but more then 1 was returned as being missing."); Debug.Assert(!_missedCallbackExtensionData.Contains(missingExentinsionData[0]), "We should not have tried to update smart content that was not in the editor."); _missedCallbackExtensionData.Add(missingExentinsionData[0]); }
private bool InsertSmartContentFromEmbed(string embed) { ContentSourceInfo contentSource = ContentSourceManager.FindContentSource(typeof(VideoContentSource)); if (contentSource != null) { SmartContentSource smartSource = contentSource.Instance as SmartContentSource; VideoContentSource videoSource = smartSource as VideoContentSource; IExtensionData extensionData = _contentSourceSite.CreateExtensionData(Guid.NewGuid().ToString()); ISmartContent smartContent = new SmartContent(extensionData); videoSource.CreateContentFromEmbed(embed, smartContent); // generate html and insert it string content = videoSource.GenerateEditorHtml(smartContent, _contentSourceSite); if (content != null) { _contentSourceSite.InsertContent(VideoContentSource.ID, content, extensionData); return(true); } else { Trace.Fail("Video Source content generated from embed tag was empty"); return(false); } } Trace.Fail("Cannot find the video plugin"); return(false); }
public IExtensionData[] CalculateReferencedExtensionData(string content) { Hashtable datas = new Hashtable(); ContentSourceManager.SmartContentPredicate predicate = new ContentSourceManager.SmartContentPredicate(); SimpleHtmlParser p = new SimpleHtmlParser(content); for (Element el; null != (el = p.Next());) { if (predicate.IsMatch(el)) { BeginTag bt = el as BeginTag; Attr idAttr = bt.GetAttribute("id"); if (idAttr != null) //Synchronized WP posts will strip ID attrs (bug 488143) { string smartContentSourceId; string smartContentId; string smartContentElementId = idAttr.Value; ContentSourceManager.ParseContainingElementId(smartContentElementId, out smartContentSourceId, out smartContentId); IExtensionData data = GetExtensionData(smartContentId); if (data != null) { datas[smartContentId] = data; } } } } return((IExtensionData[])ArrayHelper.CollectionToArray(datas.Values, typeof(IExtensionData))); }
/// <summary> /// Serializes the extension information of attributes of the specified extension data. /// </summary> /// <param name="data">The extension data that may contain attributes to serialize.</param> private void SerializeExtensionAttributes(IExtensionData data) { if ((data != null) && data.HasAttributes) { foreach (IExtensionAttribute attribute in data.GetAttributes()) { this.writer.WriteAttributeString(attribute.LocalName, attribute.Namespace, attribute.Value); } } }
/// <summary> /// Serializes the extension information of children of the specified extension data. /// </summary> /// <param name="data">The extension data that may contain children to serialize.</param> private void SerializeExtensionChildren(IExtensionData data) { if ((data != null) && data.HasChildren) { foreach (ElementInfo child in data.GetChildren()) { this.SerializeImpl(child.LocalName, child.Namespace, null, child.Element, null); } } }
public VideoSmartContentWaitOperation(ISynchronizeInvoke context, SmartContentOperationType checkType, IExtensionData[] extendionDataList) : base(context) { validState = VideoPublishStatus.Completed; invalidState = VideoPublishStatus.Error; if (checkType == SmartContentOperationType.Close) validState |= VideoPublishStatus.RemoteProcessing; _extensionDataList = extendionDataList; }
/// <summary> /// Clones active smart content contained in the provided HTML, and disables unknown smart content. /// </summary> public static string PrepareSmartContentHtmlForEditorInsertion(string html, IContentSourceSidebarContext sourceContext) { StringBuilder output = new StringBuilder(); ContentSourceManager.SmartContentPredicate predicate = new ContentSourceManager.SmartContentPredicate(); SimpleHtmlParser p = new SimpleHtmlParser(html); for (Element el; null != (el = p.Next());) { if (predicate.IsMatch(el)) { BeginTag bt = el as BeginTag; Attr idAttr = bt.GetAttribute("id"); String contentSourceId, contentItemId; ContentSourceManager.ParseContainingElementId(idAttr.Value, out contentSourceId, out contentItemId); ISmartContent smartContent = sourceContext.FindSmartContent(contentItemId); if (smartContent != null) { String newId = Guid.NewGuid().ToString(); sourceContext.CloneSmartContent(contentItemId, newId); if (RefreshableContentManager.ContentSourcesWithRefreshableContent.Contains(contentSourceId)) { IExtensionData extensionData = sourceContext.FindExtentsionData(newId); Debug.Assert(extensionData != null); // Since we just made a new id for the smart content just about to be inserted // we want to give it a chance to get a callback because its callback might have happened while // it was on the clipboard(in the event of cut). This means the refreshable content manager doesnt know // to watch out for this smart content on paste, it only knows to look out for who created it. Thus // we just force the callback, and if it didnt need it, nothing will happen. if (extensionData.RefreshCallBack == null) { extensionData.RefreshCallBack = DateTime.UtcNow; } } idAttr.Value = ContentSourceManager.MakeContainingElementId(contentSourceId, newId); } else { ContentSourceManager.RemoveSmartContentAttributes(bt); } } output.Append(el.ToString()); } return(output.ToString()); }
internal IExtensionData GetExtensionDataWithMinCallback() { DateTime minCallback = DateTime.MaxValue; IExtensionData minCallBackExtensionData = null; foreach (IExtensionData extensionData in _extensionData.Values) { if (extensionData.RefreshCallBack < minCallback) { minCallback = (DateTime)extensionData.RefreshCallBack; minCallBackExtensionData = extensionData; } } return(minCallBackExtensionData); }
void _extensionDataList_RefreshableCallbackTriggered(object sender, EventArgs e) { _refreshableContentTimer.Stop(); IExtensionData extensionData = _extensionDataList.GetExtensionDataWithMinCallback(); if (extensionData == null) { return; } Int32 refreshMillisec = Convert.ToInt32(extensionData.RefreshCallBack.Value.Subtract(DateTimeHelper.UtcNow).TotalMilliseconds); _refreshableContentTimer.Interval = Math.Max(refreshMillisec, INTERVAL_TICK); _refreshableContentTimer.Start(); }
public EditableSmartContent(IContentSourceSidebarContext context, SmartContentSource contentSource, IHTMLElement smartContentElement) { GC.SuppressFinalize(this); _contentSourceContext = context; _contentSource = contentSource; _smartContentElement = smartContentElement; ContentSourceManager.ParseContainingElementId(_smartContentElement.id, out _contentSourceId, out _smartContentId); _smartContent = _contentSourceContext.FindSmartContent(_smartContentId); _extensionData = _contentSourceContext.FindExtentsionData(_smartContentId); _properties = new EditableRootProperties(); _layout = new EditableLayoutStyle(); _supportingFiles = new EditableSupportingFiles(); MakeSmartContentEditable(); }
/// <summary> /// Adds an extension's data. /// </summary> /// <param name="extension">The extension data to add.</param> public void AddExtensionData(IExtensionData extension) { if (null != extension.TableDefinitions) { foreach (TableDefinition tableDefinition in extension.TableDefinitions) { try { this.TableDefinitions.Add(tableDefinition); } catch (ArgumentException) { Messaging.Instance.OnMessage(WixErrors.DuplicateExtensionTable(extension.GetType().ToString(), tableDefinition.Name)); } } } }
/// <summary> /// Adds an extension. /// </summary> /// <param name="extension">The extension to add.</param> public void AddExtensionData(IExtensionData extension) { if (null != extension.TableDefinitions) { foreach (TableDefinition tableDefinition in extension.TableDefinitions) { if (!this.tableDefinitions.Contains(tableDefinition.Name)) { this.tableDefinitions.Add(tableDefinition); } else { Messaging.Instance.OnMessage(WixErrors.DuplicateExtensionTable(extension.GetType().ToString(), tableDefinition.Name)); } } } }
private bool InsertSmartContentFromUrl(ContentSourceInfo contentSource, string url) { SmartContentSource smartSource = contentSource.Instance as SmartContentSource; string title = String.Empty; IExtensionData extensionData = _contentSourceSite.CreateExtensionData(Guid.NewGuid().ToString()); ISmartContent smartContent = new SmartContent(extensionData); if (UrlContentRetreivalWithProgress.ExecuteSmartContentRetreival( EditorContext.FrameWindow, contentSource, url, ref title, smartContent)) { string content = smartSource.GenerateEditorHtml(smartContent, _contentSourceSite); if (content != null) { _contentSourceSite.InsertContent(contentSource.Id, content, extensionData); } return(true); } else { return(false); } }
public static string GenerateContentBlock(string contentSourceId, string blockId, string content, IExtensionData exData) { return(SmartContentInsertionHelper.GenerateContentBlock(contentSourceId, blockId, content, (ISmartContent) new SmartContent(exData), null)); }
public SmartContentItem(string contentSourceId, IExtensionData extensionData) : this(contentSourceId, extensionData.Id, new SmartContent(extensionData)) { }
public InternalSmartContent(IExtensionData extensionData, IInternalSmartContentContextSource smartContentContextSource, string contentSourceId) : base(extensionData) { _smartContentContext = new InternalSmartContentContext(smartContentContextSource, contentSourceId); }
public static string GenerateContentBlock(string contentSourceId, string blockId, string content, IExtensionData exData) { return SmartContentInsertionHelper.GenerateContentBlock(contentSourceId, blockId, content, (ISmartContent)new SmartContent(exData), null); }
void IContentSourceSite.InsertContent(string contentSourceId, string content, IExtensionData extensionData, HtmlInsertionOptions insertionOptions) { //Insert gestures are only supported in the body, so force focus to the body FocusBody(); InsertContentBlock(contentSourceId, content, extensionData, insertionOptions); }
private void InsertContentBlock(string contentSourceId, string content, IExtensionData extensionData, HtmlInsertionOptions insertionOptions) { // generate a new unique id for this content block string blockId = extensionData.Id; using (new HtmlEditorControl.InitialInsertionNotify(_normalHtmlContentEditor)) { // insert the appropriate html InsertHtml(SmartContentInsertionHelper.GenerateContentBlock(contentSourceId, blockId, content, extensionData), insertionOptions); } }
IExtensionData[] IContentSourceSite.UpdateContent(IExtensionData[] extensionDataListOrginal) { IExtensionData[] extensionDataList = (IExtensionData[])extensionDataListOrginal.Clone(); // Find all the smart content in the list, and tell them to update. IHTMLElement2 postBodyElement = (IHTMLElement2)_normalHtmlContentEditor.PostBodyElement; if (postBodyElement != null) { foreach (IHTMLElement divElement in postBodyElement.getElementsByTagName("div")) { // Make sure that the div we have is a smart content, and that it isn't just a div that is part of smart content. if (divElement.className == null || divElement.id == null || divElement.className == ContentSourceManager.SMART_CONTENT || !ContentSourceManager.IsSmartContent(divElement)) continue; string contentSourceId = ""; string contentId = ""; // Get the contentid of the div smart content we have ContentSourceManager.ParseContainingElementId(divElement.id, out contentSourceId, out contentId); // Check to see if this smart content is one we want to update int index = ArrayHelper.SearchForIndexOf<string, IExtensionData>(extensionDataList, contentId, delegate (string a, IExtensionData b) { return b != null && a == b.Id; }); if (index == -1) continue; // The smart content we found in the DOM is also one we // want to update, so save a reference to it from the data list IExtensionData extensionData = extensionDataList[index]; // We remove it from the list, which at the end of the function will only // leave the IExtensionData that were not found in the editor. extensionDataList[index] = null; // Make a SmartContent for the element we are about to update, // this will allow the content source to get at the properties bag // for the smart content so it knows how to update the content SmartContent smartContent = new SmartContent(extensionData); IContentSourceSidebarContext sourceContext = this; // Find the content source that we will use to update the smart content ContentSourceInfo contentSourceInfo = sourceContext.FindContentSource(contentSourceId); // Make sure that we found one, and that is it indeed SmartContentSource if (contentSourceInfo != null && contentSourceInfo.Instance is SmartContentSource) { // Get the html that the content source wants to update the element with string newHtml = ((SmartContentSource)contentSourceInfo.Instance).GenerateEditorHtml(smartContent, this); // If the source for this smart content wants to filter some updates // give it a chance to right now. if (contentSourceInfo.Instance is IContentUpdateFilter) { if (!((IContentUpdateFilter)contentSourceInfo.Instance).ShouldUpdateContent(divElement.innerHTML, newHtml)) continue; } // If we are actually sure we want to update the element then we insert it // and wrap it in an invisible undo unit so it will undo the last change the user // made if they ctrl+z using (EditorUndoUnit undo = new EditorUndoUnit(_currentEditor, true)) { SmartContentInsertionHelper.InsertContentIntoElement(newHtml, smartContent, sourceContext, divElement); _htmlEditorSidebarHost.ForceUpdateSidebarState(); undo.Commit(); } } } } return (IExtensionData[])ArrayHelper.Compact(extensionDataList); }
public SmartContent(IExtensionData extensionData) { _extensionData = extensionData; }