Пример #1
0
 private int CleanDirectories(DirectoryInfo Directory, DateTime RetainTime, List <DirectoryInfo> DirectoriesToDelete, int TargetDepth, int CurrentDepth = 0)
 {
     // Go deeper if we need to.
     if (TargetDepth > CurrentDepth)
     {
         int DirsFound = 0;
         foreach (DirectoryInfo SubDirectory in Directory.EnumerateDirectories())
         {
             DirsFound += CleanDirectories(SubDirectory, RetainTime, DirectoriesToDelete, TargetDepth, CurrentDepth + 1);
         }
         return(DirsFound);
     }
     else
     {
         CommandUtils.LogInformation("Scanning {0}...", Directory);
         IEnumerable <DirectoryInfo> DirsToScan = Directory.EnumerateDirectories();
         foreach (DirectoryInfo BuildDirectory in DirsToScan)
         {
             try
             {
                 if (!BuildDirectory.EnumerateFiles("*", SearchOption.AllDirectories).Any(x => x.LastWriteTimeUtc > RetainTime))
                 {
                     DirectoriesToDelete.Add(BuildDirectory);
                 }
             }
             catch (Exception Ex)
             {
                 CommandUtils.LogWarning("Unable to enumerate {0}: {1}", BuildDirectory.FullName, Ex.ToString());
             }
         }
         return(DirsToScan.Count());
     }
 }
        /// <summary>
        /// Entry point for the commandlet
        /// </summary>
        public override void ExecuteBuild()
        {
            string ReportDir = ParseParamValue("ReportDir", null);

            if (ReportDir == null)
            {
                throw new AutomationException("Missing -ReportDir parameter");
            }

            string Days = ParseParamValue("Days", null);

            if (Days == null)
            {
                throw new AutomationException("Missing -Days parameter");
            }

            double DaysValue;

            if (!Double.TryParse(Days, out DaysValue))
            {
                throw new AutomationException("'{0}' is not a valid value for the -Days parameter", Days);
            }

            DateTime RetainTime = DateTime.UtcNow - TimeSpan.FromDays(DaysValue);

            // Enumerate all the build directories
            CommandUtils.LogInformation("Scanning {0}...", ReportDir);
            int NumFolders = 0;
            List <DirectoryInfo> FoldersToDelete = new List <DirectoryInfo>();

            foreach (DirectoryInfo BuildDirectory in new DirectoryInfo(ReportDir).EnumerateDirectories())
            {
                if (!BuildDirectory.EnumerateFiles("*", SearchOption.AllDirectories).Any(x => x.LastWriteTimeUtc > RetainTime))
                {
                    FoldersToDelete.Add(BuildDirectory);
                }
                NumFolders++;
            }
            CommandUtils.LogInformation("Found {0} builds; {1} to delete.", NumFolders, FoldersToDelete.Count);

            // Delete them all
            for (int Idx = 0; Idx < FoldersToDelete.Count; Idx++)
            {
                try
                {
                    CommandUtils.LogInformation("[{0}/{1}] Deleting {2}...", Idx + 1, FoldersToDelete.Count, FoldersToDelete[Idx].FullName);
                    FoldersToDelete[Idx].Delete(true);
                }
                catch (Exception Ex)
                {
                    CommandUtils.LogWarning("Failed to delete folder; will try one file at a time: {0}", Ex);
                    CommandUtils.DeleteDirectory_NoExceptions(true, FoldersToDelete[Idx].FullName);
                }
            }
        }
