NameValueCollectionRequest.cs :  » Build-Systems » CruiseControl.NET » ThoughtWorks » CruiseControl » WebDashboard » MVC » 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 » MVC » NameValueCollectionRequest.cs
using System;
using System.Collections.Specialized;

namespace ThoughtWorks.CruiseControl.WebDashboard.MVC{
  // ToDo - test!!
  public class NameValueCollectionRequest : IRequest
  {
    private readonly NameValueCollection parameters;
      private readonly NameValueCollection headers;
      private readonly string path;
    private readonly string rawUrl;
    private readonly string applicationPath;

    public NameValueCollectionRequest(NameValueCollection parameters, NameValueCollection headers, string path, string rawUrl, string applicationPath)
    {
      this.parameters = parameters;
        this.headers = headers;
        this.path = path;
      this.rawUrl = rawUrl;
      this.applicationPath = applicationPath;
    }

    public string FindParameterStartingWith(string prefix)
    {
      foreach (string key in parameters.Keys)
      {
        if (key.StartsWith(prefix))
        {
          return key;
        }
      }
      return string.Empty;
    }

    public string GetText(string id)
    {
      string text = parameters[id];
      if (text == null || text == string.Empty)
      {
        return string.Empty;
      }
      else
      {
        return text;
      }
    }

    public bool GetChecked(string id)
    {
      string value = GetText(id);
      return (value != null && value == "on");
    }

    public int GetInt(string id, int defaultValue)
    {
      // To Do - something more sensible
      string text = GetText(id);
      if (text != null && text != string.Empty)
      {
        try
        {
          return int.Parse(text);
        }
        catch (FormatException)
        {
          // Todo - exception?
          return defaultValue;
        }
      }
      else
      {
        return defaultValue;
      }
    }

      public string RawUrl
    {
      get { return rawUrl; }
    }

    public string FileNameWithoutExtension
    {
      get
      {
        int lastSlashIndex = path.LastIndexOf('/');
        if (lastSlashIndex == -1)
          lastSlashIndex = 0;

        int lastPeriod = path.LastIndexOf('.');
        if (lastPeriod == -1)
          lastPeriod = path.Length;

        return path.Substring(lastSlashIndex + 1, lastPeriod - lastSlashIndex - 1);
      }
    }

    public string[] SubFolders
    {
      get
      {
        string relativePath = path.Substring(applicationPath.Length + (applicationPath.EndsWith("/") ? 0 : 1));
        int lastSlashIndex = relativePath.LastIndexOf('/');
        if (lastSlashIndex < 0)
        {
          return new string[0];
        }

        return relativePath.Substring(0, lastSlashIndex).Split('/');
      }
    }

    public string ApplicationPath
    {
      get { return applicationPath; }
    }


      public string IfModifiedSince
      {
            get { return headers["If-Modified-Since"]; }
      }

      public string IfNoneMatch
      {
            get { return headers["If-None-Match"]; }
      }
  }
}
www.java2v.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.