public void Update()
{
OSAEImageManager imgMgr = new OSAEImageManager();
bool stateChanged = false;
try
{
OSAEObjectState stateCurrent = OSAEObjectStateManager.GetObjectStateValue(ObjectName);
if (CurState != stateCurrent.Value) stateChanged = true;
CurState = stateCurrent.Value;
CurStateLabel = stateCurrent.StateLabel;
LastStateChange = stateCurrent.LastStateChange;
}
catch
{ }
foreach (OSAEObjectProperty p in screenObject.Properties)
{
if (p.Value.ToLower() == CurState.ToLower()) StateMatch = p.Name.Substring(0, p.Name.LastIndexOf(' '));
}
try
{
Location.X = Double.Parse(OSAE.OSAEObjectPropertyManager.GetObjectPropertyValue(screenObject.Name, StateMatch + " X").Value);
Location.Y = Double.Parse(OSAE.OSAEObjectPropertyManager.GetObjectPropertyValue(screenObject.Name, StateMatch + " Y").Value);
try
{
string propertyCheck = OSAEObjectPropertyManager.GetObjectPropertyValue(ObjectName, "Light Level").Value;
if (propertyCheck != "") LightLevel = Convert.ToUInt16(propertyCheck);
else LightLevel = 100;
}
catch { }
if (sliderVisible && updatingSlider == false)
{
try { CurLevel = OSAEObjectPropertyManager.GetObjectPropertyValue(ObjectName, "Level").Value; }
catch { CurLevel = "0"; }
Dispatcher.Invoke((Action)(() =>
{
sldSlider.ToolTip = CurLevel + "%";
sldSlider.Value = Convert.ToUInt16(CurLevel);
if (CurLevel != "") Image.ToolTip = ObjectName + "\n" + CurStateLabel + " (" + CurLevel + "%) since: " + LastStateChange;
else Image.ToolTip = ObjectName + "\n" + CurStateLabel + " since: " + LastStateChange;
}));
}
if (stateChanged)
{
timer.Stop();
string imgName = screenObject.Property(StateMatch + " Image").Value;
string imgName2 = screenObject.Property(StateMatch + " Image 2").Value;
string imgName3 = screenObject.Property(StateMatch + " Image 3").Value;
string imgName4 = screenObject.Property(StateMatch + " Image 4").Value;
if (imgName != "")
{
OSAEImage img1 = imgMgr.GetImage(imgName);
if (img1.Type == "gif")
{
ms1 = new MemoryStream(img1.Data);
Dispatcher.Invoke((Action)(() =>
{
Image.Source = null;
Image.ToolTip = ObjectName + " " + CurStateLabel + "\n" + "since: " + LastStateChange;
BitmapImage bitmapImage = new BitmapImage();
bitmapImage.BeginInit();
bitmapImage.StreamSource = ms1;
bitmapImage.EndInit();
ImageWidth = bitmapImage.Width;
ImageHeight = bitmapImage.Height;
ImageBehavior.SetAnimatedSource(Image, bitmapImage);
Image.Visibility = System.Windows.Visibility.Visible;
}));
}
else if (img1 != null)
{
ms1 = new MemoryStream(img1.Data);
imageFrames = 1;
currentFrame = 1;
Dispatcher.Invoke((Action)(() =>
{
Image.Source = null;
Image.ToolTip = ObjectName + " " + CurStateLabel + "\n" + "since: " + LastStateChange;
BitmapImage bitmapImage = new BitmapImage();
bitmapImage.BeginInit();
bitmapImage.StreamSource = ms1;
bitmapImage.EndInit();
Image.Source = bitmapImage;
ImageWidth = bitmapImage.Width;
ImageHeight = bitmapImage.Height;
ImageBehavior.SetAnimatedSource(Image, bitmapImage);
}));
// Primary Frame is loaded, load up additional frames for the time to display.
if (imgName2 != "")
{
OSAEImage img2 = imgMgr.GetImage(imgName2);
if (img2 != null)
{
ms2 = new MemoryStream(img2.Data);
imageFrames = 2;
if (imgName3 != "")
{
OSAEImage img3 = imgMgr.GetImage(imgName3);
if (img3 != null)
{
ms3 = new MemoryStream(img3.Data);
imageFrames = 3;
if (imgName4 != "")
{
OSAEImage img4 = imgMgr.GetImage(imgName4);
if (img4 != null)
{
ms4 = new MemoryStream(img4.Data);
imageFrames = 4;
}
}
}
}
}
}
}
}
else
{
Dispatcher.Invoke((Action)(() =>
{
Image.Source = null; // Image.Visibility = System.Windows.Visibility.Hidden;
}));
}
if (imageFrames > 1) timer.Start();
}
}
catch (Exception ex)
{ MessageBox.Show(ex.Message, "StateImage Update"); }
}