示例#1
0
 /// <summary>
 /// Set the status of the acknowledgement.
 /// </summary>
 /// <param name="ack"></param>
 public void SetAck(string ack)
 {
     try
     {
         if (ack == null)
         {
             this.Remove("ack");
         }
         else
         {
             if (HUtil.CheckAck(ack))
             {
                 Debug.WriteLine("{0} : only 'recv' and 'read' are authorized for ack");
             }
             else
             {
                 this["ack"] = ack;
             }
         }
     }
     catch (Exception e)
     {
         Debug.WriteLine("{0} : Can not update the ack attribute", e.ToString());
     }
 }
示例#2
0
        private void fillTransportOptions(string login, string password, HOptions options, JObject context)
        {
            try
            {
                this.transportOptions.Login    = login;
                this.transportOptions.Password = password;
                this.transportOptions.Timeout  = options.GetTimeout();
                this.transportOptions.AuthCb   = options.AuthCb;


                //for endpoints, pick one randomly and fill transport options
                if (options.GetEndpoints().Count() > 0)
                {
                    int    endpointIndex = HUtil.PickIndex(options.GetEndpoints());
                    string endpoint      = options.GetEndpoints()[endpointIndex].ToString();

                    transportOptions.EndpointHost = HUtil.GetHost(endpoint);
                    transportOptions.EndpointPort = HUtil.GetPort(endpoint);
                    transportOptions.EndpointPath = HUtil.GetPath(endpoint);
                }
                else
                {
                    transportOptions.EndpointHost = null;
                    transportOptions.EndpointPort = 0;
                    transportOptions.EndpointPath = null;
                }
            }
            catch (Exception e)
            {
                Debug.WriteLine("{0} : ", e);
            }
        }
示例#3
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);
        }
        private void Login(string username, string password)
        {
            JObject data = new JObject();

            try
            {
                data.Add("login", username);
                data.Add("password", password);
                data.Add("sent", HUtil.DateTime2Timestamps(DateTime.UtcNow));
                if (options.Context != null)
                {
                    data.Add("context", options.Context);
                }

                socketIO.Emit("hConnect", data);
            }
            catch (Exception e)
            {
                if (socketIO != null)
                {
                    Disconnect();
                }
                if (connTimeoutTimer != null)
                {
                    connTimeoutTimer.Cancel();
                    connTimeoutTimer = null;
                }
                updateStatus(ConnectionStatus.DISCONNECTED, ConnectionErrors.TECH_ERROR, e.Message);
            }
        }
示例#5
0
        private void notifyMessage(HMessage message, Action <HMessage> messageDelegate)
        {
            // 1 - we search the delegate with the ref if any in delegate dictionnary.
            if (messageDelegates.Count > 0 && message.GetRef() != null && messageDelegates.ContainsKey(HUtil.GetApiRef(message.GetRef())))
            {
                string msgRef = HUtil.GetApiRef(message.GetRef());
                if (timerOutDictionary.ContainsKey(msgRef))
                {
                    ThreadPoolTimer timer = timerOutDictionary[msgRef];
                    timerOutDictionary.Remove(msgRef);
                    if (timer != null)
                    {
                        timer.Cancel();
                    }
                }
                Action <HMessage> action = messageDelegates[msgRef];
                messageDelegates.Remove(msgRef);
                if (action != null)
                {
                    IAsyncAction threadPoolWorkItem = ThreadPool.RunAsync(
                        (source) =>
                    {
                        action(message);
                    }
                        );
                }
            }

            // 2 - if the ref can not provide a delegate, we try the parameter sent
            else if (messageDelegate != null)
            {
                IAsyncAction threadPoolWorkItem = ThreadPool.RunAsync(
                    (source) =>
                {
                    messageDelegate(message);
                }
                    );
            }

            else
            {
                // 3 - in other case, try the default message delegate onMessage.
                if (this.onMessage != null)
                {
                    IAsyncAction threadPoolWorkItem = ThreadPool.RunAsync(
                        (source) =>
                    {
                        this.onMessage(message);
                    }
                        );
                }
            }
        }
示例#6
0
        /// <summary>
        /// Mandatory. The date and time at which the message has been published. NULL if undefined
        /// </summary>
        /// <returns></returns>
        public DateTime?GetPublishedAsDate()
        {
            DateTime?published = null;

            try
            {
                published = HUtil.Timestamps2Datetime(this["published"].ToObject <long>());
            }
            catch (Exception e)
            {
                Debug.WriteLine("{0} : Can not fetch the published attribute", e.ToString());
            }
            return(published);
        }
示例#7
0
        public DateTime?GetRelevanceAsDate()
        {
            DateTime?relevance = null;

            try
            {
                relevance = HUtil.Timestamps2Datetime(this["relevance"].ToObject <long>());
            }
            catch (Exception e)
            {
                Debug.WriteLine("{0} : Can not fetch the relevance attribute", e.ToString());
            }
            return(relevance);
        }
示例#8
0
        /// <summary>
        ///
        /// </summary>
        /// <returns>sent. Null if undefined.</returns>
        public DateTime?GetSentAsDate()
        {
            DateTime?sent = null;

            try
            {
                sent = HUtil.Timestamps2Datetime(this["sent"].ToObject <long>());
            }
            catch (Exception e)
            {
                Debug.WriteLine("{0} : Can not fetch the sent attribute", e.ToString());
            }
            return(sent);
        }
示例#9
0
 public void SetPublished(DateTime?published)
 {
     try
     {
         if (published == null)
         {
             this.Remove("published");
         }
         else
         {
             this["published"] = HUtil.DateTime2Timestamps(published.Value);
         }
     }
     catch (Exception e)
     {
         Debug.WriteLine("{0} : Can not update the published attribute", e.ToString());
     }
 }
示例#10
0
 public void SetRelevance(DateTime?relevance)
 {
     try
     {
         if (relevance == null)
         {
             this.Remove("relevance");
         }
         else
         {
             this["relevance"] = HUtil.DateTime2Timestamps(relevance.Value);
         }
     }
     catch (Exception e)
     {
         Debug.WriteLine("{0} : Can not update the relevance attribute", e.ToString());
     }
 }
示例#11
0
 public void SetSent(DateTime?sent)
 {
     try
     {
         if (sent == null)
         {
             this.Remove("sent");
         }
         else
         {
             this["sent"] = HUtil.DateTime2Timestamps(sent.Value);
         }
     }
     catch (Exception e)
     {
         Debug.WriteLine("{0} : Can not update the sent attribute", e.ToString());
     }
 }