예제 #1
0
        /// <summary>
        /// Adds new user message rule to virtual server.
        /// </summary>
        /// <param name="enabled">Specifies if user message rules is enabled.</param>
        /// <param name="description">User message rule description.</param>
        /// <param name="matchExpression">Match expression.</param>
        /// <param name="checkNext">Specifies when next rule is checked.</param>
        /// <returns></returns>
        public UserMessageRule Add(bool enabled,string description,string matchExpression,GlobalMessageRule_CheckNextRule_enum checkNext)
        {
            /* AddUserMessageRule <virtualServerID> "<userID>" "<ruleID>" <cost> <enabled> "<description>" "<matchExpression>" <checkNext>
                  Responses:
                    +OK                     
                    -ERR <errorText>
            */
            
            string id   = Guid.NewGuid().ToString();
            long   cost = DateTime.Now.Ticks;

            // Call TCP AddUserMessageRule
            m_pUser.VirtualServer.Server.TcpClient.TcpStream.WriteLine("AddUserMessageRule " + 
                m_pUser.VirtualServer.VirtualServerID + " " + 
                TextUtils.QuoteString(m_pUser.UserID) + " " + 
                TextUtils.QuoteString(id) + " " + 
                cost + " " +
                enabled + " " +
                TextUtils.QuoteString(description) + " " + 
                TextUtils.QuoteString(matchExpression.TrimEnd()) + " " + 
                (int)checkNext
            );
                        
            string response = m_pUser.VirtualServer.Server.ReadLine();
            if(!response.ToUpper().StartsWith("+OK")){
                throw new Exception(response);
            }

            UserMessageRule rule = new UserMessageRule(this,id,cost,enabled,description,matchExpression,checkNext);
            m_pRules.Add(rule);
            return rule;
        }
 /// <summary>
 /// Default constructor.
 /// </summary>
 /// <param name="owner">Owner UserMessageRuleCollection collection that owns this rule.</param>
 /// <param name="id">Rule ID.</param>
 /// <param name="cost">Rule cost.</param>
 /// <param name="enabled">Specifies if rule is enabled.</param>
 /// <param name="description">Rule description text.</param>
 /// <param name="matchexpression">Rule match expression.</param>
 /// <param name="checkNext">Specifies when next rule is checked.</param>
 internal UserMessageRule(UserMessageRuleCollection owner,string id,long cost,bool enabled,string description,string matchexpression,GlobalMessageRule_CheckNextRule_enum checkNext)
 {
     m_pOwner          = owner;
     m_ID              = id;
     m_Cost            = cost;
     m_Enabled         = enabled;
     m_Description     = description;
     m_MatchExpression = matchexpression;
     m_CheckNext       = checkNext;
 }
예제 #3
0
 /// <summary>
 /// Default constructor.
 /// </summary>
 /// <param name="owner">Owner UserMessageRuleCollection collection that owns this rule.</param>
 /// <param name="id">Rule ID.</param>
 /// <param name="cost">Rule cost.</param>
 /// <param name="enabled">Specifies if rule is enabled.</param>
 /// <param name="description">Rule description text.</param>
 /// <param name="matchexpression">Rule match expression.</param>
 /// <param name="checkNext">Specifies when next rule is checked.</param>
 internal UserMessageRule(UserMessageRuleCollection owner, string id, long cost, bool enabled, string description, string matchexpression, GlobalMessageRule_CheckNextRule_enum checkNext)
 {
     m_pOwner          = owner;
     m_ID              = id;
     m_Cost            = cost;
     m_Enabled         = enabled;
     m_Description     = description;
     m_MatchExpression = matchexpression;
     m_CheckNext       = checkNext;
 }
        /// <summary>
        /// Adds new user message rule.
        /// </summary>
        /// <param name="userID">User who owns specified rule.</param>
        /// <param name="ruleID">Rule ID. Guid.NewID().ToString() is suggested.</param>
        /// <param name="cost">Cost specifies in what order rules are processed. Costs with lower values are processed first.</param>
        /// <param name="enabled">Specifies if rule is enabled.</param>
        /// <param name="checkNextRule">Specifies when next rule is checked.</param>
        /// <param name="description">Rule description.</param>
        /// <param name="matchExpression">Rule match expression.</param>
        public void AddUserMessageRule(string userID,string ruleID,long cost,bool enabled,GlobalMessageRule_CheckNextRule_enum checkNextRule,string description,string matchExpression)
        {
            if(userID == null || userID == ""){
                throw new Exception("Invalid userID value, userID can't be '' or null !");
            }
            if(ruleID == null || ruleID == ""){
                throw new Exception("Invalid ruleID value, ruleID can't be '' or null !");
            }

            using(WSqlCommand sqlCmd = new WSqlCommand(m_ConStr,"lspr_AddUserMessageRule")){
                sqlCmd.AddParameter("_userID"          ,NpgsqlDbType.Varchar,userID);
                sqlCmd.AddParameter("_ruleID"          ,NpgsqlDbType.Varchar,ruleID);
                sqlCmd.AddParameter("_cost"            ,NpgsqlDbType.Bigint  ,cost);
                sqlCmd.AddParameter("_enabled"         ,NpgsqlDbType.Boolean ,enabled);
                sqlCmd.AddParameter("_checkNextRule"   ,NpgsqlDbType.Integer ,checkNextRule);
                sqlCmd.AddParameter("_description"     ,NpgsqlDbType.Varchar,description);
                sqlCmd.AddParameter("_matchExpression" ,NpgsqlDbType.Bytea   ,System.Text.Encoding.Default.GetBytes(matchExpression));

                DataSet ds = sqlCmd.Execute();
            }
        }
