public void SortedArrayKeyList_without_duplicates()
        {
            var a = new CKSortedArrayKeyList <int, string>(i => i.ToString());

            a.AddRangeArray(3, 2, 1);

            bool exists;

            Assert.That(a.GetByKey("1", out exists) == 1 && exists);
            Assert.That(a.GetByKey("10", out exists) == 0 && !exists);
            Assert.That(a.GetByKey("2", out exists) == 2 && exists);

            Assert.That(a.Contains("2"));
            Assert.That(a.Contains("1"));
            Assert.That(!a.Contains("21"));

            object o;

            o = "2";
            Assert.That(a.Contains(o), "Using the key.");
            o = 2;
            Assert.That(a.Contains(o), "Using the value itself.");
            o = null;
            Assert.That(a.Contains(o), Is.False);
            o = 42;
            Assert.That(a.Contains(o), Is.False);
            o = "42";
            Assert.That(a.Contains(o), Is.False);

            Assert.That(!a.Add(3));
            Assert.That(!a.Add(2));
            Assert.That(!a.Add(1));

            CheckList(a.GetAllByKey("2"), 2);
        }
示例#2
0
        public void SortedArrayKeyList_without_duplicates()
        {
            var a = new CKSortedArrayKeyList <int, string>(i => i.ToString());

            a.AddRangeArray(3, 2, 1);

            bool exists;

            a.GetByKey("1", out exists).Should().Be(1); exists.Should().BeTrue();
            a.GetByKey("10", out exists).Should().Be(0); exists.Should().BeFalse();
            a.GetByKey("2", out exists).Should().Be(2); exists.Should().BeTrue();

            a.Contains("2").Should().BeTrue();
            a.Contains("1").Should().BeTrue();
            a.Contains("21").Should().BeFalse();

            object o;

            o = "2";
            a.Contains(o).Should().BeTrue("Using the key.");
            o = 2;
            a.Contains(o).Should().BeTrue("Using the value itself.");
            o = null;
            a.Contains(o).Should().BeFalse();
            o = 42;
            a.Contains(o).Should().BeFalse();
            o = "42";
            a.Contains(o).Should().BeFalse();

            a.Add(3).Should().BeFalse();
            a.Add(2).Should().BeFalse();
            a.Add(1).Should().BeFalse();

            CheckList(a.GetAllByKey("2"), 2);
        }
        public void another_test_with_duplicates_in_SortedArrayKeyList()
        {
            var a = new CKSortedArrayKeyList <int, string>(i => (i % 100).ToString(), true);

            a.AddRangeArray(2, 1);

            bool exists;

            Assert.That(a.GetByKey("1", out exists) == 1 && exists);
            Assert.That(a.GetByKey("2", out exists) == 2 && exists);

            Assert.That(a.Add(102));
            Assert.That(a.Add(101));

            int v1 = a.GetByKey("1");

            Assert.That(v1, Is.EqualTo(1).Or.EqualTo(101), "It is one or the other that is returned.");
            int v2 = a.GetByKey("2");

            Assert.That(v2, Is.EqualTo(2).Or.EqualTo(102), "It is one or the other that is returned.");

            Assert.That(a.KeyCount("2") == 2);
            CheckList(a.GetAllByKey("2").OrderBy(Util.FuncIdentity), 2, 102);

            Assert.That(a.Add(102));
            Assert.That(a.Add(102));
            Assert.That(a.Add(102));
            Assert.That(a.Add(202));
            Assert.That(a.Add(302));

            Assert.That(a.KeyCount("2") == 7);
            CheckList(a.GetAllByKey("2").OrderBy(Util.FuncIdentity), 2, 102, 102, 102, 102, 202, 302);

            Assert.That(a.KeyCount("5454") == 0);
            Assert.That(a.GetAllByKey("5454"), Is.Empty);
        }
