BacklinkMenuItem [] GetBacklinkMenuItems() { List <BacklinkMenuItem> items = new List <BacklinkMenuItem> (); string search_title = Note.Title; string encoded_title = XmlEncoder.Encode(search_title.ToLower()); // Go through each note looking for // notes that link to this one. foreach (Note note in Note.Manager.Notes) { if (note != Note && // don't match ourself CheckNoteHasMatch(note, encoded_title)) { BacklinkMenuItem item = new BacklinkMenuItem(note, search_title); items.Add(item); } } items.Sort(); return(items.ToArray()); }
protected void OnActivated(object sender, EventArgs args) { if (notebook == null) { return; } // Look for the template note and create a new note Note templateNote = notebook.GetTemplateNote(); Note note; NoteManager noteManager = Tomboy.DefaultNoteManager; note = noteManager.Create(); if (templateNote != null) { // Use the body from the template note string xmlContent = templateNote.XmlContent.Replace(XmlEncoder.Encode(templateNote.Title), XmlEncoder.Encode(note.Title)); xmlContent = NoteManager.SanitizeXmlContent(xmlContent); note.XmlContent = xmlContent; } note.AddTag(notebook.Tag); note.Window.Show(); }
private XmlElement CreateXmlElement(string key, object value) { var element = _properties.CreateElement(key); var attribute = _properties.CreateAttribute("type"); attribute.InnerText = value.GetType().ToString(); element.Attributes.Append(attribute); if (value.GetType() == typeof(byte[])) { element.InnerText = HexEncoding.ToString((byte[])value); } else { if (key == "userparameters") { // This is a weird value in that it contains non-printable characters which are // invalid for the underlying XML storage... so we'll just convert the value to // Hexadecimal for storage and then convert out a string if needed later. var valueBytes = new UnicodeEncoding().GetBytes((string)value); element.InnerText = HexEncoding.ToString(valueBytes); } else { element.InnerText = value is string?XmlEncoder.Encode(value.ToString()) : value.ToString(); } } if (_debugMode) { _log.Debug($"{key} > {attribute.InnerText} : {element.InnerText}"); } return(element); }
public string XmlEncode(object s) { if (s == null) { return(null); } return(XmlEncoder.Encode(s.ToString())); }
private void SerializeConfigFile(FileConfig config) { string configFilePath = PlayerPrefs.GetString(localPathKey); string tempXml = UnityPath.Combinate("temp.xml", UnityPath.AssetPath.Persistent); XmlEncoder.Serialize <FileConfig>(tempXml, config); XmlEncoder.Encode(tempXml, configFilePath); File.Delete(tempXml); }
public static void XmlEscapeStringValues(IDictionary dict) { foreach (var key in new ArrayList(dict.Keys)) { var value = dict[key]; if (value is string) { dict[key] = XmlEncoder.Encode(value as string); } } }
public void Encode_Should_ReturnCorrectlyEncodedString_When_StringIsANormalString() { // Arrange const string expected = "Normal"; const string source = "Normal"; // Act var actual = XmlEncoder.Encode(source); // Assert Assert.Equal(expected, actual); }
public void Encode_Should_ReturnCorrectlyEncodedString_When_StringContainsTwoSpaces() { // Arrange const string expected = " "; const string source = " "; // Act var actual = XmlEncoder.Encode(source); // Assert Assert.Equal(expected, actual); }
public void Encode_Should_ReturnCorrectlyEncodedString_When_StringContainsSingleQuote() { // Arrange const string expected = "'"; const string source = "\'"; // Act var actual = XmlEncoder.Encode(source); // Assert Assert.Equal(expected, actual); }
public void Encode_Should_ReturnCorrectlyEncodedString_When_StringContainsNonPrintable() { // Arrange const string expected = " "; const string source = "\r"; // Act var actual = XmlEncoder.Encode(source); // Assert Assert.Equal(expected, actual); }
public void Encode_Should_ReturnCorrectlyEncodedString_When_StringContainsGreaterThan() { // Arrange const string expected = ">"; const string source = ">"; // Act var actual = XmlEncoder.Encode(source); // Assert Assert.Equal(expected, actual); }
public string Format(Exception e) { const string projDir = @".:\\(Documents and Settings|projects)\\\w+(\\My Documents\\Visual Studio Projects)?"; string nl = Environment.NewLine; var rx = new Regex(" in " + projDir + "(.*$)", RegexOptions.Multiline | RegexOptions.IgnoreCase | RegexOptions.Compiled); var s = new Stack(); while (e != null) { s.Push(e); e = e.InnerException; } var sb = new StringBuilder(); while (s.Count > 0 && (e = (Exception)s.Pop()) != null) { var be = e as BaseException; sb.AppendFormat("<strong class='exception-text'>{0}: ", XmlEncoder.Encode(e.GetType().FullName)); if (be != null && !String.IsNullOrEmpty(be.Title)) { sb.AppendFormat("<span class='exception-title'>{0}:</span> ", be.Title); } sb.AppendFormat("{0}</strong>", XmlEncoder.Encode(e.Message)); if (be != null && !String.IsNullOrEmpty(be.AdditionalInfo)) { sb.AppendFormat(" <em class='exception-details'>({0})</em>", XmlEncoder.Encode(be.AdditionalInfo)); } sb.Append(nl); if (!String.IsNullOrEmpty(e.StackTrace)) { string stackTrace = XmlEncoder.Encode(e.StackTrace); stackTrace = rx.Replace(stackTrace, nl + "\t<span class='exception-sourcefile'>in $3</span>"); sb.Append(stackTrace).Append(nl); } sb.Append(nl); } return(sb.ToString()); }
private static void ec_ReferenceInsertion(object sender, ReferenceInsertionEventArgs e) { if (e.OriginalValue == null) { return; } var s = e.GetCopyOfReferenceStack(); while (s.Count > 0) { var current = s.Pop(); if (!(current is IEscapable)) { continue; } e.NewValue = XmlEncoder.Encode(Convert.ToString(e.OriginalValue)); return; } }
public void SingleQuote() { Assert.AreEqual("'", XmlEncoder.Encode("'", '\'')); }
public void WhenContainsApostraphe_ThenEncodeToEntity() { var result = XmlEncoder.Encode(Text.FormatWith("'")); Assert.That(result, Is.EqualTo(Text.FormatWith("'"))); }
public void WhenIsNull_ThenReturnNull() { var result = XmlEncoder.Encode(null); Assert.That(result, Is.Null); }
public void WhenContainsDoubleQuote_ThenEncodeToEntity() { var result = XmlEncoder.Encode(Text.FormatWith("\"")); Assert.That(result, Is.EqualTo(Text.FormatWith("""))); }
public void WhenContainsGreaterThan_ThenEncodeToEntity() { var result = XmlEncoder.Encode(Text.FormatWith(">")); Assert.That(result, Is.EqualTo(Text.FormatWith(">"))); }
public void Ampersand() { Assert.AreEqual("&", XmlEncoder.Encode("&", '\'')); }
public void WhenIsEmpty_ThenReturnEmpty() { var result = XmlEncoder.Encode(string.Empty); Assert.That(result, Is.Empty); }
public void WhenContainsAmpersand_ThenEncodeToEntity() { var result = XmlEncoder.Encode(Text.FormatWith("&")); Assert.That(result, Is.EqualTo(Text.FormatWith("&"))); }
static string XmlEncode(string item) { char quoteChar = '\''; return(XmlEncoder.Encode(item, quoteChar)); }
/// <summary> /// Encode/escape any special xml characters /// </summary> /// <param name="source">string which may contain special xml chracters</param> /// <returns>escaped output</returns> protected string XmlEncodeString(string source) { return(_xmlEncoder.Encode(source)); }