getRecord method

AsyncReply<KeyList<PropertyTemplate, List<PropertyValue>>?> getRecord(
  1. IResource resource,
  2. DateTime fromDate,
  3. DateTime toDate
)
override
Get resource history. IResource. From date. To date.

Implementation

AsyncReply<KeyList<PropertyTemplate, List<PropertyValue>>?> getRecord(
    IResource resource, DateTime fromDate, DateTime toDate) {
  if (resource is DistributedResource) {
    var dr = resource as DistributedResource;

    if (dr.connection != this)
      return new AsyncReply<
          KeyList<PropertyTemplate, List<PropertyValue>>?>.ready(null);

    var reply =
        new AsyncReply<KeyList<PropertyTemplate, List<PropertyValue>>>();

    sendRequest(IIPPacketAction.ResourceHistory)
      ..addUint32(dr.id as int)
      ..addDateTime(fromDate)
      ..addDateTime(toDate)
      ..done().then<dynamic>((rt) {
        if (rt != null) {
          var content = rt[0] as DC;

          Codec.parseHistory(content, 0, content.length, resource, this)
              .then((history) => reply.trigger(history));
        } else {
          reply.triggerError(Exception("Null response"));
        }
      }).error((ex) => reply.triggerError(ex));

    return reply;
  } else
    return AsyncReply<KeyList<PropertyTemplate, List<PropertyValue>>?>.ready(
        null);
}