示例#4
0
        public void another_test_with_duplicates_in_SortedArrayKeyList()
        {
            var a = new CKSortedArrayKeyList <int, string>(i => (i % 100).ToString(), true);

            a.AddRangeArray(2, 1);

            bool exists;

            a.GetByKey("1", out exists).Should().Be(1); exists.Should().BeTrue();
            a.GetByKey("2", out exists).Should().Be(2); exists.Should().BeTrue();

            a.Add(102);
            a.Add(101);

            int v1 = a.GetByKey("1");

            v1.Should().BeOneOf(new[] { 1, 101 }, "It is one or the other that is returned.");
            int v2 = a.GetByKey("2");

            v2.Should().BeOneOf(new[] { 2, 102 }, "It is one or the other that is returned.");

            a.KeyCount("2").Should().Be(2);
            CheckList(a.GetAllByKey("2").OrderBy(Util.FuncIdentity), 2, 102);

            a.Add(102);
            a.Add(102);
            a.Add(102);
            a.Add(202);
            a.Add(302);

            a.KeyCount("2").Should().Be(7);
            CheckList(a.GetAllByKey("2").OrderBy(Util.FuncIdentity), 2, 102, 102, 102, 102, 202, 302);

            a.KeyCount("5454").Should().Be(0);
            a.GetAllByKey("5454").Should().BeEmpty();
        }
示例#5
0
 /// <summary>
 /// Gets the final configuration status for a given service or plugin ID.
 /// </summary>
 /// <param name="serviceOrPluginFullName">Service or plugin ID to check.</param>
 /// <returns>The status of the item, or Optional if the item does not exist.</returns>
 public ConfigurationStatus GetStatus(string serviceOrPluginFullName)
 {
     Debug.Assert(ConfigurationStatus.Optional == 0);
     return(_items.GetByKey(serviceOrPluginFullName).Status);
 }
示例#6
0
        private static void ReadPlugin(XmlReader r, DiscoveredInfo d,
                                       CKSortedArrayKeyList <ServiceInfo, string> loadedServices,
                                       CKSortedArrayKeyList <PluginInfo, string> loadedPlugins,
                                       List <PendingPluginService> pendingPluginServices,
                                       List <PendingServiceReference> pendingServiceReferences
                                       )
        {
            r.Read();

            string pluginFullName  = String.Empty;
            string serviceFullName = null;

            List <Tuple <string, DependencyRequirement> > references = new List <Tuple <string, DependencyRequirement> >();

            while (r.Read())
            {
                if (r.IsStartElement() && !r.IsEmptyElement)
                {
                    switch (r.Name)
                    {
                    case "FullName":
                        if (r.Read())
                        {
                            pluginFullName = r.Value;
                        }
                        break;

                    case "Service":
                        if (r.Read())
                        {
                            serviceFullName = r.Value;
                        }
                        break;

                    case "ServiceReferences":
                        while (r.Read())
                        {
                            if (r.IsStartElement() && r.Name == "ServiceReference")
                            {
                                string serviceFullName2 = r.GetAttribute("Service");
                                if (!String.IsNullOrEmpty(serviceFullName2))
                                {
                                    DependencyRequirement requirement = (DependencyRequirement)Enum.Parse(typeof(DependencyRequirement), r.GetAttribute("Requirement"));

                                    references.Add(Tuple.Create(serviceFullName2, requirement));
                                }
                            }
                        }
                        break;
                    }
                }
            }


            PluginInfo p = new PluginInfo(pluginFullName, d.DefaultAssembly);

            d.PluginInfos.Add(p);
            loadedPlugins.Add(p);

            if (!String.IsNullOrEmpty(serviceFullName))
            {
                if (loadedServices.Contains(serviceFullName))
                {
                    var service = loadedServices.GetByKey(serviceFullName);
                    p.Service = service;
                }
                else
                {
                    pendingPluginServices.Add(new PendingPluginService(p, serviceFullName));
                }
            }

            foreach (var t in references)
            {
                if (loadedServices.Contains(t.Item1))
                {
                    p.AddServiceReference(loadedServices.GetByKey(t.Item1), t.Item2);
                }
                else
                {
                    pendingServiceReferences.Add(new PendingServiceReference(p, t.Item1, t.Item2));
                }
            }
        }
