private static void ReadStatistics(ProjectStatsData data, XmlReader xmlReader)
        {
            xmlReader.Read();

            int buildIdCounter = 0;

            while (xmlReader.NodeType != XmlNodeType.EndElement)
            {
                switch (xmlReader.Name)
                {
                case "timestamp":

                    xmlReader.Read();

                    break;

                case "integration":

                    ProjectStatsBuildEntry entry = new ProjectStatsBuildEntry(buildIdCounter++);
                    entry.BuildLabel = ReadAttribute(xmlReader, "build-label");

                    ReadIntegrationEntry(entry, ReadAttribute(xmlReader, "status"), xmlReader);

                    data.Builds.Add(entry);

                    break;

                default:
                    throw new NotSupportedException();
                }
            }

            xmlReader.Read();
        }
        public ProjectStatsGraphData(ProjectStatsData statsData)
        {
            // sort builds by their start times
            buildsSortedByStartTime = new SortedList <DateTime, ProjectStatsBuildEntry>();

            foreach (ProjectStatsBuildEntry build in statsData.Builds)
            {
                buildsSortedByStartTime.Add(build.BuildStartTime, build);
            }

            // now find out each build's order id
            foreach (ProjectStatsBuildEntry build in buildsSortedByStartTime.Values)
            {
                buildsToIntegers.Add(build.BuildId, buildsSortedByStartTime.IndexOfValue(build));
            }
        }
Esempio n. 3
0
        /// <summary>
        /// Execute tasks for drawing chart
        /// </summary>
        /// <param name="stopSignal">stop signal</param>
        public void ExecuteTask(WaitHandle stopSignal)
        {
            // get statistic data
            ProjectStatsData data = ccnetPlugIn.FetchStatistics();
            // sort statistics data by buildId
            ProjectStatsGraphData graphData = new ProjectStatsGraphData(data);

            // labels on X-Axis
            List <string>  xLabels             = new List <string>();
            IList <string> chartImageFileNames = new List <string>();

            // prepare necessary build statistic data and create graph
            foreach (ProjectStatsGraph graph in graphs)
            {
                // clear list of data
                graphData.ClearListOfData();
                // prepare list of data to be shown on graph
                PrepareDataMatrix(data, graph, graphData, xLabels);
                // draw graph
                chartImageFileNames.Add(DrawChart(graph, graphData, xLabels));
            }

            // translate storage locations to URLs
            for (int i = 0; i < chartImageFileNames.Count; i++)
            {
                string chartImageFileName = chartImageFileNames[i];
                Uri    url = fileManager.TranslateToUrl(chartImageFileName);
                chartImageFileNames[i] = url.ToString();
            }

            // generate wrapper HTML document
            // and save it to the project's storage location
            Hashtable templateContext = new Hashtable();

            templateContext.Add("project", projectId);
            templateContext.Add("reportImages", chartImageFileNames);
            templateEngine.ApplyTemplate(
                "CCNetReportStatistics.vm",
                templateContext,
                fileManager.GetProjectFullFileName(projectId, ModuleId, "CCNetReportStatistics.html", true));
        }
        public static ProjectStatsData Load(Stream stream)
        {
            ProjectStatsData data = new ProjectStatsData();

            XmlReaderSettings xmlReaderSettings = new XmlReaderSettings();

            xmlReaderSettings.IgnoreComments = true;
            xmlReaderSettings.IgnoreProcessingInstructions = true;
            xmlReaderSettings.IgnoreWhitespace             = true;

            using (XmlReader xmlReader = XmlReader.Create(stream, xmlReaderSettings))
            {
                xmlReader.Read();

                while (false == xmlReader.EOF)
                {
                    switch (xmlReader.NodeType)
                    {
                    case XmlNodeType.Element:
                        if (xmlReader.Name != "statistics")
                        {
                            throw new XmlException("<statistics> (root) element expected.");
                        }

                        ReadStatistics(data, xmlReader);

                        break;

                    case XmlNodeType.XmlDeclaration:
                        xmlReader.Read();
                        continue;

                    default:
                        throw new XmlException();
                    }
                }
            }

            return(data);
        }
Esempio n. 5
0
        private void PrepareDataMatrix(
            ProjectStatsData data,
            ProjectStatsGraph graph,
            ProjectStatsGraphData graphData,
            List <string> xLabels)
        {
            int buildId = 0;

            xLabels.Clear();

            // go through all builds
            for (int i = 0; i < data.Builds.Count; i++)
            {
                // show last 50 builds on graph if parameter is set to false
                if (!showBuildProjectHistory)
                {
                    if (i < data.Builds.Count - BuildNumbers)
                    {
                        continue;
                    }
                }

                ProjectStatsBuildEntry entry = data.Builds[i];

                // ignore unsuccessful builds
                if (graph.IgnoreFailures && entry.Parameters["Success"] == "0")
                {
                    continue;
                }

                // flag, that marks if parameter value will be added to the list or
                // value will increase existing value (depends on buildId)
                bool addValue = false;

                // if the current build label has not already been added to the xLabels
                if (entry.BuildLabel != xLabels.Find(temp => temp == entry.BuildLabel))
                {
                    // add build name to list. Build name will be shown on x-axis
                    xLabels.Add(entry.BuildLabel);

                    addValue = true;
                    buildId  = entry.BuildId;
                }

                // go through all graph parameters
                foreach (ProjectStatsGraphParameter parameter in graph.GraphParameters)
                {
                    double value = 0;

                    // if parameter exists in build statistic then get parameter value
                    if (entry.Parameters.ContainsKey(parameter.ParameterName))
                    {
                        if (parameter.ParameterType == typeof(TimeSpan))
                        {
                            value = TimeSpan.Parse(entry.Parameters[parameter.ParameterName]).TotalSeconds;
                        }
                        else if (parameter.ParameterType == typeof(double))
                        {
                            value = Convert.ToDouble(
                                entry.Parameters[parameter.ParameterName],
                                CultureInfo.InvariantCulture);
                        }
                    }

                    if (addValue)
                    {
                        // set value
                        graphData.SetValue(buildId, parameter.ParameterName, value);
                    }
                    else
                    {
                        // increment value
                        graphData.IncValue(buildId, parameter.ParameterName, value);
                    }
                }
            }
        }