Version 0.5 hAPI MessageOption. For more info, see Hubiquitus reference
Exemplo n.º 1
0
        private HMessage InnerBuildMessage(string actor, string type, JToken payload, HMessageOptions mOptions)
        {
            if (actor == null || actor.Length <= 0)
                throw new MissingAttrException("actor");

            HMessage message = new HMessage();
            message.SetActor(actor);
            message.SetType(type);
            if (mOptions != null)
            {
                message.SetRef(mOptions.Ref);
                message.SetConvid(mOptions.Convid);
                message.SetPriority(mOptions.Priority);
                message.SetAuthor(mOptions.Author);
                message.SetHeaders(mOptions.Headers);
                message.SetLocation(mOptions.Location);
                message.SetPublished(mOptions.Published);
                message.SetPersistent(mOptions.Persistent);
                message.SetTimeout(mOptions.Timeout);
                if (mOptions.RelevanceOffset != null)
                {
                    Debug.WriteLine("----   " + mOptions.RelevanceOffset);
                    message.SetRelevance((DateTime.UtcNow).AddMilliseconds(mOptions.RelevanceOffset.Value));
                    Debug.WriteLine("++++   " + message.GetRelevance());
                }
                else
                    message.SetRelevance(mOptions.Relevance);
            }
            if (transportOptions != null && transportOptions.Login != null)
                message.SetPublisher(transportOptions.FullUrn);
            else
                message.SetPublisher(null);
            message.SetPayload(payload);
            return message;
        }
Exemplo n.º 2
0
        //---private methods---
        private HMessage InnerBuildResult(string actor, string @ref, ResultStatus? status, JToken result, HMessageOptions mOptions)
        {
            if (actor == null || actor.Length <= 0)
                throw new MissingAttrException("actor");
            if (@ref == null || @ref.Length <= 0)
                throw new MissingAttrException("ref");
            if (status == null)
                throw new MissingAttrException("status");

            HResult hResult = new HResult();
            hResult.SetResult(result);
            hResult.SetStatus(status);
            if (mOptions == null)
                mOptions = new HMessageOptions();
            mOptions.Ref = @ref;

            return BuildMessage(actor, "hResult", hResult, mOptions);
        }
Exemplo n.º 3
0
 public HMessage BuildMessage(string actor, string type, HResult payload, HMessageOptions mOptions)
 {
     return InnerBuildMessage(actor, type, payload, mOptions);
 }
Exemplo n.º 4
0
 public HMessage BuildResult(string actor, string @ref, ResultStatus status, double result, HMessageOptions mOptions)
 {
     return InnerBuildResult(actor, @ref, status, result, mOptions);
 }
Exemplo n.º 5
0
        /// <summary>
        /// The client MUST be connected to access to this service.
        /// Allow a hubapp client to create a hMessage with a hConvState payload.
        /// </summary>
        /// <param name="actor"></param>
        /// <param name="convid"></param>
        /// <param name="status"></param>
        /// <param name="mOptions"></param>
        /// <returns></returns>
        public HMessage BuildConvState(string actor, string convid, string status, HMessageOptions mOptions)
        {
            if (actor == null || actor.Length <= 0)
                throw new MissingAttrException("actor");
            if (convid == null || convid.Length <= 0)
                throw new MissingAttrException("convid");
            if (status == null || status.Length <= 0)
                throw new MissingAttrException("status");

            HConvState convState = new HConvState();
            convState.SetStatus(status);

            HMessage message = BuildMessage(actor, "hConvState", convState, mOptions);
            message.SetConvid(convid);
            return message;
        }
Exemplo n.º 6
0
        /// <summary>
        /// The client MUST be connected to access to this service.
        /// Allow a hubapp client to create a hMessage with a hMeasure payload.
        /// </summary>
        /// <param name="actor"></param>
        /// <param name="value"></param>
        /// <param name="unit"></param>
        /// <param name="mOptions"></param>
        /// <returns></returns>
        public HMessage BuildMeasure(string actor, string value, string unit, HMessageOptions mOptions)
        {
            if (actor == null || actor.Length <= 0)
                    throw new MissingAttrException("actor");
                if (value == null || value.Length <= 0)
                    throw new MissingAttrException("value");
                if (unit == null || unit.Length <= 0)
                    throw new MissingAttrException("unit");

                HMeasure hmeasure = new HMeasure();
                hmeasure.SetUnit(unit);
                hmeasure.SetValue(value);

                HMessage message = BuildMessage(actor, "hMeasure", hmeasure, mOptions);
                return message;
        }
