//===================================================================== /// <summary> /// Constructor /// </summary> public TimeZoneListDlg() { InitializeComponent(); dgvCalendar.AutoGenerateColumns = false; tbcLastModified.DefaultCellStyle.Format = CultureInfo.CurrentCulture.DateTimeFormat.ShortDatePattern + " " + CultureInfo.CurrentCulture.DateTimeFormat.ShortTimePattern; vCal = null; timeZones = new VTimeZoneCollection(); LoadGridWithItems(); }
//===================================================================== /// <summary> /// Constructor /// </summary> public CalendarBrowserForm() { InitializeComponent(); // The string format to use when drawing the status text sf = new StringFormat(StringFormatFlags.NoWrap); sf.Alignment = StringAlignment.Near; sf.LineAlignment = StringAlignment.Center; sf.Trimming = StringTrimming.EllipsisCharacter; dgvCalendar.AutoGenerateColumns = false; // Load the time zone collection with info from the registry TimeZoneRegInfo.LoadTimeZoneInfo(); vCal = new VCalendar(); LoadComponentList(); LoadGridWithItems(true); }
/// <summary> /// Open a vCalendar or iCalendar 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 calendar?", "Discard Changes", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2) == DialogResult.No) return; using(OpenFileDialog dlg = new OpenFileDialog()) { dlg.Title = "Load Calendar File"; dlg.Filter = "ICS files (*.ics)|*.ics|VCS files (*.vcs)|*.vcs|All files (*.*)|*.*"; if(vCal.Version == SpecificationVersions.vCalendar10) { dlg.DefaultExt = "vcs"; dlg.FilterIndex = 2; } else { dlg.DefaultExt = "ics"; dlg.FilterIndex = 1; } dlg.InitialDirectory = Path.GetFullPath(Path.Combine( Environment.CurrentDirectory, @"..\..\..\..\..\PDIFiles")); if(dlg.ShowDialog() == DialogResult.OK) { try { this.Cursor = Cursors.WaitCursor; // Parse the calendar information from the file and load the data grid with some basic // information about the items in it. vCal.Dispose(); vCal = VCalendarParser.ParseFromFile(dlg.FileName); LoadComponentList(); // Find the first collection with items if(vCal.Events.Count != 0) cboComponents.SelectedIndex = 0; else if(vCal.ToDos.Count != 0) cboComponents.SelectedIndex = 1; else if(vCal.Journals.Count != 0) cboComponents.SelectedIndex = 2; else if(vCal.FreeBusys.Count != 0) cboComponents.SelectedIndex = 3; else cboComponents.SelectedIndex = 0; LoadGridWithItems(true); lblFilename.Text = dlg.FileName; } catch(Exception ex) { string error = String.Format("Unable to load calendar:\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; } } } }
//===================================================================== /// <summary> /// This is overridden to allow cloning of a PDI object /// </summary> /// <returns>A clone of the object</returns> public override object Clone() { VCalendar o = new VCalendar(); o.Clone(this); return o; }
/// <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) { SpecificationVersions version = SpecificationVersions.None; string temp; int idx; // Is it parsing a sub-object? if(currentState != VCalendarParserState.VCalendar) { switch(currentState) { case VCalendarParserState.VEvent: VEventParser(propertyName, parameters, propertyValue); break; case VCalendarParserState.VToDo: VToDoParser(propertyName, parameters, propertyValue); break; case VCalendarParserState.VJournal: VJournalParser(propertyName, parameters, propertyValue); break; case VCalendarParserState.VAlarm: VAlarmParser(propertyName, parameters, propertyValue); break; case VCalendarParserState.VFreeBusy: VFreeBusyParser(propertyName, parameters, propertyValue); break; case VCalendarParserState.VTimeZone: VTimeZoneParser(propertyName, parameters, propertyValue); break; case VCalendarParserState.ObservanceRule: ObservanceRuleParser(propertyName, parameters, propertyValue); break; case VCalendarParserState.Custom: CustomObjectParser(propertyName, parameters, propertyValue); break; } return; } // The last entry is always CustomProperty so scan for length minus one for(idx = 0; idx < ntvCal.Length - 1; idx++) if(ntvCal[idx].IsMatch(propertyName)) break; // An opening BEGIN:VCALENDAR property must have been seen if(vCal == null && ntvCal[idx].EnumValue != PropertyType.Begin) throw new PDIParserException(this.LineNumber, LR.GetString("ExParseNoBeginProp", "BEGIN:VCALENDAR", propertyName)); // Handle or create the property switch(ntvCal[idx].EnumValue) { case PropertyType.Begin: // Start a new object temp = propertyValue.Trim(); // The last entry is always Custom so scan for length - 1 for(idx = 0; idx < ntvObjs.Length - 1; idx++) if(ntvObjs[idx].IsMatch(temp)) break; priorState.Push(currentState); currentState = ntvObjs[idx].EnumValue; switch(currentState) { case VCalendarParserState.VCalendar: // NOTE: If serializing into an existing instance, this may not be null. If so, it // is ignored. It may also exist if two calendars appear in the same file. In that // case, they will be merged into one calendar. if(vCal == null) vCal = new VCalendar(); break; case VCalendarParserState.VEvent: vEvent = new VEvent(); vCal.Events.Add(vEvent); break; case VCalendarParserState.VToDo: vToDo = new VToDo(); vCal.ToDos.Add(vToDo); break; case VCalendarParserState.VJournal: vJournal = new VJournal(); vCal.Journals.Add(vJournal); break; case VCalendarParserState.VFreeBusy: vFreeBusy = new VFreeBusy(); vCal.FreeBusys.Add(vFreeBusy); break; case VCalendarParserState.VTimeZone: // NOTE: Unlike the other objects, time zone are not added to the collection until // the END Tag is encountered as they are shared amongst all calendar instances. vTimeZone = new VTimeZone(); break; case VCalendarParserState.Custom: CustomObjectParser(propertyName, parameters, propertyValue); break; } break; case PropertyType.End: // The value must be VCALENDAR if(String.Compare(propertyValue.Trim(), "VCALENDAR", StringComparison.OrdinalIgnoreCase) != 0) throw new PDIParserException(this.LineNumber, LR.GetString("ExParseUnrecognizedTagValue", ntvCal[idx].Name, propertyValue)); // When done, we'll propagate the version number to all objects to make it consistent vCal.PropagateVersion(); break; case PropertyType.Version: // Version must be 1.0 or 2.0 temp = propertyValue.Trim(); if(temp == "1.0") version = SpecificationVersions.vCalendar10; else if(temp == "2.0") version = SpecificationVersions.iCalendar20; else throw new PDIParserException(this.LineNumber, LR.GetString("ExParseUnrecognizedVersion", "vCalendar/iCalendar", temp)); vCal.Version = version; break; case PropertyType.ProductId: vCal.ProductId.EncodedValue = propertyValue; break; case PropertyType.CalendarScale: vCal.CalendarScale.DeserializeParameters(parameters); vCal.CalendarScale.EncodedValue = propertyValue; break; case PropertyType.Method: vCal.Method.DeserializeParameters(parameters); vCal.Method.EncodedValue = propertyValue; break; case PropertyType.GeographicPosition: vCal.VCalendarGeographicPosition.EncodedValue = propertyValue; break; case PropertyType.TimeZone: vCal.VCalendarTimeZone.DeserializeParameters(parameters); vCal.VCalendarTimeZone.EncodedValue = propertyValue; break; case PropertyType.Daylight: vCal.VCalendarDaylightRule.DeserializeParameters(parameters); vCal.VCalendarDaylightRule.EncodedValue = propertyValue; break; default: // Anything else is a custom property CustomProperty c = new CustomProperty(propertyName); c.DeserializeParameters(parameters); c.EncodedValue = propertyValue; vCal.CustomProperties.Add(c); break; } }
/// <summary> /// This static method can be used to load property values into an existing instance of a calendar from a /// string. /// </summary> /// <param name="calendarText">A set of calendar properties in a string</param> /// <param name="calendar">The calendar instance into which the properties will be loaded</param> /// <remarks>The properties of the specified calendar will be cleared before the new properties are /// loaded into it.</remarks> /// <example> /// <code language="cs"> /// VCalendar vCalendar = new VCalendar(); /// VCalendarParser.ParseFromString(calendarString, vCalendar); /// </code> /// <code language="vbnet"> /// Dim vCalendar As New VCalendar /// VCalendarParser.ParseFromString(calendarString, vCalendar) /// </code> /// </example> public static void ParseFromString(string calendarText, VCalendar calendar) { VCalendarParser vcp = new VCalendarParser(calendar); vcp.ParseString(calendarText); }
/// <summary> /// This version of the constructor is used when parsing calendar data that is to be stored in an /// existing vCalendar/iCalendar instance. /// </summary> /// <remarks>The properties in the passed calendar will be cleared</remarks> /// <param name="calendar">The existing calendar instance</param> /// <exception cref="ArgumentNullException">This is thrown if the specified calendar object is null</exception> protected VCalendarParser(VCalendar calendar) : this() { if(calendar == null) throw new ArgumentNullException("calendar", LR.GetString("ExParseNullObject", "vCalendar/iCalendar")); vCal = calendar; vCal.ClearProperties(); }