private string HandleFileLine(string line, ITLCGenPlugin plugin, int visualVer) { var writeline = line; var settings = plugin.Controller.Data.CCOLVersie switch { CCOLVersieEnum.CCOL8 => CCOLGeneratorSettingsProvider.Default.Settings.VisualSettings, CCOLVersieEnum.CCOL9 => CCOLGeneratorSettingsProvider.Default.Settings.VisualSettingsCCOL9, CCOLVersieEnum.CCOL95 => CCOLGeneratorSettingsProvider.Default.Settings.VisualSettingsCCOL95, CCOLVersieEnum.CCOL100 => CCOLGeneratorSettingsProvider.Default.Settings.VisualSettingsCCOL100, CCOLVersieEnum.CCOL110 => CCOLGeneratorSettingsProvider.Default.Settings.VisualSettingsCCOL110, _ => throw new ArgumentOutOfRangeException() }; var ccolinclpaths = settings.CCOLIncludesPaden; var ccolextralibs = settings.CCOLLibs; var ccollibsnotig = settings.CCOLLibsPathNoTig; var ccollibspath = settings.CCOLLibsPath; var ccolppdefs = string.Join(";", GetNeededPreprocDefs(plugin.Controller, false, visualVer).OrderBy(x => x)); var ccolppdefsextra = settings.CCOLPreprocessorDefinitions; var ccolrespath = settings.CCOLResPath; var ccollibs = string.Join(";", GetNeededCCOLLibraries(plugin.Controller, false, visualVer).OrderBy(x => x)); // Replace all if (writeline.Contains("__")) { writeline = writeline.Replace("__CONTROLLERNAME__", plugin.Controller.Data.Naam); writeline = writeline.Replace("__GUID__", Guid.NewGuid().ToString()); var actualccollibspath = ccollibspath == null ? "" : ccollibspath.Remove(ccollibspath.Length - 1); if (!actualccollibspath.EndsWith("\\")) { actualccollibspath += "\\"; } writeline = writeline.Replace("__CCOLLIBSDIR__", actualccollibspath); writeline = writeline.Replace("__CCOLLIBSDIRNOTIG__", ccollibsnotig ?? ""); writeline = writeline.Replace("__CCOLLIBS__", ccollibs); writeline = writeline.Replace("__CCOLLIBSEXTRA__", ccolextralibs ?? ""); var actualccolrespath = ccolrespath == null ? "" : ccolrespath.Remove(ccolrespath.Length - 1); if (!actualccolrespath.EndsWith("\\")) { actualccolrespath += "\\"; } writeline = writeline.Replace("__CCOLLRESDIR__", actualccolrespath); writeline = writeline.Replace("__ADDITIONALINCLUDEDIRS__", ccolinclpaths ?? ""); writeline = writeline.Replace("__PREPROCESSORDEFS__", ccolppdefs); writeline = writeline.Replace("__PREPROCESSORDEFSEXTRA__", ccolppdefsextra); } // If conditions if (!string.IsNullOrWhiteSpace(line)) { var lineif = Regex.IsMatch(line, @"^\s*__IF;.*"); var lineelif = Regex.IsMatch(line, @"^\s*__ELIF;.*"); var lineelse = Regex.IsMatch(line, @"^\s*__ELSE__*"); var result = false; if (lineif || lineelif && !_prevCondition) { #region Conditions var conditionsString = Regex.Replace(line, @"^\s*__(IF|ELIF);([A-Z0-9;!]+)__.*", "$2"); var conditions = conditionsString.Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries); foreach (var condition in conditions) { var invert = condition.StartsWith("!"); var actualCondition = condition.Replace("!", ""); result = actualCondition switch { "IGT" => plugin.Controller.Data.CCOLVersie >= CCOLVersieEnum.CCOL95 && plugin.Controller.Data.Intergroen, "CCOL9ORHIGHER" => plugin.Controller.Data.CCOLVersie >= CCOLVersieEnum.CCOL9, "CCOL95ORHIGHER" => plugin.Controller.Data.CCOLVersie >= CCOLVersieEnum.CCOL95, "PRIO" => plugin.Controller.PrioData.PrioIngrepen != null && plugin.Controller.PrioData.PrioIngrepen.Any() || plugin.Controller.PrioData.HDIngrepen != null && plugin.Controller.PrioData.HDIngrepen.Any(), "MV" => plugin.Controller.Data.KWCType != KWCTypeEnum.Geen, "MVVIALIS" => plugin.Controller.Data.KWCType == KWCTypeEnum.Vialis, "MVOVERIG" => plugin.Controller.Data.KWCType != KWCTypeEnum.Vialis && plugin.Controller.Data.KWCType != KWCTypeEnum.Geen, "PTP" => plugin.Controller.PTPData.PTPKoppelingen != null && plugin.Controller.PTPData.PTPKoppelingen.Any(), "KS" => plugin.Controller.PTPData.PTPKoppelingen != null && plugin.Controller.PTPData.PTPKoppelingen.Any(), "MS" => plugin.Controller.Data.CCOLMulti, "SYNC" => plugin.Controller.Data.SynchronisatiesType == SynchronisatiesTypeEnum.SyncFunc && plugin.Controller.InterSignaalGroep.Gelijkstarten.Any() || plugin.Controller.InterSignaalGroep.Voorstarten.Any(), "HS" => plugin.Controller.HalfstarData.IsHalfstar, "RIS" => plugin.Controller.RISData.RISToepassen && plugin.Controller.RISData.RISFasen.Any(x => x.LaneData.Any()), "RISSIM" => plugin.Controller.RISData.RISToepassen && plugin.Controller.RISData.RISFasen.Any(x => x.LaneData.Any(x2 => x2.SimulatedStations.Any())), _ => false }; if (invert) { result = !result; } if (!result) { break; } #endregion // Conditions } } else if (lineelse && !_prevCondition) { result = true; } if ((lineif || lineelif || lineelse) && !result) { writeline = null; if (lineif) { _prevCondition = false; } } else if (lineif || lineelif || lineelse) { writeline = Regex.Replace(writeline, @"^(\s*)__(IF|ELIF|ELSE)[A-Z0-9;!]*__", "$1"); _prevCondition = true; } } return(writeline); }
/// Loads settings for a given TLCGen addin, such as a generator or importer. The settings are retrieved from /// the instance of CustomDataModel parsed, which is searched for the name of the addin. /// The settings are applied to the addin by loading the properties of the Type parsed, and calling /// SetValue for the properties that have the TLCGenCustomSetting attribute, and for which settings are found. /// </summary> /// <param name="addin">An instance of ITLCGenAddin</param> /// <param name="addintype">And instance of Type, indicating the type of the addin. This is used to read its properties (through reflection).</param> /// <param name="customdata">Instance of CustomDataModel to read settings from.</param> public static void LoadAddinSettings(ITLCGenPlugin addin, Type addintype, CustomDataModel customdata) { // Cast the addin to ITLCGenAddin so we can read its name var iaddin = addin as ITLCGenPlugin; // Loop the settings data, to see if we have settings for this Generator foreach (AddinSettingsModel addindata in customdata.AddinSettings) { if (addindata.Naam == iaddin.GetPluginName()) { // From the Generator, real all properties attributed with [TLCGenGeneratorSetting] var dllprops = addintype.GetProperties().Where( prop => Attribute.IsDefined(prop, typeof(TLCGenCustomSettingAttribute))); // Loop the saved settings, and load if applicable foreach (AddinSettingsPropertyModel dataprop in addindata.Properties) { foreach (var propinfo in dllprops) { // Only load here, if it is a controller specific setting TLCGenCustomSettingAttribute propattr = (TLCGenCustomSettingAttribute)Attribute.GetCustomAttribute(propinfo, typeof(TLCGenCustomSettingAttribute)); if (propinfo.Name == dataprop.Naam) { if (propattr != null && propattr.SettingType == TLCGenCustomSettingAttribute.SettingTypeEnum.Application) { try { string type = propinfo.PropertyType.ToString(); switch (type) { case "System.Double": double d; if (Double.TryParse(dataprop.Setting, out d)) { propinfo.SetValue(addin, d); } break; case "System.Int32": int i32; if (Int32.TryParse(dataprop.Setting, out i32)) { propinfo.SetValue(addin, i32); } break; case "System.String": propinfo.SetValue(addin, dataprop.Setting); break; default: throw new InvalidCastException("False IGenerator property type: " + type); } } catch { System.Windows.MessageBox.Show("Error load generator settings."); } } } } } } } }
public MainWindowViewModel() { var tmpCurDir = Directory.GetCurrentDirectory(); Directory.SetCurrentDirectory(AppDomain.CurrentDomain.BaseDirectory); try { GuiActionsManager.SetStatusBarMessage = (string text) => { StatusBarVM.StatusText = text; }; MessengerInstance.Register(this, new Action <Messaging.Requests.PrepareForGenerationRequest>(OnPrepareForGenerationRequest)); MessengerInstance.Register(this, new Action <ControllerCodeGeneratedMessage>(OnControllerCodeGenerated)); MessengerInstance.Register(this, new Action <ControllerProjectGeneratedMessage>(OnControllerProjectGenerated)); MessengerInstance.Register(this, new Action <ControllerFileNameChangedMessage>(OnControllerFileNameChanged)); // Load application settings and defaults TLCGenSplashScreenHelper.ShowText("Laden instellingen en defaults..."); SettingsProvider.Default.LoadApplicationSettings(); DefaultsProvider.Default.LoadSettings(); TemplatesProvider.Default.LoadSettings(); TLCGenModelManager.Default.InjectDefaultAction((x, s) => DefaultsProvider.Default.SetDefaultsOnModel(x, s)); TLCGenControllerDataProvider.Default.InjectDefaultAction(x => DefaultsProvider.Default.SetDefaultsOnModel(x)); // Load available applicationparts and plugins var assms = Assembly.GetExecutingAssembly(); var types = from t in assms.GetTypes() where t.IsClass && t.Namespace == "TLCGen.ViewModels" select t; TLCGenSplashScreenHelper.ShowText("Laden applicatie onderdelen..."); TLCGenPluginManager.Default.LoadApplicationParts(types.ToList()); TLCGenSplashScreenHelper.ShowText("Laden plugins..."); TLCGenPluginManager.Default.LoadPlugins(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Plugins\\")); // Instantiate all parts _ApplicationParts = new List <Tuple <TLCGenPluginElems, ITLCGenPlugin> >(); var parts = TLCGenPluginManager.Default.ApplicationParts.Concat(TLCGenPluginManager.Default.ApplicationPlugins); foreach (var part in parts) { ITLCGenPlugin instpl = part.Item2; TLCGenSplashScreenHelper.ShowText($"Laden plugin {instpl.GetPluginName()}..."); var flags = Enum.GetValues(typeof(TLCGenPluginElems)); foreach (TLCGenPluginElems elem in flags) { if ((part.Item1 & elem) == elem) { switch (elem) { case TLCGenPluginElems.Generator: Generators.Add(new IGeneratorViewModel(instpl as ITLCGenGenerator)); break; case TLCGenPluginElems.HasSettings: ((ITLCGenHasSettings)instpl).LoadSettings(); break; case TLCGenPluginElems.Importer: MenuItem mi = new MenuItem(); mi.Header = instpl.GetPluginName(); mi.Command = ImportControllerCommand; mi.CommandParameter = instpl; ImportMenuItems.Add(mi); break; case TLCGenPluginElems.IOElementProvider: break; case TLCGenPluginElems.MenuControl: PluginMenuItems.Add(((ITLCGenMenuItem)instpl).Menu); break; case TLCGenPluginElems.TabControl: break; case TLCGenPluginElems.ToolBarControl: break; case TLCGenPluginElems.XMLNodeWriter: break; case TLCGenPluginElems.PlugMessaging: (instpl as ITLCGenPlugMessaging).UpdateTLCGenMessaging(); break; case TLCGenPluginElems.Switcher: (instpl as ITLCGenSwitcher).ControllerSet += (sender, model) => { SetController(model); }; (instpl as ITLCGenSwitcher).FileNameSet += (sender, model) => { TLCGenControllerDataProvider.Default.ControllerFileName = model; }; break; } } TLCGenPluginManager.LoadAddinSettings(instpl, part.Item2.GetType(), SettingsProvider.Default.Settings.CustomData); } _ApplicationParts.Add(new Tuple <TLCGenPluginElems, ITLCGenPlugin>(part.Item1, instpl as ITLCGenPlugin)); } if (Generators.Count > 0) { SelectedGenerator = Generators[0]; } // Construct the ViewModel ControllerVM = new ControllerViewModel(); if (!DesignMode.IsInDesignMode) { if (Application.Current != null && Application.Current.MainWindow != null) { Application.Current.MainWindow.Closing += new CancelEventHandler(MainWindow_Closing); } } #if !DEBUG Application.Current.DispatcherUnhandledException += (o, e) => { string message = "Er is een onverwachte fout opgetreden.\n\n"; if (TLCGenControllerDataProvider.Default.Controller != null) { try { string t = TLCGenControllerDataProvider.Default.ControllerFileName; if (string.IsNullOrWhiteSpace(TLCGenControllerDataProvider.Default.ControllerFileName)) { TLCGenControllerDataProvider.Default.ControllerFileName = System.IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "TLC_recoverysave.tlc"); } TLCGenControllerDataProvider.Default.ControllerFileName = System.IO.Path.Combine( System.IO.Path.GetDirectoryName(TLCGenControllerDataProvider.Default.ControllerFileName), DateTime.Now.ToString("yyyyMMdd-HHmmss-", System.Globalization.CultureInfo.InvariantCulture) + System.IO.Path.GetFileName(TLCGenControllerDataProvider.Default.ControllerFileName)); TLCGenControllerDataProvider.Default.SaveController(); message += "De huidige regeling is hier opgeslagen:\n" + TLCGenControllerDataProvider.Default.ControllerFileName + "\n\n"; if (t != null) { TLCGenControllerDataProvider.Default.ControllerFileName = t; } } catch { } } message += "Gelieve dit probleem inclusief onderstaande details doorgeven aan de ontwikkelaar:\n\n"; var win = new TLCGen.Dialogs.UnhandledExceptionWindow(); win.DialogTitle = "Onverwachte fout in TLCGen"; win.DialogMessage = message; win.DialogExpceptionText = e.Exception.ToString(); win.ShowDialog(); }; #endif } catch (Exception e) { TLCGenSplashScreenHelper.Hide(); string message = "Er is een onverwachte fout opgetreden.\n\n"; message += "Gelieve dit probleem inclusief onderstaande details doorgeven aan de ontwikkelaar:\n\n"; var win = new UnhandledExceptionWindow { DialogTitle = "Onverwachte fout in TLCGen", DialogMessage = message, DialogExpceptionText = e.ToString() }; win.ShowDialog(); } Directory.SetCurrentDirectory(tmpCurDir); #if !DEBUG // Find out if there is a newer version available via Wordpress REST API Task.Run(() => { // clean potential old data var key = Registry.CurrentUser.OpenSubKey("Software", true); var sk1 = key?.OpenSubKey("CodingConnected e.U.", true); var sk2 = sk1?.OpenSubKey("TLCGen", true); var tempFile = (string)sk2?.GetValue("TempInstallFile", null); if (tempFile != null) { if (File.Exists(tempFile)) { File.Delete(tempFile); } sk2?.DeleteValue("TempInstallFile"); } var webRequest = WebRequest.Create(@"https://codingconnected.eu/wp-json/wp/v2/pages/1105"); webRequest.UseDefaultCredentials = true; using (var response = webRequest.GetResponse()) using (var content = response.GetResponseStream()) if (content != null) { using (var reader = new StreamReader(content)) { var strContent = reader.ReadToEnd().Replace("\n", ""); var jsonDeserializer = new JavaScriptSerializer(); var deserializedJson = jsonDeserializer.Deserialize <dynamic>(strContent); if (deserializedJson == null) { return; } var contentData = deserializedJson["content"]; if (contentData == null) { return; } var renderedData = contentData["rendered"]; if (renderedData == null) { return; } var data = renderedData as string; if (data == null) { return; } var all = data.Split('\r'); var tlcgenVer = all.FirstOrDefault(v => v.StartsWith("TLCGen=")); if (tlcgenVer == null) { return; } var oldvers = Assembly.GetEntryAssembly().GetName().Version.ToString().Split('.'); var newvers = tlcgenVer.Replace("TLCGen=", "").Split('.'); bool newer = false; if (oldvers.Length > 0 && oldvers.Length == newvers.Length) { for (int i = 0; i < newvers.Length; i++) { var o = int.Parse(oldvers[i]); var n = int.Parse(newvers[i]); if (o > n) { break; } if (n > o) { newer = true; break; } } } if (newer) { DispatcherHelper.CheckBeginInvokeOnUI(() => { var w = new NewVersionAvailableWindow(tlcgenVer.Replace("TLCGen=", "")); w.ShowDialog(); }); } } } }); #endif }