/// <summary>
        /// Deletes the channel.
        /// </summary>
        private void DeleteChannel()
        {
            GatewayConfig gatewayConfig = lvwChannels.SelectedObject as GatewayConfig;

            if (gatewayConfig != null)
            {
                DialogResult result = FormHelper.Confirm(string.Format(Resources.MsgConfirmDeleteGateway, gatewayConfig.Id));
                if (result == DialogResult.Yes)
                {
                    // Delete the gateway configuration
                    GatewayConfig.Delete(g => g.Id == gatewayConfig.Id);

                    /*
                     * this.lvwChannels.RemoveObject(gatewayConfig);
                     * this.lvwChannels.RefreshObjects(this.lvwChannels.SelectedObjects);
                     */

                    //this.lvwChannels.ClearObjects();
                    //ShowChannels();

                    this.lvwChannels.RemoveObjects(this.lvwChannels.SelectedObjects);

                    if (GatewayRemoved != null)
                    {
                        // Raise the event
                        GatewayEventHandlerArgs arg = new GatewayEventHandlerArgs(gatewayConfig.Id);
                        this.GatewayRemoved.BeginInvoke(this, arg, new AsyncCallback(this.AsyncCallback), null);
                    }
                }
            }
            else
            {
                FormHelper.ShowInfo(Resources.MsgGatewayMustBeSelected);
            }
        }
        /// <summary>
        /// Gateways the form_ gateway added.
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="e">The e.</param>
        private void gatewayForm_GatewayAdded(object sender, GatewayEventHandlerArgs e)
        {
            GatewayConfig newChannel = GatewayConfig.SingleOrDefault(g => g.Id == e.GatewayId);

            this.lvwChannels.AddObject(newChannel);
            if (GatewayAdded != null)
            {
                // Raise the event
                GatewayEventHandlerArgs arg = new GatewayEventHandlerArgs(e.GatewayId);
                this.GatewayAdded.BeginInvoke(this, arg, new AsyncCallback(this.AsyncCallback), null);
            }
        }
        /// <summary>
        /// Invoked when a gateway is updated
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="e">The e.</param>
        private void gatewayForm_GatewayUpdated(object sender, GatewayEventHandlerArgs e)
        {
            GatewayConfig updatedChannel = GatewayConfig.SingleOrDefault(g => g.Id == e.GatewayId);

            // Refresh the list view
            RefreshView();

            if (GatewayUpdated != null)
            {
                // Raise the event
                GatewayEventHandlerArgs arg = new GatewayEventHandlerArgs(e.GatewayId);
                this.GatewayUpdated.BeginInvoke(this, arg, new AsyncCallback(this.AsyncCallback), null);
            }
        }
        /// <summary>
        /// Saves the changes.
        /// </summary>
        /// <returns></returns>
        private bool SaveChanges()
        {
            // Validate the name is not empty
            if (!FormHelper.ValidateNotEmpty(txtName, Resources.MsgUniqueNameRequired))
            {
                return false;
            }

            string gatewayId = txtName.Text.Trim();
            if (!this.IsUpdate)
            {
                // The gateway name must be unique 
                if (GatewayConfig.Exists(g => g.Id.ToLower() == gatewayId.ToLower()))
                {
                    FormHelper.ShowError(txtName, string.Format(Resources.MsgGatewayNameAlreadyExists, gatewayId));
                    return false;
                }

                // The port name should not be in use
                if (GatewayConfig.Exists(g => g.ComPort.ToLower() == cboPort.Text.ToLower()))
                {
                    DialogResult dialogResult = FormHelper.Confirm(string.Format(Resources.MsgDuplicateComPort, cboPort.Text));
                    if (dialogResult == DialogResult.No)
                    {
                        return false;
                    }
                }
            }           

            // If forwarded is checked, make sure email address is not empty
            if (chkForwardArchivedMessageLogAsEmail.Checked)
            {
                if (!FormHelper.ValidateNotEmpty(txtEmailAddress, Resources.MsgEmailAddressRequired))
                {
                    return false;
                }
            }

            // If auto response is required, make sure the text is not empty
            if (chkAutoResponseCall.Checked)
            {
                if (!FormHelper.ValidateNotEmpty(txtAutoResponseText, Resources.MsgAutoResponseTextRequired))
                {
                    return false;
                }
            }

            try
            {
                // Save the gateway configuration
                GatewayConfig gatewayConfig = new GatewayConfig();

                if (this.IsUpdate)
                {
                    gatewayConfig = GatewayConfig.SingleOrDefault(g => g.Id == gatewayId);
                }
                
                // General
                gatewayConfig.Id = gatewayId;
                gatewayConfig.OwnNumber = txtPhoneNo.Text;
                gatewayConfig.AutoConnect = chkConnectAtStartup.Checked;
                gatewayConfig.Functions = 0;
                if (chkSendMessage.Checked)
                    gatewayConfig.Functions += (int)GatewayFunction.SendMessage;
                if (chkReceiveMessage.Checked)
                    gatewayConfig.Functions += (int)GatewayFunction.ReceiveMessage;
                gatewayConfig.LogSettings = cboLogType.Text;
                gatewayConfig.ClearLogOnConnect = chkClearLogOnConnect.Checked;
                gatewayConfig.Initialize = false;
                
                // Communication
                gatewayConfig.ComPort = cboPort.Text;
                gatewayConfig.BaudRate = cboBaudRate.Text;
                gatewayConfig.DataBits = cboDataBits.Text;
                gatewayConfig.Parity = cboParity.Text;
                gatewayConfig.StopBits = cboStopBits.Text;
                gatewayConfig.Handshake = cboHandshake.Text;
                gatewayConfig.CommandTimeout = Convert.ToInt32(updCommandTimeout.Value);
                gatewayConfig.CommandDelay = Convert.ToInt32(updCommandDelay.Value);
                gatewayConfig.ReadTimeout = Convert.ToInt32(updReadIntervalTimeout.Value);
                
               
                // Message Settings
                gatewayConfig.Smsc = txtSmsc.Text;
                gatewayConfig.UseSimSmsc = chkUseSmscFromSim.Checked;
                gatewayConfig.MessageMemory = cboMessageMemory.Text;
                gatewayConfig.MessageValidity = cboMessageValidity.Text;
                gatewayConfig.SendRetry = Convert.ToInt32(updSendRetry.Value);
                gatewayConfig.SendDelay = Convert.ToInt32(updSendDelay.Value);
                gatewayConfig.RequestStatusReport = chkRequestDeliveryStatusReport.Checked;
                gatewayConfig.DeleteAfterRetrieve = chkDeleteAfterRetrieve.Checked;
                
               
                // Message log
                gatewayConfig.AutoArchiveLog = chkAutoArchiveMessageLog.Checked;
                gatewayConfig.AutoArchiveLogInterval = Convert.ToInt32(updArchiveMessageLogDay.Value);
                gatewayConfig.ArchiveOldMessageInterval = Convert.ToInt32(updArchiveMessageOlderThanDay.Value);
                gatewayConfig.ForwardArchivedMessage = chkForwardArchivedMessageLogAsEmail.Checked;
                gatewayConfig.ForwardEmail = txtEmailAddress.Text;
                gatewayConfig.DeleteArchivedMessage = chkDeleteArchivedMessageOlderThan.Checked;
                gatewayConfig.DeleteArchivedMessageInterval = Convert.ToInt32(updDeleteArchivedMessageOlderThanDay.Value);

                // Other settings
                gatewayConfig.SignalRefreshInterval = Convert.ToInt32(updRefreshSignalInterval.Value);
                gatewayConfig.Pin = txtPin.Text;
                gatewayConfig.AutoResponseCall = chkAutoResponseCall.Checked;
                gatewayConfig.AutoResponseCallText = txtAutoResponseText.Text;

                if (!this.IsUpdate)
                    gatewayConfig.Save();
                else
                    gatewayConfig.Update();

                if (GatewayAdded != null)
                {
                    // Raise the event
                    GatewayEventHandlerArgs arg = new GatewayEventHandlerArgs(gatewayId);
                    this.GatewayAdded.BeginInvoke(this, arg, new AsyncCallback(this.AsyncCallback), null);
                }

                if (GatewayUpdated != null)
                {
                    // Raise the event
                    GatewayEventHandlerArgs arg = new GatewayEventHandlerArgs(gatewayId);
                    this.GatewayUpdated.BeginInvoke(this, arg, new AsyncCallback(this.AsyncCallback), null);
                }

            }
            catch (Exception ex)
            {
                FormHelper.ShowError(ex.Message);
                return false;
            }

            // Reset to false
            isFormChanged = false;

            // Show successful save message
            FormHelper.ShowInfo(Resources.MsgGatewayConfigSaved);

            // Return true as saving is successful
            return true;

        }
        /// <summary>
        /// CTLs the channels_ gateway added.
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="e">The e.</param>
        private void ctlChannels_GatewayAdded(object sender, GatewayEventHandlerArgs e)
        {
            log.Info(string.Format("New gateway [{0}] is added", e.GatewayId));
            EventAction action = new EventAction(StringEnum.GetStringValue(EventNotificationType.NewGateway));
            action.Values.Add(EventParameter.GatewayId, e.GatewayId);
            RemotingHelper.NotifyEvent(serviceEventListenerUrl, action);

            // Reset the settings in NewMessage user control
            ctlNewMessage.SetupMessageSettings();
        }
        /// <summary>
        /// Invoked when a gateway is updated
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="e">The e.</param>
        private void gatewayForm_GatewayUpdated(object sender, GatewayEventHandlerArgs e)
        {
            GatewayConfig updatedChannel = GatewayConfig.SingleOrDefault(g => g.Id == e.GatewayId);

            // Refresh the list view
            RefreshView();

            if (GatewayUpdated != null)
            {
                // Raise the event
                GatewayEventHandlerArgs arg = new GatewayEventHandlerArgs(e.GatewayId);
                this.GatewayUpdated.BeginInvoke(this, arg, new AsyncCallback(this.AsyncCallback), null);
            }
        }
        /// <summary>
        /// Deletes the channel.
        /// </summary>
        private void DeleteChannel()
        {
            GatewayConfig gatewayConfig = lvwChannels.SelectedObject as GatewayConfig;
            if (gatewayConfig != null) 
            {
                DialogResult result = FormHelper.Confirm(string.Format(Resources.MsgConfirmDeleteGateway, gatewayConfig.Id));
                if (result == DialogResult.Yes) 
                {
                    // Delete the gateway configuration
                    GatewayConfig.Delete(g=> g.Id == gatewayConfig.Id);

                    /*
                    this.lvwChannels.RemoveObject(gatewayConfig);
                    this.lvwChannels.RefreshObjects(this.lvwChannels.SelectedObjects);
                    */

                    //this.lvwChannels.ClearObjects();
                    //ShowChannels();

                    this.lvwChannels.RemoveObjects(this.lvwChannels.SelectedObjects);

                    if (GatewayRemoved != null)
                    {
                        // Raise the event
                        GatewayEventHandlerArgs arg = new GatewayEventHandlerArgs(gatewayConfig.Id);
                        this.GatewayRemoved.BeginInvoke(this, arg, new AsyncCallback(this.AsyncCallback), null);
                    }
                }
            } else 
            {
                FormHelper.ShowInfo(Resources.MsgGatewayMustBeSelected);
            }

        }
 /// <summary>
 /// Gateways the form_ gateway added.
 /// </summary>
 /// <param name="sender">The sender.</param>
 /// <param name="e">The e.</param>
 private void gatewayForm_GatewayAdded(object sender, GatewayEventHandlerArgs e)
 {
     GatewayConfig newChannel = GatewayConfig.SingleOrDefault(g => g.Id == e.GatewayId);
     this.lvwChannels.AddObject(newChannel);
     if (GatewayAdded != null)
     {
         // Raise the event
         GatewayEventHandlerArgs arg = new GatewayEventHandlerArgs(e.GatewayId);
         this.GatewayAdded.BeginInvoke(this, arg, new AsyncCallback(this.AsyncCallback), null);
     }
 }
