private bool TermAlreadyLinked(string term, string url) { IHTMLElement2 bodyElement = (IHTMLElement2)_blogPostHtmlEditorControl.PostBodyElement; IHTMLElementCollection aElements = bodyElement.getElementsByTagName("a"); foreach (IHTMLElement aElement in aElements) { try { IHTMLAnchorElement anchor = aElement as IHTMLAnchorElement; if (anchor != null && aElement.innerText != null && aElement.innerText.ToLower(CultureInfo.CurrentCulture) == term.ToLower(CultureInfo.CurrentCulture) && anchor.href != null && anchor.href.TrimEnd('/') == url.TrimEnd('/')) { return(true); } } catch (COMException ex) { // Bug 624250: Swallow operation failed exception if (ex.ErrorCode != unchecked ((int)0x80004005)) { throw; } else { Trace.WriteLine(ex.ToString()); } } } return(false); }
/// <summary> /// Try to extract the EditUri (RSD file URI) from the passed DOM /// </summary> /// <param name="weblogDOM"></param> /// <returns></returns> private static string ExtractEditUri(string homepageUrl, IHTMLDocument2 weblogDOM) { // look in the first HEAD tag IHTMLElementCollection headElements = ((IHTMLDocument3)weblogDOM).getElementsByTagName("HEAD"); if (headElements.length > 0) { // get the first head element IHTMLElement2 firstHeadElement = (IHTMLElement2)headElements.item(0, 0); // look for link tags within the head foreach (IHTMLElement element in firstHeadElement.getElementsByTagName("LINK")) { IHTMLLinkElement linkElement = element as IHTMLLinkElement; if (linkElement != null) { string linkRel = linkElement.rel; if (linkRel != null && (linkRel.ToUpperInvariant().Equals("EDITURI"))) { return(UrlHelper.UrlCombineIfRelative(homepageUrl, linkElement.href)); } } } } // couldn't find one return(null); }
private static IEnumerable <IHTMLElement> FindUsername(IHTMLElement passwordElement) { IHTMLElement2 root = (IHTMLElement2)FindClosestForm(passwordElement); if (root == null) { root = passwordElement.document.Body; } if (root != null) { foreach (IHTMLElement htmlElement in root.getElementsByTagName("input")) { if (htmlElement != passwordElement) { string type = htmlElement.getAttribute("type"); if (type.ToUpper() != "TEXT" && type.ToUpper() != "EMAIL") { continue; } yield return(htmlElement); } } } }
public List <String> GetTdNodes(string TdClassName) { List <String> listOut = new List <string>(); IHTMLElement2 ie = (IHTMLElement2)oHtmlDoc.body; IHTMLElementCollection iec = (IHTMLElementCollection)ie.getElementsByTagName("td"); foreach (IHTMLElement item in iec) { if (item.className == TdClassName) { listOut.Add(item.innerHTML); } } return(listOut); }
public HtmlElementCollection GetElementsByTagName(string tagName) { if (_element != null) { IHTMLElement2 el2 = _element as IHTMLElement2; if (el2 != null) { IHTMLElementCollection value = el2.getElementsByTagName(tagName); if (value != null) { return(new MsHtmlElementCollection(value)); } } } return(new NetHtmlElementCollection()); }
private static IEnumerable <IHTMLElement> FindPassword(HTMLDocument document) { IHTMLElement2 body = (IHTMLElement2)document.body; foreach (IHTMLElement htmlElement in body.getElementsByTagName("input")) { string type = htmlElement.getAttribute("type"); if (string.IsNullOrEmpty(type)) { continue; } if (type.ToUpper() == "PASSWORD") { yield return(htmlElement); } } }
public static string DiscoverUrl(string homepageUrl, IHTMLDocument2 weblogDOM) { if (weblogDOM == null) { return(String.Empty); } try { // look in the first HEAD tag IHTMLElementCollection headElements = ((IHTMLDocument3)weblogDOM).getElementsByTagName("HEAD"); if (headElements.length > 0) { // get the first head element IHTMLElement2 firstHeadElement = (IHTMLElement2)headElements.item(0, 0); // look for link tags within the head foreach (IHTMLElement element in firstHeadElement.getElementsByTagName("LINK")) { IHTMLLinkElement linkElement = element as IHTMLLinkElement; if (linkElement != null) { string linkRel = linkElement.rel; if (linkRel != null && (linkRel.ToUpperInvariant().Equals("WLWMANIFEST"))) { if (linkElement.href != null && linkElement.href != String.Empty) { return(UrlHelper.UrlCombineIfRelative(homepageUrl, linkElement.href)); } } } } } } catch (Exception ex) { Trace.Fail("Unexpected error attempting to discover manifest URL: " + ex.ToString()); } // couldn't find one return(String.Empty); }
private static int GetElementIndex(IHTMLElement element) { IHTMLElement2 parentElement = element.parentElement as IHTMLElement2; if (null == parentElement) { return(0); } IHTMLElementCollection elementCollection = parentElement.getElementsByTagName(element.tagName); for (int i = 0; i < elementCollection.length; i++) { if (element == elementCollection.item(i)) { return(i); } } return(0); }
private void MatchingControlBookmarks(Stack <KeyValuePair <IHTMLDOMNode, PartBookmark> > controlMarkupStack, IHTMLDOMNode htmlNode) { IHTMLElement2 htmlElement = htmlNode as IHTMLElement2; IHTMLElementCollection anchors = htmlElement.getElementsByTagName("A"); foreach (IHTMLElement anchor in anchors) { PartBookmark bookmark = ParseToPartBookmark(anchor); if (bookmark != null && bookmark.IsControlBookmark) { IHTMLDOMNode node = anchor as IHTMLDOMNode; if (controlMarkupStack.Count == 0) { controlMarkupStack.Push(new KeyValuePair <IHTMLDOMNode, PartBookmark>(node, bookmark)); } else { KeyValuePair <IHTMLDOMNode, PartBookmark> previous = controlMarkupStack.Peek(); bool isMatch = (previous.Value.Type == BookmarkType.StartForeach && bookmark.Type == BookmarkType.EndForeach) || (previous.Value.Type == BookmarkType.StartIf && bookmark.Type == BookmarkType.EndIf); isMatch = isMatch && previous.Key.parentNode == node.parentNode; if (isMatch) { controlMarkupStack.Pop(); } else { controlMarkupStack.Push(new KeyValuePair <IHTMLDOMNode, PartBookmark>(node, bookmark)); } } } } }
private static List <NewImageInfo> ScanImages(IBlogPostHtmlEditor currentEditor, IEditorAccount editorAccount, ContentEditor editor, bool useDefaultTargetSettings) { List <NewImageInfo> newImages = new List <NewImageInfo>(); ApplicationPerformance.ClearEvent("InsertImage"); ApplicationPerformance.StartEvent("InsertImage"); using (new WaitCursor()) { IHTMLElement2 postBodyElement = (IHTMLElement2)((BlogPostHtmlEditorControl)currentEditor).PostBodyElement; if (postBodyElement != null) { foreach (IHTMLElement imgElement in postBodyElement.getElementsByTagName("img")) { string imageSrc = imgElement.getAttribute("srcDelay", 2) as string; if (string.IsNullOrEmpty(imageSrc)) { imageSrc = imgElement.getAttribute("src", 2) as string; } // WinLive 96840 - Copying and pasting images within shared canvas should persist source // decorator settings. "wlCopySrcUrl" is inserted while copy/pasting within canvas. bool copyDecoratorSettings = false; string attributeCopySrcUrl = imgElement.getAttribute("wlCopySrcUrl", 2) as string; if (!string.IsNullOrEmpty(attributeCopySrcUrl)) { copyDecoratorSettings = true; imgElement.removeAttribute("wlCopySrcUrl", 0); } // Check if we need to apply default values for image decorators bool applyDefaultDecorator = true; string attributeNoDefaultDecorator = imgElement.getAttribute("wlNoDefaultDecorator", 2) as string; if (!string.IsNullOrEmpty(attributeNoDefaultDecorator) && string.Compare(attributeNoDefaultDecorator, "TRUE", StringComparison.OrdinalIgnoreCase) == 0) { applyDefaultDecorator = false; imgElement.removeAttribute("wlNoDefaultDecorator", 0); } string applyDefaultMargins = imgElement.getAttribute("wlApplyDefaultMargins", 2) as string; if (!String.IsNullOrEmpty(applyDefaultMargins)) { DefaultImageSettings defaultImageSettings = new DefaultImageSettings(editorAccount.Id, editor.DecoratorsManager); MarginStyle defaultMargin = defaultImageSettings.GetDefaultImageMargin(); // Now apply it to the image imgElement.style.marginTop = String.Format(CultureInfo.InvariantCulture, "{0} px", defaultMargin.Top); imgElement.style.marginLeft = String.Format(CultureInfo.InvariantCulture, "{0} px", defaultMargin.Left); imgElement.style.marginBottom = String.Format(CultureInfo.InvariantCulture, "{0} px", defaultMargin.Bottom); imgElement.style.marginRight = String.Format(CultureInfo.InvariantCulture, "{0} px", defaultMargin.Right); imgElement.removeAttribute("wlApplyDefaultMargins", 0); } if ((UrlHelper.IsFileUrl(imageSrc) || IsFullPath(imageSrc)) && !ContentSourceManager.IsSmartContent(imgElement)) { Uri imageSrcUri = new Uri(imageSrc); try { BlogPostImageData imageData = BlogPostImageDataList.LookupImageDataByInlineUri(editor.ImageList, imageSrcUri); Emoticon emoticon = EmoticonsManager.GetEmoticon(imgElement); if (imageData == null && emoticon != null) { // This is usually an emoticon copy/paste and needs to be cleaned up. Uri inlineImageUri = editor.EmoticonsManager.GetInlineImageUri(emoticon); imgElement.setAttribute("src", UrlHelper.SafeToAbsoluteUri(inlineImageUri), 0); } else if (imageData == null) { if (!File.Exists(imageSrcUri.LocalPath)) { throw new FileNotFoundException(imageSrcUri.LocalPath); } // WinLive 188841: Manually attach the behavior so that the image cannot be selected or resized while its loading. DisabledImageElementBehavior disabledImageBehavior = new DisabledImageElementBehavior(editor.IHtmlEditorComponentContext); disabledImageBehavior.AttachToElement(imgElement); Size sourceImageSize = ImageUtils.GetImageSize(imageSrcUri.LocalPath); ImagePropertiesInfo imageInfo = new ImagePropertiesInfo(imageSrcUri, sourceImageSize, new ImageDecoratorsList(editor.DecoratorsManager, new BlogPostSettingsBag())); DefaultImageSettings defaultImageSettings = new DefaultImageSettings(editorAccount.Id, editor.DecoratorsManager); // Make sure this is set because some imageInfo properties depend on it. imageInfo.ImgElement = imgElement; bool isMetafile = ImageHelper2.IsMetafile(imageSrcUri.LocalPath); ImageClassification imgClass = ImageHelper2.Classify(imageSrcUri.LocalPath); if (!isMetafile && ((imgClass & ImageClassification.AnimatedGif) != ImageClassification.AnimatedGif)) { // WinLive 96840 - Copying and pasting images within shared canvas should persist source // decorator settings. if (copyDecoratorSettings) { // Try to look up the original copied source image. BlogPostImageData imageDataOriginal = BlogPostImageDataList.LookupImageDataByInlineUri(editor.ImageList, new Uri(attributeCopySrcUrl)); if (imageDataOriginal != null && imageDataOriginal.GetImageSourceFile() != null) { // We have the original image reference, so lets make a clone of it. BlogPostSettingsBag originalBag = (BlogPostSettingsBag)imageDataOriginal.ImageDecoratorSettings.Clone(); ImageDecoratorsList originalDecoratorsList = new ImageDecoratorsList(editor.DecoratorsManager, originalBag); ImageFileData originalImageFileData = imageDataOriginal.GetImageSourceFile(); Size originalImageSize = new Size(originalImageFileData.Width, originalImageFileData.Height); imageInfo = new ImagePropertiesInfo(originalImageFileData.Uri, originalImageSize, originalDecoratorsList); } else { // There are probably decorators applied to the image, but in a different editor so we can't access them. // We probably don't want to apply any decorators to this image, so apply blank decorators and load the // image as full size so it looks like it did before. imageInfo.ImageDecorators = defaultImageSettings.LoadBlankLocalImageDecoratorsList(); imageInfo.InlineImageSizeName = ImageSizeName.Full; } } else if (applyDefaultDecorator) { imageInfo.ImageDecorators = defaultImageSettings.LoadDefaultImageDecoratorsList(); if ((imgClass & ImageClassification.TransparentGif) == ImageClassification.TransparentGif) { imageInfo.ImageDecorators.AddDecorator(NoBorderDecorator.Id); } } else { // Don't use default values for decorators imageInfo.ImageDecorators = defaultImageSettings.LoadBlankLocalImageDecoratorsList(); imageInfo.InlineImageSizeName = ImageSizeName.Full; } } else { ImageDecoratorsList decorators = new ImageDecoratorsList(editor.DecoratorsManager, new BlogPostSettingsBag()); decorators.AddDecorator(editor.DecoratorsManager.GetDefaultRemoteImageDecorators()); imageInfo.ImageDecorators = decorators; } imageInfo.ImgElement = imgElement; imageInfo.DhtmlImageViewer = editorAccount.EditorOptions.DhtmlImageViewer; //discover the "natural" target settings from the DOM string linkTargetUrl = imageInfo.LinkTargetUrl; if (linkTargetUrl == imageSrc) { imageInfo.LinkTarget = LinkTargetType.IMAGE; } else if (!String.IsNullOrEmpty(linkTargetUrl) && !UrlHelper.IsFileUrl(linkTargetUrl)) { imageInfo.LinkTarget = LinkTargetType.URL; } else { imageInfo.LinkTarget = LinkTargetType.NONE; } if (useDefaultTargetSettings) { if (!GlobalEditorOptions.SupportsFeature(ContentEditorFeature.SupportsImageClickThroughs) && imageInfo.DefaultLinkTarget == LinkTargetType.IMAGE) { imageInfo.DefaultLinkTarget = LinkTargetType.NONE; } if (imageInfo.LinkTarget == LinkTargetType.NONE) { imageInfo.LinkTarget = imageInfo.DefaultLinkTarget; } if (imageInfo.DefaultLinkOptions.ShowInNewWindow) { imageInfo.LinkOptions.ShowInNewWindow = true; } imageInfo.LinkOptions.UseImageViewer = imageInfo.DefaultLinkOptions.UseImageViewer; imageInfo.LinkOptions.ImageViewerGroupName = imageInfo.DefaultLinkOptions.ImageViewerGroupName; } Size defaultImageSize = defaultImageSettings.GetDefaultInlineImageSize(); Size initialSize = ImageUtils.GetScaledImageSize(defaultImageSize.Width, defaultImageSize.Height, sourceImageSize); // add to list of new images newImages.Add(new NewImageInfo(imageInfo, imgElement, initialSize, disabledImageBehavior)); } else { // When switching blogs, try to adapt image viewer settings according to the blog settings. ImagePropertiesInfo imageInfo = new ImagePropertiesInfo(imageSrcUri, ImageUtils.GetImageSize(imageSrcUri.LocalPath), new ImageDecoratorsList(editor.DecoratorsManager, imageData.ImageDecoratorSettings)); imageInfo.ImgElement = imgElement; // Make sure the new crop and tilt decorators get loaded imageInfo.ImageDecorators.MergeDecorators(DefaultImageSettings.GetImplicitLocalImageDecorators()); string viewer = imageInfo.DhtmlImageViewer; if (viewer != editorAccount.EditorOptions.DhtmlImageViewer) { imageInfo.DhtmlImageViewer = editorAccount.EditorOptions.DhtmlImageViewer; imageInfo.LinkOptions = imageInfo.DefaultLinkOptions; } // If the image is an emoticon, update the EmoticonsManager with the image's uri so that duplicate emoticons can point to the same file. if (emoticon != null) { editor.EmoticonsManager.SetInlineImageUri(emoticon, imageData.InlineImageFile.Uri); } } } catch (ArgumentException e) { Trace.WriteLine("Could not initialize image: " + imageSrc); Trace.WriteLine(e.ToString()); } catch (DirectoryNotFoundException) { Debug.WriteLine("Image file does not exist: " + imageSrc); } catch (FileNotFoundException) { Debug.WriteLine("Image file does not exist: " + imageSrc); } catch (IOException e) { Debug.WriteLine("Image file cannot be read: " + imageSrc + " " + e); DisplayMessage.Show(MessageId.FileInUse, imageSrc); } } } } } return(newImages); }
public string[][] parseAdditionalPhonebook() { string[][] o = null; try { WebClient client = new WebClient(); // grab external resource string raw = client.DownloadString("http://192.168.130.215/~telefonbuch/fstatus.php"); // prepare parsing (type conversion mostly) object[] obj = { raw }; HTMLDocument doc = new HTMLDocument(); IHTMLDocument2 doc2 = (IHTMLDocument2)doc; doc2.write(raw); IHTMLElement2 ie = (IHTMLElement2)doc2.body; IHTMLElementCollection iecr = (IHTMLElementCollection)ie.getElementsByTagName("tr"); IHTMLElementCollection iec = (IHTMLElementCollection)ie.getElementsByTagName("td"); //create boundaries int rows = iecr.length; //int cols = iec.length / rows + 1; int cols = iec.length / rows; ++rows; //create output container //string[][] o = new string[rows][]; o = new string[rows][]; for (int k = 0; k < o.Length; k++) { o[k] = new string[cols]; } //parse loop int irow = 0; int icol = 0; foreach (IHTMLElement item in iec) { string put; if (item.innerHTML == null) { put = " "; } else { put = item.innerHTML.ToString(); } if (put == " ") { put = ""; } o[irow][icol] = put; // make sure the data is in the right order. icol = icol + 1; // if row is fully parsed switch to next row. if (icol == cols) { irow = irow + 1; icol = 0; } } } catch { } return(o); }