Example #1
0
        /// <summary>
        /// Get available views.
        /// </summary>
        /// <param name="parent">Parent component where views are shown.</param>
        /// <param name="eventHandler">Event what is called when user press button on the view.</param>
        /// <returns>List of available views.</returns>
        public static Dictionary <Type, List <IGXDLMSView> > GetViews(Control parent, EventHandler eventHandler)
        {
            Dictionary <Type, List <IGXDLMSView> > views = new Dictionary <Type, List <IGXDLMSView> >();

            foreach (Type type in typeof(IGXDLMSView).Assembly.GetTypes())
            {
                GXDLMSViewAttribute[] att = (GXDLMSViewAttribute[])type.GetCustomAttributes(typeof(GXDLMSViewAttribute), true);
                if (!type.IsInterface && typeof(IGXDLMSView).IsAssignableFrom(type))
                {
                    IGXDLMSView view = Activator.CreateInstance(type) as IGXDLMSView;
                    Form        f    = view as Form;
                    f.TopLevel        = false;
                    f.TopMost         = false;
                    f.FormBorderStyle = FormBorderStyle.None;
                    f.Dock            = DockStyle.Fill;
                    f.Width           = parent.Width;
                    f.Height          = parent.Height;
                    List <IGXDLMSView> list;
                    if (views.ContainsKey(att[0].DLMSType))
                    {
                        list = views[att[0].DLMSType];
                    }
                    else
                    {
                        list = new List <IGXDLMSView>();
                        views.Add(att[0].DLMSType, list);
                    }
                    list.Add(view);
                    GXDlmsUi.Init(view, eventHandler);
                }
            }
            return(views);
        }
Example #2
0
 /// <summary>
 /// Load macro from the file.
 /// </summary>
 /// <param name="import">Is macro imported(append).</param>
 private void LoadFile(bool import, string path)
 {
     dirty        = import;
     SelectedView = null;
     //SelectedView must remove from the controls.
     ObjectPanelFrame.Controls.Clear();
     if (!import)
     {
         MacrosView.VirtualListSize = 0;
         Macros2.Clear();
         Filtered.Clear();
         mruManager.Insert(0, path);
         this.path = path;
     }
     UpdateTitle();
     using (XmlReader reader = XmlReader.Create(path))
     {
         XmlSerializer x = new XmlSerializer(typeof(GXMacro[]));
         Macros2.AddRange((GXMacro[])x.Deserialize(reader));
         UpdateFilteredMacros();
         reader.Close();
         MacrosView.VirtualListSize = GetMacros().Count;
     }
     if (!import && GetMacros().Count != 0)
     {
         MacrosView.SelectedIndices.Clear();
         MacrosView.SelectedIndices.Add(0);
     }
 }
Example #3
0
        /// <summary>
        /// Update attribute value for the view.
        /// </summary>
        /// <param name="view">Updated view.</param>
        /// <param name="controls">Update controls.</param>
        /// <param name="index">Attribute index.</param>
        /// <param name="value">Updated value.</param>
        /// <returns></returns>
        private static bool UpdateProperty(IGXDLMSView view, ControlCollection controls, int index, object value)
        {
            bool found = false;

            foreach (Control it in controls)
            {
                if (it is GXValueField)
                {
                    GXValueField obj = it as GXValueField;
                    if (obj.Index == index)
                    {
                        obj.Target = view.Target;
                        obj.UpdateValueItems(view.Target, index, value);
                        obj.Value = value;
                        found     = true;
                    }
                }
                else if (it is GXButton)
                {
                    GXButton obj = it as GXButton;
                    obj.Enabled = false;
                }
                else if (it.Controls.Count != 0)
                {
                    found = UpdateProperty(view, it.Controls, index, value);
                }
                if (found)
                {
                    break;
                }
            }
            return(found);
        }
