コード例 #1
0
ファイル: AuditAdvice.cs プロジェクト: ronmark1/ClearCanvas-1
            public void Intercept(IInvocation invocation)
            {
                // ensure the thread-static variable is initialized for the current thread
                if (_invocationInfo == null)
                {
                    _invocationInfo = new Stack <InvocationInfo>();
                }

                try
                {
                    var recorderContexts = AttributeUtils.GetAttributes <AuditRecorderAttribute>(invocation.MethodInvocationTarget, true)
                                           .Select(a => new RecorderContext(invocation, (IServiceOperationRecorder)Activator.CreateInstance(a.RecorderClass)))
                                           .ToList();

                    _invocationInfo.Push(new InvocationInfo(recorderContexts));

                    invocation.Proceed();

                    _invocationInfo.Peek().PostCommit();
                }
                finally
                {
                    // clear current invocation
                    _invocationInfo.Pop();
                }
            }
コード例 #2
0
        private void BuildTestsFromMethod(Test parent, IMethodInfo method, string namePrefix, string nameSuffix)
        {
            try
            {
                foreach (TestAttribute2 attrib in AttributeUtils.GetAttributes <TestAttribute2>(method, true))
                {
                    BuildTest(parent, method, namePrefix, nameSuffix, attrib);
                }

                foreach (RowTestAttribute2 attrib in AttributeUtils.GetAttributes <RowTestAttribute2>(method, true))
                {
                    BuildRowTest(parent, method, namePrefix, nameSuffix, attrib);
                }

                foreach (CombinatorialTestAttribute2 attrib in AttributeUtils.GetAttributes <CombinatorialTestAttribute2>(method, true))
                {
                    BuildCombinatorialTest(parent, method, namePrefix, nameSuffix, attrib);
                }
            }
            catch (Exception ex)
            {
                testModel.AddAnnotation(new Annotation(AnnotationType.Error, method,
                                                       "An exception was thrown while exploring an MbUnit v2 test method.", ex));
            }
        }
コード例 #3
0
        private void LoadExtensions()
        {
            lock (Extensions)
            {
                if (!_extensionLoaded)
                {
                    try
                    {
                        Extensions.Clear();

                        var attrs = AttributeUtils.GetAttributes <ExtensibleAttribute>(this.GetType(), true);
                        foreach (var attr in attrs)
                        {
                            var xp = Activator.CreateInstance(attr.ExtensionPoint);
                            Extensions.AddRange((xp as ExtensionPoint).CreateExtensions());
                        }

                        _extensionLoaded = true;
                    }
                    catch (Exception ex)
                    {
                        Platform.Log(LogLevel.Error, ex, "Unable to load page extension");
                    }
                }
            }
        }
コード例 #4
0
        private static void PopulateMethodMetadata(ICodeElementInfo codeElement, PropertyBag metadata)
        {
            foreach (TestAttribute attr in AttributeUtils.GetAttributes <TestAttribute>(codeElement, true))
            {
                // Add timeout
                if (attr.Timeout > 0)
                {
                    TimeSpan timeout = TimeSpan.FromMilliseconds(attr.Timeout);
                    metadata.Add("Timeout", timeout.Seconds.ToString("0.000"));
                }

                // Add categories
                string categories = attr.Categories;
                if (!String.IsNullOrEmpty(categories))
                {
                    foreach (string category in categories.Split(','))
                    {
                        metadata.Add(MetadataKeys.Category, category);
                    }
                }
            }

            // Add expected exception type
            foreach (ExpectedExceptionAttribute attr in AttributeUtils.GetAttributes <ExpectedExceptionAttribute>(codeElement, true))
            {
                metadata.Add(MetadataKeys.ExpectedException, attr.ExceptionType.FullName);
            }

            PopulateCommonMetadata(codeElement, metadata);
        }
コード例 #5
0
                public ChildInfo GetPossibleChildFor(IList <TList> list)
                {
                    var description = AttributeUtils.GetAttributes <DescriptionAttribute, TElement>().FirstOrDefault();

                    return(new ChildInfo(
                               name: _name,
                               description: description?.Description,
                               create: () => new AddToCollection <TList>(list, new TElement())));
                }