예제 #5
0
파일: mssql_API.cs 프로젝트: dioptre/nkd
 public void UpdateGlobalMessageRule(string ruleID, long cost, bool enabled, GlobalMessageRule_CheckNextRule_enum checkNextRule, string description, string matchExpression)
 {
     if (ruleID == null || ruleID == "")
     {
         throw new Exception("Invalid ruleID value, ruleID can't be '' or null !");
     }
     this.m_UpdSync.BeginUpdate();
     try
     {
         if (!this.GlobalMessageRuleExists(ruleID))
         {
             throw new Exception("Invalid ruleID '" + ruleID + "', specified ruleID doesn't exist !");
         }
         foreach (DataRow dataRow in this.dsRules.Tables["GlobalMessageRules"].Rows)
         {
             if (dataRow["RuleID"].ToString().ToLower() == ruleID)
             {
                 dataRow["RuleID"] = ruleID;
                 dataRow["Cost"] = cost;
                 dataRow["Enabled"] = enabled;
                 dataRow["CheckNextRuleIf"] = (int)checkNextRule;
                 dataRow["Description"] = description;
                 dataRow["MatchExpression"] = matchExpression;
                 this.dsRules.WriteXml(this.m_DataPath + "GlobalMessageRules.xml", XmlWriteMode.IgnoreSchema);
                 break;
             }
         }
     }
     catch (Exception ex)
     {
         throw ex;
     }
     finally
     {
         this.m_UpdSync.EndUpdate();
     }
 }
예제 #6
0
파일: mssql_API.cs 프로젝트: dioptre/nkd
 public void AddGlobalMessageRule(string ruleID, long cost, bool enabled, GlobalMessageRule_CheckNextRule_enum checkNextRule, string description, string matchExpression)
 {
     if (ruleID == null || ruleID == "")
     {
         throw new Exception("Invalid ruleID value, ruleID can't be '' or null !");
     }
     this.m_UpdSync.BeginUpdate();
     try
     {
         if (this.GlobalMessageRuleExists(ruleID))
         {
             throw new Exception("Specified ruleID '" + ruleID + "' already exists, choose another ruleID !");
         }
         DataRow dataRow = this.dsRules.Tables["GlobalMessageRules"].NewRow();
         dataRow["RuleID"] = ruleID;
         dataRow["Cost"] = cost;
         dataRow["Enabled"] = enabled;
         dataRow["CheckNextRuleIf"] = (int)checkNextRule;
         dataRow["Description"] = description;
         dataRow["MatchExpression"] = matchExpression;
         this.dsRules.Tables["GlobalMessageRules"].Rows.Add(dataRow);
         this.dsRules.WriteXml(this.m_DataPath + "GlobalMessageRules.xml", XmlWriteMode.IgnoreSchema);
     }
     catch (Exception ex)
     {
         throw ex;
     }
     finally
     {
         this.m_UpdSync.EndUpdate();
     }
 }
예제 #7
0
파일: xml_API.cs 프로젝트: dioptre/nkd
		/// <summary>
        /// Updates specified user message rule.
        /// </summary>
        /// <param name="userID">User who owns specified rule.</param>
        /// <param name="ruleID">Rule ID.</param>
        /// <param name="cost">Cost specifies in what order rules are processed. Costs with lower values are processed first.</param>
        /// <param name="enabled">Specifies if rule is enabled.</param>
        /// <param name="checkNextRule">Specifies when next rule is checked.</param>
        /// <param name="description">Rule description.</param>
        /// <param name="matchExpression">Rule match expression.</param>
        public void UpdateUserMessageRule(string userID,string ruleID,long cost,bool enabled,GlobalMessageRule_CheckNextRule_enum checkNextRule,string description,string matchExpression)
        {
            if(userID == null || userID == ""){
                throw new Exception("Invalid userID value, userID can't be '' or null !");
            }
            if(ruleID == null || ruleID == ""){
                throw new Exception("Invalid ruleID value, ruleID can't be '' or null !");
            }

            m_UpdSync.BeginUpdate();

			try{
                // TODO: check match expression

                // Check that specified user exists
                if(!ContainsID(dsUsers.Tables["Users"],"UserID",userID)){
                    throw new Exception("User with specified id '" + userID + "' doesn't exist !");
                }

                // Check that specified rule exists
                if(!ContainsID(dsUserMessageRules.Tables["UserMessageRules"],"RuleID",ruleID)){
                    throw new Exception("Invalid ruleID '" + ruleID + "', specified ruleID doesn't exist !");
                }

                foreach(DataRow dr in dsUserMessageRules.Tables["UserMessageRules"].Rows){
                    if(dr["RuleID"].ToString().ToLower() == ruleID){
                        dr["UserID"]          = userID;
                        dr["RuleID"]          = ruleID;
					    dr["Cost"]            = cost;
					    dr["Enabled"]         = enabled;
					    dr["CheckNextRuleIf"] = (int)checkNextRule;
					    dr["Description"]     = description;
                        dr["MatchExpression"] = matchExpression;

                        dsUserMessageRules.WriteXml(m_DataPath + "UserMessageRules.xml",XmlWriteMode.IgnoreSchema);
                        break;
                    }
                }
			}
			catch(Exception x){
				throw x;
			}
			finally{
				m_UpdSync.EndUpdate();
			}
        }
