Beispiel #1
0
        /// <summary>
        /// This static method can be used to load property values into a new vCard collection from a file.  The
        /// filename can be a disk file or a URL.
        /// </summary>
        /// <param name="filename">A path or URL to a file containing one or more vCards</param>
        /// <returns>A new vCard collection as created from the file</returns>
        /// <example>
        /// <code language="cs">
        /// VCardCollection vCards1 = VCardParser.ParseFromFile(@"C:\AddressBook.vcf");
        /// VCardCollection vCards2 = VCardParser.ParseFromFile(
        ///     "http://www.mydomain.com/VCards/AddressBook.vcf");
        /// </code>
        /// <code language="vbnet">
        /// Dim vCards1 As VCardCollection = VCardParser.ParseFromFile("C:\AddressBook.vcf")
        /// Dim vCards2 As VCardCollection = VCardParser.ParseFromFile(
        ///     "http://www.mydomain.com/VCards/AddressBook.vcf")
        /// </code>
        /// </example>
        public static VCardCollection ParseFromFile(string filename)
        {
            VCardParser vcp = new VCardParser();

            vcp.ParseFile(filename);

            return(vcp.VCards);
        }
Beispiel #2
0
        /// <summary>
        /// This static method can be used to load property values into a new vCard collection from a
        /// <see cref="TextReader"/> derived object such as a <see cref="StreamReader"/> or a
        /// <see cref="StringReader"/>.
        /// </summary>
        /// <param name="stream">An IO stream from which to read the vCards.  It is up to you to open the stream
        /// with the appropriate text encoding method if necessary.</param>
        /// <returns>A new vCard collection as created from the IO stream</returns>
        /// <example>
        /// <code language="cs">
        /// StreamReader sr = new StreamReader(@"C:\Test.vcf");
        /// VCardCollection vCards1 = VCardParser.ParseFromStream(sr);
        /// sr.Close();
        /// </code>
        /// <code language="vbnet">
        /// Dim sr As New StreamReader("C:\Test.vcf")
        /// Dim vCards1 As VCardCollection = VCardParser.ParseFromStream(sr)
        /// sr.Close()
        /// </code>
        /// </example>
        public static VCardCollection ParseFromStream(TextReader stream)
        {
            VCardParser vcp = new VCardParser();

            vcp.ParseReader(stream);

            return(vcp.VCards);
        }
Beispiel #3
0
        //=====================================================================

        /// <summary>
        /// This static method can be used to load property values into a new instance of a single vCard from a
        /// string.
        /// </summary>
        /// <param name="vCardText">A set of properties for a single vCard in a string</param>
        /// <returns>A new vCard instance as created from the string</returns>
        /// <example>
        /// <code language="cs">
        /// VCard vCard = VCardParser.ParseFromString(oneVCard);
        /// </code>
        /// <code language="vbnet">
        /// Dim vCard As VCard = VCardParser.ParseFromString(oneVCard)
        /// </code>
        /// </example>
        public static VCard ParseFromString(string vCardText)
        {
            VCardParser vcp = new VCardParser();

            vcp.ParseString(vCardText);

            return(vcp.VCards[0]);
        }
Beispiel #4
0
        /// <summary>
        /// This static method can be used to load property values into a new vCard collection from a string
        /// containing one or more vCards.
        /// </summary>
        /// <param name="vCards">A set of properties for one or more vCards in a string</param>
        /// <returns>A new vCard collection as created from the string</returns>
        /// <example>
        /// <code language="cs">
        /// VCardCollection vCards = VCardParser.ParseSetFromString(vCards);
        /// </code>
        /// <code language="vbnet">
        /// Dim vCards As VCardCollection = VCardParser.ParseSetFromString(vCards)
        /// </code>
        /// </example>
        public static VCardCollection ParseSetFromString(string vCards)
        {
            VCardParser vcp = new VCardParser();

            vcp.ParseString(vCards);

            return(vcp.VCards);
        }
Beispiel #5
0
        /// <summary>
        /// This static method can be used to load property values into an existing instance of a single vCard
        /// from a string.
        /// </summary>
        /// <param name="vCardText">A set of properties for a single vCard in a string</param>
        /// <param name="vCard">The vCard instance into which the properties will be loaded</param>
        /// <remarks>The properties of the specified vCard will be cleared before the new properties are loaded
        /// into it.</remarks>
        /// <example>
        /// <code language="cs">
        /// VCard vCard = new VCard();
        /// VCardParser.ParseFromString(oneVCard, vCard);
        /// </code>
        /// <code language="vbnet">
        /// Dim vCard As New VCard
        /// VCardParser.ParseFromString(oneVCard, vCard)
        /// </code>
        /// </example>
        public static void ParseFromString(string vCardText, VCard vCard)
        {
            VCardParser vcp = new VCardParser(vCard);

            vcp.ParseString(vCardText);
        }
