//TODO: can remove PackageSettings and use GlobalPackageSettings
        public FormSelectObjects(DTE2 dte2, PackageSettings settings)
        {
            _dte2     = dte2;
            _settings = settings;

            InitializeComponent();
            LoadLocals();

            TypeRetriever   retriever = new TypeRetriever(dte2);
            List <IRuleSet> ruleSets  = new List <IRuleSet>();

            if (settings.IgnoreDynamicallyAddedProperties)
            {
                ruleSets.Add(new PropertyInClassRuleSet(retriever));
            }

            bool excludePrivates = radCheckBoxExcludePrivate.Checked;

            if (excludePrivates)
            {
                ruleSets.Add(new AccessiblePropertiesRuleSet(retriever));
            }

            _ruleSetValidator = new RuleSetValidator(ruleSets);
        }
Example #2
0
        public static IEnumerable <IPredicateVisitorConverter> GetPredicateVisitorConverters <T>()
            where T : IPredicateVisitorConverter
        {
            var retriever = new TypeRetriever();
            var types     = retriever.GetTypes <T>();

            return(types.Select(type => (IPredicateVisitorConverter)Activator.CreateInstance(type)));
        }
        private async void buttonExport_Click(object sender, EventArgs e)
        {
            //Create Export Paramaters
            bool             excludePrivates         = radCheckBoxExcludePrivate.Checked;
            bool             ignoreDynamicProperties = _settings.IgnoreDynamicallyAddedProperties;
            ExportType       exportType       = GetExportType();
            int              maxDepth         = (int)numericUpDownMaxDepth.Value;
            ExportParamaters exportParamaters = new ExportParamaters(excludePrivates, ignoreDynamicProperties, maxDepth, exportType);

            CancellationTokenSource cancellationTokenSource = new CancellationTokenSource();

            _waitingDialog = new ProgressDialog(cancellationTokenSource);

            List <ExpressionWithSource> expressions = GetAllExpressions();

            if (expressions.Any())
            {
                //Hide and Show Progress Bar
                this.Hide();
                _waitingDialog.Show(this);

                TypeRetriever retriever       = new TypeRetriever(_dte2);
                var           exportGenerator = new ExportGenerator(expressions, retriever, exportParamaters);

                try
                {
                    Dictionary <string, string> lookupGeneratedTexts = await exportGenerator.GenerateTextWithKey(cancellationTokenSource.Token);

                    //Setup event for when the form is shown to close the waiting dialog
                    FormDisplayGeneratedText formDisplayGeneratedText = new FormDisplayGeneratedText(lookupGeneratedTexts, exportType);
                    formDisplayGeneratedText.Shown += formDisplayGeneratedText_Shown;
                    formDisplayGeneratedText.ShowDialog(this);
                }
                catch (ThreadAbortException ex)
                {
                    _waitingDialog.Close();
                }
                catch (ObjectDisposedException ex)
                {
                    _waitingDialog.Close();
                }
                catch (Exception ex)
                {
                    _waitingDialog.Close();
                    Raygun.LogException(ex);
                    MessageBox.Show("Error when attempting to export objects. If error reporting has not been disabled," +
                                    " then your error has already been logged.");
                }
                finally
                {
                    this.Show();
                }
            }
        }
        public ExportGenerator(IEnumerable <ExpressionWithSource> expressionsWithSources,
                               TypeRetriever retriever, ExportParamaters exportParamaters)
        {
            _type = exportParamaters.ExportType;
            _expressionsWithSources = expressionsWithSources;
            _maxDepth = exportParamaters.MaxDepth;

            List <IRuleSet> ruleSets = new List <IRuleSet>();

            if (exportParamaters.ExcludePropertiesNotInClass)
            {
                ruleSets.Add(new PropertyInClassRuleSet(retriever));
            }
            if (exportParamaters.ExludePrivateProperties)
            {
                ruleSets.Add(new AccesiblePropertiesRuleSet(retriever));
            }

            _ruleSetValidator = new RuleSetValidator(ruleSets);
        }
        public void ShouldRetrieveAllTypesWithSimplInjectAttribute()
        {
            const string assemblyname = "assemblyName";

            var assemblyLoaderMock = new Mock<IAssemblyLoader>();
            assemblyLoaderMock
                .Setup(it => it.RetrieveTypesFrom(assemblyname))
                .Returns(new List<Type> { typeof(DateTime), typeof(string) });

            var attributeVerifierMock = new Mock<IAttributeVerifier>();
            attributeVerifierMock.Setup(it => it.HasAttribute(It.IsAny<Type>())).Returns(false);
            attributeVerifierMock.Setup(it => it.HasAttribute(typeof (string))).Returns(true);

            var retriever = new TypeRetriever(assemblyLoaderMock.Object, attributeVerifierMock.Object);

            var typesToBeInjected = retriever.RetrieveFrom(assemblyname);
            typesToBeInjected.Should().Have.Count.EqualTo(1);
            typesToBeInjected.Should().Have.SameSequenceAs(typeof (string));
            typesToBeInjected.Should().Not.Have.SameSequenceAs(typeof (DateTime));

            assemblyLoaderMock.Verify(it => it.RetrieveTypesFrom(assemblyname), Times.Once());
            attributeVerifierMock.Verify(it => it.HasAttribute(It.IsAny<Type>()), Times.Exactly(2));
        }
Example #6
0
 public PropertyInClassRuleSet(TypeRetriever retriever)
 {
     _retriever = retriever;
 }
 protected ContentLoaderBase(Type annotatedClass, ProcessingEnvironment environment)
 {
     _environment    = environment;
     _annotatedClass = annotatedClass;
     _typeRetriever  = TypeRetriever.With(environment);
 }
Example #8
0
 public AccessiblePropertiesRuleSet(TypeRetriever retriever)
 {
     _retriever = retriever;
 }
 public AccessiblePropertiesRuleSet(TypeRetriever retriever)
 {
     _retriever = retriever;
 }
 public PropertyInClassRuleSet(TypeRetriever retriever)
 {
     _retriever = retriever;
 }