Пример #1
0
 /// <summary>
 /// Verifies whether or not the specified extension type exists in the extension collection. If not found, an instance of the <see cref="CloudApplicationException"/>
 /// will be thrown.
 /// </summary>
 /// <typeparam name="T">The type of the extension. Must implement <see cref="System.ServiceModel.IExtension&lt;T&gt;"/> as prescribed by the extension model.</typeparam>
 /// <param name="collection">The instance of the object implementing the <see cref="System.ServiceModel.IExtensionCollection&lt;T&gt;"/> interface.</param>
 public static void Demand <T>(this IExtensionCollection <IExtensibleCloudServiceComponent> collection) where T : ICloudServiceComponentExtension
 {
     if (null == collection || null == collection.Find <T>())
     {
         throw new CloudApplicationException(String.Format(CultureInfo.CurrentCulture, ExceptionMessages.ExtensionObjectNotFound, typeof(T).Name));
     }
 }
Пример #2
0
        public void T2_Tests()
        {
            IExtensionCollection <GraphObject, IExtension <GraphObject> > exts = _context.Extensions;

            ArborNode node = new ArborNode("");

            exts.Add(node);

            Assert.IsTrue(exts.Contains(node));
            Assert.AreEqual(1, exts.Count);

            IExtension <GraphObject> xt = exts.Find <ArborNode>();

            Assert.IsNotNull(xt);
            Assert.IsTrue(xt is ArborNode);
            Assert.AreEqual(node, xt);

            //

            Assert.IsTrue(exts.Remove(node));
            Assert.IsFalse(exts.Contains(node));
            Assert.AreEqual(0, exts.Count);

            //

            exts.Add(node);
            ArborNode node1 = new ArborNode("");

            exts.Add(node1);

            Assert.IsTrue(exts.Contains(node));
            Assert.IsTrue(exts.Contains(node1));
            Assert.AreEqual(2, exts.Count);

            Collection <ArborNode> cols = exts.FindAll <ArborNode>();

            Assert.AreEqual(2, cols.Count);

            Assert.IsTrue(exts.Remove(node));
            Assert.IsFalse(exts.Contains(node));
            Assert.IsTrue(exts.Contains(node1));
            Assert.AreEqual(1, exts.Count);

            //

            exts.Add(node); // adding second node, but internal array was length=2

            //

            exts.Clear();
            Assert.AreEqual(0, exts.Count);

            //

            Assert.IsFalse(exts.Remove(null));
            Assert.Throws(typeof(ArgumentNullException), () => { exts.Add(null); });
            Assert.Throws(typeof(ArgumentNullException), () => { new ExtensionCollection <GraphObject, IExtension <GraphObject> >(null); });
        }
        protected override ITypeConfiguration Create(TypeInfo parameter)
        {
            var property = new TypeProperty <string>(_names, parameter);
            var root     = _extensions.Find <RootContextExtension>()
                           .Root;
            var result = Source.Default
                         .Get(parameter)
                         .Invoke(root, property);

            return(result);
        }
Пример #4
0
        private WcfOperationContextStorageExtension <T> GetWcfStorageExtension()
        {
            Fail.IfNull(OperationContext.Current, "There is no WCF " + nameof(OperationContext) + " available");

            IExtensionCollection <OperationContext> extensions = OperationContext.Current.Extensions;
            var instance = extensions.Find <WcfOperationContextStorageExtension <T> >();

            if (instance == null)
            {
                instance = new WcfOperationContextStorageExtension <T>();
                extensions.Add(instance);
            }

            return(instance);
        }
 public TypeConfigurations(IExtensionCollection extensions)
     : this(extensions, extensions.Find <TypeNamesExtension>()
            .Names, new ConcurrentDictionary <TypeInfo, ITypeConfiguration>())
 {
 }
 T IExtensionCollection.Find <T>() => _extensions.Find <T>();