A
download MyTestPackage.cs
Language: C#
License: MSVSSDK
LOC: 89
Project Info
C# Example.MyTestTypeSample
Server: Visual Studio SDK
Type: filesystem
...xtensibility\MyTest\MyTest\
   assembly.cs
   MyHostAdapter.cs
   ...pterRunConfigControl.cs
   ...nfigControl.Designer.cs
   ...erRunConfigControl.resx
   MyTest.cs
   MyTest.csproj
   MyTestAdapter.cs
   MyTestAssertHelper.cs
   MyTestEditorControl.cs
   ...itorControl.Designer.cs
   MyTestEditorControl.resx
   MyTestEditorFactory.cs
   MyTestPackage.cs
   MyTestResourceIds.cs
   MyTestResult.cs
   MyTestResultViewControl.cs
   ...ViewControl.designer.cs
   ...tResultViewControl.resx
   MyTestResultViewWindow.cs
   MyTestRunConfigControl.cs
   ...nfigControl.Designer.cs
   ...stRunConfigControl.resx
   MyTestTip.cs
   MyTestTuip.cs
   MyTestWizard.cs

/***************************************************************************
 
Copyright (c) Microsoft Corporation. All rights reserved.
This code is licensed under the Visual Studio SDK license terms.
THIS CODE IS PROVIDED *AS IS* WITHOUT WARRANTY OF
ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY
IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR
PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT.
 
***************************************************************************/
//*************************************************************************************************
// MyTestPackage.cs
//
// This file defines the MyTest package.
//
// Copyright(c) Microsoft Corporation, 2004
//*************************************************************************************************

namespace Microsoft.VisualStudio.TestTools.Samples
{
	using System;
	using System.Collections;
	using System.Collections.Generic;
	using System.ComponentModel.Design;
	using System.Diagnostics;
	using System.Diagnostics.CodeAnalysis;
	using System.IO;
	using System.Runtime.InteropServices;
	using System.Windows.Forms;

	using Microsoft.VisualStudio.Shell;

	using Microsoft.VisualStudio.TestTools.Common;
	using Microsoft.VisualStudio.TestTools.Exceptions;
	using Microsoft.VisualStudio.TestTools.TestManagement;
	using Microsoft.VisualStudio.TestTools.Tips.TuipPackage;
	using Microsoft.VisualStudio.TestTools.Vsip;

	/// <summary>
	/// MyTest package implementation.
	/// Implement a package when you need to host your own editor, result
	/// details viewer, or new test wizard.
	/// Packages are standard VSIP packages and derive from
	/// Microsoft.VisualStudio.Shell.Package.
	/// There are a number of attributes to help with registration, including
	/// RegisterTestType, ProvideServiceForTestType, ProvideToolWindow, and
	/// AddNewItemTemplates.
	/// </summary>
	// TODO: Generate a unique GUID for your package. To get a valid package
	// load key for your package, you need to visit http://vsipdev.com and
	// request one. Use the ProvideLoadKey attribute to provide the PLK
	// information for registration with regpkg.
    [Guid("BA1248C1-49F2-4899-9A2C-548035755F2C")]
    [ProvideMenuResource(1000, 1)]
    [DefaultRegistryRoot(@"Software\Microsoft\VisualStudio\8.0")]
    [ProvideLoadKey("Professional", "1.0", "eDT Test Integration Sample", "n/a", (short)ResourceIds.MyTestPackageLoadKey)]
    [RegisterTestType(typeof(MyTest), typeof(MyTestTip), typeof(MyTestEditorFactory), 100, new string[] { ".mytest" }, new int[] { (int)ResourceIds.MyTestIcon }, (int)ResourceIds.MyTestName, (int)ResourceIds.MyTestEditorCaption)]
	//[RegisterTestTypeNoEditor(typeof(MyTest), typeof(MyTestTip), new string[] { ".mytest" }, new int[] { (int)ResourceIds.MyTestIcon }, (int)ResourceIds.MyTestName)]
    [RegisterHostAdapter(MyHostAdapter.Name, typeof(MyHostAdapter), typeof(MyHostAdapterRunConfigControl))]
    [ProvideServiceForTestType(typeof(MyTest), typeof(SMyTestService))]
    [ProvideToolWindow(typeof(MyTestResultViewWindow), Orientation = ToolWindowOrientation.Left, Style = VsDockStyle.MDI)]
    // Suppress AvoidUninstantiatedInternalClasses.
    // MyTestPackage is created late-bound.
    [SuppressMessage("Microsoft.Performance", "CA1812")]
    internal sealed class MyTestPackage : Microsoft.VisualStudio.Shell.Package
    {
        #region Constructors

        /// <summary>
        ///	Constructor for the package. Setup the required Service and associated callback
        ///	</summary>
        public MyTestPackage()
            : base()
        {
            ServiceCreatorCallback callback = new ServiceCreatorCallback(this.OnCreateService);
            IServiceContainer container = GetService(typeof(IServiceContainer)) as IServiceContainer;

            Debug.Assert(container != null, "Package didn't provide IServiceContainer so we cannot provide services");

            if (container != null)
            {
                // For every TUIP, add its service here.
                container.AddService(typeof(SMyTestService), callback, true);
            }

            m_package = this;
        }

        #endregion

        #region Properties

		/// <value>
		/// The Instance of the package that allows other classess to access the packages services
		/// </value>
        internal static MyTestPackage Instance
        {
            get { Debug.Assert(m_package != null, "Package needs to be created before Instance is called."); return m_package; }
        }

        #endregion

        #region Operations
		/// <summary>
		/// Used to get different services through the VS COM Interop assemblies
		/// </summary>
		/// <param name="typeService">The Type of the service to get & return</param>
		/// <returns>A Service of the requested type</returns>
        internal new object GetService(Type typeService)
        {
            return base.GetService(typeService);
        }

        #endregion

        #region Overrides

        /// <summary>
        /// Provide initialization of the package
        /// </summary>
        protected override void Initialize()
        {
            base.Initialize();

            // For each of the editor factory you want to register, do the following
            MyTestEditorFactory factory = new MyTestEditorFactory();
            base.RegisterEditorFactory(factory);
        }

        #endregion

        #region Private helpers

        /// <summary>
        /// Callback from IServiceContainer to demand create our services.
        /// </summary>
        /// <param name="container">service container</param>
        /// <param name="serviceType">type of service</param>
        /// <returns>the service provider object</returns>
        private object OnCreateService(IServiceContainer container, Type serviceType)
        {
            if (container == null)
            {
                throw new ArgumentNullException("container");
            }

            if (serviceType == null)
            {
                throw new ArgumentNullException("serviceType");
            }

            //Hint: return your service from here
            if (serviceType == typeof(SMyTestService))
            {
                return new MyTestTuip(this);
            }
            else
            {
                Debug.Fail("service container requested service: " + serviceType.FullName + ", but we don't support it");
                return null;
            }
			
        }

        #endregion

        #region Private data

        // The one instance of this package.
        private static MyTestPackage m_package;

        #endregion
    }
}

About Koders | Resources | Downloads | Support | Black Duck | Terms of Service | DMCA | Privacy Policy | Contact Us