Exemple #1
0
        /// <summary>
        /// Gets server groups and binds them to this.
        /// </summary>
        private void Bind()
        {
            /* GetRoutes <virtualServerID>
             *    Responses:
             +OK <sizeOfData>
             *      <data>
             *
             *      -ERR <errorText>
             */

            lock (m_pVirtualServer.Server.LockSynchronizer){
                // Call TCP GetRoutes
                m_pVirtualServer.Server.TcpClient.TcpStream.WriteLine("GetRoutes " + m_pVirtualServer.VirtualServerID);

                string response = m_pVirtualServer.Server.ReadLine();
                if (!response.ToUpper().StartsWith("+OK"))
                {
                    throw new Exception(response);
                }

                int          sizeOfData = Convert.ToInt32(response.Split(new char[] { ' ' }, 2)[1]);
                MemoryStream ms         = new MemoryStream();
                m_pVirtualServer.Server.TcpClient.TcpStream.ReadFixedCount(ms, sizeOfData);

                // Decompress dataset
                DataSet ds = Utils.DecompressDataSet(ms);

                if (ds.Tables.Contains("Routing"))
                {
                    foreach (DataRow dr in ds.Tables["Routing"].Rows)
                    {
                        RouteAction_enum actionType = (RouteAction_enum)Convert.ToInt32(dr["Action"]);
                        RouteActionBase  action     = null;
                        if (actionType == RouteAction_enum.RouteToEmail)
                        {
                            action = new RouteAction_RouteToEmail(Convert.FromBase64String(dr["ActionData"].ToString()));
                        }
                        else if (actionType == RouteAction_enum.RouteToHost)
                        {
                            action = new RouteAction_RouteToHost(Convert.FromBase64String(dr["ActionData"].ToString()));
                        }
                        else if (actionType == RouteAction_enum.RouteToMailbox)
                        {
                            action = new RouteAction_RouteToMailbox(Convert.FromBase64String(dr["ActionData"].ToString()));
                        }

                        m_pRoutes.Add(new Route(
                                          this,
                                          dr["RouteID"].ToString(),
                                          Convert.ToInt64(dr["Cost"]),
                                          dr["Description"].ToString(),
                                          dr["Pattern"].ToString(),
                                          Convert.ToBoolean(dr["Enabled"].ToString()),
                                          action
                                          ));
                    }
                }
            }
        }
        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();
        }
        /// <summary>
        /// Adds new route.
        /// </summary>
        /// <param name="routeID">Route ID.</param>
        /// <param name="cost">Cost specifies in what order roues are processed. Costs with lower values are processed first.</param>
        /// <param name="enabled">Specifies if route is enabled.</param>
        /// <param name="description">Route description text.</param>
        /// <param name="pattern">Match pattern. For example: *,*@domain.com,*[email protected].</param>
        /// <param name="action">Specifies route action.</param>
        /// <param name="actionData">Route action data.</param>
        public void AddRoute(string routeID,long cost,bool enabled,string description,string pattern,RouteAction_enum action,byte[] actionData)
        {
            if(routeID.Length == 0){
                throw new Exception("You must specify routeID");
            }
            if(pattern.Length == 0){
                throw new Exception("You must specify pattern");
            }

            using(WSqlCommand sqlCmd = new WSqlCommand(m_ConStr,"lspr_AddRoute")){
                sqlCmd.AddParameter("_routeID"     ,NpgsqlDbType.Varchar,routeID);
                sqlCmd.AddParameter("_cost"        ,NpgsqlDbType.Bigint ,cost);
                sqlCmd.AddParameter("_enabled"     ,NpgsqlDbType.Boolean,enabled);
                sqlCmd.AddParameter("_description" ,NpgsqlDbType.Varchar,description);
                sqlCmd.AddParameter("_pattern"     ,NpgsqlDbType.Varchar,pattern);
                sqlCmd.AddParameter("_action"      ,NpgsqlDbType.Integer,action);
                sqlCmd.AddParameter("_actionData"  ,NpgsqlDbType.Bytea  ,actionData);

                DataSet ds = sqlCmd.Execute();
            }
        }
