Example #1
0
 void IGXDLMSBase.SetValue(GXDLMSSettings settings, int index, object value)
 {
     if (index == 1)
     {
         if (value is string)
         {
             LogicalName = value.ToString();
         }
         else
         {
             LogicalName = GXDLMSClient.ChangeType((byte[])value, DataType.OctetString).ToString();
         }
     }
     else if (index == 2)
     {
         Entries = null;
         if (value != null)
         {
             List <GXDLMSSpecialDay> items = new List <GXDLMSSpecialDay>();
             foreach (Object[] item in (Object[])value)
             {
                 GXDLMSSpecialDay it = new GXDLMSSpecialDay();
                 it.Index = Convert.ToUInt16(item[0]);
                 it.Date  = (GXDateTime)GXDLMSClient.ChangeType((byte[])item[1], DataType.Date);
                 it.DayId = Convert.ToByte(item[2]);
                 items.Add(it);
             }
             Entries = items.ToArray();
         }
     }
     else
     {
         throw new ArgumentException("SetValue failed. Invalid attribute index.");
     }
 }
 void IGXDLMSBase.SetValue(GXDLMSSettings settings, ValueEventArgs e)
 {
     if (e.Index == 1)
     {
         LogicalName = GXCommon.ToLogicalName(e.Value);
     }
     else if (e.Index == 2)
     {
         Entries = null;
         if (e.Value != null)
         {
             List <GXDLMSSpecialDay> items = new List <GXDLMSSpecialDay>();
             foreach (Object[] item in (Object[])e.Value)
             {
                 GXDLMSSpecialDay it = new GXDLMSSpecialDay();
                 it.Index = Convert.ToUInt16(item[0]);
                 it.Date  = (GXDate)GXDLMSClient.ChangeType((byte[])item[1], DataType.Date, settings.UseUtc2NormalTime);
                 it.DayId = Convert.ToByte(item[2]);
                 items.Add(it);
             }
             Entries = items.ToArray();
         }
     }
     else
     {
         e.Error = ErrorCode.ReadWriteDenied;
     }
 }
        /// <summary>
        /// Inserts a new entry in the table.
        /// </summary>
        /// <remarks>
        /// </remarks>
        /// <returns>
        ///  If a special day with the same index or with the same date as an already defined day is inserted,
        ///  the old entry will be overwritten.
        /// </returns>
        public byte[][] Insert(GXDLMSClient client, GXDLMSSpecialDay entry)
        {
            GXByteBuffer bb = new GXByteBuffer();

            bb.SetUInt8(DataType.Structure);
            bb.SetUInt8(3);
            GXCommon.SetData(null, bb, DataType.UInt16, entry.Index);
            GXCommon.SetData(null, bb, DataType.OctetString, entry.Date);
            GXCommon.SetData(null, bb, DataType.UInt8, entry.DayId);
            return(client.Method(this, 1, bb.Array(), DataType.Array));
        }
 void IGXDLMSBase.SetValue(GXDLMSSettings settings, ValueEventArgs e)
 {
     if (e.Index == 1)
     {
         LogicalName = GXCommon.ToLogicalName(e.Value);
     }
     else if (e.Index == 2)
     {
         Entries = null;
         if (e.Value != null)
         {
             List <GXDLMSSpecialDay> items = new List <GXDLMSSpecialDay>();
             foreach (object tmp in (IEnumerable <object>)e.Value)
             {
                 List <object> item;
                 if (tmp is List <object> )
                 {
                     item = (List <object>)tmp;
                 }
                 else
                 {
                     item = new List <object>((object[])tmp);
                 }
                 GXDLMSSpecialDay it = new GXDLMSSpecialDay();
                 it.Index = Convert.ToUInt16(item[0]);
                 if (item[1] is GXDate)
                 {
                     it.Date = (GXDate)item[1];
                 }
                 else if (item[1] is byte[])
                 {
                     it.Date = (GXDate)GXDLMSClient.ChangeType((byte[])item[1], DataType.Date, settings.UseUtc2NormalTime);
                 }
                 else
                 {
                     throw new Exception("Invalid date.");
                 }
                 it.DayId = Convert.ToByte(item[2]);
                 items.Add(it);
             }
             Entries = items.ToArray();
         }
     }
     else
     {
         e.Error = ErrorCode.ReadWriteDenied;
     }
 }
 byte[] IGXDLMSBase.Invoke(GXDLMSSettings settings, ValueEventArgs e)
 {
     if (e.Index != 1 && e.Index != 2)
     {
         e.Error = ErrorCode.ReadWriteDenied;
     }
     else
     {
         List <GXDLMSSpecialDay> items = new List <GXDLMSSpecialDay>();
         if (Entries != null)
         {
             items.AddRange(Entries);
         }
         if (e.Index == 1)
         {
             Object[]         item = (Object[])e.Parameters;
             GXDLMSSpecialDay it   = new GXDLMSSpecialDay();
             it.Index = Convert.ToUInt16(item[0]);
             it.Date  = (GXDate)GXDLMSClient.ChangeType((byte[])item[1], DataType.Date, settings.UseUtc2NormalTime);
             it.DayId = Convert.ToByte(item[2]);
             foreach (GXDLMSSpecialDay item2 in items)
             {
                 if (item2.Index == it.Index)
                 {
                     items.Remove(item2);
                     break;
                 }
             }
             items.Add(it);
         }
         else if (e.Index == 2)
         {
             UInt16 index = Convert.ToUInt16(e.Parameters);
             foreach (GXDLMSSpecialDay item in items)
             {
                 if (item.Index == index)
                 {
                     items.Remove(item);
                     break;
                 }
             }
         }
         Entries = items.ToArray();
     }
     return(null);
 }
        void IGXDLMSBase.Load(GXXmlReader reader)
        {
            List <GXDLMSSpecialDay> list = new List <GXDLMSSpecialDay>();

            if (reader.IsStartElement("Entries", true))
            {
                while (reader.IsStartElement("Entry", true))
                {
                    GXDLMSSpecialDay it = new GXDLMSSpecialDay();
                    it.Index = (UInt16)reader.ReadElementContentAsInt("Index");
                    it.Date  = new GXDate(reader.ReadElementContentAsString("Date"), CultureInfo.InvariantCulture);
                    it.DayId = (byte)reader.ReadElementContentAsInt("DayId");
                    list.Add(it);
                }
                reader.ReadEndElement("Entries");
            }
            Entries = list.ToArray();
        }
 void IGXDLMSBase.SetValue(int index, object value)
 {
     if (index == 1)
     {
         if (value is string)
         {
             LogicalName = value.ToString();
         }
         else
         {
             LogicalName = GXDLMSClient.ChangeType((byte[])value, DataType.OctetString).ToString();
         }
     }
     else if (index == 2)
     {
         Entries = null;
         if (value != null)
         {
             List<GXDLMSSpecialDay> items = new List<GXDLMSSpecialDay>();
             foreach (Object[] item in (Object[])value)
             {
                 GXDLMSSpecialDay it = new GXDLMSSpecialDay();
                 it.Index = Convert.ToUInt16(item[0]);
                 it.Date = (GXDateTime)GXDLMSClient.ChangeType((byte[])item[1], DataType.Date);
                 it.DayId = Convert.ToByte(item[2]);
                 items.Add(it);
             }
             Entries = items.ToArray();
         }
     }
     else
     {
         throw new ArgumentException("SetValue failed. Invalid attribute index.");
     }
 }
 /// <summary>
 /// Deletes an entry from the table.
 /// </summary>
 /// <returns></returns>
 public byte[][] Delete(GXDLMSClient client, GXDLMSSpecialDay entry)
 {
     return(client.Method(this, 2, (UInt16)entry.Index));
 }
 void IGXDLMSBase.SetValue(GXDLMSSettings settings, ValueEventArgs e)
 {
     if (e.Index == 1)
     {
         if (e.Value is string)
         {
             LogicalName = e.Value.ToString();
         }
         else
         {
             LogicalName = GXDLMSClient.ChangeType((byte[])e.Value, DataType.OctetString).ToString();
         }
     }
     else if (e.Index == 2)
     {
         Entries = null;
         if (e.Value != null)
         {
             List<GXDLMSSpecialDay> items = new List<GXDLMSSpecialDay>();
             foreach (Object[] item in (Object[])e.Value)
             {
                 GXDLMSSpecialDay it = new GXDLMSSpecialDay();
                 it.Index = Convert.ToUInt16(item[0]);
                 it.Date = (GXDateTime)GXDLMSClient.ChangeType((byte[])item[1], DataType.Date);
                 it.DayId = Convert.ToByte(item[2]);
                 items.Add(it);
             }
             Entries = items.ToArray();
         }
     }
     else
     {
         e.Error = ErrorCode.ReadWriteDenied;
     }
 }
Example #10
0
 /// <summary>
 /// Inserts a new entry in the table.
 /// </summary>
 /// <remarks>
 /// </remarks>
 /// <returns>
 ///  If a special day with the same index or with the same date as an already defined day is inserted,
 ///  the old entry will be overwritten.
 /// </returns>
 public byte[][] Insert(GXDLMSClient client, GXDLMSSpecialDay entry)
 {
     return(Insert(client, new GXDLMSSpecialDay[] { entry }));
 }