/// <summary>
		/// Initializes a new instance of the <see cref="PrintToolViewModel"/> class.
		/// </summary>
		/// <param name="other">The other.</param>
		public PrintToolViewModel(PrintToolViewModel other)
		{
			CopyAllSettings(other);

			Error = null;
			Status = null;
		}
		/// <summary>
		/// Copies all settings.
		/// </summary>
		/// <param name="source">The source.</param>
		private void CopyAllSettings(PrintToolViewModel source)
		{
			if (source != null)
			{
				this.IsServiceAsynchronous = source.IsServiceAsynchronous;
				this.PrintWithArcGISServer = source.PrintWithArcGISServer;
				this.UseProxy = source.UseProxy;
				this.PrintTaskURL = source.PrintTaskURL;
				this.Title = source.Title;
				this.IsTitleVisible = source.IsTitleVisible;
				this.Description = source.Description;
				this.IsDescriptionVisible = source.IsDescriptionVisible;				
				this.PrintWidthString = Convert.ToString(source.PrintWidth, CultureInfo.InvariantCulture);
				this.IsWidthVisible = source.IsWidthVisible;
				this.PrintHeightString = Convert.ToString(source.PrintHeight, CultureInfo.InvariantCulture);
				this.IsHeightVisible = source.IsHeightVisible;
				this.PrintLayout = source.PrintLayout;
				this.IsPrintLayoutVisible = source.IsPrintLayoutVisible;
				this.CopyrightText = source.CopyrightText;
				this.IsCopyrightTextVisible = source.IsCopyrightTextVisible;
				this.Author = source.Author;
				this.IsAuthorVisible = source.IsAuthorVisible;
				this.LayoutTemplates = source.LayoutTemplates;
				this.LayoutTemplate = source.LayoutTemplate;
				this.IsLayoutTemplatesVisible = source.IsLayoutTemplatesVisible;
				this.Formats = source.Formats;
				this.Format = source.Format;
				this.IsFormatsVisible = source.IsFormatsVisible;
				this.UseScale = source.UseScale;
				this.MapScaleString = Convert.ToString(Math.Round(source.MapScale, 0), CultureInfo.InvariantCulture);
                this.IsDpiVisible = source.IsDpiVisible;
                this.DpiString = source.DpiString;
                this.IsUseScaleVisible = source.isUseScaleVisible;
			}
		}
		/// <summary>
		/// Applies the changes using source model.
		/// </summary>
		/// <param name="sourceModel">The source model.</param>
		public void ApplyChanges(PrintToolViewModel sourceModel)
		{
			CopyAllSettings(sourceModel);
			Status = null;
			Error = null;
		}
		/// <summary>
		/// Shows the PrintToolView when the icon on the toolbar is clicked.
		/// </summary>
		public void Execute(object parameter)
		{
			ToolExecuting = true;
			var toolViewModel = printToolView.DataContext as PrintToolViewModel;
			if (toolViewModel == null && savedConfiguration != null)
			{
				toolViewModel = new PrintToolViewModel(savedConfiguration);
				toolViewModel.Map = MapApplication.Current.Map;
				printToolView.DataContext = toolViewModel;
			}
			if (toolViewModel != null) toolViewModel.Activate();

			// If there is at least one visible setting, print tool view is shown. 
			// Otherwise, print command is executed without the intermediate dialog.
			if (toolViewModel.HasVisibleSetting)
			{
				MapApplication.Current.ShowWindow(Resources.Strings.PrintToolTitle, printToolView, false,
					null,
					(s, e) =>
					{
						ToolExecuting = false;
					},
					WindowType.Floating);
			}
			else
			{
				ToolExecuting = toolViewModel.IsPrinting;
				toolViewModel.PropertyChanged += (a, b) =>
					{
						if (b.PropertyName == "IsPrinting")
							ToolExecuting = toolViewModel.IsPrinting;
					};
				if (toolViewModel.Print.CanExecute(null))
					toolViewModel.Print.Execute(null);
			}
		}
		/// <summary>
		/// Called when configuration wizard is completed.
		/// Updates last saved configuration.
		/// </summary>
		public void OnCompleted()
		{
			var configViewModel = printToolConfigView.DataContext as PrintToolViewModel;
			if (configViewModel != null)
			{
				if (savedConfiguration == null)
					savedConfiguration = new PrintToolViewModel(configViewModel);
				else
					savedConfiguration.ApplyChanges(configViewModel);

				// Tool view on builder must immediately reflect latest configuration
				// so changes are applied to this instance as well.
				var toolViewModel = printToolView.DataContext as PrintToolViewModel;
				if (toolViewModel != null)
					toolViewModel.ApplyChanges(savedConfiguration); 
			}
		}	
		/// <summary>
		/// Deserializes the saved print configuration settings.
		/// </summary>
		public void LoadConfiguration(string configData)
		{
            if (!string.IsNullOrEmpty(configData))
            {
				using (MemoryStream memoryStream = new MemoryStream(Encoding.UTF8.GetBytes(configData)))
				{
					DataContractSerializer xmlSerializer = new DataContractSerializer(typeof(PrintToolViewModel));
					memoryStream.Position = 0;
					savedConfiguration = (PrintToolViewModel)xmlSerializer.ReadObject(memoryStream);					
					memoryStream.Close();
				}
            }
		}