예제 #1
0
        /// <summary>
        /// Retrieves the amount of free disk space.
        /// </summary>
        /// <param name="request"></param>
        /// <returns>The amount of free space in bytes.</returns>
        public DataResponse GetFreeDiskSpace(ServerRequest request)
        {
            string data = null;
            DataResponse response = new DataResponse(RunServerRequest(request,
                null,
                null,
                delegate
                {
                    //TODO: this is currently a hack
                    // this method sould return a collection of drives used by ccnet
                    // since each project can be hostet on a different drive.
                    // We should determine the drives used by a project
                    // (working, artefacs, SCM checkout, build publisher, etc)
                    // of each project and return a list of free disc space for every used drive.
                    var drive = ConfigurationManager.AppSettings["DataDrive"];
                    if (string.IsNullOrEmpty(drive))
                    {
                        if (System.IO.Path.DirectorySeparatorChar == '/')
                            drive = "/";
                        else
                            drive = "C:";
                    }

                    var fileSystem = new SystemIoFileSystem();
                    data = fileSystem.GetFreeDiskSpace(drive).ToString(CultureInfo.CurrentCulture);
                }));

            response.Data = data;
            return response;
        }
예제 #2
0
        /// <summary>
        /// Retrieves some summaries for the project.
        /// </summary>
        /// <param name="start">The first summary to retrieve. This starts from the last summary generated.</param>
        /// <param name="count">The number of summaries to retrieve.</param>
        /// <returns>
        /// The summaries.
        /// </returns>
        public IList<BuildSummary> GetSummaries(int start, int count)
        {
            var logDirectory = this.GetLogDirectory();
            if (string.IsNullOrEmpty(logDirectory))
            {
                return null;
            }

            try
            {
                count = count > 50 ? 50 : count;
                var summaries = new List<BuildSummary>();
                var fileSystem = new SystemIoFileSystem();
                var serialiser = new XmlSerializer(typeof(BuildSummary));
                Func<string, BuildSummary> loadSummary = f =>
                                                             {
                                                                 using (var stream = fileSystem.OpenInputStream(f))
                                                                 {
                                                                     var summary = serialiser.Deserialize(stream);
                                                                     return summary as BuildSummary;
                                                                 }
                                                             };
                var files = fileSystem.GetFilesInDirectory(logDirectory, "*.summary", SearchOption.TopDirectoryOnly);
                summaries.AddRange(
                    files.OrderByDescending(f => f).Skip(start).Take(count).Select(loadSummary));
                return summaries;
            }
            catch (DirectoryNotFoundException error)
            {
                throw new CruiseControlException("Log directory does not exist. This normally occurs because there are no builds for this project.", error);
            }
        }
