Exemplo n.º 1
0
        // ========================================================================
        // Methods

        #region === Methods

        /// <summary>
        /// Visit a <see cref="NRAssembly"/>.
        /// </summary>
        /// <param name="nrAssembly">The <see cref="NRAssembly"/> to visit.</param>
        public void Visit(NRAssembly nrAssembly)
        {
            OutputLine("NRAssembly");
            indent++;
            nrAssembly.Attributes.ForEach(nrAttribute => nrAttribute.Accept(this));
            VisitEnities(nrAssembly);
        }
Exemplo n.º 2
0
        // ========================================================================
        // Methods

        #region === Methods

        /// <summary>
        /// Visit a <see cref="NRAssembly"/>.
        /// </summary>
        /// <param name="nrAssembly">The <see cref="NRAssembly"/> to visit.</param>
        public void Visit(NRAssembly nrAssembly)
        {
            OutputLine("Assembly " + nrAssembly.FullName);
            OutputLine("  Source " + nrAssembly.Source);
            VisitAttributes(nrAssembly);
            OutputLine("");
            PrintEntities(nrAssembly);
        }
Exemplo n.º 3
0
        private void AddRelationships(NRAssembly nrAssembly)
        {
            if (!settings.CreateRelationships)
            {
                return;
            }

            RelationshipCreator relationshipCreator = new RelationshipCreator();
            NRRelationships     nrRelationships     = relationshipCreator.CreateRelationships(nrAssembly, settings.CreateNestings,
                                                                                              settings.CreateGeneralizations,
                                                                                              settings.CreateRealizations,
                                                                                              settings.CreateAssociations);

            AddRelationships(nrRelationships);
        }
Exemplo n.º 4
0
        // ========================================================================
        // Properties

        #region === Properties


        #endregion

        // ========================================================================
        // Methods

        #region === Methods

        /// <summary>
        /// The main entry point of this class. Imports the assembly which is given
        /// as the parameter.
        /// </summary>
        /// <param name="fileName">The file name and path of the assembly to import.</param>
        /// <returns><c>True</c>, if the import was successful.</returns>
        public bool ImportAssembly(string fileName, bool useNewAppDomain = true)
        {
            if (string.IsNullOrEmpty(fileName))
            {
                throw new ArgumentNullException(nameof(fileName), Strings.Error_NoAssembly);
            }

            try
            {
                diagram.Name            = Path.GetFileName(fileName);
                diagram.RedrawSuspended = true;

                IncludeFilter includeFilter = new IncludeFilter();
                includeFilter.Rules.AddRange(settings.FilterRules);
                IFilter filter = includeFilter;
                if (!settings.UseAsWhiteList)
                {
                    filter = new InvertFilter(includeFilter);
                }

                NClassImportFilter nClassImportFilter = new NClassImportFilter(filter);
                Reflector          reflector          = new Reflector();
                filter = nClassImportFilter;
                NRAssembly nrAssembly = reflector.Reflect(fileName, ref filter, useNewAppDomain);
                nClassImportFilter = (NClassImportFilter)filter;

                AddInterfaces(nrAssembly.Interfaces);
                AddClasses(nrAssembly.Classes);
                AddStrcts(nrAssembly.Structs);
                AddDelegates(nrAssembly.Delegates);
                AddEnums(nrAssembly.Enums);

                ArrangeTypes();

                AddRelationships(nrAssembly);

                if (nClassImportFilter.UnsafeTypesPresent)
                {
                    throw new UnsafeTypesPresentException(Strings.UnsafeTypesPresent);
                }
            }
            finally
            {
                diagram.RedrawSuspended = false;
            }

            return(true);
        }
Exemplo n.º 5
0
        /// <summary>
        /// Invokes the given visitor for the given assembly.
        /// </summary>
        /// <param name="nrAssembly">The assembly to run the visitor for.</param>
        /// <param name="visitorName">The name of the visitor to run.</param>
        /// <returns>The result of the visitor.</returns>
        public string RunVisitor(NRAssembly nrAssembly, string visitorName)
        {
            if (!visitorTypes.ContainsKey(visitorName))
            {
                throw new ArgumentException("Visitor '" + visitorName + "' is unknown.");
            }

            StringWriter  stringWriter = new StringWriter();
            IVisitor      visitor      = Activator.CreateInstance(visitorTypes[visitorName], stringWriter) as IVisitor;
            VisitorConfig config       = GetVisitorConfig(visitorName);

            if (config != null)
            {
                config.Apply(visitor);
            }
            nrAssembly.Accept(visitor);

            return(stringWriter.ToString());
        }
