コード例 #1
0
        public bool TopicExists(string topicName)
        {
            MQTTModel mqtt   = new MQTTModel();
            var       topics = from t in mqtt.Topics where t.TopicName == topicName where t.Account.ID == defaultAccount.ID select t;

            return(topics.Count() > 0);
        }
コード例 #2
0
        public void StoreTopic(string topicName, QOS qos)
        {
            MQTTModel model  = new MQTTModel();
            var       topics = from t in model.Topics where t.TopicName == topicName where t.Account.ID == defaultAccount.ID select t;

            if (topics.Count() > 0)
            {
                Topic currTopic = topics.First();
                currTopic.QOS = qos;
                model.Topics.Attach(currTopic);
                var entry = model.Entry(currTopic);
                entry.Property(t => t.QOS).IsModified = true;
                model.SaveChanges();
            }
            else
            {
                Topic newTopic = new Topic();
                newTopic.QOS       = qos;
                newTopic.TopicName = topicName;
                newTopic.Account   = defaultAccount;

                model.Accounts.Attach(defaultAccount);
                model.Topics.Add(newTopic);
                model.Entry(defaultAccount).State = EntityState.Unchanged;
                model.SaveChanges();
            }
        }
コード例 #3
0
        public void UnmarkAsDefault(Account account)
        {
            MQTTModel mqtt = new MQTTModel();

            account.IsDefault = false;
            mqtt.Accounts.Attach(account);
            var entry = mqtt.Entry(account);

            entry.Property(a => a.IsDefault).IsModified = true;
            mqtt.SaveChanges();
        }
コード例 #4
0
        public void DeleteTopic(string topicName)
        {
            MQTTModel mqtt   = new MQTTModel();
            var       topics = from t in mqtt.Topics where t.TopicName == topicName where t.Account.ID == defaultAccount.ID select t;

            if (topics.Count() > 0)
            {
                mqtt.Topics.Remove(topics.First());
            }

            mqtt.SaveChanges();
        }
コード例 #5
0
        public void DeleteAllTopics()
        {
            MQTTModel mqtt   = new MQTTModel();
            var       topics = from t in mqtt.Topics where t.Account.ID == defaultAccount.ID select t;

            if (topics.Count() > 0)
            {
                mqtt.Topics.RemoveRange(topics);
            }

            mqtt.SaveChanges();
        }
コード例 #6
0
        public List <mqtt.avps.Topic> GetAllTopics()
        {
            MQTTModel mqtt   = new MQTTModel();
            var       topics = from t in mqtt.Topics where t.Account.ID == defaultAccount.ID select t;
            List <mqtt.avps.Topic> result = new List <iotbroker.mqtt.avps.Topic>();

            foreach (var currTopic in topics)
            {
                result.Add(new mqtt.avps.Topic(currTopic.TopicName, currTopic.QOS));
            }

            return(result);
        }
コード例 #7
0
        public void StoreMessage(string topicName, byte[] content, QOS qos)
        {
            Message newMessage = new Message();

            newMessage.QOS       = qos;
            newMessage.Content   = content;
            newMessage.TopicName = topicName;
            newMessage.Incoming  = true;
            newMessage.Account   = defaultAccount;

            MQTTModel model = new MQTTModel();

            model.Accounts.Attach(defaultAccount);
            model.Messages.Add(newMessage);
            model.Entry(defaultAccount).State = EntityState.Unchanged;
            model.SaveChanges();
        }