Пример #1
0
        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());
        }
Пример #2
0
        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();
        }
Пример #3
0
        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);
        }
Пример #4
0
        public string XmlEncode(object s)
        {
            if (s == null)
            {
                return(null);
            }

            return(XmlEncoder.Encode(s.ToString()));
        }
Пример #5
0
    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);
    }
Пример #6
0
 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);
         }
     }
 }
Пример #7
0
        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);
        }
Пример #8
0
        public void Encode_Should_ReturnCorrectlyEncodedString_When_StringContainsTwoSpaces()
        {
            // Arrange
            const string expected = "&nbsp; ";
            const string source   = "  ";

            // Act
            var actual = XmlEncoder.Encode(source);

            // Assert
            Assert.Equal(expected, actual);
        }
Пример #9
0
        public void Encode_Should_ReturnCorrectlyEncodedString_When_StringContainsSingleQuote()
        {
            // Arrange
            const string expected = "&apos;";
            const string source   = "\'";

            // Act
            var actual = XmlEncoder.Encode(source);

            // Assert
            Assert.Equal(expected, actual);
        }
Пример #10
0
        public void Encode_Should_ReturnCorrectlyEncodedString_When_StringContainsNonPrintable()
        {
            // Arrange
            const string expected = "&#13;";
            const string source   = "\r";

            // Act
            var actual = XmlEncoder.Encode(source);

            // Assert
            Assert.Equal(expected, actual);
        }
Пример #11
0
        public void Encode_Should_ReturnCorrectlyEncodedString_When_StringContainsGreaterThan()
        {
            // Arrange
            const string expected = "&gt;";
            const string source   = ">";

            // Act
            var actual = XmlEncoder.Encode(source);

            // Assert
            Assert.Equal(expected, actual);
        }
Пример #12
0
        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());
        }
Пример #13
0
        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;
            }
        }
Пример #14
0
 public void SingleQuote()
 {
     Assert.AreEqual("&apos;", XmlEncoder.Encode("'", '\''));
 }
Пример #15
0
            public void WhenContainsApostraphe_ThenEncodeToEntity()
            {
                var result = XmlEncoder.Encode(Text.FormatWith("'"));

                Assert.That(result, Is.EqualTo(Text.FormatWith("&apos;")));
            }
Пример #16
0
            public void WhenIsNull_ThenReturnNull()
            {
                var result = XmlEncoder.Encode(null);

                Assert.That(result, Is.Null);
            }
Пример #17
0
            public void WhenContainsDoubleQuote_ThenEncodeToEntity()
            {
                var result = XmlEncoder.Encode(Text.FormatWith("\""));

                Assert.That(result, Is.EqualTo(Text.FormatWith("&quot;")));
            }
Пример #18
0
            public void WhenContainsGreaterThan_ThenEncodeToEntity()
            {
                var result = XmlEncoder.Encode(Text.FormatWith(">"));

                Assert.That(result, Is.EqualTo(Text.FormatWith("&gt;")));
            }
Пример #19
0
 public void Ampersand()
 {
     Assert.AreEqual("&amp;", XmlEncoder.Encode("&", '\''));
 }
Пример #20
0
            public void WhenIsEmpty_ThenReturnEmpty()
            {
                var result = XmlEncoder.Encode(string.Empty);

                Assert.That(result, Is.Empty);
            }
Пример #21
0
            public void WhenContainsAmpersand_ThenEncodeToEntity()
            {
                var result = XmlEncoder.Encode(Text.FormatWith("&"));

                Assert.That(result, Is.EqualTo(Text.FormatWith("&amp;")));
            }
Пример #22
0
        static string XmlEncode(string item)
        {
            char quoteChar = '\'';

            return(XmlEncoder.Encode(item, quoteChar));
        }
Пример #23
0
 /// <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));
 }