829 lines
32 KiB
C#
829 lines
32 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Windows;
|
|
using System.Windows.Controls;
|
|
using System.Windows.Data;
|
|
using System.Windows.Documents;
|
|
using System.Windows.Input;
|
|
using System.Windows.Media;
|
|
using System.Windows.Media.Imaging;
|
|
using System.Windows.Media.Animation;
|
|
using System.Windows.Navigation;
|
|
using System.Windows.Shapes;
|
|
using System.Windows.Threading;
|
|
using System.Net.Cache;
|
|
using System.IO;
|
|
using System.Net;
|
|
using System.Diagnostics;
|
|
//using System.Drawing;
|
|
|
|
|
|
namespace Kaehler.scr
|
|
{
|
|
/// <summary>
|
|
/// Interaktionslogik für MainWindow.xaml
|
|
/// </summary>
|
|
public partial class MainWindow : Window
|
|
{
|
|
const int cTimerStart = 1;
|
|
const int cStartAnzeige = 12;
|
|
const int cAusblenden = 11;
|
|
const int cTimerDeAni = 31; //war 21
|
|
|
|
private DispatcherTimer randTimer;
|
|
private bool bRandTimer;
|
|
//0=nix, 1..5 Image, 6 Zitat
|
|
private int iAktivesElement;
|
|
private Random oRand;
|
|
private int randCounter;
|
|
|
|
public MainWindow()
|
|
{
|
|
InitializeComponent();
|
|
}
|
|
|
|
public void SCRBeenden()
|
|
{
|
|
App.Current.Shutdown();
|
|
}
|
|
|
|
private void Window_Loaded(object sender, RoutedEventArgs e)
|
|
{
|
|
try
|
|
{
|
|
randTimer = new DispatcherTimer();
|
|
randTimer.Tick += new EventHandler(randTimer_Tick);
|
|
randTimer.Interval = new TimeSpan(0, 0, 0, 10); //10 Sekunden (3 zum Test)
|
|
oRand = new Random();
|
|
iAktivesElement = 0;
|
|
randCounter = 0;
|
|
Logge("Starte Anzeige-Verdunklung");
|
|
WinDeAni();
|
|
Logge("Starte Randomizer");
|
|
bRandTimer = true;
|
|
randTimer.Start();
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
LoggeFehler("Exception in " + ex.Source + ": " + ex.Message);
|
|
//MessageBox.Show("Exception in " + ex.Source + ": " + ex.Message);
|
|
}
|
|
}
|
|
|
|
private void Logge(string sLogText)
|
|
{
|
|
Console.WriteLine(sLogText);
|
|
SimpleEventLog(sLogText,false);
|
|
}
|
|
|
|
private void LoggeFehler(string sLogText)
|
|
{
|
|
Console.WriteLine(sLogText);
|
|
SimpleEventLog(sLogText, true);
|
|
}
|
|
|
|
private void randTimer_Tick(object sender, EventArgs e)
|
|
{
|
|
try
|
|
{
|
|
if (bRandTimer)
|
|
{
|
|
randCounter += 1;
|
|
Logge("Timer: " + randCounter.ToString());
|
|
if (randCounter == cTimerStart) //erster Durchlauf nach 10s
|
|
{
|
|
// ... beginne mit Zitat
|
|
LoadZoomZitat();
|
|
randCounter = cTimerDeAni; // 1 x 10s bis zur DeAnimation
|
|
}
|
|
// cAusblenden ... cStartAnzeige = Pause
|
|
else if (randCounter == cStartAnzeige) //Starte zufällige Anzeige
|
|
{
|
|
//Auswürfeln ..
|
|
LayoutReset();
|
|
iAktivesElement = (int)oRand.Next(7);
|
|
if (iAktivesElement == 0) { iAktivesElement = 1; }
|
|
if (iAktivesElement == 7) { iAktivesElement = 6; }
|
|
Logge("Random-Wert: " + iAktivesElement.ToString());
|
|
//Test:
|
|
//iAktivesElement = 5;
|
|
switch (iAktivesElement)
|
|
{
|
|
case 1:
|
|
LoadZoomImage(image1);
|
|
break;
|
|
case 2:
|
|
LoadZoomImage(image2);
|
|
break;
|
|
case 3:
|
|
LoadZoomImage(image3);
|
|
break;
|
|
case 4:
|
|
LoadZoomImage(image4);
|
|
break;
|
|
case 5:
|
|
LoadOpaqueImage(image5);
|
|
break;
|
|
default:
|
|
LoadZoomZitat();
|
|
break;
|
|
}
|
|
}
|
|
else if (randCounter == cStartAnzeige + 1) //10s nach Anzeige-Start
|
|
{ // manchmal wird die Animation nicht ausgeführt (?)
|
|
|
|
//Logge("(deaktiviert) Aktives Element (" + iAktivesElement.ToString() + ") auf Sichtbar zwingen ...");
|
|
//switch (iAktivesElement)
|
|
//{
|
|
// case 1:
|
|
// image1.Visibility = Visibility.Visible;
|
|
// image1.Opacity = 1;
|
|
// break;
|
|
// case 2:
|
|
// image2.Visibility = Visibility.Visible;
|
|
// image2.Opacity = 1;
|
|
// break;
|
|
// case 3:
|
|
// image3.Visibility = Visibility.Visible;
|
|
// image3.Opacity = 1;
|
|
// break;
|
|
// case 4:
|
|
// image4.Visibility = Visibility.Visible;
|
|
// image4.Opacity = 1;
|
|
// break;
|
|
// case 5:
|
|
// txtZitat.Visibility = Visibility.Visible;
|
|
// txtZitat.Opacity = 1;
|
|
// break;
|
|
//}
|
|
|
|
}
|
|
else if (randCounter > cTimerDeAni) // 10 x 10s ... Bild lange genug gezeigt
|
|
{ // Ausblenden mit Ani
|
|
switch (iAktivesElement)
|
|
{
|
|
case 1:
|
|
DeAniImage(image1);
|
|
break;
|
|
case 2:
|
|
DeAniImage(image2);
|
|
break;
|
|
case 3:
|
|
DeAniImage(image3);
|
|
break;
|
|
case 4:
|
|
DeAniImage(image4);
|
|
break;
|
|
case 5:
|
|
DeAniImage(image5);
|
|
break;
|
|
default:
|
|
ZitatDeAni();
|
|
break;
|
|
}
|
|
iAktivesElement = 0;
|
|
randCounter = cAusblenden;
|
|
}
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
LoggeFehler("Exception in " + ex.Source + ": " + ex.Message);
|
|
//MessageBox.Show("Exception in " + ex.Source + ": " + ex.Message);
|
|
}
|
|
}
|
|
|
|
private void LoadZoomZitat()
|
|
{
|
|
Logge("Lade Zitat...");
|
|
try
|
|
{
|
|
iAktivesElement = 5;
|
|
bool hasText = LoadZitat();
|
|
if (hasText)
|
|
{
|
|
ZoomZitatAni();
|
|
}
|
|
else
|
|
{
|
|
txtZitat.Visibility = Visibility.Hidden;
|
|
Logge("Zitat ausblenden / Err");
|
|
randCounter = cTimerDeAni; // DeAnimation
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
LoggeFehler("Exception in " + ex.Source + ": " + ex.Message);
|
|
//MessageBox.Show("Exception in " + ex.Source + ": " + ex.Message);
|
|
}
|
|
}
|
|
|
|
private void LoadZoomImage(Image ZielImage)
|
|
{
|
|
try
|
|
{
|
|
double xMax = LoadImage(ZielImage);
|
|
Logge("Image geladen");
|
|
if (xMax < imageSCR.Height)
|
|
{
|
|
Logge("Imagegröße kleiner Screenhöhe: " + xMax.ToString());
|
|
ZielImage.Height = xMax;
|
|
}
|
|
else
|
|
{
|
|
Logge("Imagegröße größer Screenhöhe: " + xMax.ToString());
|
|
ZielImage.Height = imageSCR.Height;
|
|
}
|
|
if (xMax < imageSCR.Width)
|
|
{
|
|
Logge("Imagegröße kleiner Screenbreite: " + xMax.ToString());
|
|
ZielImage.Width = xMax;
|
|
}
|
|
else
|
|
{
|
|
Logge("Imagegröße größer Screenbreite: " + xMax.ToString());
|
|
ZielImage.Width = imageSCR.Width;
|
|
}
|
|
//AniImage(ZielImage);
|
|
ZoomAni(ZielImage);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
LoggeFehler("Exception in " + ex.Source.ToString() + ": " + ex.Message);
|
|
//MessageBox.Show("Exception in " + ex.Source.ToString() + ": " + ex.Message);
|
|
}
|
|
}
|
|
|
|
private void LoadOpaqueImage(Image ZielImage)
|
|
{
|
|
try
|
|
{
|
|
double xMax = LoadImage(ZielImage);
|
|
Logge("Image geladen");
|
|
if (xMax < imageSCR.Height)
|
|
{
|
|
Logge("Imagegröße kleiner Screenhöhe: " + xMax.ToString());
|
|
ZielImage.Height = xMax;
|
|
}
|
|
else
|
|
{
|
|
Logge("Imagegröße größer Screenhöhe: " + xMax.ToString());
|
|
ZielImage.Height = imageSCR.Height;
|
|
}
|
|
if (xMax < imageSCR.Width)
|
|
{
|
|
Logge("Imagegröße kleiner Screenbreite: " + xMax.ToString());
|
|
ZielImage.Width = xMax;
|
|
}
|
|
else
|
|
{
|
|
Logge("Imagegröße größer Screenbreite: " + xMax.ToString());
|
|
ZielImage.Width = imageSCR.Width;
|
|
}
|
|
AniImage(ZielImage);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
LoggeFehler("Exception in " + ex.Source + ": " + ex.Message);
|
|
//MessageBox.Show("Exception in " + ex.Source + ": " + ex.Message);
|
|
}
|
|
}
|
|
|
|
public void LayoutReset()
|
|
{
|
|
try
|
|
{
|
|
//Zurück auf Startposition
|
|
//Zielimage
|
|
this.imageSCR.Width = this.ActualWidth - 110;
|
|
this.imageSCR.Height = this.ActualHeight - 110;
|
|
this.imageSCR.Visibility = Visibility.Hidden;
|
|
//Zitat
|
|
this.txtZitat.SetValue(Canvas.LeftProperty, (double)55);
|
|
this.txtZitat.SetValue(Canvas.TopProperty, (double)110);
|
|
this.txtZitat.Width = this.ActualWidth - 120;
|
|
this.txtZitat.Height = this.ActualHeight - 120;
|
|
this.txtZitat.Visibility = Visibility.Hidden;
|
|
this.txtZitat.Opacity = 1;
|
|
//Quellbilder
|
|
this.image1.Visibility = Visibility.Hidden;
|
|
this.image1.SetValue(Canvas.LeftProperty, (double)5);
|
|
this.image1.SetValue(Canvas.TopProperty, (double)5);
|
|
this.image1.Opacity = 1;
|
|
this.image2.Visibility = Visibility.Hidden;
|
|
this.image2.SetValue(Canvas.LeftProperty, (double)5);
|
|
this.image2.SetValue(Canvas.LeftProperty, (double)this.ActualWidth - 55);
|
|
this.image2.Opacity = 1;
|
|
this.image3.Visibility = Visibility.Hidden;
|
|
this.image3.SetValue(Canvas.LeftProperty, (double)this.ActualHeight - 55);
|
|
this.image3.SetValue(Canvas.LeftProperty, (double)5);
|
|
this.image3.Opacity = 1;
|
|
this.image4.Visibility = Visibility.Hidden;
|
|
this.image4.SetValue(Canvas.LeftProperty, (double)this.ActualHeight - 55);
|
|
this.image4.SetValue(Canvas.LeftProperty, (double)this.ActualWidth - 55);
|
|
this.image4.Opacity = 1;
|
|
this.image5.Visibility = Visibility.Hidden;
|
|
this.image5.Opacity = 1;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
LoggeFehler("Exception in " + ex.Source + ": " + ex.Message);
|
|
//MessageBox.Show("Exception in " + ex.Source + ": " + ex.Message);
|
|
}
|
|
}
|
|
|
|
private void ZoomAni(Image ZielImage)
|
|
{
|
|
try
|
|
{
|
|
//Skalierung XY
|
|
DoubleAnimation daScaleXY = new DoubleAnimation(0.1, 1, TimeSpan.FromSeconds(5));
|
|
AnimationClock myClockXY = daScaleXY.CreateClock();
|
|
ScaleTransform scaleXY = new ScaleTransform(1,1);
|
|
ZielImage.RenderTransform = scaleXY;
|
|
//Ecke oben
|
|
DoubleAnimation daTop = new DoubleAnimation();
|
|
daTop.Duration = new Duration(TimeSpan.FromSeconds(5));
|
|
//Ecke Links
|
|
DoubleAnimation daLeft = new DoubleAnimation();
|
|
daLeft.Duration = new Duration(TimeSpan.FromSeconds(5));
|
|
//Opacity
|
|
DoubleAnimation daOpa = new DoubleAnimation(0.1, 1, TimeSpan.FromSeconds(5));
|
|
//
|
|
switch (ZielImage.Name)
|
|
{
|
|
case "image1":
|
|
daTop.From = (double)5;
|
|
daTop.To = (double)55;
|
|
daLeft.From = (double)5;
|
|
daLeft.To = (double)55;
|
|
break;
|
|
case "image2":
|
|
daTop.From = (double)5;
|
|
daTop.To = (double)55;
|
|
daLeft.From = (double)(this.ActualWidth - 55);
|
|
daLeft.To = (double)((this.ActualWidth - ZielImage.Width) / 2);
|
|
break;
|
|
case "image3":
|
|
daTop.From = (double)(this.ActualHeight - 55);
|
|
daTop.To = (double)((this.ActualHeight - ZielImage.Height) / 2);
|
|
daLeft.From = (double)5;
|
|
daLeft.To = (double)55;
|
|
break;
|
|
case "image4":
|
|
daTop.From = (double)this.ActualHeight - 55;
|
|
daTop.To = (double)((this.ActualHeight - ZielImage.Height) / 2);
|
|
daLeft.From = (double)(this.ActualWidth - 55);
|
|
daLeft.To = (double)((this.ActualWidth - ZielImage.Width) / 2);
|
|
break;
|
|
}
|
|
//Logge("Top: " + daTop.From.ToString() + " => " + daTop.To.ToString());
|
|
//Logge("Left: " + daLeft.From.ToString() + " => " + daLeft.To.ToString());
|
|
//
|
|
//zur Sicherheit - weil einige Bilder einfach nicht angezeigt werden
|
|
if (daTop.To > (double)1000) { daTop.To = (double)1; };
|
|
if (daLeft.To > (double)1000) { daLeft.To = (double)1; };
|
|
|
|
Storyboard sb = new Storyboard();
|
|
sb.Children.Add(daLeft);
|
|
sb.Children.Add(daTop);
|
|
//sb.Children.Add(daScaleX);
|
|
//sb.Children.Add(daScaleY);
|
|
//
|
|
sb.Children.Add(daOpa);
|
|
//
|
|
Storyboard.SetTargetName(daLeft, ZielImage.Name);
|
|
Storyboard.SetTargetProperty(daLeft, new PropertyPath(Canvas.LeftProperty));
|
|
Storyboard.SetTargetName(daTop, ZielImage.Name);
|
|
Storyboard.SetTargetProperty(daTop, new PropertyPath(Canvas.TopProperty));
|
|
Storyboard.SetTargetName(daLeft, ZielImage.Name);
|
|
//Storyboard.SetTargetProperty(daScaleX, new PropertyPath(ScaleTransform.ScaleXProperty));
|
|
//Storyboard.SetTargetProperty(daScaleY, new PropertyPath(ScaleTransform.ScaleYProperty));
|
|
//
|
|
Storyboard.SetTargetProperty(daOpa, new PropertyPath("(Opacity)"));
|
|
Storyboard.SetTargetName(daOpa, ZielImage.Name);
|
|
//
|
|
this.Resources.Clear();
|
|
this.Resources.Add("ZoomAniImg", sb);
|
|
//ZielImage.Opacity = 0; //durchsichtig
|
|
ZielImage.Visibility = Visibility.Visible;
|
|
sb.Begin();
|
|
//Logge("StoryboardAnimation gestartet");
|
|
scaleXY.ApplyAnimationClock(ScaleTransform.ScaleXProperty, myClockXY);
|
|
scaleXY.ApplyAnimationClock(ScaleTransform.ScaleYProperty, myClockXY);
|
|
//Logge("AnimationClock gestartet");
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
//LoggeFehler("Exception in " + ex.Source + ": " + ex.Message);
|
|
MessageBox.Show("Exception in " + ex.Source + ": " + ex.Message,"ZoomAni");
|
|
}
|
|
}
|
|
|
|
private void AniImage(Image ZielImage)
|
|
{
|
|
Logge("Ani " + ZielImage.Name);
|
|
try
|
|
{
|
|
//in die Mitte
|
|
ZielImage.SetValue(Canvas.LeftProperty, (double)((this.ActualWidth - ZielImage.Width) / 2));
|
|
ZielImage.SetValue(Canvas.TopProperty, (double)((this.ActualHeight - ZielImage.Height) / 2));
|
|
ZielImage.Opacity = 0; //durchsichtig
|
|
ZielImage.Visibility = Visibility.Visible; //sichtbar - na ja - fast
|
|
DoubleAnimation da = new DoubleAnimation();
|
|
da.From = 0;
|
|
da.To = 1;
|
|
da.Duration = new Duration(TimeSpan.FromSeconds(7));
|
|
Storyboard sb = new Storyboard();
|
|
sb.Children.Add(da);
|
|
Storyboard.SetTargetName(da, ZielImage.Name);
|
|
Storyboard.SetTargetProperty(da, new PropertyPath("(Opacity)"));
|
|
this.Resources.Clear();
|
|
this.Resources.Add("AniImg", sb);
|
|
sb.Begin();
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
LoggeFehler("Exception in " + ex.Source + ": " + ex.Message);
|
|
//MessageBox.Show("Exception in " + ex.Source + ": " + ex.Message);
|
|
}
|
|
}
|
|
|
|
|
|
private void ZoomZitatAni()
|
|
{
|
|
Logge("Zitat ani ...");
|
|
try
|
|
{
|
|
DoubleAnimation da = new DoubleAnimation();
|
|
da.From = 0;
|
|
da.To = 1;
|
|
da.Duration = new Duration(TimeSpan.FromSeconds(1));
|
|
Storyboard sb = new Storyboard();
|
|
sb.Children.Add(da);
|
|
Storyboard.SetTargetName(da, txtZitat.Name);
|
|
Storyboard.SetTargetProperty(da, new PropertyPath("(Opacity)"));
|
|
this.Resources.Clear();
|
|
this.Resources.Add("AniZitat", sb);
|
|
txtZitat.Visibility = Visibility.Visible;
|
|
sb.Begin();
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
LoggeFehler("Exception in " + ex.Source + ": " + ex.Message);
|
|
//MessageBox.Show("Exception in " + ex.Source + ": " + ex.Message);
|
|
}
|
|
|
|
}
|
|
|
|
private void ZitatDeAni()
|
|
{
|
|
Logge("Zitat de-ani ...");
|
|
try
|
|
{
|
|
DoubleAnimation da = new DoubleAnimation();
|
|
da.From = 1;
|
|
da.To = 0;
|
|
da.Duration = new Duration(TimeSpan.FromSeconds(2));
|
|
Storyboard sb = new Storyboard();
|
|
sb.Children.Add(da);
|
|
Storyboard.SetTargetName(da, txtZitat.Name);
|
|
Storyboard.SetTargetProperty(da, new PropertyPath("(Opacity)"));
|
|
this.Resources.Clear();
|
|
this.Resources.Add("DeAniZitat", sb);
|
|
sb.Begin();
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
LoggeFehler("Exception in " + ex.Source + ": " + ex.Message);
|
|
//MessageBox.Show("Exception in " + ex.Source + ": " + ex.Message);
|
|
}
|
|
}
|
|
|
|
private void WinDeAni()
|
|
{
|
|
Logge("MainWindow DeAni ...");
|
|
try
|
|
{
|
|
DoubleAnimation da = new DoubleAnimation();
|
|
da.From = 0;
|
|
da.To = 1;
|
|
da.Duration = new Duration(TimeSpan.FromSeconds(2));
|
|
Storyboard sb = new Storyboard();
|
|
sb.Children.Add(da);
|
|
Storyboard.SetTargetName(da, this.Name);
|
|
Storyboard.SetTargetProperty(da, new PropertyPath("(Opacity)"));
|
|
this.Resources.Clear();
|
|
this.Resources.Add("DeAniWin", sb);
|
|
sb.Begin();
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
LoggeFehler("Exception in " + ex.Source + ": " + ex.Message);
|
|
//MessageBox.Show("Exception in " + ex.Source + ": " + ex.Message);
|
|
}
|
|
}
|
|
|
|
private bool LoadZitat()
|
|
{
|
|
try
|
|
{
|
|
string phpUrl = "https://robert.rkaehler.net/kaehler.scr/getZitatTxt.php";
|
|
string sDummy = LoadTextFromUrl(phpUrl);
|
|
Logge("Zitat geladen:" + sDummy);
|
|
if (sDummy.StartsWith("Err:"))
|
|
{
|
|
txtZitat.Text = "Fehler beim Zugriff auf die Zitate-Datenbank: \r\n" +
|
|
sDummy.Substring(5);
|
|
return false;
|
|
}
|
|
else
|
|
{
|
|
txtZitat.Text = sDummy;
|
|
int xlen = sDummy.Length;
|
|
if (xlen > 0)
|
|
{ return true; }
|
|
else
|
|
{ return false; }
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
LoggeFehler("Exception in " + ex.Source + ": " + ex.Message);
|
|
//MessageBox.Show("Exception in " + ex.Source + ": " + ex.Message);
|
|
return false;
|
|
}
|
|
}
|
|
|
|
private double LoadImage(Image ZielImage)
|
|
{
|
|
try
|
|
{
|
|
string ImageName = ZielImage.Name.ToString();
|
|
string BaseName = "https://robert.rkaehler.net/kaehler.scr/getFile_";
|
|
string DirNum = ImageName.Substring(ImageName.Length - 1);
|
|
string phpUrl = BaseName + DirNum + ".php";
|
|
string ImageUrl = LoadTextFromUrl(phpUrl).Replace("\r\n", "");
|
|
if ((ImageUrl.Length == 0) | (ImageUrl.StartsWith("Err:")))
|
|
{ return 0; }
|
|
else
|
|
{ return LoadImageFromUrl(ZielImage, ImageUrl); }
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
LoggeFehler("Exception in " + ex.Source + ": " + ex.Message);
|
|
//MessageBox.Show("Exception in " + ex.Source + ": " + ex.Message);
|
|
return 0;
|
|
}
|
|
|
|
}
|
|
|
|
private void DeAniImage(Image ZielImage)
|
|
{
|
|
Logge("DeAni " + ZielImage.Name);
|
|
try
|
|
{
|
|
DoubleAnimation da = new DoubleAnimation();
|
|
da.From = 1;
|
|
da.To = 0;
|
|
da.Duration = new Duration(TimeSpan.FromSeconds(2));
|
|
Storyboard sb = new Storyboard();
|
|
sb.Children.Add(da);
|
|
Storyboard.SetTargetName(da, ZielImage.Name);
|
|
Storyboard.SetTargetProperty(da, new PropertyPath("(Opacity)"));
|
|
this.Resources.Clear();
|
|
this.Resources.Add("DeAniImg", sb);
|
|
sb.Begin();
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
LoggeFehler("Exception in " + ex.Source + ": " + ex.Message);
|
|
//MessageBox.Show("Exception in " + ex.Source + ": " + ex.Message);
|
|
}
|
|
}
|
|
|
|
private string LoadTextFromUrl(string TextUrl)
|
|
{
|
|
int BytesToRead = 100;
|
|
string sDummy = "";
|
|
try
|
|
{
|
|
//WebRequest request = WebRequest.Create(new Uri(TextUrl, UriKind.Absolute));
|
|
WebRequest request = WebRequest.Create(TextUrl);
|
|
request.Timeout = 500;
|
|
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
|
|
WebResponse response = request.GetResponse();
|
|
Console.WriteLine(((HttpWebResponse)response).StatusDescription);
|
|
Stream responseStream = response.GetResponseStream();
|
|
BinaryReader reader = new BinaryReader(responseStream);
|
|
MemoryStream memoryStream = new MemoryStream();
|
|
byte[] bytebuffer = new byte[BytesToRead];
|
|
int bytesRead = reader.Read(bytebuffer, 0, BytesToRead);
|
|
while (bytesRead > 0)
|
|
{
|
|
memoryStream.Write(bytebuffer, 0, bytesRead);
|
|
bytesRead = reader.Read(bytebuffer, 0, BytesToRead);
|
|
}
|
|
memoryStream.Seek(0, SeekOrigin.Begin);
|
|
StreamReader readerTXT = new StreamReader(memoryStream);
|
|
sDummy = readerTXT.ReadToEnd();
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
sDummy = "Err: " + ex.Message;
|
|
}
|
|
return sDummy.Trim();
|
|
}
|
|
|
|
private string getTempPath()
|
|
{
|
|
string tempPath = System.IO.Path.GetTempPath();
|
|
tempPath += "Kaehler.Scr\\";
|
|
if (!File.Exists(tempPath))
|
|
{
|
|
System.IO.Directory.CreateDirectory(tempPath);
|
|
}
|
|
return tempPath;
|
|
}
|
|
|
|
private string getTempImgName(string ImageUrl)
|
|
{
|
|
string sName = getTempPath();
|
|
int x1 = ImageUrl.LastIndexOf("/");
|
|
string sPre = ImageUrl.Substring(x1 - 1, 1) + "_";
|
|
return sName + sPre + ImageUrl.Substring(x1+1);
|
|
}
|
|
|
|
private double LoadImageFromUrl(Image ZielImage, string ImageUrl)
|
|
{
|
|
Logge("LoadImage " + ImageUrl + " => " + ZielImage.Name);
|
|
double xMax = 0;
|
|
int BytesToRead = 100;
|
|
try
|
|
{
|
|
BitmapImage tmpImage = new BitmapImage();
|
|
string sCacheFileName = getTempImgName(ImageUrl);
|
|
if (!File.Exists(sCacheFileName))
|
|
{
|
|
//WebRequest request = WebRequest.Create(new Uri(ImageUrl, UriKind.Absolute));
|
|
WebRequest request = WebRequest.Create(ImageUrl);
|
|
request.Timeout = 500;
|
|
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
|
|
WebResponse response = request.GetResponse();
|
|
Stream responseStream = response.GetResponseStream();
|
|
BinaryReader reader = new BinaryReader(responseStream);
|
|
MemoryStream memoryStream = new MemoryStream();
|
|
|
|
byte[] bytebuffer = new byte[BytesToRead];
|
|
int bytesRead = reader.Read(bytebuffer, 0, BytesToRead);
|
|
while (bytesRead > 0)
|
|
{
|
|
memoryStream.Write(bytebuffer, 0, bytesRead);
|
|
bytesRead = reader.Read(bytebuffer, 0, BytesToRead);
|
|
}
|
|
tmpImage.BeginInit();
|
|
memoryStream.Seek(0, SeekOrigin.Begin);
|
|
tmpImage.StreamSource = memoryStream;
|
|
tmpImage.EndInit();
|
|
|
|
ZielImage.Source = tmpImage;
|
|
//in den Cache ...
|
|
FileStream jpgstream = new FileStream(sCacheFileName, FileMode.Create);
|
|
JpegBitmapEncoder encoder = new JpegBitmapEncoder();
|
|
encoder.Frames.Add(BitmapFrame.Create(tmpImage));
|
|
encoder.Save(jpgstream);
|
|
jpgstream.Flush();
|
|
jpgstream.Close();
|
|
//
|
|
}
|
|
else //aus dem Cache lesen
|
|
{
|
|
tmpImage.BeginInit();
|
|
tmpImage.UriSource = new Uri(@"file:///" + sCacheFileName, UriKind.RelativeOrAbsolute);
|
|
tmpImage.EndInit();
|
|
ZielImage.Source = tmpImage;
|
|
}
|
|
|
|
if (tmpImage.Height > tmpImage.Width)
|
|
{
|
|
xMax = tmpImage.Height;
|
|
}
|
|
else
|
|
{
|
|
xMax = tmpImage.Width;
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
LoggeFehler("Fehler in LoadImageFromUrl: " + ex.Message);
|
|
//MessageBox.Show("Exception in " + ex.Source + ": " + ex.Message);
|
|
ZielImage.Source = imageBug.Source;
|
|
xMax = imageBug.Height;
|
|
}
|
|
return xMax;
|
|
}
|
|
|
|
private void Window_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
|
|
{
|
|
SCRBeenden();
|
|
}
|
|
|
|
private void Window_MouseRightButtonUp(object sender, MouseButtonEventArgs e)
|
|
{
|
|
SCRBeenden();
|
|
}
|
|
|
|
private void Window_MouseDoubleClick(object sender, MouseButtonEventArgs e)
|
|
{
|
|
SCRBeenden();
|
|
}
|
|
|
|
private void Window_KeyUp(object sender, KeyEventArgs e)
|
|
{
|
|
SCRBeenden();
|
|
}
|
|
|
|
private void image1_KeyDown(object sender, KeyEventArgs e)
|
|
{
|
|
SCRBeenden();
|
|
}
|
|
|
|
private void image1_MouseDown(object sender, MouseButtonEventArgs e)
|
|
{
|
|
SCRBeenden();
|
|
}
|
|
|
|
private void image1_MouseWheel(object sender, MouseWheelEventArgs e)
|
|
{
|
|
SCRBeenden();
|
|
}
|
|
|
|
private void image2_KeyDown(object sender, KeyEventArgs e)
|
|
{
|
|
SCRBeenden();
|
|
}
|
|
|
|
private void image2_MouseDown(object sender, MouseButtonEventArgs e)
|
|
{
|
|
SCRBeenden();
|
|
}
|
|
|
|
private void image2_MouseWheel(object sender, MouseWheelEventArgs e)
|
|
{
|
|
SCRBeenden();
|
|
}
|
|
|
|
private void txtZitat_MouseDown(object sender, MouseButtonEventArgs e)
|
|
{
|
|
SCRBeenden();
|
|
}
|
|
|
|
private void txtZitat_KeyDown(object sender, KeyEventArgs e)
|
|
{
|
|
SCRBeenden();
|
|
}
|
|
|
|
private void txtZitat_MouseWheel(object sender, MouseWheelEventArgs e)
|
|
{
|
|
SCRBeenden();
|
|
}
|
|
|
|
private void SimpleEventLog(String sText, Boolean fErr)
|
|
{
|
|
//'Schreibt nur als Information in Anwendungs-Log
|
|
try
|
|
{
|
|
String sBereich = "";
|
|
if (fErr)
|
|
{
|
|
sBereich = "KaehlerSCR-Fehler: ";
|
|
using (EventLog eventLog = new EventLog("Application"))
|
|
{
|
|
eventLog.Source = "Application";
|
|
eventLog.WriteEntry(sBereich + sText, EventLogEntryType.Error, 102, 2);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
sBereich = "KaehlerSCR-Meldung: ";
|
|
using (EventLog eventLog = new EventLog("Application"))
|
|
{
|
|
eventLog.Source = "Application";
|
|
eventLog.WriteEntry(sText, EventLogEntryType.Information, 101, 1);
|
|
}
|
|
}
|
|
//EventLogTraceListener listener = new EventLogTraceListener(sBereich);
|
|
//Debug.Listeners.Add(listener);
|
|
//Debug.WriteLine(sText);
|
|
//listener.Flush();
|
|
}
|
|
catch (Exception ignore) {
|
|
Console.WriteLine("Fehler in SimpleEventLog: " + ignore.Message);
|
|
Console.WriteLine("Fehler in SimpleEventLog Fehlertext war: " + sText);
|
|
}
|
|
}
|
|
}
|
|
}
|