Click here to Skip to main content
15,895,667 members
Articles / Web Development / HTML

A Server Control Authoring JavaScript

Rate me:
Please Sign up or sign in to vote.
4.33/5 (5 votes)
12 Jun 20067 min read 38.3K   379   30  
This is a short series of articles about Abstract Programming. This part is a look at C# authoring a JavaScript file at design time.
using EnvDTE;
using System;
using System.Diagnostics;
using System.Runtime.InteropServices;
using System.Collections;
using System.Runtime.InteropServices.ComTypes;

namespace ProMatrix.Lib.Controls
{
	/*
		support for:

		EnableUnmanagedDebugging
		FxCopRuleAssemblies
		StartWorkingDirectory
		CurrentWebsiteLanguage
		EnableASPXDebugging
		StartURL
		VsWebServerPort
		StartProgram
		StartAction
		StartArguments
		FullPath
		OpenedURL
		EnableSQLServerDebugging
		FxCopRules
		EnableNTLMAuthentication
		WebSiteType
		EnableFxCop
		EnableVsWebServer
		BrowseURL
		StartPage
		VSPolicyExtenderProvider.TDLFileName
		EnableVsWebServerDynamicPort
	*/

	public class ControlDesignerHelper
	{
		private DTE _oDTE = null;
		private Hashtable ProjectPropertiesHashTable = new Hashtable();
		private ArrayList ProjectPropertiesArrayList = new ArrayList();
		public string AllProjectProperties="";
		
		[DllImportAttribute("ole32.dll")]
		private static extern int GetRunningObjectTable(int reserved, out IRunningObjectTable prot);

		[DllImportAttribute("ole32.dll")]
		private static extern int CreateBindCtx(int reserved, out IBindCtx ppbc);
		
		//********************
		// CONSTRUCTORS
		//
		/// <summary>
		///     Default constructor needed for XML serialization
		/// </summary>
		public ControlDesignerHelper()
		{
			init();
		}

		~ControlDesignerHelper()
		{
			try { _oDTE = null;	}
			finally
			{ //base.Finalize(); 
			}
		}

		public string ProjectDocument()
		{
			return _oDTE.ActiveDocument.FullName;
		}

		public string ProjectProperties(string key)
		{
			if ( ProjectPropertiesHashTable.ContainsKey(key))
				return ProjectPropertiesHashTable[key].ToString();
			else
				return "";
		}
		
		private void GetMSDEVFromGIT(string left, string right)
		{
			string str;
			object local;
			IRunningObjectTable iRunningObjectTable;
			IEnumMoniker iEnumMoniker;
			IBindCtx iBindCtx = null;
			try
			{
				GetRunningObjectTable(0, out iRunningObjectTable);
				iRunningObjectTable.EnumRunning(out iEnumMoniker);
				iEnumMoniker.Reset();
				IMoniker[] iMonikers = new IMoniker[1];

				IntPtr intptr = new IntPtr(0);

				while (iEnumMoniker.Next(1, iMonikers, intptr) == 0)
				{
					CreateBindCtx(0, out iBindCtx);
					iMonikers[0].GetDisplayName(iBindCtx, null, out str);
					if (str.StartsWith(left) && str.EndsWith(right))
					{
						iRunningObjectTable.GetObject(iMonikers[0], out local);
						_oDTE = (DTE)local;
					}
				}
			
			}
			catch (Exception e)
			{ throw e; }
		}

		public void init()
		{
			System.Array projs;
			EnvDTE.Project proj;
			ProjectPropertiesHashTable.Clear();
			
			GetMSDEVFromGIT("!VisualStudio.DTE.8", System.Diagnostics.Process.GetCurrentProcess().Id.ToString());
			if (_oDTE == null) return;

			projs = (System.Array)_oDTE.ActiveSolutionProjects;

			proj = (EnvDTE.Project)projs.GetValue(0);
			EnvDTE.Properties pProps = proj.Properties;
			
			try
			{ 
				foreach (EnvDTE.Property propObj in pProps)
				{
					ProjectPropertiesHashTable.Add(propObj.Name, propObj.Value.ToString());
				}
			
			}
			catch {}
		}
	}
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
United States United States
My formal education was in Electronic Engineering with a background in real-time data acquisition for aerospace. Early in my career, I switched my focus from hardware engineering to software engineering. Most, but not all, of my development experience has been using Microsoft technologies and tools. My current accomplishments are web applications using ASP.Net, SQL Server 2005, JavaScript, and Visual Studio Tools for Office. I enjoy all facets of a development life cycle, and have played almost all roles. Most recently, I have been involved in project technical leadership, architecture, and training, and I have created several small courses including this one on Abstract Programming.

Comments and Discussions