Example #1
0
        public bool Connected()
        {
            // The request to send
            Message request = new Message(Keyword.Ping, this.Name, null);

            // The reply received
            object reply = this.clientFrontEnd.SendRequest(request, 5000);

            // If it was a timeout
            if (reply == null) {
                return false;
            }

            // If it was a valid reply
            if (reply is Message) {
                return true;
            }

            // The server should never send invalid replys, because the request-reply classes ensures that the received reply is a reply for this request
            Contract.Assert(false);
            return false;
        }
Example #2
0
        /// <summary>
        /// May I have all information about the person with this cpr. nr.?
        /// </summary>
        /// <param name="cpr">The cpr number of the person</param>
        /// <returns>The person</returns>
        public Person GetPersonFromCpr(int cpr)
        {
            Contract.Ensures(this.Connected() ? Contract.Result<Person>() != null : Contract.Result<Person>() == null);

            // The request to send
            Message request = new Message(Keyword.GetPersonFromCpr, this.Name, cpr);

            // The reply received
            object reply = this.clientFrontEnd.SendRequest(request, 5000);

            // If it was a timeout
            if (reply == null) {
                return null;
            }

            // If it was a valid reply
            if (reply is Message && ((Message)reply).GetValue is Person) {
                Message replyMessage = (Message) reply;
                return (Person)replyMessage.GetValue;
            }

            // The server should never send invalid replys, because the request-reply classes ensures that the received reply is a reply for this request
            Contract.Assert(false);
            return null;
        }
Example #3
0
        /// <summary>
        /// What are the valid tables for this server?
        /// </summary>
        /// <returns></returns>
        public string[] ValidTables()
        {
            Contract.Ensures(!this.Connected() ? Contract.Result<string[]>() == null : true);

            // The request to send
            Message request = new Message(Keyword.ValidTables, this.Name, null);

            // The reply received
            object reply = this.clientFrontEnd.SendRequest(request, 5000);

            // If it was a timeout
            if (reply == null) {
                return null;
            }

            // If it was a valid reply
            if (reply is Message && ((Message)reply).GetValue is string[]) {
                Message replyMessage = (Message)reply;
                return (string[])replyMessage.GetValue;
            }

            // The server should never send invalid replys, because the request-reply classes ensures that the received reply is a reply for this request
            Contract.Assert(false);
            return null;
        }
Example #4
0
        /// <summary>
        /// Unregister that this voter has voted
        /// </summary>
        /// <param name="person">The id of the voter</param>
        /// <returns>If the voter was unregistered</returns>
        public bool UnregisterVoter(Person person)
        {
            Contract.Requires(person != null);
            Contract.Ensures(this.Connected() ? true : Contract.Result<bool>() == false);

            // The request to send
            Message request = new Message(Keyword.UnregisterVoter, this.Name, person);

            // The reply received
            object reply = this.clientFrontEnd.SendRequest(request, 5000);

            // If it was a timeout
            if (reply == null) {
                return false;
            }

            // If it was a valid reply
            if (reply is Message && ((Message)reply).GetValue is bool) {
                Message replyMessage = (Message)reply;
                return (bool)replyMessage.GetValue;
            }

            // The server should never send invalid replys, because the request-reply classes ensures that the received reply is a reply for this request
            Contract.Assert(false);
            return false;
        }