TryReadElementFromXml method

  1. @override
Future<bool> TryReadElementFromXml(
  1. EwsServiceXmlReader reader
)
override
Tries to read element from XML. The reader.

Implementation

@override
Future<bool> TryReadElementFromXml(EwsServiceXmlReader reader) async {
  switch (reader.LocalName) {
    case XmlElementNames.Periods:
      do {
        await reader.Read();

        if (reader.IsStartElementWithNamespace(
            XmlNamespace.Types, XmlElementNames.Period)) {
          TimeZonePeriod period = new TimeZonePeriod();
          await period.LoadFromXmlElementName(reader);

          // OM:1648848 Bad timezone data from clients can include duplicate rules
          // for one year, with duplicate ID. In that case, let the first one win.
          if (!this._periods.containsKey(period.Id)) {
            this._periods[period.Id] = period;
          } else {
            reader.Service.TraceMessage(
                TraceFlags.EwsTimeZones, """string.Format(
                                      "An entry with the same key (Id) '{0}' already exists in Periods. Cannot add another one. Existing entry: [Name='{1}', Bias='{2}']. Entry to skip: [Name='{3}', Bias='{4}'].",
                                      period.Id,
                                      this.Periods[period.Id].Name,
                                      this.Periods[period.Id].Bias,
                                      period.Name,
                                      period.Bias)""");
          }
        }
      } while (!reader.IsEndElementWithNamespace(
          XmlNamespace.Types, XmlElementNames.Periods));

      return true;
    case XmlElementNames.TransitionsGroups:
      do {
        await reader.Read();

        if (reader.IsStartElementWithNamespace(
            XmlNamespace.Types, XmlElementNames.TransitionsGroup)) {
          TimeZoneTransitionGroup transitionGroup =
              new TimeZoneTransitionGroup(this);

          await transitionGroup.LoadFromXmlElementName(reader);

          this._transitionGroups[transitionGroup.Id] = transitionGroup;
        }
      } while (!reader.IsEndElementWithNamespace(
          XmlNamespace.Types, XmlElementNames.TransitionsGroups));

      return true;
    case XmlElementNames.Transitions:
      do {
        await reader.Read();

        if (reader.IsStartElement()) {
          TimeZoneTransition transition =
              TimeZoneTransition.Create(this, reader.LocalName);

          await transition.LoadFromXmlElementName(reader);

          this._transitions.add(transition);
        }
      } while (!reader.IsEndElementWithNamespace(
          XmlNamespace.Types, XmlElementNames.Transitions));

      return true;
    default:
      return false;
  }
}