using System;
using System.Collections;
using System.Collections.Specialized;
using System.Data;
using System.Text;
using System.Web;
using System.Net;

using ms.aq.cview.util;

namespace ms.aq.cview.query {
    public class MDXFactoryException:Exception{
        public MDXFactoryException(string s):base(s) {}
    }
    public abstract class NitPick{
        public static bool IsMeasure(string uid) {
            return uid.IndexOf("[Measure]") > -1;
        }
        public static string GetHierarchy(string uid) {
            StringCollection tmp = common.UID2Tokens(uid);
            return tmp[0] + "." + tmp[1];
        }
        public static void DumpDimensionList(StringBuilder sb, ref StringCollection sc) {
            StringDictionary sd = NitPick.GroupByHierarchy(sc);
            int c = 0;
            sb.Append("{");
            foreach (string k in sd.Keys) {
                ++c;
                sb.Append("\t{" + sd[k] + "}");
                if (c < sd.Keys.Count)
                    sb.Append(",");
                sb.AppendLine();
            }
            sb.Append("}");
        }
        public static string Constrain(string uid,int cap) {
            return uid;// return "head(" + uid + "," + cap + ")";
            //DumpDimensionList(sb, ref sc);
            //sb.AppendLine(", " + cap + ")");
        }
        public static StringDictionary GroupByHierarchy(StringCollection uids) {
            StringDictionary rst = new StringDictionary();
            string h = null;
            foreach (string ss in uids) {
                h = GetHierarchy(ss);
                string s = Constrain(ss,100);
                if (rst.ContainsKey(h))
                    rst[h] = rst[h] + "," + s;
                else
                    rst.Add(h, s);
            }
            return rst;
        }
        public static StringDictionary GroupByHierarchy2(StringCollection uids) {
            StringDictionary rst = new StringDictionary();
            string h = null;
            foreach (string ss in uids) {
                h = GetHierarchy(ss);
                if (rst.ContainsKey(h))
                    rst[h] = rst[h] + " or " + ss;
                else
                    rst.Add(h, ss);
            }
            return rst;
        }
    }
}
