DefaultExtensions Save(string path) { if (path == null) { throw new ArgumentNullException("path"); } const int mimeTypeWidth = 48; const int tabulationWidth = 8; using (var streamWriter = new StreamWriter(path, false, Encoding.Default)) { streamWriter.WriteLine(LastModifiedFormat, LastModified.ToUniversalTime().ToString("O", CultureInfo.InvariantCulture)); streamWriter.WriteLine("#"); streamWriter.WriteLine("# MIME type (lowercased)\t\t\tExtensions"); streamWriter.WriteLine("# ============================================\t=========="); foreach (var mimeType in this.OrderBy(mimeType => mimeType.ToString(), StringComparer.OrdinalIgnoreCase)) { var mimeTypeName = mimeType.ToString(); if (mimeType.Extensions != null) { streamWriter.WriteLine("{0}{1}{2}", mimeTypeName, new string('\t', mimeTypeName.Length < mimeTypeWidth ? (mimeTypeWidth - mimeTypeName.Length) / tabulationWidth + 1 : 1), string.Join(" ", mimeType.Extensions.Select(extension => extension.Substring(1)))); } else { streamWriter.WriteLine("# {0}", mimeTypeName); } } } return(this); }
public string GetText() { var text = new StringBuilder(); text.AppendLine("BEGIN:VEVENT"); // header text.AppendLine($"UID:{Uid}"); // definition if (AllDay) { text.AppendLine($"DTSTART;VALUE=DATE:{Start.ToString("yyyyMMdd")}"); text.AppendLine($"DTEND;VALUE=DATE:{End.ToString("yyyyMMdd")}"); } else { text.AppendLine($"DTSTART:{Start.ToUniversalTime().ToString("yyyyMMddTHHmmssZ")}"); text.AppendLine($"DTEND:{End.ToUniversalTime().ToString("yyyyMMddTHHmmssZ")}"); } text.AppendLine($"DTSTAMP:{Stamp.ToUniversalTime().ToString("yyyyMMddTHHmmssZ")}"); text.AppendLine($"CREATED:{Created.ToUniversalTime().ToString("yyyyMMddTHHmmssZ")}"); text.AppendLine($"LAST-MODIFIED:{LastModified.ToUniversalTime().ToString("yyyyMMddTHHmmssZ")}"); text.AppendLine($"TRANSP:{Transparency}"); text.AppendLine($"STATUS:{Status}"); if (!string.IsNullOrEmpty(Organizer)) { text.AppendLine($"ORGANIZER:{Organizer}"); } if (!string.IsNullOrEmpty(Location)) { text.AppendLine($"X-LIC-LOCATION:{Location}"); } if (Attendees != null) { foreach (var attendee in Attendees) { text.AppendLine($"ATTENDEE:{attendee}"); } } if (!string.IsNullOrEmpty(Description)) { text.AppendLine($"DESCRIPTION:{Description}"); } if (!string.IsNullOrEmpty(Summary)) { text.AppendLine($"SUMMARY:{Summary}"); } // alarm if (Alarm != null) { text.AppendLine(Alarm.GetText()); } // end text.AppendLine("END:VEVENT"); return(text.ToString()); }