Beispiel #1
0
        public void Run()
        {
            string RepoPath = WeavverUnitContext.RepoPath;
               Repository xx = new Repository(RepoPath);

               string localRev = xx.Head.Tip.Id.ToString().Substring(0, 7);
               string buildLabel = "Build " + DateTime.Now.ToString("MM.dd.yy") + " GIT " + localRev.ToString();

               #region Add WWW folder
               string tempFolder = Path.Combine(Path.GetTempPath(), "WeavverBuild");
               if (Directory.Exists(tempFolder))
                    Directory.Delete(tempFolder, true);
               Directory.CreateDirectory(tempFolder);

               Weavver.Utilities.Common.CopyFolder(Path.Combine(RepoPath, "www"), Path.Combine(tempFolder, "www"));

               string releaseConfig = Path.Combine(tempFolder, @"www\web-default.config");
               Weavver.Utilities.Common.SetConfigSetting(releaseConfig, "version", buildLabel);
               Weavver.Utilities.Common.SetConfigSetting(releaseConfig, "install_mode", "true");

               string repoConfig = Path.Combine(RepoPath, @"www\web.config");
               Weavver.Utilities.Common.SetConfigSetting(repoConfig, "version", buildLabel);

               string webconfigPath = Path.Combine(tempFolder, "www/web.config");
               if (File.Exists(webconfigPath))
                    File.Delete(webconfigPath);
               string aspnetFolder = Path.Combine(tempFolder, "www/aspnet_client/");
               if (Directory.Exists(aspnetFolder))
                    Directory.Delete(aspnetFolder, true);

               string binPath = Path.Combine(tempFolder, "www", "Bin");
               string[] binConfigFiles = Directory.GetFiles(binPath, "*.config");
               foreach (string binConfigFile in binConfigFiles)
               {
                    if (File.Exists(binConfigFile))
                         File.Delete(binConfigFile);
               }

               string uploadFolder = Path.Combine(tempFolder, "www", "Uploads");
               Directory.Delete(uploadFolder, true);

               string swFolder = Path.Combine(tempFolder, "www", "Bin", "SnapWeavver.dll");
               File.Delete(swFolder);

               //string appBase = @"C:\Weavver\Main\Projects\App\bin\x86\Release\";
               //File.Copy(appBase + @"Weavver.exe", Path.Combine(tempFolder, "Weavver.exe"));
               //File.Copy(appBase + @"CassiniDev4-lib.dll", Path.Combine(tempFolder, "CassiniDev4-lib.dll"));
               //File.Copy(appBase + @"Weavver.exe.config", Path.Combine(tempFolder, "Weavver.exe.config"));
               #endregion

               #region Add DB Files
               string dataPath = Path.Combine(new DirectoryInfo(RepoPath).Parent.FullName, "data");
               File.Copy(
                    Path.Combine(dataPath, @"database\bin\Release\Weavver.DAL.dll"),
                    Path.Combine(tempFolder, @"www\bin\Weavver.DAL.dll"),
                    true
                    );
               // Copy it again for running IIS straight off of the github repo folder "www"
               File.Copy(
                    Path.Combine(dataPath, @"database\bin\Release\Weavver.DAL.dll"),
                    Path.Combine(RepoPath, @"www\bin\Weavver.DAL.dll"),
                    true
                    );
               using (WeavverEntityContainer db = new WeavverEntityContainer())
               {
                    string createScript = db.CreateDatabaseScript() + "\r\n";
                    createScript += File.ReadAllText(Path.Combine(dataPath, @"database\aspnet_regsql.sql")) + "\r\n";
                    createScript += File.ReadAllText(Path.Combine(dataPath, @"database\Database.sql")) + "\r\n";
                    DirectoryInfo fkScripts = new DirectoryInfo(Path.Combine(dataPath, @"database\ForeignKeys\"));
                    foreach (FileInfo file in fkScripts.GetFiles("*.sql"))
                    {
                         string fkScript = File.ReadAllText(file.FullName);
                         string[] x = Regex.Split(fkScript, "\n");
                         foreach (string y in x)
                         {
                              if (y.Contains("NOCHECK CONSTRAINT"))
                              {
                                   createScript += y + "\r\n";
                              }
                         }
                    }

                    string databaseSqlPath = Path.Combine(tempFolder, @"www\bin\Database.sql");
                    File.WriteAllText(databaseSqlPath, createScript);

                    // Write it again for running IIS straight off of the github repo folder "www"
                    File.WriteAllText(Path.Combine(RepoPath, @"www\bin\Database.sql"), createScript);
               }
               #endregion

               File.Copy(Path.Combine(RepoPath, @"units\build\Readme.txt"), Path.Combine(tempFolder, "Readme.txt"));

               string distDir = Path.Combine(RepoPath, "dist");
               if (!Directory.Exists(distDir))
                    Directory.CreateDirectory(distDir);

               string zipPath = Path.Combine(distDir, "Weavver-" + buildLabel.Replace(" ", "-") + ".zip");
               if (File.Exists(zipPath))
                    File.Delete(zipPath);

               Process p = new Process();
               p.StartInfo.WorkingDirectory = tempFolder;
               p.StartInfo.FileName = Path.Combine(RepoPath, @"vendors\7-Zip\7z.exe");
               p.StartInfo.Arguments = "a " + zipPath + " " + tempFolder + "\\*";
               p.Start();
               p.WaitForExit();

               Assert.Equals(p.ExitCode, 0);

               //Ionic.Zip.ZipFile weavverZip = new ZipFile();
               //weavverZip.AddDirectory(tempFolder);
               //weavverZip.Save(zipPath);
        }