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); }
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(); } }
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(); }
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(); }
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(); }
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); }
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(); }