Exemple #1
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();
            }
        }
Exemple #2
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();
        }
Exemple #3
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();
        }