示例#1
0
        /// <summary>
        /// Gets the direct config.
        /// </summary>
        /// <returns></returns>
        protected DextopConfig GetDirectConfig()
        {
            if (DextopApplication == null)
            {
                throw new DextopSessionNotInitializedException();
            }

            var urlFormat = DextopUtil.AbsolutePath(String.Format("{{0}}.ashx?sid={0}", SessionId));

            if (!String.IsNullOrEmpty(DextopApplication.AppKey))
            {
                urlFormat += "&app=" + DextopApplication.AppKey;
            }

            var res = new DextopConfig();

            res["remotingUrl"] = String.Format(urlFormat, "rpc");
            if (UseLongPolling)
            {
                res["longPollingUrl"] = String.Format(urlFormat, "lpoll");
            }
            else if (UsePolling)
            {
                res["pollingUrl"]      = String.Format(urlFormat, "poll");
                res["pollingInterval"] = PollingInterval;
            }
            return(res);
        }
        /// <summary>
        /// Initializes the remotable object.
        /// </summary>
        /// <param name="remote">Remote object used for communication with the client-side object.</param>
        /// <param name="config">Configuration of the object to be created on the client side.</param>
        public virtual void InitRemotable(DextopRemote remote, DextopConfig config)
        {
            Remote = remote;
            config.Add("direct", GetDirectConfig());

            var appPath = DextopEnvironment.VirtualAppPath;

            if (!appPath.EndsWith("/"))
            {
                appPath += "/";
            }

            config.Add("virtualAppPath", appPath);

            DextopConfig modules = new DextopConfig();

            foreach (var m in DextopApplication.GetModules())
            {
                var r = m.RegisterSession(this);
                if (r != null)
                {
                    modules.Add(m.ModuleName, Remote.TrackRemotableComponent(r));
                }
            }
            if (modules.Count > 0)
            {
                config.Add("modules", modules);
            }
        }
 /// <summary>
 /// Adds the remotable component. Remotable component configuration will be available on the client side.
 /// </summary>
 /// <param name="name">The name.</param>
 /// <param name="remotable">The remotable.</param>
 /// <param name="remoteId">The remote id.</param>
 /// <param name="subRemote">if set to <c>true</c> [sub remote].</param>
 /// <param name="own">if set to <c>true</c> [own].</param>
 public void AddRemotableComponent(String name, IDextopRemotable remotable, String remoteId = null, bool subRemote = true, bool own = true)
 {
     if (componentsConfig == null)
     {
         componentsConfig = new DextopConfig();
     }
     componentsConfig.Add(name, TrackRemotableComponent(remotable, remoteId, subRemote, own));
 }
示例#4
0
        /// <summary>
        /// Initializes the remotable object.
        /// </summary>
        /// <param name="remote">Remote object used for communication with the client-side object.</param>
        /// <param name="config">Configuration of the object to be created on the client side.</param>
        public void InitRemotable(DextopRemote remote, DextopConfig config)
        {
            Remote = remote;
            if (Config != null)
            {
                config.Apply(Config);
                Config = null;
            }

            remote.RemoteHostType = RemoteHostType;
        }
 /// <summary>
 /// Adds the component.
 /// </summary>
 /// <param name="name">The name.</param>
 /// <param name="o">The o.</param>
 /// <param name="own">if set to <c>true</c> component will be disposed.</param>
 public void AddComponent(String name, object o, bool own = true)
 {
     if (own && o is IDisposable)
     {
         TrackDisposable((IDisposable)o);
     }
     if (componentsConfig == null)
     {
         componentsConfig = new DextopConfig();
     }
     componentsConfig.Add(name, o);
 }
示例#6
0
 /// <summary>
 /// Initializes a new instance of the <see cref="DextopRemotableConfig"/> class.
 /// </summary>
 /// <param name="remoteHostType">Type of the remote host.</param>
 /// <param name="config">The config.</param>
 public DextopRemotableConfig(string remoteHostType, DextopConfig config)
 {
     Config         = config;
     RemoteHostType = remoteHostType;
 }
 /// <summary>
 /// Initializes the remotable object.
 /// </summary>
 /// <param name="remote">Remote object used for communication with the client-side object.</param>
 /// <param name="config">Configuration of the object to be created on the client side.</param>
 public virtual void InitRemotable(DextopRemote remote, DextopConfig config)
 {
     Remote = remote;
 }
        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;
            }
        }