public override IMessage Invoke(IMessage reqMsg)
        {
            this.AssertValid();
            IMessage message = null;

            if (reqMsg is IConstructionCallMessage)
            {
                if (((IConstructionCallMessage)reqMsg).ArgCount > 0)
                {
                    throw new ServicedComponentException(Resource.FormatString("ServicedComponentException_ConstructorArguments"));
                }
                MarshalByRefObject transparentProxy = (MarshalByRefObject)this.GetTransparentProxy();
                return(EnterpriseServicesHelper.CreateConstructionReturnMessage((IConstructionCallMessage)reqMsg, transparentProxy));
            }
            MethodBase methodBase = ((IMethodMessage)reqMsg).MethodBase;
            MemberInfo mi         = methodBase;

            if (methodBase == _getTypeMethod)
            {
                IMethodCallMessage mcm = (IMethodCallMessage)reqMsg;
                return(new ReturnMessage(this.ProxiedType, null, 0, mcm.LogicalCallContext, mcm));
            }
            if (methodBase == _getHashCodeMethod)
            {
                int hashCode = this.GetHashCode();
                IMethodCallMessage message3 = (IMethodCallMessage)reqMsg;
                return(new ReturnMessage(hashCode, null, 0, message3.LogicalCallContext, message3));
            }
            if (methodBase == _isInstanceOfTypeMethod)
            {
                IMethodCallMessage message4 = (IMethodCallMessage)reqMsg;
                Type inArg = (Type)message4.GetInArg(0);
                return(new ReturnMessage(inArg.IsInstanceOfType(this.ProxiedType), null, 0, message4.LogicalCallContext, message4));
            }
            MemberInfo m = ReflectionCache.ConvertToClassMI(this.ProxiedType, mi);

            try
            {
                int num2;
                if ((this._fUseIntfDispatch || (((num2 = ServicedComponentInfo.MICachedLookup(m)) & 4) != 0)) || ((num2 & 8) != 0))
                {
                    MemberInfo info3 = ReflectionCache.ConvertToInterfaceMI(mi);
                    if (info3 == null)
                    {
                        throw new ServicedComponentException(Resource.FormatString("ServicedComponentException_SecurityMapping"));
                    }
                    MethodCallMessageWrapperEx ex = new MethodCallMessageWrapperEx((IMethodCallMessage)reqMsg, (MethodBase)info3);
                    message = RemotingServices.ExecuteMessage((MarshalByRefObject)this._server, ex);
                }
                else
                {
                    string          str2;
                    bool            flag     = (num2 & 2) != 0;
                    string          s        = ComponentServices.ConvertToString(reqMsg);
                    IRemoteDispatch dispatch = (IRemoteDispatch)this._server;
                    if (flag)
                    {
                        str2 = dispatch.RemoteDispatchAutoDone(s);
                    }
                    else
                    {
                        str2 = dispatch.RemoteDispatchNotAutoDone(s);
                    }
                    message = ComponentServices.ConvertToReturnMessage(str2, reqMsg);
                }
            }
            catch (COMException exception)
            {
                if ((exception.ErrorCode != -2147164158) && (exception.ErrorCode != -2147164157))
                {
                    throw;
                }
                if (!this.IsDisposeRequest(reqMsg))
                {
                    throw;
                }
                IMethodCallMessage message5 = reqMsg as IMethodCallMessage;
                message = new ReturnMessage(null, null, 0, message5.LogicalCallContext, message5);
            }
            if (this.IsDisposeRequest(reqMsg))
            {
                this.Dispose(true);
            }
            return(message);
        }
