public void AddUsefulTips() { try { var pathService = new PathService(); var tipsProvider = new TipsProvider(pathService); var tipContexts = new List <TipContext>(); foreach (var language in tipsProvider.SupportedLanguages) { var tipsLanguageFullPath = GetTipsLanguagePath(language); CreateTipsImportContent(tipsLanguageFullPath, language); var tipsImportFile = Path.Combine(tipsLanguageFullPath, "TipsImport.xml"); var tips = GetTipsForImport(tipsProvider, tipsImportFile, tipsLanguageFullPath); if (tips?.Count > 0) { tipContexts.Add(new TipContext { LanguageId = language, Tips = tips }); } } tipsProvider.AddTips(tipContexts, StringResources.SDLTM_Anonymizer_Name); } catch (Exception ex) { Trace.WriteLine(ex.Message); } }
protected override void Initialize(IViewContext context) { SettingsService = new SettingsService(new PathInfo()); Model = new MainViewModel(SettingsService, this); Model.PropertyChanged += Model_PropertyChanged; Model.SelectedTabIndex = 0; _explorerControl = new TmAnonymizerExplorerControl(Model); _logViewController = new SDLTMAnonymizerLogViewPart(Model); if (SettingsService.GetSettings().Accepted) { Model.LogViewModel.IsEnabled = true; _control = new TmAnonymizerViewControl(Model); var pathInfo = new RwsAppStore.UsefulTipsService.Model.PathInfo(PluginResources.Plugin_Name, "16"); var tipsProvider = new TipsProvider(pathInfo); var usefulTipsService = new UsefulTipsService(tipsProvider, SettingsService.PathInfo); var tipLanguages = usefulTipsService.GetPluginUsefulTips(); var tipsInstalled = TipsInstalled(tipLanguages, "SDLTMAnonymizerView"); if (tipsInstalled == 0) { var importTips = new ImportTips { TipLanguages = tipLanguages }; var countInstalled = usefulTipsService.AddUsefulTips(importTips, true); Trace.WriteLine(string.Format("Installed {0}", countInstalled)); } AlignLanguageTipIds(tipLanguages, tipsProvider, usefulTipsService); //var tipReferences = new List<TipReference>(); //foreach (var tipLanguage in tipLanguages) //{ // tipReferences.Add(new TipReference // { // LanguageId = tipLanguage.LanguageId, // Resources = tipLanguage.Resources.Select(a => a.RelativePath).ToList(), // TipIds = tipLanguage.Tips.Where(a => !string.IsNullOrEmpty(a.Id)).Select(a => a.Id).ToList() // }); //} //var removeTips = new RemoveTips { TipReferences = tipReferences }; //var countRemoved = usefulTipsService.RemoveUsefulTips(removeTips); //Trace.WriteLine(string.Format("Removed {0}", countRemoved)); // Debug //var count = usefulTipsService.RemoveUsefulTips(usefulTips, StringResources.SDLTM_Anonymizer_Name); } else { Model.LogViewModel.IsEnabled = false; } }
protected override void Execute() { var customViewPathInfo = new CustomViewPathInfo(); var pathInfo = new PathInfo(PluginResources.Plugin_Name, "16"); var tipsProvider = new TipsProvider(pathInfo); var usefulTipsService = new UsefulTipsService(tipsProvider, customViewPathInfo); var tipLanguages = usefulTipsService.GetPluginUsefulTips(); if (tipLanguages.Count == 0) { MessageBox.Show(PluginResources.No_useful_tips_found, PluginResources.Plugin_Name); } AlignLanguageTipIds(tipLanguages, tipsProvider, usefulTipsService); var tipReferences = new List <TipReference>(); foreach (var tipLanguage in tipLanguages) { tipReferences.Add(new TipReference { LanguageId = tipLanguage.LanguageId, Resources = tipLanguage.Resources.Select(a => a.RelativePath).ToList(), TipIds = tipLanguage.Tips.Where(a => !string.IsNullOrEmpty(a.Id)).Select(a => a.Id).ToList() }); } var removeTips = new RemoveTips { TipReferences = tipReferences }; var count = usefulTipsService.RemoveUsefulTips(removeTips); if (count > 0) { //Option (1) // Use this if you have a reference to "using Sdl.Desktop.Platform" and comment out Option (2) //var message = string.Format(PluginResources.Removed__0__useful_tips, count); //message += Environment.NewLine + Environment.NewLine; //message += PluginResources.Restart_Trados_Studio_to_apply_changes; //var dr = MessageBox.Show(message, PluginResources.Plugin_Name, MessageBoxButton.YesNo, MessageBoxImage.Question); //if (dr == MessageBoxResult.Yes) //{ // StudioPlatform.Studio.Restart(); //} //Option (2) // Use this if you DO NOT have a reference to "using Sdl.Desktop.Platform" and comment out Option (1) var message = string.Format(PluginResources.Removed__0__useful_tips, count); message += Environment.NewLine + Environment.NewLine; message += PluginResources.Restart_Trados_Studio_before_changes_are_applied; MessageBox.Show(message, PluginResources.Plugin_Name, MessageBoxButton.OK, MessageBoxImage.Information); return; } MessageBox.Show(PluginResources.No_useful_tips_removed, PluginResources.Plugin_Name); }
/// <summary> /// Actions performed when "Tips & Tricks" menu clicked. /// </summary> private void ExecuteTips(object sender, EventArgs e) { if (dlgTips == null) { tips = new TipsProvider(); dlgTips = new AboutBoxTipsForm(tips); } dlgTips.ShowDialog(); }
protected override void Execute() { var customViewPathInfo = new CustomViewPathInfo(); var pathInfo = new PathInfo(PluginResources.Plugin_Name, "16"); var tipsProvider = new TipsProvider(pathInfo); var usefulTipsService = new UsefulTipsService(tipsProvider, customViewPathInfo); var tipLanguages = usefulTipsService.GetPluginUsefulTips(); if (tipLanguages.Count == 0) { MessageBox.Show(PluginResources.No_useful_tips_found, PluginResources.Plugin_Name); } var importTips = new ImportTips { TipLanguages = tipLanguages }; var count = usefulTipsService.AddUsefulTips(importTips, true); if (count > 0) { //Option (1) // Use this if you have a reference to "using Sdl.Desktop.Platform" and comment out Option (2) //var message = string.Format(PluginResources.Added__0__useful_tips, count); //message += Environment.NewLine + Environment.NewLine; //message += PluginResources.Restart_Trados_Studio_to_apply_changes; //var dr = MessageBox.Show(message, PluginResources.Plugin_Name, MessageBoxButton.YesNo, MessageBoxImage.Question); //if (dr == MessageBoxResult.Yes) //{ // StudioPlatform.Studio.Restart(); //} //Option (2) // Use this if you DO NOT have a reference to "using Sdl.Desktop.Platform" and comment out Option (1) var message = string.Format(PluginResources.Added__0__useful_tips, count); message += Environment.NewLine + Environment.NewLine; message += PluginResources.Restart_Trados_Studio_before_changes_are_applied; MessageBox.Show(message, PluginResources.Plugin_Name, MessageBoxButton.OK, MessageBoxImage.Information); return; } MessageBox.Show(PluginResources.No_new_useful_tips_installed, PluginResources.Plugin_Name); }
private static List <Tip> GetTipsForImport(TipsProvider tipsService, string tipsImportFile, string tipsLanguageFullPath) { var tips = tipsService.ReadTipsImportFile(tipsImportFile); // update the relative path info for each of the Tips foreach (var tip in tips) { tip.Icon = GetFullPath(tip.Icon, tipsLanguageFullPath); tip.Content = GetFullPath(tip.Content, tipsLanguageFullPath); tip.DescriptionImage = GetFullPath(tip.DescriptionImage, tipsLanguageFullPath); } // save the updated tips with the relative path info tipsService.CreateTipsImportFile(tipsImportFile, tips); return(tips); }
public UsefulTipsService(TipsProvider tipsProvider, Model.PathInfo pluginPathInfo) { _tipsRoot = new XmlRootAttribute("Tips"); _tipsProvider = tipsProvider; _pluginPathInfo = pluginPathInfo; }
public UsefulTipsService(TipsProvider tipsProvider, CustomViewPathInfo customViewPathInfo) { _tipsRoot = new XmlRootAttribute("Tips"); _tipsProvider = tipsProvider; _customViewPathInfo = customViewPathInfo; }
public AboutBoxTipsForm(TipsProvider tips) { this.tips = tips; InitializeComponent(); }
private static void AlignLanguageTipIds(IEnumerable <TipLanguage> tipLanguages, TipsProvider tipsProvider, UsefulTipsService usefulTipsService) { var studioTips = tipsProvider.GetStudioTips(); foreach (var tipLanguage in tipLanguages) { var installedTipLanguages = studioTips.FirstOrDefault(a => a.LanguageId == tipLanguage.LanguageId); if (installedTipLanguages == null) { continue; } foreach (var languageTip in tipLanguage.Tips) { var existingTip = usefulTipsService.GetExistingTip(installedTipLanguages.Tips, languageTip); if (existingTip != null) { languageTip.Id = existingTip.Id; } } } }