示例#1
0
        /// <summary>
        /// Gets the type of a given defined variable
        /// </summary>
        /// <returns></returns>
        public string GetDefinedVariableType(string variableName)
        {
            foreach (IDashboardRule rule in this)
            {
                if (rule is DataAssignmentRule)
                {
                    DataAssignmentRule assignRule = rule as DataAssignmentRule;
                    return(assignRule.DestinationColumnType);
                }
            }

            throw new ApplicationException(string.Format(SharedStrings.DASHBOARD_ERROR_DEFINED_VARIABLE_MISSING, variableName));
        }
示例#2
0
        /// <summary>
        /// Gets the number of assignments for a given column
        /// </summary>
        /// <returns>Int; represents the number of variables dependent on the variable passed in as a parameter</returns>
        public int GetColumnAssignmentCount(string friendlyRule)
        {
            IDashboardRule rule = GetRule(friendlyRule);

            if (rule is DataAssignmentRule)
            {
                DataAssignmentRule assignRule = rule as DataAssignmentRule;
                return(GetRules(assignRule.DestinationColumnName).Count);
            }
            else
            {
                return(-1);
            }
        }
示例#3
0
        /// <summary>
        /// Gets a dictionary of all user-defined variables in this rule set
        /// </summary>
        /// <returns>Dictionary of user-defined variables</returns>
        public Dictionary <string, string> GetUserDefinedVariables()
        {
            Dictionary <string, string> userDefinedVariableNames = new Dictionary <string, string>();

            foreach (IDashboardRule rule in this)
            {
                if (rule is DataAssignmentRule)
                {
                    DataAssignmentRule assignRule = rule as DataAssignmentRule;
                    userDefinedVariableNames.Add(assignRule.DestinationColumnName, assignRule.DestinationColumnType);
                }
            }

            return(userDefinedVariableNames);
        }
示例#4
0
        /// <summary>
        /// Adds a new rule to the set of dashboard rules
        /// </summary>
        /// <param name="rule">The rule to add</param>
        /// <returns>Boolean; whether the addition was successful</returns>
        public bool AddRule(IDashboardRule rule)
        {
            #region Input Validation
            if (rule == null || string.IsNullOrEmpty(rule.FriendlyRule))
            {
                throw new ArgumentNullException("rule");
            }
            #endregion // Input Validation

            // check for duplicate rules
            foreach (DataRow row in RuleTable.Rows)
            {
                IDashboardRule rRule = (IDashboardRule)row[COLUMN_RULE];

                if (rRule.FriendlyRule.Equals(rule.FriendlyRule))
                {
                    // cannot add a duplicate rule, so return false
                    return(false);
                }
            }

            // find the highest run order value of all the rules presently in the table
            int maxInt = int.MinValue;

            foreach (DataRow row in RuleTable.Rows)
            {
                int value = row.Field <int>(COLUMN_RUN_ORDER);
                maxInt = Math.Max(maxInt, value);
            }

            RuleTable.Rows.Add(maxInt + 1, rule);

            // sort by run order
            this.ruleTable = RuleTable.Select("", COLUMN_RUN_ORDER).CopyToDataTable().DefaultView.ToTable("RuleTable");

            if (rule is DataAssignmentRule)
            {
                DataAssignmentRule assignRule = rule as DataAssignmentRule;
                if (!dashboardHelper.TableColumnNames.ContainsKey(assignRule.DestinationColumnName))
                {
                    dashboardHelper.TableColumnNames.Add(assignRule.DestinationColumnName, assignRule.DestinationColumnType);
                }
            }

            return(true);
        }
示例#5
0
        /// <summary>
        /// Gets the dependencies for a particular defined variable
        /// </summary>
        /// <returns>Int; represents the number of variables dependent on the variable passed in as a parameter</returns>
        public List <VariableDependency> GetDependencyList(string friendlyRule)
        {
            IDashboardRule            rule         = GetRule(friendlyRule);
            List <VariableDependency> dependencies = new List <VariableDependency>();

            if (rule is DataAssignmentRule)
            {
                // the one we're checking on for dependencies
                DataAssignmentRule assignRule = rule as DataAssignmentRule;

                for (int i = 0; i < RuleTable.Rows.Count; i++)
                {
                    DataRow        row   = RuleTable.Rows[i];
                    IDashboardRule iRule = ((IDashboardRule)row[COLUMN_RULE]);

                    if (rule is DataAssignmentRule && rule.FriendlyRule != friendlyRule)
                    {
                        // a variable in the list, being checked to see if it's being depended on
                        //DataAssignmentRule iAssignRule = rule as DataAssignmentRule;

                        //VariableDependency vd = new VariableDependency();
                        //vd.VariableName = iAssignRule.DestinationColumnName;

                        //if (iAssignRule is Rule_Recode)
                        //{
                        //    Rule_Recode iRecodeRule = iAssignRule as Rule_Recode;
                        //    if(iRecodeRule.SourceColumnName
                        //}


                        //if (assignRule.DestinationColumnName.ToLower().Equals(destinationColumnName.ToLower()))
                        //{
                        //    rules.Add(assignRule);
                        //}
                    }
                }
            }

            return(dependencies);
        }
示例#6
0
        /// <summary>
        /// Returns all user-defined variables with the given destination column
        /// </summary>
        /// <param name="destinationColumnName">The destination column name</param>
        /// <returns>Rule</returns>
        public List <IDashboardRule> GetRules(string destinationColumnName)
        {
            int     i;
            DataRow row = null;
            List <IDashboardRule> rules = new List <IDashboardRule>();

            for (i = 0; i < RuleTable.Rows.Count; i++)
            {
                row = RuleTable.Rows[i];
                IDashboardRule rule = ((IDashboardRule)row[COLUMN_RULE]);
                if (rule is DataAssignmentRule)
                {
                    DataAssignmentRule assignRule = rule as DataAssignmentRule;
                    if (assignRule.DestinationColumnName.ToLower().Equals(destinationColumnName.ToLower()))
                    {
                        rules.Add(assignRule);
                    }
                }
            }

            return(rules);
        }
示例#7
0
        /// <summary>
        /// Removes a rule
        /// </summary>
        /// <returns>Bool</returns>
        public bool RemoveRule(string friendlyRule)
        {
            int     i;
            int     rowIndexToRemove = -1;
            DataRow row = null;

            for (i = 0; i < RuleTable.Rows.Count; i++)
            {
                row = RuleTable.Rows[i];
                string str = row[COLUMN_RULE].ToString();

                if (str.Equals(friendlyRule))
                {
                    rowIndexToRemove = i;
                    break;
                }
            }

            if (rowIndexToRemove >= 0)
            {
                row = RuleTable.Rows[rowIndexToRemove];

                IDashboardRule rule = ((IDashboardRule)row[COLUMN_RULE]);

                if (rule is DataAssignmentRule && this.GetColumnAssignmentCount(rule.FriendlyRule) == 1)
                {
                    DataAssignmentRule assignRule = rule as DataAssignmentRule;
                    if (dashboardHelper.TableColumnNames.ContainsKey(assignRule.DestinationColumnName))
                    {
                        dashboardHelper.TableColumnNames.Remove(assignRule.DestinationColumnName);
                    }
                }

                RuleTable.Rows.Remove(row);
                return(true);
            }
            return(false);
        }