Example #4
0
        public static bool UpdateDirty(IGXDLMSView view, System.Windows.Forms.Control.ControlCollection controls, GXDLMSObject target, int index, bool dirty)
        {
            bool found = false;

            foreach (Control it in controls)
            {
                if (it is GXValueField)
                {
                    GXValueField obj = it as GXValueField;
                    if (obj.Index == index)
                    {
                        if (dirty && index != 0)
                        {
                            view.ErrorProvider.SetError(it, Properties.Resources.ValueChangedTxt);
                        }
                        else
                        {
                            view.ErrorProvider.Clear();
                        }
                        found = true;
                    }
                }
                else if (it.Controls.Count != 0)
                {
                    found = UpdateDirty(view, it.Controls, target, index, dirty);
                }
                if (found)
                {
                    break;
                }
            }
            return(found);
        }
        /// <summary>
        /// Update attribute value for the view.
        /// </summary>
        /// <param name="view">Updated view.</param>
        /// <param name="controls">Update controls.</param>
        /// <param name="index">Attribute index.</param>
        /// <param name="value">Updated value.</param>
        /// <returns></returns>
        private static GXValueField UpdateProperty(IGXDLMSView view, ControlCollection controls, int index, object value)
        {
            GXValueField item = null;

            foreach (Control it in controls)
            {
                if (it is GXValueField)
                {
                    GXValueField obj = it as GXValueField;
                    if (obj.Index == index)
                    {
                        obj.Target = view.Target;
                        obj.UpdateValueItems(view.Target, index, value);
                        obj.Value = value;
                        item      = obj;
                    }
                }
                else if (it is GXButton)
                {
                    //Do nothing.
                }
                else if (it.Controls.Count != 0)
                {
                    item = UpdateProperty(view, it.Controls, index, value);
                }
                if (item != null)
                {
                    break;
                }
            }
            return(item);
        }
Example #6
0
        private static bool UpdateError(IGXDLMSView view, System.Windows.Forms.Control.ControlCollection controls,
                                        GXDLMSObject target, int index, Exception ex)
        {
            bool found = false;

            foreach (Control it in controls)
            {
                if (it is GXValueField)
                {
                    GXValueField obj = it as GXValueField;
                    if (obj.Index == index)
                    {
                        if (ex == null)
                        {
                            view.ErrorProvider.SetError(it, null);
                        }
                        else
                        {
                            view.ErrorProvider.SetError(it, ex.Message);
                        }
                        found = true;
                        break;
                    }
                }
                else if (it.Controls.Count != 0)
                {
                    found = UpdateError(view, it.Controls, target, index, ex);
                }
                if (found)
                {
                    break;
                }
            }
            return(found);
        }
Example #7
0
        /// <summary>
        /// Called when new object is selected. This will update the access rights.
        /// </summary>
        /// <param name="view"></param>
        /// <param name="target"></param>
        /// <param name="connected"></param>
        public static void UpdateAccessRights(IGXDLMSView view, GXDLMSClient client, GXDLMSObject target, bool connected)
        {
            //Update attributes.
            List <int>        attributeIndexes = new List <int>();
            List <int>        methodIndexes    = new List <int>();
            ControlCollection controls         = (view as Form).Controls;

            for (int index = 1; index <= (target as IGXDLMSBase).GetAttributeCount(); ++index)
            {
                if (!UpdateAccessRights(view, client, controls, target, index, false, connected))
                {
                    attributeIndexes.Add(index);
                }
            }
            //Update methods.
            for (int index = 0; index <= (target as IGXDLMSBase).GetMethodCount(); ++index)
            {
                if (!UpdateAccessRights(view, client, controls, target, index, true, connected))
                {
                    if (index != 0)
                    {
                        methodIndexes.Add(index);
                    }
                }
            }
            foreach (int index in attributeIndexes)
            {
                OnAccessRightsChange(view, client, target, index, connected, false);
            }
            //Update methods.
            foreach (int index in methodIndexes)
            {
                OnAccessRightsChange(view, client, target, index, connected, true);
            }
        }
Example #8
0
 private void GXMacroView_FormClosing(object sender, FormClosingEventArgs e)
 {
     if (!SaveChanges())
     {
         e.Cancel = true;
     }
     else if (Record)
     {
         e.Cancel = true;
         MessageBox.Show(this, "Recording is on progress.", GXDLMSDirector.Properties.Resources.GXDLMSDirectorTxt, MessageBoxButtons.OK);
     }
     else if (running)
     {
         e.Cancel = true;
         MessageBox.Show(this, "Macro is running.", GXDLMSDirector.Properties.Resources.GXDLMSDirectorTxt, MessageBoxButtons.OK);
     }
     else
     {
         SelectedView = null;
         //SelectedView must remove from the controls.
         ObjectPanelFrame.Controls.Clear();
         Properties.Settings.Default.MacroFiles = string.Join(";", mruManager.GetNames());
         this.dirty = false;
         clearToolStripMenuItem_Click(null, null);
         if (e.CloseReason == CloseReason.UserClosing)
         {
             e.Cancel = true;
             Hide();
         }
         else
         {
         }
     }
 }
