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 static string GetAppropriateBitnessModuleModulePath(bool is64bit, RuntimeVersions runtimeVersion)
 {
     if (RuntimeVersions.V40 == runtimeVersion)
     {
         // Retrieve the regkey with Read permission. Note that on Windows 8 and later, only Trusted installer has write access to this key.
         using (RegistryHandle regKey = RegistryHandle.GetCorrectBitnessHKLMSubkey(is64bit, ServiceModelInstallStrings.WinFXRegistryKey, false))
         {
             return(regKey.GetStringValue(ServiceModelInstallStrings.RuntimeInstallPathName).TrimEnd('\0') + "\\" + fileName);
         }
     }
     else
     {
         // Try to find the 3.0 version
         RegistryHandle regkey = null;
         try
         {
             if (SafeNativeMethods.ERROR_SUCCESS == RegistryHandle.TryGetCorrectBitnessHKLMSubkey(is64bit, Wcf30RegistryKey, out regkey))
             {
                 return(regkey.GetStringValue(Runtime30InstallPathName).TrimEnd('\0') + "\\" + fileName);
             }
             else
             {
                 //We don't want to automatically roll forward to 4.0, so we throw an exception if we can't find the 3.0 reg key
                 throw Tool.CreateException(SR.GetString(SR.FailedToGetRegistryKey, Wcf30RegistryKey, "3.0"), null);
             }
         }
         finally
         {
             if (regkey != null)
             {
                 regkey.Dispose();
             }
         }
     }
 }
Ejemplo n.º 3
0
        public static string GetDotNetFolder(RuntimeVersions netVersion, ProcArc procArc)
        {
            var winDir = System.Environment.GetFolderPath(System.Environment.SpecialFolder.Windows);

            var dotNetDir = Path.Combine(winDir, "Microsoft.NET");

            if (!Directory.Exists(dotNetDir))
            {
                throw new DirectoryNotFoundException("Каталог не найден: " + dotNetDir);
            }

            var procDir = string.Empty;

            switch (procArc)
            {
            case ProcArc.IA64:
            case ProcArc.Amd64:
            case ProcArc.MSIL:
                procDir = "Framework64";
                break;

            default:
                procDir = "Framework";
                break;
            }

            string frameworkDir = Path.Combine(dotNetDir, procDir);

            string versPrefix = string.Empty;

            switch (netVersion)
            {
            case RuntimeVersions.v4:
                versPrefix = "v4.";
                break;

            default:
                versPrefix = "v2.";
                break;
            }

            var versFolder           = string.Empty;
            var frameworkDirectories = new DirectoryInfo(frameworkDir).EnumerateDirectories().Select(di => di.Name);

            foreach (var dir in frameworkDirectories)
            {
                if (dir.StartsWith(versPrefix))
                {
                    versFolder = dir;
                }
            }

            if (string.IsNullOrEmpty(versFolder))
            {
                throw new DirectoryNotFoundException("Каталог с версией .NET не найден по пути: " + frameworkDir);
            }

            return(Path.Combine(frameworkDir, versFolder));
        }
        public static void InstallListener(Guid appid, string path, RuntimeVersions runtimeVersion)
        {
            string application = appid.ToString("B");
            string partitionId = null;


            ICatalog2 catalog = GetCatalog();

            partitionId = GetPartitionIdForApplication(catalog, application, false);

            // Search for the listener in this partition..
            bool   is64bit  = GetApplicationBitness(catalog, partitionId, application);
            Guid   clsidVal = Guid.NewGuid();
            string clsid    = clsidVal.ToString("B");
            string tlb      = Path.Combine(path, application + "." + clsid + ".tlb");

            try
            {
                // No other listener in this partition, we're the first - install using RegistrationHelper
                AtomicFile.SafeDeleteFile(tlb);
                string modulePath = GetAppropriateBitnessModuleModulePath(is64bit, runtimeVersion);
                if (string.IsNullOrEmpty(modulePath))
                {
                    throw Tool.CreateException(SR.GetString(SR.CannotFindServiceInitializerModuleInRegistry), null);
                }
                CreateTypeLib(tlb, clsidVal);
                CreateRegistryKey(is64bit, clsidVal, modulePath);
                catalog.InstallComponent(application, modulePath, tlb, null);
                MarkComponentAsPrivate(catalog, partitionId, application, ListenerWSUName);
                if (!SetComponentProperty(application, ListenerWSUName, PropertyName.Description, ListenerComponentDescription))
                {
                    ToolConsole.WriteWarning(SR.GetString(SR.CannotSetComponentDescription, clsid, appid.ToString("B")));
                }
                if (!SetComponentProperty(application, ListenerWSUName, PropertyName.InitializesServerApplication, "1"))
                {
                    ToolConsole.WriteWarning(SR.GetString(SR.CannotSetComponentInitializerProperty, ListenerWSUName, appid.ToString("B")));
                }
                if (!SetComponentProperty(application, ListenerWSUName, PropertyName.ComponentAccessChecksEnabled, "0"))
                {
                    ToolConsole.WriteWarning(SR.GetString(SR.CannotDisableAccessChecksOnInitializer, ListenerWSUName, appid.ToString("B")));
                }
            }
            catch (Exception ex)
            {
                if (ex is NullReferenceException || ex is SEHException)
                {
                    throw ex;
                }

                throw Tool.CreateException(SR.GetString(SR.CouldNotInstallListener), ex);
            }
            finally
            {
                AtomicFile.SafeDeleteFile(tlb);
            }
        }