Пример #3
0
        public void Execute()
        {
            if (ProjectDirectory == null)
            {
                throw new NullReferenceException("Project directory must be set.");
            }

            if (!ProjectDirectory.Exists)
            {
                throw new ArgumentException(string.Format("Project directory {0} does not exist.",
                                                          ProjectDirectory.FullName));
            }

            if (BuildDirectory == null)
            {
                throw new NullReferenceException("Build directory must be set.");
            }

            BuildDirectory.Refresh();
            if (!BuildDirectory.Exists)
            {
                throw new ArgumentException(string.Format("Build directory {0} does not exist.",
                                                          BuildDirectory.FullName));
            }

            if (Executable == null)
            {
                throw new NullReferenceException("Assembly executable must be set.");
            }

            if (!Executable.Exists)
            {
                throw new ArgumentException(string.Format("Assembly executable {0} does not exist.", Executable.FullName));
            }

            if (Target == null || Target.Trim().Length == 0)
            {
                throw new NullReferenceException("Target must be set.");
            }

            if (Type == null)
            {
                throw new Exception("Installation must be set.");
            }

            if (Type == InstallType.WebService)
            {
                TransformWebConfig();
            }
            else
            {
                TransformAppConfig();
            }

            if (Type == InstallType.ScheduledTask || Type == InstallType.SelfHostedService)
            {
                TransformTaskConfig();
            }

            TransformLog4NetConfig();

            Log.Info("Config file transormation complete.");
        }
 Test(BuildDirectory(_singleValues), AssertPresentInt32, AssertMissingInt32);
Пример #5
0
        public void Execute()
        {
            if (BuildDirectory == null)
            {
                throw new NullReferenceException("Build directory must be set.");
            }

            BuildDirectory.Refresh();
            if (!BuildDirectory.Exists)
            {
                throw new ArgumentException(string.Format("Build directory {0} does not exist.",
                                                          BuildDirectory.FullName));
            }

            if (Target == null || Target.Trim().Length == 0)
            {
                throw new NullReferenceException("Target must be set.");
            }

            if (Version == null)
            {
                throw new NullReferenceException("Version must be set.");
            }

            if (OutputDirectory == null)
            {
                throw new NullReferenceException("Output directory must be set.");
            }

            OutputDirectory.Refresh();
            if (!OutputDirectory.Exists)
            {
                OutputDirectory.Create();
            }

            var zipDir = BuildDirectory.FullName + "\\_PublishedWebsites\\" + ProjectName;

            if (!Directory.Exists(zipDir))
            {
                zipDir = BuildDirectory.FullName;
            }

            var paths = Directory.GetFiles(zipDir, "*.*", SearchOption.AllDirectories);

            if (paths.Length == 0)
            {
                Log.Warn(string.Format("No files found to zip in directory {0}. ", zipDir));
                return;
            }

            var taskItems = new ITaskItem[paths.Length];

            for (var i = 0; i < paths.Length; i++)
            {
                taskItems[i] = new TaskItem(paths[i]);
                Log.Info(string.Format("Compressing file: {0}.", paths[i]));
            }

            var zipFileName = string.Format("{0}\\{1}-{2}-{3}.zip", OutputDirectory.FullName, AssemblyName, Target,
                                            Version);
            var task = new Zip();

            task.TaskAction    = "Create";
            task.RemoveRoot    = new TaskItem(zipDir);
            task.CompressFiles = taskItems;
            task.ZipFileName   = new TaskItem(zipFileName);
            task.BuildEngine   = new FakeBuildEngine();
            task.Execute();

            ZipFile = new FileInfo(zipFileName);
            Log.Info(string.Format("Compression of directory {0} to zip file {1} complete.", zipDir, zipFileName));
        }