コード例 #6
0
ファイル: PluginInfo.cs プロジェクト: bangush/server-1
        /// <summary>
        /// Internal method used by the framework to discover extension points and extensions declared in a plugin.
        /// </summary>
        /// <param name="asm"></param>
        /// <param name="points"></param>
        /// <param name="extensions"></param>
        internal static void DiscoverExtensionPointsAndExtensions(Assembly asm, List <ExtensionPointInfo> points, List <ExtensionInfo> extensions)
        {
            foreach (var type in asm.GetTypes())
            {
                var epAttr = AttributeUtils.GetAttribute <ExtensionPointAttribute>(type, false);
                if (epAttr != null)
                {
                    if (IsValidExtensionPointClass(type))
                    {
                        points.Add(new ExtensionPointInfo(type, GetExtensionInterface(type), epAttr.Name, epAttr.Description));
                    }
                    else
                    {
                        Platform.Log(LogLevel.Error, SR.ExceptionExtensionPointMustSubclassExtensionPoint, type.FullName);
                    }
                }

                var attrs = AttributeUtils.GetAttributes <ExtensionOfAttribute>(type, false);
                foreach (var a in attrs)
                {
                    // is the extension a concrete class?
                    if (!IsConcreteClass(type))
                    {
                        Platform.Log(LogLevel.Error, SR.ExceptionExtensionMustBeConcreteClass, type.FullName);
                        continue;
                    }

                    var extensionPointClass = a.ExtensionPointClass;
                    if (!IsValidExtensionPointClass(extensionPointClass))
                    {
                        Platform.Log(LogLevel.Error, SR.ExceptionExtensionDoesNotExtendValidExtensionPointClass, type.FullName);
                        continue;
                    }

                    // does the extension implement the required interface?
                    var extensionInterface = GetExtensionInterface(extensionPointClass);
                    if (!extensionInterface.IsAssignableFrom(type))
                    {
                        Platform.Log(LogLevel.Error, SR.ExceptionExtensionDoesNotImplementRequiredInterface,
                                     type.FullName,
                                     extensionInterface);

                        continue;
                    }
                    extensions.Add(
                        new ExtensionInfo(
                            type,
                            extensionPointClass,
                            a.Name,
                            a.Description,
                            ExtensionSettings.Default.IsEnabled(type, a.Enabled),
                            a.FeatureToken
                            )
                        );
                }
            }
        }
コード例 #7
0
        private static bool IsApplicableAction(Type actionClass, ServerRuleTypeEnum ruleType)
        {
            var attrs = AttributeUtils.GetAttributes <ActionApplicabilityAttribute>(actionClass);

            // if no attributes, assume applicable to all rule types
            if (!attrs.Any())
            {
                return(true);
            }

            return(attrs.Any(a => a.RuleType.ToServerRuleTypeEnum().Equals(ruleType)));
        }
コード例 #8
0
        /// <inheritdoc />
        public IEnumerable <IPattern> GetPatterns(ICodeElementInfo codeElement)
        {
            if (codeElement == null)
            {
                throw new ArgumentNullException("codeElement");
            }

            foreach (PatternAttribute attribute in AttributeUtils.GetAttributes <PatternAttribute>(codeElement, true))
            {
                yield return(attribute);
            }
        }
コード例 #9
0
        public static void PopulateTestMetadata(Test test, IMemberInfo member)
        {
            foreach (TestPatternAttribute2 attrib in AttributeUtils.GetAttributes <TestPatternAttribute2>(member, true))
            {
                if (!String.IsNullOrEmpty(attrib.Description))
                {
                    test.Metadata.Add(MetadataKeys.Description, attrib.Description);
                }
            }

            PopulateFixtureOrTestMetadata(test, member);
        }
コード例 #10
0
            public override IEnumerable <ChildInfo> GetPossibleChildrenFor(TContainer container)
            {
                var description = AttributeUtils.GetAttributes <DescriptionAttribute, TProperty>().FirstOrDefault();

                return(new[]
                {
                    new ChildInfo(
                        name: _name,
                        description: description?.Description,
                        create: () => new SetValueCommand <TProperty>(_getPointer(container), new TProperty()))
                });
            }
コード例 #11
0
ファイル: ImexUtils.cs プロジェクト: hksonngan/Xian
 /// <summary>
 /// Finds the imex that supports the specified data-class.
 /// </summary>
 /// <param name="dataClass"></param>
 /// <returns></returns>
 /// <exception cref="NotSupportedException">Indicates that no imex was found that supports the specified data-class.</exception>
 public static IXmlDataImex FindImexForDataClass(string dataClass)
 {
     return((IXmlDataImex) new XmlDataImexExtensionPoint().CreateExtension(
                delegate(ExtensionInfo info)
     {
         return CollectionUtils.Contains(AttributeUtils.GetAttributes <ImexDataClassAttribute>(info.ExtensionClass),
                                         delegate(ImexDataClassAttribute a)
         {
             return a != null && a.DataClass.Equals(
                 dataClass, StringComparison.InvariantCultureIgnoreCase);
         });
     }));
 }
