public void PreAction(GXActionArgs arg)
 {
 }
 public void PostAction(GXActionArgs arg)
 {
     arg.Action = ActionType.None;
 }
        public void PostAction(GXActionArgs arg)
        {
            GXDLMSImageTransfer it     = Target as GXDLMSImageTransfer;
            GXImageUpdateStatus status = (GXImageUpdateStatus)arg.Tag;

            if (arg.Action == ActionType.Read)
            {
                if (arg.Index == 5)
                {
                    if (!it.ImageTransferEnabled)
                    {
                        GXHelpers.ShowMessageBox(this, Properties.Resources.ImageTransferDisabled, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        arg.Action = ActionType.None;
                        return;
                    }
                    OnDescription(Properties.Resources.ImageTransferEnabled);
                    //Get ImageBlockSize.
                    arg.Index = 2;
                }
                else if (arg.Index == 2)
                {
                    OnDescription(Properties.Resources.ImageBlockSize + it.ImageBlockSize);
                    //Read image_transferred_blocks_status.
                    arg.Index = 3;
                }
                else if (arg.Index == 3)
                {
                    int index = 0;
                    foreach (char b in it.ImageTransferredBlocksStatus)
                    {
                        if (b == '0')
                        {
                            DialogResult ret = GXHelpers.ShowMessageBox(this, index + " Image blocks already exists. Do you want to overwrite image? " + Environment.NewLine
                                                                        + "Answering No will update missing blocks.", "GXDLMSDirector",
                                                                        MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question);
                            if (ret == DialogResult.Cancel)
                            {
                                arg.Action = ActionType.None;
                                return;
                            }
                            if (ret == DialogResult.No)
                            {
                                status.ImageStartIndex = index;
                                arg.Index  = 2;
                                arg.Action = ActionType.Action;
                                return;
                            }
                            break;
                        }
                        ++index;
                    }
                    OnDescription(Properties.Resources.ImageBlockSize + it.ImageBlockSize);
                    //Invoke Initiates image transfer.
                    arg.Index  = 1;
                    arg.Action = ActionType.Action;
                }
                else if (arg.Index == 6)
                {
                    OnImageTransferStatus(it.ImageTransferStatus);
                    GetDelay(arg);
                    if (arg.Exception != null)
                    {
                        return;
                    }
                    int delay = (int)arg.Value;
                    arg.Value = null;
                    switch (it.ImageTransferStatus)
                    {
                    case ImageTransferStatus.NotInitiated:
                        if (++status.StatusReadCount > 10)
                        {
                            OnDescription("Failed to read Image transfer status after image transfer initiate.");
                            GXHelpers.ShowMessageBox(this, "Failed to read Image transfer status after image transfer initiate.", "", MessageBoxButtons.OK, MessageBoxIcon.Information);
                            arg.Action = ActionType.None;
                            return;
                        }
                        Thread.Sleep(delay);
                        arg.Index = 6;
                        break;

                    case ImageTransferStatus.TransferInitiated:
                        if (!status.TransformingImage)
                        {
                            arg.Action = ActionType.Action;
                            arg.Index  = 2;
                            status.TransformingImage = true;
                        }
                        else
                        {
                            if (!Properties.Settings.Default.ImageManualUpdate)
                            {
                                arg.Action = ActionType.Action;
                                if (arg.Client.CanInvoke(arg.Target, 3))
                                {
                                    arg.Index = 3;
                                }
                                else if (arg.Client.CanInvoke(arg.Target, 4))
                                {
                                    arg.Index = 4;
                                }
                                else
                                {
                                    GXHelpers.ShowMessageBox(this, Properties.Resources.ImageTransferedNotActivatedTxt, "", MessageBoxButtons.OK, MessageBoxIcon.Information);
                                    arg.Action = ActionType.None;
                                }
                            }
                            else
                            {
                                arg.Action = ActionType.None;
                                ManualBtn_CheckedChanged(null, null);
                            }
                        }
                        break;

                    case ImageTransferStatus.VerificationInitiated:
                        Thread.Sleep(delay);
                        OnDescription(Properties.Resources.VerificationInitiated);
                        arg.Text  = Properties.Resources.VerificationInitiated;
                        arg.Index = 6;
                        break;

                    case ImageTransferStatus.VerificationSuccessful:
                        arg.Index  = 4;
                        arg.Action = ActionType.Action;
                        break;

                    case ImageTransferStatus.VerificationFailed:
                        OnDescription(Properties.Resources.VerificationFailed);
                        arg.Text   = Properties.Resources.VerificationFailed;
                        arg.Action = ActionType.None;
                        break;

                    case ImageTransferStatus.ActivationInitiated:
                        Thread.Sleep(delay);
                        OnDescription(Properties.Resources.ActivationInitiated);
                        arg.Text = Properties.Resources.ActivationInitiated;
                        break;

                    case ImageTransferStatus.ActivationSuccessful:
                        OnDescription(Properties.Resources.ActivationSuccessful);
                        GXHelpers.ShowMessageBox(this, Properties.Resources.ImageActivatedTxt, "", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        arg.Action = ActionType.None;
                        break;

                    case ImageTransferStatus.ActivationFailed:
                        OnDescription(Properties.Resources.ActivationFailed);
                        arg.Text   = Properties.Resources.ActivationFailed;
                        arg.Action = ActionType.None;
                        break;
                    }
                }
            }
            else if (arg.Action == ActionType.Action)
            {
                if (arg.Index == 1)
                {
                    OnDescription("Image transfer initiated.");
                    arg.Action = ActionType.Read;
                    arg.Index  = 6;
                }
                else if (arg.Index == 2)
                {
                    OnDescription("Image transfered.");
                    arg.Index  = 6;
                    arg.Action = ActionType.Read;
                }
                else if (arg.Index == 3)
                {
                    if (arg.Exception is GXDLMSException)
                    {
                        //If meter is verifying the image.
                        if ((arg.Exception as GXDLMSException).ErrorCode == (int)ErrorCode.TemporaryFailure)
                        {
                            if (!Properties.Settings.Default.ImageManualUpdate)
                            {
                                arg.Exception = null;
                                GetDelay(arg);
                                if (arg.Exception != null)
                                {
                                    return;
                                }
                                int delay = (int)arg.Value;
                                Thread.Sleep(delay);
                                arg.Value = null;
                            }
                        }
                        else
                        {
                            OnDescription("Image verifying failed.");
                        }
                        return;
                    }
                    if (!Properties.Settings.Default.ImageManualUpdate)
                    {
                        arg.Index  = 6;
                        arg.Action = ActionType.Read;
                    }
                    else
                    {
                        arg.Action = ActionType.None;
                    }
                }
                else if (arg.Index == 4)
                {
                    if (arg.Exception is GXDLMSException)
                    {
                        //If meter is activating image.
                        if ((arg.Exception as GXDLMSException).ErrorCode == (int)ErrorCode.TemporaryFailure)
                        {
                            if (!Properties.Settings.Default.ImageManualUpdate)
                            {
                                arg.Exception = null;
                                GetDelay(arg);
                                if (arg.Exception != null)
                                {
                                    return;
                                }
                                int delay = (int)arg.Value;
                                Thread.Sleep(delay);
                                arg.Value = null;
                            }
                        }
                        else
                        {
                            OnDescription("Image activation failed.");
                        }
                        return;
                    }
                    OnDescription(Properties.Resources.ImageActivatedTxt);
                    arg.Action    = ActionType.None;
                    arg.Rebooting = true;
                    GXHelpers.ShowMessageBox(this, Properties.Resources.ActionImplemented, "", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
            }
        }
 void OnShowDlg(GXActionArgs arg)
 {
     if (InvokeRequired)
     {
         BeginInvoke(new ShowDlgEventHandler(OnShowDlg), arg).AsyncWaitHandle.WaitOne();
     }
     else
     {
         GXTextDlg       dlg;
         IPv6AddressType type;
         GXDLMSIp6Setup  target = Target as GXDLMSIp6Setup;
         if (arg.Index == 1)
         {
             if (AddressTab.SelectedIndex == 0)
             {
                 dlg  = new GXTextDlg("Add Unicast Address", "Unicast address:", "", typeof(IPAddress));
                 type = IPv6AddressType.Unicast;
             }
             else if (AddressTab.SelectedIndex == 1)
             {
                 dlg  = new GXTextDlg("Add Multicast IP Address", "Multicast address:", "", typeof(IPAddress));
                 type = IPv6AddressType.Multicast;
             }
             else if (AddressTab.SelectedIndex == 2)
             {
                 dlg  = new GXTextDlg("Add Gateway IP Address", "Gateway address:", "", typeof(IPAddress));
                 type = IPv6AddressType.Gateway;
             }
             else
             {
                 throw new ArgumentOutOfRangeException();
             }
             if (dlg.ShowDialog(this) == DialogResult.OK)
             {
                 IPAddress addr = IPAddress.Parse(dlg.GetValue());
                 arg.Value = target.AddAddress(arg.Client, type, addr);
             }
             else
             {
                 arg.Handled = true;
             }
         }
         else if (arg.Index == 2)
         {
             if (AddressTab.SelectedIndex == 0 && UnicastAddressView.SelectedItems.Count != 0)
             {
                 ListViewItem li      = UnicastAddressView.SelectedItems[0];
                 IPAddress    address = (IPAddress)li.Tag;
                 UnicastAddressView.Items.Remove(li);
                 arg.Value = target.RemoveAddress(arg.Client, IPv6AddressType.Unicast, address);
             }
             else if (AddressTab.SelectedIndex == 1 && MulticastAddressView.SelectedItems.Count != 0)
             {
                 ListViewItem li      = MulticastAddressView.SelectedItems[0];
                 IPAddress    address = (IPAddress)li.Tag;
                 MulticastAddressView.Items.Remove(li);
                 arg.Value = target.RemoveAddress(arg.Client, IPv6AddressType.Multicast, address);
             }
             else if (AddressTab.SelectedIndex == 2 && GatewayAddressView.SelectedItems.Count != 0)
             {
                 ListViewItem li      = GatewayAddressView.SelectedItems[0];
                 IPAddress    address = (IPAddress)li.Tag;
                 GatewayAddressView.Items.Remove(li);
                 arg.Value = target.RemoveAddress(arg.Client, IPv6AddressType.Gateway, address);
             }
             else
             {
                 throw new ArgumentOutOfRangeException();
             }
         }
         else
         {
             arg.Handled = true;
         }
     }
 }
 public void PreAction(GXActionArgs arg)
 {
     arg.Value = (sbyte)0;
 }
Exemplo n.º 6
0
        public void PostAction(GXActionArgs arg)
        {
            GXDLMSImageTransfer it = Target as GXDLMSImageTransfer;

            if (arg.Action == ActionType.Read)
            {
                if (arg.Index == 5)
                {
                    if (!it.ImageTransferEnabled)
                    {
                        updatingImage = false;
                        GXHelpers.ShowMessageBox(this, Properties.Resources.ImageTransferDisabled, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        arg.Action = ActionType.None;
                        return;
                    }
                    OnDescription(Properties.Resources.ImageTransferEnabled);
                    //Get ImageBlockSize.
                    arg.Index = 2;
                }
                else if (arg.Index == 2)
                {
                    OnDescription(Properties.Resources.ImageBlockSize + it.ImageBlockSize);
                    //Invoke Initiates image transfer.
                    arg.Index  = 1;
                    arg.Action = ActionType.Action;
                }
                else if (arg.Index == 6)
                {
                    OnImageTransferStatus(it.ImageTransferStatus);
                    GetDelay(arg);
                    if (arg.Exception != null)
                    {
                        return;
                    }
                    int delay = (int)arg.Value;
                    arg.Value = null;
                    switch (it.ImageTransferStatus)
                    {
                    case ImageTransferStatus.NotInitiated:
                        if (++statusReadCount > 10)
                        {
                            OnDescription("Failed to read Image transfer status after image transfer initiate.");
                            GXHelpers.ShowMessageBox(this, "Failed to read Image transfer status after image transfer initiate.", "", MessageBoxButtons.OK, MessageBoxIcon.Information);
                            arg.Action    = ActionType.None;
                            updatingImage = false;
                            return;
                        }
                        Thread.Sleep(delay);
                        arg.Index = 6;
                        break;

                    case ImageTransferStatus.TransferInitiated:
                        if (!transformingImage)
                        {
                            arg.Action        = ActionType.Action;
                            arg.Index         = 2;
                            transformingImage = true;
                        }
                        else
                        {
                            if (!Properties.Settings.Default.ImageManualUpdate)
                            {
                                arg.Index  = 3;
                                arg.Action = ActionType.Action;
                            }
                            else
                            {
                                arg.Action = ActionType.None;
                                ManualBtn_CheckedChanged(null, null);
                            }
                        }
                        break;

                    case ImageTransferStatus.VerificationInitiated:
                        Thread.Sleep(delay);
                        OnDescription(Properties.Resources.VerificationInitiated);
                        arg.Text  = Properties.Resources.VerificationInitiated;
                        arg.Index = 6;
                        break;

                    case ImageTransferStatus.VerificationSuccessful:
                        arg.Index  = 4;
                        arg.Action = ActionType.Action;
                        break;

                    case ImageTransferStatus.VerificationFailed:
                        OnDescription(Properties.Resources.VerificationFailed);
                        arg.Text   = Properties.Resources.VerificationFailed;
                        arg.Action = ActionType.None;
                        break;

                    case ImageTransferStatus.ActivationInitiated:
                        Thread.Sleep(delay);
                        OnDescription(Properties.Resources.ActivationInitiated);
                        arg.Text = Properties.Resources.ActivationInitiated;
                        break;

                    case ImageTransferStatus.ActivationSuccessful:
                        OnDescription(Properties.Resources.ActivationSuccessful);
                        GXHelpers.ShowMessageBox(this, Properties.Resources.ImageActivatedTxt, "", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        arg.Action = ActionType.None;
                        break;

                    case ImageTransferStatus.ActivationFailed:
                        OnDescription(Properties.Resources.ActivationFailed);
                        arg.Text   = Properties.Resources.ActivationFailed;
                        arg.Action = ActionType.None;
                        break;
                    }
                }
            }
            else if (arg.Action == ActionType.Action)
            {
                if (arg.Index == 1)
                {
                    OnDescription("Image transfer initiated.");
                    arg.Action = ActionType.Read;
                    arg.Index  = 6;
                }
                else if (arg.Index == 2)
                {
                    OnDescription("Image transfered.");
                    arg.Index  = 6;
                    arg.Action = ActionType.Read;
                }
                else if (arg.Index == 3)
                {
                    if (arg.Exception is GXDLMSException)
                    {
                        //If meter is activating image.
                        if ((arg.Exception as GXDLMSException).ErrorCode == (int)ErrorCode.TemporaryFailure)
                        {
                            if (!Properties.Settings.Default.ImageManualUpdate)
                            {
                                arg.Exception = null;
                                GetDelay(arg);
                                if (arg.Exception != null)
                                {
                                    return;
                                }
                                int delay = (int)arg.Value;
                                Thread.Sleep(delay);
                                arg.Value = null;
                            }
                            return;
                        }
                    }
                    if (!Properties.Settings.Default.ImageManualUpdate)
                    {
                        arg.Index  = 6;
                        arg.Action = ActionType.Read;
                    }
                    else
                    {
                        arg.Action = ActionType.None;
                    }
                }
                else if (arg.Index == 4)
                {
                    if (arg.Exception is GXDLMSException)
                    {
                        //If meter is activating image.
                        if ((arg.Exception as GXDLMSException).ErrorCode == (int)ErrorCode.TemporaryFailure)
                        {
                            if (!Properties.Settings.Default.ImageManualUpdate)
                            {
                                arg.Exception = null;
                                GetDelay(arg);
                                if (arg.Exception != null)
                                {
                                    return;
                                }
                                int delay = (int)arg.Value;
                                Thread.Sleep(delay);
                                arg.Value = null;
                            }
                            return;
                        }
                    }
                    OnDescription(Properties.Resources.ImageActivatedTxt);
                    arg.Action    = ActionType.None;
                    arg.Rebooting = true;
                }
            }
        }
 public void PreAction(GXActionArgs arg)
 {
     //Add object to association view.
     if (arg.Index == 3)
     {
         GXDLMSObject it = new GXDLMSData();
         OnShowDialog(it, arg);
     }
     else if (arg.Index == 4)
     {
         // Remove object from association view.
         OnShowDialog(null, arg);
     }
     //Add user to user list.
     else if (arg.Index == 5)
     {
         OnShowDialog(true, arg);
     }
     else if (arg.Index == 6)
     {
         // Remove user from user list.
         OnShowDialog(false, arg);
     }
     if (arg.Action == ActionType.Write && arg.Index == 7)
     {
         DialogResult ret;
         //Update pw.
         ret = GXHelpers.ShowMessageBox(this, Properties.Resources.SetPasswordWarning, "", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question);
         if (ret == DialogResult.Yes)
         {
             byte[] value;
             if (SecretAsciiCb.Checked)
             {
                 value = ASCIIEncoding.ASCII.GetBytes(SecretTB.Text);
             }
             else
             {
                 value = GXDLMSTranslator.HexToBytes(SecretTB.Text);
             }
             GXDLMSAssociationLogicalName target = Target as GXDLMSAssociationLogicalName;
             if (target.AuthenticationMechanismName.MechanismId == Authentication.Low)
             {
                 arg.Index  = 7;
                 arg.Action = ActionType.Write;
             }
             else
             {
                 arg.Action = ActionType.Action;
                 arg.Index  = 2;
             }
             if (arg.Action == ActionType.Write)
             {
                 target.Secret = value;
             }
             else
             {
                 GXByteBuffer bb = new GXByteBuffer();
                 bb.SetUInt8((byte)DataType.OctetString);
                 bb.SetUInt8((byte)value.Length);
                 bb.Set(value);
                 arg.Value = bb.Array();
             }
         }
         arg.Handled = ret != DialogResult.Yes;
     }
     else if (arg.Action == ActionType.Write && arg.Index == 2)
     {
         //Skip write invoke.
         arg.Handled = true;
     }
 }