Ejemplo n.º 1
0
        private void UpdateCounters()
        {
            for (int i = 0; i < m_counterListBox.Items.Count; ++i)
            {
                var entry = m_counterListBox.Items[i] as CounterEntry;
                entry.Tagged = false;
            }

            using (var session = m_connection.DataEngine.OpenSession(m_snapshot.Id))
                using (var tx = session.BeginTransaction())
                {
                    var counters = session.CreateCriteria <Counter>()
                                   .AddOrder(Order.Asc("Id"))
                                   .List <Counter>();
                    foreach (Counter c in counters)
                    {
                        string name = c.Name;
                        if (string.IsNullOrEmpty(name))
                        {
                            name = string.Format("Counter #{0}", c.Id);
                        }

                        var newEntry           = new CounterEntry(c.Id, name);
                        int existingEntryIndex = m_counterListBox.Items.IndexOf(newEntry);
                        if (existingEntryIndex >= 0)
                        {
                            var existingEntry = m_counterListBox.Items[existingEntryIndex] as CounterEntry;
                            existingEntry.Name   = name;
                            existingEntry.Tagged = true;
                        }
                        else
                        {
                            m_counterListBox.Items.Add(new CounterEntry(c.Id, name));
                        }
                    }

                    tx.Commit();
                }

            int index = 0;

            while (index < m_counterListBox.Items.Count)
            {
                var entry = m_counterListBox.Items[index] as CounterEntry;
                if (!entry.Tagged)
                {
                    //this is a stale entry, so remove it
                    m_counterListBox.Items.RemoveAt(index);
                }
                else
                {
                    //it's fine, keep going
                    ++index;
                }
            }
        }
Ejemplo n.º 2
0
		private void UpdateCounters()
		{
			for(int i = 0; i < m_counterListBox.Items.Count; ++i)
			{
				var entry = m_counterListBox.Items[i] as CounterEntry;
				entry.Tagged = false;
			}

			using(var session = m_connection.DataEngine.OpenSession(m_snapshot.Id))
			using(var tx = session.BeginTransaction())
			{
				var counters = session.CreateCriteria<Counter>()
					.AddOrder(Order.Asc("Id"))
					.List<Counter>();
				foreach(Counter c in counters)
				{
					string name = c.Name;
					if(string.IsNullOrEmpty(name))
						name = string.Format("Counter #{0}", c.Id);

					var newEntry = new CounterEntry(c.Id, name);
					int existingEntryIndex = m_counterListBox.Items.IndexOf(newEntry);
					if(existingEntryIndex >= 0)
					{
						var existingEntry = m_counterListBox.Items[existingEntryIndex] as CounterEntry;
						existingEntry.Name = name;
						existingEntry.Tagged = true;
					}
					else
					{
						m_counterListBox.Items.Add(new CounterEntry(c.Id, name));
					}
				}

				tx.Commit();
			}

			int index = 0;
			while(index < m_counterListBox.Items.Count)
			{
				var entry = m_counterListBox.Items[index] as CounterEntry;
				if(!entry.Tagged)
				{
					//this is a stale entry, so remove it
					m_counterListBox.Items.RemoveAt(index);
				}
				else
				{
					//it's fine, keep going
					++index;
				}
			}
		}