Esempio n. 1
0
        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);
        }
        ComplusEndpointConfigContainer(ComAdminAppInfo appInfo)
        {
            this.appInfo = appInfo;
            this.scope = null;
            if (appInfo.ApplicationDirectory != null && appInfo.ApplicationDirectory.Length > 0)
            {
                this.appDir = appInfo.ApplicationDirectory;
                this.mustGenerateAppDir = false;

                if (!Directory.Exists(this.appDir))
                {
                    // We will not tolerate misconfigured COM+ apps (i.e. we wont create the dir for you, which is consistent with what COM+ does
                    throw Tool.CreateException(SR.GetString(SR.ApplicationDirectoryDoesNotExist, appDir), null);
                }
            }
            else
            {
                this.appDir = GeneratedAppDirectoryName();

                if (!Directory.Exists(this.appDir))
                    this.mustGenerateAppDir = true;
            }

            this.configFile = new AtomicFile(Path.Combine(this.appDir, "application.config"));
            this.manifestFile = new AtomicFile(Path.Combine(this.appDir, "application.manifest"));

            this.listenerComponentExists = appInfo.ListenerExists;
            this.hasServices = listenerComponentExists;   // notice how we initialize this

        }
Esempio n. 3
0
        ComplusEndpointConfigContainer(ComAdminAppInfo appInfo)
        {
            this.appInfo = appInfo;
            this.scope   = null;
            if (appInfo.ApplicationDirectory != null && appInfo.ApplicationDirectory.Length > 0)
            {
                this.appDir             = appInfo.ApplicationDirectory;
                this.mustGenerateAppDir = false;

                if (!Directory.Exists(this.appDir))
                {
                    // We will not tolerate misconfigured COM+ apps (i.e. we wont create the dir for you, which is consistent with what COM+ does
                    throw Tool.CreateException(SR.GetString(SR.ApplicationDirectoryDoesNotExist, appDir), null);
                }
            }
            else
            {
                this.appDir = GeneratedAppDirectoryName();

                if (!Directory.Exists(this.appDir))
                {
                    this.mustGenerateAppDir = true;
                }
            }

            this.configFile   = new AtomicFile(Path.Combine(this.appDir, "application.config"));
            this.manifestFile = new AtomicFile(Path.Combine(this.appDir, "application.manifest"));

            this.listenerComponentExists = appInfo.ListenerExists;
            this.hasServices             = listenerComponentExists; // notice how we initialize this
        }
Esempio n. 4
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()));
        }
        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);
            }
        }
Esempio n. 6
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 static ComAdminAppInfo GetAppInfo(string appidOrName)
        {
            ICatalogObject     appObj  = null;
            ICatalogCollection appColl = null;

            if (!FindApplication(appidOrName, out appObj, out appColl))
            {
                return(null);
            }

            ComAdminAppInfo appInfo = null;

            try
            {
                appInfo = new ComAdminAppInfo(appObj, appColl);
            }
            catch (COMException ex)
            {
                ToolConsole.WriteWarning(SR.GetString(SR.FailedToFetchApplicationInformationFromCatalog, appidOrName, ex.ErrorCode, ex.Message));
            }
            return(appInfo);
        }
Esempio n. 9
0
        public static ComAdminAppInfo GetAppInfo(string appidOrName)
        {
            ICatalogObject appObj = null;
            ICatalogCollection appColl = null;
            if (!FindApplication(appidOrName, out appObj, out appColl))
            {
                return null;
            }

            ComAdminAppInfo appInfo = null;
            try
            {
                appInfo = new ComAdminAppInfo(appObj, appColl);
            }
            catch (COMException ex)
            {
                ToolConsole.WriteWarning(SR.GetString(SR.FailedToFetchApplicationInformationFromCatalog, appidOrName, ex.ErrorCode, ex.Message));
            }
            return appInfo;
        }
