コード例 #1
0
ファイル: UserViewModel.cs プロジェクト: savionak/SPP_4
        private void FilterNewsListExecute()
        {
            _shownNewsCount = 0;
            if (IsFiltered)
            {
                foreach (NewsViewModel news in NewsList)
                {
                    bool r = IncludeFilter.Check(news.FullText) &&
                             ExcludeFilter.Check(news.FullText);

                    news.IsVisible = r;
                    if (r)
                    {
                        ++_shownNewsCount;
                    }
                }
            }
            else
            {
                foreach (NewsViewModel news in NewsList)
                {
                    news.IsVisible = true;
                    ++_shownNewsCount;
                }
            }
            OnPropertyChanged("ShownNewsCount");
        }
コード例 #2
0
        private IQueryable <T> Process <T>(IncludeFilter include, IQueryable <T> source, string prefix = "")
        {
            MethodInfo m = includeMethod.MakeGenericMethod(typeof(T));

            source  = (IQueryable <T>)m.Invoke(source, new object[] { source, prefix + include.Field });
            prefix += include.Field + ".";
            source  = Process <T>(include.With, source, prefix);

            return(source);
        }
コード例 #3
0
        public void IncludeTest()
        {
            SetupData("include");

            var filter = new IncludeFilter("*\\out\\*", "*testfile");

            // These have "/out/" in their path
            Assert.AreEqual(filter.ShouldExcludeFile(Path.Combine(TestOutput, "testfile")), false);
            Assert.AreEqual(filter.ShouldExcludeFile(Path.Combine(TestOutput, ".testfile")), false);
            Assert.AreEqual(filter.ShouldExcludeFile(Path.Combine(TestOutput, "asdf")), false);
            Assert.AreEqual(filter.ShouldExcludeFile(Path.Combine(TestOutput, "out")), false);
            Assert.AreEqual(filter.ShouldExcludeFile(Path.Combine(TestOutput, "krout")), false);
            Assert.AreEqual(filter.ShouldExcludeFile(Path.Combine(TestInput, "out\\")), false);

            // Matches against second filter
            Assert.AreEqual(filter.ShouldExcludeFile(Path.Combine(TestInput, "testfile")), false);

            // Shouldn't match against either filter, unless
            // test system somewhere has an out in it! D:
            Assert.AreEqual(filter.ShouldExcludeFile(Path.Combine(TestInput, "false")), true);
            Assert.AreEqual(filter.ShouldExcludeFile(Path.Combine(TestInput, "out")), true);
            Assert.AreEqual(filter.ShouldExcludeFile(Path.Combine(TestInput, "fa.lse")), true);
            Assert.AreEqual(filter.ShouldExcludeFile(Path.Combine(TestInput, "testfile2")), true);
        }
コード例 #4
0
ファイル: NETImport.cs プロジェクト: gbaychev/NClass
    // ========================================================================
    // 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;
    }
コード例 #5
0
ファイル: Program.cs プロジェクト: immeraufdemhund/NReflect
        /// <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);
        }