Пример #6
0
        void BuildInternal(buildCompleteAction onComplete)
        {
            Output = null;
            if (!BuildDirectory.Exists)
            {
                BuildDirectory.Create();
            }
            var outputPath = PathUtilities.AddSlash(BuildDirectory.FullName) + FileName;
            //Debug.Log("Build Output Path = " + outputPath);
            //Debug.Log("Build Directory = " + BuildDirectory.FullName);
            //Debug.Log("Filename = " + FileName);
            AssemblyBuilder builder = new AssemblyBuilder(outputPath, Scripts.ToArray());

            builder.additionalDefines    = Defines.ToArray();
            builder.additionalReferences = References.ToArray();
            builder.buildTarget          = Target;
            builder.buildTargetGroup     = TargetGroup;
            builder.excludeReferences    = VerifyPaths(ExcludedReferences);
            builder.flags = Flags;
            Action <string, CompilerMessage[]> buildCompleteAction = null;
            var outputInfo = new OutputDetails();

            outputInfo.OutputPath = outputPath;
            buildCompleteAction   = (dest, messages) =>
            {
                //Debug.Log("---------Dest = " + dest);
                outputInfo.CompilerMessages = messages;
                Building = false;
                if (messages.Any(cm => cm.type == CompilerMessageType.Error))
                {
                    Debug.LogError("Error building assembly = " + FileName);
                    string assemblyReferences = "References: " + Environment.NewLine;
                    foreach (var reference in References.Concat(GetDefaultReferences()))
                    {
                        assemblyReferences += reference + Environment.NewLine;
                    }
                    Debug.LogError(assemblyReferences);

                    string assemblyExclusions = "Exclusions: " + Environment.NewLine;
                    foreach (var exclusion in ExcludedReferences)
                    {
                        assemblyExclusions += exclusion + Environment.NewLine;
                    }
                    Debug.LogError(assemblyExclusions);
                    outputInfo.Success = false;
                    foreach (var message in messages)
                    {
                        if (message.type == CompilerMessageType.Error)
                        {
                            Debug.LogError(message.message);
                        }
                        else
                        {
                            //Debug.LogWarning(message.message);
                        }
                    }
                }
                else
                {
                    outputInfo.Success = true;
                }
                //Debug.Log("_____SUCCESS = " + outputInfo.Success);
                builder.buildFinished -= buildCompleteAction;
                Output = outputInfo;
                if (onComplete != null)
                {
                    onComplete(Output);
                }
            };
            Building = true;
            try
            {
                builder.buildFinished += buildCompleteAction;
                builder.Build();
            }
            catch (Exception)
            {
                builder.buildFinished -= buildCompleteAction;
                Building = false;
                throw;
            }
        }
