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");
}
}
|