Example #9
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 #10
0
        /// <summary>
        /// Called when new object is selected. This will update the access rights.
        /// </summary>
        /// <param name="view"></param>
        /// <param name="target"></param>
        /// <param name="connected"></param>
        public static void ObjectChanged(IGXDLMSView view, GXDLMSClient client, GXDLMSObject target, bool connected)
        {
            UpdateAccessRights(view, client, target, connected);

            for (int index = 1; index <= (target as IGXDLMSBase).GetAttributeCount(); ++index)
            {
                UpdateProperty(client, target, index, view, connected, true);
            }
        }
 private static bool UpdateAccessRights(IGXDLMSView view, System.Windows.Forms.Control.ControlCollection controls, GXDLMSObject target, int index, bool method, bool connected)
 {
     foreach (Control it in controls)
     {
         if (!method && it is GXValueField)
         {
             GXValueField obj = it as GXValueField;
             if (obj.Index == index)
             {
                 obj.Target = target;
                 AccessMode am = target.GetAccess(index);
                 OnUpdateAccessRights(view, obj, connected && ((am & AccessMode.Write) != 0));
                 return(!obj.NotifyChanges);
             }
         }
         else if (it is GXButton)
         {
             GXButton btn = it as GXButton;
             btn.Target = target;
             //Update custom buttons.
             if (method && index == 0 && btn.Index < 1)
             {
                 OnUpdateAccessRights(view, btn, connected);
                 continue;
             }
             if (method && btn.Index == index && btn.Action == ActionType.Action)
             {
                 MethodAccessMode ma = target.GetMethodAccess(index);
                 OnUpdateAccessRights(view, btn, connected && ma != MethodAccessMode.NoAccess);
                 return(true);
             }
             if (!method && btn.Index == index && (btn.Action == ActionType.Read || btn.Action == ActionType.Write))
             {
                 AccessMode am = target.GetAccess(index);
                 if (btn.Action == ActionType.Read)
                 {
                     OnUpdateAccessRights(view, btn, connected && ((am & AccessMode.Read) != 0));
                 }
                 else if (btn.Action == ActionType.Write)
                 {
                     OnUpdateAccessRights(view, btn, connected && ((am & AccessMode.Write) != 0));
                 }
             }
         }
         else if (it.Controls.Count != 0)
         {
             bool ret = UpdateAccessRights(view, it.Controls, target, index, method, connected);
             //If object is updated.
             if (ret)
             {
                 return(true);
             }
         }
     }
     return(false);
 }
        /// <summary>
        /// Update selected values of given COSEM object.
        /// </summary>
        /// <param name="obj"></param>
        /// <param name="view"></param>
        public static void UpdateProperty(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), 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)
                    {
                        view.OnValueChanged(it, value, user, connected);
                    }
                    if (it == index)
                    {
                        break;
                    }
                }
            }
        }
Example #13
0
 /// <summary>
 /// User has selected new OBIS code.
 /// </summary>
 private void ObjectList_ItemSelectionChanged(object sender, ListViewItemSelectionChangedEventArgs e)
 {
     try
     {
         GXDLMSObject obj          = (GXDLMSObject)e.Item.Tag;
         IGXDLMSView  SelectedView = GXDlmsUi.GetView(Views, obj);
         SelectedView.Target = obj;
         GXDlmsUi.ObjectChanged(SelectedView, null, obj, false);
         ObjectPanelFrame.Controls.Add(((Form)SelectedView));
         ((Form)SelectedView).Show();
     }
     catch (Exception Ex)
     {
         GXDLMS.Common.Error.ShowError(this, Ex);
     }
 }
