Пример #1
0
        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));
        }
Пример #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();
        }
Пример #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);
        }
Пример #4
0
        public void GetServerTime()
        {
            string jsonMethod = JSON.Method("UpdateTime", DateTime.Now);

            CometWorker.SendToClient(_clientId, jsonMethod);
            CometWorker.SendToAll(jsonMethod);
        }
Пример #5
0
 public void playerFires(int location)
 {
     if (otherPlayerId != string.Empty)
     {
         CometWorker.SendToClient(otherPlayerId, EXTML.Method("playerShot", location));
     }
 }
Пример #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);
        }
Пример #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);
        }
Пример #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();
        }
Пример #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));
        }
Пример #10
0
        public WCFSample(string clientId)
        {
            ClientId = clientId;
            CometWorker.SendToClient(ClientId, "UpdateServiceStatus(" + ServerConnected.ToString().ToLower() + ");");

            if (ServerConnected)
            {
                proxy.AddClient(clientId);
            }
        }
Пример #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);
            }
        }
Пример #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);
        }
Пример #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()));
        }
Пример #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() + ");");
            }
        }
Пример #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);
        }
Пример #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);
        }
Пример #17
0
        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 = "";
            }
        }
Пример #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");
        }
Пример #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));
            }
        }
Пример #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);
            }
        }
Пример #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 + "';");
 }
Пример #22
0
 public void LeaveChannel()
 {
     CometWorker.Groups.UnpinClient(_clientId, "Stock1");
     CometWorker.SendToClient(_clientId, "Unpinned();");
 }
Пример #23
0
 public void ServerTime()
 {
     CometWorker.SendToClient(ClientId, JSON.Method("TimeReceived", DateTime.Now.ToLongTimeString()));
 }
Пример #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();");
 }
Пример #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 + "';");
 }
Пример #26
0
 void MsdosExited(object sender, EventArgs e)
 {
     CometWorker.SendToClient(ClientId, "ConsoleClosed();");
 }
Пример #27
0
 public void GetServerTime()
 {
     CometWorker.SendToClient(clientId, JSON.Method("ShowTime", DateTime.Now));
 }
Пример #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 + "');");
 }
Пример #29
0
        public void GetServerTime()
        {
            string msg = JSON.Method("ServerTime", DateTime.Now);

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

            CometWorker.SendToClient(clientID, str);
        }