Extenders.cs :  » Development » devAdvantage » AnticipatingMinds » DevAdvantageVSAddIn » 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 » devAdvantage 
devAdvantage » AnticipatingMinds » DevAdvantageVSAddIn » Extenders.cs
using System;
using System.Runtime.InteropServices;
using System.Windows.Forms;
using System.Diagnostics;
using Extensibility;
using EnvDTE;
using System.Collections;
using System.Collections.Specialized;
using System.ComponentModel;
using AnticipatingMinds.Genesis.KnowledgeManagement;
using AnticipatingMinds.Genesis.KnowledgeManagement.KnowledgeBaseUI;
using AnticipatingMinds.PlatformServices.Globalization;

namespace AnticipatingMinds.DevAdvantageVSAddIn{
  /// <summary>
  /// Summary description for Extenders.
  /// </summary>
  [ComVisibleAttribute(true)]
  [GuidAttribute("D2AD4769-ED5E-4b21-8471-0F98CC4F9148")] 
  [ProgId("DevAdvantage.SolutionExtender")]  
  public class SolutionExtender
  {
    public SolutionExtender(Solution solution,KnowledgeBase knowledgeBase,int extenderCookie, EnvDTE.IExtenderSite extenderSite)
    {
      this.extenderCookie = extenderCookie;
      this.solution = solution;
      this.knowledgeBase = knowledgeBase;
      this.extenderSite = extenderSite;
    }
    
    ~SolutionExtender()
    {
      // Wrap this call in a try-catch to avoid any failure code the
      // Site may return. For instance, since this object is GC'ed,
      // the Site may have already let go of its Cookie.
      try
      {
        if (extenderSite != null)
          extenderSite.NotifyDelete(extenderCookie);
      }
      catch(Exception)
      {
      }
    }


    [EditorAttribute(typeof(ProfilesArrayUIEditor),typeof(System.Drawing.Design.UITypeEditor))]
    [TypeConverterAttribute(typeof(ProfilesArrayReadOnlyTypeConverter))]
    public Profile[] DevAdvantageProfiles
    {
      get
      {
        if(solution.Globals.get_VariableExists("DevAdvantage_Profiles"))
        {
          string profileIds = (string) solution.Globals["DevAdvantage_Profiles"];
          if(profileIds.Length == 0 || profileIds.Split(',').Length == 0)
          {
            return new Profile[0];
          }
          else
          {
            bool needToResetProfiles = false;
            string[] profileStringIds = profileIds.Split(',');
            ArrayList profiles = new ArrayList();
            foreach(string profileId in profileStringIds)
            {
              Profile profile = knowledgeBase.GetProfileById(profileId);
              if(profile == null)
              {
                needToResetProfiles = true;
                continue;
              }
              else
              {
                profiles.Add(profile);
              }
            }

            Profile[] retValue = new Profile[profiles.Count];

            for(int profileIndex = 0;profileIndex < profiles.Count;profileIndex++)
              retValue[profileIndex] = profiles[profileIndex] as Profile;
            
            if(needToResetProfiles)
              this.DevAdvantageProfiles = retValue;

            return retValue;
          }

        }
        else
        {
          return new Profile[1] {knowledgeBase.GetProfileById(knowledgeBase.AllRulesProfileId)};
        }
      }
      set
      {
        string profileIds;
        if(value == null || value.Length == 0)
        {
          profileIds = string.Empty;
        }
        else
        {
          profileIds = value[0].Id;
          for(int i = 1; i < value.Length; i++)
            profileIds += ("," + value[i].Id); 
        }

        try
        {
          if(!solution.Globals.get_VariableExists("DevAdvantage_Profiles") || ((solution.Globals["DevAdvantage_Profiles"] as string) != profileIds))
          {
            solution.Globals["DevAdvantage_Profiles"] = profileIds;
            solution.Globals.set_VariablePersists("DevAdvantage_Profiles",true);
          }
        }
        catch(System.Runtime.InteropServices.COMException exception)
        {
          if(exception.ErrorCode == unchecked((int)0x80004005)) //E_ABORT
          {
            MessageBox.Show(GetLocalizedString("CannotSaveProfilesSolutionUnderSourceControl"),GetLocalizedString("ProductName"),MessageBoxButtons.OK,MessageBoxIcon.Exclamation);
            return;
          }
          
          throw;
        }
      }
    }
    public static string GetLocalizedString(string resourceName,params string[] arguments)
    {
      return assemblyResourceManager.GetFormatedString(resourceName,arguments);
    }

