public void Show(Message message)
{
var query = from entry in message.Attachments where entry.Score.HasValue select entry.Score.Value;
bool isRecyclable = true;
if (query.Any())
{
List<double> scoreList = query.ToList();
this.maxScore = scoreList.Max<double>();
this.minScore = scoreList.Min<double>();
this.isReversed = false;
bool isAvailable = false;
for (int i = 0; i < scoreList.Count - 1; i++)
{
if (scoreList[i] != scoreList[i + 1])
{
isAvailable = true;
break;
}
}
if (isAvailable)
{
int counter = 0;
for (int i = 0; i < scoreList.Count - 1; i++)
{
if (scoreList[i] >= scoreList[i + 1])
{
counter++;
}
}
if (counter == scoreList.Count - 1)
{
this.isReversed = true;
}
}
if (this.isReversed)
{
this.thresholdScore = this.nextThresholdScore = this.minScore;
}
else
{
this.thresholdScore = this.nextThresholdScore = this.maxScore;
}
}
this.messageCollection.Add(message);
if (this.messageCollection.Count > this.maxHistory)
{
List<Message> messageList = this.messageCollection.ToList();
for (int i = 0; i < messageList.Count - this.maxHistory; i++)
{
Message m = messageList[i];
Size size1 = GetBalloonSize(m);
double height = 0;
foreach (object o in m)
{
Entry entry = o as Entry;
if (entry != null)
{
Size size2 = GetInspectorSize(entry);
if (size2.Height > height)
{
height = size2.Height;
}
}
}
if (m.HasAttachments)
{
double h = m.Attachments.Max<Entry, double>(entry => GetInspectorSize(entry).Height);
if (h > height)
{
height = h;
}
}
if (height > 0)
{
height -= 11;
}
if (size1.Width * this.maxScale == this.LayoutRoot.Width && (size1.Height + height) * this.maxScale == this.LayoutRoot.Height)
{
isRecyclable = false;
break;
}
}
messageList.RemoveRange(0, messageList.Count - this.maxHistory);
this.messageCollection.Clear();
messageList.ForEach(delegate (Message m)
{
this.messageCollection.Add(m);
});
}
if (this.messageCollection.Count - 1 >= 0)
{
this.historyPoint = new Nullable<int>(this.messageCollection.Count - 1);
}
Size balloonSize = GetBalloonSize(message, ref this.messageIsScrollable);
double maxHeight = 0;
foreach (object o in message)
{
Entry entry = o as Entry;
if (entry != null)
{
Size size = GetInspectorSize(entry);
if (size.Height > maxHeight)
{
maxHeight = size.Height;
}
}
}
if (message.HasAttachments)
{
double height = message.Attachments.Max<Entry, double>(entry => GetInspectorSize(entry).Height);
if (height > maxHeight)
{
maxHeight = height;
}
}
if (maxHeight > 0)
{
maxHeight -= 11;
}
Size maxSize = new Size(balloonSize.Width, balloonSize.Height + maxHeight);
if (isRecyclable && this.LayoutRoot.Width >= maxSize.Width * this.maxScale && this.LayoutRoot.Height >= maxSize.Height * this.maxScale)
{
maxSize.Width = this.LayoutRoot.Width;
maxSize.Height = this.LayoutRoot.Height;
}
else
{
foreach (Message m in from m in this.messageCollection where m != message select m)
{
Size size1 = GetBalloonSize(m);
double height = 0;
foreach (object o in m)
{
Entry entry = o as Entry;
if (entry != null)
{
Size size2 = GetInspectorSize(entry);
if (size2.Height > height)
{
height = size2.Height;
}
}
}
if (m.HasAttachments)
{
double h = m.Attachments.Max<Entry, double>(entry => GetInspectorSize(entry).Height);
if (h > height)
{
height = h;
}
}
if (height > 0)
{
height -= 11;
}
if (size1.Width > maxSize.Width)
{
maxSize.Width = size1.Width;
}
if (size1.Height + height > maxSize.Height)
{
maxSize.Height = size1.Height + height;
}
}
maxSize.Width = maxSize.Width * this.maxScale;
maxSize.Height = maxSize.Height * this.maxScale;
}
this.sourceSize = this.targetSize = balloonSize;
this.targetOpacity = 1;
this.targetScaleX = this.targetScaleY = 1;
Geometry roundedRectangleGeometry = CreateRoundedRectangleGeometry(new Rect(0, 0, this.sourceSize.Width, this.sourceSize.Height - 11 + 4), 8, 8);
Geometry balloonGeometry = CreateBalloonGeometry(new Rect(4, 4, this.sourceSize.Width - 4 * 2, this.sourceSize.Height - 4), 8 * 3 / 4, 8 * 3 / 4);
Geometry highlightGeometry = CreateHighlightGeometry(new Rect(0, 0, this.sourceSize.Width, this.baseHeaderHeight + 8), 8, 8);
Geometry highlightLineGeometry = CreateHighlightLineGeometry(new Rect(0, 0, this.sourceSize.Width, 8), 8, 8);
if (roundedRectangleGeometry.CanFreeze)
{
roundedRectangleGeometry.Freeze();
}
if (balloonGeometry.CanFreeze)
{
balloonGeometry.Freeze();
}
if (highlightGeometry.CanFreeze)
{
highlightGeometry.Freeze();
}
if (highlightLineGeometry.CanFreeze)
{
highlightLineGeometry.Freeze();
}
GeometryGroup geometryGroup = new GeometryGroup();
geometryGroup.FillRule = FillRule.Nonzero;
geometryGroup.Children.Add(roundedRectangleGeometry);
geometryGroup.Children.Add(balloonGeometry);
if (geometryGroup.CanFreeze)
{
geometryGroup.Freeze();
}
RadialGradientBrush radialGradientBrush = new RadialGradientBrush();
GradientStop gradientStop1 = new GradientStop(Color.FromArgb(Byte.MaxValue, Byte.MaxValue, Byte.MaxValue, Byte.MaxValue), 0);
GradientStop gradientStop2 = new GradientStop(Color.FromArgb(Byte.MaxValue, 0, 0, 0), 1);
radialGradientBrush.GradientOrigin = new Point(0.5, 0);
radialGradientBrush.Center = new Point(0.5, 0);
radialGradientBrush.RadiusX = 0.5;
radialGradientBrush.RadiusY = this.sourceSize.Width / 2 < this.sourceSize.Height - this.baseFooterHeight ? this.sourceSize.Width / 2 / this.sourceSize.Height : (this.sourceSize.Height - this.baseFooterHeight) / this.sourceSize.Height;
radialGradientBrush.Opacity = 0.1;
radialGradientBrush.GradientStops.Add(gradientStop1);
radialGradientBrush.GradientStops.Add(gradientStop2);
if (radialGradientBrush.CanFreeze)
{
radialGradientBrush.Freeze();
}
this.Width = this.LayoutRoot.Width = maxSize.Width;
this.Height = this.LayoutRoot.Height = maxSize.Height;
this.OuterPath.Width = roundedRectangleGeometry.Bounds.Right;
this.OuterPath.Height = roundedRectangleGeometry.Bounds.Bottom;
this.OuterPath.Data = roundedRectangleGeometry;
this.InnerPath.Width = balloonGeometry.Bounds.Right;
this.InnerPath.Height = balloonGeometry.Bounds.Bottom;
this.InnerPath.Data = balloonGeometry;
this.OverlayPath.Width = geometryGroup.Bounds.Right;
this.OverlayPath.Height = geometryGroup.Bounds.Bottom;
this.OverlayPath.Data = geometryGroup;
this.OverlayPath.Fill = radialGradientBrush;
this.HighlightPath.Width = highlightGeometry.Bounds.Right;
this.HighlightPath.Height = highlightGeometry.Bounds.Bottom;
this.HighlightPath.Data = highlightGeometry;
this.HighlightLinePath.Width = highlightLineGeometry.Bounds.Right;
this.HighlightLinePath.Height = highlightLineGeometry.Bounds.Bottom;
this.HighlightLinePath.Data = highlightLineGeometry;
this.Canvas.Width = this.sourceSize.Width;
this.Canvas.Height = this.sourceSize.Height;
this.ScaleTransform.CenterX = this.sourceSize.Width / 2;
this.ScaleTransform.CenterY = this.sourceSize.Height;
Canvas.SetLeft(this.Canvas, (maxSize.Width - this.sourceSize.Width) / 2);
Canvas.SetTop(this.Canvas, maxSize.Height - this.sourceSize.Height);
Canvas.SetLeft(this.FilterImage, this.sourceSize.Width - 14);
Canvas.SetLeft(this.ScrollImage, this.sourceSize.Width - 14);
Canvas.SetLeft(this.CloseImage, this.sourceSize.Width - 17);
Canvas.SetLeft(this.BackImage, this.sourceSize.Width - 30);
Canvas.SetLeft(this.UpImage, this.sourceSize.Width - 17);
Canvas.SetTop(this.UpImage, this.sourceSize.Height - 32);
Canvas.SetLeft(this.DownImage, this.sourceSize.Width - 17);
Canvas.SetTop(this.DownImage, this.sourceSize.Height - 21);
Show();
}