Example #14
0
 /// <summary>
 /// Clear actions.
 /// </summary>
 private void clearToolStripMenuItem_Click(object sender, EventArgs e)
 {
     if (SaveChanges())
     {
         path  = null;
         dirty = false;
         UpdateTitle();
         SelectedView = null;
         //SelectedView must remove from the controls.
         ObjectPanelFrame.Controls.Clear();
         MacrosView.VirtualListSize = 0;
         Macros2.Clear();
         Filtered.Clear();
         MacrosView.SelectedIndices.Clear();
         ActionsList_SelectedIndexChanged(null, null);
     }
 }
Example #15
0
 private static void OnUpdateAccessRights(IGXDLMSView view, GXDLMSClient client, object target, bool enabled)
 {
     if ((view as Form).InvokeRequired)
     {
         (view as Form).BeginInvoke(new UpdateAccessRightsEventHandler(OnUpdateAccessRights), view, client, target, enabled);
     }
     else
     {
         if (target is GXValueField)
         {
             (target as GXValueField).ReadOnly = !enabled;
         }
         else
         {
             (target as GXButton).Enabled = enabled;
         }
     }
 }
 private static void OnAccessRightsChange(IGXDLMSView view, GXDLMSObject target, int index, int mode, bool connected, bool method)
 {
     if ((view as Form).InvokeRequired)
     {
         (view as Form).BeginInvoke(new AccessRightsChangeEventHandler(OnAccessRightsChange), view, target, index, mode, connected, method);
     }
     else
     {
         if (method)
         {
             view.OnAccessRightsChange(index, (MethodAccessMode)mode, connected);
         }
         else
         {
             view.OnAccessRightsChange(index, (AccessMode)mode, connected);
         }
     }
 }
Example #17
0
 private static void Init(IGXDLMSView view, System.Windows.Forms.Control.ControlCollection controls, EventHandler eventHandler)
 {
     foreach (Control it in controls)
     {
         if (it is GXButton)
         {
             GXButton btn = it as GXButton;
             btn.View   = view;
             btn.Click += eventHandler;
         }
         else if (it is GXValueField)
         {
             GXValueField vf = it as GXValueField;
             vf.DefaultType = vf.Type;
         }
         else if (it.Controls.Count != 0)
         {
             Init(view, it.Controls, eventHandler);
         }
     }
 }
Example #18
0
        /// <summary>
        /// Update attribute value for the view.
        /// </summary>
        /// <param name="view">Updated view.</param>
        /// <param name="controls">Update controls.</param>
        /// <param name="index">Attribute index.</param>
        /// <param name="value">Updated value.</param>
        /// <returns></returns>
        private static GXValueField UpdateProperty(IGXDLMSView view, ControlCollection controls, int index, object value)
        {
            GXValueField item = null;

            foreach (Control it in controls)
            {
                if (it is GXValueField)
                {
                    GXValueField obj = it as GXValueField;
                    if (obj.Index == index)
                    {
                        obj.Target = view.Target;
                        obj.UpdateValueItems(view.Target, index, value);
                        if (obj.Index != 1 && view.Target.GetLastReadTime(index) == DateTime.MinValue &&
                            obj.Type != ValueFieldType.CheckedListBox)
                        {
                            obj.Value = null;
                        }
                        else
                        {
                            obj.Value = value;
                        }
                        item = obj;
                    }
                }
                else if (it is GXButton)
                {
                    //Do nothing.
                }
                else if (it.Controls.Count != 0)
                {
                    item = UpdateProperty(view, it.Controls, index, value);
                }
                if (item != null)
                {
                    break;
                }
            }
            return(item);
        }
Example #19
0
 private static void OnAccessRightsChange(IGXDLMSView view, GXDLMSClient client, GXDLMSObject target, int index, bool connected, bool method)
 {
     if ((view as Form).InvokeRequired)
     {
         (view as Form).BeginInvoke(new AccessRightsChangeEventHandler(OnAccessRightsChange), view, client, target, index, connected, method);
     }
     else
     {
         GXDLMSViewArguments arg = new GXDLMSViewArguments()
         {
             Client = client, Index = index, Connected = connected
         };
         if (method)
         {
             view.OnMethodAccessRightsChange(arg);
         }
         else
         {
             view.OnAccessRightsChange(arg);
         }
     }
 }