Exemplo n.º 7
0
        /// <summary>
        /// since v0.5
        /// The client MUST be connected to access to this service.
        /// Allow a hubapp client to create a hMessage with a hCommand payload.
        /// </summary>
        /// <param name="actor"></param>
        /// <param name="cmd"></param>
        /// <param name="params"></param>
        /// <param name="filter"></param>
        /// <param name="mOptions"></param>
        /// <returns></returns>
        public HMessage BuildCommand(string actor, string cmd, JToken @params, HCondition filter, HMessageOptions mOptions)
        {
            if (actor == null || actor.Length <= 0)
                throw new MissingAttrException("actor");
            if (cmd == null || cmd.Length <= 0)
                throw new MissingAttrException("cmd");

            HCommand hcommand = new HCommand(cmd, @params, filter);

            HMessage hmessage = BuildMessage(actor, "hCommand", hcommand, mOptions);
            return hmessage;
        }
Exemplo n.º 8
0
        /// <summary>
        /// The client MUST be connected to access to this service.
        /// Allow a hubapp client to create a hMessage with a hAlert payload.
        /// </summary>
        /// <param name="actor"></param>
        /// <param name="alert"></param>
        /// <param name="mOptions"></param>
        /// <returns></returns>
        public HMessage BuildAlert(string actor, string alert, HMessageOptions mOptions)
        {
            if (actor == null || actor.Length <= 0)
                throw new MissingAttrException("actor");
            if (alert == null || alert.Length <= 0)
                throw new MissingAttrException("alert");

            HAlert halert = new HAlert();
            halert.SetAlert(alert);

            HMessage message = BuildMessage(actor, "hAlert", halert, mOptions);
            return message;
        }
Exemplo n.º 9
0
        //HAckValue à faire
        /// <summary>
        /// The client MUST be connected to access to this service.
        /// Allow a hubapp client to create a hMessage with a hAck payload.
        /// </summary>
        /// <param name="actor"></param>
        /// <param name="ref"></param>
        /// <param name="ackValue">
        /// The following values are authorized :
        /// “recv” / HAckValue.RECV : means that the message has been received by the participant (on at least one of its devices)
        /// “read” / HAckValue.READ : means that the message has been read by the participant
        /// </param>
        /// <param name="mOptions"></param>
        /// <returns></returns>
        public HMessage BuildAck(string actor, string @ref, string ackValue, HMessageOptions mOptions)
        {
            if (actor == null || actor.Length <= 0)
                throw new MissingAttrException("actor");
            if (@ref == null || @ref.Length <= 0)
                throw new MissingAttrException("ref");
            if (ackValue == null)
                throw new MissingAttrException("ack");
            if (HUtil.CheckAck(ackValue))
                throw new Exception("only 'recv' and 'read' are authorized for ack");

            HAck hack = new HAck();
            hack.SetAck(ackValue);
            if (mOptions == null)
                mOptions = new HMessageOptions();
            mOptions.Ref = @ref;
            HMessage message = BuildMessage(actor, "hAck", hack, mOptions);
            return message;
        }
Exemplo n.º 10
0
 private void pubCSBt_Click(object sender, RoutedEventArgs e)
 {
     HMessageOptions mOptions = new HMessageOptions();
     if (persistentCb.IsChecked.Value)
         mOptions.Persistent = true;
     else
         mOptions.Persistent = false;
     HMessage hMsg = client.BuildConvState(actorTbx.Text, convidTbx.Text, statusTbx.Text, mOptions);
     client.Send(hMsg, callback);
 }
Exemplo n.º 11
0
        private void sendBt_Click(object sender, RoutedEventArgs e)
        {
            HMessageOptions mOptions = new HMessageOptions();
            if (persistentCb.IsChecked.Value)
                mOptions.Persistent = true;
            else
                mOptions.Persistent = false;
            if (!string.IsNullOrEmpty(timeoutTbx.Text))
                mOptions.Timeout = int.Parse(timeoutTbx.Text);
            if (!string.IsNullOrEmpty(relevantTbx.Text))
                mOptions.RelevanceOffset = int.Parse(relevantTbx.Text);
            HMessage hMsg = client.BuildMessage(actorTbx.Text, "text", msgTbx.Text, mOptions);
            client.Send(hMsg, null);
            Debug.WriteLine(">>>Send Message<<<\n" + hMsg.ToString() + "\n");

        }