예제 #3
0
        /// <summary>
        /// Integrates the specified request.	
        /// </summary>
        /// <param name="request">The request.</param>
        /// <returns></returns>
        /// <remarks></remarks>
        public IIntegrationResult Integrate(IntegrationRequest request)
        {
            Log.Trace("Integrating {0}", Name);
            IIntegrationResult result = null;

            lock (currentProjectStatus)
            {
                // Build up all the child items
                // Note: this will only build up the direct children, it doesn't handle below the initial layer
                currentProjectItems.Clear();
                sourceControlOperations.Clear();
                currentProjectStatus.Status = ItemBuildStatus.Running;
                currentProjectStatus.ChildItems.Clear();
                currentProjectStatus.TimeCompleted = null;
                currentProjectStatus.TimeOfEstimatedCompletion = null;
                currentProjectStatus.TimeStarted = DateTime.Now;
                GenerateSourceControlOperation(SourceControlOperation.CheckForModifications);
                GenerateTaskStatuses("Pre-build tasks", PrebuildTasks);
                GenerateSourceControlOperation(SourceControlOperation.GetSource);
                GenerateTaskStatuses("Build tasks", Tasks);
                GenerateTaskStatuses("Publisher tasks", Publishers);
            }

            // Start the integration
            IDisposable impersonation = null;
            var hasError = false;
            var timer = new Stopwatch();
            timer.Start();
            var summary = new BuildSummary
                              {
                                  StartTime = DateTime.Now
                              };
            var logDirectory = this.GetLogDirectory();
            var fileSystem = new SystemIoFileSystem();
            var serialiser = new XmlSerializer(typeof(BuildSummary));
            //Action<IIntegrationResult> writeSummary =
            //    r =>
            //    {
            //        var path = Path.ChangeExtension(Path.Combine(logDirectory, new LogFile(r).Filename), "summary");
            //        timer.Stop();
            //        summary.Duration = timer.ElapsedMilliseconds;
            //        summary.Status = r.Status;
            //        summary.LogName = new LogFile(r).Filename;
            //        fileSystem.EnsureFolderExists(path);
            //        using (var output = fileSystem.OpenOutputStream(path))
            //        {
            //            serialiser.Serialize(output, summary);
            //        }
            //    };
            try
            {
                if (Impersonation != null) impersonation = Impersonation.Impersonate();
                var dynamicSourceControl = sourceControl as IParamatisedItem;
                if (dynamicSourceControl != null)
                {
                    dynamicSourceControl.ApplyParameters(request.BuildValues, parameters);
                }
                result = integratable.Integrate(request);
                summary.Label = result.Label;
                //writeSummary(result);
                writeSummary(result, logDirectory, summary, timer, fileSystem, serialiser);
            }
            catch (Exception error)
            {
                //writeSummary(result);
                writeSummary(result, logDirectory, summary, timer, fileSystem, serialiser);
                Log.Error(error);
                hasError = true;
                throw;
            }
            finally
            {
                if (impersonation != null) impersonation.Dispose();

                // Tidy up the status
                lock (currentProjectStatus)
                {
                    CancelAllOutstandingItems(currentProjectStatus);
                    currentProjectStatus.TimeCompleted = DateTime.Now;
                    IntegrationStatus resultStatus = result == null ?
                        (hasError ? IntegrationStatus.Exception : IntegrationStatus.Unknown) :
                        result.Status;
                    switch (resultStatus)
                    {
                        case IntegrationStatus.Success:
                            currentProjectStatus.Status = ItemBuildStatus.CompletedSuccess;
                            break;
                        case IntegrationStatus.Unknown:
                            // This probably means the build was cancelled (i.e. no changes detected)
                            currentProjectStatus.Status = ItemBuildStatus.Cancelled;
                            break;
                        default:
                            currentProjectStatus.Status = ItemBuildStatus.CompletedFailed;
                            break;
                    }
                }
            }

            // Store the project status so it can be used by other parts of the system
            if (this.DataStore != null)
            {
                this.DataStore.StoreProjectSnapshot(result, this.GenerateSnapshot());
            }

            // Finally, return the actual result
            return result;
        }
예제 #4
0
        private void writeSummary(IIntegrationResult r, string logDir, BuildSummary summary, Stopwatch timer, SystemIoFileSystem fileSystem, XmlSerializer serialiser)
        {
            if (r == null) return;

            var path = Path.ChangeExtension(Path.Combine(logDir, new LogFile(r).Filename), "summary");
            timer.Stop();
            summary.Duration = timer.ElapsedMilliseconds;
            summary.Status = r.Status;
            summary.LogName = new LogFile(r).Filename;
            fileSystem.EnsureFolderExists(path);
            using (var output = fileSystem.OpenOutputStream(path))
            {
                serialiser.Serialize(output, summary);
            }
        }
        public void GetFilesInDirectoryIncludesSubDirectories()
        {
            var tempPath = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString());
            try
            {
                Directory.CreateDirectory(tempPath);
                var files = new[] 
                    {
                        Path.Combine(tempPath, "file1.txt"),
                        Path.Combine(tempPath, "file2.txt"),
                        Path.Combine(tempPath, "file3.txt")
                    };
                foreach (var file in files)
                {
                    File.WriteAllText(file, "Some data");
                }

                var subDir = Path.Combine(tempPath, "subDir");
                Directory.CreateDirectory(subDir);
                var subFile = Path.Combine(subDir, "file4.txt");
                File.WriteAllText(subFile, "Some data");

                var results = new SystemIoFileSystem().GetFilesInDirectory(tempPath, true);
                CollectionAssert.AreEqual(files.Concat(new[] { subFile}), results);
            }
            finally
            {
                // Clean up
                if (Directory.Exists(tempPath))
                {
                    Directory.Delete(tempPath, true);
                }
            }
        }