Esempio n. 1
0
        private void Import(string fileName, Person.Format fmt)
        {
            PersonsList pl = null;

            // Import contacts
            if (fmt == Person.Format.CSV)
            {
                pl = PersonsList.ImportCsv(fileName);
            }
            else
            if (fmt == Person.Format.VCF)
            {
                pl = PersonsList.ImportVcf(fileName);
            }
            else
            {
                throw new ApplicationException("Sorry, cannot import from HTML");
            }

            // Add new contacts
            foreach (var p in pl)
            {
                agendaSystem.PersonsList.Insert(p);
            }

            // Finish
            this.persons           = this.agendaSystem.PersonsList;
            this.cbCategory.Active = 0;
            this.UpdatePersons();
            Util.MsgInfo(this, AppInfo.Name, "Added " + pl.Size() + " persons");
        }
Esempio n. 2
0
        public static FileFormatManager CreateManager(Person.Format fmt, string fileName)
        {
            FileFormatManager toret = null;

            if (fmt == Person.Format.CSV)
            {
                // CSV
                toret = new CsvManager(fileName);
            }
            else
            if (fmt == Person.Format.HTML)
            {
                // HTML
                toret = new HtmlManager(fileName);
            }
            else
            if (fmt == Person.Format.VCF)
            {
                // VCard
                toret = new VcfManager(fileName);
            }

            if (toret == null)
            {
                throw new ApplicationException("Internal: format not found");
            }

            return(toret);
        }
Esempio n. 3
0
        public void Convert(Person.Format fmt, string fileName)
        {
            SetStatus("Converting...");

            try {
                var manager = FileFormatManager.CreateManager(fmt, fileName);

                manager.Export(persons);

                Util.MsgInfo(this, AppInfo.Name, "File generated");
            } catch (Exception exc)
            {
                Util.MsgError(this, AppInfo.Name, "Unexpected error while converting:\n" + exc.Message);
            }

            SetStatus();
        }