Example #1
0
        /// <summary>
        /// Update all values of given COSEM object.
        /// </summary>
        /// <param name="obj"></param>
        /// <param name="view"></param>
        public static void UpdateProperties(IGXDLMSBase obj, IGXDLMSView view)
        {
            if (obj == null)
            {
                return;
            }
            GXDLMSObject tmp = view.Target;

            view.Description = tmp.Description;
            //If we want to show what properties are changed.
            if (view.ErrorProvider != null)
            {
                view.ErrorProvider.Clear();
                foreach (int it in tmp.GetDirtyAttributeIndexes())
                {
                    UpdateDirty(view, ((Form)view).Controls, tmp, it, true);
                }
            }
            //Update atribute values.
            for (int it = 1; it != obj.GetAttributeCount() + 1; ++it)
            {
                object value = null;
                bool   dirty = view.Target.GetDirty(it, out value);
                value = view.Target.GetValues()[it - 1];
                bool bFound = UpdateProperty(view, ((Form)view).Controls, it, value);
                if (!bFound)
                {
                    view.OnAccessRightsChange(it, view.Target.GetAccess(it));
                }
                if (!bFound)
                {
                    view.OnValueChanged(it, value, false);
                }
            }
        }
Example #2
0
        /// <summary>
        /// Update selected values of given COSEM object.
        /// </summary>
        /// <param name="obj"></param>
        /// <param name="view"></param>
        public static void UpdateProperty(GXDLMSClient client, GXDLMSObject obj, int index, IGXDLMSView view, bool connected, bool user)
        {
            if (obj == null)
            {
                return;
            }
            if ((view as Form).InvokeRequired)
            {
                try
                {
                    (view as Form).BeginInvoke(new UpdatePropertyEventHandler(UpdateProperty), client, obj, index, view, connected, user);
                }
                catch (Exception ex)
                {
                    System.Windows.Forms.MessageBox.Show(view as Form, ex.Message, "Error", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error);
                }
                return;
            }
            GXDLMSObject tmp = view.Target;

            view.Description = tmp.Description;
            //If we want to show what properties are changed.
            if (view.ErrorProvider != null)
            {
                view.ErrorProvider.Clear();
                foreach (int it in tmp.GetDirtyAttributeIndexes())
                {
                    UpdateDirty(view, ((Form)view).Controls, tmp, it, true);
                }
            }
            //Update atribute values.
            for (int it = 1; it != (obj as IGXDLMSBase).GetAttributeCount() + 1; ++it)
            {
                if (index == 0 || it == index)
                {
                    object value = null;
                    bool   dirty = view.Target.GetDirty(it, out value);
                    value = view.Target.GetValues()[it - 1];
                    GXValueField item = UpdateProperty(view, ((Form)view).Controls, it, value);
                    if (item == null || item.NotifyChanges)
                    {
                        GXDLMSViewArguments arg = new GXDLMSViewArguments()
                        {
                            Client = client, Index = it, Connected = connected, User = user, Value = value
                        };
                        view.OnValueChanged(arg);
                    }
                    if (it == index)
                    {
                        break;
                    }
                }
            }
        }
Example #3
0
 static void OnValueChanged(IGXDLMSView view, int index, object value, bool changeByUser)
 {
     view.OnValueChanged(index, value, changeByUser);
 }
Example #4
0
 private void UpdateProperties(object obj, IGXDLMSView view, List<object> UpdatedObjects, int index)
 {
     if (obj == null)
     {
         return;
     }
     UpdateWriteEnabled();
     GXDLMSObject tmp = view.Target;
     view.Description = tmp.Description;
     if (view.ErrorProvider != null)
     {
         view.ErrorProvider.Clear();
         foreach (int it in tmp.GetDirtyAttributeIndexes())
         {
             UpdateDirty(view, ((Form)view).Controls, tmp, it, true);
         }
     }
     bool InvokeRequired = ((Form)view).InvokeRequired;
     for (int it = 1; it != (obj as IGXDLMSBase).GetAttributeCount() + 1; ++it)
     {
         if (index == 0 || index == it)
         {
             object value = null;
             bool dirty = view.Target.GetDirty(it, out value);
             value = view.Target.GetValues()[it - 1];
             bool bFound = UpdateProperties(view, ((Form)view).Controls, view.Target, it, value);
             if (!bFound)
             {
                 view.OnAccessRightsChange(it, view.Target.GetAccess(it));
             }
             if (!bFound)
             {
                 if (InvokeRequired)
                 {
                     ((Form)view).Invoke(new ValueChangedEventHandler(OnValueChanged), new object[] { view, it, value, dirty });
                 }
                 else
                 {
                     view.OnValueChanged(it, value, false);
                 }
             }
         }
     }
 }
