ServerInformationServerPlugin.cs :  » Build-Systems » CruiseControl.NET » ThoughtWorks » CruiseControl » WebDashboard » Plugins » ServerReport » C# / CSharp Open Source

Home
C# / CSharp Open Source
1.2.6.4 mono .net core
2.2.6.4 mono core
3.Aspect Oriented Frameworks
4.Bloggers
5.Build Systems
6.Business Application
7.Charting Reporting Tools
8.Chat Servers
9.Code Coverage Tools
10.Content Management Systems CMS
11.CRM ERP
12.Database
13.Development
14.Email
15.Forum
16.Game
17.GIS
18.GUI
19.IDEs
20.Installers Generators
21.Inversion of Control Dependency Injection
22.Issue Tracking
23.Logging Tools
24.Message
25.Mobile
26.Network Clients
27.Network Servers
28.Office
29.PDF
30.Persistence Frameworks
31.Portals
32.Profilers
33.Project Management
34.RSS RDF
35.Rule Engines
36.Script
37.Search Engines
38.Sound Audio
39.Source Control
40.SQL Clients
41.Template Engines
42.Testing
43.UML
44.Web Frameworks
45.Web Service
46.Web Testing
47.Wiki Engines
48.Windows Presentation Foundation
49.Workflows
50.XML Parsers
C# / C Sharp
C# / C Sharp by API
C# / CSharp Tutorial
C# / CSharp Open Source » Build Systems » CruiseControl.NET 
CruiseControl.NET » ThoughtWorks » CruiseControl » WebDashboard » Plugins » ServerReport » ServerInformationServerPlugin.cs
using System.Collections;
using Exortech.NetReflector;
using ThoughtWorks.CruiseControl.WebDashboard.Dashboard;
using ThoughtWorks.CruiseControl.WebDashboard.IO;
using ThoughtWorks.CruiseControl.WebDashboard.MVC;
using ThoughtWorks.CruiseControl.WebDashboard.MVC.Cruise;
using ThoughtWorks.CruiseControl.WebDashboard.MVC.View;
using ThoughtWorks.CruiseControl.WebDashboard.ServerConnection;

namespace ThoughtWorks.CruiseControl.WebDashboard.Plugins.ServerReport{
    /// <title>Server Information Server Plugin</title>
    /// <version>1.4.4</version>
    /// <summary>
    /// The Server Information Server Plugin gives you information about a build server, for example the version of CruiseControl.NET the build
    /// server is running.
    /// </summary>
    /// <example>
    /// <code title="Minimalist example">
    /// &lt;serverInformationServerPlugin /&gt;
    /// </code>
    /// <code title="Full example">
    /// &lt;serverInformationServerPlugin minFreeSpace="524288" /&gt;
    /// </code>
    /// </example>
    [ReflectorType("serverInformationServerPlugin")]
  public class ServerInformationServerPlugin : ICruiseAction, IPlugin
  {
    private readonly IFarmService farmService;
    private readonly IVelocityViewGenerator viewGenerator;
    private long minFreeSpace = 1048576;

    public ServerInformationServerPlugin(IFarmService farmService, IVelocityViewGenerator viewGenerator)
    {
      this.farmService = farmService;
      this.viewGenerator = viewGenerator;
    }

        /// <summary>
        /// The minimum required amount of free disk space in bytes. If the free disk space is less than this a warning will be displayed.
        /// </summary>
        /// <version>1.4.4</version>
        /// <default>1048576</default>
        [ReflectorProperty("minFreeSpace", Required = false)]
    public long MinFreeSpace
        {
      get { return minFreeSpace; }
      set { minFreeSpace = value; }
        }

    public IResponse Execute(ICruiseRequest request)
    {
      Hashtable velocityContext = new Hashtable();
      
      velocityContext["serverversion"] = farmService.GetServerVersion(request.ServerSpecifier);
      velocityContext["servername"] = request.ServerSpecifier.ServerName;
            long freeSpace = farmService.GetFreeDiskSpace(request.ServerSpecifier);
            velocityContext["serverSpace"] = FormatSpace(freeSpace);
      velocityContext["spaceMessage"] = minFreeSpace > freeSpace ?
                "WARNING: Disk space is running low!" :
                string.Empty;
      
      return viewGenerator.GenerateView(@"ServerInfo.vm", velocityContext);
    }

    public string LinkDescription
    {
      get { return "View Server Info"; }
    }

    public INamedAction[] NamedActions
    {
      get {  return new INamedAction[] { new ImmutableNamedAction("ViewServerInfo", this) }; }
    }

        private string FormatSpace(long space)
        {
            string formated;
            double value = space;

            if (space > 1073741824)
            {
                value /= 1073741824;
                formated = string.Format("{0:#,##0.00} Gb", value);
            }
            else if (space > 1048576)
            {
                value /= 1048576;
                formated = string.Format("{0:#,##0.00} Mb", value);
            }
            else if (space > 1024)
            {
                value /= 1024;
                formated = string.Format("{0:#,##0.00} Kb", value);
            }
            else
            {
                formated = string.Format("{0:#,##0} b", space);
            }

            return formated;
        }

  }
}
www.java2v.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.