Пример #7
0
        public static void Main(string[] args)
        {
            string failedTestDir       = augmentTestDir + @"FailedTests\";
            string submissionsDir      = augmentTestDir + @"SubmissionsUnderTest\";
            string metaProjectDir      = Path.GetFullPath(Path.Combine(augmentTestDir, @"..\editedMetaProject\"));
            string metaProgramFilePath = metaProjectDir + "MetaProgram.cs";
            string assemblyName        = "meta_project1525456207";
            //Put all Pex-generated tests into dictionary
            Dictionary <string, int> candidateTests = getAllFailingTestDirectories(failedTestDir);
            //Sort dictionary by value, descending order
            var sortedCandidates = from pair in candidateTests
                                   orderby pair.Value descending
                                   select pair;

            //Get full paths of all submissions under test
            string[] submissions = Directory.GetFiles(submissionsDir, ".cs", SearchOption.AllDirectories); //".cs" denotes file format


            foreach (var myCandidate in sortedCandidates)
            {
                //Replace candidate test method, starting w/ test that occured most frequently
                replaceCandidateTest(myCandidate);

                //Loop through each submission
                foreach (var submissionPath in submissions)
                {
                    //Replace student's submission in editedMetaProject
                    replaceStudentSubmission(submissionPath, metaProgramFilePath);
                    //Re-build editedMetaProject
                    if (BuildDirectory.BuildSingleProject(metaProjectDir, true))
                    {
                        //Below line ensures that TestAugmentor uses most updated ver. of editedMetaProject's asembly file
                        Pex4Fun.Program.copyOverAssemblyFile(metaProjectDir, currDir, assemblyName);

                        //Call candidateTest()
                        try
                        {
                            candidateTest();
                            Console.WriteLine("Submission did NOT fail this test!!");
                        }
                        catch (Exception e)
                        {
                            Console.WriteLine("Submission failed this test!! NICE! Had following exception:");
                            Console.WriteLine(e.ToString());

                            //TODO:
                            //Implement logic to increm #submissions failing the test and exclude them from next round
                        }
                    }
                }
            }

            /* Steps:
             * 1. Get dictionary of all candidate tests from files (DONE)
             * 1. Paste candidate check method into candidateTest() (DONE)
             * 2. Recompile editedMetaProject solution each time I replace (DONE)
             * 3.
             * 2. For loop:
             * a. Paste student submission into editedMetaProject's addToEnd() [DONE]
             * b. Call candidateTest() [DONE]
             * c. Increm #submissions failing the test and exclude them from next round (put in list)
             * 3. Print test to be added to test suite
             * Format:
             *  List list = new List(0);
             *  List copy = new List(0);
             *  for (int i = 0; i < times; i++)
             *  {
             *      addToEnd(copy, 0); //Instructor solution
             *      addToEnd(0); //Student submission
             *  }
             * Where 'times' = (last param. of Check method) + (#occurences of '*.value' b/t 's0.value' and 's0.next')
             */
        }
Пример #8
0
        public void Execute()
        {
            var sbsInstallHome = ConfigurationManager.AppSettings["SBS_INSTALL_HOME"];

            if (sbsInstallHome == null)
            {
                throw new NullReferenceException("The location of the SBSInstall.exe directory must be set in the config.");
            }

            if (BuildDirectory == null)
            {
                throw new NullReferenceException("Build directory must be set.");
            }

            BuildDirectory.Refresh();
            if (!BuildDirectory.Exists)
            {
                throw new ArgumentException(string.Format("Build directory {0} does not exist.",
                                                          BuildDirectory.FullName));
            }

            if (Target == null || Target.Trim().Length == 0)
            {
                throw new NullReferenceException("Target must be set.");
            }

            if (Version == null)
            {
                throw new NullReferenceException("Version must be set.");
            }

            if (Archive == null)
            {
                throw new NullReferenceException("Archive location must be set.");
            }

            if (Type == null)
            {
                throw new Exception("Installation must be set.");
            }

            if ((Type == InstallType.Service || Type == InstallType.WebService) &&
                string.IsNullOrEmpty(ServiceName))
            {
                throw new Exception("Sevice name must be specified for Service and WebService installations.");
            }

            var projectName = Path.GetFileNameWithoutExtension(ProjectFile.FullName);
            var zipDir      = BuildDirectory.FullName + "\\_PublishedWebsites\\" + projectName;

            if (!Directory.Exists(zipDir))
            {
                zipDir = BuildDirectory.FullName;
            }

            var paths = Directory.GetFiles(zipDir, "*.*", SearchOption.AllDirectories);

            if (paths.Length == 0)
            {
                Log.Warn(string.Format("No files found to zip in directory {0}. ", zipDir));
                return;
            }

            var zipFileName = string.Format("{0}\\Setup-{1}-{2}-{3}.zip", Archive.Uri, AssemblyName, Target, Version);

            var zip = new Zip();

            zip.ExeXmlConfig = ((SfxConfig)System.Configuration.ConfigurationManager.GetSection("SfxConfig")).ExeXmlConfig;
            zip.UnlockComponent("SHUTTEZIP_sYpChNabpHrd");
            zip.NewZip(zipFileName);

            zip.PathPrefix = "application/";
            zip.AppendFiles(zipDir, true);

            zip.PathPrefix = "installer/";
            zip.AppendFiles(sbsInstallHome, true);

            zip.AutoTemp = true;
            zip.AutoRun  = "installer/SBSInstaller.exe";
            var args = "-t {0} -a {1} -d application";

            if (!string.IsNullOrEmpty(ServiceName))
            {
                args += " -s \"{2}\"";
            }
            if (!string.IsNullOrEmpty(WebsiteName))
            {
                args += " -w \"{3}\"";
            }
            if (!string.IsNullOrEmpty(AppPoolName))
            {
                args += " -p \"{4}\"";
            }
            zip.AutoRunParams = string.Format(args, Type, AssemblyName, ServiceName, WebsiteName, AppPoolName);

            zip.ExeTitle = string.Format("Self Extracting Installation for {0} {1}", AssemblyName, Type);

            var fileName       = string.Format("Setup--{0}-{1}.exe", Target, Version);
            var zipExeFileName = Archive.Archive(zip, Target, fileName);

            ArchiveZipExeFile = zipExeFileName;

            Log.Info(string.Format("Compression of directory {0} to installation file {1} complete.", zipDir, zipExeFileName));
        }