Esempio n. 10
0
        static void GetComponentsFromInputForRemove(ComAdminAppInfo appInfo, IList<ComponentDefinition<string>> inComps, out IList<ComponentDefinition<Guid>> outComps)
        {
            outComps = new List<ComponentDefinition<Guid>>();

            foreach (ComponentDefinition<string> inComp in inComps)
            {
                ComponentDefinition<Guid> outComp = null;

                ComAdminClassInfo classInfo = appInfo.FindClass(inComp.Component);

                if (classInfo == null)
                {
                    ToolConsole.WriteWarning(SR.GetString(SR.CannotFindComponentInApplicationSkipping, inComp.Component, Tool.Options.ShowGuids ? appInfo.ID.ToString("B") : appInfo.Name));
                    continue;
                }


                // Find existing componentDef if it was referenced in an earlier iteration
                foreach (ComponentDefinition<Guid> cd in outComps)
                {
                    if (cd.Component == classInfo.Clsid)
                    {
                        outComp = cd;
                    }
                }

                if (outComp == null)
                {
                    outComp = new ComponentDefinition<Guid>(classInfo.Clsid);
                }

                if (inComp.AllInterfaces)
                {
                    foreach (ComAdminInterfaceInfo interfaceInfo in classInfo.Interfaces)
                        outComp.AddInterface(interfaceInfo.Iid, ComPlusTypeValidator.FetchAllMethodsForInterface(interfaceInfo, false));
                    outComp.AddInterface(typeof(IMetadataExchange).GUID, null);


                }
                else
                {
                    foreach (InterfaceDefination<string> comInterface in inComp.Interfaces)
                    {
                        string itfName = comInterface.Interface;
                        if (itfName == typeof(IMetadataExchange).GUID.ToString("B"))
                        {
                            outComp.AddInterface(typeof(IMetadataExchange).GUID, null);
                        }
                        else
                        {
                            ComAdminInterfaceInfo interfaceInfo = classInfo.FindInterface(itfName);
                            if (interfaceInfo == null)
                            {
                                ToolConsole.WriteWarning(SR.GetString(SR.CannotFindInterfaceInCatalogForComponentSkipping, itfName, inComp.Component));
                                continue;
                            }
                            if (comInterface.AllMethods)
                            {
                                outComp.AddInterface(interfaceInfo.Iid, ComPlusTypeValidator.FetchAllMethodsForInterface(interfaceInfo));
                            }
                            else
                            {

                                outComp.AddInterface(interfaceInfo.Iid, (List<string>)comInterface.Methods);
                            }

                        }
                    }
                }
                if (outComp.Interfaces != null)
                    outComps.Add(outComp);
                else
                {
                    ToolConsole.WriteWarning(SR.GetString(SR.NoneOfTheSpecifiedInterfacesForComponentWereFoundSkipping, inComp.Component));
                }
            }
        }
Esempio n. 11
0
        // returns strongly typed, verified components, from loosely-typed (string) user inputs
        static void GetComponentsFromInputForAdd(ComAdminAppInfo appInfo, IList<ComponentDefinition<string>> inComps, bool mex, bool priorEndpointsExist, out IList<ComponentDefinition<Guid>> outComps)
        {
            string missingInterface = String.Empty;
            outComps = new List<ComponentDefinition<Guid>>();

            foreach (ComponentDefinition<string> inComp in inComps)
            {
                ComponentDefinition<Guid> outComp = null;

                ComAdminClassInfo classInfo = appInfo.FindClass(inComp.Component);

                if (classInfo == null)
                {
                    ToolConsole.WriteWarning(SR.GetString(SR.CannotFindComponentInApplicationSkipping, inComp.Component, Tool.Options.ShowGuids ? appInfo.ID.ToString("B") : appInfo.Name));
                    continue;
                }

                if (!ValidateClass(classInfo))
                    continue;

                // Find existing componentDef if it was referenced in an earlier iteration
                foreach (ComponentDefinition<Guid> cd in outComps)
                {
                    if (cd.Component == classInfo.Clsid)
                    {
                        outComp = cd;
                    }
                }

                if (outComp == null)
                {
                    outComp = new ComponentDefinition<Guid>(classInfo.Clsid);
                }

                if (inComp.AllInterfaces)
                {
                    foreach (ComAdminInterfaceInfo interfaceInfo in classInfo.Interfaces)
                    {
                        if (ComPlusTypeValidator.VerifyInterface(interfaceInfo, options.AllowReferences, classInfo.Clsid))
                            outComp.AddInterface(interfaceInfo.Iid, ComPlusTypeValidator.FetchAllMethodsForInterface(interfaceInfo));

                    }
                    if ((outComp.Interfaces != null) && mex)
                        outComp.AddInterface(typeof(IMetadataExchange).GUID, null);


                }
                else
                {
                    foreach (InterfaceDefination<string> comInterface in inComp.Interfaces)
                    {
                        string itfName = comInterface.Interface;
                        if (itfName == typeof(IMetadataExchange).GUID.ToString("B"))
                        {
                            if (!mex)
                                outComp.AddInterface(typeof(IMetadataExchange).GUID, null);
                        }
                        else
                        {
                            ComAdminInterfaceInfo interfaceInfo = classInfo.FindInterface(itfName);
                            if (interfaceInfo == null)
                            {
                                ToolConsole.WriteWarning(SR.GetString(SR.CannotFindInterfaceInCatalogForComponentSkipping, itfName, inComp.Component));
                                missingInterface = itfName;
                                continue;
                            }
                            if (comInterface.AllMethods)
                            {
                                if (ComPlusTypeValidator.VerifyInterface(interfaceInfo, options.AllowReferences, classInfo.Clsid, true))
                                    outComp.AddInterface(interfaceInfo.Iid, ComPlusTypeValidator.FetchAllMethodsForInterface(interfaceInfo));
                                else
                                    throw CreateException(SR.GetString(SR.InvalidInterface), null);
                            }
                            else
                            {
                                if (ComPlusTypeValidator.VerifyInterfaceMethods(interfaceInfo, comInterface.Methods, options.AllowReferences, true))
                                    outComp.AddInterface(interfaceInfo.Iid, (List<string>)comInterface.Methods);
                                else
                                    throw CreateException(SR.GetString(SR.InvalidMethod), null);
                            }

                        }
                    }

                    if ((outComp.Interfaces != null) || priorEndpointsExist)
                    {
                        if (mex)
                            outComp.AddInterface(typeof(IMetadataExchange).GUID, null);
                    }

                }
                if (outComp.Interfaces != null)
                    outComps.Add(outComp);
                else
                    ToolConsole.WriteWarning(SR.GetString(SR.NoneOfTheSpecifiedInterfacesForComponentWereFoundSkipping, inComp.Component));
            }

            if (outComps.Count == 0 && (!String.IsNullOrEmpty(missingInterface)))
                throw Tool.CreateException(SR.GetString(SR.NoComponentContainsInterface, missingInterface), null);
        }
