Exemplo n.º 1
0
        /// <summary>
        /// Handle a message recieved to the socket.
        /// </summary>
        /// <param name="session">Web Socket Session information.</param>
        /// <param name="value">Value recieved.</param>
        /// <returns>True if the method was handled properly.</returns>
        protected override bool HandleNewMessage(WebSocketSession session, string value)
        {
            if (base.HandleNewMessage(session, value))
            {
                return(true);
            }

            Request request = JSONDataHandler.ToRequest(value);
            MethodReceivedEventArgs args = new MethodReceivedEventArgs(request);

            switch (request.MethodName)
            {
            case "startSession":
                FileLogger.Instance.LogMessage("startSession Method Recieved.");
                if (StartSessionMethodReceived != null)
                {
                    StartSessionMethodReceived(this, args);
                }
                return(true);

            default:
                FileLogger.Instance.LogMessage("Undefined Method Recieved.");
                if (UndefinedMethodReceived != null)
                {
                    UndefinedMethodReceived(this, args);
                }
                return(false);
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Send a Log Message to the Web Socket client.
        /// </summary>
        /// <param name="type">Type of the Log Message</param>
        /// <param name="message">Message Content.</param>
        /// <param name="data">Additional Data For Message.</param>
        /// <param name="ErrorMessage">Error Information for failiures.</param>
        /// <returns></returns>
        public bool SendLogMessage(string type, string message, string data)
        {
            try
            {
                FileLogger.Instance.LogMessage("Sending Log Message. Type=" + type + ". Message =" + message + ". Data =" + data);
                Dictionary <string, Hashtable> responseParams = new Dictionary <string, Hashtable>();

                Hashtable Hashmessage = new Hashtable();
                Hashtable Hashdata    = new Hashtable();

                Hashmessage.Add("Message", message);
                Hashdata.Add("Data", data);

                responseParams.Add("message", Hashmessage);
                responseParams.Add("data", Hashdata);

                Response logResponse  = new Response(type, true, responseParams);
                string   jsonResponse = JSONDataHandler.ToResponseString(logResponse);

                FileLogger.Instance.LogMessage("Sending Log Message. Raw=" + jsonResponse);
                currentSession.Send(jsonResponse);

                return(true);
            }
            catch (Exception exception)
            {
                FileLogger.Instance.LogException(exception);
                return(false);
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Send a Response to the Web Socket client.
        /// </summary>
        /// <param name="response">Response Information.</param>
        /// <param name="ErrorMessage">Error Information for failiures.</param>
        /// <returns>Returns true if message sending was successful.</returns>
        public bool SendResponse(Response response)
        {
            try
            {
                string jsonResponse = JSONDataHandler.ToResponseString(response);

                Console.WriteLine("Sending Response.");
                FileLogger.Instance.LogMessage("Sending Response. Raw=" + jsonResponse);
                currentSession.Send(jsonResponse);

                return(true);
            }
            catch (Exception exception)
            {
                FileLogger.Instance.LogException(exception);
                return(false);
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// Handle a message recieved to the socket.
        /// </summary>
        /// <param name="session">Web Socket Session information.</param>
        /// <param name="value">Value recieved.</param>
        /// <returns>True if the method was handled properly.</returns>
        protected virtual bool HandleNewMessage(WebSocketSession session, string value)
        {
            Request request = JSONDataHandler.ToRequest(value);
            MethodReceivedEventArgs args = new MethodReceivedEventArgs(request);

            switch (request.MethodName)
            {
            case "about":
                FileLogger.Instance.LogMessage("About Method Recieved.");
                if (AboutMethodReceived != null)
                {
                    AboutMethodReceived(this, args);
                }
                return(true);

            default:
                return(false);
            }
        }
 private void Start()
 {
     handler = gameObject.GetComponent <JSONDataHandler>();
     getAllHosts();
 }
Exemplo n.º 6
0
        /// <summary>
        /// Handle a message recieved to the socket.
        /// </summary>
        /// <param name="session">Web Socket Session information.</param>
        /// <param name="value">Value recieved.</param>
        /// <returns>True if the method was handled properly.</returns>
        protected override bool HandleNewMessage(WebSocketSession session, string value)
        {
            if (base.HandleNewMessage(session, value))
            {
                return(true);
            }

            Request request = JSONDataHandler.ToRequest(value);
            MethodReceivedEventArgs args = new MethodReceivedEventArgs(request);

            switch (request.MethodName)
            {
            case "getCpuAlerts":
                FileLogger.Instance.LogMessage("getCpuAlerts Method Recieved.");
                if (GetCpuAlertsMethodReceived != null)
                {
                    GetCpuAlertsMethodReceived(this, args);
                }
                return(true);

            case "getDISKUsage":
                FileLogger.Instance.LogMessage("getDISKUsage Method Recieved.");
                if (GetDiskUsageMethodReceived != null)
                {
                    GetDiskUsageMethodReceived(this, args);
                }
                return(true);

            case "getRAMUsage":
                FileLogger.Instance.LogMessage("getRAMUsage Method Recieved.");
                if (GetRamUsageMethodReceived != null)
                {
                    GetRamUsageMethodReceived(this, args);
                }
                return(true);

            case "getCPUUsage":
                FileLogger.Instance.LogMessage("getCPUUsage Method Recieved.");
                if (GetCpuUsageMethodReceived != null)
                {
                    GetCpuUsageMethodReceived(this, args);
                }
                return(true);

            case "startMonitoring":
                FileLogger.Instance.LogMessage("startMonitoring Method Recieved.");
                if (StartMonitoringMethodReceived != null)
                {
                    StartMonitoringMethodReceived(this, args);
                }
                return(true);

            default:
                FileLogger.Instance.LogMessage("Undefined Method Recieved.");
                if (UndefinedMethodReceived != null)
                {
                    UndefinedMethodReceived(this, args);
                }
                return(false);
            }
        }
Exemplo n.º 7
0
 private static List <User> ReadUsers(string file)
 {
     return(JSONDataHandler.ReadFrom <User>(file));
 }
Exemplo n.º 8
0
 private static List <Post> ReadPosts(string file)
 {
     return(JSONDataHandler.ReadFrom <Post>(file));
 }