void AssignStyle(ImmutableEnvelope item, string session)
 {
     Style += cell =>
     {
         if (session == (cell.Value as string))
         {
             cell.Style.BackColor = DomainAwareAnalysis.GetBackgroundColorForCategory(session);
         }
         else if (cell.Value is char)
         {
             cell.Style.BackColor = DomainAwareAnalysis.GetBackgroundColorForCategory(Class);
         }
         else
         {
             cell.Style.BackColor = DomainAwareAnalysis.GetBackgroundColorForContract(item.Items[0]);
         }
     };
 }
Beispiel #2
0
        void LoadEventsTill(long maxVersion, bool sync, ToolStripItem sender)
        {
            var context = TaskScheduler.FromCurrentSynchronizationContext();

            _domainGrid.DataSource = new[] { new { Message = "Loading..." } };

            var start = sync ? _client.SyncLog(s => Log(s)) : Task.Factory.StartNew(() => { });

            start.ContinueWith(t =>
            {
                var list = new List <DomainLogDisplayItem>();

                long maxCount;
                if (!Int64.TryParse(txtCount.Text, out maxCount))
                {
                    maxCount = MaxCount;
                }

                MaxCount = (int)maxCount;

                _client.ObserveTill(maxVersion, (int)maxCount, s =>
                {
                    var envelope = _serializer.ReadAsEnvelopeData(s.Data);


                    for (int i = 0; i < envelope.Items.Length; i++)
                    {
                        var item    = envelope.Items[i];
                        var session = DomainAwareAnalysis.GetCategoryNames(item);
                        // clone batch envelopes into separate ones
                        var clone = EnvelopeBuilder.CloneProperties(envelope.EnvelopeId + "-" + i, envelope);
                        clone.AddItem(item.Content);
                        list.Add(new DomainLogDisplayItem(clone.Build(), session, s.Version));
                    }
                });
                return(list);
            }).ContinueWith(x =>
            {
                if (x.Exception != null)
                {
                    Log("Exception: {0}", x.Exception.Message);
                    Trace.WriteLine(x.Exception);
                    return;
                }
                var items = x.Result;
                if (items.Count > 0)
                {
                    var min    = items.Min(i => i.StoreIndex) - 1;
                    _currentId = min;
                }

                _domainGrid.DataSource  = items;
                tabControl1.SelectedTab = _domainLogTab;

                // paint

                foreach (DataGridViewRow dataGridViewRow in _domainGrid.Rows)
                {
                    var disp = (DomainLogDisplayItem)dataGridViewRow.DataBoundItem;
                    foreach (DataGridViewCell cell in dataGridViewRow.Cells)
                    {
                        disp.Style(cell);
                    }
                }

                _domainGrid.Columns[0].Width = 200;
                _domainGrid.Columns[1].Width = 80;
                _domainGrid.Columns[2].Width = 90;
                _domainGrid.Columns[3].Width = 40;

                Log("Displayed {0} records starting from version {1}.", items.Count, _currentId);
            }, context)
            .ContinueWith(_ =>
            {
                if (sender != null)
                {
                    Invoke(new MethodInvoker(() => sender.Enabled = true));
                }
            });

            if (start.Status == TaskStatus.Created)
            {
                start.Start();
            }
        }