Exemple #4
0
 public void UpdateRoute(string routeID, long cost, bool enabled, string description, string pattern, RouteAction_enum action, byte[] actionData)
 {
     if (pattern.Length == 0)
     {
         throw new Exception("You must specify pattern");
     }
     this.m_UpdSync.BeginUpdate();
     try
     {
         bool flag = false;
         foreach (DataRow dataRow in this.dsRouting.Tables["Routing"].Rows)
         {
             if (dataRow["RouteID"].ToString() == routeID)
             {
                 dataRow["Cost"] = cost;
                 dataRow["Enabled"] = enabled;
                 dataRow["Description"] = description;
                 dataRow["Pattern"] = pattern;
                 dataRow["Action"] = action;
                 dataRow["ActionData"] = actionData;
                 this.dsRouting.WriteXml(this.m_DataPath + "Routing.xml", XmlWriteMode.IgnoreSchema);
                 flag = true;
                 break;
             }
         }
         if (!flag)
         {
             throw new Exception("Route with specified ID '" + routeID + "' doesn't exist !");
         }
     }
     catch (Exception ex)
     {
         throw ex;
     }
     finally
     {
         this.m_UpdSync.EndUpdate();
     }
 }
Exemple #5
0
 public void AddRoute(string routeID, long cost, bool enabled, string description, string pattern, RouteAction_enum action, byte[] actionData)
 {
     if (routeID.Length == 0)
     {
         throw new Exception("You must specify routeID");
     }
     if (pattern.Length == 0)
     {
         throw new Exception("You must specify pattern");
     }
     this.m_UpdSync.BeginUpdate();
     try
     {
         if (this.ContainsID(this.dsRouting.Tables["Routing"], "RouteID", routeID))
         {
             throw new Exception("Route with specified ID '" + routeID + "' already exists !");
         }
         DataRow dataRow = this.dsRouting.Tables["Routing"].NewRow();
         dataRow["RouteID"] = routeID;
         dataRow["Cost"] = cost;
         dataRow["Enabled"] = enabled;
         dataRow["Description"] = description;
         dataRow["Pattern"] = pattern;
         dataRow["Action"] = action;
         dataRow["ActionData"] = actionData;
         this.dsRouting.Tables["Routing"].Rows.Add(dataRow);
         this.dsRouting.WriteXml(this.m_DataPath + "Routing.xml", XmlWriteMode.IgnoreSchema);
     }
     catch (Exception ex)
     {
         throw ex;
     }
     finally
     {
         this.m_UpdSync.EndUpdate();
     }
 }
Exemple #6
0
 /// <summary>
 /// Default constructor.
 /// </summary>
 /// <param name="actionType">Route action type.</param>
 internal RouteActionBase(RouteAction_enum actionType)
 {
     m_ActionType = actionType;
 }
        /// <summary>
        /// Adds new route.
        /// </summary>
        /// <param name="routeID">Route ID.</param>
        /// <param name="cost">Cost specifies in what order roues are processed. Costs with lower values are processed first.</param>
        /// <param name="enabled">Specifies if route is enabled.</param>
        /// <param name="description">Route description text.</param>
        /// <param name="pattern">Match pattern. For example: *,*@domain.com,*[email protected].</param>
        /// <param name="action">Specifies route action.</param>
        /// <param name="actionData">Route action data.</param>
        public void AddRoute(string routeID,long cost,bool enabled,string description,string pattern,RouteAction_enum action,byte[] actionData)
        {
            if(routeID.Length == 0){
                throw new Exception("You must specify routeID");
            }
            if(pattern.Length == 0){
                throw new Exception("You must specify pattern");
            }

            using(WSqlCommand sqlCmd = new WSqlCommand(m_ConStr,"lspr_AddRoute")){
                sqlCmd.AddParameter("@routeID"     ,SqlDbType.NVarChar,routeID);
                sqlCmd.AddParameter("@cost"        ,SqlDbType.BigInt  ,cost);
                sqlCmd.AddParameter("@enabled"     ,SqlDbType.Bit     ,enabled);
                sqlCmd.AddParameter("@description" ,SqlDbType.NVarChar,description);
                sqlCmd.AddParameter("@pattern"     ,SqlDbType.NVarChar,pattern);
                sqlCmd.AddParameter("@action"      ,SqlDbType.Int     ,action);
                sqlCmd.AddParameter("@actionData"  ,SqlDbType.Image   ,actionData);

                DataSet ds = sqlCmd.Execute();
                ds.Tables[0].TableName = "Routing";

                if(ds.Tables["Routing"].Rows.Count > 0 && ds.Tables["Routing"].Rows[0]["ErrorText"].ToString().Length > 0){
                    throw new Exception(ds.Tables["Routing"].Rows[0]["ErrorText"].ToString());
                }
            }
        }
Exemple #8
0
 /// <summary>
 /// Default constructor.
 /// </summary>
 /// <param name="actionType">Route action type.</param>
 internal RouteActionBase(RouteAction_enum actionType)
 {
     m_ActionType = actionType;
 }