示例#1
0
        public override PersonsList Import()
        {
            string[]    parts = null;
            PersonsList toret = new PersonsList();
            var         file  = new StreamReader(FileName);

            string line = file.ReadLine();

            while (!file.EndOfStream)
            {
                parts = SplitCsvLine(line);

                if (parts.Length >= 4)
                {
                    toret.Insert(new Person(parts[0], parts[1], parts[2], parts[3]));
                }
                else
                {
                    throw new ApplicationException("Bad CSV format");
                }

                line = file.ReadLine();
            }

            file.Close();

            return(toret);
        }
示例#2
0
 public override void Export(PersonsList pl)
 {
     using (var file = new StreamWriter(FileName)) {
         file.WriteLine(pl.ToVCard());
         file.WriteLine();
     }
 }
示例#3
0
		/// <summary>
		/// Save the agenda, using a specified file name.
		/// </summary>
		/// <param name="fileName">the file name, as a string.</param>
		public void Save(string fileName)
		{
			if ( this.Modified ) {
				// Set name
				this.FileName = fileName;
				
				// Sort
				this.Sort();
				
				// Prepare file
				XmlTextWriter textWriter =
	 				new XmlTextWriter( FileName, System.Text.Encoding.UTF8 )
				;
				
				// Write standard header
				textWriter.WriteStartDocument();
				
				// Write categories & persons
				textWriter.WriteStartElement( EtqAgenda );
				CategoryList.SaveCategories( textWriter );
				PersonsList.SavePersons( textWriter );
				textWriter.WriteEndElement();
				
				// Write the end of the document
				textWriter.WriteEndDocument();
				textWriter.Close();
			}
			
			return;
		}
示例#4
0
        public void Export(PersonsList pl, char delimiter)
        {
            if (Delimiters.IndexOf(delimiter) < 0)
            {
                delimiter = CommaDelimiter;
            }

            using (var file = new StreamWriter(FileName)) {
                file.WriteLine(pl.ToCsv(delimiter));
                file.WriteLine();
            }
        }
示例#5
0
        public override void Export(PersonsList pl)
        {
            using (var file = new StreamWriter(FileName)) {
                file.WriteLine("<html>\n<head>\n");
                file.WriteLine("<meta http-equiv=\"CONTENT-TYPE\" content=\"text/html; charset=UTF-8\">");
                file.WriteLine("\n<title>Tacto Conversion</title>\n</head>\n<body>");

                file.WriteLine(pl.ToHtml());

                file.WriteLine("</body></html>");
            }
        }
示例#6
0
        /// <summary>
        /// Loads a list of persons with the specified file name.
        /// </summary>
        /// <param name="fileName">The file name, as a string.</param>
        public static PersonsList Load(String fileName)
        {
            PersonsList toret  = new PersonsList();
            XmlDocument docXml = new XmlDocument();

            // Open document
            docXml.Load(fileName);
            XmlNode mainNode = docXml.DocumentElement;

            LoadPersons(mainNode, toret);

            toret.Modified = false;
            return(toret);
        }
示例#7
0
        public override PersonsList Import()
        {
            string section;

            string[]    attributes;
            string      data;
            string      line;
            PersonsList toret = new PersonsList();
            Person      p     = null;

            var file = new StreamReader(FileName);

            Status = State.TopLevel;

            line = file.ReadLine().Trim();
            while (!file.EndOfStream)
            {
                if (line.Length > 0)
                {
                    SplitVcfLine(line, out section, out attributes, out data);

                    if (Status == State.TopLevel &&
                        section == EtqBeginSection &&
                        data.ToUpper() == EtqCardAttribute &&
                        attributes.Length == 0)
                    {
                        // Start vCard
                        Status = State.InCard;
                        p      = new Person();
                    }
                    else
                    if (Status == State.InCard &&
                        section == EtqEndSection &&
                        data.ToUpper() == EtqCardAttribute &&
                        attributes.Length == 0)
                    {
                        // Finish VCard
                        Status = State.TopLevel;
                        toret.Insert(p);
                        p = null;
                    }
                    else
                    if (Status == State.InCard)
                    {
                        // Fill fields
                        FillCard(p, section, attributes, data);
                    }
                    else
                    {
                        throw new ApplicationException("Misplaced statement:'"
                                                       + section + "'\nin '"
                                                       + line + "'\nwhile in state: "
                                                       + Status
                                                       );
                    }
                }

                line = file.ReadLine().Trim();
            }

            file.Close();
            return(toret);
        }
