예제 #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
        //-------------------------------------------------------------------------

        public Program(string[] args)
        {
            // No args?
            if (args.Length == 0)
            {
                return;
            }

            // Specfied folder doesn't exist?
            if (Directory.Exists(args[0]) == false)
            {
                return;
            }

            // Significant builds only? Excludeds builds shorter than a certain time.
            bool significantBuildsOnly = false;

            if (args.Length > 1)
            {
                significantBuildsOnly = (args[1].ToLower() == "-s");
            }

            // Command line args for sql connection?
            string sqlServerName = null;
            string sqlDbName     = null;
            string sqlUsername   = null;
            string sqlPassword   = null;

            foreach (string a in args)
            {
                if (a.StartsWith("-server="))
                {
                    sqlServerName = a.Remove(0, "-server=".Length);
                }
                else if (a.StartsWith("-dbname="))
                {
                    sqlDbName = a.Remove(0, "-dbname=".Length);
                }
                else if (a.StartsWith("-user="******"-user="******"-password="******"-password="******"*.buildspy-prj-log",
                    SearchOption.TopDirectoryOnly);

            if (dbConnection == null)
            {
                ProcessFilesAndOutputSummary(files, significantBuildsOnly);
            }
            else
            {
                ProcessFilesAndImportIntoDb(files, dbConnection);
            }

            Console.WriteLine("Done.");
            //Console.ReadKey();
        }