From e317a7943e47c34e731729eacc46f8ce48905927 Mon Sep 17 00:00:00 2001 From: Roy Ben-Shabat Date: Wed, 7 Mar 2018 16:28:54 +0200 Subject: Working on Users & Roles Module. --- .../MachineStudio/Tango.MachineStudio.UI/Views/MainView.xaml | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Views') diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Views/MainView.xaml b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Views/MainView.xaml index a4256436c..8e6fa36f5 100644 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Views/MainView.xaml +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Views/MainView.xaml @@ -48,16 +48,19 @@ - + , - + - + + + + -- cgit v1.3.1 From 1270aaf9eac23a03ee8e8ec6ceb9fc6cae6d6c65 Mon Sep 17 00:00:00 2001 From: Roy Date: Sat, 10 Mar 2018 20:05:42 +0200 Subject: Profiling and performance optimizations.. --- Software/DB/Tango.mdf | Bin 75497472 -> 75497472 bytes Software/DB/Tango_log.ldf | Bin 1048576 -> 1048576 bytes .../Tango.MachineStudio.UI/MainWindow.xaml | 10 +++++----- .../Tango.MachineStudio.UI/MainWindow.xaml.cs | 13 +++++++++++++ .../ViewModels/LoadingViewVM.cs | 11 +++++++++++ .../ViewModels/MachineConnectionViewVM.cs | 9 ++++++++- .../ViewModels/ShutdownViewVM.cs | 4 +++- .../Tango.MachineStudio.UI/Views/LoadingView.xaml | 2 +- .../Tango.MachineStudio.UI/Views/ShutdownView.xaml | 2 +- .../Views/ShutdownView.xaml.cs | 8 +++++++- .../Tango.MachineStudio.UI/Views/UpdateView.xaml | 4 ++-- .../Services/ExternalBridgeScanner.cs | 8 +++----- .../Adapters/TcpTransportAdapter.cs | 2 +- .../Adapters/UsbTransportAdapter.cs | 2 +- .../Tango.Transport/TransporterBase.cs | 9 +++++---- 15 files changed, 61 insertions(+), 23 deletions(-) (limited to 'Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Views') diff --git a/Software/DB/Tango.mdf b/Software/DB/Tango.mdf index fffab33c8..598a7c37e 100644 Binary files a/Software/DB/Tango.mdf and b/Software/DB/Tango.mdf differ diff --git a/Software/DB/Tango_log.ldf b/Software/DB/Tango_log.ldf index 6e69db505..1411d7c4e 100644 Binary files a/Software/DB/Tango_log.ldf and b/Software/DB/Tango_log.ldf differ diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/MainWindow.xaml b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/MainWindow.xaml index 63b2b3f6a..6b2bbaaec 100644 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/MainWindow.xaml +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/MainWindow.xaml @@ -14,7 +14,7 @@ - + @@ -22,16 +22,16 @@ - + - + - + - + diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/MainWindow.xaml.cs b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/MainWindow.xaml.cs index 36ee95f10..c4d9b4a28 100644 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/MainWindow.xaml.cs +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/MainWindow.xaml.cs @@ -10,7 +10,9 @@ using System.Windows.Controls; using System.Windows.Data; using System.Windows.Documents; using System.Windows.Input; +using System.Windows.Interop; using System.Windows.Media; +using System.Windows.Media.Animation; using System.Windows.Media.Imaging; using System.Windows.Navigation; using System.Windows.Shapes; @@ -30,6 +32,8 @@ namespace Tango.MachineStudio.UI public MainWindow() { + //Timeline.DesiredFrameRateProperty.OverrideMetadata(typeof(Timeline), new FrameworkPropertyMetadata { DefaultValue = 40 }); + try { InitializeComponent(); @@ -42,6 +46,15 @@ namespace Tango.MachineStudio.UI { LogManager.Log(ex); } + + this.Loaded += MainWindow_Loaded; + } + + private void MainWindow_Loaded(object sender, RoutedEventArgs e) + { + //HwndSource hwndSource = PresentationSource.FromVisual(this) as HwndSource; + //HwndTarget hwndTarget = hwndSource.CompositionTarget; + //hwndTarget.RenderMode = RenderMode.SoftwareOnly; } private void MainWindow_Closing(object sender, System.ComponentModel.CancelEventArgs e) diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/LoadingViewVM.cs b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/LoadingViewVM.cs index 7d83fa032..9ee8471ec 100644 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/LoadingViewVM.cs +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/LoadingViewVM.cs @@ -28,6 +28,14 @@ namespace Tango.MachineStudio.UI.ViewModels private LogManager logManager = LogManager.Default; public IStudioApplicationManager ApplicationManager { get; set; } + private bool _isLoading; + + public bool IsLoading + { + get { return _isLoading; } + set { _isLoading = value; RaisePropertyChangedAuto(); } + } + /// /// Initializes a new instance of the class. /// @@ -48,6 +56,8 @@ namespace Tango.MachineStudio.UI.ViewModels /// private void Load() { + IsLoading = true; + ThreadsHelper.StartStaThread(() => { try @@ -57,6 +67,7 @@ namespace Tango.MachineStudio.UI.ViewModels { _studioModuleLoader.LoadModules(); _navigationManager.NavigateTo(NavigationView.LoginView); + IsLoading = false; }); } catch (Exception ex) diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/MachineConnectionViewVM.cs b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/MachineConnectionViewVM.cs index 23be8d274..4fcebe3dd 100644 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/MachineConnectionViewVM.cs +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/MachineConnectionViewVM.cs @@ -49,7 +49,6 @@ namespace Tango.MachineStudio.UI.ViewModels { Scanner = scanner; ConnectCommand = new RelayCommand(Connect,(x) => SelectedMachine != null); - Scanner.Start(); } /// @@ -59,10 +58,17 @@ namespace Tango.MachineStudio.UI.ViewModels { if (SelectedMachine != null) { + Scanner.Stop(); Accept(); } } + protected override void Cancel() + { + Scanner.Stop(); + base.Cancel(); + } + /// /// Called when the dialog has been shown. /// @@ -70,6 +76,7 @@ namespace Tango.MachineStudio.UI.ViewModels { base.OnShow(); Scanner.AvailableMachines.Clear(); + Scanner.Start(); } } } diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/ShutdownViewVM.cs b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/ShutdownViewVM.cs index ed771f00a..92e0eb9b5 100644 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/ShutdownViewVM.cs +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/ShutdownViewVM.cs @@ -3,13 +3,15 @@ using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; +using Tango.SharedUI; namespace Tango.MachineStudio.UI.ViewModels { /// /// Represents the Machine Studio shutdown view, view model. /// - public class ShutdownViewVM + public class ShutdownViewVM : ViewModel { + } } diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Views/LoadingView.xaml b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Views/LoadingView.xaml index 5f65100df..91fc11a22 100644 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Views/LoadingView.xaml +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Views/LoadingView.xaml @@ -15,7 +15,7 @@ Machine Studio Twine Solutions - + Loading, please wait... diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Views/ShutdownView.xaml b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Views/ShutdownView.xaml index dd86238ce..cc1060b2a 100644 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Views/ShutdownView.xaml +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Views/ShutdownView.xaml @@ -15,7 +15,7 @@ Machine Studio Twine Solutions - + Shutting Down, please wait... diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Views/ShutdownView.xaml.cs b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Views/ShutdownView.xaml.cs index e1d49aec0..afe6d3800 100644 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Views/ShutdownView.xaml.cs +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Views/ShutdownView.xaml.cs @@ -12,17 +12,23 @@ using System.Windows.Media; using System.Windows.Media.Imaging; using System.Windows.Navigation; using System.Windows.Shapes; +using static Tango.SharedUI.Controls.MultiTransitionControl; namespace Tango.MachineStudio.UI.Views { /// /// Interaction logic for ShutdownView.xaml /// - public partial class ShutdownView : UserControl + public partial class ShutdownView : UserControl, ITransitionView { public ShutdownView() { InitializeComponent(); } + + public void OnTransitionCompleted() + { + progressRing.IsActive = true; + } } } diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Views/UpdateView.xaml b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Views/UpdateView.xaml index dabbaab94..e34cdb83b 100644 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Views/UpdateView.xaml +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Views/UpdateView.xaml @@ -16,9 +16,9 @@ - + Update Center diff --git a/Software/Visual_Studio/Tango.Integration/Services/ExternalBridgeScanner.cs b/Software/Visual_Studio/Tango.Integration/Services/ExternalBridgeScanner.cs index c0d14d102..b8e9b2c6d 100644 --- a/Software/Visual_Studio/Tango.Integration/Services/ExternalBridgeScanner.cs +++ b/Software/Visual_Studio/Tango.Integration/Services/ExternalBridgeScanner.cs @@ -29,6 +29,7 @@ namespace Tango.Integration.Services { private Thread _tcpDiscoveryThread; private Thread _usbDiscoveryThread; + private UdpClient _server; private LogManager LogManager = LogManager.Default; private ObservableCollection _availableMachines; @@ -56,6 +57,7 @@ namespace Tango.Integration.Services /// public ExternalBridgeScanner() { + _server = new UdpClient(SettingsManager.Default.Integration.ExternalBridgeServiceDiscoveryPort); AvailableMachines = new ObservableCollection(); } @@ -121,12 +123,10 @@ namespace Tango.Integration.Services /// private void TcpDiscoveryThreadMethod() { - var Server = new UdpClient(SettingsManager.Default.Integration.ExternalBridgeServiceDiscoveryPort); - while (!IsStarted) { var ClientEp = new IPEndPoint(IPAddress.Any, 0); - var ClientRequestData = Server.Receive(ref ClientEp); + var ClientRequestData = _server.Receive(ref ClientEp); ExternalBridgeUdpDiscoveryPacket packet = ExternalBridgeUdpDiscoveryPacket.Parser.ParseFrom(ClientRequestData); @@ -144,8 +144,6 @@ namespace Tango.Integration.Services Thread.Sleep(1000); } - - Server.Close(); } /// diff --git a/Software/Visual_Studio/Tango.Transport/Adapters/TcpTransportAdapter.cs b/Software/Visual_Studio/Tango.Transport/Adapters/TcpTransportAdapter.cs index 768f0914f..4a0b47fe4 100644 --- a/Software/Visual_Studio/Tango.Transport/Adapters/TcpTransportAdapter.cs +++ b/Software/Visual_Studio/Tango.Transport/Adapters/TcpTransportAdapter.cs @@ -186,7 +186,7 @@ namespace Tango.Transport.Adapters { read += _socket.GetStream().Read(data, read, Math.Min(_socket.Available, expectedSize - read)); - Thread.Sleep(2); + //Thread.Sleep(2); if (State != TransportComponentState.Connected) { diff --git a/Software/Visual_Studio/Tango.Transport/Adapters/UsbTransportAdapter.cs b/Software/Visual_Studio/Tango.Transport/Adapters/UsbTransportAdapter.cs index 019c7099d..99c6a7a49 100644 --- a/Software/Visual_Studio/Tango.Transport/Adapters/UsbTransportAdapter.cs +++ b/Software/Visual_Studio/Tango.Transport/Adapters/UsbTransportAdapter.cs @@ -163,7 +163,7 @@ namespace Tango.Transport.Adapters { read += _serialPort.Read(data, read, Math.Min(_serialPort.BytesToRead, expectedSize - read)); - Thread.Sleep(2); + //Thread.Sleep(2); if (State != TransportComponentState.Connected) { diff --git a/Software/Visual_Studio/Tango.Transport/TransporterBase.cs b/Software/Visual_Studio/Tango.Transport/TransporterBase.cs index e9e3afc52..2ca9c51ba 100644 --- a/Software/Visual_Studio/Tango.Transport/TransporterBase.cs +++ b/Software/Visual_Studio/Tango.Transport/TransporterBase.cs @@ -414,7 +414,7 @@ namespace Tango.Transport { while (State == TransportComponentState.Connected) { - if (Adapter != null && _sendingQueue.Count > 0) + while (Adapter != null && _sendingQueue.Count > 0) { TransportMessageBase message; if (_sendingQueue.TryDequeue(out message)) @@ -447,7 +447,8 @@ namespace Tango.Transport } } - Thread.Sleep(1); + Thread.Sleep(10); + } } catch (Exception ex) @@ -471,7 +472,7 @@ namespace Tango.Transport { byte[] data; - if (Adapter != null && _arrivedResponses.Count > 0) + while (Adapter != null && _arrivedResponses.Count > 0) { if (_arrivedResponses.TryDequeue(out data)) { @@ -566,7 +567,7 @@ namespace Tango.Transport } } - Thread.Sleep(1); + Thread.Sleep(10); } } catch (Exception ex) -- cgit v1.3.1 From e75cf513acb73558e948d6012b45f221c718dcf7 Mon Sep 17 00:00:00 2001 From: Roy Ben-Shabat Date: Mon, 12 Mar 2018 17:03:38 +0200 Subject: Added cascade delete for Machine -> Jobs. Added addresses auto complete to users & roles. Maybe Users & Roles module is complete.. --- Software/DB/Tango.mdf | Bin 75497472 -> 75497472 bytes Software/DB/Tango_log.ldf | Bin 1048576 -> 1048576 bytes .../Views/JobView.xaml.cs | 1 + .../Providers/Place.cs | 31 +++++ .../Providers/PlaceAddress.cs | 53 +++++++++ .../Providers/PlacesProvider.cs | 47 ++++++++ .../Tango.MachineStudio.UsersAndRoles.csproj | 14 +++ .../ViewModels/MainViewVM.cs | 132 ++++++++++++++++++++- .../Views/AddressView.xaml | 8 +- .../Views/OrganizationManagementView.xaml | 10 +- .../Views/OrganizationManagementView.xaml.cs | 8 +- .../Views/UserManagementView.xaml | 27 ++++- .../Views/UserManagementView.xaml.cs | 8 +- .../Views/UserView.xaml | 23 ++++ .../Views/UserView.xaml.cs | 28 +++++ .../Tango.MachineStudio.UsersAndRoles/app.config | 11 ++ .../packages.config | 1 + .../Tango.MachineStudio.UI/Views/MainView.xaml.cs | 1 + .../Tango.AutoComplete/Editors/Themes/Generic.xaml | 3 +- .../Tango.BL/EntitiesExtensions/Contact.cs | 38 +++++- .../Tango.BL/EntitiesExtensions/User.cs | 31 +++++ .../Visual_Studio/Tango.BL/IObservableEntity.cs | 7 ++ .../Visual_Studio/Tango.BL/ObservableEntity.cs | 17 ++- Software/Visual_Studio/Tango.BL/Tango.BL.csproj | 3 + Software/Visual_Studio/Tango.BL/packages.config | 1 + .../Tango.SharedUI/Helpers/PasswordHelper.cs | 98 +++++++++++++++ .../Tango.SharedUI/Tango.SharedUI.csproj | 1 + 27 files changed, 583 insertions(+), 19 deletions(-) create mode 100644 Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.UsersAndRoles/Providers/Place.cs create mode 100644 Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.UsersAndRoles/Providers/PlaceAddress.cs create mode 100644 Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.UsersAndRoles/Providers/PlacesProvider.cs create mode 100644 Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.UsersAndRoles/Views/UserView.xaml create mode 100644 Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.UsersAndRoles/Views/UserView.xaml.cs create mode 100644 Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.UsersAndRoles/app.config create mode 100644 Software/Visual_Studio/Tango.SharedUI/Helpers/PasswordHelper.cs (limited to 'Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Views') diff --git a/Software/DB/Tango.mdf b/Software/DB/Tango.mdf index cb00adf1a..a1dced350 100644 Binary files a/Software/DB/Tango.mdf and b/Software/DB/Tango.mdf differ diff --git a/Software/DB/Tango_log.ldf b/Software/DB/Tango_log.ldf index 972799de3..2b587c81f 100644 Binary files a/Software/DB/Tango_log.ldf and b/Software/DB/Tango_log.ldf differ diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Views/JobView.xaml.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Views/JobView.xaml.cs index 0c99dfe5f..044046450 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Views/JobView.xaml.cs +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Views/JobView.xaml.cs @@ -82,6 +82,7 @@ namespace Tango.MachineStudio.Developer.Views } jobBrushList.ItemsSource = segments; + UpdateGradientBrushDisplay(); } } diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.UsersAndRoles/Providers/Place.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.UsersAndRoles/Providers/Place.cs new file mode 100644 index 000000000..a2ac2a9b7 --- /dev/null +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.UsersAndRoles/Providers/Place.cs @@ -0,0 +1,31 @@ +using Newtonsoft.Json; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Xml.Serialization; + +namespace Tango.MachineStudio.UsersAndRoles.Providers +{ + public class Place + { + [XmlElement("address")] + [JsonProperty("address")] + public PlaceAddress Address { get; set; } + + [XmlAttribute("display_name")] + [JsonProperty("display_name")] + public String DisplayName { get; set; } + + public Place() + { + Address = new PlaceAddress(); + } + + public override string ToString() + { + return DisplayName; + } + } +} diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.UsersAndRoles/Providers/PlaceAddress.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.UsersAndRoles/Providers/PlaceAddress.cs new file mode 100644 index 000000000..5b25794d1 --- /dev/null +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.UsersAndRoles/Providers/PlaceAddress.cs @@ -0,0 +1,53 @@ +using Newtonsoft.Json; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Xml.Serialization; + +namespace Tango.MachineStudio.UsersAndRoles.Providers +{ + public class PlaceAddress + { + [XmlElement("road")] + [JsonProperty("road")] + public String Road { get; set; } + + [XmlElement("village")] + [JsonProperty("village")] + public String Village + { + get { return City; } + set { City = value; } + } + + [XmlElement("town")] + [JsonProperty("town")] + public String Town + { + get { return City; } + set { City = value; } + } + + [XmlElement("city")] + [JsonProperty("city")] + public String City { get; set; } + + [XmlElement("state")] + [JsonProperty("state")] + public String State { get; set; } + + [XmlElement("postcode")] + [JsonProperty("postcode")] + public String PostalCode { get; set; } + + [XmlElement("country")] + [JsonProperty("country")] + public String Country { get; set; } + + [XmlElement("country_code")] + [JsonProperty("country_code")] + public String CountryCode { get; set; } + } +} diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.UsersAndRoles/Providers/PlacesProvider.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.UsersAndRoles/Providers/PlacesProvider.cs new file mode 100644 index 000000000..681815d4c --- /dev/null +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.UsersAndRoles/Providers/PlacesProvider.cs @@ -0,0 +1,47 @@ +using Newtonsoft.Json; +using System; +using System.Collections; +using System.Collections.Generic; +using System.Linq; +using System.Net; +using System.Text; +using System.Threading.Tasks; +using Tango.AutoComplete.Editors; +using Tango.Logging; + +namespace Tango.MachineStudio.UsersAndRoles.Providers +{ + public class PlacesProvider : ISuggestionProvider + { + public IEnumerable GetSuggestions(string filter) + { + List places = new List(); + + using (WebClient web = new WebClient()) + { + try + { + String json = null; + + web.Headers.Add(HttpRequestHeader.UserAgent, "Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:47.0) Gecko/20100101 Firefox/47.0"); + web.Headers.Add(HttpRequestHeader.ContentType, "application/json"); + web.Headers.Add(HttpRequestHeader.AcceptLanguage, "en-US"); + + json = web.DownloadString(String.Format("https://nominatim.openstreetmap.org/search?q={0}&format=json&addressdetails=1", filter)); + + if (json != null) + { + List results = JsonConvert.DeserializeObject>(json); + places.AddRange(results); + } + } + catch (Exception ex) + { + LogManager.Default.Log(ex, LogCategory.Debug); + } + } + + return places; + } + } +} diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.UsersAndRoles/Tango.MachineStudio.UsersAndRoles.csproj b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.UsersAndRoles/Tango.MachineStudio.UsersAndRoles.csproj index a64c536ed..9064519c0 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.UsersAndRoles/Tango.MachineStudio.UsersAndRoles.csproj +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.UsersAndRoles/Tango.MachineStudio.UsersAndRoles.csproj @@ -58,6 +58,9 @@ ..\..\..\packages\CommonServiceLocator.1.3\lib\portable-net4+sl5+netcore45+wpa81+wp8\Microsoft.Practices.ServiceLocation.dll + + ..\..\..\packages\Newtonsoft.Json.10.0.3\lib\net45\Newtonsoft.Json.dll + @@ -83,6 +86,9 @@ + + + @@ -104,6 +110,9 @@ UserManagementView.xaml + + UserView.xaml + @@ -123,6 +132,7 @@ ResXFileCodeGenerator Resources.Designer.cs + SettingsSingleFileGenerator @@ -188,6 +198,10 @@ Designer MSBuild:Compile + + Designer + MSBuild:Compile + diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.UsersAndRoles/ViewModels/MainViewVM.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.UsersAndRoles/ViewModels/MainViewVM.cs index 9478014b7..7d82cbbbc 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.UsersAndRoles/ViewModels/MainViewVM.cs +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.UsersAndRoles/ViewModels/MainViewVM.cs @@ -10,6 +10,7 @@ using Tango.BL.Entities; using Tango.Core.Commands; using Tango.MachineStudio.Common.Notifications; using Tango.MachineStudio.UsersAndRoles.Navigation; +using Tango.MachineStudio.UsersAndRoles.Providers; using Tango.SharedUI; namespace Tango.MachineStudio.UsersAndRoles.ViewModels @@ -71,6 +72,36 @@ namespace Tango.MachineStudio.UsersAndRoles.ViewModels set { _managedUser = value; RaisePropertyChangedAuto(); } } + private Place _selectedUserPlace; + public Place SelectedUserPlace + { + get { return _selectedUserPlace; } + set + { + _selectedUserPlace = value; + + if (_selectedUserPlace != null && _selectedUserPlace.Address != null) + { + SetUserPlace(value); + } + } + } + + private Place _selectedOrganizationPlace; + public Place SelectedOrganizationPlace + { + get { return _selectedOrganizationPlace; } + set + { + _selectedOrganizationPlace = value; + + if (_selectedOrganizationPlace != null && _selectedOrganizationPlace.Address != null) + { + SetOrganizationPlace(value); + } + } + } + public RelayCommand ManageOrganizationCommand { get; set; } public RelayCommand BackToOrganizationsCommand { get; set; } @@ -89,6 +120,10 @@ namespace Tango.MachineStudio.UsersAndRoles.ViewModels public RelayCommand SaveManagedUserCommand { get; set; } + public RelayCommand AddUserCommand { get; set; } + + public RelayCommand RemoveUserCommand { get; set; } + public MainViewVM(UsersAndRolesNavigationManager navigation, INotificationProvider notification) { _navigation = navigation; @@ -98,13 +133,15 @@ namespace Tango.MachineStudio.UsersAndRoles.ViewModels ManageOrganizationCommand = new RelayCommand(LoadSelectedOrganization, () => SelectedOrganization != null); BackToOrganizationsCommand = new RelayCommand(BackToOrganizations); - ManageUserCommand = new RelayCommand(ManageUser, () => SelectedUser != null); + ManageUserCommand = new RelayCommand(LoadSelectedUser, () => SelectedUser != null); SaveOrganizationCommand = new RelayCommand(SaveOrganization); AddOrganizationCommand = new RelayCommand(AddOrganization); RemoveOrganizationCommand = new RelayCommand(RemoveOrganization, () => SelectedOrganization != null); BackToManagedOrganizationCommand = new RelayCommand(BackToManagedOrganization); RemoveRoleCommand = new RelayCommand(RemoveUserRole); SaveManagedUserCommand = new RelayCommand(SaveManagedUser); + AddUserCommand = new RelayCommand(AddNewUser); + RemoveUserCommand = new RelayCommand(RemoveSelectedUser, () => SelectedUser != null); } private async void AddOrganization() @@ -144,14 +181,13 @@ namespace Tango.MachineStudio.UsersAndRoles.ViewModels { using (_notification.PushTaskItem("Saving organization address and contact...")) { - ManagedOrganization.Contact.SetFullName(); await ManagedOrganization.SaveAsync(_manageContext); LoadOrganizations(); SelectedOrganization = Organizations.SingleOrDefault(x => x.Guid == ManagedOrganization.Guid); } } - private void ManageUser() + private void LoadSelectedUser() { using (_notification.PushTaskItem("Loading user details...")) { @@ -189,9 +225,18 @@ namespace Tango.MachineStudio.UsersAndRoles.ViewModels private async void SaveManagedUser() { + try + { + ManagedUser.Validate(_userContext); + } + catch (Exception ex) + { + _notification.ShowError(ex.Message); + return; + } + using (_notification.PushTaskItem("Saving user details...")) { - ManagedUser.Contact.SetFullName(); await ManagedUser.SaveAsync(_userContext); LoadSelectedOrganization(); } @@ -237,6 +282,85 @@ namespace Tango.MachineStudio.UsersAndRoles.ViewModels ManagedUserRoles.Add(role); } + private async void RemoveSelectedUser() + { + if (_notification.ShowQuestion("Are you sure you want to remove the selected user?")) + { + using (_notification.PushTaskItem("Removing user...")) + { + await SelectedUser.DeleteCascadeAsync(_manageContext); + LoadSelectedOrganization(); + } + } + } + + private async void AddNewUser() + { + String email = _notification.ShowTextInput("Enter user email", "email"); + + if (!String.IsNullOrWhiteSpace(email)) + { + User user = new User(); + user.Email = email; + user.Password = "1111"; + user.Contact = new Contact() + { + FirstName = "Twine", + LastName = "User", + Email = email, + }; + + user.UsersRoles.Add(new UsersRole() + { + User = user, + Role = _manageContext.Roles.SingleOrDefault(x => x.Code == (int)BL.Enumerations.Roles.User) + }); + + try + { + user.Validate(_manageContext); + } + catch (Exception ex) + { + _notification.ShowError(ex.Message); + return; + } + + user.Address = new Address(); + + ManagedOrganization.Users.Add(user); + + using (_notification.PushTaskItem("Adding new user...")) + { + await ManagedOrganization.SaveAsync(_manageContext); + LoadOrganizations(); + SelectedOrganization = Organizations.SingleOrDefault(x => x.Guid == ManagedOrganization.Guid); + } + } + } + + private void SetUserPlace(Place place) + { + ManagedUser.Address.AddressString = place.Address.Road; + ManagedUser.Address.City = place.Address.City; + ManagedUser.Address.Country = place.Address.Country; + ManagedUser.Address.CountryCode = place.Address.CountryCode; + ManagedUser.Address.Locality = place.Address.CountryCode; + ManagedUser.Address.PostalCode = place.Address.PostalCode; + ManagedUser.Address.State = place.Address.State; + } + + private void SetOrganizationPlace(Place place) + { + ManagedOrganization.Address.AddressString = place.Address.Road; + ManagedOrganization.Address.City = place.Address.City; + ManagedOrganization.Address.Country = place.Address.Country; + ManagedOrganization.Address.CountryCode = place.Address.CountryCode; + ManagedOrganization.Address.Locality = place.Address.CountryCode; + ManagedOrganization.Address.PostalCode = place.Address.PostalCode; + ManagedOrganization.Address.State = place.Address.State; + } + protected override void RaisePropertyChangedAuto([CallerMemberName] string caller = null) { base.RaisePropertyChangedAuto(caller); diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.UsersAndRoles/Views/AddressView.xaml b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.UsersAndRoles/Views/AddressView.xaml index 41f7871e2..937cf14dd 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.UsersAndRoles/Views/AddressView.xaml +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.UsersAndRoles/Views/AddressView.xaml @@ -15,17 +15,17 @@ - + - + - + - + diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.UsersAndRoles/Views/OrganizationManagementView.xaml b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.UsersAndRoles/Views/OrganizationManagementView.xaml index 7769f65ed..64b05769a 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.UsersAndRoles/Views/OrganizationManagementView.xaml +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.UsersAndRoles/Views/OrganizationManagementView.xaml @@ -9,6 +9,7 @@ xmlns:autoComplete="clr-namespace:Tango.AutoComplete.Editors;assembly=Tango.AutoComplete" xmlns:controls="clr-namespace:Tango.SharedUI.Controls;assembly=Tango.SharedUI" xmlns:mahApps="http://metro.mahapps.com/winfx/xaml/controls" + xmlns:providers="clr-namespace:Tango.MachineStudio.UsersAndRoles.Providers" xmlns:entities="clr-namespace:Tango.BL.Entities;assembly=Tango.BL" xmlns:local="clr-namespace:Tango.MachineStudio.UsersAndRoles.Views" xmlns:converters="clr-namespace:Tango.SharedUI.Converters;assembly=Tango.SharedUI" @@ -17,6 +18,7 @@ + @@ -38,7 +40,13 @@ ADDRESS - + + + + + + + CONTACT diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.UsersAndRoles/Views/OrganizationManagementView.xaml.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.UsersAndRoles/Views/OrganizationManagementView.xaml.cs index 76b256d62..e2c44a584 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.UsersAndRoles/Views/OrganizationManagementView.xaml.cs +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.UsersAndRoles/Views/OrganizationManagementView.xaml.cs @@ -12,17 +12,23 @@ using System.Windows.Media; using System.Windows.Media.Imaging; using System.Windows.Navigation; using System.Windows.Shapes; +using static Tango.SharedUI.Controls.MultiTransitionControl; namespace Tango.MachineStudio.UsersAndRoles.Views { /// /// Interaction logic for OrganizationManagementView.xaml /// - public partial class OrganizationManagementView : UserControl + public partial class OrganizationManagementView : UserControl , ITransitionView { public OrganizationManagementView() { InitializeComponent(); } + + public void OnTransitionCompleted() + { + address_auto.Text = ""; + } } } diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.UsersAndRoles/Views/UserManagementView.xaml b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.UsersAndRoles/Views/UserManagementView.xaml index b92682b84..ccb38b198 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.UsersAndRoles/Views/UserManagementView.xaml +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.UsersAndRoles/Views/UserManagementView.xaml @@ -5,6 +5,7 @@ xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:global="clr-namespace:Tango.MachineStudio.UsersAndRoles" xmlns:vm="clr-namespace:Tango.MachineStudio.UsersAndRoles.ViewModels" + xmlns:providers="clr-namespace:Tango.MachineStudio.UsersAndRoles.Providers" xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes" xmlns:dragAndDrop="clr-namespace:Tango.DragAndDrop;assembly=Tango.DragAndDrop" xmlns:autoComplete="clr-namespace:Tango.AutoComplete.Editors;assembly=Tango.AutoComplete" @@ -16,6 +17,10 @@ mc:Ignorable="d" d:DesignHeight="1080" d:DesignWidth="1920" d:DataContext="{d:DesignInstance Type=vm:MainViewVM, IsDesignTimeCreatable=False}" DataContext="{x:Static global:ViewModelLocator.MainViewVM}"> + + + + @@ -39,19 +44,31 @@ - + - ADDRESS - - + LOGIN + + CONTACT - + + + ADDRESS + + + + + + + + + + diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.UsersAndRoles/Views/UserManagementView.xaml.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.UsersAndRoles/Views/UserManagementView.xaml.cs index b26f0ea03..f2ff25637 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.UsersAndRoles/Views/UserManagementView.xaml.cs +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.UsersAndRoles/Views/UserManagementView.xaml.cs @@ -15,13 +15,14 @@ using System.Windows.Shapes; using Tango.BL.Entities; using Tango.DragAndDrop; using Tango.MachineStudio.UsersAndRoles.ViewModels; +using static Tango.SharedUI.Controls.MultiTransitionControl; namespace Tango.MachineStudio.UsersAndRoles.Views { /// /// Interaction logic for UserManagementView.xaml /// - public partial class UserManagementView : UserControl + public partial class UserManagementView : UserControl, ITransitionView { private MainViewVM _vm; @@ -47,5 +48,10 @@ namespace Tango.MachineStudio.UsersAndRoles.Views _vm.OnDropRole(e.Draggable.DataContext as Role); } } + + public void OnTransitionCompleted() + { + address_auto.Text = ""; + } } } diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.UsersAndRoles/Views/UserView.xaml b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.UsersAndRoles/Views/UserView.xaml new file mode 100644 index 000000000..6c7596015 --- /dev/null +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.UsersAndRoles/Views/UserView.xaml @@ -0,0 +1,23 @@ + + + + + + + + + + + + + diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.UsersAndRoles/Views/UserView.xaml.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.UsersAndRoles/Views/UserView.xaml.cs new file mode 100644 index 000000000..b617bdbc4 --- /dev/null +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.UsersAndRoles/Views/UserView.xaml.cs @@ -0,0 +1,28 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Data; +using System.Windows.Documents; +using System.Windows.Input; +using System.Windows.Media; +using System.Windows.Media.Imaging; +using System.Windows.Navigation; +using System.Windows.Shapes; + +namespace Tango.MachineStudio.UsersAndRoles.Views +{ + /// + /// Interaction logic for UserView.xaml + /// + public partial class UserView : UserControl + { + public UserView() + { + InitializeComponent(); + } + } +} diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.UsersAndRoles/app.config b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.UsersAndRoles/app.config new file mode 100644 index 000000000..cacd4cd77 --- /dev/null +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.UsersAndRoles/app.config @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.UsersAndRoles/packages.config b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.UsersAndRoles/packages.config index cf0df03c8..6b8afad69 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.UsersAndRoles/packages.config +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.UsersAndRoles/packages.config @@ -6,4 +6,5 @@ + \ No newline at end of file diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Views/MainView.xaml.cs b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Views/MainView.xaml.cs index c40904173..e0ae60b87 100644 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Views/MainView.xaml.cs +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Views/MainView.xaml.cs @@ -76,6 +76,7 @@ namespace Tango.MachineStudio.UI.Views { Tag = module.Name, Content = grid, + Visibility = Visibility.Hidden, }); _loader.UserModules.Add(module); diff --git a/Software/Visual_Studio/SideChains/Tango.AutoComplete/Editors/Themes/Generic.xaml b/Software/Visual_Studio/SideChains/Tango.AutoComplete/Editors/Themes/Generic.xaml index a3c124841..25667d1d1 100644 --- a/Software/Visual_Studio/SideChains/Tango.AutoComplete/Editors/Themes/Generic.xaml +++ b/Software/Visual_Studio/SideChains/Tango.AutoComplete/Editors/Themes/Generic.xaml @@ -93,7 +93,8 @@ x.Role).ToList().SelectMany(x => x.RolesPermissions).Select(x => x.Permission).ToList(); } } + + public override void Validate(ObservablesContext context) + { + var users = context.Users.ToList(); + + if (users.Exists(x => x.Guid != Guid && x.Email.ToLower() == Email.ToLower())) + { + throw new ArgumentException("The specified email is already taken by another account."); + } + + if (!Email.IsEmail()) + { + throw new ArgumentException("The specified email address is invalid."); + } + + if (!Password.IsBetweenLength(4, 30)) + { + throw new ArgumentException("A user password must be at least 4 characters long and maximum 30."); + } + + if (Contact != null) + { + Contact.Validate(context); + } + + if (Address != null) + { + Address.Validate(context); + } + } } } diff --git a/Software/Visual_Studio/Tango.BL/IObservableEntity.cs b/Software/Visual_Studio/Tango.BL/IObservableEntity.cs index 586d4da21..265b51179 100644 --- a/Software/Visual_Studio/Tango.BL/IObservableEntity.cs +++ b/Software/Visual_Studio/Tango.BL/IObservableEntity.cs @@ -83,5 +83,12 @@ namespace Tango.BL /// Deletes this entity using an SQL statement which will cause the database delete cascade effect. /// Task DeleteCascadeAsync(ObservablesContext context); + + /// + /// Performs entity field validation. + /// Will throw an exception with the proper message if one of the fields is invalid. + /// + /// The context. + void Validate(ObservablesContext context); } } diff --git a/Software/Visual_Studio/Tango.BL/ObservableEntity.cs b/Software/Visual_Studio/Tango.BL/ObservableEntity.cs index 43d5c06de..e46e54ad3 100644 --- a/Software/Visual_Studio/Tango.BL/ObservableEntity.cs +++ b/Software/Visual_Studio/Tango.BL/ObservableEntity.cs @@ -166,7 +166,7 @@ namespace Tango.BL /// public Task SaveAsync(ObservablesContext context) { - return Task.Factory.StartNew(() => + return Task.Factory.StartNew(() => { Save(context); }); @@ -296,11 +296,26 @@ Maybe you have deleted an entity that was no yet inserted into database?", LogCa return me == other; } + /// + /// Deletes this entity using an SQL statement which will cause the database delete cascade effect. + /// + /// + /// public Task DeleteCascadeAsync(ObservablesContext context) { return context.Database.ExecuteSqlCommandAsync(String.Format("DELETE FROM {0} WHERE GUID='{1}'", this.GetType().GetCustomAttribute().Name, Guid)); } + /// + /// Performs entity field validation. + /// Will throw an exception with the proper message if one of the fields is invalid. + /// + /// The context. + public virtual void Validate(ObservablesContext context) + { + + } + #region Operator Overloading //public static bool operator ==(ObservableEntity observable1, ObservableEntity observable2) diff --git a/Software/Visual_Studio/Tango.BL/Tango.BL.csproj b/Software/Visual_Studio/Tango.BL/Tango.BL.csproj index 8159e0f3b..a3f952644 100644 --- a/Software/Visual_Studio/Tango.BL/Tango.BL.csproj +++ b/Software/Visual_Studio/Tango.BL/Tango.BL.csproj @@ -45,6 +45,9 @@ ..\packages\Newtonsoft.Json.10.0.3\lib\net45\Newtonsoft.Json.dll + + ..\packages\SimpleValidator.0.6.1.0\lib\net40\SimpleValidator.dll + diff --git a/Software/Visual_Studio/Tango.BL/packages.config b/Software/Visual_Studio/Tango.BL/packages.config index dcc94a0a3..ed5d800c9 100644 --- a/Software/Visual_Studio/Tango.BL/packages.config +++ b/Software/Visual_Studio/Tango.BL/packages.config @@ -3,6 +3,7 @@ + diff --git a/Software/Visual_Studio/Tango.SharedUI/Helpers/PasswordHelper.cs b/Software/Visual_Studio/Tango.SharedUI/Helpers/PasswordHelper.cs new file mode 100644 index 000000000..b87faf08f --- /dev/null +++ b/Software/Visual_Studio/Tango.SharedUI/Helpers/PasswordHelper.cs @@ -0,0 +1,98 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Controls; + +namespace Tango.SharedUI.Helpers +{ + public class PasswordHelper + { + public static readonly DependencyProperty PasswordProperty = + DependencyProperty.RegisterAttached("Password", + typeof(string), typeof(PasswordHelper), + new FrameworkPropertyMetadata(string.Empty, OnPasswordPropertyChanged)); + + public static readonly DependencyProperty AttachProperty = + DependencyProperty.RegisterAttached("Attach", + typeof(bool), typeof(PasswordHelper), new PropertyMetadata(false, Attach)); + + private static readonly DependencyProperty IsUpdatingProperty = + DependencyProperty.RegisterAttached("IsUpdating", typeof(bool), + typeof(PasswordHelper)); + + + public static void SetAttach(DependencyObject dp, bool value) + { + dp.SetValue(AttachProperty, value); + } + + public static bool GetAttach(DependencyObject dp) + { + return (bool)dp.GetValue(AttachProperty); + } + + public static string GetPassword(DependencyObject dp) + { + return (string)dp.GetValue(PasswordProperty); + } + + public static void SetPassword(DependencyObject dp, string value) + { + dp.SetValue(PasswordProperty, value); + } + + private static bool GetIsUpdating(DependencyObject dp) + { + return (bool)dp.GetValue(IsUpdatingProperty); + } + + private static void SetIsUpdating(DependencyObject dp, bool value) + { + dp.SetValue(IsUpdatingProperty, value); + } + + private static void OnPasswordPropertyChanged(DependencyObject sender, + DependencyPropertyChangedEventArgs e) + { + PasswordBox passwordBox = sender as PasswordBox; + passwordBox.PasswordChanged -= PasswordChanged; + + if (!(bool)GetIsUpdating(passwordBox)) + { + passwordBox.Password = (string)e.NewValue; + } + passwordBox.PasswordChanged += PasswordChanged; + } + + private static void Attach(DependencyObject sender, + DependencyPropertyChangedEventArgs e) + { + PasswordBox passwordBox = sender as PasswordBox; + + if (passwordBox == null) + return; + + if ((bool)e.OldValue) + { + passwordBox.PasswordChanged -= PasswordChanged; + } + + if ((bool)e.NewValue) + { + passwordBox.PasswordChanged += PasswordChanged; + } + } + + private static void PasswordChanged(object sender, RoutedEventArgs e) + { + PasswordBox passwordBox = sender as PasswordBox; + SetIsUpdating(passwordBox, true); + SetPassword(passwordBox, passwordBox.Password); + SetIsUpdating(passwordBox, false); + } + } + +} diff --git a/Software/Visual_Studio/Tango.SharedUI/Tango.SharedUI.csproj b/Software/Visual_Studio/Tango.SharedUI/Tango.SharedUI.csproj index 1a751fda2..49590dcf5 100644 --- a/Software/Visual_Studio/Tango.SharedUI/Tango.SharedUI.csproj +++ b/Software/Visual_Studio/Tango.SharedUI/Tango.SharedUI.csproj @@ -120,6 +120,7 @@ ParameterizedEditor.xaml + -- cgit v1.3.1