/// <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, 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, controls, target, index, false, connected))
                {
                    attributeIndexes.Add(index);
                }
            }
            //Update methods.
            for (int index = 0; index <= (target as IGXDLMSBase).GetMethodCount(); ++index)
            {
                if (!UpdateAccessRights(view, controls, target, index, true, connected))
                {
                    if (index != 0)
                    {
                        methodIndexes.Add(index);
                    }
                }
            }
            foreach (int index in attributeIndexes)
            {
                OnAccessRightsChange(view, target, index, (int)target.GetAccess(index), connected, false);
            }
            //Update methods.
            foreach (int index in methodIndexes)
            {
                OnAccessRightsChange(view, target, index, (int)target.GetMethodAccess(index), 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);
 }
 public void OnAccessRightsChange(int index, AccessMode access, bool connected)
 {
     if (index == 2)
     {
     }
     else if (index == 3)
     {
         ClientSAPTb.ReadOnly = ServerSAPTb.ReadOnly = (access & AccessMode.Write) == 0;
     }
     else if (index == 4)
     {
         // Application context name.
         ApplicationJointISOCTTTb.ReadOnly           = ApplicationCountryTb.ReadOnly =
             ApplicationCountryNameTb.ReadOnly       = ApplicationIdentifiedOrganizationTb.ReadOnly =
                 ApplicationDLMSUATb.ReadOnly        = ApplicationContextTb.ReadOnly =
                     ApplicationContextIDTb.ReadOnly = (access & AccessMode.Write) == 0;
     }
     else if (index == 5)
     {
         // xDLMS_context_info
         ConformanceTB.ReadOnly           = MaxReceivePDUSizeTb.ReadOnly = MaxSendPDUSizeTb.ReadOnly =
             DLMSVersionNumberTB.ReadOnly = CypheringInfoTb.ReadOnly = (access & AccessMode.Write) == 0;
     }
     else if (index == 6)
     {
         // authentication_mechanism_name
         AuthenticationJointISOCTTTb.ReadOnly = AuthenticationCountryTb.ReadOnly = AuthenticationCountryNameTb.ReadOnly =
             AuthenticationIdentifiedorganizationTb.ReadOnly = AuthenticationDLMSUATb.ReadOnly =
                 AuthenticationMechanismNameTb.ReadOnly      = AuthenticationMechanismIdTb.ReadOnly = (access & AccessMode.Write) == 0;
     }
     else if (index == 7)
     {
         GXDLMSAssociationLogicalName target = Target as GXDLMSAssociationLogicalName;
         bool enabled = false;
         if (target.AuthenticationMechanismName.MechanismId == Authentication.Low)
         {
             enabled        = (access & AccessMode.Write) != 0;
             SecretLbl.Text = "Low Secret:";
         }
         else if (target.AuthenticationMechanismName.MechanismId == Authentication.High)
         {
             enabled        = Target.GetMethodAccess(2) == MethodAccessMode.Access;
             SecretLbl.Text = "High Secret:";
         }
         else
         {
             SecretLbl.Text = "Secret:";
         }
         UpdatePwBtn.Enabled = enabled;
         SecretTB.ReadOnly   = !enabled;
     }
     else if (index == 9)
     {
         SecuritySetupCb.Enabled = (access & AccessMode.Write) != 0;
     }
 }
Esempio n. 4
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);
 }
        private void UpdateAttributes()
        {
            bindingSource1.Clear();
            List <GXDLMSAttributeSettings> list = new List <GXDLMSAttributeSettings>();

            string[] names = (Target as IGXDLMSBase).GetNames();
            for (int pos = 0; pos != (Target as IGXDLMSBase).GetAttributeCount(); ++pos)
            {
                GXDLMSAttributeSettings a = new GXDLMSAttributeSettings()
                {
                    Index = pos + 1, Name = names[pos]
                };
                Target.Attributes.Add(a);
                //Logical name is always read-only.
                if (pos == 0)
                {
                    if (version < 3)
                    {
                        a.Access = AccessMode.Read;
                    }
                    else
                    {
                        a.Access3 = AccessMode3.Read;
                    }
                }
                else
                {
                    if (version < 3)
                    {
                        AccessMode mode = Target.GetAccess(1 + pos);
                        a.Access = mode;
                    }
                    else
                    {
                        AccessMode3 mode = Target.GetAccess3(1 + pos);
                        a.Access3 = mode;
                    }
                }
                list.Add(a);
            }
            foreach (var it in list)
            {
                bindingSource1.Add(it);
            }
            Accessrights.DataSource = bindingSource1;
            //Show method access levels of COSEM object.
            bindingSource3.Clear();
            list.Clear();
            //Add all methods.
            names = (Target as IGXDLMSBase).GetMethodNames();
            for (int pos = 0; pos != (Target as IGXDLMSBase).GetMethodCount(); ++pos)
            {
                GXDLMSAttributeSettings a = new GXDLMSAttributeSettings()
                {
                    Index = pos + 1, Name = names[pos]
                };
                Target.MethodAttributes.Add(a);
                if (version < 3)
                {
                    MethodAccessMode mode = Target.GetMethodAccess(1 + pos);
                    a.MethodAccess = mode;
                }
                else
                {
                    MethodAccessMode3 mode = Target.GetMethodAccess3(1 + pos);
                    a.MethodAccess3 = mode;
                }
                list.Add(a);
            }
            foreach (var it in list)
            {
                bindingSource3.Add(it);
            }
            MethodAccessrights.DataSource = bindingSource3;
        }