SetLastReadTime() private method

private SetLastReadTime ( int attributeIndex, System.DateTime tm ) : void
attributeIndex int
tm System.DateTime
return void
 /// <summary>
 /// Read object.
 /// </summary>
 /// <param name="InitialValues"></param>
 /// <param name="obj"></param>
 /// <param name="attribute"></param>
 public void Read(object sender, GXDLMSObject obj, int attribute)
 {
     GXReplyData reply = new GXReplyData();
     foreach (int it in (obj as IGXDLMSBase).GetAttributeIndexToRead())
     {
         reply.Clear();
         if (obj is GXDLMSProfileGeneric && it == 2)
         {
             if (OnBeforeRead != null)
             {
                 OnBeforeRead(obj, it);
             }
             try
             {
                 CurrentProfileGeneric = obj as GXDLMSProfileGeneric;
                 OnDataReceived += new GXDLMSCommunicator.DataReceivedEventHandler(this.OnProfileGenericDataReceived);
                 if (CurrentProfileGeneric.AccessSelector == AccessRange.Range ||
                     CurrentProfileGeneric.AccessSelector == AccessRange.Last)
                 {
                     byte[][] tmp = client.ReadRowsByRange(CurrentProfileGeneric, Convert.ToDateTime(CurrentProfileGeneric.From), Convert.ToDateTime(CurrentProfileGeneric.To));
                     ReadDataBlock(tmp[0], "Reading profile generic data", 1, reply);
                 }
                 else if (CurrentProfileGeneric.AccessSelector == AccessRange.Entry)
                 {
                     byte[][] tmp = client.ReadRowsByEntry(CurrentProfileGeneric, Convert.ToInt32(CurrentProfileGeneric.From), Convert.ToInt32(CurrentProfileGeneric.To));
                     ReadDataBlock(tmp[0], "Reading profile generic data " + CurrentProfileGeneric.Name, 1, reply);
                 }
                 else //Read all.
                 {
                     byte[] tmp = client.Read(CurrentProfileGeneric, 2)[0];
                     ReadDataBlock(tmp, "Reading profile generic data " + CurrentProfileGeneric.Name, 1, reply);
                 }
             }
             finally
             {
                 if (OnAfterRead != null)
                 {
                     OnAfterRead(obj, it);
                 }
                 OnDataReceived -= new GXDLMSCommunicator.DataReceivedEventHandler(OnProfileGenericDataReceived);
             }
             continue;
         }
         else
         {
             if (OnBeforeRead != null)
             {
                 OnBeforeRead(obj, it);
             }
             byte[] data = client.Read(obj.Name, obj.ObjectType, it)[0];
             try
             {
                 ReadDataBlock(data, "Read object type " + obj.ObjectType + " index: " + it, reply);
             }
             catch (GXDLMSException ex)
             {
                 if (ex.ErrorCode == 3 ||  //If read is denied.
                     ex.ErrorCode == 4 || // Undefined object.
                     ex.ErrorCode == 13) //Actaris returns access violation error.
                 {
                     obj.SetAccess(it, AccessMode.NoAccess);
                     continue;
                 }
                 else
                 {
                     throw ex;
                 }
             }
             if (obj is IGXDLMSBase)
             {
                 object value = reply.Value;
                 DataType type;
                 if (value is byte[] && (type = obj.GetUIDataType(it)) != DataType.None)
                 {
                     value = GXDLMSClient.ChangeType((byte[])value, type);
                 }
                 client.UpdateValue(obj, it, value);
             }
             if (OnAfterRead != null)
             {
                 OnAfterRead(obj, it);
             }
             obj.SetLastReadTime(it, DateTime.Now);
             //If only selected attribute is read.
             if (attribute != 0)
             {
                 break;
             }
         }
     }
 }
 /// <summary>
 /// Read object.
 /// </summary>
 /// <param name="InitialValues"></param>
 /// <param name="obj"></param>
 /// <param name="attribute"></param>
 public void Read(object sender, GXDLMSObject obj, int attribute)
 {
     foreach (int it in (obj as IGXDLMSBase).GetAttributeIndexToRead())
     {
         if (obj is GXDLMSProfileGeneric && it == 2)
         {
             if (OnBeforeRead != null)
             {
                 OnBeforeRead(obj, it);
             }
             try
             {
                 CurrentProfileGeneric = obj as GXDLMSProfileGeneric;
                 OnDataReceived += new GXDLMSCommunicator.DataReceivedEventHandler(this.OnProfileGenericDataReceived);
                 if (CurrentProfileGeneric.AccessSelector != AccessRange.Entry)
                 {
                     GXDLMSObject obj2 = CurrentProfileGeneric.CaptureObjects[0].Key;
                     byte[] tmp = m_Cosem.ReadRowsByRange(CurrentProfileGeneric.Name, obj2.LogicalName,
                         obj2.ObjectType, obj2.Version,
                         Convert.ToDateTime(CurrentProfileGeneric.From), Convert.ToDateTime(CurrentProfileGeneric.To));
                     ReadDataBlock(tmp, "Reading profile generic data", 1);
                 }
                 else
                 {
                     byte[] tmp = m_Cosem.ReadRowsByEntry(CurrentProfileGeneric.Name, Convert.ToInt32(CurrentProfileGeneric.From), Convert.ToInt32(CurrentProfileGeneric.To));
                     ReadDataBlock(tmp, "Reading profile generic data " + CurrentProfileGeneric.Name, 1);
                 }
             }
             finally
             {
                 if (OnAfterRead != null)
                 {
                     OnAfterRead(obj, it);
                 }
                 OnDataReceived -= new GXDLMSCommunicator.DataReceivedEventHandler(OnProfileGenericDataReceived);
             }
             continue;
         }
         else
         {
             if (OnBeforeRead != null)
             {
                 OnBeforeRead(obj, it);
             }
             byte[] data = m_Cosem.Read(obj.Name, obj.ObjectType, it)[0];
             try
             {
                 data = ReadDataBlock(data, "Read object type " + obj.ObjectType + " index: " + it);
             }
             catch (GXDLMSException ex)
             {
                 if (ex.ErrorCode == 3 ||  //If read is denied.
                     ex.ErrorCode == 4 || // Undefined object.
                     ex.ErrorCode == 13) //Actaris returns access violation error.
                 {
                     obj.SetAccess(it, AccessMode.NoAccess);
                     continue;
                 }
                 else
                 {
                     throw ex;
                 }
             }
             if (obj is IGXDLMSBase)
             {
                 object value = m_Cosem.GetValue(data);
                 DataType type;
                 if (value is byte[] && (type = obj.GetUIDataType(it)) != DataType.None)
                 {
                     value = GXDLMS.Common.GXHelpers.ConvertFromDLMS(value, obj.GetDataType(it), type, true);
                 }
                 (obj as IGXDLMSBase).SetValue(it, value);
             }
             if (OnAfterRead != null)
             {
                 OnAfterRead(obj, it);
             }
             obj.SetLastReadTime(it, DateTime.Now);
             //If only selected attribute is read.
             if (attribute != 0)
             {
                 break;
             }
         }
     }
 }