    private Solution solution;
    private KnowledgeBase knowledgeBase;
    private int extenderCookie;
    private EnvDTE.IExtenderSite extenderSite;
    private static AssemblyResourceManager assemblyResourceManager = AssemblyResourceManager.GetInstance("AnticipatingMinds.DevAdvantageVSAddIn.Messages");
  }

  /// <summary>
  /// Summary description for Extenders.
  /// </summary>
  [ComVisibleAttribute(true)]
  [GuidAttribute("87E8B321-4E61-4b29-8ED8-87437D9E3369")] 
  [ProgId("DevAdvantage.ProjectExtender")]  
  public class ProjectExtender
  {
    public ProjectExtender(Project project,KnowledgeBase knowledgeBase,int extenderCookie, EnvDTE.IExtenderSite extenderSite)
    {
      this.extenderCookie = extenderCookie;
      this.project = project;
      this.knowledgeBase = knowledgeBase;
      this.extenderSite = extenderSite;
    }
    ~ProjectExtender()
    {
      // Wrap this call in a try-catch to avoid any failure code the
      // Site may return. For instance, since this object is GC'ed,
      // the Site may have already let go of its Cookie.
      try
      {
        if (extenderSite != null)
          extenderSite.NotifyDelete(extenderCookie);
      }
      catch(Exception)
      {
      }
    }


    [EditorAttribute(typeof(ProfilesArrayUIEditor),typeof(System.Drawing.Design.UITypeEditor))]
    [TypeConverterAttribute(typeof(ProfilesArrayReadOnlyTypeConverter))]
    public Profile[] DevAdvantageProfiles
    {
      get
      {
        
        if(project.Globals.get_VariableExists("DevAdvantage_Profiles"))
        {
          string profileIds = (string) project.Globals["DevAdvantage_Profiles"];
          if(profileIds.Length == 0 || profileIds.Split(',').Length == 0)
          {
            return new Profile[0];
          }
          else
          {
            bool needToResetProfiles = false;
            string[] profileStringIds = profileIds.Split(',');
            ArrayList profiles = new ArrayList();
            foreach(string profileId in profileStringIds)
            {
              Profile profile = knowledgeBase.GetProfileById(profileId);
              if(profile == null)
              {
                needToResetProfiles = true;
                continue;
              }
              else
              {
                profiles.Add(profile);
              }
            }

            Profile[] retValue = new Profile[profiles.Count];

            for(int profileIndex = 0;profileIndex < profiles.Count;profileIndex++)
              retValue[profileIndex] = profiles[profileIndex] as Profile;

            if(needToResetProfiles)
              this.DevAdvantageProfiles = retValue;

            return retValue;
          }

        }
        return new Profile[0];
      }
      set
      {
        string profileIds;
        if(value == null || value.Length == 0)
        {
          profileIds = string.Empty;
        }
        else
        {
          profileIds = value[0].Id;
          for(int i = 1; i < value.Length; i++)
            profileIds += ("," + value[i].Id); 
        }

        try
        {
          if(!project.Globals.get_VariableExists("DevAdvantage_Profiles") || ((string)project.Globals["DevAdvantage_Profiles"]) != profileIds)
          {
            project.Globals["DevAdvantage_Profiles"] = profileIds;
            project.Globals.set_VariablePersists("DevAdvantage_Profiles",true);
          }
        }
        catch(System.Runtime.InteropServices.COMException exception)
        {
          if(exception.ErrorCode == unchecked((int)0x80004005)) //E_ABORT
          {
            MessageBox.Show(GetLocalizedString("CannotSaveProfilesProjectUnderSourceControl"),GetLocalizedString("ProductName"),MessageBoxButtons.OK,MessageBoxIcon.Exclamation);
            return;
          }
          
          throw;
        }

      }

    }

    public static string GetLocalizedString(string resourceName,params string[] arguments)
    {
      return assemblyResourceManager.GetFormatedString(resourceName,arguments);
    }

    private Project project;
    private KnowledgeBase knowledgeBase;
    private int extenderCookie;
    private EnvDTE.IExtenderSite extenderSite;
    private static AssemblyResourceManager assemblyResourceManager = AssemblyResourceManager.GetInstance("AnticipatingMinds.DevAdvantageVSAddIn.Messages");
  }


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