//*****************************************************************************
// Description.....WF4.5 Message Mediation Library
//
// Author..........Roman Kiss, rkiss@pathcom.com
// Copyright © 2009 ATZ Consulting Inc. (see included license.rtf file)
//
// Date Created: 07/07/09
//
// Date Modified By Description
//-----------------------------------------------------------------------------
// 07/07/09 Roman Kiss Initial Revision
// 10/10/12 Roman Kiss Upadate 4.5
//*****************************************************************************
//
#region Namespaces
using System;
using System.IO;
using System.Windows;
using System.Windows.Forms;
using ManageableServicesConsole.UserControls;
#endregion
namespace RKiss.WorkflowDesignerTester
{
public partial class Form1 : Form
{
private string filepath;
public DateTime? LoadedDT { get; set; }
public string LoadedXaml { get; set; }
public Form1()
{
InitializeComponent();
this.LoadedDT = null;
}
public WorkflowDesignerUserControl Designer
{
get { return this.workflowDesignerUserControl1; }
}
private void saveToolStripMenuItem_Click(object sender, EventArgs e)
{
this.SaveXamlFile();
}
private void openToolStripMenuItem_Click(object sender, EventArgs e)
{
if(this.Designer.IsDirty)
{
var result = System.Windows.MessageBox.Show("Would you like to save all changes?", "Open new xaml", MessageBoxButton.YesNoCancel, MessageBoxImage.Question);
if (result == MessageBoxResult.Yes)
this.SaveXamlFile();
else if (result == MessageBoxResult.Cancel)
return;
}
var dialog = new OpenFileDialog()
{
Filter = "xaml|*.xaml|xamlx|*.xamlx|all|*.*",
CheckFileExists = true,
DefaultExt = ".xaml",
Multiselect = false,
RestoreDirectory = true,
Title = "Open xaml file",
};
if (dialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
this.Filepath = dialog.FileName;
this.LoadXamlFile();
}
}
private void newToolStripMenuItem_Click(object sender, EventArgs e)
{
this.LoadedDT = DateTime.Now;
this.LoadedXaml = string.Empty;
this.Designer.Xaml = string.Empty;
}
private void saveAsToolStripMenuItem1_Click(object sender, EventArgs e)
{
var dialog = new SaveFileDialog()
{
CheckPathExists = true,
Filter = "xaml|*.xaml|xamlx|*.xamlx",
AddExtension = true,
OverwritePrompt = true,
CheckFileExists = false,
DefaultExt = ".xaml",
RestoreDirectory = true,
Title = "Save xaml file",
};
if (dialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
if(string.IsNullOrEmpty(dialog.FileName) == false)
this.SaveAsXamlFile(dialog.FileName);
}
}
private void exitToolStripMenuItem_Click(object sender, EventArgs e)
{
this.Close();
}
public void LoadXamlFile()
{
this.LoadXamlFile(this.Filepath);
}
public void LoadXamlFile(string filename)
{
if (File.Exists(filename))
{
this.LoadedDT = DateTime.Now;
this.LoadedXaml = File.ReadAllText(filename);
this.Designer.Xaml = this.LoadedXaml;
}
}
public void SaveXamlFile()
{
this.SaveXamlFile(this.Filepath);
}
public void SaveXamlFile(string filename)
{
if (this.Designer.IsDirty)
{
var result = System.Windows.MessageBox.Show("Would you like to save all changes?", "Open new xaml", MessageBoxButton.YesNoCancel, MessageBoxImage.Question);
if (result == MessageBoxResult.Yes)
File.WriteAllText(filename, this.Designer.Xaml);
else if (result == MessageBoxResult.Cancel)
return;
}
this.Designer.IsDirty = false;
}
public void SaveAsXamlFile(string filename)
{
this.Filepath = filename;
File.WriteAllText(filename, this.Designer.Xaml);
this.Designer.IsDirty = false;
}
public string Filepath
{
get { return filepath; }
set
{
filepath = value;
this.Text = "Workflow Designer (" + value + ")";
}
}
private void aboutWorkflowDesignerToolStripMenuItem_Click(object sender, EventArgs e)
{
new RKiss.WorkflowDesignerTester.Dialogs.WorkflowDesignerTesterAboutBox().ShowDialog();
}
}
}