public override void Seed(IDbContext context)
        {
            var descriptor = new SPDescriptorSettings
            {
                WantAssertionsSigned = true,
                RequestSigned        = true,
                CacheDuration        = new DatepartValue {
                    Value = 100, Datepart = Datapart.Day
                },
                ValidUntil = DateTimeOffset.Now.AddDays(90),
                ErrorUrl   = "http://localhost:60879/api/Account/Error"
            };
            //role descriptor protocols
            var protocols = Seeder._cache[Seeder.ProtocolsKey] as IEnumerable <Protocol>;

            protocols.Aggregate(descriptor, (d, next) =>
            {
                next.RoleDescriptors.Add(descriptor);
                d.Protocols.Add(next);
                return(d);
            });

            //role descriptor certificates
            var certificates = Seeder._cache[Seeder.CertificatesKey] as IEnumerable <Certificate>;

            certificates.Aggregate(descriptor, (d, next) =>
            {
                d.Certificates.Add(next);
                next.RoleDescriptors.Add(descriptor);
                return(d);
            });

            var bindings        = Seeder._cache[Seeder.BindingsKey] as IEnumerable <Binding>;
            var httpPostBinding = bindings.First(x => x.Name.Equals("HTTP-POST", StringComparison.OrdinalIgnoreCase));

            descriptor.LogoutServices.Add(new EndPointSetting {
                Binding = httpPostBinding, Url = "http://localhost:60879/api/Account/SSOLogout"
            });

            //sp descriptor assertion services

            descriptor.AssertionServices.Add(new IndexedEndPointSetting
            {
                Index     = 0,
                IsDefault = true,
                Binding   = httpPostBinding,
                Url       = "http://localhost:60879/api/Account/SSOLogon"
            });

            context.Add <SPDescriptorSettings>(descriptor);
            Seeder._cache.Add(Seeder.SPDescriptorsKey, new[] { descriptor });
        }
        private static SPSSODescriptorConfiguration BuildSPSSODescriptorConfiguration(SPDescriptorSettings sPDescriptor, OrganisationConfiguration organisation)
        {
            var sPSSODescriptorConfiguration = new SPSSODescriptorConfiguration
            {
                WantAssertionsSigned         = sPDescriptor.WantAssertionsSigned,
                ValidUntil                   = sPDescriptor.ValidUntil,
                Organisation                 = organisation,
                AuthenticationRequestsSigned = sPDescriptor.RequestSigned,
                CacheDuration                = MetadataHelper.TimeSpanFromDatapartEntry(sPDescriptor.CacheDuration),
                RoleDescriptorType           = typeof(ServiceProviderSingleSignOnDescriptor),
                ErrorUrl = new Uri(sPDescriptor.ErrorUrl)
            };

            sPDescriptor.NameIdFormats.Aggregate(sPSSODescriptorConfiguration, (c, next) =>
            {
                c.NameIdentifierFormats.Add(new Uri(next.Uri));
                return(c);
            });

            //logout services
            sPDescriptor.LogoutServices.Aggregate(sPSSODescriptorConfiguration.SingleLogoutServices, (t, next) =>
            {
                t.Add(new EndPointConfiguration
                {
                    Binding  = new Uri(next.Binding.Uri),
                    Location = new Uri(next.Url)
                });
                return(t);
            });
            //supported protocols
            sPDescriptor.Protocols.Aggregate(sPSSODescriptorConfiguration.ProtocolSupported, (t, next) =>
            {
                t.Add(new Uri(next.Uri));
                return(t);
            });

            //key descriptors

            sPDescriptor.Certificates.Aggregate(sPSSODescriptorConfiguration.KeyDescriptors, (t, next) =>
            {
                var keyDescriptorConfiguration = MetadataHelper.BuildKeyDescriptorConfiguration(next);
                t.Add(keyDescriptorConfiguration);
                return(t);
            });

            //assertion service
            sPDescriptor.AssertionServices.Aggregate(sPSSODescriptorConfiguration.AssertionConsumerServices, (t, next) =>
            {
                var indexedEndPointConfiguration = new IndexedEndPointConfiguration
                {
                    Index     = next.Index,
                    IsDefault = next.IsDefault,
                    Binding   = new Uri(next.Binding.Uri),
                    Location  = new Uri(next.Url)
                };
                t.Add(indexedEndPointConfiguration);
                return(t);
            });

            return(sPSSODescriptorConfiguration);
        }