/// <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);
        }
 public ClientCodeStatus(CometWorker worker)
 {
     Events = new Dictionary<string, BrowserHelper.ClientElementEventReceived>();
     LastSend = DateTime.Now;
     LastListen = DateTime.Now;
     Worker = worker;
 }
Пример #3
0
 public ClientCodeStatus(CometWorker worker)
 {
     Events = new Dictionary<string, BrowserHelper.ClientElementEventReceived>();
     LastSend = DateTime.Now;
     LastListen = DateTime.Now;
     Worker = worker;
 }
Пример #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;
        }