Ejemplo n.º 5
0
        public static string GetFilePathName(RuntimeVersions netVersion, ProcessorArchitecture procArc)
        {
            var dotNetToolsFolder = Core_4_0.Utilites.GetDotNetFolder(netVersion, procArc);

            var filePathName = Path.Combine(dotNetToolsFolder, "RegAsm.exe");

            if (File.Exists(filePathName))
            {
                throw new FileNotFoundException("Файл RegAsm не найден по пути " + filePathName);
            }

            return(filePathName);
        }
Ejemplo n.º 6
0
 internal Converter(ProjectOptions options)
 {
     _options = options;
     _tempGuid = Guid.NewGuid();
     _tempPath = Path.Combine(Path.GetTempPath(), _tempGuid.ToString());
     Directory.CreateDirectory(_tempPath);
     Directory.CreateDirectory(TempSolutionPath);
     Directory.CreateDirectory(TempProjectPath);
     Directory.CreateDirectory(TempPropertiesPath);
     Directory.CreateDirectory(TempNetOfficePath);
     Environments = new EnvironmentVersions();
     SolutionFormats = new SolutionFormatVersions();
     Tools = new ToolsVersions();
     Runtimes = new RuntimeVersions();
 }
        WasEndpointConfigContainer(string webServerName, string webDirectoryName, string webDirectoryPath, RuntimeVersions runtimeVersion)
        {
            if (string.IsNullOrEmpty(webDirectoryPath) || !Directory.Exists(webDirectoryPath))
            {
                // We will not tolerate a webDir that does not exist
                throw Tool.CreateException(SR.GetString(SR.WebDirectoryPathNotFound, webDirectoryName, webDirectoryPath), null);
            }

            this.webDirectoryName = webDirectoryName;
            this.webDirectoryPath = webDirectoryPath;
            this.webServerName = webServerName;
            this.closed = false;
            this.configFile = new AtomicFile(this.webDirectoryPath + "\\web.config");
            this.svcFileManager = new SvcFileManager(this.webDirectoryPath);
            this.runtimeVersion = runtimeVersion;
        }
        WasEndpointConfigContainer(string webServerName, string webDirectoryName, string webDirectoryPath, RuntimeVersions runtimeVersion)
        {
            if (string.IsNullOrEmpty(webDirectoryPath) || !Directory.Exists(webDirectoryPath))
            {
                // We will not tolerate a webDir that does not exist
                throw Tool.CreateException(SR.GetString(SR.WebDirectoryPathNotFound, webDirectoryName, webDirectoryPath), null);
            }

            this.webDirectoryName = webDirectoryName;
            this.webDirectoryPath = webDirectoryPath;
            this.webServerName    = webServerName;
            this.closed           = false;
            this.configFile       = new AtomicFile(this.webDirectoryPath + "\\web.config");
            this.svcFileManager   = new SvcFileManager(this.webDirectoryPath);
            this.runtimeVersion   = runtimeVersion;
        }
        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;
            }
        }
