init
This commit is contained in:
@@ -0,0 +1,9 @@
|
||||
using Prism.Events;
|
||||
|
||||
namespace DTS.Common.Events
|
||||
{
|
||||
public class LoadViewModulEvent : PubSubEvent<LoadViewModulArg> { }
|
||||
public class LoadViewModulArg : EventBase
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,191 @@
|
||||
using DTS.Common.Events;
|
||||
using DTS.Common.SharedResource.Strings;
|
||||
using DTS.Common.Utilities.Logging;
|
||||
using Prism.Events;
|
||||
using Prism.Events;
|
||||
using Prism.Ioc;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing.Text;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Interop;
|
||||
|
||||
namespace DTS.Common.Classes.Locking
|
||||
{
|
||||
public class SensorsLocking
|
||||
{
|
||||
private LockRecord[] _existingLocks = null;
|
||||
private static readonly object MyLock = new object();
|
||||
|
||||
private CancellationTokenSource _cancellationTokenSource = null;
|
||||
private readonly Task _updateTask = null;
|
||||
private const int MAX_WAIT_TIME_MS = 10000;
|
||||
/// <summary>
|
||||
/// returns false if stop was not needed or failed
|
||||
/// returns true if stop was completed
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
private bool StopUpdating()
|
||||
{
|
||||
if (null == _cancellationTokenSource || null == _existingLocks) { return false; }
|
||||
lock (MyLock)
|
||||
{
|
||||
_cancellationTokenSource.Cancel();
|
||||
if (!_updateTask.Wait(MAX_WAIT_TIME_MS))
|
||||
{
|
||||
APILogger.Log("Failed to stop updating locks");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
public void Unlock(bool bCheckLock, string userName, int userId)
|
||||
{
|
||||
if (!StopUpdating()) { return; }
|
||||
|
||||
lock (MyLock)
|
||||
{
|
||||
if (null == _existingLocks || 0 == _existingLocks.Length) { return; }
|
||||
}
|
||||
try
|
||||
{
|
||||
FreeLocks();
|
||||
}
|
||||
catch (Exception ex) { APILogger.Log(ex); }
|
||||
}
|
||||
private void FreeLocks()
|
||||
{
|
||||
LockRecord[] locks;
|
||||
lock (MyLock)
|
||||
{
|
||||
if (null == _existingLocks || 0 == _existingLocks.Length) { return; }
|
||||
locks = _existingLocks.ToArray();
|
||||
}
|
||||
foreach( var record in locks)
|
||||
{
|
||||
try
|
||||
{
|
||||
LockManager.FreeLoc
|
||||
}
|
||||
catch(Exception ex) { APILogger.Log(ex); }
|
||||
}
|
||||
}
|
||||
private bool CheckLock(bool publishErrors, string userName, int userId, LockRecord lockRecord, out LockError lockError)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
/// <summary>
|
||||
/// performs an immediate update of locks, publishes an error if the lock could not be updated
|
||||
/// </summary>
|
||||
/// <param name="publishErrors">whether to publish when there's an error or not</param>
|
||||
/// <returns></returns>
|
||||
private bool CheckLocks(bool publishErrors, string userName, int userId)
|
||||
{
|
||||
try
|
||||
{
|
||||
LockRecord[] records;
|
||||
lock (MyLock)
|
||||
{
|
||||
//FB 18006 Prevent null reference exception
|
||||
if (_existingLocks == null || 0 == _existingLocks.Length)
|
||||
{
|
||||
APILogger.Log("_existingLock is null");
|
||||
return false;
|
||||
}
|
||||
//create a local copy of the locks so we can update them without the lock
|
||||
records = _existingLocks.ToArray();
|
||||
}
|
||||
var failed = new List<LockRecord>();
|
||||
var errors = new List<LockError>();
|
||||
foreach (var record in records)
|
||||
{
|
||||
LockError lockError;
|
||||
if (!CheckLock(publishErrors, userName, userId, record, out lockError))
|
||||
{
|
||||
failed.Add(record);
|
||||
errors.Add(lockError);
|
||||
}
|
||||
}
|
||||
if (failed.Any() && errors.Any())
|
||||
{
|
||||
if (publishErrors)
|
||||
{
|
||||
var msg = GetErrorMessage(errors.ToArray(), records.ToArray());
|
||||
var eventAggregator = ContainerLocator.Container.Resolve<IEventAggregator>();
|
||||
eventAggregator.GetEvent<PageErrorEvent>().Publish(new PageErrorArg(new[] { msg }, null));
|
||||
}
|
||||
//if we failed to update ANY of them we need to wipe out our selection
|
||||
lock (MyLock)
|
||||
{
|
||||
_existingLocks = new LockRecord[0];
|
||||
}
|
||||
WipeOutChanges();
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
APILogger.Log(ex);
|
||||
if (publishErrors)
|
||||
{
|
||||
var eventAggregator = ContainerLocator.Container.Resolve<IEventAggregator>();
|
||||
eventAggregator.GetEvent<PageErrorEvent>().Publish(new PageErrorArg(
|
||||
new[] { $"{StringResources.FailedToUpdateLock}, {ex.Message}" }, null));
|
||||
}
|
||||
_cancellationTokenSource?.Cancel();
|
||||
lock (MyLock)
|
||||
{
|
||||
_existingLocks = new LockRecord[0];
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
private void WipeOutChanges()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
private static string GetErrorMessage(LockError[] errors, LockRecord[] lockRecords )
|
||||
{
|
||||
StringBuilder sb = new StringBuilder(0);
|
||||
|
||||
for( var i = 0; i < errors.Length && i < lockRecords.Length; i ++)
|
||||
{
|
||||
var error = errors[i];
|
||||
var record = lockRecords[i];
|
||||
if (error.LockStolen)
|
||||
{
|
||||
sb.AppendLine(string.Format(StringResources.LockStolen_Sensors, record.ItemKey, error.LockingUser, error.LockingMachine));
|
||||
}
|
||||
else if(error.LockLost)
|
||||
{
|
||||
sb.AppendLine(string.Format(StringResources.LockLost_Sensors, record.ItemKey));
|
||||
}
|
||||
else
|
||||
{
|
||||
sb.AppendLine($"{StringResources.FailedToUpdateLock} - {record.ItemKey}");
|
||||
}
|
||||
}
|
||||
return sb.ToString();
|
||||
}
|
||||
/// <summary>
|
||||
/// returns true if the lockrecord matches the sensor currently locked in this control
|
||||
/// 14340 sensor lost/locked - unlocked on sensor import
|
||||
/// </summary>
|
||||
/// <param name="lockRecord"></param>
|
||||
/// <returns></returns>
|
||||
public bool IsCurrentlyLocked(LockRecord lockRecord)
|
||||
{
|
||||
lock (MyLock)
|
||||
{
|
||||
if (null == _existingLocks) { return false; }
|
||||
|
||||
return Array.Exists(_existingLocks, x => x.ItemId == lockRecord.ItemId && x.ItemCategory == lockRecord.ItemCategory);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
using DTS.Common.Base;
|
||||
|
||||
namespace DTS.Common.Interface
|
||||
{
|
||||
public interface ITestSettingsViewModel : IBaseViewModel { }
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
using Prism.Events;
|
||||
|
||||
namespace DTS.Common.Events.Groups.GroupChannelList
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// The GroupUpdated event.
|
||||
/// </summary>
|
||||
///
|
||||
/// <remarks>called when a template is selected.</remarks>
|
||||
///
|
||||
public class GroupUpdatedEvent : PubSubEvent<GroupUpdatedEventArgs> { }
|
||||
|
||||
public class GroupUpdatedEventArgs
|
||||
{
|
||||
public object Page { get; }
|
||||
|
||||
public enum Status
|
||||
{
|
||||
ChannelsInserted,
|
||||
AssignmentsMade
|
||||
}
|
||||
public Status UpdateStatus { get; }
|
||||
public GroupUpdatedEventArgs(object page, Status status)
|
||||
{
|
||||
Page = page;
|
||||
UpdateStatus = status;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
using Prism.Events;
|
||||
// ReSharper disable CheckNamespace
|
||||
|
||||
namespace DTS.Common.Events
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// The Data Folder changed event.
|
||||
/// </summary>
|
||||
public class ResetZoomChangedEvent : PubSubEvent<bool> { }
|
||||
}
|
||||
@@ -0,0 +1,74 @@
|
||||
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
|
||||
|
||||
<Style x:Key="CheckBoxFocusVisual">
|
||||
<Setter Property="Control.Template">
|
||||
<Setter.Value>
|
||||
<ControlTemplate>
|
||||
<Border>
|
||||
<Rectangle
|
||||
Margin="15,0,0,0"
|
||||
StrokeThickness="1"
|
||||
Stroke="#60000000"
|
||||
StrokeDashArray="1 2"/>
|
||||
</Border>
|
||||
</ControlTemplate>
|
||||
</Setter.Value>
|
||||
</Setter>
|
||||
</Style>
|
||||
|
||||
<Style x:Key="{x:Type CheckBox}" TargetType="CheckBox">
|
||||
<Setter Property="SnapsToDevicePixels" Value="true"/>
|
||||
<Setter Property="OverridesDefaultStyle" Value="true"/>
|
||||
<Setter Property="FontFamily" Value="{DynamicResource MetroFontRegular}"/>
|
||||
<Setter Property="FocusVisualStyle" Value="{StaticResource CheckBoxFocusVisual}"/>
|
||||
<Setter Property="Foreground" Value="#999999"/>
|
||||
<Setter Property="Background" Value="#3f3f3f"/>
|
||||
<Setter Property="FontSize" Value="12"/>
|
||||
<Setter Property="VerticalContentAlignment" Value="Center"/>
|
||||
<Setter Property="Template">
|
||||
<Setter.Value>
|
||||
<ControlTemplate TargetType="CheckBox">
|
||||
<BulletDecorator Background="Transparent">
|
||||
<BulletDecorator.Bullet>
|
||||
<Border x:Name="Border"
|
||||
Width="13"
|
||||
Height="13"
|
||||
CornerRadius="0"
|
||||
Background="#3f3f3f"
|
||||
BorderBrush="#999999"
|
||||
BorderThickness="1">
|
||||
<Path
|
||||
Width="7" Height="7"
|
||||
x:Name="CheckMark"
|
||||
SnapsToDevicePixels="False"
|
||||
Stroke="#979797"
|
||||
StrokeThickness="2"
|
||||
Data="M 0 0 L 7 7 M 0 7 L 7 0" />
|
||||
</Border>
|
||||
</BulletDecorator.Bullet>
|
||||
<ContentPresenter Margin="8,0,0,0"
|
||||
VerticalAlignment="Center"
|
||||
HorizontalAlignment="Left"
|
||||
RecognizesAccessKey="True"/>
|
||||
</BulletDecorator>
|
||||
<ControlTemplate.Triggers>
|
||||
<Trigger Property="IsChecked" Value="false">
|
||||
<Setter TargetName="CheckMark" Property="Visibility" Value="Collapsed"/>
|
||||
</Trigger>
|
||||
<Trigger Property="IsChecked" Value="{x:Null}">
|
||||
<Setter TargetName="CheckMark" Property="Data" Value="M 0 7 L 7 0" />
|
||||
</Trigger>
|
||||
<Trigger Property="IsMouseOver" Value="true">
|
||||
<Setter TargetName="Border" Property="Background" Value="#454545" />
|
||||
<Setter TargetName="Border" Property="BorderBrush" Value="{DynamicResource ApplicationAccentBrush}" />
|
||||
</Trigger>
|
||||
<Trigger Property="IsEnabled" Value="false">
|
||||
<Setter Property="Foreground" Value="#c1c1c1"/>
|
||||
</Trigger>
|
||||
</ControlTemplate.Triggers>
|
||||
</ControlTemplate>
|
||||
</Setter.Value>
|
||||
</Setter>
|
||||
</Style>
|
||||
</ResourceDictionary>
|
||||
@@ -0,0 +1,6 @@
|
||||
using DTS.Common.Base;
|
||||
|
||||
namespace DTS.Common.Interface.DASFactory.Diagnostics.HardwareList
|
||||
{
|
||||
public interface IHardwareListOverdueView : IBaseView { }
|
||||
}
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 3.1 KiB |
Binary file not shown.
Reference in New Issue
Block a user