Ejemplo n.º 2
0
        internal static void InstallUtilityApplication(Type t)
        {
            DBG.Info(DBG.Registration, "Starting utility installation:");

            try
            {
                if (Platform.IsLessThan(Platform.W2K))
                {
                    return;
                }

                ICatalog           cat  = null;
                ICatalogCollection apps = null;
                ICatalogObject     app  = null;
                int junk = 0;

                cat = (ICatalog)(new xCatalog());

                if (!Platform.IsLessThan(Platform.Whistler))
                {
                    // AS/URT 97116:  Keep this from failing the install if
                    // we're on a Beta2 Whistler machine, which has a different
                    // GUID for ICatalog2.
                    ICatalog2 cat2 = cat as ICatalog2;

                    if (cat2 != null)
                    {
                        cat2.CurrentPartition(cat2.GlobalPartitionID());
                    }
                }

                apps = (ICatalogCollection)(cat.GetCollection("Applications"));
                RegistrationDriver.Populate(apps);

                app = FindApplication(apps, _appid, ref junk);
                if (app == null)
                {
                    DBG.Info(DBG.Registration, "Didn't find existing application...");
                    app = (ICatalogObject)(apps.Add());
                    app.SetValue("Name", _appname);
                    app.SetValue("Activation", ActivationOption.Library);
                    app.SetValue("ID", "{" + _appid.ToString() + "}");
                    if (!Platform.IsLessThan(Platform.Whistler))
                    {
                        // AS/URT 97116:  Keep this from failing the install if
                        // we're on a Beta2 Whistler machine, which has no Replicable property.
                        try
                        {
                            app.SetValue("Replicable", 0);
                        }
                        catch (Exception) {}
                    }
                    apps.SaveChanges();
                }
                else
                {
                    // Make sure that we can change this puppy:
                    app.SetValue("Changeable", true);
                    app.SetValue("Deleteable", true);
                    apps.SaveChanges();
                    app.SetValue("Name", _appname);
                    if (!Platform.IsLessThan(Platform.Whistler))
                    {
                        // AS/URT 97116:  Keep this from failing the install if
                        // we're on a Beta2 Whistler machine, which has no Replicable property.
                        try
                        {
                            app.SetValue("Replicable", 0);
                        }
                        catch (Exception) {}
                    }
                    apps.SaveChanges();
                }

                // Import ourselves into the application:
                Guid clsid = Marshal.GenerateGuidForType(typeof(RegistrationHelperTx));
                ICatalogCollection comps = (ICatalogCollection)(apps.GetCollection("Components", app.Key()));
                ICatalogObject     comp  = FindComponent(comps, clsid, ref junk);
                if (comp == null)
                {
                    cat.ImportComponent("{" + _appid + "}", "{" + clsid + "}");
                    comps = (ICatalogCollection)(apps.GetCollection("Components", app.Key()));
                    comp  = FindComponent(comps, clsid, ref junk);
                }
                DBG.Assert(comp != null, "Couldn't find imported component!");

                ConfigureComponent(comps, comp);

                // And finally, lock this guy down:
                app.SetValue("Changeable", false);
                app.SetValue("Deleteable", false);
                apps.SaveChanges();

                DBG.Info(DBG.Registration, "Registering Proxy/Stub dlls:");
                Thunk.Proxy.RegisterProxyStub();


                // HACK
                // This is a HACK to get Windows XP Client COM+ export/import functionallity to work.
                // Export code will try to export System.EnterpriseServices.Thunk.dll because its not in it's
                // list of non-redist dlls.
                // We should get rid of this once this name is in the harcoded list in the export code.
                RegistryPermission rp = new RegistryPermission(PermissionState.Unrestricted);
                rp.Demand();
                rp.Assert();

                RegistryKey rk = Registry.LocalMachine.CreateSubKey("SOFTWARE\\MICROSOFT\\OLE\\NONREDIST");
                rk.SetValue("System.EnterpriseServices.Thunk.dll", "");
                rk.Close();
                // END HACK
            }
            catch (Exception e)
            {
                // Log a failure in some acceptable manner.
                try
                {
                    EventLog appLog = new EventLog();
                    appLog.Source = "System.EnterpriseServices";
                    String errMsg = String.Format(Resource.FormatString("Reg_ErrInstSysEnt"), e);
                    appLog.WriteEntry(errMsg, EventLogEntryType.Error);
                }
                catch
                {}

                // We threw an exception?  What do we do here?
                //DBG.Assert(false,
                //           "Installation of System.EnterpriseServices threw an exception!",
                //           "Exception: " + e);
            }
        }
