SolutionListenerForProjectEvents.cs :  » Development » StyleCop » Microsoft » VisualStudio » Package » 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 » Development » StyleCop 
StyleCop » Microsoft » VisualStudio » Package » SolutionListenerForProjectEvents.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.

***************************************************************************/

using Microsoft.VisualStudio.Shell.Interop;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.Runtime.InteropServices;
using System.Security;
using System.Windows;
using Microsoft.VisualStudio.OLE.Interop;
using Microsoft.VisualStudio.Shell;
using System.Drawing;
using System.IO;
using System.Windows.Forms;
using System.Collections;
using System.Text;
using IOleServiceProviderMicrosoft.VisualStudio.OLE.Interop.IServiceProvider;
using IServiceProviderSystem.IServiceProvider;
using ShellConstantsMicrosoft.VisualStudio.Shell.Interop.Constants;
using OleConstantsMicrosoft.VisualStudio.OLE.Interop.Constants;

namespace Microsoft.VisualStudio.Package{
  /// <summary>
  /// This class triggers the project events for "our" hierrachies.
  /// </summary>
  internal class SolutionListenerForProjectEvents : SolutionListener, IProjectEvents
  {
    #region events
    /// Event raised just after the project file opened.
    /// </summary>
    public event EventHandler<AfterProjectFileOpenedEventArgs> AfterProjectFileOpened;

    /// <summary>
    /// Event raised before the project file closed.
    /// </summary>
    public event EventHandler<BeforeProjectFileClosedEventArgs> BeforeProjectFileClosed;
    #endregion

    #region ctor
    internal SolutionListenerForProjectEvents(IServiceProvider serviceProvider)
      : base(serviceProvider)
    {
    }
    #endregion

    #region overridden methods
    public override int OnAfterOpenProject(IVsHierarchy hierarchy, int added)
    {
      IProjectEventsListener projectEventListener = hierarchy as IProjectEventsListener;
      if (projectEventListener != null && projectEventListener.IsProjectEventsListener)
      {
        this.RaiseAfterProjectFileOpened((added != 0) ? true : false);
      }

      return VSConstants.S_OK;
    }

    public override int OnBeforeCloseProject(IVsHierarchy hierarchy, int removed)
    {
      IProjectEventsListener projectEvents = hierarchy as IProjectEventsListener;
      if (projectEvents != null && projectEvents.IsProjectEventsListener)
      {
        this.RaiseBeforeProjectFileClosed((removed != 0) ? true : false);
      }

      return VSConstants.S_OK;
    }
    #endregion

    #region helpers
    /// <summary>
    /// Raises after project file opened event.
    /// </summary>
    /// <param name="added">True if the project is added to the solution after the solution is opened. false if the project is added to the solution while the solution is being opened.</param>
    private void RaiseAfterProjectFileOpened(bool added)
    {
      // Save event in temporary variable to avoid race condition.
      EventHandler<AfterProjectFileOpenedEventArgs> tempEvent = this.AfterProjectFileOpened;
      if (tempEvent != null)
      {
        tempEvent(this, new AfterProjectFileOpenedEventArgs(added));
      }
    }

    


    /// <summary>
    /// Raises the before  project file closed event.
    /// </summary>
    /// <param name="added">true if the project was removed from the solution before the solution was closed. false if the project was removed from the solution while the solution was being closed.</param>
    private void RaiseBeforeProjectFileClosed(bool removed)
    {
      // Save event in temporary variable to avoid race condition.
      EventHandler<BeforeProjectFileClosedEventArgs> tempEvent = this.BeforeProjectFileClosed;
      if (tempEvent != null)
      {
        tempEvent(this, new BeforeProjectFileClosedEventArgs(removed));
      }
    }
  }
  #endregion
}
www.java2v.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.