示例#7
0
        private static void ReadService(XmlReader r, DiscoveredInfo d,
                                        CKSortedArrayKeyList <ServiceInfo, string> loadedServices,
                                        CKSortedArrayKeyList <PluginInfo, string> loadedPlugins,
                                        List <PendingGeneralization> pendingGeneralizations,
                                        List <PendingPluginService> pendingPluginServices,
                                        List <PendingServiceReference> pendingServiceReferences
                                        )
        {
            r.Read();
            string serviceFullName = r.GetAttribute("FullName");

            Debug.Assert(serviceFullName != null, "FullName attribute was found in Service XML element.");

            var s = new ServiceInfo(serviceFullName, d.DefaultAssembly);

            d.ServiceInfos.Add(s);
            loadedServices.Add(s);

            ServiceInfo generalization = null;

            while (r.Read())
            {
                if (r.IsStartElement() && !r.IsEmptyElement)
                {
                    if (r.Name == "Generalization")
                    {
                        if (r.Read())
                        {
                            string generalizationName = r.Value;
                            if (!String.IsNullOrEmpty(generalizationName))
                            {
                                if (loadedServices.Contains(generalizationName))
                                {
                                    generalization   = loadedServices.GetByKey(generalizationName);
                                    s.Generalization = generalization;
                                }
                                else
                                {
                                    pendingGeneralizations.Add(new PendingGeneralization(s, generalizationName));
                                }
                            }
                        }
                    }
                }
            }

            // Fix pending references of this service
            foreach (var pg in pendingGeneralizations.Where(x => x.PendingServiceFullName == serviceFullName).ToList())
            {
                pg.Service.Generalization = s;
                pendingGeneralizations.Remove(pg);
            }

            foreach (var pps in pendingPluginServices.Where(x => x.PendingServiceFullName == serviceFullName).ToList())
            {
                pps.Plugin.Service = s;
                pendingPluginServices.Remove(pps);
            }

            foreach (var psr in pendingServiceReferences.Where(x => x.PendingServiceFullName == serviceFullName).ToList())
            {
                psr.Plugin.AddServiceReference(s, psr.Requirement);
                pendingServiceReferences.Remove(psr);
            }
        }
示例#8
0
        private static void ReadService( XmlReader r, DiscoveredInfo d,
            CKSortedArrayKeyList<ServiceInfo, string> loadedServices,
            CKSortedArrayKeyList<PluginInfo, string> loadedPlugins,
            List<PendingGeneralization> pendingGeneralizations,
            List<PendingPluginService> pendingPluginServices,
            List<PendingServiceReference> pendingServiceReferences
            )
        {
            r.Read();
            string serviceFullName = r.GetAttribute( "FullName" );
            Debug.Assert( serviceFullName != null, "FullName attribute was found in Service XML element." );

            var s = new ServiceInfo( serviceFullName, d.DefaultAssembly );
            d.ServiceInfos.Add( s );
            loadedServices.Add( s );

            ServiceInfo generalization = null;

            while( r.Read() )
            {
                if( r.IsStartElement() && !r.IsEmptyElement )
                {
                    if( r.Name == "Generalization" )
                    {
                        if( r.Read() )
                        {
                            string generalizationName = r.Value;
                            if( !String.IsNullOrEmpty( generalizationName ) )
                            {
                                if( loadedServices.Contains( generalizationName ) )
                                {
                                    generalization = loadedServices.GetByKey( generalizationName );
                                    s.Generalization = generalization;
                                }
                                else
                                {
                                    pendingGeneralizations.Add( new PendingGeneralization( s, generalizationName ) );
                                }
                            }
                        }
                    }
                }
            }

            // Fix pending references of this service
            foreach( var pg in pendingGeneralizations.Where( x => x.PendingServiceFullName == serviceFullName ).ToList() )
            {
                pg.Service.Generalization = s;
                pendingGeneralizations.Remove( pg );
            }

            foreach( var pps in pendingPluginServices.Where( x => x.PendingServiceFullName == serviceFullName ).ToList() )
            {
                pps.Plugin.Service = s;
                pendingPluginServices.Remove( pps );
            }

            foreach( var psr in pendingServiceReferences.Where( x => x.PendingServiceFullName == serviceFullName ).ToList() )
            {
                psr.Plugin.AddServiceReference( s, psr.Requirement );
                pendingServiceReferences.Remove( psr );
            }
        }