Example #20
0
 /// <summary>
 /// Show action data.
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void ActionsList_SelectedIndexChanged(object sender, EventArgs e)
 {
     if (MacrosView.SelectedIndices.Count == 1)
     {
         GXMacro macro = GetMacros()[MacrosView.SelectedIndices[0]];
         if (macro.Type == UserActionType.Get || macro.Type == UserActionType.Set)
         {
             if (!tabControl1.TabPages.Contains(VisualizedTab))
             {
                 tabControl1.TabPages.Insert(0, VisualizedTab);
             }
         }
         else
         {
             if (tabControl1.TabPages.Contains(VisualizedTab))
             {
                 tabControl1.TabPages.Remove(VisualizedTab);
             }
         }
         string actual, expected;
         if (Properties.Settings.Default.MacroRaw)
         {
             expected = macro.Data;
         }
         else
         {
             expected = macro.Value;
         }
         OriginalDataTb.Text = expected;
         if (Results.ContainsKey(macro))
         {
             if (Properties.Settings.Default.MacroRaw)
             {
                 actual   = Results[macro].Data;
                 expected = macro.Data;
             }
             else
             {
                 actual   = Results[macro].Value;
                 expected = macro.Value;
             }
             if (actual != expected)
             {
                 ReplyDataTb.Text    = actual;
                 ActualPanel.Visible = true;
             }
             else
             {
                 ActualPanel.Visible = false;
             }
         }
         else
         {
             ActualPanel.Visible = false;
             ReplyDataTb.Text    = null;
         }
         try
         {
             if (macro.Type == UserActionType.Get || macro.Type == UserActionType.Set)
             {
                 if (macro.ObjectType != 0)
                 {
                     GXDLMSObject obj = GXDLMSClient.CreateObject((ObjectType)macro.ObjectType);
                     if (obj != null)
                     {
                         obj.LogicalName = macro.LogicalName;
                         for (int pos = 1; pos != (obj as IGXDLMSBase).GetAttributeCount() + 1; ++pos)
                         {
                             obj.SetAccess(pos, AccessMode.NoAccess);
                         }
                         obj.SetAccess(macro.Index, AccessMode.ReadWrite);
                         obj.SetDataType(macro.Index, (DataType)macro.DataType);
                         obj.SetUIDataType(macro.Index, (DataType)macro.UIDataType);
                         if (!string.IsNullOrEmpty(macro.Data) && Target != null)
                         {
                             object value = GXDLMSTranslator.XmlToValue(macro.Data);
                             if (value is byte[] && macro.UIDataType != 0)
                             {
                                 value = Target.Comm.client.ChangeType(new GXByteBuffer((byte[])value), (DataType)macro.UIDataType);
                             }
                             else if (value is byte[] &&
                                      macro.DataType != (int)DataType.None &&
                                      macro.DataType != (int)DataType.OctetString)
                             {
                                 if (macro.DataType == (int)DataType.Array ||
                                     macro.DataType == (int)DataType.Structure)
                                 {
                                     GXByteBuffer bb = new GXByteBuffer((byte[])value);
                                     //Skip data type.
                                     bb.Position = 1;
                                     value       = Target.Comm.client.ChangeType(bb, (DataType)macro.DataType);
                                 }
                                 else
                                 {
                                     GXByteBuffer bb = new GXByteBuffer((byte[])value);
                                     value = Target.Comm.client.ChangeType(bb, (DataType)macro.DataType);
                                 }
                             }
                             if (macro.ObjectType == (int)ObjectType.ProfileGeneric && macro.Index == 2 && !string.IsNullOrEmpty(macro.External))
                             {
                                 Target.Comm.client.UpdateValue(obj, 3, GXDLMSTranslator.XmlToValue(macro.External));
                             }
                             Target.Comm.client.UpdateValue(obj, macro.Index, value);
                         }
                         if (SelectedView == null || SelectedView.Target.ObjectType != obj.ObjectType)
                         {
                             //SelectedView must remove from the controls.
                             ObjectPanelFrame.Controls.Clear();
                             if (Target == null)
                             {
                                 SelectedView = GXDlmsUi.GetView(Views, obj, Standard.DLMS);
                             }
                             else
                             {
                                 SelectedView = GXDlmsUi.GetView(Views, obj, Target.Comm.client.Standard);
                             }
                             SelectedView.Target = obj;
                             GXDlmsUi.ObjectChanged(SelectedView, obj, false);
                             SelectedView.OnDirtyChange(macro.Index, true);
                             ObjectPanelFrame.Controls.Add(((Form)SelectedView));
                             ((Form)SelectedView).Show();
                         }
                         else
                         {
                             SelectedView.Target = obj;
                             GXDlmsUi.ObjectChanged(SelectedView, obj, false);
                             SelectedView.OnDirtyChange(macro.Index, true);
                         }
                     }
                 }
             }
         }
         catch (Exception Ex)
         {
             GXDLMS.Common.Error.ShowError(this, Ex);
         }
     }
     else
     {
         OriginalDataTb.Text = "";
         if (GetMacros().Count == 0 && tabControl1.TabPages.Contains(VisualizedTab))
         {
             tabControl1.TabPages.Remove(VisualizedTab);
         }
     }
 }
