示例#1
0
文件: VNoteParser.cs 项目: ywscr/PDI
        /// <summary>
        /// This version of the constructor is used when parsing vNote data that is to be stored in an existing
        /// vNote instance.
        /// </summary>
        /// <remarks>The properties in the passed vNote will be cleared</remarks>
        /// <param name="vNote">The existing vNote instance</param>
        /// <exception cref="ArgumentNullException">This is thrown if the specified vNote object is null</exception>
        protected VNoteParser(VNote vNote) : this()
        {
            currentNote = vNote ?? throw new ArgumentNullException(nameof(vNote),
                                                                   LR.GetString("ExParseNullObject", "vNote"));

            currentNote.ClearProperties();
            vNotes.Add(vNote);
        }
示例#2
0
        /// <summary>
        /// This version of the constructor is used when parsing vNote data that is to be stored in an existing
        /// vNote instance.
        /// </summary>
        /// <remarks>The properties in the passed vNote will be cleared</remarks>
        /// <param name="vNote">The existing vNote instance</param>
        /// <exception cref="ArgumentNullException">This is thrown if the specified vNote object is null</exception>
        protected VNoteParser(VNote vNote) : this()
        {
            if (vNote == null)
            {
                throw new ArgumentNullException("vNote", LR.GetString("ExParseNullObject", "vNote"));
            }

            currentNote = vNote;
            currentNote.ClearProperties();
            vNotes.Add(vNote);
        }
示例#3
0
        /// <summary>
        /// This is implemented to handle properties as they are parsed from the data stream
        /// </summary>
        /// <param name="propertyName">The name of the property.</param>
        /// <param name="parameters">A string collection containing the parameters and their values.  If empty,
        /// there are no parameters.</param>
        /// <param name="propertyValue">The value of the property.</param>
        /// <remarks><para>There may be a mixture of name/value pairs or values alone in the parameters string
        /// collection.  It is up to the derived class to process the parameter list based on the specification
        /// to which it conforms.  For entries that are parameter names, the entry immediately following it in
        /// the collection is its associated parameter value.  The property name, parameter names, and their
        /// values may be in upper, lower, or mixed case.</para>
        ///
        /// <para>The value may be an encoded string.  The properties are responsible for any decoding that may
        /// need to occur (i.e. base 64 encoded image data).</para></remarks>
        /// <exception cref="PDIParserException">This is thrown if an error is encountered while parsing the data
        /// stream.  Refer to the and inner exceptions for information on the cause of the problem.</exception>
        protected override void PropertyParser(string propertyName, StringCollection parameters, string propertyValue)
        {
            string temp;
            int    idx;

            // The last entry is always CustomProperty so scan for length minus one
            for (idx = 0; idx < ntv.Length - 1; idx++)
            {
                if (ntv[idx].IsMatch(propertyName))
                {
                    break;
                }
            }

            // An opening BEGIN:VNOTE property must have been seen
            if (currentNote == null && ntv[idx].EnumValue != PropertyType.Begin)
            {
                throw new PDIParserException(this.LineNumber, LR.GetString("ExParseNoBeginProp", "BEGIN:VNOTE",
                                                                           propertyName));
            }

            // Handle or create the property
            switch (ntv[idx].EnumValue)
            {
            case PropertyType.Begin:
                // The value must be VNOTE
                if (String.Compare(propertyValue.Trim(), "VNOTE", StringComparison.OrdinalIgnoreCase) != 0)
                {
                    throw new PDIParserException(this.LineNumber, LR.GetString("ExParseUnrecognizedTagValue",
                                                                               ntv[idx].Name, propertyValue));
                }

                // NOTE: If serializing into an existing instance, this may not be null.  If so, it is
                // ignored.
                if (currentNote == null)
                {
                    currentNote = new VNote();
                    vNotes.Add(currentNote);
                }
                break;

            case PropertyType.End:
                // The value must be VNOTE
                if (String.Compare(propertyValue.Trim(), "VNOTE", StringComparison.OrdinalIgnoreCase) != 0)
                {
                    throw new PDIParserException(this.LineNumber, LR.GetString("ExParseUnrecognizedTagValue",
                                                                               ntv[idx].Name, propertyValue));
                }

                // When done, we'll propagate the version number to all objects to make it consistent
                currentNote.PropagateVersion();

                // The vNote is added to the collection when created so we don't have to rely on an END:VNOTE
                // to add it.
                currentNote = null;
                break;

            case PropertyType.Version:
                // Version must be 1.1
                temp = propertyValue.Trim();

                if (temp != "1.1")
                {
                    throw new PDIParserException(this.LineNumber, LR.GetString("ExParseUnrecognizedVersion",
                                                                               "vNote", temp));
                }

                currentNote.Version = SpecificationVersions.IrMC11;
                break;

            case PropertyType.UniqueId:
                currentNote.UniqueId.EncodedValue = propertyValue;
                break;

            case PropertyType.Summary:
                currentNote.Summary.DeserializeParameters(parameters);
                currentNote.Summary.EncodedValue = propertyValue;
                break;

            case PropertyType.Body:
                currentNote.Body.DeserializeParameters(parameters);
                currentNote.Body.EncodedValue = propertyValue;
                break;

            case PropertyType.Class:
                currentNote.Classification.EncodedValue = propertyValue;
                break;

            case PropertyType.Categories:
                currentNote.Categories.DeserializeParameters(parameters);
                currentNote.Categories.EncodedValue = propertyValue;
                break;

            case PropertyType.DateCreated:
                currentNote.DateCreated.DeserializeParameters(parameters);
                currentNote.DateCreated.EncodedValue = propertyValue;
                break;

            case PropertyType.LastModified:
                currentNote.LastModified.DeserializeParameters(parameters);
                currentNote.LastModified.EncodedValue = propertyValue;
                break;

            default:        // Anything else is a custom property
                CustomProperty c = new CustomProperty(propertyName);
                c.DeserializeParameters(parameters);
                c.EncodedValue = propertyValue;
                currentNote.CustomProperties.Add(c);
                break;
            }
        }
示例#4
0
        /// <summary>
        /// This static method can be used to load property values into an existing instance of a single vNote
        /// from a string.
        /// </summary>
        /// <param name="vNoteText">A set of properties for a single vNote in a string</param>
        /// <param name="vNote">The vNote instance into which the properties will be loaded</param>
        /// <remarks>The properties of the specified vNote will be cleared before the new properties are loaded
        /// into it.</remarks>
        /// <example>
        /// <code language="cs">
        /// VNote vNote = new VNote();
        /// VNoteParser.ParseFromString(oneVNote, vNote);
        /// </code>
        /// <code language="vbnet">
        /// Dim vNote As New VNote
        /// VNoteParser.ParseFromString(oneVNote, vNote)
        /// </code>
        /// </example>
        public static void ParseFromString(string vNoteText, VNote vNote)
        {
            VNoteParser vcp = new VNoteParser(vNote);

            vcp.ParseString(vNoteText);
        }