Imports System.Collections.ObjectModel Imports System.IO Imports EgtWPFLib5 Imports Newtonsoft.Json Imports EgtBEAMWALL.Core Imports EgtUILib Public Class ForcedStrategyPanelVM Inherits VMBase #Region "FIELDS & PROPERTIES" Public Const AUTOMATICSTRATEGYID As String = "AUTOMATIC" Private m_StrategyList As New ObservableCollection(Of Strategy) Public Property StrategyList As ObservableCollection(Of Strategy) Get Return m_StrategyList End Get Set(value As ObservableCollection(Of Strategy)) m_StrategyList = value End Set End Property Private m_SelStrategy As Strategy Public Property SelStrategy As Strategy Get Return m_SelStrategy End Get Set(value As Strategy) m_SelStrategy = value NotifyPropertyChanged(NameOf(SelStrategy)) End Set End Property Public ReadOnly Property ForcedStrategy_Visibility As Visibility Get Return If(Map.refMainWindowVM.MainWindowM.nUserLevel > 5, Visibility.Visible, Visibility.Collapsed) End Get End Property Private m_CurrentFeature As BTLFeatureM ' Definizione Comandi Private m_cmdOk As ICommand Private m_cmdCancel As ICommand #End Region ' Fields & Properties #Region "CONSTRUCTOR" Sub New() Map.SetRefForcedStrategyPanelVM(Me) End Sub #End Region ' Constructor #Region "METHODS" Friend Sub Init(Feature As BTLFeatureM) m_CurrentFeature = Feature LoadStrategyListFromTopology(Feature.nFeatureId, Feature.nPRC, Feature.nSelGRP) ' leggo eventuali parametri forzati Dim sStrategyID As String = "" EgtGetInfo(m_CurrentFeature.nFeatureId, "STRATEGY", sStrategyID) If String.IsNullOrWhiteSpace(sStrategyID) Then Return Dim ForcedStrategy As Strategy = m_StrategyList.FirstOrDefault(Function(x) x.sStrategyId = sStrategyID) If IsNothing(ForcedStrategy) Then Else SelStrategy = ForcedStrategy For Each Param In SelStrategy.ParameterList Select Case Param.GetType() Case GetType(BooleanStrategyParameter) Dim bValue As Boolean = False EgtGetInfo(m_CurrentFeature.nFeatureId, m_SelStrategy.sStrategyId & "_" & Param.sNameNge, bValue) DirectCast(Param, BooleanStrategyParameter).SetValue(bValue) Case GetType(DoubleStrategyParameter) Dim dValue As Double = 0 EgtGetInfo(m_CurrentFeature.nFeatureId, m_SelStrategy.sStrategyId & "_" & Param.sNameNge, dValue) DirectCast(Param, DoubleStrategyParameter).SetValue(dValue) Case GetType(ComboStrategyParameter) Dim sValue As String = String.Empty EgtGetInfo(m_CurrentFeature.nFeatureId, m_SelStrategy.sStrategyId & "_" & Param.sNameNge, sValue) Dim ComboStrategyParameter As ComboStrategyParameter = DirectCast(Param, ComboStrategyParameter) Dim SelCombo = ComboStrategyParameter.ComboList.FirstOrDefault(Function(x) x.sValue = sValue) ComboStrategyParameter.SelValue = SelCombo Case GetType(StringStrategyParameter) Dim sValue As String = String.Empty EgtGetInfo(m_CurrentFeature.nFeatureId, m_SelStrategy.sStrategyId & "_" & Param.sNameNge, sValue) DirectCast(Param, StringStrategyParameter).SetValue(sValue) Case GetType(ListStrategyParameter) Dim sValue As String = String.Empty EgtGetInfo(m_CurrentFeature.nFeatureId, m_SelStrategy.sStrategyId & "_" & Param.sNameNge, sValue) Dim ListStrategyParameter As ListStrategyParameter = DirectCast(Param, ListStrategyParameter) Dim SelValue As ToolParameter = Nothing Dim sTrimValue As String = sValue.TrimEnd(";"c) Dim sTmpValue As String() = sTrimValue.Split(";"c) Dim sSplitValue As String() = Nothing For Each ItemValue As String In sTmpValue sSplitValue = ItemValue.Split(","c) For Each ItemTool As ToolParameter In ListStrategyParameter.ListValue If sSplitValue(0) = ItemTool.sUUID AndAlso sSplitValue(1) = ItemTool.sName Then ItemTool.bIsActive = True SelValue = ListStrategyParameter.ListValue.FirstOrDefault(Function(x) x.sName = ItemTool.sName AndAlso x.sUUID = ItemTool.sUUID) End If Next Next ListStrategyParameter.SelValue = SelValue End Select Next End If End Sub Friend Function LoadStrategyListFromTopology(nFeatureId As Integer, nPRC As Integer, nGRP As Integer) As Boolean m_StrategyList.Clear() Dim sTopologyName As String = "Feature" ' carico default Dim sStrategiesDirPath As String = Map.refMainWindowVM.MainWindowM.GetStrategiesDirPath(ProjectManagerVM.CurrProd.nType) Dim sAvailableStrategiesFilePath As String = sStrategiesDirPath & "\" & AVAILABLESTRATEGYLIST_FILE & ".json" If File.Exists(sAvailableStrategiesFilePath) Then Dim sReadedFile As String = File.ReadAllText(sAvailableStrategiesFilePath) Dim JsonStrategyFeatureList As List(Of JsonAvailableStrategyFeature) = JsonConvert.DeserializeObject(Of List(Of JsonAvailableStrategyFeature))(sReadedFile) nGRP = CalcBeamPrivateProfileGRP(nGRP) Dim JsonAvailableStrategyFeature As JsonAvailableStrategyFeature = JsonStrategyFeatureList.FirstOrDefault(Function(x) x.nGRP = nGRP AndAlso x.nPRC = nPRC) If IsNothing(JsonAvailableStrategyFeature) Then Return False Dim JsonAvailableTopology As JsonAvailableTopology = JsonAvailableStrategyFeature.TopologyList.FirstOrDefault(Function(x) x.sName = sTopologyName) If IsNothing(JsonAvailableTopology) Then ' ricavo topologia da feature FindTopologyFromFeature(nFeatureId, sTopologyName) JsonAvailableTopology = JsonAvailableStrategyFeature.TopologyList.FirstOrDefault(Function(x) x.sName = sTopologyName) End If If IsNothing(JsonAvailableTopology) Then Return False m_StrategyList = New ObservableCollection(Of Strategy)((From JsonAvailableStrategy In JsonAvailableTopology.StrategyList Select JsonAvailableStrategy.Deserialize(ProjectManagerVM.CurrProd.nType, -1)).ToList()) End If ' recupero custom Dim nPartId As Integer = EgtGetParent(EgtGetParent(nFeatureId)) Dim nPartProjId As Integer = 0 If Not EgtGetInfo(nPartId, PROJ, nPartProjId) OrElse nPartProjId <= 0 Then Return False Dim nBTLInfoLayerId As Integer = GetCurrProjBtlInfoLayerId(nPartProjId) Dim sStrategySetupName As String = "" EgtGetInfo(nBTLInfoLayerId, "AISETUP", sStrategySetupName) If Not String.IsNullOrWhiteSpace(sStrategySetupName) Then ' carico custom Dim sAISetupDirPath As String = Map.refMainWindowVM.MainWindowM.GetAISetupDirPath(ProjectManagerVM.CurrProd.nType, True) Dim sStrategyConfigurationFilePath As String = sAISetupDirPath & "\" & sStrategySetupName & ".json" If File.Exists(sStrategyConfigurationFilePath) Then Dim sReadedFile As String = File.ReadAllText(sStrategyConfigurationFilePath) Dim JsonStrategyFeatureList As List(Of JsonStrategyFeature) = JsonConvert.DeserializeObject(Of List(Of JsonStrategyFeature))(sReadedFile) Dim JsonStrategyFeature As JsonStrategyFeature = JsonStrategyFeatureList.FirstOrDefault(Function(x) x.nGRP = nGRP AndAlso x.nPRC = nPRC) If IsNothing(JsonStrategyFeature) Then Return False Dim JsonTopology As JsonTopology = JsonStrategyFeature.TopologyList.FirstOrDefault(Function(x) x.sName = sTopologyName) If IsNothing(JsonTopology) Then Return False For Each Strategy In JsonTopology.StrategyList Dim DefaultStrategy As Strategy = m_StrategyList.FirstOrDefault(Function(x) x.sStrategyId = Strategy.sStrategyId) If IsNothing(DefaultStrategy) Then ' DefaultTopology.StrategyList.Add(New Strategy(DefaultTopology, Strategy)) ' verifico indici!! Else DefaultStrategy.ReadConfiguration(Strategy) End If Next End If End If ' aggiungo strategia automatica m_StrategyList.Insert(0, New Strategy() With {.sStrategyId = AUTOMATICSTRATEGYID, .sStrategyName = AUTOMATICSTRATEGYID}) NotifyPropertyChanged(NameOf(StrategyList)) Return True End Function Friend Function GetCurrProjBtlInfoLayerId(nProjId As Integer) As Integer ' cerco tra i layer BTLInfo Dim nBTLInfoLayerId As Integer = EgtGetFirstNameInGroup(GDB_ID.ROOT, BTLINFO) While nBTLInfoLayerId <> GDB_ID.NULL ' verifico se il layer appartiene al ProjId Dim nBTLInfoLayerProjId As Integer EgtGetInfo(nBTLInfoLayerId, BTL_PRT_PROJ, nBTLInfoLayerProjId) If nBTLInfoLayerProjId = nProjId Then Return nBTLInfoLayerId End If nBTLInfoLayerId = EgtGetNextName(nBTLInfoLayerId, BTLINFO) End While Return -1 End Function #End Region ' Methods #Region "COMMANDS" #Region "Ok_Command" Public ReadOnly Property Ok_Command As ICommand Get If m_cmdOk Is Nothing Then m_cmdOk = New Command(AddressOf Ok) End If Return m_cmdOk End Get End Property Public Sub Ok() ' cancello precedenti valori Dim sPrecStrategyID As String = "" EgtGetInfo(m_CurrentFeature.nFeatureId, "STRATEGY", sPrecStrategyID) If Not String.IsNullOrWhiteSpace(sPrecStrategyID) Then Dim PrecInfo As String() = {} EgtGetAllInfo(m_CurrentFeature.nFeatureId, PrecInfo) Dim PrecStrategyInfo As String() = PrecInfo.Where(Function(x) x.StartsWith(sPrecStrategyID)).ToArray() For Each Info In PrecStrategyInfo EgtRemoveInfo(m_CurrentFeature.nFeatureId, Info.Split("="c)(0)) Next End If If m_SelStrategy.sStrategyId = AUTOMATICSTRATEGYID Then EgtRemoveInfo(m_CurrentFeature.nFeatureId, "STRATEGY") Else EgtSetInfo(m_CurrentFeature.nFeatureId, "STRATEGY", SelStrategy.sStrategyId) Dim sInfo As String = String.Empty For Each Param In SelStrategy.ParameterList Select Case Param.GetType() Case GetType(BooleanStrategyParameter) EgtSetInfo(m_CurrentFeature.nFeatureId, m_SelStrategy.sStrategyId & "_" & Param.sNameNge, DirectCast(Param, BooleanStrategyParameter).bValue) Case GetType(DoubleStrategyParameter) EgtSetInfo(m_CurrentFeature.nFeatureId, m_SelStrategy.sStrategyId & "_" & Param.sNameNge, DirectCast(Param, DoubleStrategyParameter).sValue) Case GetType(ComboStrategyParameter) EgtSetInfo(m_CurrentFeature.nFeatureId, m_SelStrategy.sStrategyId & "_" & Param.sNameNge, DirectCast(Param, ComboStrategyParameter).SelValue.sValue) Case GetType(StringStrategyParameter) EgtSetInfo(m_CurrentFeature.nFeatureId, m_SelStrategy.sStrategyId & "_" & Param.sNameNge, DirectCast(Param, StringStrategyParameter).sValue) Case GetType(ListStrategyParameter) For Each Item As ToolParameter In DirectCast(Param, ListStrategyParameter).ListValue If Item.bIsActive Then sInfo &= Item.sUUID & "," & Item.sName & ";" EgtSetInfo(m_CurrentFeature.nFeatureId, m_SelStrategy.sStrategyId & "_" & Param.sNameNge, sInfo) End If Next End Select Next End If Map.refProjectVM.SetSelManagerTab(ProjectVM.StrategyManagerTab.RAWPARTMANAGER) ' Abilito LeftPanel Map.refProjectVM.SetOnlyProdLeftPanel_IsEnabled(True) Map.refProjectVM.SetOnlyProdLeftPanel_Opacity(1) End Sub #End Region ' Ok_Command #Region "Cancel_Command" Public ReadOnly Property Cancel_Command As ICommand Get If m_cmdCancel Is Nothing Then m_cmdCancel = New Command(AddressOf Cancel) End If Return m_cmdCancel End Get End Property Public Sub Cancel() Map.refProjectVM.SetSelManagerTab(ProjectVM.StrategyManagerTab.RAWPARTMANAGER) ' Abilito LeftPanel Map.refProjectVM.SetOnlyProdLeftPanel_IsEnabled(True) Map.refProjectVM.SetOnlyProdLeftPanel_Opacity(1) End Sub #End Region ' Cancel_Command #End Region ' Commands End Class