/// <summary>
        /// Return the HashCode of this object.
        /// </summary>
        /// <returns>The HashCode of this object.</returns>
        public override Int32 GetHashCode()
        {
            unchecked
            {
                return(RequestedMessage.GetHashCode() * 5 ^

                       (ConnectorId.HasValue
                            ? ConnectorId.GetHashCode()
                            : 0));
            }
        }
        /// <summary>
        /// Return a XML representation of this object.
        /// </summary>
        public XElement ToXML()

        => new XElement(OCPPNS.OCPPv1_6_CP + "triggerMessageRequest",

                        new XElement(OCPPNS.OCPPv1_6_CP + "requestedMessage", RequestedMessage.AsText()),

                        ConnectorId.HasValue
                       ? new XElement(OCPPNS.OCPPv1_6_CP + "connectorId", ConnectorId.ToString())
                       : null

                        );
        /// <summary>
        /// Compares two TriggerMessage requests for equality.
        /// </summary>
        /// <param name="TriggerMessageRequest">A TriggerMessage request to compare with.</param>
        /// <returns>True if both match; False otherwise.</returns>
        public override Boolean Equals(TriggerMessageRequest TriggerMessageRequest)
        {
            if (TriggerMessageRequest is null)
            {
                return(false);
            }

            return(RequestedMessage.Equals(TriggerMessageRequest.RequestedMessage) &&

                   (!ConnectorId.HasValue && !TriggerMessageRequest.ConnectorId.HasValue) ||
                   (ConnectorId.HasValue && TriggerMessageRequest.ConnectorId.HasValue && ConnectorId.Equals(TriggerMessageRequest.ConnectorId)));
        }
        /// <summary>
        /// Return a JSON representation of this object.
        /// </summary>
        /// <param name="CustomTriggerMessageRequestSerializer">A delegate to serialize custom TriggerMessage requests.</param>
        public JObject ToJSON(CustomJObjectSerializerDelegate <TriggerMessageRequest> CustomTriggerMessageRequestSerializer)
        {
            var JSON = JSONObject.Create(

                new JProperty("requestedMessage", RequestedMessage.AsText()),

                ConnectorId.HasValue
                               ? new JProperty("connectorId", ConnectorId.Value.Value)
                               : null

                );

            return(CustomTriggerMessageRequestSerializer != null
                       ? CustomTriggerMessageRequestSerializer(this, JSON)
                       : JSON);
        }
Exemplo n.º 5
0
    void GetResponce()
    {
        //Debug.Log("MessageListRequestClient.GetResponce");
        bool disconnected = false;

        NetworkStream serverStream = client.GetStream();

        byte[] messageStrLengthBytes = new byte[MESSAGE_LIST_LENGTH_BYTE_NUM];
        var    totalReadBytesLength  = 0;

        do
        {
            var read = serverStream.Read(messageStrLengthBytes, totalReadBytesLength, MESSAGE_LIST_LENGTH_BYTE_NUM - totalReadBytesLength);
            totalReadBytesLength += read;
        } while (totalReadBytesLength != MESSAGE_LIST_LENGTH_BYTE_NUM);

        int messageStrLength = BitConverter.ToInt32(messageStrLengthBytes, 0);
        //Debug.Log("messageStrLength: " + messageStrLength);

        string requestedMessagesStr = "";


        byte[] buffer = new byte[1024];
        totalReadBytesLength = 0;
        using (MemoryStream ms = new MemoryStream())
        {
            int readBytesLength;
            while (true)
            {
                readBytesLength       = serverStream.Read(buffer, 0, buffer.Length);
                totalReadBytesLength += readBytesLength;
                ms.Write(buffer, 0, readBytesLength);
                //Debug.Log("totalReadBytesLength: " + totalReadBytesLength);
                if (totalReadBytesLength >= messageStrLength)
                {
                    break;
                }
            }

            requestedMessagesStr = Encoding.ASCII.GetString(ms.ToArray(), 0, (int)ms.Length);
        }

        //Debug.Log("requestedMessagesStr:"+ requestedMessagesStr);
        if (requestedMessagesStr == " ")
        {
            UnityMainThreadDispatcher.Instance().Enqueue(() =>
            {
                GUIManager.Instance.messageListPanelController.logText.text       = "No alert record yet :)";
                GUIManager.Instance.messageListPanelController.syncButton.enabled = true;
            });
            return;
        }
        //Debug.Log("requestedMessagesStr:" + requestedMessagesStr);
        CultureInfo enUS = new CultureInfo("en-US");

        string[] requestedMessageStrs = requestedMessagesStr.Split('|');
        for (int i = 0; i < requestedMessageStrs.Length; i++)
        {
            //Debug.Log("requestedMessageStrs[i]:" + requestedMessageStrs[i]);
            RequestedMessage requestedMessage = JsonUtility.FromJson <RequestedMessage>(requestedMessageStrs[i]);

            DataManager.Instance.AddMessage(requestedMessage.v,
                                            requestedMessage.f,
                                            DateTime.ParseExact(requestedMessage.t, "yyyy,M,d,H,m,s", enUS, DateTimeStyles.None).ToString("dd-MMM-yyyy HH:mm:ss"),
                                            DateTime.Now.ToString("dd-MMM-yyyy HH:mm:ss"));
        }


        if (!disconnected)
        {
            UnityMainThreadDispatcher.Instance().Enqueue(() =>
            {
                GUIManager.Instance.messageListPanelController.logText.text = "";
                GUIManager.Instance.messageListPanelController.AddButtons();
                //GUIManager.Instance.messageListPanelController.syncButton.enabled = true;
            });
        }
    }