public static void addDimension(Dimension dimension)
 {
     XmlDocument doc = init(parametersFilePath);
     XmlNode node = doc.SelectSingleNode("/root/Dimensions");
     XmlDocument tempDoc = new XmlDocument();
     tempDoc.LoadXml(dimension.ToXml());
     XmlNode n = doc.ImportNode(tempDoc.FirstChild, true);
     node.AppendChild(n);
     doc.Save(parametersFilePath);
 }
 public static void removeDimension(Dimension dimension)
 {
     XmlDocument doc = init(parametersFilePath);
     XmlNode node = doc.SelectSingleNode("/root/Dimensions/Dimension[@name='"+ dimension.Name+"']");
     node.ParentNode.RemoveChild(node);
     doc.Save(parametersFilePath);
 }
        private static Query loadXmlQuery(Report report, string queryName)
        {
            XmlDocument doc = init(reportsFilePath);
            // Load metrics
            XmlNodeList xmlNodeList = doc.SelectNodes("/root/Reports/Report[@name='" + report + "']/Queries/Query[@name='"+ queryName + "']/Metrics/Metric");
            List<Metric> metrics = new List<Metric>();
            foreach (XmlNode metricNode in xmlNodeList)
            {
                string metricName = metricNode.Attributes["name"].Value;
                string metricTag = metricNode.Attributes["tag"].Value;
                Metric metric = new Metric(metricName, metricTag);
                metrics.Add(metric);
            }
            // Load dimensions
            xmlNodeList = doc.SelectNodes("/root/Reports/Report[@name='" + report + "']/Queries/Query[@name='" + queryName + "']/Dimensions/Dimension");
            List<Dimension> dimensions = new List<Dimension>();
            foreach (XmlNode dimensionNode in xmlNodeList)
            {
                string dimensionName = dimensionNode.Attributes["name"].Value;
                string dimensionTag = dimensionNode.Attributes["tag"].Value;
                Dimension dimension = new Dimension(dimensionName, dimensionTag);
                dimensions.Add(dimension);
            }

            xmlNodeList = doc.SelectNodes("/root/Reports/Report[@name='" + report + "']/Queries/Query[@name='" + queryName + "']/Filters/Filter");
            // Load filters
            List<Filter> filters = new List<Filter>();
            foreach (XmlNode filterNode in xmlNodeList)
            {
                String parameterTag = filterNode.Attributes["parameter"].Value;
                String expression = filterNode.InnerText;
                Operator op = Operator.GetOperator(filterNode.Attributes["operator"].Value);
                Parameter parameter = new Dimension("", parameterTag);
                Filter filter = new Filter(parameter, op, expression);
                filters.Add(filter);
            }
            XmlNode segmentNode = doc.SelectSingleNode("/root/Reports/Report[@name='" + report + "']/Queries/Query[@name='" + queryName + "']/Segment");
            String segmentName = segmentNode.Attributes["name"].Value;
            String semgentId = segmentNode.Attributes["id"].Value;
            AnaliticsAddIn.XML.Objects.ReportQuery.Filter.Segment segment = new AnaliticsAddIn.XML.Objects.ReportQuery.Filter.Segment(segmentName,semgentId);
            DateTime end = DateTime.Today;
            DateTime start = end;
            TimeUnit unit = report.Unit;
            return new Query(metrics, dimensions, filters, segment, unit, start, end, queryName);
        }
 public static List<Dimension> loadXmlDimensions()
 {
     XmlDocument doc = init(parametersFilePath);
     XmlNodeList xmlNodeList = doc.SelectNodes("/root/Dimensions/Dimension");
     List<Dimension> list = new List<Dimension>();
     foreach (XmlNode node in xmlNodeList)
     {
         string name = node.Attributes["name"].Value;
         String tag = node.Attributes["tag"].Value;
         Dimension dimension = new Dimension(name,tag);
         list.Add(dimension);
     }
     return list;
 }