Example #5
0
 static void OnValueChanged(IGXDLMSView view, int attributeID, object value, bool changeByUser)
 {
     view.OnValueChanged(attributeID, value);
 }
Example #6
0
        private void UpdateProperties(object obj, IGXDLMSView view, List<object> UpdatedObjects, int index)
        {
            if (obj == null)
            {
                return;
            }
            UpdateWriteEnabled();
            GXDLMSObject tmp = view.Target;
            view.Description = tmp.Description;
            if (view.ErrorProvider != null)
            {
                view.ErrorProvider.Clear();
                foreach (int it in tmp.GetDirtyAttributeIndexes())
                {
                    UpdateDirty(view, ((Form)view).Controls, tmp, it, true);
                }
            }
            bool InvokeRequired = ((Form)view).InvokeRequired;
            for(int it = 1; it != (obj as IGXDLMSBase).GetAttributeCount() + 1; ++it)
            {
                if (index == 0 || index == it)
                {
                    object value = null;
                    bool dirty = view.Target.GetDirty(it, out value);
                    value = view.Target.GetValues()[it - 1];
                    bool bFound = UpdateProperties(view, ((Form)view).Controls, view.Target, it, value);
                    if (!bFound)
                    {
                        view.OnAccessRightsChange(it, view.Target.GetAccess(it));
                    }
                    if (!bFound)
                    {
                        if (InvokeRequired)
                        {
                            ((Form)view).Invoke(new ValueChangedEventHandler(OnValueChanged), new object[] { view, it, value, dirty });
                        }
                        else
                        {
                            view.OnValueChanged(it, value);
                        }
                    }
                }
            }

            /*
            PropertyDescriptorCollection properties = TypeDescriptor.GetProperties(obj);
            foreach (PropertyDescriptor it in properties)
            {
                GXDLMSAttributeSettings att = it.Attributes[typeof(GXDLMSAttribute)] as GXDLMSAttribute;
                if (att != null && att.Index != 0 && (index == 0 || index == att.Index))
                {
                    //Use user defined attribute if set.
                    GXDLMSAttributeSettings tmp = ((GXDLMSObject)obj).Attributes.Find(att.Index);
                    if (tmp != null)
                    {
                        att = tmp;
                    }
                    object value = null;
                    bool dirty = view.Target.GetDirty(att.Index, out value);
                    value = it.GetValue(obj);
                    bool bFound = UpdateProperties(view, ((Form)view).Controls, view.Target, att, value);
                    if (!bFound)
                    {
                        view.OnAccessRightsChange(att.Index, att.Access);
                    }
                    if (!bFound)
                    {
                        if (InvokeRequired)
                        {
                            ((Form)view).Invoke(new ValueChangedEventHandler(OnValueChanged), new object[] { view, att.Index, value, dirty });
                        }
                        else
                        {
                            view.OnValueChanged(att.Index, value);
                        }
                    }
                }
                else if (it.PropertyType.IsClass)
                {
                    if (it.PropertyType == typeof(string))
                    {
                        continue;
                    }
                    //If component is not already searched.
                    if (!UpdatedObjects.Contains(obj))
                    {
                        UpdatedObjects.Add(obj);
                        UpdateProperties(it.GetValue(obj), view, UpdatedObjects, index);
                    }
                }
            }
             * * */
        }