コード例 #12
0
        public static void PopulateFixtureMetadata(Test test, ITypeInfo fixtureType)
        {
            foreach (AuthorAttribute2 attrib in AttributeUtils.GetAttributes <AuthorAttribute2>(fixtureType, true))
            {
                if (!String.IsNullOrEmpty(attrib.Name))
                {
                    test.Metadata.Add(MetadataKeys.AuthorName, attrib.Name);
                }
                if (!String.IsNullOrEmpty(attrib.EMail) && attrib.EMail != @"unspecified")
                {
                    test.Metadata.Add(MetadataKeys.AuthorEmail, attrib.EMail);
                }
                if (!String.IsNullOrEmpty(attrib.HomePage) && attrib.HomePage != @"unspecified")
                {
                    test.Metadata.Add(MetadataKeys.AuthorHomepage, attrib.HomePage);
                }
            }

            foreach (FixtureCategoryAttribute2 attrib in AttributeUtils.GetAttributes <FixtureCategoryAttribute2>(fixtureType, true))
            {
                test.Metadata.Add(MetadataKeys.Category, attrib.Category);
            }

            try
            {
                foreach (TestsOnAttribute2 attrib in AttributeUtils.GetAttributes <TestsOnAttribute2>(fixtureType, true))
                {
                    test.Metadata.Add(MetadataKeys.TestsOn, attrib.TestedType.AssemblyQualifiedName);
                }
            }
            catch (ReflectionResolveException)
            {
                // Ignore failures to resolve the tested type.
            }

            foreach (ImportanceAttribute2 attrib in AttributeUtils.GetAttributes <ImportanceAttribute2>(fixtureType, true))
            {
                test.Metadata.Add(MetadataKeys.Importance, attrib.Importance.ToString());
            }

            foreach (TestFixturePatternAttribute2 attrib in AttributeUtils.GetAttributes <TestFixturePatternAttribute2>(fixtureType, true))
            {
                if (!String.IsNullOrEmpty(attrib.Description))
                {
                    test.Metadata.Add(MetadataKeys.Description, attrib.Description);
                }
            }

            PopulateFixtureOrTestMetadata(test, fixtureType);
        }
コード例 #13
0
        private static void PopulateFixtureOrTestMetadata(Test test, ICodeElementInfo codeElement)
        {
            foreach (IgnoreAttribute2 attrib in AttributeUtils.GetAttributes <IgnoreAttribute2>(codeElement, true))
            {
                test.Metadata.Add(MetadataKeys.IgnoreReason, attrib.Description ?? "<unknown>");
            }

            string xmlDocumentation = codeElement.GetXmlDocumentation();

            if (xmlDocumentation != null)
            {
                test.Metadata.Add(MetadataKeys.XmlDocumentation, xmlDocumentation);
            }
        }
コード例 #14
0
ファイル: XmlStorage.cs プロジェクト: isaveu/common
        private static XmlQualifiedName[] GetQualifiedNames <T>()
        {
            var namespaceAttributes = AttributeUtils.GetAttributes <XmlNamespaceAttribute, T>();
            var qualifiedNames      = namespaceAttributes.Select(attr => attr.QualifiedName);

            var rootAttribute = AttributeUtils.GetAttributes <XmlRootAttribute, T>().FirstOrDefault();

            if (rootAttribute != null)
            {
                qualifiedNames = qualifiedNames.Concat(new[] { new XmlQualifiedName("", rootAttribute.Namespace) });
            }

            return(qualifiedNames.ToArray());
        }
コード例 #15
0
        private Test BuildAssemblyTest(Test parent, ICollection <KeyValuePair <Test, string> > unresolvedDependencies)
        {
            Test assemblyTest = new Test(assembly.Name, assembly);

            PopulateAssemblyTestMetadata(assemblyTest, assembly);

            foreach (AssemblyDependsOnAttribute2 attrib in AttributeUtils.GetAttributes <AssemblyDependsOnAttribute2>(assembly, false))
            {
                unresolvedDependencies.Add(new KeyValuePair <Test, string>(assemblyTest, attrib.AssemblyName));
            }

            parent.AddChild(assemblyTest);
            return(assemblyTest);
        }
コード例 #16
0
 private static void InitializeAssembly(IPatternScope rootScope, IAssemblyInfo assembly)
 {
     foreach (TestAssemblyInitializationAttribute attrib in AttributeUtils.GetAttributes <TestAssemblyInitializationAttribute>(assembly, false))
     {
         try
         {
             attrib.Initialize(rootScope, assembly);
         }
         catch (Exception ex)
         {
             rootScope.TestModelBuilder.PublishExceptionAsAnnotation(assembly, ex);
         }
     }
 }
