public static ComplusEndpointConfigContainer Get(string appIdOrName, bool rethrow) { ComAdminAppInfo appInfo = ComAdminWrapper.GetAppInfo(appIdOrName); if (appInfo == null) { return(null); } try { ComplusEndpointConfigContainer container = new ComplusEndpointConfigContainer(appInfo); return(container); } catch (Exception ex) { if (ex is NullReferenceException || ex is SEHException) { throw; } if (rethrow) { throw; } else { ToolConsole.WriteWarning(SR.GetString(SR.FailedToLoadConfigForApplicationIgnoring, appInfo.Name, ex.Message)); } } return(null); }
public override string BaseServiceAddress(Guid appId, Guid clsid, Guid iid) { ComAdminAppInfo adminAppInfo = ComAdminWrapper.GetAppInfo(appId.ToString("B")); if (null == adminAppInfo) { throw Tool.CreateException(SR.GetString(SR.CannotFindAppInfo, appId.ToString("B")), null); } ComAdminClassInfo adminClassInfo = adminAppInfo.FindClass(clsid.ToString("B")); if (null == adminClassInfo) { throw Tool.CreateException(SR.GetString(SR.CannotFindClassInfo, clsid.ToString("B")), null); } string uri = Uri.EscapeUriString("net.pipe://localhost/" + adminAppInfo.Name + "/" + GetPartitionId(appId) + adminClassInfo.Name); if (Uri.IsWellFormedUriString(uri, UriKind.Absolute)) { return(uri); } return("net.pipe://localhost/" + (appId.ToString() + "/" + clsid.ToString())); }
public override string DefaultEndpointAddress(Guid appId, Guid clsid, Guid iid) { ComAdminAppInfo adminAppInfo = ComAdminWrapper.GetAppInfo(appId.ToString("B")); if (null == adminAppInfo) { throw Tool.CreateException(SR.GetString(SR.CannotFindAppInfo, appId.ToString("B")), null); } ComAdminClassInfo adminClassInfo = adminAppInfo.FindClass(clsid.ToString("B")); if (null == adminClassInfo) { throw Tool.CreateException(SR.GetString(SR.CannotFindClassInfo, clsid.ToString("B")), null); } ComAdminInterfaceInfo adminInterfaceInfo = adminClassInfo.FindInterface(iid.ToString("B")); if (null == adminInterfaceInfo) { throw Tool.CreateException(SR.GetString(SR.CannotFindInterfaceInfo, iid.ToString("B")), null); } string uri = Uri.EscapeUriString(adminInterfaceInfo.Name); if (Uri.IsWellFormedUriString(uri, UriKind.RelativeOrAbsolute)) { return(uri); } return(iid.ToString().ToUpperInvariant()); }
public static WasEndpointConfigContainer Get(string webServer, string webDirectory, string applicationIdOrName) { string webDirectoryPath = null; RuntimeVersions runtimeVersion = RuntimeVersions.V40; if (!string.IsNullOrEmpty(applicationIdOrName)) { ComAdminAppInfo appInfo = ComAdminWrapper.GetAppInfo(applicationIdOrName); runtimeVersion = appInfo.RuntimeVersion; } if (WasAdminWrapper.GetWebDirectoryPath(webServer, webDirectory, out webDirectoryPath)) { try { return(new WasEndpointConfigContainer(webServer, webDirectory, webDirectoryPath, runtimeVersion)); } catch (Exception ex) { if (ex is NullReferenceException || ex is SEHException) { throw ex; } ToolConsole.WriteWarning(SR.GetString(SR.FailedToLoadConfigForWebDirectoryOnWebSite, webDirectory, webServer)); } return(null); } else { return(null); } }
public override void PrepareChanges() { this.closed = true; bool workDone = this.configFile.HasBeenModified() && WasModified; TransactionOptions opts = new TransactionOptions(); opts.Timeout = TimeSpan.FromMinutes(5); opts.IsolationLevel = IsolationLevel.Serializable; scope = new TransactionScope(TransactionScopeOption.Required, opts, EnterpriseServicesInteropOption.Full); if (workDone) { // if appDir doesnt exist, we must create it before we prepare the config files below if (this.mustGenerateAppDir) { // create it Directory.CreateDirectory(this.appDir); ToolConsole.WriteLine(SR.GetString(SR.DirectoryCreated, this.appDir)); } // set the COM+ app property ComAdminWrapper.SetAppDir(this.appInfo.ID.ToString("B"), this.appDir); } this.configFile.Prepare(); if (workDone) { ToolConsole.WriteLine(SR.GetString((this.configFile.OriginalFileExists ? SR.FileUpdated : SR.FileCreated), configFile.OriginalFileName)); } if (workDone && !this.manifestFile.CurrentExists() && this.hasServices) { string fileName = this.manifestFile.GetCurrentFileName(false); // for update CreateManifestFile(this.manifestFile.GetCurrentFileName(false)); ToolConsole.WriteLine(SR.GetString(SR.FileCreated, this.manifestFile.OriginalFileName)); } this.manifestFile.Prepare(); if (workDone) { // Now, install the Listener if it isnt already there if (this.hasServices && !this.listenerComponentExists) { ComAdminWrapper.InstallListener(this.appInfo.ID, this.appDir, this.appInfo.RuntimeVersion); } else if (!this.hasServices && this.listenerComponentExists) { ComAdminWrapper.RemoveListener(this.appInfo.ID); } if (this.appInfo.IsServerActivated) { ToolConsole.WriteWarning(SR.GetString(SR.ShouldRestartApp, this.appInfo.Name)); } } }
// Just like COM+ Import, we create the following directory "%ProgramFiles%\ComPlus Applications\{appid}" string GeneratedAppDirectoryName() { string programFiles; if (ComAdminWrapper.IsApplicationWow(appInfo.ID)) { programFiles = Environment.GetEnvironmentVariable("ProgramFiles(x86)"); } else { programFiles = Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles); } return(programFiles + "\\ComPlus Applications\\" + this.appInfo.ID.ToString("B") + "\\"); }
public static List <ComplusEndpointConfigContainer> Get() { List <ComplusEndpointConfigContainer> containers = new List <ComplusEndpointConfigContainer>(); Guid[] ids = ComAdminWrapper.GetApplicationIds(); foreach (Guid id in ids) { ComplusEndpointConfigContainer container = ComplusEndpointConfigContainer.Get(id.ToString("B")); if (container != null) { containers.Add(container); } } return(containers); }
public static SvcFile CreateNew(string webDirectoryPath, Guid appid, Guid clsid) { ComAdminAppInfo adminAppInfo = ComAdminWrapper.GetAppInfo(appid.ToString("B")); if (null == adminAppInfo) { throw Tool.CreateException(SR.GetString(SR.CannotFindAppInfo, appid.ToString("B")), null); } ComAdminClassInfo adminClassInfo = adminAppInfo.FindClass(clsid.ToString("B")); if (null == adminClassInfo) { throw Tool.CreateException(SR.GetString(SR.CannotFindClassInfo, clsid.ToString("B")), null); } string fileName = webDirectoryPath + "\\" + adminClassInfo.Name; if (File.Exists(fileName + ".svc")) { int count = 1; while (File.Exists(fileName + "." + count.ToString(CultureInfo.InvariantCulture) + ".svc")) { count++; } fileName = fileName + "." + count.ToString(CultureInfo.InvariantCulture); } fileName = fileName + ".svc"; string comPlusString = clsid.ToString("B") + "," + appid.ToString("B"); using (StreamWriter sw = File.CreateText(fileName)) { sw.WriteLine("<%@ServiceHost {0}=\"{1}\" {2}=\"{3}\" %>", factoryAttributeName, typeof(WasHostedComPlusFactory).FullName, serviceAttributeName, comPlusString); } return(new SvcFile(appid, clsid, SvcFileState.Added, new AtomicFile(fileName))); }
//returns the properly formatted partiton id iff the app is not in the default partition string GetPartitionId(Guid appId) { string partitionId = null; partitionId = ComAdminWrapper.GetPartitionIdForApplication(appId); if ((!String.IsNullOrEmpty(partitionId)) && partitionId != ComAdminWrapper.GetGlobalPartitionID()) { //convert guid to representation without {} Guid partitionGuid = new Guid(partitionId); partitionId = partitionGuid.ToString(); partitionId = partitionId + "/"; } else { partitionId = ""; } return(partitionId); }
void BuildClasses(ICatalogObject appObj, ICatalogCollection appColl) { int versionStrSize = 256; StringBuilder version = new StringBuilder(256); bool isFrameworkVersionSet = false; bool isRuntimeVersionSet = false; bool isRuntimeVersionInstalled = true; int length = 0; Version appClrVersion = null; this.classes = new List <ComAdminClassInfo>(); ICatalogCollection comps = (ICatalogCollection)appColl.GetCollection(CollectionName.Components, appObj.Key()); comps.Populate(); for (int i = 0; i < comps.Count(); i++) { ICatalogObject comp = (ICatalogObject)comps.Item(i); ComAdminClassInfo classInfo = new ComAdminClassInfo(comp, comps); isFrameworkVersionSet = false; if (!isRuntimeVersionSet) { isFrameworkVersionSet = (SafeNativeMethods.ERROR_SUCCESS == SafeNativeMethods.GetRequestedRuntimeVersionForCLSID(classInfo.Clsid, version, versionStrSize, ref length, 0)); if (isFrameworkVersionSet && TryGetVersionFromString(version, out appClrVersion)) { if (IsCLRVersionInstalled(appClrVersion)) { isRuntimeVersionSet = true; } else if (ValidateCLRVersion(appClrVersion)) { // We've found an valid CLR version in the app but that runtime version is not installed isRuntimeVersionSet = true; isRuntimeVersionInstalled = false; } } } if (ComAdminWrapper.IsListenerComponent(comp)) { this.listenerExists = true; } else { this.classes.Add(classInfo); } } //Parse the version number we get // If the version is V4.0* we are going to register the 4.0 version of ServiceMonikerSupport.dll // Anything else we are going to register the 3.0 version of ServiceMonikerSupport.dll if (isRuntimeVersionSet && isRuntimeVersionInstalled) { if (appClrVersion.Major == 4 && appClrVersion.Minor == 0) { this.runtimeVersion = RuntimeVersions.V40; } else if (appClrVersion.Major == 2 && appClrVersion.Minor == 0) { this.runtimeVersion = RuntimeVersions.V20; } else { // It is non of the CLR version this tool recognize throw Tool.CreateException(SR.GetString(SR.FailedToGetRuntime, appClrVersion.ToString()), null); } } else if (!isRuntimeVersionInstalled) { // When we can't find the matching runtime for the user application, throw an application exception throw Tool.CreateException(SR.GetString(SR.FailedToGetRuntime, appClrVersion.ToString()), null); } else { this.runtimeVersion = RuntimeVersions.V40; } }