/// <summary>
        /// Initialises the extension.
        /// </summary>
        /// <param name="server">The server that this extension is for.</param>
        /// <param name="extensionConfig"></param>
        public virtual void Initialise(ICruiseServer server, ExtensionConfiguration extensionConfig)
        {
            if (server == null)
            {
                throw new ArgumentNullException("server");
            }
            else
            {
                server.IntegrationStarted += (o, e) =>
                {
                    // Check all the drives that they have sufficient space
                    var  fileSystem = server.RetrieveService(typeof(IFileSystem)) as IFileSystem ?? new SystemIoFileSystem();
                    bool hasSpace   = true;
                    foreach (var drive in driveSpaces.Keys)
                    {
                        var freeSpace = fileSystem.GetFreeDiskSpace(drive);
                        hasSpace &= (freeSpace >= driveSpaces[drive]);
                    }
                    e.Result = hasSpace ? IntegrationStartedEventArgs.EventResult.Continue
                        : IntegrationStartedEventArgs.EventResult.Cancel;
                    if (!hasSpace)
                    {
                        Log.Warning(string.Format(System.Globalization.CultureInfo.CurrentCulture, "Integration for '{0}' cancelled due to a lack of space.", e.ProjectName));
                    }
                };
            }

            foreach (var element in extensionConfig.Items ?? new XmlElement[0])
            {
                if (element.Name == "drive")
                {
                    if (element.SelectNodes("*").Count > 0)
                    {
                        throw new ArgumentException("Drive definitions cannot contain child elements");
                    }
                    AddDriveSpace(element.GetAttribute("name"), element.GetAttribute("unit"), element.InnerText);
                }
                else
                {
                    throw new ArgumentOutOfRangeException("Unknown configuration option: " + element.Name);
                }
            }

            if (driveSpaces.Count == 0)
            {
                throw new ArgumentOutOfRangeException("At least one drive must be defined to monitor");
            }
        }
        /// <summary>
        /// Initialises the extension.
        /// </summary>
        /// <param name="server">The server that this extension is for.</param>
        /// <param name="extensionConfig"></param>
        public virtual void Initialise(ICruiseServer server, ExtensionConfiguration extensionConfig)
        {
            if (server == null)
            {
                throw new ArgumentNullException("server");
            }
            else
            {
                server.IntegrationStarted += (o, e) =>
                {
                    // Check all the drives that they have sufficient space
                    var fileSystem = server.RetrieveService(typeof(IFileSystem)) as IFileSystem ?? new SystemIoFileSystem();
                    bool hasSpace = true;
                    foreach (var drive in driveSpaces.Keys)
                    {
                        var freeSpace = fileSystem.GetFreeDiskSpace(drive);
                        hasSpace &= (freeSpace >= driveSpaces[drive]);
                    }
                    e.Result = hasSpace ? IntegrationStartedEventArgs.EventResult.Continue 
                        : IntegrationStartedEventArgs.EventResult.Cancel;
                    if (!hasSpace)
                    {
                        Log.Warning(string.Format(System.Globalization.CultureInfo.CurrentCulture,"Integration for '{0}' cancelled due to a lack of space.", e.ProjectName));
                    }
                };
            }

            foreach (var element in extensionConfig.Items ?? new XmlElement[0])
            {
                if (element.Name == "drive")
                {
                    if (element.SelectNodes("*").Count > 0) throw new ArgumentException("Drive definitions cannot contain child elements");
                    AddDriveSpace(element.GetAttribute("name"), element.GetAttribute("unit"), element.InnerText);
                }
                else
                {
                    throw new ArgumentOutOfRangeException("Unknown configuration option: " + element.Name);
                }
            }

            if (driveSpaces.Count == 0)
            {
                throw new ArgumentOutOfRangeException("At least one drive must be defined to monitor");
            }
        }
示例#3
0
        public void SendMessageReceived(object obj, CancelProjectEventArgs <Message> message)
        {
            string        messageTxt    = message.Data.Text;
            CustomMessage customMessage = GetCustomMessage(messageTxt);

            if (customMessage != null)
            {
                var fileSystem = server.RetrieveService(typeof(IFileSystem)) as IFileSystem ??
                                 new SystemIoFileSystem();
                if (customMessage.Command == "ChangeBranch")
                {
                    ChangeBranch(fileSystem, customMessage.Branch, message.ProjectName);
                }
                if (customMessage.Command == "GetAllBranches")
                {
                    if (!string.IsNullOrEmpty(customMessage.Repo) &&
                        !string.IsNullOrEmpty(customMessage.WorkingDirectory) &&
                        !string.IsNullOrEmpty(customMessage.SourcecontrolType))
                    {
                        GetAllBranches(fileSystem, message.ProjectName, customMessage);
                    }
                }
            }
        }
示例#4
0
 /// <summary>
 /// Retrieves a service.
 /// </summary>
 /// <param name="serviceType">The type of service to retrieve.</param>
 /// <returns>A valid service, if found, null otherwise.</returns>
 public virtual object RetrieveService(Type serviceType)
 {
     return(server.RetrieveService(serviceType));
 }