Exemplo n.º 6
0
        // ========================================================================
        // Properties

        #region === Properties


        #endregion

        // ========================================================================
        // Methods

        #region === Methods

        /// <summary>
        /// The main entry point of this class. Imports the assembly which is given
        /// as the parameter.
        /// </summary>
        /// <param name="fileName">The file name and path of the assembly to import.</param>
        /// <returns><c>True</c>, if the import was successful.</returns>
        public bool ImportAssembly(string fileName)
        {
            if (string.IsNullOrEmpty(fileName))
            {
                MessageBox.Show(Strings.Error_NoAssembly, Strings.Error_MessageBoxTitle, MessageBoxButtons.OK, MessageBoxIcon.Error);
                return(false);
            }
            try
            {
                diagram.Name            = Path.GetFileName(fileName);
                diagram.RedrawSuspended = true;

                IncludeFilter includeFilter = new IncludeFilter();
                includeFilter.Rules.AddRange(settings.FilterRules);
                IFilter filter = includeFilter;
                if (!settings.UseAsWhiteList)
                {
                    filter = new InvertFilter(includeFilter);
                }

                NClassImportFilter nClassImportFilter = new NClassImportFilter(filter);
                Reflector          reflector          = new Reflector();
                filter = nClassImportFilter;
                NRAssembly nrAssembly = reflector.Reflect(fileName, ref filter);
                nClassImportFilter = (NClassImportFilter)filter;

                AddInterfaces(nrAssembly.Interfaces);
                AddClasses(nrAssembly.Classes);
                AddStrcts(nrAssembly.Structs);
                AddDelegates(nrAssembly.Delegates);
                AddEnums(nrAssembly.Enums);

                ArrangeTypes();

                RelationshipCreator relationshipCreator = new RelationshipCreator();
                NRRelationships     nrRelationships     = relationshipCreator.CreateRelationships(nrAssembly, settings.CreateNestings,
                                                                                                  settings.CreateGeneralizations,
                                                                                                  settings.CreateRealizations,
                                                                                                  settings.CreateAssociations);
                AddRelationships(nrRelationships);

                if (nClassImportFilter.UnsafeTypesPresent)
                {
                    MessageBox.Show(null, Strings.UnsafeTypesPresent, Strings.WarningTitle, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                }
            }
            catch (ReflectionTypeLoadException)
            {
                MessageBox.Show(Strings.Error_MissingReferencedAssemblies, Strings.Error_MessageBoxTitle, MessageBoxButtons.OK, MessageBoxIcon.Error);
                return(false);
            }
            catch (FileLoadException)
            {
                MessageBox.Show(Strings.Error_MissingReferencedAssemblies, Strings.Error_MessageBoxTitle, MessageBoxButtons.OK, MessageBoxIcon.Error);
                return(false);
            }
            catch (BadImageFormatException)
            {
                MessageBox.Show(Strings.Error_BadImageFormat, Strings.Error_MessageBoxTitle, MessageBoxButtons.OK, MessageBoxIcon.Error);
                return(false);
            }
            catch (Exception ex)
            {
                MessageBox.Show(String.Format(Strings.Error_GeneralException, ex), Strings.Error_MessageBoxTitle, MessageBoxButtons.OK, MessageBoxIcon.Error);
                return(false);
            }
            finally
            {
                diagram.RedrawSuspended = false;
            }

            return(true);
        }
Exemplo n.º 7
0
 /// <summary>
 /// Initializes a new instance of <see cref="NReflectResult"/>.
 /// </summary>
 /// <param name="nrAssembly">The assembly of the result.</param>
 /// <param name="nrRelationships">The relationships of the result.</param>
 public NReflectResult(NRAssembly nrAssembly, NRRelationships nrRelationships)
 {
     NRAssembly      = nrAssembly;
     NRRelationships = nrRelationships;
 }
Exemplo n.º 8
0
        // ========================================================================
        // Methods

        #region === Methods

        /// <summary>
        /// Visit a <see cref="NRAssembly"/>.
        /// </summary>
        /// <param name="nrAssembly">The <see cref="NRAssembly"/> to visit.</param>
        public void Visit(NRAssembly nrAssembly)
        {
            NRAssembly = nrAssembly;

            if (KnownNamespaces != null)
            {
                foreach (string knownNamespace in KnownNamespaces.Where(s => !string.IsNullOrWhiteSpace(s)))
                {
                    OutputLine("using " + knownNamespace + ";");
                }
                if (KnownNamespaces.Length > 0)
                {
                    OutputLine("");
                }
            }
            IEnumerable <string> namespaces = (from type in nrAssembly.Types
                                               select type.Namespace).Distinct();

            foreach (string ns in namespaces)
            {
                bool nsPresent = !string.IsNullOrWhiteSpace(ns);
                if (nsPresent)
                {
                    OutputLine("namespace " + ns);
                    OutputLine("{");
                    indent++;
                }
                foreach (NRClass nrClass in nrAssembly.Classes)
                {
                    if (nrClass.Namespace == ns)
                    {
                        nrClass.Accept(this);
                    }
                }
                foreach (NRStruct nrStruct in nrAssembly.Structs)
                {
                    if (nrStruct.Namespace == ns)
                    {
                        nrStruct.Accept(this);
                    }
                }
                foreach (NRInterface nrInterface in nrAssembly.Interfaces)
                {
                    if (nrInterface.Namespace == ns)
                    {
                        nrInterface.Accept(this);
                    }
                }
                foreach (NRDelegate nrDelegate in nrAssembly.Delegates)
                {
                    if (nrDelegate.Namespace == ns)
                    {
                        nrDelegate.Accept(this);
                    }
                }
                foreach (NREnum nrEnum in nrAssembly.Enums)
                {
                    if (nrEnum.Namespace == ns)
                    {
                        nrEnum.Accept(this);
                    }
                }
                if (nsPresent)
                {
                    indent--;
                    OutputLine("}");
                    OutputEmptyLineAfterType();
                }
            }
        }