Click here to Skip to main content
15,867,594 members
Articles / Programming Languages / C#

An Introduction to the Silverlight samples in the All-In-One Framework

Rate me:
Please Sign up or sign in to vote.
5.00/5 (26 votes)
12 Dec 2009Ms-PL5 min read 54.9K   2.2K   56  
This article introduces several Silverlight samples in the All-In-One Framework.
/****************************** Module Header ******************************\
* Module Name:  GenerateDeepZoomService.cs
* Project:      DeepZoomProjectSite
* Copyright (c) Microsoft Corporation.
* 
* This example demonstrates how to generate the deep zoom content programmatically in Silverlight using C#. It wraps the functionality in a WCF service.
* 
* This source is subject to the Microsoft Public License.
* See http://www.microsoft.com/opensource/licenses.mspx#Ms-PL.
* All other rights reserved.
* 
* History:
* * 8/27/2009 15:40 Yilun Luo Created
\***************************************************************************/

using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.Text;
using System.IO;
using System.ServiceModel.Activation;
using System.Web;
using System.Net;
using Microsoft.DeepZoomTools;
using System.Xml.Linq;
using System.Windows;

// NOTE: If you change the class name "GenerateDeepZoomService" here, you must also update the reference to "GenerateDeepZoomService" in Web.config.
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
public class GenerateDeepZoomService : IGenerateDeepZoomService
{

	public bool PrepareDeepZoom(bool forceGenerateDeepZoom)
	{
		if(!Directory.Exists(HttpContext.Current.Server.MapPath("~/ClientBin/GeneratedImages/dzc_output_images")) || forceGenerateDeepZoom)
		{
			try
			{
				this.CreateDeepZoom();
			}
			catch
			{
				return false;
			}
		}
		return true;
	}

	/// <summary>
	/// Generate the deep zoom content using a CollectionCreator.
	/// </summary>
	private void CreateDeepZoom()
	{
		CollectionCreator creator = new CollectionCreator();
		List<Image> images = new List<Image>();
		XDocument doc = XDocument.Load(HttpContext.Current.Server.MapPath("~/ClientBin/GeneratedImages/Metadata.xml"));
		var imageElements = doc.Root.Elements("Image");
		double aspectRatio = double.Parse(doc.Root.Element("AspectRatio").Value);
		//Populates a list of Microsoft.DeepZoomTools.Image objects using the value provided in Metadata.xml.
		foreach (XElement imageElement in imageElements)
		{
			int zOrder = int.Parse(imageElement.Element("ZOrder").Value);
			double width = 1d / double.Parse(imageElement.Element("Width").Value);
			images.Add(new Image(HttpContext.Current.Server.MapPath("~/SourceImages/" + imageElement.Element("FileName").Value))
			{
				ViewportWidth = width,
				ViewportOrigin = new Point(double.Parse(imageElement.Element("x").Value) * -width, double.Parse(imageElement.Element("y").Value) * -width / aspectRatio),
			});
		}
		creator.Create(images, HttpContext.Current.Server.MapPath("~/ClientBin/GeneratedImages/dzc_output"));
	}
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Microsoft Public License (Ms-PL)


Written By
China China
Microsoft All-In-One Code Framework delineates the framework and skeleton of Microsoft development techniques through typical sample codes in three popular programming languages (Visual C#, VB.NET, Visual C++). Each sample is elaborately selected, composed, and documented to demonstrate one frequently-asked, tested or used coding scenario based on our support experience in MSDN newsgroups and forums. If you are a software developer, you can fill the skeleton with blood, muscle and soul. If you are a software tester or a support engineer like us, you may extend the sample codes a little to fit your specific test scenario or refer your customer to this project if the customer's question coincides with what we collected.
http://cfx.codeplex.com/

Comments and Discussions