Example #1
0
        protected override void OnActivate()
        {
            WorkStarted("fetching collections");

            var currentActiveCollection = ActiveCollection;

            using (var session = server.OpenSession())
            {
                session.Advanced.AsyncDatabaseCommands
                .GetCollectionsAsync(0, 25)
                .ContinueWith(
                    x =>
                {
                    WorkCompleted("fetching collections");

                    Collections = x.Result;
                    NotifyOfPropertyChange(() => LargestCollectionCount);
                    NotifyOfPropertyChange(() => Collections);

                    ActiveCollection = currentActiveCollection ?? Collections.FirstOrDefault();
                    NotifyOfPropertyChange(() => HasCollections);

                    Status = Collections.Any() ? string.Empty : "The database contains no collections.";
                },
                    faulted =>
                {
                    WorkCompleted("fetching collections");
                    var error = "Unable to retrieve collections from server.";
                    Status    = error;
                    NotifyError(error);
                });
            }
        }
Example #2
0
 public void AddCollection(Collections.CollectionMapping collection)
 {
     if (Collections.Any(x => x.Name == collection.Name))
     {
         throw new InvalidOperationException("Tried to add collection '" + collection.Name + "' when already added.");
     }
     AddMapping(collection, MappingType.Collection);
 }
Example #3
0
 /// <summary>
 /// Adds a collection to the database.
 /// </summary>
 public void AddCollection(string collectionName)
 {
     if (Collections.Any(collection => collection.Name == collectionName))
     {
         throw new ArgumentException("Duplicate collection name.");
     }
     Collections.Add(new CollectionModel(Parent, this, collectionName));
 }
Example #4
0
 public bool IsUnique(string alias)
 {
     return(!Collections.Any(col => col.Alias == alias));
 }
Example #5
0
 bool ICollectionConfig.IsUnique(string alias)
 {
     return(!Collections.Any(col => col.Alias == alias));
 }
Example #6
0
        public override void AddRoutesTo(RouteCollection routeCollection)
        {
            _resourcesMapper.SetResourceAs(MappedName ?? ResourceName);

            var routes = new List <Route>();

            if (Collections != null && Collections.Any())
            {
                foreach (var member in Collections)
                {
                    routes.Add(_resourcesMapper.CollectionRoute(member.Key, member.Value));
                }
            }

            if (IncludesAction(names.IndexName))
            {
                routes.Add(_resourcesMapper.IndexRoute());
            }

            if (IncludesAction(names.CreateName))
            {
                routes.Add(_resourcesMapper.CreateRoute());
            }

            if (IncludesAction(names.NewName))
            {
                routes.Add(_resourcesMapper.NewRoute());
            }

            if (IncludesAction(names.EditName))
            {
                routes.Add(_resourcesMapper.EditRoute());
            }

            if (IncludesAction(names.ShowName))
            {
                routes.Add(_resourcesMapper.ShowRoute());
            }

            if (IncludesAction(names.UpdateName))
            {
                routes.Add(_resourcesMapper.UpdateRoute());
            }

            if (IncludesAction(names.DestroyName))
            {
                routes.Add(_resourcesMapper.DestroyRoute());
            }

            if (Members != null && Members.Any())
            {
                foreach (var member in Members)
                {
                    routes.Add(_resourcesMapper.MemberRoute(member.Key, member.Value));
                }
            }

            foreach (var route in routes)
            {
                ConfigureRoute(route);
                routeCollection.Add(route);
            }

            var newConstraints = Context.Constraints;

            if (newConstraints.ContainsKey("id"))
            {
                var idConstraint = newConstraints.FirstOrDefault(x => x.Key == "id");

                newConstraints.Remove("id");

                newConstraints[RouteSet.Singularize(_resourcesMapper.ResourceName) + "Id"] = idConstraint.Value;
            }

            foreach (var mapping in Mappings)
            {
                mapping.Context.Constraints = newConstraints;

                mapping.AddRoutesTo(routeCollection);
            }
        }