Esempio n. 9
0
        /// <summary>
        /// Saves the changes.
        /// </summary>
        /// <returns></returns>
        private bool SaveChanges()
        {
            // Validate the name is not empty
            if (!FormHelper.ValidateNotEmpty(txtName, Resources.MsgUniqueNameRequired))
            {
                return(false);
            }

            string gatewayId = txtName.Text.Trim();

            if (!this.IsUpdate)
            {
                // The gateway name must be unique
                if (GatewayConfig.Exists(g => g.Id.ToLower() == gatewayId.ToLower()))
                {
                    FormHelper.ShowError(txtName, string.Format(Resources.MsgGatewayNameAlreadyExists, gatewayId));
                    return(false);
                }

                // The port name should not be in use
                if (GatewayConfig.Exists(g => g.ComPort.ToLower() == cboPort.Text.ToLower()))
                {
                    DialogResult dialogResult = FormHelper.Confirm(string.Format(Resources.MsgDuplicateComPort, cboPort.Text));
                    if (dialogResult == DialogResult.No)
                    {
                        return(false);
                    }
                }
            }

            // If forwarded is checked, make sure email address is not empty
            if (chkForwardArchivedMessageLogAsEmail.Checked)
            {
                if (!FormHelper.ValidateNotEmpty(txtEmailAddress, Resources.MsgEmailAddressRequired))
                {
                    return(false);
                }
            }

            // If auto response is required, make sure the text is not empty
            if (chkAutoResponseCall.Checked)
            {
                if (!FormHelper.ValidateNotEmpty(txtAutoResponseText, Resources.MsgAutoResponseTextRequired))
                {
                    return(false);
                }
            }

            try
            {
                // Save the gateway configuration
                GatewayConfig gatewayConfig = new GatewayConfig();

                if (this.IsUpdate)
                {
                    gatewayConfig = GatewayConfig.SingleOrDefault(g => g.Id == gatewayId);
                }

                // General
                gatewayConfig.Id          = gatewayId;
                gatewayConfig.OwnNumber   = txtPhoneNo.Text;
                gatewayConfig.AutoConnect = chkConnectAtStartup.Checked;
                gatewayConfig.Functions   = 0;
                if (chkSendMessage.Checked)
                {
                    gatewayConfig.Functions += (int)GatewayFunction.SendMessage;
                }
                if (chkReceiveMessage.Checked)
                {
                    gatewayConfig.Functions += (int)GatewayFunction.ReceiveMessage;
                }
                gatewayConfig.LogSettings       = cboLogType.Text;
                gatewayConfig.ClearLogOnConnect = chkClearLogOnConnect.Checked;
                gatewayConfig.Initialize        = false;

                // Communication
                gatewayConfig.ComPort        = cboPort.Text;
                gatewayConfig.BaudRate       = cboBaudRate.Text;
                gatewayConfig.DataBits       = cboDataBits.Text;
                gatewayConfig.Parity         = cboParity.Text;
                gatewayConfig.StopBits       = cboStopBits.Text;
                gatewayConfig.Handshake      = cboHandshake.Text;
                gatewayConfig.CommandTimeout = Convert.ToInt32(updCommandTimeout.Value);
                gatewayConfig.CommandDelay   = Convert.ToInt32(updCommandDelay.Value);
                gatewayConfig.ReadTimeout    = Convert.ToInt32(updReadIntervalTimeout.Value);


                // Message Settings
                gatewayConfig.Smsc                = txtSmsc.Text;
                gatewayConfig.UseSimSmsc          = chkUseSmscFromSim.Checked;
                gatewayConfig.MessageMemory       = cboMessageMemory.Text;
                gatewayConfig.MessageValidity     = cboMessageValidity.Text;
                gatewayConfig.SendRetry           = Convert.ToInt32(updSendRetry.Value);
                gatewayConfig.SendDelay           = Convert.ToInt32(updSendDelay.Value);
                gatewayConfig.RequestStatusReport = chkRequestDeliveryStatusReport.Checked;
                gatewayConfig.DeleteAfterRetrieve = chkDeleteAfterRetrieve.Checked;


                // Message log
                gatewayConfig.AutoArchiveLog            = chkAutoArchiveMessageLog.Checked;
                gatewayConfig.AutoArchiveLogInterval    = Convert.ToInt32(updArchiveMessageLogDay.Value);
                gatewayConfig.ArchiveOldMessageInterval = Convert.ToInt32(updArchiveMessageOlderThanDay.Value);
                gatewayConfig.ForwardArchivedMessage    = chkForwardArchivedMessageLogAsEmail.Checked;
                gatewayConfig.ForwardEmail                  = txtEmailAddress.Text;
                gatewayConfig.DeleteArchivedMessage         = chkDeleteArchivedMessageOlderThan.Checked;
                gatewayConfig.DeleteArchivedMessageInterval = Convert.ToInt32(updDeleteArchivedMessageOlderThanDay.Value);

                // Other settings
                gatewayConfig.SignalRefreshInterval = Convert.ToInt32(updRefreshSignalInterval.Value);
                gatewayConfig.Pin = txtPin.Text;
                gatewayConfig.AutoResponseCall     = chkAutoResponseCall.Checked;
                gatewayConfig.AutoResponseCallText = txtAutoResponseText.Text;

                if (!this.IsUpdate)
                {
                    gatewayConfig.Save();
                }
                else
                {
                    gatewayConfig.Update();
                }

                if (GatewayAdded != null)
                {
                    // Raise the event
                    GatewayEventHandlerArgs arg = new GatewayEventHandlerArgs(gatewayId);
                    this.GatewayAdded.BeginInvoke(this, arg, new AsyncCallback(this.AsyncCallback), null);
                }

                if (GatewayUpdated != null)
                {
                    // Raise the event
                    GatewayEventHandlerArgs arg = new GatewayEventHandlerArgs(gatewayId);
                    this.GatewayUpdated.BeginInvoke(this, arg, new AsyncCallback(this.AsyncCallback), null);
                }
            }
            catch (Exception ex)
            {
                FormHelper.ShowError(ex.Message);
                return(false);
            }

            // Reset to false
            isFormChanged = false;

            // Show successful save message
            FormHelper.ShowInfo(Resources.MsgGatewayConfigSaved);

            // Return true as saving is successful
            return(true);
        }