示例#8
0
		/// <summary>
		/// Sorts the persons in this agenda.
		/// @see PersonsList.Sort
		/// </summary>
		public void Sort()
		{
			PersonsList.Sort();
		}
示例#9
0
        /// <summary>
        /// Loads the persons under a given XmlNode.
        /// </summary>
        /// <param name="mainNode">The main XML node, as a XmlNode.</param>
        /// <param name="toret">The PersonsList with the extracted info.</param>
        public static void LoadPersons(XmlNode mainNode, PersonsList toret)
        {
            // Run over all persons
            if (mainNode.Name.ToLower() == EtqPersons)
            {
                foreach (XmlNode node in mainNode.ChildNodes)
                {
                    string   surname    = "";
                    string   name       = "";
                    string   address    = "";
                    string   email      = "";
                    string   email2     = "";
                    string   web        = "";
                    string   wphone     = "";
                    string   hphone     = "";
                    string   mphone     = "";
                    string   id         = "";
                    string   comments   = "";
                    string[] categories = null;

                    if (node.Name.ToLower() == EtqPerson)
                    {
                        // Load name and surname
                        XmlNode nameNode = node.Attributes.GetNamedItem(EtqName);

                        if (nameNode != null)
                        {
                            name = nameNode.InnerText;
                        }
                        else
                        {
                            throw new XmlException(EtqName + " attribute should appear in node");
                        }

                        nameNode = node.Attributes.GetNamedItem(EtqSurname);

                        if (nameNode != null)
                        {
                            surname = nameNode.InnerText;
                        }
                        else
                        {
                            throw new XmlException(EtqSurname + " attribute should appear in node");
                        }

                        // Load the remaining data
                        foreach (XmlNode childNode in node.ChildNodes)
                        {
                            if (childNode.Name.ToLower() == EtqAddress)
                            {
                                address = childNode.InnerText;
                            }
                            else
                            if (childNode.Name.ToLower() == EtqEmail)
                            {
                                email = childNode.InnerText;
                            }
                            else
                            if (childNode.Name.ToLower() == EtqEmail2)
                            {
                                email2 = childNode.InnerText;
                            }
                            else
                            if (childNode.Name.ToLower() == EtqWeb)
                            {
                                web = childNode.InnerText;
                            }
                            else
                            if (childNode.Name.ToLower() == EtqWPhone)
                            {
                                wphone = childNode.InnerText;
                            }
                            else
                            if (childNode.Name.ToLower() == EtqHPhone)
                            {
                                hphone = childNode.InnerText;
                            }
                            else
                            if (childNode.Name.ToLower() == EtqMPhone)
                            {
                                mphone = childNode.InnerText;
                            }
                            else
                            if (childNode.Name.ToLower() == EtqId)
                            {
                                id = childNode.InnerText;
                            }
                            else
                            if (childNode.Name.ToLower() == EtqComments)
                            {
                                comments = childNode.InnerText;
                            }
                            else
                            if (childNode.Name.ToLower() == EtqCategory)
                            {
                                categories = childNode.InnerText.Split(';');
                            }
                        }

                        // Prepare categories
                        var cats = new List <Category>();
                        for (int i = 0; i < categories.Length; ++i)
                        {
                            var category = new Category(categories[i]);
                            if (!CategoryList.IsCategoryAll(category))
                            {
                                cats.Add(category);
                            }
                        }

                        // Add person
                        var p = new Person();
                        p.Surname     = surname;
                        p.Name        = name;
                        p.Email       = email;
                        p.WorkPhone   = wphone;
                        p.HomePhone   = hphone;
                        p.MobilePhone = mphone;
                        p.Address     = address;
                        p.Email2      = email2;
                        p.Web         = web;
                        p.Id          = id;
                        p.Comments    = comments;
                        p.Categories  = cats.ToArray();
                        toret.Insert(p);
                    }
                }
            }
            else
            {
                throw new XmlException("Invalid main label, expected '" + EtqPersons + "'");
            }

            return;
        }
示例#10
0
 abstract public void Export(PersonsList pl);
示例#11
0
 public override void Export(PersonsList pl)
 {
     Export(pl, CommaDelimiter);
 }