コード例 #17
0
 private void BuildFixturesFromType(Test parent, ITypeInfo type)
 {
     try
     {
         foreach (TestFixturePatternAttribute2 attrib in AttributeUtils.GetAttributes <TestFixturePatternAttribute2>(type, true))
         {
             BuildTestFixtureFromPatternAttribute(parent, type, attrib);
         }
     }
     catch (Exception ex)
     {
         testModel.AddAnnotation(new Annotation(AnnotationType.Error, type,
                                                "An exception was thrown while exploring an MbUnit v2 test type.", ex));
     }
 }
コード例 #18
0
        private static void PopulateCommonMetadata(ICodeElementInfo codeElement, PropertyBag metadata)
        {
            // Add ignore reason.
            foreach (IgnoreAttribute attr in AttributeUtils.GetAttributes <IgnoreAttribute>(codeElement, true))
            {
                metadata.Add(MetadataKeys.IgnoreReason, attr.Reason ?? "<unknown>");
            }

            // Add documentation.
            string xmlDocumentation = codeElement.GetXmlDocumentation();

            if (!String.IsNullOrEmpty(xmlDocumentation))
            {
                metadata.Add(MetadataKeys.XmlDocumentation, xmlDocumentation);
            }
        }
コード例 #19
0
        private static void PopulateFixtureMetadata(ICodeElementInfo codeElement, PropertyBag metadata)
        {
            foreach (TestFixtureAttribute attr in AttributeUtils.GetAttributes <TestFixtureAttribute>(codeElement, true))
            {
                // Add categories
                string categories = attr.Categories;
                if (!String.IsNullOrEmpty(categories))
                {
                    foreach (string category in categories.Split(','))
                    {
                        metadata.Add(MetadataKeys.Category, category);
                    }
                }
            }

            PopulateCommonMetadata(codeElement, metadata);
        }
コード例 #20
0
            public override IEnumerable <EntryInfo> GetEntriesIn(TContainer container)
            {
                var pointer = _getPointer(container);

                if (pointer.Value != null)
                {
                    var description = AttributeUtils.GetAttributes <DescriptionAttribute, TProperty>().FirstOrDefault();
                    yield return(new EntryInfo(
                                     name: _name,
                                     description: description?.Description,
                                     target: pointer.Value,
                                     getEditorControl: executor => CreateEditor(container, pointer.Value, executor),
                                     toXmlString: () => pointer.Value.ToXmlString(),
                                     fromXmlString: xmlString =>
                    {
                        var newValue = XmlStorage.FromXmlString <TProperty>(xmlString);
                        return newValue.Equals(pointer.Value) ? null : new SetValueCommand <TProperty>(pointer, newValue);
                    },
                                     removeCommand: new SetValueCommand <TProperty>(pointer, null)));
                }
            }
コード例 #21
0
        private static void BuildRowTest(Test parent, IMethodInfo method, string namePrefix, string nameSuffix,
                                         RowTestAttribute2 attrib)
        {
            foreach (RowAttribute2 rowAttrib in AttributeUtils.GetAttributes <RowAttribute2>(method, true))
            {
                // Note: The way the name is formatted must be identical to that which MbUnit v2 natively produces.
                object[]     row     = rowAttrib.GetRow();
                StringWriter rowName = new StringWriter(CultureInfo.InvariantCulture);
                rowName.Write('(');
                for (int i = 0; i < row.Length; i++)
                {
                    if (i != 0)
                    {
                        rowName.Write(',');
                    }
                    rowName.Write(row[i]);
                }
                rowName.Write(')');

                AddChildTest(parent, method, namePrefix, rowName + nameSuffix);
            }
        }
コード例 #22
0
                public EntryInfo TryGetEntry(TContainer container, IList <TList> list, TList candidate)
                {
                    if (!(candidate is TElement element))
                    {
                        return(null);
                    }

                    var description = AttributeUtils.GetAttributes <DescriptionAttribute, TElement>().FirstOrDefault();

                    return(new EntryInfo(
                               name: _name,
                               description: description?.Description,
                               target: element,
                               getEditorControl: executor => CreateEditor(container, element, executor),
                               toXmlString: () => element.ToXmlString(),
                               fromXmlString: xmlString =>
                    {
                        var newValue = XmlStorage.FromXmlString <TElement>(xmlString);
                        return newValue.Equals(element) ? null : new ReplaceInList <TList>(list, element, newValue);
                    },
                               removeCommand: new RemoveFromCollection <TList>(list, element)));
                }