d0d53b9d47ff45db36c3cfaacbdce4b80b1cd47d
[teamcity/dotNetPackagesSupport.git] / nuget-extensions / nuget-runner / src / NuGetInstallExtensions.cs
1 using System;\r
2 using System.Collections.Generic;\r
3 using System.IO;\r
4 \r
5 namespace JetBrains.TeamCity.NuGetRunner\r
6 {\r
7   public class NuGetInstallExtensions\r
8   {\r
9     public NuGetInstallExtensions(NuGetRunner runner, IEnumerable<string> extensions)\r
10     {\r
11       Func<string> computeHome = () => Path.Combine(runner.NuGetExtensionsPath.Value, "TeamCity.Extensions");\r
12       runner.BeforeNuGetStarted += (_, __) =>\r
13                                      {\r
14                                        string home = computeHome();\r
15                                        if (!Directory.Exists(home))\r
16                                          Directory.CreateDirectory(home);\r
17 \r
18                                        foreach (var ext in extensions)\r
19                                        {\r
20                                          File.Copy(ext, Path.Combine(home, Path.GetFileName(ext)));\r
21                                        }\r
22                                      };\r
23 \r
24       runner.AfterNuGetFinished += (_, __) =>\r
25                                      {\r
26                                        string home = computeHome();\r
27                                        if (Directory.Exists(home))\r
28                                          Directory.Delete(home, true);\r
29                                      };\r
30     }\r
31   }\r
32 }