Esempio n. 1
0
        public void Reflect(TestCaseAssembly testCase)
        {
            ObservableCollection <Message> messages = CoreData.Instance.Messages;

            // Do the reflection
            NRAssembly nrAssembly;
            IFilter    filter = new StatisticFilter(new ReflectAllFilter());

            try
            {
                Reflector reflector = new Reflector();
                nrAssembly = reflector.Reflect(testCase.FullPath, ref filter);
            }
            catch (Exception ex)
            {
                messages.Add(new Message {
                    MessageText = "Reflection failed with the following exception: " + ex.Message, Severity = MessageSeverity.Error
                });
                testCase.State = TestCaseState.ReflectionFailed;
                return;
            }
            messages.Add(new Message {
                MessageText = "Reflection successful.", Severity = MessageSeverity.Info
            });

            // Create relationships
            RelationshipCreator relationshipCreator = new RelationshipCreator();
            NRRelationships     nrRelationships     = relationshipCreator.CreateRelationships(nrAssembly);

            // Save the results
            testCase.CurrentResult = new NReflectResult(nrAssembly, nrRelationships);
        }
Esempio n. 2
0
        /// <summary>
        /// Compiles and reflects a single <see cref="TestCase"/>.
        /// </summary>
        /// <param name="testCase">The <see cref="TestCase"/> to run.</param>
        public void CompileAndReflect(TestCaseCSharp testCase)
        {
            ObservableCollection <Message> messages = CoreData.Instance.Messages;

            messages.Add(new Message {
                MessageText = "Compilation of test case '" + testCase.Name + "' started.", Severity = MessageSeverity.Info
            });

            // Compile the code
            CompilerResults compilerResults = Compile(new[] { testCase.Code });

            List <Message> compileMessages = ToMessages(compilerResults.Errors, testCase.Name);

            compileMessages.ForEach(messages.Add);

            if (compileMessages.Count > 0)
            {
                messages.Add(new Message {
                    MessageText = "Compilation failed. Aboarding.", Severity = MessageSeverity.Error
                });
                testCase.State = TestCaseState.CompilationFailed;
                return;
            }
            messages.Add(new Message {
                MessageText = "Compilation successful.", Severity = MessageSeverity.Info
            });

            // Do the reflection
            NRAssembly nrAssembly;
            IFilter    filter = new StatisticFilter(new ReflectAllFilter());

            try
            {
                Reflector reflector = new Reflector();
                nrAssembly = reflector.Reflect(compilerResults.CompiledAssembly, ref filter);
            }
            catch (Exception ex)
            {
                messages.Add(new Message {
                    MessageText = "Reflection failed with the following exception: " + ex.Message, Severity = MessageSeverity.Error
                });
                testCase.State = TestCaseState.ReflectionFailed;
                return;
            }
            messages.Add(new Message {
                MessageText = "Reflection successful.", Severity = MessageSeverity.Info
            });

            // Create relationships
            RelationshipCreator relationshipCreator = new RelationshipCreator();
            NRRelationships     nrRelationships     = relationshipCreator.CreateRelationships(nrAssembly);

            // Save the results
            testCase.CurrentResult = new NReflectResult(nrAssembly, nrRelationships);
        }
Esempio 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);
        }
Esempio n. 4
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldOnlyChangeLockedRecordsWhenUpgradingToDenseNode()
        public virtual void ShouldOnlyChangeLockedRecordsWhenUpgradingToDenseNode()
        {
            // GIVEN
            long      nodeId    = CreateNodeWithRelationships(DENSE_NODE_THRESHOLD);
            NeoStores neoStores = FlipToNeoStores();

            Tracker tracker = new Tracker(neoStores);
            RelationshipGroupGetter groupGetter         = new RelationshipGroupGetter(neoStores.RelationshipGroupStore);
            RelationshipCreator     relationshipCreator = new RelationshipCreator(groupGetter, 5);

            // WHEN
            relationshipCreator.RelationshipCreate(_idGeneratorFactory.get(IdType.RELATIONSHIP).nextId(), 0, nodeId, nodeId, tracker, tracker);

            // THEN
            assertEquals(tracker.RelationshipLocksAcquired.Count, tracker.ChangedRelationships.Count);
            assertFalse(tracker.RelationshipLocksAcquired.Count == 0);
        }
Esempio n. 5
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);
        }
Esempio 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;
    }
