Ejemplo n.º 1
0
        public static Rule GetRuleFromOss()
        {
            OssObject obj = null;
            try
            {
                obj = ossClient.GetObject(bucket, RuleFileHelper.Speed28RuleFile);
            }
            catch (Exception ex)
            {
            }
            string ruleStr = string.Empty;
            if (obj != null)
            {
                using (StreamReader sr = new StreamReader(obj.Content))
                {
                    ruleStr = sr.ReadToEnd();
                }
            }

            Rule rule = null;
            if (!string.IsNullOrEmpty(ruleStr))
            {
                string[] items = ruleStr.Split(new string[] { ":" }, StringSplitOptions.RemoveEmptyEntries);
                if (items != null && items.Length == 2)
                {
                    string[] valuesStr = items[1].Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries);
                    if (valuesStr.Length == Speed28.MaxLen)
                    {
                        int[] values = new int[Speed28.MaxLen];
                        for (int i = 0; i < Speed28.MaxLen; i++)
                        {
                            values[i] = int.Parse(valuesStr[i]);
                        }

                        rule = new Rule(items[0], values);
                    }
                }
            }

            return rule;
        }
Ejemplo n.º 2
0
        public static IList<Rule> GetRules()
        {
            IList<Rule> result = new List<Rule>();

            string rules = Rules;
            if (string.IsNullOrEmpty(rules))
            {
                return result;
            }

            string[] items = rules.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries);
            foreach (var item in items)
            {
                string[] r = item.Split(new char[] { ':' }, StringSplitOptions.RemoveEmptyEntries);
                if (r.Length == 2)
                {
                    string[] numStrs = r[1].Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
                    if (numStrs.Length != Speed28.MaxLen)
                    {
                        continue;
                    }

                    string name = r[0];
                    int[] values = new int[Speed28.MaxLen];
                    for (int i = 0; i < Speed28.MaxLen; i++)
                    {
                        values[i] = int.Parse(numStrs[i]);
                    }

                    Rule rule = new Rule(name, values);
                    result.Add(rule);
                }
            }
            return result;
        }