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);
        }
示例#3
0
        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 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;
                    }
                }
            }
        }