Esempio n. 7
0
        /// <summary>
        /// The main method of the program.
        /// </summary>
        /// <param name="args">The arguments supplied at the console.</param>
        static void Main(string[] args)
        {
            string fileName = null;

            foreach (string s in args)
            {
                if (s.StartsWith("-"))
                {
                    foreach (char c in s.Substring(1))
                    {
                        switch (c)
                        {
                        case 'a':
                            assembly = true;
                            break;

                        case 'm':
                            modules = true;
                            break;

                        case 'r':
                            relations = true;
                            break;

                        case 's':
                            statistic = true;
                            break;

                        default:
                            PrintUsage();
                            return;
                        }
                    }
                }
                else
                {
                    if (fileName != null)
                    {
                        PrintUsage();
                        return;
                    }
                    fileName = s;
                }
            }

            if (fileName == null)
            {
                PrintUsage();
                return;
            }

            Console.WriteLine("Will now reflect " + fileName);

            // Create the filter
            ReflectAllFilter allFilter = new ReflectAllFilter();

            IncludeFilter includeFilter = new IncludeFilter();

            includeFilter.Rules.Add(new FilterRule(FilterModifiers.AllModifiers, FilterElements.Class));
            includeFilter.Rules.Add(new FilterRule(FilterModifiers.AllModifiers, FilterElements.Field));
            includeFilter.Rules.Add(new FilterRule(FilterModifiers.AllModifiers, FilterElements.Attribute));

            StatisticFilter statisticFilter = new StatisticFilter(allFilter);

            // Do the reflection
            NRAssembly nrAssembly;
            IFilter    filter = statisticFilter;

            try
            {
                Reflector reflector = new Reflector();
                nrAssembly = reflector.Reflect(fileName, ref filter);
            }
            catch (Exception ex)
            {
                Console.WriteLine("Exception while reflecting: " + ex.Message);
                return;
            }

            // Output of the results
            IVisitor visitor = new PrintTreeVisitor();

//      IVisitor visitor = new CSharpVisitor();
//      IVisitor visitor = new PrintVisitor();
            if (assembly)
            {
                nrAssembly.Accept(visitor);
                Console.WriteLine();
            }

            if (modules)
            {
                foreach (NRModule nrModule in nrAssembly.Modules)
                {
                    nrModule.Accept(visitor);
                }
                Console.WriteLine();
            }

            if (relations)
            {
                RelationshipCreator relationshipCreator = new RelationshipCreator();
                NRRelationships     nrRelationships     = relationshipCreator.CreateRelationships(nrAssembly);

                Console.WriteLine("Nesting relationships:");
                foreach (NRNesting nrNestingRelationship in nrRelationships.Nestings)
                {
                    Console.WriteLine(nrNestingRelationship);
                }
                Console.WriteLine();

                Console.WriteLine("Generalization relationships:");
                foreach (NRGeneralization nrGeneralizationRelationship in nrRelationships.Generalizations)
                {
                    Console.WriteLine(nrGeneralizationRelationship);
                }
                Console.WriteLine();

                Console.WriteLine("Realization relationships:");
                foreach (NRRealization nrRealizationRelationship in nrRelationships.Realizations)
                {
                    Console.WriteLine(nrRealizationRelationship);
                }
                Console.WriteLine();

                Console.WriteLine("Association relationships:");
                foreach (NRAssociation nrAssociationRelationship in nrRelationships.Associations)
                {
                    Console.WriteLine(nrAssociationRelationship);
                }
                Console.WriteLine();
            }

            if (statistic)
            {
                statisticFilter = (StatisticFilter)filter;
                Console.WriteLine();
                Console.WriteLine("Statistic:");
                Console.WriteLine("Classes     : {0}/{1}", statisticFilter.ReflectedClasses, statisticFilter.ReflectedClasses + statisticFilter.IgnoredClasses);
                Console.WriteLine("Interfaces  : {0}/{1}", statisticFilter.ReflectedInterfaces, statisticFilter.ReflectedInterfaces + statisticFilter.IgnoredInterfaces);
                Console.WriteLine("Structures  : {0}/{1}", statisticFilter.ReflectedStructures, statisticFilter.ReflectedStructures + statisticFilter.IgnoredStructures);
                Console.WriteLine("Delegates   : {0}/{1}", statisticFilter.ReflectedDelegates, statisticFilter.ReflectedDelegates + statisticFilter.IgnoredDelegates);
                Console.WriteLine("Enums       : {0}/{1}", statisticFilter.ReflectedEnums, statisticFilter.ReflectedEnums + statisticFilter.IgnoredEnums);
                Console.WriteLine("EnumValues  : {0}/{1}", statisticFilter.ReflectedEnumValues, statisticFilter.ReflectedEnumValues + statisticFilter.IgnoredEnumValues);
                Console.WriteLine("Constructors: {0}/{1}", statisticFilter.ReflectedConstructors, statisticFilter.ReflectedConstructors + statisticFilter.IgnoredConstructors);
                Console.WriteLine("Methods     : {0}/{1}", statisticFilter.ReflectedMethods, statisticFilter.ReflectedMethods + statisticFilter.IgnoredMethods);
                Console.WriteLine("Fields      : {0}/{1}", statisticFilter.ReflectedFields, statisticFilter.ReflectedFields + statisticFilter.IgnoredFields);
                Console.WriteLine("Properties  : {0}/{1}", statisticFilter.ReflectedProperties, statisticFilter.ReflectedProperties + statisticFilter.IgnoredProperties);
                Console.WriteLine("Events      : {0}/{1}", statisticFilter.ReflectedEvents, statisticFilter.ReflectedEvents + statisticFilter.IgnoredEvents);
                Console.WriteLine("Operators   : {0}/{1}", statisticFilter.ReflectedOperators, statisticFilter.ReflectedOperators + statisticFilter.IgnoredOperators);
                Console.WriteLine("Attributes  : {0}/{1}", statisticFilter.ReflectedAttributes, statisticFilter.ReflectedAttributes + statisticFilter.IgnoredAttributes);
                Console.WriteLine("Modules     : {0}/{1}", statisticFilter.ReflectedModules, statisticFilter.ReflectedModules + statisticFilter.IgnoredModules);
            }

            Console.WriteLine("Press any key to exit...");
            Console.ReadKey(true);
        }