Example #21
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);
                    }
                }
            }
             * * */
        }
Example #22
0
 /// <summary>
 ///Update error.
 /// </summary>
 /// <param name="view"></param>
 /// <param name="target"></param>
 /// <param name="connected"></param>
 public static void UpdateError(IGXDLMSView view, GXDLMSObject target, int index, Exception ex)
 {
     UpdateError(view, (view as Form).Controls, target, index, ex);
 }
Example #23
0
 static void OnValueChanged(IGXDLMSView view, int attributeID, object value, bool changeByUser)
 {
     view.OnValueChanged(attributeID, value);
 }
Example #24
0
 public static void Init(IGXDLMSView view, EventHandler eventHandler)
 {
     Init(view, (view as Form).Controls, eventHandler);
 }
Example #25
0
 /// <summary>
 /// Update attribute value for the view.
 /// </summary>
 /// <param name="view">Updated view.</param>
 /// <param name="index">Attribute index.</param>
 /// <param name="value">Updated value.</param>
 /// <returns></returns>
 public static void UpdateProperty(IGXDLMSView view, int index, object value)
 {
     UpdateProperty(view, ((Form)view).Controls, index, value);
 }
Example #26
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 #27
0
 private static bool UpdateAccessRights(IGXDLMSView view, GXDLMSClient client, System.Windows.Forms.Control.ControlCollection controls, GXDLMSObject target, int index, bool method, bool connected)
 {
     foreach (Control it in controls)
     {
         if (!method && it is GXValueField)
         {
             GXValueField obj = it as GXValueField;
             if (obj.Index == index)
             {
                 obj.Target = target;
                 bool access = connected;
                 if (connected)
                 {
                     if (client != null)
                     {
                         access = client.CanWrite(target, index);
                     }
                     else
                     {
                         AccessMode am = target.GetAccess(index);
                         access = (am & AccessMode.Write) != 0;
                     }
                 }
                 OnUpdateAccessRights(view, client, obj, connected && access);
                 return(!obj.NotifyChanges);
             }
         }
         else if (it is GXButton)
         {
             bool     access;
             GXButton btn = it as GXButton;
             btn.Target = target;
             //Update custom buttons.
             if (method && index == 0 && btn.Index < 1)
             {
                 OnUpdateAccessRights(view, client, btn, connected);
                 continue;
             }
             if (method && btn.Index == index && btn.Action == ActionType.Action)
             {
                 if (client != null)
                 {
                     access = client.CanInvoke(target, index);
                 }
                 else
                 {
                     access = target.GetMethodAccess(index) != MethodAccessMode.NoAccess;
                     if (!access)
                     {
                         access = target.GetMethodAccess3(index) != MethodAccessMode3.NoAccess;
                     }
                 }
                 OnUpdateAccessRights(view, client, btn, connected && access);
                 return(true);
             }
             if (!method && btn.Index == index && (btn.Action == ActionType.Read || btn.Action == ActionType.Write))
             {
                 if (btn.Action == ActionType.Read)
                 {
                     if (client != null)
                     {
                         access = client.CanRead(target, index);
                     }
                     else
                     {
                         access = (target.GetAccess(index) & AccessMode.Read) != 0;
                         if (!access)
                         {
                             access = (target.GetAccess3(index) & AccessMode3.Read) != 0;
                         }
                     }
                     OnUpdateAccessRights(view, client, btn, connected && access);
                 }
                 else if (btn.Action == ActionType.Write)
                 {
                     if (client != null)
                     {
                         access = client.CanWrite(target, index);
                     }
                     else
                     {
                         access = (target.GetAccess(index) & AccessMode.Write) != 0;
                         if (!access)
                         {
                             access = (target.GetAccess3(index) & AccessMode3.Write) != 0;
                         }
                     }
                     OnUpdateAccessRights(view, client, btn, connected && access);
                 }
             }
         }
         else if (it.Controls.Count != 0)
         {
             bool ret = UpdateAccessRights(view, client, it.Controls, target, index, method, connected);
             //If object is updated.
             if (ret)
             {
                 return(true);
             }
         }
     }
     return(false);
 }
