public void gotShot(string xs, string ys)
        {
            string playerId = otherPlayerId;

            CometWorker.SendToClient(playerId,
                                     EXTML.Method("playerShot:andY:andWidth:andHeight:", xs, ys, opponentSize.Width, opponentSize.Height));
        }
Example #2
0
        public void SetName(string userName)
        {
            if (_username != "")
            {
                CometWorker.SendToClient(_clientID, "alert('You already have a username!');");
                return;
            }
            lock (Names)
            {
                if (Names.ContainsKey(userName))
                {
                    CometWorker.SendToClient(_clientID, "alert('Another user is using the name you choose! Please try another one.');");
                    return;
                }
                else
                {
                    Names.Add(userName, _clientID);
                    Users.Add(_clientID, userName);
                    _username = userName;
                }
            }

            CometWorker.SendToClient(_clientID, JSON.Method("UsernameSet", PokeIn.JSON.Tidy(userName)));
            CometWorker.SendToAll(JSON.Method("AppendToChat", "<strong>" + PokeIn.JSON.Tidy(userName) + " has enterred the building!</strong>"));
            RenderMemberList();
        }
Example #3
0
        public void SendPrivateMessage(string destinationUser, string message)
        {
            string privateMessage = "<strong>" + GetUserName(_clientID) + "</strong>::" + message;
            string json           = PokeIn.JSON.Method("HandlePrivateMessage", privateMessage);

            CometWorker.SendToClient(destinationUser, json);
        }
Example #4
0
        public void GetServerTime()
        {
            string jsonMethod = JSON.Method("UpdateTime", DateTime.Now);

            CometWorker.SendToClient(_clientId, jsonMethod);
            CometWorker.SendToAll(jsonMethod);
        }
 public void playerFires(int location)
 {
     if (otherPlayerId != string.Empty)
     {
         CometWorker.SendToClient(otherPlayerId, EXTML.Method("playerShot", location));
     }
 }
Example #6
0
        static void CometWorker_OnClientCreated(string clientId)
        {
            //Client connection is done
            string message = JSON.Method("UpdateString", "Now, you are connected!");

            CometWorker.SendToClient(clientId, message);
        }
Example #7
0
        public void SetName(string userName)
        {
            if (_username != "")
            {
                CometWorker.SendToClient(_clientId, "alert('You already have a username!');btnChat.disabled = '';");
                return;
            }

            lock (Names)
            {
                if (Names.ContainsKey(userName))
                {
                    Names[userName] = _clientId;
                }
                else
                {
                    Names.Add(userName, _clientId);
                    Users.Add(_clientId, userName);
                }
            }
            _username = userName;

            //Create JSON Method
            string json = JSON.Method("UsernameSet", userName);//UsernameSet('UserName');

            CometWorker.SendToClient(_clientId, json);
        }
Example #8
0
        //Client side calls this method to mark his status and start listen for his events
        public void StartListenForEvents()
        {
            string sessionId = CometWorker.GetSessionId(ClientId);

            //to make consistent log-in process lock the user status
            lock (MessageBroker.PreUserDefinitions)
            {
                string userName;
                MessageBroker.SessionUserPair.TryGetValue(sessionId, out userName);

                if (userName == null)//User Session Lost
                {
                    PokeIn.Comet.BrowserHelper.RedirectPage(ClientId, "/Sample/Home");
                    return;
                }

                MessageBroker.PreUserDefinitions.TryGetValue(userName, out userDefinition);
            }

            string jsonMethod = PokeIn.JSON.Method("SetTitle", "Hello " + userDefinition.Username + "! ");

            CometWorker.SendToClient(ClientId, jsonMethod);


            //Call Role Based User Initializitation
            InitializeUser();
        }
Example #9
0
        static void CometWorker_FileUploadRequested(ref HttpFile file)
        {
            string fileName = file.ServerMapPath + "\\Upload\\" + file.FileName;

            file.SaveAs(fileName);
            string resourceName = file.FileName.Replace("&", "_");

            ResourceManager.AddReplaceResource(fileName, resourceName, ResourceType.Image, file.ClientId);
            CometWorker.SendToClient(file.ClientId, JSON.Method("ShowImage", resourceName));
        }
Example #10
0
        public WCFSample(string clientId)
        {
            ClientId = clientId;
            CometWorker.SendToClient(ClientId, "UpdateServiceStatus(" + ServerConnected.ToString().ToLower() + ");");

            if (ServerConnected)
            {
                proxy.AddClient(clientId);
            }
        }
