@ -7,11 +7,16 @@
@@ -7,11 +7,16 @@
* To change this template use Tools | Options | Coding | Edit Standard Headers .
* /
using System ;
using System.Collections.Generic ;
using System.ComponentModel ;
using System.Diagnostics ;
using System.Linq.Expressions ;
using System.Reflection ;
using System.Windows ;
using System.Windows.Input ;
using ICSharpCode.SharpDevelop.Project ;
using Microsoft.Win32 ;
namespace Gui.Dialogs.ReferenceDialog
{
@ -20,11 +25,34 @@ namespace Gui.Dialogs.ReferenceDialog
@@ -20,11 +25,34 @@ namespace Gui.Dialogs.ReferenceDialog
/// </summary>
public class AddServiceReferenceViewModel : ViewModelBase
{
string header1 = "To see a list of available services on an specific Server, " ;
string header2 = "enter a service URL and click Go. To browse for available services click Discover" ;
string noUrl = "Please enter he address of the Service." ;
string discoverMenu = "Services in Solution" ;
public AddServiceReferenceViewModel ( IProject project )
{
Project = project ;
title = "Add Service Reference to <" + Project . Name + ">" ;
title = "Add Service Reference" ;
discoverButtonContend = "Disvover" ;
HeadLine = header1 + header2 ;
MruServices = AddMruList ( ) ;
SelectedService = MruServices [ 0 ] ;
GoCommand = new RelayCommand ( ExecuteGo , CanExecuteGo ) ;
DiscoverCommand = new RelayCommand ( ExecuteDiscover , CanExecuteDiscover ) ;
}
private string art ;
public string Art {
get { return art ; }
set { art = value ;
base . RaisePropertyChanged ( ( ) = > Art ) ;
}
}
@ -36,7 +64,10 @@ namespace Gui.Dialogs.ReferenceDialog
@@ -36,7 +64,10 @@ namespace Gui.Dialogs.ReferenceDialog
base . RaisePropertyChanged ( ( ) = > Title ) ;
}
}
public string HeadLine { get ; private set ; }
private string discoverButtonContend ;
public string DiscoverButtonContend {
@ -56,6 +87,81 @@ namespace Gui.Dialogs.ReferenceDialog
@@ -56,6 +87,81 @@ namespace Gui.Dialogs.ReferenceDialog
}
}
#region Create List of services
// Modifyed Code from Matt
List < string > AddMruList ( )
{
var list = new List < string > ( ) ;
try {
RegistryKey key = Registry . CurrentUser . OpenSubKey ( @"Software\Microsoft\Internet Explorer\TypedURLs" ) ;
if ( key ! = null ) {
foreach ( string name in key . GetValueNames ( ) ) {
list . Add ( ( string ) key . GetValue ( name ) ) ;
}
}
} catch ( Exception )
{
} ;
return list ;
}
private List < string > mruServices ;
public List < string > MruServices {
get {
if ( mruServices = = null ) {
mruServices = new List < string > ( ) ;
}
return mruServices ; }
set { mruServices = value ;
base . RaisePropertyChanged ( ( ) = > MruServices ) ;
}
}
private string selectedService ;
public string SelectedService {
get { return selectedService ; }
set { selectedService = value ;
base . RaisePropertyChanged ( ( ) = > SelectedService ) ; }
}
#endregion
#region Go
public ICommand GoCommand { get ; private set ; }
private void ExecuteGo ( )
{
string s = String . Format ( "<Go> with Service <{0}>" , SelectedService ) ;
MessageBox . Show ( s ) ;
}
private bool CanExecuteGo ( )
{
return true ;
}
#endregion
#region Discover
public ICommand DiscoverCommand { get ; private set ; }
private bool CanExecuteDiscover ( )
{
return true ;
}
private void ExecuteDiscover ( )
{
MessageBox . Show ( "<Discover> is not implemented at the Moment" ) ;
}
#endregion
}
public class ViewModelBase : INotifyPropertyChanged
@ -118,4 +224,147 @@ namespace Gui.Dialogs.ReferenceDialog
@@ -118,4 +224,147 @@ namespace Gui.Dialogs.ReferenceDialog
return memberExpression . Member . Name ;
}
}
public class RelayCommand < T > : ICommand
{
#region Declarations
readonly Predicate < T > _ canExecute ;
readonly Action < T > _ execute ;
#endregion
#region Constructors
/// <summary>
/// Initializes a new instance of the <see cref="RelayCommand<T>"/> class and the command can always be executed.
/// </summary>
/// <param name="execute">The execution logic.</param>
public RelayCommand ( Action < T > execute )
: this ( execute , null )
{
}
/// <summary>
/// Initializes a new instance of the <see cref="RelayCommand<T>"/> class.
/// </summary>
/// <param name="execute">The execution logic.</param>
/// <param name="canExecute">The execution status logic.</param>
public RelayCommand ( Action < T > execute , Predicate < T > canExecute )
{
if ( execute = = null )
throw new ArgumentNullException ( "execute" ) ;
_ execute = execute ;
_ canExecute = canExecute ;
}
#endregion
#region ICommand Members
public event EventHandler CanExecuteChanged
{
add
{
if ( _ canExecute ! = null )
CommandManager . RequerySuggested + = value ;
}
remove
{
if ( _ canExecute ! = null )
CommandManager . RequerySuggested - = value ;
}
}
[DebuggerStepThrough]
public Boolean CanExecute ( Object parameter )
{
return _ canExecute = = null ? true : _ canExecute ( ( T ) parameter ) ;
}
public void Execute ( Object parameter )
{
_ execute ( ( T ) parameter ) ;
}
#endregion
}
/// <summary>
/// A command whose sole purpose is to relay its functionality to other objects by invoking delegates. The default return value for the CanExecute method is 'true'.
/// </summary>
public class RelayCommand : ICommand
{
#region Declarations
readonly Func < Boolean > _ canExecute ;
readonly Action _ execute ;
#endregion
#region Constructors
/// <summary>
/// Initializes a new instance of the <see cref="RelayCommand<T>"/> class and the command can always be executed.
/// </summary>
/// <param name="execute">The execution logic.</param>
public RelayCommand ( Action execute )
: this ( execute , null )
{
}
/// <summary>
/// Initializes a new instance of the <see cref="RelayCommand<T>"/> class.
/// </summary>
/// <param name="execute">The execution logic.</param>
/// <param name="canExecute">The execution status logic.</param>
public RelayCommand ( Action execute , Func < Boolean > canExecute )
{
if ( execute = = null )
throw new ArgumentNullException ( "execute" ) ;
_ execute = execute ;
_ canExecute = canExecute ;
}
#endregion
#region ICommand Members
public event EventHandler CanExecuteChanged
{
add
{
if ( _ canExecute ! = null )
CommandManager . RequerySuggested + = value ;
}
remove
{
if ( _ canExecute ! = null )
CommandManager . RequerySuggested - = value ;
}
}
[DebuggerStepThrough]
public Boolean CanExecute ( Object parameter )
{
return _ canExecute = = null ? true : _ canExecute ( ) ;
}
public void Execute ( Object parameter )
{
_ execute ( ) ;
}
#endregion
}
}