/// <summary>
        /// Binds the specified listen URL.
        /// </summary>
        /// <param name="listenUrl">The listen URL.</param>
        /// <param name="sendUrl">The send URL.</param>
        /// <param name="page">Page object</param>
        /// <param name="classDefs">Class definition handler</param>
        /// <param name="clientId">The client id</param>
        /// <param name="cometEnabled">if set to <c>true</c> [comet enabled].</param>
        /// <returns></returns>
        public static bool Bind(string listenUrl, string sendUrl, System.Web.UI.Page page, DefineClassObjects classDefs, out string clientId, bool cometEnabled)
        {
            clientId = NewClientId;

            lock (_clients)
            {
                _clients.Add(clientId, new CometMessage());
            }

            Dictionary <string, object> classList = new Dictionary <string, object>();

            classDefs(clientId, ref classList);

            bool anyAdd = false;

            lock (DynamicCode.Definitions)
            {
                foreach (KeyValuePair <string, object> en in classList)
                {
                    object ba = en.Value;
                    DynamicCode.Definitions.Add(en.Key, ref ba, clientId);
                    anyAdd = true;
                }
                object brO = new BrowserEvents(clientId);
                DynamicCode.Definitions.Add("BrowserEvents", ref brO, clientId);
                System.Reflection.FieldInfo fi = page.GetType().GetField("PokeInSafe");
                if (fi != null)
                {
                    object br1 = page;
                    DynamicCode.Definitions.Add("MainPage", ref br1, clientId);
                }
            }

            if (!anyAdd)
            {
                page.Response.Write("<script>alert('There is no server side class!');</script>");
                return(false);
            }

            JWriter.WriteClientScript(ref page, clientId, listenUrl, sendUrl, cometEnabled);

            CometWorker worker = new CometWorker(clientId);

            lock (ClientStatus)
            {
                ClientStatus.Add(clientId, new ClientCodeStatus(worker));

                //Oguz Bastemur
                //to-do::smart threads through the core units
                if (cometEnabled)
                {
                    System.Threading.ThreadStart ts = new System.Threading.ThreadStart(ClientStatus[clientId].Worker.ClientThread);
                    ClientStatus[clientId].Worker._thread = new System.Threading.Thread(ts);
                    ClientStatus[clientId].Worker._thread.SetApartmentState(System.Threading.ApartmentState.MTA);
                    ClientStatus[clientId].Worker._thread.Start();
                }
            }

            return(true);
        }
 /// <summary>
 /// Binds the specified listen URL.
 /// </summary>
 /// <param name="listenUrl">The listen URL.</param>
 /// <param name="sendUrl">The send URL.</param>
 /// <param name="page">Page object</param>
 /// <param name="classDefs">Class definition handler</param>
 /// <param name="clientId">The client id</param>
 /// <returns></returns>
 public static bool Bind(string listenUrl, string sendUrl, System.Web.UI.Page page, DefineClassObjects classDefs, out string clientId)
 {
     return(Bind(listenUrl, sendUrl, page, classDefs, out clientId, true));
 }
 /// <summary>
 /// Binds the specified handler URL.
 /// </summary>
 /// <param name="handlerUrl">The handler URL</param>
 /// <param name="page">Page object</param>
 /// <param name="classDefs">Class definition handler</param>
 /// <param name="clientId">The client id</param>
 /// <returns></returns>
 public static bool Bind(string handlerUrl, System.Web.UI.Page page, DefineClassObjects classDefs, out string clientId)
 {
     return(Bind(handlerUrl, handlerUrl, page, classDefs, out clientId, true));
 }
Example #4
0
        /// <summary>
        /// Binds the specified listen URL.
        /// </summary>
        /// <param name="listenUrl">The listen URL.</param>
        /// <param name="sendUrl">The send URL.</param>
        /// <param name="page">Page object</param>
        /// <param name="classDefs">Class definition handler</param>
        /// <param name="clientId">The client id</param>
        /// <param name="cometEnabled">if set to <c>true</c> [comet enabled].</param>
        /// <returns></returns>
        public static bool Bind(string listenUrl, string sendUrl, System.Web.UI.Page page, DefineClassObjects classDefs, out string clientId, bool cometEnabled)
        {  
            clientId = NewClientId; 

            lock (_clients)
            {
                _clients.Add(clientId, new CometMessage());
            }

            Dictionary<string, object> classList = new Dictionary<string, object>();
            classDefs(clientId, ref classList);

            bool anyAdd = false;

            lock (DynamicCode.Definitions)
            {
                foreach (KeyValuePair<string, object> en in classList)
                {
                    object ba = en.Value;
                    DynamicCode.Definitions.Add(en.Key, ref ba, clientId);
                    anyAdd = true;
                }
                object brO = new BrowserEvents(clientId);
                DynamicCode.Definitions.Add("BrowserEvents", ref brO, clientId);
                System.Reflection.FieldInfo fi = page.GetType().GetField("PokeInSafe") ;
                if (fi != null)
                {
                    object br1 = page;
                    DynamicCode.Definitions.Add("MainPage", ref br1, clientId);
                }
            }

            if (!anyAdd)
            {
                page.Response.Write("<script>alert('There is no server side class!');</script>");
                return false;
            } 

            JWriter.WriteClientScript(ref page, clientId, listenUrl, sendUrl, cometEnabled); 

            CometWorker worker = new CometWorker(clientId);

            lock (ClientStatus)
            {
                ClientStatus.Add(clientId, new ClientCodeStatus(worker));

                //Oguz Bastemur
                //to-do::smart threads through the core units
                if (cometEnabled)
                {
                    System.Threading.ThreadStart ts = new System.Threading.ThreadStart(ClientStatus[clientId].Worker.ClientThread);
                    ClientStatus[clientId].Worker._thread = new System.Threading.Thread(ts);
                    ClientStatus[clientId].Worker._thread.SetApartmentState(System.Threading.ApartmentState.MTA);
                    ClientStatus[clientId].Worker._thread.Start();
                }
            } 
             
            return true;
        }
Example #5
0
 /// <summary>
 /// Binds the specified listen URL.
 /// </summary>
 /// <param name="listenUrl">The listen URL.</param>
 /// <param name="sendUrl">The send URL.</param>
 /// <param name="page">Page object</param>
 /// <param name="classDefs">Class definition handler</param>
 /// <param name="clientId">The client id</param>
 /// <returns></returns>
 public static bool Bind(string listenUrl, string sendUrl, System.Web.UI.Page page, DefineClassObjects classDefs, out string clientId)
 {
     return Bind(listenUrl, sendUrl, page, classDefs, out clientId, true); 
 }
Example #6
0
 /// <summary>
 /// Binds the specified handler URL.
 /// </summary>
 /// <param name="handlerUrl">The handler URL</param>
 /// <param name="page">Page object</param>
 /// <param name="classDefs">Class definition handler</param>
 /// <param name="clientId">The client id</param>
 /// <returns></returns>
 public static bool Bind(string handlerUrl, System.Web.UI.Page page, DefineClassObjects classDefs, out string clientId)
 {
     return Bind(handlerUrl, handlerUrl, page, classDefs, out clientId, true);
 }