예제 #8
0
        /// <summary>
        /// Adds new user message rule to virtual server.
        /// </summary>
        /// <param name="enabled">Specifies if user message rules is enabled.</param>
        /// <param name="description">User message rule description.</param>
        /// <param name="matchExpression">Match expression.</param>
        /// <param name="checkNext">Specifies when next rule is checked.</param>
        /// <returns></returns>
        public UserMessageRule Add(bool enabled, string description, string matchExpression, GlobalMessageRule_CheckNextRule_enum checkNext)
        {
            /* AddUserMessageRule <virtualServerID> "<userID>" "<ruleID>" <cost> <enabled> "<description>" "<matchExpression>" <checkNext>
             *    Responses:
             +OK
             *      -ERR <errorText>
             */

            string id   = Guid.NewGuid().ToString();
            long   cost = DateTime.Now.Ticks;

            // Call TCP AddUserMessageRule
            m_pUser.VirtualServer.Server.TcpClient.TcpStream.WriteLine("AddUserMessageRule " +
                                                                       m_pUser.VirtualServer.VirtualServerID + " " +
                                                                       TextUtils.QuoteString(m_pUser.UserID) + " " +
                                                                       TextUtils.QuoteString(id) + " " +
                                                                       cost + " " +
                                                                       enabled + " " +
                                                                       TextUtils.QuoteString(description) + " " +
                                                                       TextUtils.QuoteString(matchExpression.TrimEnd()) + " " +
                                                                       (int)checkNext
                                                                       );

            string response = m_pUser.VirtualServer.Server.ReadLine();

            if (!response.ToUpper().StartsWith("+OK"))
            {
                throw new Exception(response);
            }

            UserMessageRule rule = new UserMessageRule(this, id, cost, enabled, description, matchExpression, checkNext);

            m_pRules.Add(rule);
            return(rule);
        }
        /// <summary>
        /// Adds new user message rule.
        /// </summary>
        /// <param name="userID">User who owns specified rule.</param>
        /// <param name="ruleID">Rule ID. Guid.NewID().ToString() is suggested.</param>
        /// <param name="cost">Cost specifies in what order rules are processed. Costs with lower values are processed first.</param>
        /// <param name="enabled">Specifies if rule is enabled.</param>
        /// <param name="checkNextRule">Specifies when next rule is checked.</param>
        /// <param name="description">Rule description.</param>
        /// <param name="matchExpression">Rule match expression.</param>
        public void AddUserMessageRule(string userID,string ruleID,long cost,bool enabled,GlobalMessageRule_CheckNextRule_enum checkNextRule,string description,string matchExpression)
        {
            if(userID == null || userID == ""){
                throw new Exception("Invalid userID value, userID can't be '' or null !");
            }
            if(ruleID == null || ruleID == ""){
                throw new Exception("Invalid ruleID value, ruleID can't be '' or null !");
            }

            using(WSqlCommand sqlCmd = new WSqlCommand(m_ConStr,"lspr_AddUserMessageRule")){
                sqlCmd.AddParameter("@userID"          ,SqlDbType.NVarChar,userID);
                sqlCmd.AddParameter("@ruleID"          ,SqlDbType.NVarChar,ruleID);
                sqlCmd.AddParameter("@cost"            ,SqlDbType.BigInt  ,cost);
                sqlCmd.AddParameter("@enabled"         ,SqlDbType.Bit     ,enabled);
                sqlCmd.AddParameter("@checkNextRule"   ,SqlDbType.Int     ,checkNextRule);
                sqlCmd.AddParameter("@description"     ,SqlDbType.NVarChar,description);
                sqlCmd.AddParameter("@matchExpression" ,SqlDbType.Image   ,System.Text.Encoding.Default.GetBytes(matchExpression));

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

                if(ds.Tables["UserMessageRules"].Rows.Count > 0 && ds.Tables["UserMessageRules"].Rows[0]["ErrorText"].ToString().Length > 0){
                    throw new Exception(ds.Tables["UserMessageRules"].Rows[0]["ErrorText"].ToString());
                }
            }
        }