示例#9
0
        private static void ReadPlugin( XmlReader r, DiscoveredInfo d,
            CKSortedArrayKeyList<ServiceInfo, string> loadedServices,
            CKSortedArrayKeyList<PluginInfo, string> loadedPlugins,
            List<PendingPluginService> pendingPluginServices,
            List<PendingServiceReference> pendingServiceReferences
            )
        {
            r.Read();

            string pluginFullName = String.Empty;
            string serviceFullName = null;

            List<Tuple<string,DependencyRequirement>> references = new List<Tuple<string, DependencyRequirement>>();

            while( r.Read() )
            {
                if( r.IsStartElement() && !r.IsEmptyElement )
                {
                    switch( r.Name )
                    {
                        case "FullName":
                            if( r.Read() )
                            {
                                pluginFullName = r.Value;
                            }
                            break;
                        case "Service":
                            if( r.Read() )
                            {
                                serviceFullName = r.Value;
                            }
                            break;
                        case "ServiceReferences":
                            while( r.Read() )
                            {
                                if( r.IsStartElement() && r.Name == "ServiceReference" )
                                {
                                    string serviceFullName2 = r.GetAttribute( "Service" );
                                    if( !String.IsNullOrEmpty( serviceFullName2 ) )
                                    {
                                        DependencyRequirement requirement = (DependencyRequirement)Enum.Parse( typeof( DependencyRequirement ), r.GetAttribute( "Requirement" ) );

                                        references.Add( Tuple.Create( serviceFullName2, requirement ) );

                                    }
                                }
                            }
                            break;
                    }
                }
            }

            PluginInfo p = new PluginInfo( pluginFullName, d.DefaultAssembly );
            d.PluginInfos.Add( p );
            loadedPlugins.Add( p );

            if( !String.IsNullOrEmpty( serviceFullName ) )
            {
                if( loadedServices.Contains( serviceFullName ) )
                {
                    var service = loadedServices.GetByKey( serviceFullName );
                    p.Service = service;
                }
                else
                {
                    pendingPluginServices.Add( new PendingPluginService( p, serviceFullName ) );
                }
            }

            foreach( var t in references )
            {

                if( loadedServices.Contains( t.Item1 ) )
                {
                    p.AddServiceReference( loadedServices.GetByKey( t.Item1 ), t.Item2 );
                }
                else
                {
                    pendingServiceReferences.Add( new PendingServiceReference( p, t.Item1, t.Item2 ) );
                }
            }
        }
