Example #1
0
        internal DextopConfig Register(DextopRemote parent, IDextopRemotable remotable, String remoteId = null, bool subRemote = true)
        {
            if (remotable == null)
                throw new ArgumentNullException("remotable");

            bool isClientInitiated;

            if (remoteId == null)
            {
                remoteId = Interlocked.Increment(ref nextRemoteId).ToString();
                isClientInitiated = parent!=null && parent.IsClientInitiated;
            }
            else if (subRemote)
            {
                if (parent == null)
                    throw new DextopInternalException();
                remoteId = parent.RemoteId + '.' + remoteId;
                isClientInitiated = parent.IsClientInitiated;
            }
            else
                isClientInitiated = true;

            var context = new RemotableContext
            {
                Remotable = remotable
            };

            var remote = new DextopRemote(Context, remoteId, isClientInitiated);           

			var clientTypeName = DextopApplication.MapTypeName(remotable.GetType());

            try
            {
                var config = new DextopConfig();
                remotable.InitRemotable(remote, config);

                if (!remote.IsClientInitiated)
                {
                    DextopConfig remoteProxyConfig;
					var remoteTypeName = remote.RemoteHostType ?? clientTypeName;
                    if (remoteTypeName != null)
                    {
                        config.Add("alias", remoteTypeName);
                        remoteProxyConfig = new DextopConfig();
                        config.Add("remote", remoteProxyConfig);
                    }
                    else
                    {
                        remoteProxyConfig = config;
                    }
                    remoteProxyConfig.Add("remoteId", remoteId);
					remoteProxyConfig.Add("alias", DextopUtil.GetRemotingProxyTypeName(clientTypeName));
                    if (remote.componentsConfig != null)
                    {
                        remoteProxyConfig.Add("components", remote.componentsConfig);

                        //config not needed anymore - free memory
                        remote.componentsConfig = null;
                    }
                }

                if (!remotables.TryAdd(remoteId, context))
                    throw new DextopInternalException();

                return config;
            }
            catch
            {
                remote.Dispose();
                remotable.Dispose();
                throw;
            }

        }
        internal DextopConfig Register(DextopRemote parent, IDextopRemotable remotable, String remoteId = null, bool subRemote = true)
        {
            if (remotable == null)
            {
                throw new ArgumentNullException("remotable");
            }

            bool isClientInitiated;

            if (remoteId == null)
            {
                remoteId          = Interlocked.Increment(ref nextRemoteId).ToString();
                isClientInitiated = parent != null && parent.IsClientInitiated;
            }
            else if (subRemote)
            {
                if (parent == null)
                {
                    throw new DextopInternalException();
                }
                remoteId          = parent.RemoteId + '.' + remoteId;
                isClientInitiated = parent.IsClientInitiated;
            }
            else
            {
                isClientInitiated = true;
            }

            var context = new RemotableContext
            {
                Remotable = remotable
            };

            var remote = new DextopRemote(Context, remoteId, isClientInitiated);

            var clientTypeName = DextopApplication.MapTypeName(remotable.GetType());

            try
            {
                var config = new DextopConfig();
                remotable.InitRemotable(remote, config);

                if (!remote.IsClientInitiated)
                {
                    DextopConfig remoteProxyConfig;
                    var          remoteTypeName = remote.RemoteHostType ?? clientTypeName;
                    if (remoteTypeName != null)
                    {
                        config.Add("alias", remoteTypeName);
                        remoteProxyConfig = new DextopConfig();
                        config.Add("remote", remoteProxyConfig);
                    }
                    else
                    {
                        remoteProxyConfig = config;
                    }
                    remoteProxyConfig.Add("remoteId", remoteId);
                    remoteProxyConfig.Add("alias", DextopUtil.GetRemotingProxyTypeName(clientTypeName));
                    if (remote.componentsConfig != null)
                    {
                        remoteProxyConfig.Add("components", remote.componentsConfig);

                        //config not needed anymore - free memory
                        remote.componentsConfig = null;
                    }
                }

                if (!remotables.TryAdd(remoteId, context))
                {
                    throw new DextopInternalException();
                }

                return(config);
            }
            catch
            {
                remote.Dispose();
                remotable.Dispose();
                throw;
            }
        }