Exemplo n.º 1
0
        protected void Page_Load(object sender, EventArgs e)
        {
            this.Page.Title = "vCard Browser";

            lblMsg.Text = String.Empty;

            VCardCollection vc = (VCardCollection)Session["VCards"];

            // Load a default set of vCards on first use and store them in the session if not already there and
            // bind them to the data grid.
            if (!Page.IsPostBack || vc == null)
            {
                if (vc == null)
                {
                    if (Page.IsPostBack)
                    {
                        lblMsg.Text = "Session appears to have timed out.  Default vCards loaded.";
                    }

                    vc = VCardParser.ParseFromFile(Server.MapPath("RFC2426.vcf"));
                    vc.Sort(VCardSorter);

                    Session["VCards"] = vc;
                }

                dgVCards.DataSource = vc;
                dgVCards.DataBind();
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// This handles various commands for the data grid
        /// </summary>
        /// <param name="source">The source of the event</param>
        /// <param name="e">The event arguments</param>
        protected void dgVCards_ItemCommand(object source, DataGridCommandEventArgs e)
        {
            VCardCollection vc = (VCardCollection)Session["VCards"];

            switch (e.CommandName)
            {
            case "Add":
                vc.Add(new VCard());

                Response.Redirect(String.Format("VCardDetails.aspx?Index={0}", vc.Count - 1));
                break;

            case "Edit":
                if (e.Item.ItemIndex < vc.Count)
                {
                    Response.Redirect(String.Format("VCardDetails.aspx?Index={0}", e.Item.ItemIndex));
                }
                break;

            case "Download":
                if (vc.Count == 0)
                {
                    lblMsg.Text = "No vCards to download";
                }
                else
                {
                    // This is only applicable for vCard 2.1
                    switch (cboPropEncoding.SelectedIndex)
                    {
                    case 0:
                        BaseProperty.DefaultEncoding = new UTF8Encoding(false, false);
                        break;

                    case 1:
                        BaseProperty.DefaultEncoding = Encoding.GetEncoding("iso-8859-1");
                        break;

                    default:
                        BaseProperty.DefaultEncoding = new ASCIIEncoding();
                        break;
                    }

                    // Send the file to the user
                    this.Response.ClearContent();
                    this.Response.ContentType = "text/x-vcard";
                    this.Response.AppendHeader("Content-Disposition", "inline;filename=VCards.vcf");

                    // The collection can be written directly to the stream.  Note that more likely than not,
                    // it will be written as UTF-8 encoded data.
                    vc.WriteToStream(Response.Output);
                    Response.End();
                }
                break;
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Open a vCard file
        /// </summary>
        /// <param name="sender">The sender of the event</param>
        /// <param name="e">The event arguments</param>
        private void miOpen_Click(object sender, EventArgs e)
        {
            if (wasModified && MessageBox.Show("Do you want to discard your changes to the current vCards?",
                                               "Discard Changes", MessageBoxButtons.YesNo, MessageBoxIcon.Question,
                                               MessageBoxDefaultButton.Button2) == DialogResult.No)
            {
                return;
            }

            using (OpenFileDialog dlg = new OpenFileDialog())
            {
                dlg.Title            = "Load vCard File";
                dlg.DefaultExt       = "vcf";
                dlg.Filter           = "VCF files (*.vcf)|*.vcf|All files (*.*)|*.*";
                dlg.InitialDirectory = Path.GetFullPath(Path.Combine(
                                                            Environment.CurrentDirectory, @"..\..\..\..\..\PDIFiles"));

                if (dlg.ShowDialog() == DialogResult.OK)
                {
                    try
                    {
                        this.Cursor = Cursors.WaitCursor;

                        // Parse the vCard information from the file and load the data grid with some basic
                        // information about the vCards in it.
                        vCards = VCardParser.ParseFromFile(dlg.FileName);
                        this.LoadGridWithVCards();

                        lblFilename.Text = dlg.FileName;
                    }
                    catch (Exception ex)
                    {
                        string error = String.Format("Unable to load vCards:\n{0}", ex.Message);

                        if (ex.InnerException != null)
                        {
                            error += ex.InnerException.Message + "\n";

                            if (ex.InnerException.InnerException != null)
                            {
                                error += ex.InnerException.InnerException.Message;
                            }
                        }

                        System.Diagnostics.Debug.Write(ex);

                        MessageBox.Show(error, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                    finally
                    {
                        this.Cursor = Cursors.Default;
                    }
                }
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// Delete a vCard from the collection
        /// </summary>
        /// <param name="source">The source of the event</param>
        /// <param name="e">The event arguments</param>
        protected void dgVCards_DeleteCommand(object source, DataGridCommandEventArgs e)
        {
            VCardCollection vc = (VCardCollection)Session["VCards"];

            if (e.Item.ItemIndex < vc.Count)
            {
                vc.RemoveAt(e.Item.ItemIndex);
            }

            dgVCards.DataSource = vc;
            dgVCards.DataBind();
        }
Exemplo n.º 5
0
        //=====================================================================

        /// <summary>
        /// Constructor
        /// </summary>
        public VCardBrowserForm()
        {
            InitializeComponent();
            tbcVersion.HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter;

            // The string format to use when drawing the status text
            sf               = new StringFormat(StringFormatFlags.NoWrap);
            sf.Alignment     = StringAlignment.Center;
            sf.LineAlignment = StringAlignment.Center;
            sf.Trimming      = StringTrimming.EllipsisCharacter;

            dgvCards.AutoGenerateColumns            = false;
            tbcLastRevision.DefaultCellStyle.Format = CultureInfo.CurrentCulture.DateTimeFormat.ShortDatePattern + " " +
                                                      CultureInfo.CurrentCulture.DateTimeFormat.ShortTimePattern;

            cboVersion.SelectedIndex = 0;
            vCards = new VCardCollection();
            LoadGridWithVCards();
        }
Exemplo n.º 6
0
        //=====================================================================

        /// <summary>
        /// Constructor
        /// </summary>
		public VCardBrowserForm()
		{
			InitializeComponent();
            tbcVersion.HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter;

            // The string format to use when drawing the status text
            sf = new StringFormat(StringFormatFlags.NoWrap);
            sf.Alignment = StringAlignment.Center;
            sf.LineAlignment = StringAlignment.Center;
            sf.Trimming = StringTrimming.EllipsisCharacter;

            dgvCards.AutoGenerateColumns = false;
            tbcLastRevision.DefaultCellStyle.Format = CultureInfo.CurrentCulture.DateTimeFormat.ShortDatePattern + " " +
                  CultureInfo.CurrentCulture.DateTimeFormat.ShortTimePattern;

            cboVersion.SelectedIndex = 0;
            vCards = new VCardCollection();
            LoadGridWithVCards();
		}
Exemplo n.º 7
0
        /// <summary>
        /// Open a vCard file
        /// </summary>
        /// <param name="sender">The sender of the event</param>
        /// <param name="e">The event arguments</param>
        private void miOpen_Click(object sender, EventArgs e)
        {
            if(wasModified && MessageBox.Show("Do you want to discard your changes to the current vCards?",
              "Discard Changes", MessageBoxButtons.YesNo, MessageBoxIcon.Question,
              MessageBoxDefaultButton.Button2) == DialogResult.No)
                return;

            using(OpenFileDialog dlg = new OpenFileDialog())
            {
                dlg.Title = "Load vCard File";
                dlg.DefaultExt = "vcf";
                dlg.Filter = "VCF files (*.vcf)|*.vcf|All files (*.*)|*.*";
                dlg.InitialDirectory = Path.GetFullPath(Path.Combine(
                    Environment.CurrentDirectory, @"..\..\..\..\..\PDIFiles"));

                if(dlg.ShowDialog() == DialogResult.OK)
                {
                    try
                    {
                        this.Cursor = Cursors.WaitCursor;

                        // Parse the vCard information from the file and load the data grid with some basic
                        // information about the vCards in it.
                        vCards = VCardParser.ParseFromFile(dlg.FileName);
                        this.LoadGridWithVCards();

                        lblFilename.Text = dlg.FileName;
                    }
                    catch(Exception ex)
                    {
                        string error = String.Format("Unable to load vCards:\n{0}", ex.Message);

                        if(ex.InnerException != null)
                        {
                            error += ex.InnerException.Message + "\n";

                            if(ex.InnerException.InnerException != null)
                                error += ex.InnerException.InnerException.Message;
                        }

                        System.Diagnostics.Debug.Write(ex);

                        MessageBox.Show(error, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                    finally
                    {
                        this.Cursor = Cursors.Default;
                    }
                }
            }
        }
Exemplo n.º 8
0
        /// <summary>
        /// Save changes and return to the vCard list
        /// </summary>
        /// <param name="sender">The sender of the event</param>
        /// <param name="e">The event arguments</param>
        protected void btnSave_Click(object sender, EventArgs e)
        {
            if (!Page.IsValid)
            {
                return;
            }

            VCardCollection vc = (VCardCollection)Session["VCards"];

            // Not very friendly, but it's just a demo
            if (vc == null)
            {
                Response.Redirect("VCardBrowser.aspx");
                return;
            }

            VCard vCard = vc[(int)this.ViewState["VCardIndex"]];

            // General properties.  Unique ID is not changed.  Last Revision is set to the current date and time.
            vCard.Classification.Value       = txtClass.Text.ToUpperInvariant();
            vCard.LastRevision.DateTimeValue = DateTime.Now;

            // Set the version based on the one selected
            vCard.Version = (cboVersion.SelectedIndex == 0) ? SpecificationVersions.vCard21 :
                            SpecificationVersions.vCard30;

            // Name properties
            vCard.Name.FamilyName      = txtLastName.Text;
            vCard.Name.GivenName       = txtFirstName.Text;
            vCard.Name.AdditionalNames = txtMiddleName.Text;
            vCard.Name.NamePrefix      = txtTitle.Text;
            vCard.Name.NameSuffix      = txtSuffix.Text;
            vCard.SortString.Value     = txtSortString.Text;
            vCard.FormattedName.Value  = txtFormattedName.Text;

            // We'll parse nicknames as a comma separated string
            vCard.Nickname.NicknamesString = txtNickname.Text;

            // Work
            vCard.Organization.Name = txtOrganization.Text;
            vCard.Title.Value       = txtJobTitle.Text;
            vCard.Role.Value        = txtRole.Text;

            // We'll parse units and categories as comma separated strings
            vCard.Organization.UnitsString    = txtUnits.Text;
            vCard.Categories.CategoriesString = txtCategories.Text;

            // Other
            if (txtBirthDate.Text.Length == 0)
            {
                vCard.BirthDate.DateTimeValue = DateTime.MinValue;
            }
            else
            {
                // The web app is limited to date values only for now
                vCard.BirthDate.DateTimeValue = Convert.ToDateTime(txtBirthDate.Text, CultureInfo.CurrentCulture);
                vCard.BirthDate.ValueLocation = ValLocValue.Date;
            }

            // See if the new value is just an offset.  If so, set the value type to UTC Offset.
            try
            {
                vCard.TimeZone.TimeSpanValue = DateUtils.FromISO8601TimeZone(txtTimeZone.Text);
                vCard.TimeZone.ValueLocation = ValLocValue.UtcOffset;
            }
            catch
            {
                vCard.TimeZone.ValueLocation = ValLocValue.Text;
                vCard.TimeZone.Value         = txtTimeZone.Text;
            }

            if (txtLatitude.Text.Length != 0 || txtLongitude.Text.Length != 0)
            {
                vCard.GeographicPosition.Latitude  = Convert.ToDouble(txtLatitude.Text, CultureInfo.CurrentCulture);
                vCard.GeographicPosition.Longitude = Convert.ToDouble(txtLongitude.Text, CultureInfo.CurrentCulture);
            }
            else
            {
                vCard.GeographicPosition.Latitude = vCard.GeographicPosition.Longitude = 0.0F;
            }

            vCard.Url.Value = txtWebPage.Text;

            if (txtComments.Text.Length != 0)
            {
                if (vCard.Notes.Count != 0)
                {
                    vCard.Notes[0].Value = txtComments.Text;
                }
                else
                {
                    vCard.Notes.Add(txtComments.Text);
                }
            }
            else
            if (vCard.Notes.Count != 0)
            {
                vCard.Notes.RemoveAt(0);
            }

            Response.Redirect("VCardBrowser.aspx");
        }
Exemplo n.º 9
0
 public static IEnumerable <VCardDto> CollectionToDtoes(VCardCollection vCards)
 {
     return(from vCard in vCards
            select VCardToDto(vCard, new VCardDto()));
 }
Exemplo n.º 10
0
        //=====================================================================

        /// <summary>
        /// Default constructor
        /// </summary>
        /// <overloads>There are two overloads for the constructor</overloads>
        public VCardParser()
        {
            vCards = new VCardCollection();
        }
Exemplo n.º 11
0
        //=====================================================================

        /// <summary>
        /// Default constructor
        /// </summary>
        /// <overloads>There are two overloads for the constructor</overloads>
        public VCardParser()
        {
            vCards = new VCardCollection();
        }