Beispiel #6
0
		static void Main(string[] args)
		{
            string outputFolder, outputFile;

            if(args.GetUpperBound(0) < 1)
            {
                Console.WriteLine("Specify a folder name containing PDI files and a different one for the " +
                    "output files.");
                return;
            }

            try
            {
                // Set the default encoding to iso-8859-1 (Western European) as several of the files are encoded
                // that way.
                PDIParser.DefaultEncoding = BaseProperty.DefaultEncoding = Encoding.GetEncoding("iso-8859-1");

                outputFolder = args[1];

                if(!outputFolder.EndsWith(@"\", StringComparison.Ordinal))
                    outputFolder += @"\";

                if(!Directory.Exists(outputFolder))
                    Directory.CreateDirectory(outputFolder);

                Console.WriteLine("Parsing vCard files...");

                // Since we'll be parsing multiple files, we'll create an instance of the parser and re-use it
                // rather than using the static parsing methods.
                VCardParser vcardp = new VCardParser();

                foreach(string file in Directory.EnumerateFiles(args[0], "*.vcf"))
                {
                    Console.WriteLine("\n{0}", file);

                    vcardp.ParseFile(file);

                    Console.WriteLine(vcardp.VCards.ToString());

                    // Write it to a stream
                    outputFile = outputFolder + Path.GetFileName(file);

                    // NOTE: We must use the same encoding method when writing the file back out
                    using(var sw = new StreamWriter(outputFile, false, PDIParser.DefaultEncoding))
                    {
                        vcardp.VCards.WriteToStream(sw);
                    }

                    // Clear the collection ready for the next run
                    vcardp.VCards.Clear();
                }

                Console.WriteLine("\nParsing vCalendar files...");

                // Since we'll be parsing multiple files, we'll create an instance of the parser and re-use it
                // rather than using the static parser methods.
                VCalendarParser vcalp = new VCalendarParser();

                foreach(string file in Directory.EnumerateFiles(args[0], "*.vcs"))
                {
                    Console.WriteLine("\n{0}", file);

                    vcalp.ParseFile(file);

                    Console.WriteLine(vcalp.VCalendar.ToString());

                    // Write it to a stream
                    outputFile = outputFolder + Path.GetFileName(file);

                    // NOTE: We must use the same encoding method when writing the file back out
                    using(var sw = new StreamWriter(outputFile, false, PDIParser.DefaultEncoding))
                    {
                        vcalp.VCalendar.WriteToStream(sw);
                    }

                    // Clear the calendar ready for the next run
                    vcalp.VCalendar.ClearProperties();
                }

                Console.WriteLine("\nParsing iCalendar files...");

                // Get a list of iCalendar files to parse.  It uses the same parser as the vCalendar files
                foreach(string file in Directory.EnumerateFiles(args[0], "*.ics"))
                {
                    Console.WriteLine("\n{0}", file);

                    vcalp.ParseFile(file);

                    Console.WriteLine(vcalp.VCalendar.ToString());

                    // Write it to a stream
                    outputFile = outputFolder + Path.GetFileName(file);

                    // NOTE: We must use the same encoding method when writing the file back out
                    using(var sw = new StreamWriter(outputFile, false, PDIParser.DefaultEncoding))
                    {
                        vcalp.VCalendar.WriteToStream(sw);
                    }

                    // Clear the calendar ready for the next run
                    vcalp.VCalendar.ClearProperties();
                }

                Console.WriteLine("\nParsing vNote files...");

                // Since we'll be parsing multiple files, we'll create an instance of the parser and re-use it
                // rather than using the static parser methods.
                VNoteParser vnp = new VNoteParser();

                foreach(string file in Directory.EnumerateFiles(args[0], "*.vnt"))
                {
                    Console.WriteLine("\n{0}", file);

                    vnp.ParseFile(file);

                    Console.WriteLine(vnp.VNotes.ToString());

                    // Write it to a stream
                    outputFile = outputFolder + Path.GetFileName(file);

                    // NOTE: We must use the same encoding method when writing the file back out
                    using(var sw = new StreamWriter(outputFile, false, PDIParser.DefaultEncoding))
                    {
                        vnp.VNotes.WriteToStream(sw);
                    }

                    // Clear the collection ready for the next run
                    vnp.VNotes.Clear();
                }
            }
            catch(PDIParserException pe)
            {
                Console.WriteLine("\n\nError at line #{0}\n\n{1}", pe.LineNumber, pe.ToString());
            }
            catch(Exception ex)
            {
                Console.WriteLine("Unexpected failure:\n{0}", ex.ToString());
            }
        }
Beispiel #7
0
        /// <summary>
        /// This static method can be used to load property values into a new vCard collection from a
        /// <see cref="TextReader"/> derived object such as a <see cref="StreamReader"/> or a
        /// <see cref="StringReader"/>.
        /// </summary>
        /// <param name="stream">An IO stream from which to read the vCards.  It is up to you to open the stream
        /// with the appropriate text encoding method if necessary.</param>
        /// <returns>A new vCard collection as created from the IO stream</returns>
        /// <example>
        /// <code language="cs">
        /// StreamReader sr = new StreamReader(@"C:\Test.vcf");
        /// VCardCollection vCards1 = VCardParser.ParseFromStream(sr);
        /// sr.Close();
        /// </code>
        /// <code language="vbnet">
        /// Dim sr As New StreamReader("C:\Test.vcf")
        /// Dim vCards1 As VCardCollection = VCardParser.ParseFromStream(sr)
        /// sr.Close()
        /// </code>
        /// </example>
        public static VCardCollection ParseFromStream(TextReader stream)
        {
            VCardParser vcp = new VCardParser();
            vcp.ParseReader(stream);

            return vcp.VCards;
        }
Beispiel #8
0
        /// <summary>
        /// This static method can be used to load property values into a new vCard collection from a file.  The
        /// filename can be a disk file or a URL.
        /// </summary>
        /// <param name="filename">A path or URL to a file containing one or more vCards</param>
        /// <returns>A new vCard collection as created from the file</returns>
        /// <example>
        /// <code language="cs">
        /// VCardCollection vCards1 = VCardParser.ParseFromFile(@"C:\AddressBook.vcf");
        /// VCardCollection vCards2 = VCardParser.ParseFromFile(
        ///     "http://www.mydomain.com/VCards/AddressBook.vcf");
        /// </code>
        /// <code language="vbnet">
        /// Dim vCards1 As VCardCollection = VCardParser.ParseFromFile("C:\AddressBook.vcf")
        /// Dim vCards2 As VCardCollection = VCardParser.ParseFromFile(
        ///     "http://www.mydomain.com/VCards/AddressBook.vcf")
        /// </code>
        /// </example>
        public static VCardCollection ParseFromFile(string filename)
        {
            VCardParser vcp = new VCardParser();
            vcp.ParseFile(filename);

            return vcp.VCards;
        }
Beispiel #9
0
        /// <summary>
        /// This static method can be used to load property values into a new vCard collection from a string
        /// containing one or more vCards.
        /// </summary>
        /// <param name="vCards">A set of properties for one or more vCards in a string</param>
        /// <returns>A new vCard collection as created from the string</returns>
        /// <example>
        /// <code language="cs">
        /// VCardCollection vCards = VCardParser.ParseSetFromString(vCards);
        /// </code>
        /// <code language="vbnet">
        /// Dim vCards As VCardCollection = VCardParser.ParseSetFromString(vCards)
        /// </code>
        /// </example>
        public static VCardCollection ParseSetFromString(string vCards)
        {
            VCardParser vcp = new VCardParser();
            vcp.ParseString(vCards);

            return vcp.VCards;
        }
Beispiel #10
0
 /// <summary>
 /// This static method can be used to load property values into an existing instance of a single vCard
 /// from a string.
 /// </summary>
 /// <param name="vCardText">A set of properties for a single vCard in a string</param>
 /// <param name="vCard">The vCard instance into which the properties will be loaded</param>
 /// <remarks>The properties of the specified vCard will be cleared before the new properties are loaded
 /// into it.</remarks>
 /// <example>
 /// <code language="cs">
 /// VCard vCard = new VCard();
 /// VCardParser.ParseFromString(oneVCard, vCard);
 /// </code>
 /// <code language="vbnet">
 /// Dim vCard As New VCard
 /// VCardParser.ParseFromString(oneVCard, vCard)
 /// </code>
 /// </example>
 public static void ParseFromString(string vCardText, VCard vCard)
 {
     VCardParser vcp = new VCardParser(vCard);
     vcp.ParseString(vCardText);
 }
Beispiel #11
0
        //=====================================================================

        /// <summary>
        /// This static method can be used to load property values into a new instance of a single vCard from a
        /// string.
        /// </summary>
        /// <param name="vCardText">A set of properties for a single vCard in a string</param>
        /// <returns>A new vCard instance as created from the string</returns>
        /// <example>
        /// <code language="cs">
        /// VCard vCard = VCardParser.ParseFromString(oneVCard);
        /// </code>
        /// <code language="vbnet">
        /// Dim vCard As VCard = VCardParser.ParseFromString(oneVCard)
        /// </code>
        /// </example>
        public static VCard ParseFromString(string vCardText)
        {
            VCardParser vcp = new VCardParser();
            vcp.ParseString(vCardText);

            return vcp.VCards[0];
        }