예제 #1
0
        //-------------------------------------------------------------------------

        void ProcessFilesAndImportIntoDb(
            string[] files,
            Db.DbConnection dbConnection)
        {
            SqlCommand sqlCmd = dbConnection.CreateCommand();

            sqlCmd.Parameters.Add("@filename", System.Data.SqlDbType.NVarChar);
            sqlCmd.Parameters.Add("@eventType", System.Data.SqlDbType.NVarChar);
            sqlCmd.Parameters.Add("@timestamp", System.Data.SqlDbType.SmallDateTime);
            sqlCmd.CommandText = "INSERT INTO ImportData VALUES ( @filename, @eventType, @timestamp )";

            foreach (string f in files)
            {
                try
                {
                    sqlCmd.Parameters["@filename"].Value =
                        Path.GetFileNameWithoutExtension(f);

                    // Parse the log file.
                    BuildLogFile log = new BuildLogFile(f);

                    string[] tags = log.GetTags();
                    IReadOnlyCollection <BuildLogFile.LogEntry> entries = log.GetEntries();

                    // Extract the project name.
                    string projectName = tags[1];

                    // Add log entries to collection.
                    foreach (BuildLogFile.LogEntry entry in entries)
                    {
                        sqlCmd.Parameters["@eventType"].Value =
                            (entry.EntryType == BuildLogFile.LogEntry.LogEntryType.BUILD_STARTED ?
                             "build.start" : "build.end");

                        sqlCmd.Parameters["@timestamp"].Value = entry.Timestamp;

                        sqlCmd.ExecuteScalar();
                    }
                }
                catch (Exception ex)
                {
                    // TODO
                }
            }
        }
예제 #2
0
        //-------------------------------------------------------------------------

        private void ProcessFilesAndOutputSummary(
            string[] files,
            bool significantBuildsOnly)
        {
            foreach (string f in files)
            {
                try
                {
                    // Parse the log file.
                    BuildLogFile log = new BuildLogFile(f);

                    string[] tags = log.GetTags();
                    IReadOnlyCollection <BuildLogFile.LogEntry> entries = log.GetEntries();

                    // Extract the project name.
                    string projectName = tags[1];

                    // Add log entries to collection.
                    foreach (BuildLogFile.LogEntry entry in entries)
                    {
                        if (LogEntriesByProject.ContainsKey(projectName) == false)
                        {
                            LogEntriesByProject.Add(projectName, new List <BuildLogFile.LogEntry>());
                        }

                        LogEntriesByProject[projectName].Add(entry);
                    }
                }
                catch (Exception)
                {
                    // TODO
                }
            }

            // Sort the entries.
            foreach (List <BuildLogFile.LogEntry> entries in LogEntriesByProject.Values)
            {
                entries.Sort();
            }

            // Create stats.
            foreach (string projectName in LogEntriesByProject.Keys)
            {
                Project project = Project.GetProject(projectName);

                List <BuildLogFile.LogEntry> entries = LogEntriesByProject[projectName];

                for (int i = 0; i < entries.Count - 1; i++)
                {
                    if (entries[i].EntryType == BuildLogFile.LogEntry.LogEntryType.BUILD_STARTED &&
                        entries[i + 1].EntryType == BuildLogFile.LogEntry.LogEntryType.BUILD_ENDED)
                    {
                        if (significantBuildsOnly == false ||
                            (entries[i + 1].Timestamp - entries[i].Timestamp).TotalSeconds > 5)
                        {
                            project.AddBuild(
                                entries[i].Timestamp,
                                entries[i + 1].Timestamp,
                                entries[i].Tags.ToArray());
                        }
                    }
                    else if (entries[i].EntryType == BuildLogFile.LogEntry.LogEntryType.BUILD_STARTED)
                    {
                        if (significantBuildsOnly == false)
                        {
                            project.AddBuild(
                                entries[i].Timestamp,
                                null,
                                entries[i].Tags.ToArray());
                        }
                    }
                }
            }

            foreach (Project prj in Project.GetProjects())
            {
                IBuildStatsProvider stats = prj.GetStats("All");

                Stats.Add(stats);
            }

            // Summary.
            foreach (BuildTag tag in BuildTag.GetTags())
            {
                OutputStats(tag);
            }
        }