Getting Started

Preflight ships with a few samples covering different scenarios, be sure to check the download section for samples package.

Basic Steps

  1. Determine what dependencies you have that you want to check for
  2. If one of your verifications is not covered by a built-in verification then you will have create one
  3. Create a verification factory
  4. Configure your application so that your factory can be plugged into Preflight

 

Sample Web Application

In this example, we’re going to add Preflight to an ASP.NET MVC 4 application. This application has the following dependencies:

  1. SQL Server Database
  2. External web service
  3. X509 Certificate on host machine

 

Verification Factory

In this sample factory, we’re using the verifications built into Preflight to create the 3 dependency check we need for our sample application:

   1:  //--------------------------------------------------------------------------------------------------------------
   2:  // Copyright 2012 Microsoft Corporation. All Rights Reserved
   3:  // Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License.   
   4:  // You may obtain a copy of the License at
   5:  // http://www.apache.org/licenses/LICENSE-2.0
   6:  // Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
   7:  //--------------------------------------------------------------------------------------------------------------
   8:   
   9:  namespace TestScenarios
  10:  {
  11:      using System.Collections.Generic;
  12:      using System.Configuration;
  13:      using System.Security.Cryptography.X509Certificates;
  14:      using Preflight;
  15:      using Preflight.Model;
  16:      using Preflight.Verifications;
  17:   
  18:      public class SampleVerificationFactory : IVerificationFactory
  19:      {
  20:          public ApplicationDescription ApplicationDescription
  21:          {
  22:              get
  23:              {
  24:                  return new ApplicationDescription
  25:                             {
  26:                                 Name = "My Application",
  27:                                 Category = "Web",
  28:                                 Version = "3.4.0.0"
  29:                             };
  30:              }
  31:          }
  32:   
  33:          public IEnumerable<IVerification> GetVerifications()
  34:          {
  35:              yield return VerificationBuilder.Instance.BuildVerification(CreateCertificateVerification());
  36:              yield return VerificationBuilder.Instance.BuildVerification(CreateServiceVerification());
  37:              yield return VerificationBuilder.Instance.BuildVerification(CreateSqlServerVerification());
  38:          }         
  39:   
  40:          private static SqlConnectionVerificationDescription CreateSqlServerVerification()
  41:          {
  42:              var description = new SqlConnectionVerificationDescription
  43:                  {
  44:                      VerificationName = "Local SQL Server",
  45:                      Category = "Critical",
  46:                      GetConnectionString = () => GetConfigurationSetting("connectionString")
  47:                  };
  48:   
  49:              return description;
  50:          }
  51:   
  52:          private static WebGetVerificationDescription CreateServiceVerification()
  53:          {
  54:              var description = new WebGetVerificationDescription
  55:                  {
  56:                      VerificationName = "Data Service",
  57:                      Category = "Services",
  58:                      GetUrl = () => GetConfigurationSetting("serviceUri")
  59:                  };
  60:   
  61:              return description;
  62:          }
  63:   
  64:          private static CertificateAccessVerificationDescription CreateCertificateVerification()
  65:          {
  66:              var description = new CertificateAccessVerificationDescription
  67:                  {
  68:                      VerificationName = "X509 Certificate",
  69:                      Category = "Resources",
  70:                      GetStoreLocation = () => StoreLocation.LocalMachine,
  71:                      GetStoreName = () => StoreName.My,
  72:                      GetThumbprint = () => "cdba27d3bab4b8a11b6b487c271e68656acfaa2c"
  73:                  };
  74:   
  75:              return description;
  76:          }
  77:   
  78:          private static string GetConfigurationSetting(string key)
  79:          {
  80:              return ConfigurationManager.AppSettings[key];
  81:          }
  82:      }
  83:  }

The first property describes the application. The GetVerifications method is the main entry point for verifications so that they can be executed by the Preflight engine.

Initializing Preflight

Preflight must be initialized before making a call to the service. You can pass the service and engine options through code or through configuration. In this sample application, we’re going to initialize through code. The following is a snippet from the Global.asax code behind class

protected void Application_Start()
        {
            AreaRegistration.RegisterAllAreas();

            RegisterGlobalFilters(GlobalFilters.Filters);
            RegisterRoutes(RouteTable.Routes);

            BundleTable.Bundles.RegisterTemplateBundles();

            InitializePreflight();
        }

        private static void InitializePreflight()
        {
            var preflightServiceOptions = new PreflightServiceOptions { SecurityEnabled = false };
            var context = new PreflightContext(new SampleVerificationFactory(), new PreflightOptions());
            PreflightService.Initialize(context, preflightServiceOptions);
        }

Notice the Initialize Preflight, we’re passing in 2 different object:

  • preflightServiceOptions: This enables configuring the service. To make things simple we’re turning off security (You should never ship your application with security disabled especially if it’s externally accessible)
  • context: The engine context contains our verification factory and engine options (we’re using the default settings)

Making a Preflight Request

Using the web browser:

  1. Open your browser
  2. type in: http://localhost/preflight-api/check

Alternatively you can use the Preflight Client tool to make a request and execute your verifications

Last edited Aug 12, 2012 at 6:26 AM by aelamiri, version 17

Comments

No comments yet.