Esempio n. 12
0
        // returns strongly typed, verified components/interfaces in an application
        static void GetAllComponentsForRemove(ComAdminAppInfo appInfo, out IList<ComponentDefinition<Guid>> outComps)
        {
            outComps = new List<ComponentDefinition<Guid>>();

            foreach (ComAdminClassInfo classInfo in appInfo.Classes)
            {
                ComponentDefinition<Guid> outComp;


                outComp = new ComponentDefinition<Guid>(classInfo.Clsid);

                foreach (ComAdminInterfaceInfo interfaceInfo in classInfo.Interfaces)
                    outComp.AddInterface(interfaceInfo.Iid, null);
                outComp.AddInterface(typeof(IMetadataExchange).GUID, null);
                outComps.Add(outComp);
            }
        }
Esempio n. 13
0
        // returns strongly typed, verified components/interfaces in an application
        static void GetAllComponentsForAdd(ComAdminAppInfo appInfo, bool mex, out IList<ComponentDefinition<Guid>> outComps)
        {
            outComps = new List<ComponentDefinition<Guid>>();

            foreach (ComAdminClassInfo classInfo in appInfo.Classes)
            {
                ComponentDefinition<Guid> outComp;

                if (!ValidateClass(classInfo))
                {
                    continue;

                }

                outComp = new ComponentDefinition<Guid>(classInfo.Clsid);

                foreach (ComAdminInterfaceInfo interfaceInfo in classInfo.Interfaces)
                {
                    if (ComPlusTypeValidator.VerifyInterface(interfaceInfo, options.AllowReferences, classInfo.Clsid))
                        outComp.AddInterface(interfaceInfo.Iid, ComPlusTypeValidator.FetchAllMethodsForInterface(interfaceInfo));
                }
                if (mex && (outComp.Interfaces != null))
                    outComp.AddInterface(typeof(IMetadataExchange).GUID, null);
                if (outComp.Interfaces != null)
                    outComps.Add(outComp);
                else
                    ToolConsole.WriteWarning(SR.GetString(SR.NoneOfTheSpecifiedInterfacesForComponentWereFoundSkipping, Tool.Options.ShowGuids ? classInfo.Clsid.ToString("B") : classInfo.Name));

            }
        }
Esempio n. 14
0
        static void ValidateApplication(ComAdminAppInfo appInfo, Hosting hosting)
        {
            if (appInfo.IsSystemApplication)
            {
                throw CreateArgumentException(Cmd.Application, appInfo.Name, SR.GetString(SR.SystemApplicationsNotSupported), null);
            }

            if (hosting == Hosting.Complus)
            {
                if (!appInfo.IsServerActivated)
                {
                    throw CreateArgumentException(Cmd.Application, appInfo.Name, SR.GetString(SR.LibraryApplicationsNotSupported), null);
                }

                if (appInfo.IsAutomaticRecycling)
                {
                    throw CreateArgumentException(Cmd.Application, appInfo.Name, SR.GetString(SR.ProcessRecyclingNotSupported), null);
                }

                if (appInfo.IsProcessPooled)
                {
                    throw CreateArgumentException(Cmd.Application, appInfo.Name, SR.GetString(SR.ProcessPoolingNotSupported), null);
                }
            }
        }