Ejemplo n.º 3
0
        internal static void UninstallUtilityApplication(Type t)
        {
            DBG.Info(DBG.Registration, "Starting utility uninstallation:");

            try
            {
                if (Platform.IsLessThan(Platform.W2K))
                {
                    return;
                }

                ICatalog           cat  = null;
                ICatalogCollection apps = null;
                ICatalogObject     app  = null;
                int appidx = 0;

                cat = (ICatalog)(new xCatalog());

                if (!Platform.IsLessThan(Platform.Whistler))
                {
                    // AS/URT 97116:  Keep this from failing the install if
                    // we're on a Beta2 Whistler machine, which has a different
                    // GUID for ICatalog2.
                    ICatalog2 cat2 = cat as ICatalog2;
                    if (cat2 != null)
                    {
                        cat2.CurrentPartition(cat2.GlobalPartitionID());
                    }
                }

                apps = (ICatalogCollection)(cat.GetCollection("Applications"));
                RegistrationDriver.Populate(apps);

                app = FindApplication(apps, _appid, ref appidx);
                if (app != null)
                {
                    // Make sure that we can change this puppy:
                    app.SetValue("Changeable", true);
                    app.SetValue("Deleteable", true);
                    apps.SaveChanges();

                    DBG.Info(DBG.Registration, "Found application!");
                    int  idx = 0, compcount = 0;
                    Guid clsid = Marshal.GenerateGuidForType(typeof(RegistrationHelperTx));
                    ICatalogCollection comps = (ICatalogCollection)(apps.GetCollection("Components", app.Key()));
                    ICatalogObject     comp  = FindComponent(comps, clsid, ref idx);
                    // Store count here, if it is 1, we can delete the app later.
                    compcount = comps.Count();
                    if (comp != null)
                    {
                        DBG.Info(DBG.Registration, "Found component at " + idx);
                        comps.Remove(idx);
                        comps.SaveChanges();
                    }

                    if (comp != null && compcount == 1)
                    {
                        DBG.Info(DBG.Registration, "Removing .NET Utilities application.");
                        // we removed the last component, kill the app
                        apps.Remove(appidx);
                        apps.SaveChanges();
                    }
                    else
                    {
                        // Make sure that we can't change the app:
                        app.SetValue("Changeable", false);
                        app.SetValue("Deleteable", false);
                        apps.SaveChanges();
                    }
                }
            }
            catch (Exception e)
            {
                // Log a failure in some acceptable manner.
                try
                {
                    EventLog appLog = new EventLog();
                    appLog.Source = "System.EnterpriseServices";
                    String errMsg = String.Format(Resource.FormatString("Reg_ErrUninstSysEnt"), e);
                    appLog.WriteEntry(errMsg, EventLogEntryType.Error);
                }
                catch
                {}

                // We threw an exception?  What do we do here?
                //DBG.Assert(false,
                //           "Installation of System.EnterpriseServices threw an exception!",
                //           "Exception: " + e);
                DBG.Info(DBG.Registration, "Caught exception: " + e);
            }
        }
        public override MarshalByRefObject CreateInstance(Type serverType)
        {
            RealProxy          realProxy        = null;
            MarshalByRefObject transparentProxy = null;

            ServicedComponentProxy.CleanupQueues(false);
            if ((RemotingConfiguration.IsWellKnownClientType(serverType) != null) || (RemotingConfiguration.IsRemotelyActivatedClientType(serverType) != null))
            {
                transparentProxy = base.CreateInstance(serverType);
                realProxy        = RemotingServices.GetRealProxy(transparentProxy);
            }
            else
            {
                bool   bIsAnotherProcess = false;
                string uri   = "";
                bool   flag2 = ServicedComponentInfo.IsTypeEventSource(serverType);
                IntPtr pUnk  = Proxy.CoCreateObject(serverType, !flag2, ref bIsAnotherProcess, ref uri);
                if (pUnk != IntPtr.Zero)
                {
                    try
                    {
                        if (flag2)
                        {
                            realProxy        = new RemoteServicedComponentProxy(serverType, pUnk, true);
                            transparentProxy = (MarshalByRefObject)realProxy.GetTransparentProxy();
                        }
                        else
                        {
                            bool flag3 = (RemotingConfiguration.IsWellKnownClientType(serverType) != null) || (null != RemotingConfiguration.IsRemotelyActivatedClientType(serverType));
                            if (bIsAnotherProcess && !flag3)
                            {
                                FastRSCPObjRef objectRef = new FastRSCPObjRef(pUnk, serverType, uri);
                                transparentProxy = (MarshalByRefObject)RemotingServices.Unmarshal(objectRef);
                            }
                            else
                            {
                                transparentProxy = (MarshalByRefObject)Marshal.GetObjectForIUnknown(pUnk);
                                if (!serverType.IsInstanceOfType(transparentProxy))
                                {
                                    throw new InvalidCastException(Resource.FormatString("ServicedComponentException_UnexpectedType", serverType, transparentProxy.GetType()));
                                }
                                realProxy = RemotingServices.GetRealProxy(transparentProxy);
                                if ((!bIsAnotherProcess && !(realProxy is ServicedComponentProxy)) && !(realProxy is RemoteServicedComponentProxy))
                                {
                                    ((ServicedComponent)transparentProxy).DoSetCOMIUnknown(pUnk);
                                }
                            }
                        }
                    }
                    finally
                    {
                        Marshal.Release(pUnk);
                    }
                }
            }
            if (realProxy is ServicedComponentProxy)
            {
                ServicedComponentProxy proxy2 = (ServicedComponentProxy)realProxy;
                if (proxy2.HomeToken == Proxy.GetCurrentContextToken())
                {
                    proxy2.FilterConstructors();
                }
            }
            return(transparentProxy);
        }