<lib:TransitionPresenter x:Name="tp" Margin="10">
<lib:TransitionPresenter.Resources>
<Converters:ByteArrayToImageConverter x:Key="ByteArrayToImageConverter"/>
<DataTemplate DataType="{x:Type BusinessObjects:CustomImage}">
<Image Width="300"
Height="300"
Source="{Binding Path=Img, Converter={StaticResource ByteArrayToImageConverter}, Mode=Default}"
/>
</DataTemplate>
</lib:TransitionPresenter.Resources>
</lib:TransitionPresenter>
public class ByteArrayToImageConverter : IValueConverter
{
#region IValueConverter Members
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
BitmapImage ImgSource = null;
byte[] array = value as byte[];
if (array != null)
ImgSource = new BitmapImage();
ImgSource.BeginInit();
ImgSource.StreamSource = new MemoryStream(array);
ImgSource.EndInit();
}
return ImgSource;
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
return null;
#endregion
timer = new DispatcherTimer();
timer.Interval = new TimeSpan(0, 0, interval);
timer.IsEnabled = true;
timer.Tick += new EventHandler(timer_Tick);
timer.Start();
/// <summary>
/// Method called when the Tick event of the timer occurs.
/// </summary>
private void timer_Tick(object sender, EventArgs e)
Transition[] transitions = (Transition[])FindResource("Transitions");
int nextValTransition;
int nextValData;
do
nextValTransition = rmdTransition.Next(1, transitions.Length);
while (nextValTransition == previousTransition);
previousTransition = nextValTransition;
this.tp.Transition = transitions[nextValTransition];
nextValData = rdmImg.Next(0, GlobalImageList.Count);
while (nextValData == previousValue);
previousValue = nextValData;
this.tp.Content = GlobalImageList[nextValData];
[CallbackBehavior(ConcurrencyMode = ConcurrencyMode.Multiple, UseSynchronizationContext = false)]
public class WCFClient : IServerContractCallback
#region Member Fields
private ServerContractClient sc = null;
public delegate void GetImagesFromServerHandler(CustomImage[] imgList);
public event GetImagesFromServerHandler GetImagesFromServerEvent;
public delegate void GetUpdateFromFileShareHandler(CustomImage img);
public event GetUpdateFromFileShareHandler GetUpdateFromFileShareEvent;
/// Public constructor.
public WCFClient()
sc = new ServerContractClient(new System.ServiceModel.InstanceContext(this));
sc.Open();
/// Ask the service to launch the FileSystemWatcher on the server.
/// <param name="path">The folder to watch on the server.</param>
public void StartWatcher(string path)
sc.StartWatcher(path);
/// Ask the service to get the images which are in the dedicated folder.
/// <param name="path">The folder that you want the images.</param>
public void GetImagesFromPathAtFirstLoad(string path)
try
sc.GetImagesFromPathAtFirstLoad(path);
catch (ServerException ex)
throw new FaultException<ServerException>(new ServerException(
string.Format("An error occured !{0}{1}", Environment.NewLine, ex.Message)));
/// Disconnect the client from the service.
public void Disconnect()
sc.Close();
#region IServerContractCallback Members
/// Method called when the service pushed the images to the client.
/// <param name="imgList">The list of images to load/get from the server.</param>
public void GetImagesFromServer(CustomImage[] imgList)
if (GetImagesFromServerEvent != null)
GetImagesFromServerEvent(imgList);
/// Method called when the service detext an update in the folder where the image are stored.
/// <param name="img">The image that has been added/removed from the folder</param>
public void GetUpdateFromFileShare(CustomImage img)
if (GetUpdateFromFileShareEvent != null)
GetUpdateFromFileShareEvent(img);
client.GetImagesFromServerEvent +=
new WCFClient.GetImagesFromServerHandler(client_GetImagesFromServerEvent);
client.GetUpdateFromFileShareEvent +=
new WCFClient.GetUpdateFromFileShareHandler(client_GetUpdateFromFileShareEvent);
/// Method that get the list of images from the server, during the first startup of the application.
/// <param name="imgList">An array containing all the images in the folder.</param>
/// <returns>A list of CustomImage, representing the images in the folder.</returns>
private void client_GetImagesFromServerEvent(CustomImage[] imgList)
GlobalImageList = imgList.ToList();
/// Method that handle the update of the folder on the server.
/// <param name="img">The image added or remove from the folder on the server.</param>
/// <returns>The image that has been added/removed from the folder on the server.</returns>
private void client_GetUpdateFromFileShareEvent(CustomImage img)
switch (img.Modification)
case CustomImage.ChangeType.Add:
GlobalImageList.Add(img);
break;
case CustomImage.ChangeType.Delete:
GlobalImageList.Remove(img);
default:
Premier effet de style
Deuxième type de transition possible