Example #28
0
 static void OnValueChanged(IGXDLMSView view, int index, object value, bool changeByUser)
 {
     view.OnValueChanged(index, value, changeByUser);
 }
Example #29
0
 private static bool UpdateDirty(IGXDLMSView view, System.Windows.Forms.Control.ControlCollection controls, GXDLMSObject target, int index, bool dirty)
 {
     bool found = false;
     foreach (Control it in controls)
     {
         if (it is GXValueField)
         {
             GXValueField obj = it as GXValueField;
             if (obj.Index == index)
             {
                 if (dirty && index != 0)
                 {
                     view.ErrorProvider.SetError(it, GXDLMSDirector.Properties.Resources.ValueChangedTxt);
                 }
                 else
                 {
                     view.ErrorProvider.Clear();
                 }
                 found = true;
             }
         }
         else if (it.Controls.Count != 0)
         {
             found = UpdateDirty(view, it.Controls, target, index, dirty);
         }
         if (found)
         {
             break;
         }
     }
     return found;
 }
Example #30
0
        private void SelectItem(object obj)
        {
            try
            {
                if (SelectedView != null && SelectedView.Target != null)
                {
                    SelectedView.Target.OnChange -= new ObjectChangeEventHandler(DLMSItemOnChange);
                }
                //Do not shown list if there is only one item in the list.
                if (obj is GXDLMSObjectCollection)
                {
                    GXDLMSObjectCollection items = obj as GXDLMSObjectCollection;
                    if (items.Count == 1)
                    {
                        obj = items[0];
                    }
                }

                DeviceList.Visible = obj is GXDLMSDeviceCollection;
                //If device is selected.
                DeviceInfoView.Visible = obj is GXDLMSDevice;
                ObjectPanelFrame.Visible = obj is GXDLMSObject;
                ObjectValueView.Visible = obj is GXDLMSObjectCollection;
                if (DeviceList.Visible)
                {
                    DeviceState state = Devices.Count == 0 ? DeviceState.None : DeviceState.Initialized;
                    UpdateDeviceUI(null, state);
                    DeleteMnu.Enabled = DeleteBtn.Enabled = OptionsBtn.Enabled = false;
                }
                else if (DeviceInfoView.Visible)
                {
                    GXDLMSDevice dev = (GXDLMSDevice)obj;
                    DeviceGb.Text = dev.Name;
                    StatusValueLbl.Text = dev.Status.ToString();
                    ClientAddressValueLbl.Text = dev.ClientAddress.ToString();
                    LogicalAddressValueLbl.Text = dev.LogicalAddress.ToString();
                    PhysicalAddressValueLbl.Text = dev.PhysicalAddress.ToString();
                    ManufacturerValueLbl.Text = dev.Manufacturers.FindByIdentification(dev.Manufacturer).Name;
                    UpdateDeviceUI(dev, dev.Status);
                }
                else if (ObjectValueView.Visible)
                {
                    try
                    {
                        ObjectValueView.BeginUpdate();
                        ObjectValueItems.Clear();
                        ObjectValueView.Items.Clear();
                        int maxAttributeCount = ObjectValueView.Columns.Count - 2;
                        int originalCount = maxAttributeCount;
                        int maxColCount = 0;
                        int len = 0;
                        GXDLMSObjectCollection items = obj as GXDLMSObjectCollection;
                        List<ListViewItem> rows = new List<ListViewItem>(items.Count);
                        foreach (GXDLMSObject it in items)
                        {
                            object[] values = it.GetValues();
                            len = values.Length - 1;
                            if (len > maxColCount)
                            {
                                maxColCount = len;
                            }
                            if (len > maxAttributeCount)
                            {
                                for (int pos = maxAttributeCount; pos != len; ++pos)
                                {
                                    ObjectValueView.Columns.Add("Attribute " + (pos + 2).ToString());
                                    ++maxAttributeCount;
                                }
                            }
                            ListViewItem lv = new ListViewItem(it.LogicalName + " " + it.Description);
                            lv.SubItems.Add(it.ObjectType.ToString());
                            string[] texts = new string[len];
                            for (int pos = 0; pos != len; ++pos)
                            {
                                texts[pos] = "";
                            }
                            lv.SubItems.AddRange(texts);
                            ObjectValueItems[it] = lv;
                            lv.Tag = it;
                            for (int pos = 0; pos != len; ++pos)
                            {
                                UpdateValue(it, pos + 2, lv);
                            }
                            rows.Add(lv);
                        }
                        ObjectValueView.Items.AddRange(rows.ToArray());
                        int cnt = ObjectValueView.Columns.Count - maxColCount - 2;
                        for (int pos = 0; pos < cnt; ++pos)
                        {
                            ObjectValueView.Columns.RemoveAt(ObjectValueView.Columns.Count - 1);
                        }
                        for (int pos = originalCount + 1; pos < ObjectValueView.Columns.Count; ++pos)
                        {
                            ObjectValueView.Columns[pos].AutoResize(ColumnHeaderAutoResizeStyle.HeaderSize);
                        }
                        if (items.Count != 0)
                        {
                            GXDLMSObject obj2 = items[0] as GXDLMSObject;
                            GXDLMSDevice dev = obj2.Parent.Tag as GXDLMSDevice;
                            UpdateDeviceUI(dev, dev.Status);
                        }
                    }
                    finally
                    {
                        ObjectValueView.EndUpdate();
                    }
                }
                else
                {
                    SelectedView = Views[obj.GetType()];
                    foreach (Control it in ObjectPanelFrame.Controls)
                    {
                        it.Hide();
                    }
                    ObjectPanelFrame.Controls.Clear();
                    SelectedView.Target = (GXDLMSObject)obj;
                    SelectedView.Target.OnChange += new ObjectChangeEventHandler(DLMSItemOnChange);
                    UpdateProperties(obj, SelectedView, new List<object>(), 0);
                    ObjectPanelFrame.Controls.Add((Form)SelectedView);
                    ((Form)SelectedView).Show();
                    UpdateDeviceUI(GetDevice(SelectedView.Target), GetDevice((GXDLMSObject)obj).Status);
                }
            }
            catch (Exception Ex)
            {
                GXDLMS.Common.Error.ShowError(this, Ex);
            }
        }
Example #31
0
 private static bool UpdateProperties(IGXDLMSView view, System.Windows.Forms.Control.ControlCollection controls, GXDLMSObject target, int index, object value)
 {
     foreach (GXButton it in ActionList)
     {
         it.Click -= new EventHandler(OnAction);
     }
     ActionList.Clear();
     bool found = false;
     foreach (Control it in controls)
     {
         if (it is GXValueField)
         {
             GXValueField obj = it as GXValueField;
             if (obj.Index == index)
             {
                 obj.Target = target;
                 obj.UpdateValueItems(target, index, value);
                 obj.Value = value;
                 found = true;
             }
         }
         else if (it is GXButton)
         {
             GXButton obj = it as GXButton;
             bool enabled = target.GetMethodAccess(obj.Index) != MethodAccessMode.NoAccess;
             obj.Enabled = enabled;
             if (enabled)
             {
                 obj.Target = target;
                 it.Click += new EventHandler(OnAction);
                 ActionList.Add(obj);
             }
         }
         else if (it.Controls.Count != 0)
         {
             found = UpdateProperties(view, it.Controls, target, index, value);
         }
         if (found)
         {
             break;
         }
     }
     return found;
 }