public AnonymizeScripts LoadSettings()
        {
            AnonymizeScripts scripts;


            if (null == _optionsAgent)
            {
                _optionsAgent = GetOptionsDataAccessAgent();
            }

            if (null != _optionsAgent && _optionsAgent.OptionExits(AnonymizeOptionsKey))
            {
                scripts = _optionsAgent.Get <AnonymizeScripts>(AnonymizeOptionsKey, null, new Type[0]);
            }
            else
            {
                scripts = new AnonymizeScripts(true);

                if (null != _optionsAgent)
                {
                    _optionsAgent.Set <AnonymizeScripts>(AnonymizeOptionsKey, scripts, new Type[0]);
                }
            }

            return(scripts);
        }
        public void UpdateSettings( )
        {
            if (_optionsAgent == null)
            {
                _optionsAgent = GetOptionsDataAccessAgent();
            }

            // If _optionsAgent is still null, then the optionsAgent is not registered
            // This can happen occur with older installation of v17.5, when the optionsAgent did not exist
            if (_optionsAgent == null)
            {
                return;
            }

            if (_settings.Equals(_view))
            {
                return;
            }

            if (_view.IsDirty)
            {
                _settings = Clone(_view.AnonymizeScripts);

                _optionsAgent.Set <AnonymizeScripts>(AnonymizeOptionsKey, _settings, new Type[0]);

                _view.ChangesCommited( );
            }
        }
        private static AnonymizeScripts Clone(AnonymizeScripts options)
        {
            AnonymizeScripts clone = null;

            try
            {
                using (MemoryStream stream = new MemoryStream())
                {
                    XmlSerializer s = new XmlSerializer(typeof(AnonymizeScripts));
                    s.Serialize(stream, options);

                    stream.Seek(0, SeekOrigin.Begin);
                    clone = (AnonymizeScripts)s.Deserialize(stream);
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                // throw;
            }


            return(clone);
            //try
            //{
            //   //
            //   // Don't serialize a null object, simply return the default for that object
            //   //
            //   if (Object.ReferenceEquals(options, null))
            //   {
            //      return null;
            //   }

            //   if (!options.GetType().IsSerializable)
            //   {
            //      throw new ArgumentException("The type must be serializable.", "source");
            //   }

            //   AppDomain.CurrentDomain.AssemblyResolve += new ResolveEventHandler(CurrentDomain_AssemblyResolve);

            //   IFormatter formatter = new BinaryFormatter();
            //   Stream stream = new MemoryStream();

            //   using (stream)
            //   {
            //      formatter.Serialize(stream, options);
            //      stream.Seek(0, SeekOrigin.Begin);

            //      return (AnonymizeScripts)formatter.Deserialize(stream);
            //   }
            //}
            //finally
            //{
            //   AppDomain.CurrentDomain.AssemblyResolve -= CurrentDomain_AssemblyResolve;
            //}
        }
        public void RunView(AnonymizeOptionsView view)
        {
            _view = view;

            _settings = LoadSettings();

            view.AnonymizeScripts = Clone(_settings);
            // _view.Initialize();
            _view.SettingsChanged += new EventHandler(_view_SettingsChanged);
        }
 private void  OnSaveAnonymizeSettingsEventArgs(object sender, SaveAnonymizeSettingsEventArgs e)
 {
     // UpdateSettings( ) ;
     _settings = Clone(e.Scripts);
     ResetSettings();
 }