diff --git a/ENI-2/ENI2/ENI2/App.config b/ENI-2/ENI2/ENI2/App.config index 28528d5d..e175721e 100644 --- a/ENI-2/ENI2/ENI2/App.config +++ b/ENI-2/ENI2/ENI2/App.config @@ -19,6 +19,12 @@ Sample license text. Data Source=(localdb)\Projects;Initial Catalog=nsw;Integrated Security=True;Connect Timeout=30;Encrypt=False;TrustServerCertificate=False + + True + + + http://heupferd/bsmd.LockingService/LockingService.svc + @@ -29,15 +35,7 @@ Sample license text. - - - - - - - - + + \ No newline at end of file diff --git a/ENI-2/ENI2/ENI2/App.xaml.cs b/ENI-2/ENI2/ENI2/App.xaml.cs index f4960bf5..ed258f01 100644 --- a/ENI-2/ENI2/ENI2/App.xaml.cs +++ b/ENI-2/ENI2/ENI2/App.xaml.cs @@ -9,7 +9,7 @@ using bsmd.database; using System.Windows.Controls; using System.Windows.Input; using System; -using ENI2.LockingServiceReference; +using System.Net; namespace ENI2 { @@ -17,8 +17,7 @@ namespace ENI2 /// Interaction logic for App.xaml /// public partial class App : Application - { - private ServiceClient lockingServiceClient; + { public App() : base() { @@ -30,7 +29,7 @@ namespace ENI2 protected override void OnStartup(StartupEventArgs e) { - base.OnStartup(e); + base.OnStartup(e); // initialize static / localized lookups from sqlite database @@ -41,14 +40,12 @@ namespace ENI2 LADG.CargoHandlingDict.Add(key, cargoHandlingDict[key]); EventManager.RegisterClassHandler(typeof(DatePicker), DatePicker.PreviewKeyDownEvent, new KeyEventHandler(this.DatePicker_PreviewKeyDown)); - try - { - // this.lockingServiceClient = new ServiceClient(); - } - catch(Exception ex) - { - System.Diagnostics.Trace.WriteLine("Exception creating locking service client: {0}", ex.ToString()); - } + + // perform logon + // TODO: Benutzerverwaltung + + + } diff --git a/ENI-2/ENI2/ENI2/DetailBaseControl.cs b/ENI-2/ENI2/ENI2/DetailBaseControl.cs index 0ef1ba0e..a1512418 100644 --- a/ENI-2/ENI2/ENI2/DetailBaseControl.cs +++ b/ENI-2/ENI2/ENI2/DetailBaseControl.cs @@ -41,6 +41,11 @@ namespace ENI2 /// public event Action RequestReload; + /// + /// Mit diesem Event wird der Wunsch nach einem Lock zum Ausdruck gebracht ;-) + /// + public event Action RequestLock; + #endregion #region Properties @@ -49,6 +54,8 @@ namespace ENI2 public List Messages { get; set; } + public Guid UserId { get; set; } // TODO: Ersetzen mit der User-Entity + #endregion #region public methods @@ -71,6 +78,10 @@ namespace ENI2 this.RequestReload?.Invoke(); } + protected virtual void OnRequestLock(bool shouldLock) + { + this.RequestLock?.Invoke(shouldLock); + } protected void SetLocodeStateImage(Image stateImage, LocodeState state) { diff --git a/ENI-2/ENI2/ENI2/DetailRootControl.xaml.cs b/ENI-2/ENI2/ENI2/DetailRootControl.xaml.cs index bf600899..603ba5a5 100644 --- a/ENI-2/ENI2/ENI2/DetailRootControl.xaml.cs +++ b/ENI-2/ENI2/ENI2/DetailRootControl.xaml.cs @@ -4,10 +4,12 @@ using System; using System.Collections.Generic; +using System.Diagnostics; using System.Windows.Controls; using bsmd.database; using ENI2.DetailViewControls; +using ENI2.LockingServiceReference; namespace ENI2 { @@ -16,12 +18,27 @@ namespace ENI2 /// public partial class DetailRootControl : UserControl { + + #region Fields + private MessageCore _core; private List _listBoxList = new List(); private List _messages; private Dictionary controlCache = new Dictionary(); + private ServiceClient lockingServiceClient; + private Guid userId = Guid.NewGuid(); // remove THIS!! + + #endregion + + #region Properties + public MessageCore Core { get { return this._core; } } + + #endregion + + #region Construction + public DetailRootControl(MessageCore aCore) { _core = aCore; @@ -51,8 +68,23 @@ namespace ENI2 _messages = DBManager.Instance.GetMessagesForCore(_core, DBManager.MessageLoad.ALL); Dispatcher.BeginInvoke((Action)(() => this.listBoxMessages.SelectedIndex = 0)); + + // Connect to locking service (if enabled) + + try + { + if (ENI2.Properties.Settings.Default.UseLocking) + this.lockingServiceClient = new ServiceClient("BasicHttpBinding_IService", ENI2.Properties.Settings.Default.LockingServerAddress); + } + catch (Exception ex) + { + System.Diagnostics.Trace.WriteLine("Exception creating locking service client: {0}", ex.ToString()); + } + } + #endregion + #region class MessageGroup /// @@ -89,6 +121,7 @@ namespace ENI2 }; detailControl.RequestReload += DetailControl_RequestReload; + detailControl.RequestLock += DetailControl_RequestLock; detailControl.Initialize(); controlCache.Add(mg.MessageGroupControlType, detailControl); @@ -99,6 +132,42 @@ namespace ENI2 } } + private void DetailControl_RequestLock(bool shouldLock) + { + if(this.lockingServiceClient == null) + { + return; + } + if (shouldLock) + { + try + { + string lockResult = this.lockingServiceClient.Lock(this.Core.Id.Value, this.userId.ToString()); + if (lockResult == "") + { + // lock successful + this.Core.Locked = true; + + } + else + { + // locking failed: Notify User + + } + } + catch(Exception ex) + { + Trace.WriteLine(ex.ToString()); + // TODO + } + } + else + { + this.lockingServiceClient.Unlock(this.Core.Id.Value, this.userId.ToString()); + this.Core.Locked = false; + } + } + private void DetailControl_RequestReload() { /// core und messages neu laden diff --git a/ENI-2/ENI2/ENI2/DetailViewControls/OverViewDetailControl.xaml b/ENI-2/ENI2/ENI2/DetailViewControls/OverViewDetailControl.xaml index dfba5656..339f0f72 100644 --- a/ENI-2/ENI2/ENI2/DetailViewControls/OverViewDetailControl.xaml +++ b/ENI-2/ENI2/ENI2/DetailViewControls/OverViewDetailControl.xaml @@ -32,7 +32,9 @@ - + + + @@ -72,19 +74,25 @@ /// true if successful - [OperationContract] + [OperationContract] [WebGet(BodyStyle = WebMessageBodyStyle.Wrapped, RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json)] - bool Lock(Guid messageCoreId, string userId); + string Lock(Guid messageCoreId, string userId); /// @@ -30,6 +30,12 @@ namespace bsmd.LockingService [WebGet(BodyStyle = WebMessageBodyStyle.Wrapped, RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json)] void Unlock(Guid messageCoreId, string userId); + /// + /// Get all locks currently in use (for search result..) + /// + [OperationContract] + [WebGet(BodyStyle = WebMessageBodyStyle.Wrapped, RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json)] + List GetLocks(); /// /// To avoid Timeout, send keepalive message @@ -47,27 +53,5 @@ namespace bsmd.LockingService void Log(string msg, string host, string userId); } - - - // Use a data contract as illustrated in the sample below to add composite types to service operations. - [DataContract] - public class CompositeType - { - bool boolValue = true; - string stringValue = "Hello "; - - [DataMember] - public bool BoolValue - { - get { return boolValue; } - set { boolValue = value; } - } - - [DataMember] - public string StringValue - { - get { return stringValue; } - set { stringValue = value; } - } - } + } diff --git a/nsw/Source/bsmd.LockingService/LockingService.svc b/nsw/Source/bsmd.LockingService/LockingService.svc index bcf45de0..9b689791 100644 --- a/nsw/Source/bsmd.LockingService/LockingService.svc +++ b/nsw/Source/bsmd.LockingService/LockingService.svc @@ -1 +1 @@ -<%@ ServiceHost Language="C#" Debug="true" Service="bsmd.LockingService.LockingService" CodeBehind="LockingService.svc.cs" %> \ No newline at end of file +<%@ ServiceHost Language="C#" Debug="true" Service="bsmd.LockingService.LockingService" CodeBehind="LockingService.svc.cs" %> diff --git a/nsw/Source/bsmd.LockingService/LockingService.svc.cs b/nsw/Source/bsmd.LockingService/LockingService.svc.cs index 59120e49..722267bc 100644 --- a/nsw/Source/bsmd.LockingService/LockingService.svc.cs +++ b/nsw/Source/bsmd.LockingService/LockingService.svc.cs @@ -41,11 +41,13 @@ namespace bsmd.LockingService } private ILog log = LogManager.GetLogger(typeof(LockingService)); - - public bool Lock(Guid messageCoreId, string userId) + + #region Implementation IService + + public string Lock(Guid messageCoreId, string userId) { - if (userId.IsNullOrEmpty()) return false; - bool result = false; + if (userId.IsNullOrEmpty()) return "request error"; + string result = ""; lock (lockDict) { @@ -54,15 +56,19 @@ namespace bsmd.LockingService LockEntry le = new LockEntry(); le.lockAquired = DateTime.Now; le.userId = userId; - lockDict.Add(messageCoreId, le); - result = true; + lockDict.Add(messageCoreId, le); } else { if (lockDict[messageCoreId].userId == userId) { - lockDict[messageCoreId].lockAquired = DateTime.Now; - result = true; + // this means "refresh" + lockDict[messageCoreId].lockAquired = DateTime.Now; + } + else + { + // lock taken by somebody else.. + result = lockDict[messageCoreId].userId; } } } @@ -96,6 +102,22 @@ namespace bsmd.LockingService log.Info(string.Format("{0} {1}:{2}", host, userId, msg)); } + public List GetLocks() + { + List result = new List(); + foreach (Guid messageCoreId in lockDict.Keys) + { + CoreLock coreLock = new CoreLock(); + coreLock.CoreId = messageCoreId; + coreLock.UserId = lockDict[messageCoreId].userId; + result.Add(coreLock); + } + return result; + } + + #endregion + + #region class LockEntry internal class LockEntry { @@ -103,5 +125,7 @@ namespace bsmd.LockingService public string userId = string.Empty; } + #endregion + } } diff --git a/nsw/Source/bsmd.LockingService/Web.config b/nsw/Source/bsmd.LockingService/Web.config index f49e1619..cf0f5aa7 100644 --- a/nsw/Source/bsmd.LockingService/Web.config +++ b/nsw/Source/bsmd.LockingService/Web.config @@ -9,6 +9,11 @@ + + + + + @@ -32,5 +37,10 @@ --> - + + + + + + diff --git a/nsw/Source/bsmd.LockingService/bsmd.LockingService.csproj b/nsw/Source/bsmd.LockingService/bsmd.LockingService.csproj index f41181cf..e965eeae 100644 --- a/nsw/Source/bsmd.LockingService/bsmd.LockingService.csproj +++ b/nsw/Source/bsmd.LockingService/bsmd.LockingService.csproj @@ -16,7 +16,7 @@ v4.5.2 True true - false + true @@ -67,7 +67,10 @@ + + + @@ -80,6 +83,7 @@ Properties\AssemblyProjectKeyInfo.cs + LockingService.svc @@ -92,6 +96,9 @@ + + bsmdKey.snk + Web.config @@ -109,6 +116,12 @@ 10.0 $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) + + true + + + ..\bsmdKey.snk + @@ -120,7 +133,7 @@ True 11651 / - http://localhost/bsmd.LockingService + http://localhost:11651/ False False diff --git a/nsw/Source/bsmd.LockingService/bsmd.LockingService.csproj.user b/nsw/Source/bsmd.LockingService/bsmd.LockingService.csproj.user index cc9ce9ff..98f83566 100644 --- a/nsw/Source/bsmd.LockingService/bsmd.LockingService.csproj.user +++ b/nsw/Source/bsmd.LockingService/bsmd.LockingService.csproj.user @@ -1,7 +1,7 @@  - false + true diff --git a/nsw/Source/bsmd.LockingService/index.htm b/nsw/Source/bsmd.LockingService/index.htm new file mode 100644 index 00000000..775fabe8 --- /dev/null +++ b/nsw/Source/bsmd.LockingService/index.htm @@ -0,0 +1,16 @@ + + + + + + + +
+
+ (c) 2017 schick Informatik - Locking Service
+ WCF Service für die ausschließliche Bearbeitung von Erfassungsmasken in ENI-2. + + + + + diff --git a/nsw/Source/bsmd.LockingService/lock.png b/nsw/Source/bsmd.LockingService/lock.png new file mode 100644 index 00000000..cc0d8dee Binary files /dev/null and b/nsw/Source/bsmd.LockingService/lock.png differ diff --git a/nsw/Source/bsmd.LockingService/logo_transparent_babyblau.png b/nsw/Source/bsmd.LockingService/logo_transparent_babyblau.png new file mode 100644 index 00000000..6a9e3aa2 Binary files /dev/null and b/nsw/Source/bsmd.LockingService/logo_transparent_babyblau.png differ diff --git a/nsw/Source/bsmd.database/MessageCore.cs b/nsw/Source/bsmd.database/MessageCore.cs index cd763be5..de0f78a6 100644 --- a/nsw/Source/bsmd.database/MessageCore.cs +++ b/nsw/Source/bsmd.database/MessageCore.cs @@ -183,6 +183,11 @@ namespace bsmd.database [MaxLength(50)] public string TicketNo { get; set; } + /// + /// Property um in ENI-2 den "gelockten" Zustand zu speichern (wird nicht persistiert) + /// + public bool Locked { get; set; } + #region Felder um NSW Statusinformationen zu speichern (abgefragte Daten!) public bool? Cancelled { get; set; }