Example #11
0
        protected override void InitializeUser()
        {
            //Admin screen might be open on different browsers or machines
            UsersPool.AdminClientIDs.Add(ClientId);//Admin logged in

            //let him know for waiting user requests
            lock (UsersPool.Requests)
            {
                string jsonMethod = PokeIn.JSON.Method("RequestList", UsersPool.Requests);
                CometWorker.SendToClient(ClientId, jsonMethod);
            }
        }
Example #12
0
        public void ClassTest(TestClass tc, DateTime dt)
        {
            string message = "";

            if (IsDesktop)
            {
                message = EXTML.Method("TestClassReceived", tc.number, tc.items.Count, tc.text, dt.ToShortDateString());
            }
            else
            {
                message = JSON.Method("TestClassReceived", tc.number, tc.items.Count, tc.text, dt.ToShortDateString());
            }
            CometWorker.SendToClient(ClientId, message);
        }
Example #13
0
        //First OnClientCreated Event Handler Called By Default.aspx
        public static void OnClientCreatedToFirst(string ClientId)
        {
            //reading data from session
            object   obj = CometWorker.ReadSessionObject("openingTime");
            DateTime dt  = DateTime.MinValue;

            if (obj != null)
            {
                dt = (DateTime)obj;
            }

            //Do not send a message to the client during its OnClientConnected phase.
            //Instead use this event in order to start sending messages
            CometWorker.SendToClient(ClientId, JSON.Method("s", "OnClientCreatedToFirst event is fired, page loaded at" + dt.ToLongTimeString()));
        }
Example #14
0
        //Event Fired!
        void AdminSent(string userName)
        {
            if (userName == userDefinition.Username)
            {
                //update our definition
                MessageBroker.PreUserDefinitions.TryGetValue(userName, out userDefinition);

                int countLeft = 0;
                lock (UsersPool.Requests)
                {
                    UsersPool.Requests.TryGetValue(userDefinition.Username, out countLeft);
                }

                CometWorker.SendToClient(ClientId, "AdminSentApple(" + userDefinition.Apples.ToString() + "," + countLeft.ToString() + ");");
            }
        }
Example #15
0
        public void UnSubscribe()
        {
            CometWorker.Groups.UnpinClient(ClientId);
            string message = "";

            if (IsDesktop)
            {
                message = EXTML.Method("UnSubscribed");
            }
            else
            {
                message = JSON.Method("UnSubscribed");
            }

            CometWorker.SendToClient(ClientId, message);
        }
Example #16
0
        public void Subscribe()
        {
            string message = "";

            if (IsDesktop)
            {
                CometWorker.Groups.PinClientID(ClientId, "ServerTime-Desktop");
                message = EXTML.Method("Subscribed");
            }
            else
            {
                CometWorker.Groups.PinClientID(ClientId, "ServerTime-Web");
                message = JSON.Method("Subscribed");
            }

            CometWorker.SendToClient(ClientId, message);
        }
        public void leaveRoom()
        {
            lock (sessionKeys)
            {
                sessionKeys.Remove(details.ClientId);
            }

            lock (waitingRoom)
            {
                waitingRoom.Remove(details.ClientId);
            }

            if (otherPlayerId != string.Empty)
            {
                CometWorker.SendToClient(otherPlayerId, EXTML.Method("PlayerLeft"));
                otherPlayerId = "";
            }
        }