示例#10
0
        private void ReadService(XmlReader r)
        {
            r.Read();
            string serviceFullName = r.GetAttribute("FullName");

            Debug.Assert(serviceFullName != null, "FullName attribute was found in Service XML element.");

            ServiceInfo s = new ServiceInfo(serviceFullName, AssemblyInfoHelper.ExecutingAssemblyInfo);

            loadedServices.Add(s);

            ServiceInfo generalization = null;

            Point pos = new Point();

            pos.X = Double.NaN;
            pos.Y = Double.NaN;

            while (r.Read())
            {
                if (r.IsStartElement() && !r.IsEmptyElement)
                {
                    switch (r.Name)
                    {
                    case "Generalization":
                        if (r.Read())
                        {
                            string generalizationName = r.Value;
                            if (!String.IsNullOrEmpty(generalizationName))
                            {
                                if (loadedServices.Contains(generalizationName))
                                {
                                    generalization   = loadedServices.GetByKey(generalizationName);
                                    s.Generalization = generalization;
                                }
                                else
                                {
                                    pendingGeneralizations.Add(new PendingGeneralization(s, generalizationName));
                                }
                            }
                        }
                        break;

                    case "X":
                        if (r.Read())
                        {
                            double posX;
                            if (Double.TryParse(r.Value, NumberStyles.Any, CultureInfo.InvariantCulture, out posX))
                            {
                                pos.X = posX;
                            }
                        }
                        break;

                    case "Y":
                        if (r.Read())
                        {
                            double posY;
                            if (Double.TryParse(r.Value, NumberStyles.Any, CultureInfo.InvariantCulture, out posY))
                            {
                                pos.Y = posY;
                            }
                        }
                        break;
                    }
                }
            }

            s.PositionInGraph = pos;

            // Fix pending references of this service
            foreach (var pg in pendingGeneralizations.Where(x => x.PendingServiceFullName == serviceFullName).ToList())
            {
                pg.Service.Generalization = s;
                pendingGeneralizations.Remove(pg);
            }

            foreach (var pps in pendingPluginServices.Where(x => x.PendingServiceFullName == serviceFullName).ToList())
            {
                pps.Plugin.Service = s;
                s.InternalImplementations.Add(pps.Plugin);
                pendingPluginServices.Remove(pps);
            }

            foreach (var psr in pendingServiceReferences.Where(x => x.PendingServiceFullName == serviceFullName).ToList())
            {
                var reference = new MockServiceReferenceInfo(psr.Plugin, s, psr.Requirement);
                psr.Plugin.InternalServiceReferences.Add(reference);
                pendingServiceReferences.Remove(psr);
            }
        }
        public void another_test_with_duplicates_in_SortedArrayKeyList()
        {
            var a = new CKSortedArrayKeyList<int, string>( i => (i%100).ToString(), true );
            a.AddRangeArray( 2, 1 );

            bool exists;
            Assert.That( a.GetByKey( "1", out exists ) == 1 && exists );
            Assert.That( a.GetByKey( "2", out exists ) == 2 && exists );

            Assert.That( a.Add( 102 ) );
            Assert.That( a.Add( 101 ) );
            
            int v1 = a.GetByKey( "1" );
            Assert.That( v1, Is.EqualTo( 1 ).Or.EqualTo( 101 ), "It is one or the other that is returned." );
            int v2 = a.GetByKey( "2" );
            Assert.That( v2, Is.EqualTo( 2 ).Or.EqualTo( 102 ), "It is one or the other that is returned." );

            Assert.That( a.KeyCount( "2" ) == 2 );
            CheckList( a.GetAllByKey( "2" ).OrderBy( Util.FuncIdentity ), 2, 102 );

            Assert.That( a.Add( 102 ) );
            Assert.That( a.Add( 102 ) );
            Assert.That( a.Add( 102 ) );
            Assert.That( a.Add( 202 ) );
            Assert.That( a.Add( 302 ) );

            Assert.That( a.KeyCount( "2" ) == 7 );
            CheckList( a.GetAllByKey( "2" ).OrderBy( Util.FuncIdentity ), 2, 102, 102, 102, 102, 202, 302 );

            Assert.That( a.KeyCount( "5454" ) == 0 );
            Assert.That( a.GetAllByKey( "5454" ), Is.Empty );

        }
        public void SortedArrayKeyList_without_duplicates()
        {
            var a = new CKSortedArrayKeyList<int, string>( i => i.ToString() );
            a.AddRangeArray( 3, 2, 1 );

            bool exists;
            Assert.That( a.GetByKey( "1", out exists ) == 1 && exists );
            Assert.That( a.GetByKey( "10", out exists ) == 0 && !exists );
            Assert.That( a.GetByKey( "2", out exists ) == 2 && exists );

            Assert.That( a.Contains( "2" ) );
            Assert.That( a.Contains( "1" ) );
            Assert.That( !a.Contains( "21" ) );

            object o;
            o = "2";
            Assert.That( a.Contains( o ), "Using the key." );
            o = 2;
            Assert.That( a.Contains( o ), "Using the value itself." ); 
            o = null;
            Assert.That( a.Contains( o ), Is.False );
            o = 42;
            Assert.That( a.Contains( o ), Is.False );
            o = "42";
            Assert.That( a.Contains( o ), Is.False );

            Assert.That( !a.Add( 3 ) );
            Assert.That( !a.Add( 2 ) );
            Assert.That( !a.Add( 1 ) );

            CheckList( a.GetAllByKey( "2" ), 2 );
        }