コード例 #1
0
        static void CheckLog(string log_file, BuildInfo info)
        {
            DBRelease release = null;
            string    line, l;
            string    cmd;
            int       index;

            using (FileStream fs = new FileStream(log_file, FileMode.Open, FileAccess.Read, FileShare.ReadWrite)) {
                using (StreamReader reader = new StreamReader(fs)) {
                    List <String> files  = new List <string> ();
                    List <string> links  = new List <string> ();
                    List <bool>   hidden = new List <bool> ();

                    while (null != (l = reader.ReadLine()))
                    {
                        line = l;
                        if (line.StartsWith("@Moonbuilder:"))
                        {
                            line = line.Substring("@Moonbuilder:".Length);
                        }
                        else if (line.StartsWith("@MonkeyWrench:"))
                        {
                            line = line.Substring("@MonkeyWrench:".Length);
                        }
                        else
                        {
                            continue;
                        }

                        line = line.TrimStart(' ');

                        index = line.IndexOf(':');
                        if (index == -1)
                        {
                            continue;
                        }

                        cmd  = line.Substring(0, index);
                        line = line.Substring(index + 1);
                        while (line.StartsWith(" "))
                        {
                            line = line.Substring(1);
                        }

                        switch (cmd)
                        {
                        case "AddFile":
                        case "AddHiddenFile":
                            try {
                                Logger.Log("@MonkeyWrench command: '{0}' args: '{1}'", cmd, line);
                                files.Add(line.Trim());
                                hidden.Add(cmd.Contains("Hidden"));
                            } catch (Exception e) {
                                Logger.Log("Error while executing @MonkeyWrench command '{0}': '{1}'", cmd, e.Message);
                            }
                            break;

                        case "AddDirectory":
                        case "AddHiddenDirectory":
                            try {
                                Logger.Log("@MonkeyWrench command: '{0}' args: '{1}'", cmd, line);
                                foreach (string file in Directory.GetFiles(line.Trim()))
                                {
                                    files.Add(file);
                                    hidden.Add(cmd.Contains("Hidden"));
                                }
                            } catch (Exception e) {
                                Logger.Log("Error while executing @MonkeyWrench command '{0}': '{1}'", cmd, e.Message);
                            }
                            break;

                        case "AddFileLink":
                            try {
                                Logger.Log("@MonkeyWrench command: '{0}' args: '{1}'", cmd, line);
                                links.Add(line.Trim());
                            } catch (Exception e) {
                                Logger.Log("Error while executing @MonkeyWrench command '{0}': '{1}'", cmd, e.Message);
                            }
                            break;

                        case "SetSummary":
                            info.work.summary = line;
                            info.work         = WebService.ReportBuildStateSafe(info.work).Work;
                            break;

                        case "AddSummary":
                            info.work.summary += line;
                            info.work          = WebService.ReportBuildStateSafe(info.work).Work;
                            break;

                        case "SetReleaseVersion":
                            if (release == null)
                            {
                                release = new DBRelease();
                            }
                            release.version = line.Trim();
                            break;

                        case "SetReleaseRevision":
                            if (release == null)
                            {
                                release = new DBRelease();
                            }
                            release.revision = line.Trim();
                            break;

                        case "SetReleaseDescription":
                            if (release == null)
                            {
                                release = new DBRelease();
                            }
                            release.description = line.Trim();
                            break;

                        case "AddRelease":
                            if (release == null)
                            {
                                Logger.Log("Invalid @MonkeyWrench command: '{0}: No release created", cmd);
                                break;
                            }

                            WebServiceResponse rsp;

                            try {
                                release.filename = Path.GetFileName(line.Trim());
                                File.Copy(line.Trim(), Path.Combine(Configuration.GetReleaseDirectory(), release.filename), true);
                                rsp = WebService.AddRelease(WebService.WebServiceLogin, release);
                                if (rsp.Exception != null)
                                {
                                    Logger.Log("Error while adding release: {0}", rsp.Exception);
                                }
                            } catch (Exception ex) {
                                Logger.Log("Could not copy release: {0}", ex.ToString());
                            }
                            break;

                        default:
                            Logger.Log("Invalid @MonkeyWrench command: '{0}', entire line: '{1}'", cmd, l);
                            break;
                        }
                    }

                    if (links.Count > 0)
                    {
                        try {
                            WebService.UploadLinks(WebService.WebServiceLogin, info.work, links.ToArray());
                        } catch (Exception ex) {
                            Logger.Log("Could not upload links: {0}", ex);
                        }
                    }

                    WebService.UploadFilesSafe(info.work, files.ToArray(), hidden.ToArray());
                }
            }
        }