/// <summary> /// Loads each line read from the supplied stream as a new trigger and stores it. /// </summary> /// <param name="inputStream"> /// The source input stream where each line represents a unique trigger. /// </param> /// <param name="categoryId"> /// The category ID that all loaded triggers are to be assigned. /// </param> /// <returns> /// The total number of triggers loaded from the supplied input stream. /// </returns> public async Task <int> LoadStoreFromStream(Stream inputStream, short categoryId) { int loaded = 0; using (var transaction = m_connection.BeginTransaction()) { using (var storeCommands = new StoreCommands(m_connection)) { string line = null; using (var sw = new StreamReader(inputStream)) { while ((line = await sw.ReadLineAsync()) != null) { if (await storeCommands.StoreTrigger(line, categoryId)) { ++loaded; } } } } transaction.Commit(); } m_hasTriggers = loaded > 0; return(loaded); }
public async Task <int> LoadStoreFromList(IEnumerable <string> inputList, short categoryId) { int loaded = 0; using (var transaction = m_connection.BeginTransaction()) { using (var storeCommands = new StoreCommands(m_connection)) { foreach (string line in inputList) { if (line == null) { continue; } if (await storeCommands.StoreTrigger(line, categoryId)) { ++loaded; } } } transaction.Commit(); } m_hasTriggers = loaded > 0; return(loaded); }