Example #18
0
        /// <summary>
        /// Sets a server side function target for an event of client element
        /// </summary>
        /// <param name="clientId">The client id.</param>
        /// <param name="elementId">The element id.</param>
        /// <param name="eventName">Name of the event.</param>
        /// <param name="eventTarget">The event target.</param>
        /// <param name="returnValue">The return value.</param>
        public static void SetElementEvent(string clientId, string elementId, string eventName, ClientElementEventReceived eventTarget, string returnValue)
        {
            string fakeId     = elementId.ToLower().Trim();
            string objectType = "document.getElementById('" + elementId + "')";

            if (fakeId == "body" || fakeId == "window" || fakeId == "document" || fakeId == "document.body")
            {
                if (fakeId == "body")
                {
                    fakeId = "document.body";
                }
                objectType = fakeId;
            }
            string simpleName = elementId + "_" + eventName;

            bool hasClient;

            lock (CometWorker.ClientStatus)
            {
                hasClient = CometWorker.ClientStatus.ContainsKey(clientId);
            }
            if (hasClient)
            {
                lock (CometWorker.ClientStatus[clientId])
                {
                    if (CometWorker.ClientStatus[clientId].Events.ContainsKey(simpleName))
                    {
                        CometWorker.ClientStatus[clientId].Events.Remove(simpleName);
                    }
                    CometWorker.ClientStatus[clientId].Events.Add(simpleName, eventTarget);
                }
            }

            if (returnValue.Trim().Length == 0)
            {
                returnValue = "\"\"";
            }

            CometWorker.SendToClient(clientId, @"
            document.__" + simpleName + " = function(ev){PokeIn.Send(PokeIn.GetClientId()+'.BrowserEvents.Fired("
                                     + elementId + "," + eventName + "," + returnValue + ");'); };function c3eb(){var _item = "
                                     + objectType + "; PokeIn.AddEvent(_item, '" + eventName + "', document.__"
                                     + simpleName + ");}" + "\nc3eb();\n");
        }
Example #19
0
        public void DeleteFilesInFolder()
        {
            int fileCount = 0;

            try
            {
                string[] files = System.IO.Directory.GetFiles(FilePath + "\\Upload");
                fileCount = files.Length;
                foreach (string file in files)
                {
                    System.IO.File.Delete(file);
                }
            }
            catch (Exception e)
            {
                CometWorker.SendToClient(ClientID, JSON.Method("Error", e.Message));
            }
            finally
            {
                CometWorker.SendToClient(ClientID, JSON.Method("FilesDeleted", fileCount));
            }
        }
Example #20
0
        private void MsdosOutputDataReceived(object sender, DataReceivedEventArgs e)
        {
            if (e.Data != null && !disposed)
            {
                if (e.Data.EndsWith(">cd"))
                {
                    addNext = true;
                    return;
                }
                string command = e.Data;
                if (addNext) // cd called
                {
                    command += ">";
                    addNext  = false;
                }

                command = JSON.Method("ConsoleUpdated", command);
                command = command.Replace("<", "&lt;");
                command = command.Replace(">", "&gt;");
                CometWorker.SendToClient(ClientId, command);
            }
        }
Example #21
0
 /// <summary>
 /// Sets a property of a client element
 /// </summary>
 /// <param name="clientId">The client id</param>
 /// <param name="domElementId">The DOM element id</param>
 /// <param name="propertyName">Name of the property</param>
 /// <param name="value">Element value</param>
 public static void SetElementProperty(string clientId, string domElementId, string propertyName, string value)
 {
     CometWorker.SendToClient(clientId, "document.getElementById('" + domElementId + "')."
                              + propertyName + "='" + value + "';");
 }
Example #22
0
 public void LeaveChannel()
 {
     CometWorker.Groups.UnpinClient(_clientId, "Stock1");
     CometWorker.SendToClient(_clientId, "Unpinned();");
 }
Example #23
0
 public void ServerTime()
 {
     CometWorker.SendToClient(ClientId, JSON.Method("TimeReceived", DateTime.Now.ToLongTimeString()));
 }
Example #24
0
 //it is not important how many client is listening for this channel. Let PokeIn manage the messages
 //please notice that the FREE edition of PokeIn supports up to 10 concurrent connection
 //Get Commercial edition to break the limits
 public void JoinChannel()
 {
     CometWorker.Groups.PinClientID(_clientId, "Stock1");
     CometWorker.SendToClient(_clientId, "Pinned();");
 }
Example #25
0
 /// <summary>
 /// Redirects the page.
 /// </summary>
 /// <param name="clientId">The client id.</param>
 /// <param name="url">The URL.</param>
 public static void RedirectPage(string clientId, string url)
 {
     CometWorker.SendToClient(clientId, "PokeIn.Close();\nself.location='" + url + "';");
 }
Example #26
0
 void MsdosExited(object sender, EventArgs e)
 {
     CometWorker.SendToClient(ClientId, "ConsoleClosed();");
 }
Example #27
0
 public void GetServerTime()
 {
     CometWorker.SendToClient(clientId, JSON.Method("ShowTime", DateTime.Now));
 }
Example #28
0
 public void TestString(string str)
 {
     str = JSON.Tidy(str);//to make sure that the string is ready for proper transfer
     CometWorker.SendToClient(_clientId, "UpdateString('" + str + "');");
     CometWorker.SendToAll("UpdateString('" + str + "');");
 }
Example #29
0
        public void GetServerTime()
        {
            string msg = JSON.Method("ServerTime", DateTime.Now);

            CometWorker.SendToClient(_clientID, msg);
        }
Example #30
0
        public void GetTime()
        {
            string str = JSON.Method("UpdateTime", DateTime.Now.ToLongTimeString() + " Poked!");

            CometWorker.SendToClient(clientID, str);
        }