本文整理汇总了C#中DDay.iCal.Serialization.iCalendarSerializer.Deserialize方法的典型用法代码示例。如果您正苦于以下问题:C# iCalendarSerializer.Deserialize方法的具体用法?C# iCalendarSerializer.Deserialize怎么用?C# iCalendarSerializer.Deserialize使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DDay.iCal.Serialization.iCalendarSerializer
的用法示例。
在下文中一共展示了iCalendarSerializer.Deserialize方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: RulesetValidator
public RulesetValidator(IValidationRuleset ruleset, string text) :
this(ruleset)
{
iCalendarText = text;
try
{
iCalendarSerializer serializer = new iCalendarSerializer();
// Turn off speed optimization so line/col from
// antlr are accurate.
serializer.OptimizeForSpeed = false;
iCalendar = serializer.Deserialize(new StringReader(text), typeof(iCalendar)) as iCalendar;
}
catch (antlr.RecognitionException ex)
{
_RecognitionError = new ValidationErrorWithLookup(
"calendarParseError",
ValidationErrorType.Error,
true,
ex.line,
ex.column);
}
}
示例2: Validate
public IValidationResult[] Validate()
{
if (Ruleset != null)
{
// If no iCalendar was provided, let's ensure it can
// at least be basically parsed before moving on to
// more in-depth validation rules.
if (iCalendar == null &&
!string.IsNullOrEmpty(iCalendarText))
{
try
{
StringReader sr = new StringReader(iCalendarText);
// Turn off speed optimization to ensure we get proper
// line/column numbers
iCalendarSerializer serializer = new iCalendarSerializer();
serializer.OptimizeForSpeed = false;
iCalendar calendar = serializer.Deserialize(sr, typeof(iCalendar)) as iCalendar;
}
catch (antlr.MismatchedTokenException ex)
{
return new IValidationResult[]
{
new ValidationResult(
null,
false,
new IValidationError[] { new ValidationErrorWithLookup("calendarParseError", ValidationErrorType.Error, true, ex.line, ex.column) }
)
};
}
}
// We've passed a basic parsing test, let's move
// on to the more complex tests!
List<IValidationResult> results = new List<IValidationResult>();
foreach (IValidationRule rule in Ruleset.Rules)
{
IValidator validator = null;
Type validatorType = rule.ValidatorType;
if (validatorType != null)
validator = ValidatorActivator.Create(validatorType, iCalendar, iCalendarText);
if (validator == null)
{
results.Add(
new ValidationResult(
rule.Name,
false,
new IValidationError[] {
new ValidationError(null, "Validator for rule '" + rule.Name + "' could not be determined!")
}
)
);
}
else
{
IValidationResult[] currentResults = validator.Validate();
results.AddRange(currentResults);
// Determine if there were any fatal errors in the results.
// If there are, then we need to abort any further processing!
bool isFatal = false;
foreach (IValidationResult result in currentResults)
{
if (result.Errors != null)
{
foreach (IValidationError err in result.Errors)
{
if (err.IsFatal)
{
isFatal = true;
break;
}
}
}
if (isFatal)
break;
}
if (isFatal)
break;
}
}
return results.ToArray();
}
else return new IValidationResult[0];
}
示例3: Bug3512192
public void Bug3512192()
{
IICalendar calendar = new iCalendar();
calendar.Method = "PUBLISH";
IEvent evt = calendar.Create<Event>();
evt.Summary = "Test Event";
evt.Start = new iCalDateTime(2012, 3, 27, 22, 00, 00);
evt.Duration = TimeSpan.FromHours(1);
var attendees = new List<IAttendee>();
var attendee = new Attendee("MAILTO:[email protected]")
{
CommonName = "Test Name",
Role = "OPT-PARTICIPANT",
Members = new List<string>() { "Other", "Name" }
};
attendees.Add(attendee);
evt.Attendees = attendees;
// Serialize (save) the iCalendar
var serializer = new iCalendarSerializer(calendar);
var result = serializer.SerializeToString(calendar);
var calendars = serializer.Deserialize(new StringReader(result)) as IICalendarCollection;
calendar = calendars.First();
evt = calendar.Events.First();
Assert.AreEqual(1, evt.Attendees.Count);
Assert.AreEqual(attendee, evt.Attendees[0]);
Assert.AreEqual("Test Name", evt.Attendees[0].CommonName);
Assert.AreEqual("OPT-PARTICIPANT", evt.Attendees[0].Role);
Assert.AreEqual(1, evt.Attendees[0].Members.Count);
}
示例4: Bug3485766
public void Bug3485766()
{
IICalendar calendar = new iCalendar();
IEvent evt = calendar.Create<Event>();
evt.Start = new iCalDateTime(2012, 5, 23, 8, 0, 0);
evt.Duration = TimeSpan.FromMinutes(30);
// Ensure the DTStamp is in universal time to begin with
Assert.IsTrue(evt.DTStamp.IsUniversalTime);
// Convert to local time
evt.DTStamp = new iCalDateTime(evt.DTStamp.Local);
// Serialize the calendar
var serializer = new iCalendarSerializer();
var serialized = serializer.SerializeToString(calendar);
IICalendarCollection calendars = serializer.Deserialize(new StringReader(serialized)) as IICalendarCollection;
calendar = calendars.First();
evt = calendar.Events[0];
// Ensure the object was serialized as UTC
Assert.IsTrue(evt.DTStamp.IsUniversalTime);
}