|
using AvalonDock;
using ReflectionStudio.Core.Helpers;
using ReflectionStudio.Components.Dialogs.Startup;
using ReflectionStudio.Classes;
using System.Windows;
using ReflectionStudio.Core;
using System.Windows.Documents;
using System.Windows.Markup;
using System.IO;
using System;
using System.Windows.Navigation;
using System.ComponentModel;
using ReflectionStudio.Core.Events;
namespace ReflectionStudio.Components.UserControls
{
/// <summary>
/// Interaction logic for HomeDocument.xaml
/// </summary>
public partial class HomeDocument : DocumentContent
{
public HomeDocument()
{
InitializeComponent();
}
private void DocumentContent_Loaded(object sender, RoutedEventArgs e)
{
try
{
string urlToRead = "http://i3.codeplex.com/Project/Download/FileDownload.aspx?ProjectName=ReflectionStudio&DownloadId=132959";
string destFile = System.IO.Path.Combine(PathHelper.ApplicationPath, "Home.xaml");
BackgroundWorker webWorker = new BackgroundWorker();
webWorker.WorkerReportsProgress = false;
webWorker.WorkerSupportsCancellation = false;
webWorker.DoWork += new DoWorkEventHandler(bw_DoWork);
webWorker.RunWorkerCompleted += new RunWorkerCompletedEventHandler(bw_RunWorkerCompleted);
// Start the asynchronous operation.
webWorker.RunWorkerAsync(new UrlSaveHelper(urlToRead, destFile));
}
catch (Exception all)
{
}
}
void bw_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
{
// First, handle the case where an exception was thrown.
if (e.Error != null)
{
Tracer.Error("ProjectService.Create", e.Error);
}
else
{
UrlSaveHelper hlp = (UrlSaveHelper)e.Result;
string destFile = System.IO.Path.Combine(PathHelper.ApplicationPath, "Home.xaml");
// Finally, handle the case where the operation succeeded.
if (File.Exists(destFile))
{
FileStream fs = File.OpenRead(destFile);
FlowDocViewer.Document = (FlowDocument)XamlReader.Load(fs);
fs.Close();
ParseHyperlink(FlowDocViewer.Document);
Tracer.Verbose("ProjectService:Create", "END");
}
}
}
void bw_DoWork(object sender, DoWorkEventArgs e)
{
UrlSaveHelper hlp = (UrlSaveHelper)e.Argument;
hlp.SaveUrlContent();
}
#region --------------------FLOWDOC PROCESS--------------------
/// <summary>
/// Find elements in the flow document to associate events
/// </summary>
/// <param name="flowDocument"></param>
private void ParseHyperlink(FlowDocument flowDocument)
{
Hyperlink hp = flowDocument.FindName("HyperlinkNewProject") as Hyperlink;
hp.Click += new RoutedEventHandler(HyperlinkNewProject_Click);
hp = null;
int counter = 1;
do
{
hp = flowDocument.FindName(string.Format("HyperlinkNaviguate{0}", counter)) as Hyperlink;
if( hp != null)
hp.RequestNavigate += new RequestNavigateEventHandler(Hyperlink_RequestNavigate);
counter++;
}
while (hp != null);
}
/// <summary>
/// Launch special application link
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void HyperlinkNewProject_Click(object sender, System.Windows.RoutedEventArgs e)
{
StartupDlg dlg = new StartupDlg();
dlg.Owner = Application.Current.MainWindow;
dlg.DataContext = BindingView.Instance;
dlg.ShowDialog();
}
/// <summary>
/// launch any web request
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void Hyperlink_RequestNavigate(object sender, System.Windows.Navigation.RequestNavigateEventArgs e)
{
ProcessHelper.LaunchWebUri(e.Uri);
e.Handled = true;
}
#endregion
}
}
|
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.
WPF and MVVM fan, I practice C # in all its forms from the beginning of the NET Framework without mentioning C ++ / MFC and other software packages such as databases, ASP, WCF, Web & Windows services, Application, and now Core and UWP.
In my wasted hours, I am guilty of having fathered C.B.R. and its cousins C.B.R. for WinRT and UWP on the Windows store.
But apart from that, I am a great handyman ... the house, a rocket stove to heat the jacuzzi and the last one: a wood oven for pizza, bread, and everything that goes inside
https://guillaumewaser.wordpress.com/
https://fouretcompagnie.wordpress.com/