Beispiel #1
0
        /// <summary>
        /// Creates and adds new route to route collection.
        /// </summary>
        /// <param name="description">Route description text.</param>
        /// <param name="pattern">Route pattern.</param>
        /// <param name="enabled">Specifies if route is enabled.</param>
        /// <param name="action">Route action.</param>
        /// <returns></returns>
        public Route Add(string description,string pattern,bool enabled,RouteActionBase action)
        {
            /* AddRoute <virtualServerID> "<routeID>" <cost> "<description>" "<pattern>" <enabled> <actionType> "<actionData>:base64"
                  Responses:
                    +OK                     
                    -ERR <errorText>
            */
            
            string id   = Guid.NewGuid().ToString();
            long   cost = DateTime.Now.Ticks;

            // Call TCP AddRoute
            m_pVirtualServer.Server.TcpClient.TcpStream.WriteLine("AddRoute " + 
                m_pVirtualServer.VirtualServerID + " " + 
                TextUtils.QuoteString(id) + " " + 
                cost + " " +
                TextUtils.QuoteString(description) + " " + 
                TextUtils.QuoteString(pattern) + " " + 
                enabled + " " +
                (int)action.ActionType + " " +
                Convert.ToBase64String(action.Serialize())
            );
                        
            string response = m_pVirtualServer.Server.ReadLine();
            if(!response.ToUpper().StartsWith("+OK")){
                throw new Exception(response);
            }
            
            Route route = new Route(this,id,cost,description,pattern,enabled,action);
            m_pRoutes.Add(route);
            return route;
        }
Beispiel #2
0
        /// <summary>
        /// Edit constructor.
        /// </summary>
        /// <param name="virtualServer">Virtual server.</param>
        /// <param name="route">Route to update.</param>
        public wfrm_Routing_Route(VirtualServer virtualServer,Route route)
        {
            m_pVirtualServer = virtualServer;
            m_pRoute         = route;

            InitUI();

            m_pEnabled.Checked = route.Enabled;
            m_pDescription.Text = route.Description;
            m_pPattern.Text = route.Pattern;
            
            #region RouteToMailbox

            if(route.Action.ActionType == RouteAction_enum.RouteToMailbox){
                m_pRouteToMailbox_Mailbox.Text = ((RouteAction_RouteToMailbox)route.Action).Mailbox;

                m_pAction.SelectedIndex = 0;
            }

            #endregion

            #region RouteToEmail

            else if(route.Action.ActionType == RouteAction_enum.RouteToEmail){
                m_pRouteToEmail_Email.Text = ((RouteAction_RouteToEmail)route.Action).EmailAddress;

                m_pAction.SelectedIndex = 1;
            }

            #endregion

            #region RouteToHost

            else if(route.Action.ActionType == RouteAction_enum.RouteToHost){
                m_pRouteToHost_Host.Text  = ((RouteAction_RouteToHost)route.Action).Host;
                m_pRouteToHost_Port.Value = ((RouteAction_RouteToHost)route.Action).Port;

                m_pAction.SelectedIndex = 2;
            }

            #endregion             
             
        }
Beispiel #3
0
        /// <summary>
        /// Deletes and removes specified route from route collection.
        /// </summary>
        /// <param name="route">Route to delete.</param>
        public void Remove(Route route)
        {
            /* DeleteRoute <virtualServerID> "<routeID>"
                  Responses:
                    +OK                     
                    -ERR <errorText>
            */
            
            string id = Guid.NewGuid().ToString();

            // Call TCP DeleteRoute
            m_pVirtualServer.Server.TcpClient.TcpStream.WriteLine("DeleteRoute " + m_pVirtualServer.VirtualServerID + " " + TextUtils.QuoteString(route.ID));
                        
            string response = m_pVirtualServer.Server.ReadLine();
            if(!response.ToUpper().StartsWith("+OK")){
                throw new Exception(response);
            }

            m_pRoutes.Remove(route);
        }
Beispiel #4
0
        private void m_pOk_Click(object sender, EventArgs e)
        {
            if(m_pPattern.Text.Length == 0){
                MessageBox.Show(this,"Please specify match pattern !","Error:",MessageBoxButtons.OK,MessageBoxIcon.Error);
                return;
            }

            RouteAction_enum action     = (RouteAction_enum)((WComboBoxItem)m_pAction.SelectedItem).Tag;
            RouteActionBase  actionData = null;

            #region Route To Mailbox

            if(action == RouteAction_enum.RouteToMailbox){
                //--- Validate values ------------------------------------------------//
                if(m_pRouteToMailbox_Mailbox.Text == ""){
                    MessageBox.Show(this,"Mailbox: value can't empty !","Error:",MessageBoxButtons.OK,MessageBoxIcon.Error);
                    return;
                }
                //--------------------------------------------------------------------//

                actionData = new RouteAction_RouteToMailbox(m_pRouteToMailbox_Mailbox.Text);
            }

            #endregion

            #region Route To Email

            else if(action == RouteAction_enum.RouteToEmail){
                //--- Validate values ------------------------------------------------//
                if(m_pRouteToEmail_Email.Text == ""){
                    MessageBox.Show(this,"Email: value can't empty !","Error:",MessageBoxButtons.OK,MessageBoxIcon.Error);
                    return;
                }
                //--------------------------------------------------------------------//

                actionData = new RouteAction_RouteToEmail(m_pRouteToEmail_Email.Text);
            }

            #endregion

            #region Route To Host

            else if(action == RouteAction_enum.RouteToHost){
                //--- Validate values ------------------------------------------------//
                if(m_pRouteToHost_Host.Text == ""){
                    MessageBox.Show(this,"Host: value can't empty !","Error:",MessageBoxButtons.OK,MessageBoxIcon.Error);
                    return;
                }
                //--------------------------------------------------------------------//

                actionData = new RouteAction_RouteToHost(m_pRouteToHost_Host.Text,(int)m_pRouteToHost_Port.Value);
            }

            #endregion
            
            if(m_pRoute == null){
                m_pRoute = m_pVirtualServer.Routes.Add(
                    m_pDescription.Text,
                    m_pPattern.Text,
                    m_pEnabled.Checked,
                    actionData
                );
            }
            else{
                m_pRoute.Description = m_pDescription.Text;
                m_pRoute.Pattern = m_pPattern.Text;
                m_pRoute.Enabled = m_pEnabled.Checked;
                m_pRoute.Action = actionData;
                m_pRoute.Commit();
            }
            
            this.DialogResult = DialogResult.OK;
            this.Close();
        }