Ejemplo n.º 10
0
        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;
            }
        }
Ejemplo n.º 11
0
        public static void InstallListener(Guid appid, string path, RuntimeVersions runtimeVersion)
        {
            string application = appid.ToString("B");
            string partitionId = null;


            ICatalog2 catalog = GetCatalog();
            partitionId = GetPartitionIdForApplication(catalog, application, false);

            // Search for the listener in this partition..
            bool is64bit = GetApplicationBitness(catalog, partitionId, application);
            Guid clsidVal = Guid.NewGuid();
            string clsid = clsidVal.ToString("B");
            string tlb = Path.Combine(path, application + "." + clsid + ".tlb");
            try
            {
                // No other listener in this partition, we're the first - install using RegistrationHelper
                AtomicFile.SafeDeleteFile(tlb);
                string modulePath = GetAppropriateBitnessModuleModulePath(is64bit, runtimeVersion);
                if (string.IsNullOrEmpty(modulePath))
                    throw Tool.CreateException(SR.GetString(SR.CannotFindServiceInitializerModuleInRegistry), null);
                CreateTypeLib(tlb, clsidVal);
                CreateRegistryKey(is64bit, clsidVal, modulePath);
                catalog.InstallComponent(application, modulePath, tlb, null);
                MarkComponentAsPrivate(catalog, partitionId, application, ListenerWSUName);
                if (!SetComponentProperty(application, ListenerWSUName, PropertyName.Description, ListenerComponentDescription))
                    ToolConsole.WriteWarning(SR.GetString(SR.CannotSetComponentDescription, clsid, appid.ToString("B")));
                if (!SetComponentProperty(application, ListenerWSUName, PropertyName.InitializesServerApplication, "1"))
                    ToolConsole.WriteWarning(SR.GetString(SR.CannotSetComponentInitializerProperty, ListenerWSUName, appid.ToString("B")));
                if (!SetComponentProperty(application, ListenerWSUName, PropertyName.ComponentAccessChecksEnabled, "0"))
                    ToolConsole.WriteWarning(SR.GetString(SR.CannotDisableAccessChecksOnInitializer, ListenerWSUName, appid.ToString("B")));
            }
            catch (Exception ex)
            {
                if (ex is NullReferenceException || ex is SEHException)
                {
                    throw ex;
                }

                throw Tool.CreateException(SR.GetString(SR.CouldNotInstallListener), ex);
            }
            finally
            {
                AtomicFile.SafeDeleteFile(tlb);

            }
        }
Ejemplo n.º 12
0
 public static string GetAppropriateBitnessModuleModulePath(bool is64bit, RuntimeVersions runtimeVersion)
 {
     if (RuntimeVersions.V40 == runtimeVersion)
     {
         // Retrieve the regkey with Read permission. Note that on Windows 8 and later, only Trusted installer has write access to this key.
         using (RegistryHandle regKey = RegistryHandle.GetCorrectBitnessHKLMSubkey(is64bit, ServiceModelInstallStrings.WinFXRegistryKey, false))
         {
             return (regKey.GetStringValue(ServiceModelInstallStrings.RuntimeInstallPathName).TrimEnd('\0') + "\\" + fileName);
         }
     }
     else
     {
         // Try to find the 3.0 version
         RegistryHandle regkey = null;
         try
         {
             if (SafeNativeMethods.ERROR_SUCCESS == RegistryHandle.TryGetCorrectBitnessHKLMSubkey(is64bit, Wcf30RegistryKey, out regkey))
             {
                 return (regkey.GetStringValue(Runtime30InstallPathName).TrimEnd('\0') + "\\" + fileName);
             }
             else
             {
                 //We don't want to automatically roll forward to 4.0, so we throw an exception if we can't find the 3.0 reg key
                 throw Tool.CreateException(SR.GetString(SR.FailedToGetRegistryKey, Wcf30RegistryKey, "3.0"), null);
             }
         }
         finally
         {
             if (regkey != null)
             {
                 regkey.Dispose();
             }
         }
     }
 }
        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;
            }
        }