示例#1
0
        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()));
        }
示例#2
0
        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 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)));
            }
        public ComAdminClassInfo FindClass(string classNameOrGuid)
        {
            ComAdminClassInfo resolvedClassInfo = null;

            classNameOrGuid = classNameOrGuid.ToLowerInvariant();

            foreach (ComAdminClassInfo classInfo in this.classes)
            {
                if ((classInfo.Clsid.ToString("B").ToLowerInvariant() == classNameOrGuid) ||
                    classInfo.Name.ToLowerInvariant() == classNameOrGuid)
                {
                    if (resolvedClassInfo == null)
                    {
                        resolvedClassInfo = classInfo;
                    }
                    else
                    {
                        throw Tool.CreateException(SR.GetString(SR.AmbiguousComponentName, classNameOrGuid), null);
                    }
                }
            }

            return(resolvedClassInfo);
        }
        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;
            }
        }
示例#6
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;
            }
        }
示例#7
0
文件: Tool.cs 项目: JianwenSun/cc
 static bool ValidateClass(ComAdminClassInfo classInfo)
 {
     if (classInfo.IsPrivate)
     {
         ToolConsole.WriteWarning(SR.GetString(SR.CannotExposePrivateComponentsSkipping, Tool.Options.ShowGuids ? classInfo.Clsid.ToString("B") : classInfo.Name));
         return false;
     }
     return true;
 }