Esempio n. 1
0
        static void Main(string[] args)
        {
            var project_file_etension_pattern = new Regex(@"\.csproj$", RegexOptions.Compiled);
            var package_file_pattern_text     = @"^{0}\.[0-9]+\.[0-9]+\.[0-9]+(\.[0-9]+)?\.nupkg$";
            CommandLineParameter parameter;

            try
            {
                parameter = new CommandLineParameter(args);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                return;
            }
            while (true)
            {
                SearchRepositoryDir(parameter.RepositoryDir, (repository_dir, repository_name) =>
                {
                    SearchProjectFile(repository_dir, project_file =>
                    {
                        //System.Diagnostics.Debug.WriteLine("walking '" + project_file.FullName + "'...");
                        if (!project_file.Name.StartsWith("Test."))
                        {
                            var nuspec_file = new FileInfo(project_file_etension_pattern.Replace(project_file.FullName, ".nuspec"));
                            if (!nuspec_file.Exists)
                            {
                                CreateNuspecFile(nuspec_file, repository_name, parameter.LicenseUrl);
                            }
                            try
                            {
                                string assembly_name;
                                string output_dir;
                                ParseProjectFile(project_file, out assembly_name, out output_dir);
                                var binary_file = new[] { assembly_name + ".exe", assembly_name + ".dll" }.Select(file_name => project_file.Directory.GetFile(output_dir, file_name)).Where(file => file.Exists == true).FirstOrDefault();
                                string package_id;
                                ParseNuspecFile(nuspec_file, variable_name =>
                                {
                                    switch (variable_name)
                                    {
                                    case "id":
                                        return(assembly_name);

                                    default:
                                        throw new ApplicationException();
                                    }
                                }, out package_id);
                                var package_file_pattern = new Regex(string.Format(package_file_pattern_text, package_id), RegexOptions.Compiled);
                                var package_file         = parameter.PackageDir.EnumerateFiles("*")
                                                           .Where(file => package_file_pattern.IsMatch(file.Name) == true)
                                                           .OrderByDescending(file => file.LastWriteTimeUtc)
                                                           .FirstOrDefault();
                                LogFileInfo("csproj file", project_file);
                                LogFileInfo(".nuspec file", nuspec_file);
                                LogFileInfo("binary file", binary_file);
                                LogFileInfo("package file", package_file);
                                if (binary_file != null && binary_file.Exists && (package_file == null || package_file.Exists == false || package_file.LastWriteTimeUtc < binary_file.LastWriteTimeUtc || package_file.LastWriteTimeUtc < nuspec_file.LastWriteTimeUtc))
                                {
                                    ExecuteNuget(parameter, project_file);
                                }
                            }
                            catch
                            {
                            }
                        }
                    });
                });
                Console.WriteLine("ENTERキーを押すと再実行します。");
                Console.ReadLine();
            }
        }