public IFutureValue<int> CheckIsUsed(IRepository repository, CategoryTree categoryTree)
        {
            var query = repository.AsQueryable<WidgetCategory>().Where(ec => ec.Category.CategoryTree == categoryTree
            && !ec.Widget.IsDeleted
            && (ec.Widget.Status == ContentStatus.Draft || ec.Widget.Status == ContentStatus.Published)).ToRowCountFutureValue();

            return query;
        }
 private static IQueryable<OptionModel> GetWidgetOptionsQuery(IRepository repository, Guid widgetId)
 {
     return repository
         .AsQueryable<ContentOption>(o => o.Content.Id == widgetId)
         .Select(o => new OptionModel
             {
                 Key = o.Key,
                 DefaultValue = o.DefaultValue,
                 Type = (OptionType)(int)o.Type,
                 CustomTypeIdentifier = o.CustomOption != null ? o.CustomOption.Identifier : null
             });
 }
Example #3
0
 protected override bool ExecuteWithData(string cmd, IRepository repo, Player player)
 {
     var preName = cmd.Split(new[] {' '}, 2);
     var name = preName[1].Split('=')[0].Trim();
     var destinationName = cmd.Split('=')[1].Trim();
     var destination = repo.AsQueryable<GameObject>()
         .OfType<Room>().FirstOrDefault(m => m.Name == destinationName);
     var exit = new Exit() { Name = name.Trim(), Destination = destination, Location = player.Location };
     repo.Add(exit);
     console.WriteLine("Exit created");
     return true;
 }
Example #4
0
 public Room GetMapRoom(IRepository repo)
 {
     var mapRoom = repo.AsQueryable<GameObject>().OfType<Room>().FirstOrDefault(m => m.Name == "MapRoom");
     if (mapRoom == null)
     {
         mapRoom = new Room();
         mapRoom.Name = "The Map Room";
         repo.Add(mapRoom);
         repo.UnitOfWork.SaveChanges();
     }
     return mapRoom;
 }
Example #5
0
 public Player GetPlayer(IRepository repo)
 {
     var player = repo.AsQueryable<GameObject>().OfType<Player>().FirstOrDefault();
     if (player == null)
     {
         player = new Player();
         player.Location = GetMapRoom(repo);
         player.Aliases.Add(new Tag { Value = "Me" });
         player.Aliases.Add(new Tag { Value = "Player" });
         repo.Add(player);
         repo.UnitOfWork.SaveChanges();
     }
     return player;
 }
Example #6
0
 public static IEnumerable<PageData> GetPagesToFuture(bool enableMultilanguage, IRepository repository)
 {
     return enableMultilanguage ? repository
         .AsQueryable<Root.Models.Page>()
         .Select(p => new PageData
         {
             Id = p.Id,
             Title = p.Title,
             Url = p.PageUrl,
             LanguageId = p.Language != null ? p.Language.Id : Guid.Empty,
             LanguageGroupIdentifier = p.LanguageGroupIdentifier,
             IsPublished = p.Status == PageStatus.Published
         })
         .ToFuture() : null;
 }
Example #7
0
        protected override bool ExecuteWithData(string cmd, IRepository repo, Player player)
        {
            var parameters = cmd.Split(new[] { ' ' }, 2)[1];
            bool addStatus = parameters.Contains("+=");

            string splitVal;
            if (addStatus) splitVal = "+=";
            else splitVal = "-=";

            var goName = parameters.Split(new[] { splitVal }, StringSplitOptions.None)[0];
            var statusName = parameters.Split(new[] { splitVal }, StringSplitOptions.None)[1];

            var go = queries.FindNearPlayer(repo, player, goName);
            if (go == null)
            {
                formatters.OfType<NotFoundFormatter>().First().Format(go);
                return false;
            }
            else
            {
                var alias = repo.AsQueryable<Tag>().FirstOrDefault(m => m.Value == statusName);

                if (addStatus)
                {
                    if (alias == null)
                    {
                        alias = new Tag { Value = statusName };
                        repo.Add(alias);
                        console.WriteLine("Status created.");
                    }
                    go.Statuses.Add(alias);
                    console.WriteLine("Status added.");
                }
                else
                {
                    if (alias == null)
                    {
                        console.WriteLine("That status does not exist");
                    }
                    else
                    {
                        go.Statuses.Remove(alias);
                        console.WriteLine("Status removed.");
                    }
                }
                return true;
            }
        }
Example #8
0
 public bool IsValid(string input)
 {
     string InputHolder = input;
     if  (((IsFirstWord(InputHolder, "move")) || (IsFirstWord(InputHolder, "go"))))
     {
         InputHolder = GetAllButFirstWord(input);
     }
     using (repository = repoFactory())
     {
         var pObj = repository.AsQueryable().First(qq => qq.GameObjectId == player.Id);
         var exit = pObj.Location.Inventory.Where(qq => qq.Type == "Exit").
             FirstOrDefault(qq => qq.ExitAliases.Any(ww => ww.Alais.Equals(InputHolder, StringComparison.CurrentCultureIgnoreCase))
                 || qq.Name.Equals(InputHolder, StringComparison.CurrentCultureIgnoreCase));
         return exit != null;
     }
 }
Example #9
0
        public void Execute(string input)
        {
            string Output = GetAllButFirstWord(input);

              using (repository = repoFactory())
              {
                  var pObj = repository.AsQueryable().First(qq => qq.GameObjectId == player.Id);
                  var WhichExit = pObj.Location.Inventory.FirstOrDefault(qq => (qq.Name.Equals
                      (Output, StringComparison.CurrentCultureIgnoreCase)) && qq.Type=="Exit");
                  if (WhichExit != null)
                  {
                      pObj.Location = WhichExit.DestinationLocation;
                  }
                  format.Output(pObj.Location);
              }
        }
        private static IQueryable<RegionModel> GetLayoutRegionsQuery(IRepository repository, Guid layoutId)
        {
            return repository
                .AsQueryable<LayoutRegion>(lr => lr.Layout.Id == layoutId && !lr.Layout.IsDeleted && lr.Region != null && !lr.Region.IsDeleted)
                .Select(lr => new RegionModel
                    {
                        Id = lr.Region.Id,
                        Version = lr.Region.Version,
                        CreatedBy = lr.CreatedByUser,
                        CreatedOn = lr.CreatedOn,
                        LastModifiedBy = lr.ModifiedByUser,
                        LastModifiedOn = lr.ModifiedOn,

                        RegionIdentifier = lr.Region.RegionIdentifier,
                        Description = lr.Description
                    });
        }
Example #11
0
 protected override bool ExecuteWithData(string cmd, IRepository repo, Player player)
 {
     var preName = cmd.Split(new[] { ' ' }, 2);
     var name = preName[1].Split('.')[0];
     var preOpType = preName[1].Split(new[] { '.' }, 2);
     var opType = preOpType[1].Split('=')[0];
     var fieldInput = cmd.Split('=')[1].Trim();
     var go = goQueries.GetGameObjectByNameAndPlayerLocation(repo, name, player);
     if (opType == "+" && go != null)
     {
         var fieldTag = repo.AsQueryable<Tag>().FirstOrDefault(m => m.Value == fieldInput);
         if (fieldTag == null)
         {
             fieldTag = new Tag();
             fieldTag.Value = fieldInput;
         }
         go.Aliases.Add(fieldTag);
         console.WriteLine("Alias set!");
         return true;
     }
     else
     {
         if (go == null)
         {
             console.Write("I don't recognize: ");
             console.WriteLine(name);
             return false;
         }
         else
         {
             if (opType == "-")
             {
                 var fieldTag = go.Aliases.FirstOrDefault(m => m.Value == fieldInput);
                 go.Aliases.Remove(fieldTag);
                 console.WriteLine("Alias removed!");
                 return true;
             }
             else
             {
                 console.Write("I don't recognize: ");
                 console.WriteLine(opType);
                 return false;
             }
         }
     }
 }
Example #12
0
 private static IQueryable<OptionModel> GetWidgetOptionsQuery(IRepository repository, Guid widgetId)
 {
     return repository
         .AsQueryable<ContentOption>(o => o.Content.Id == widgetId)
         .Select(o => new OptionModel
             {
                 Key = o.Key,
                 DefaultValue = o.DefaultValue,
                 Type = (OptionType)(int)o.Type,
                 CustomTypeIdentifier = o.CustomOption != null ? o.CustomOption.Identifier : null,
                 Translations = o.Translations.Select(x => new OptionTranslationModel
                 {
                     LanguageId = x.Language.Id.ToString(),
                     Value = x.Value
                 }).ToList()
             });
 }
Example #13
0
 protected override bool ExecuteWithData(string cmd, IRepository repo, Player player)
 {
     var locationName = cmd.Split(new[] { ' ' }, 2)[1];
     var location = repo.AsQueryable<GameObject>()
         .OfType<Room>().FirstOrDefault(m => m.Name == locationName);
     if (player.Location == location)
     {
         console.WriteLine("Really!? You are already there!");
         return false;
     }
     else
     {
         player.Location = location;
         console.Write("You have teleported to: ");
         console.WriteLine(player.Location.Name);
         return true;
     }
 }
        private static IQueryable<OptionValueModel> GetPageContentOptionsQuery(IRepository repository, Guid pageContentId, IOptionService optionService)
        {
            var pageContent = repository
                .AsQueryable<PageContent>()
                .Where(f => f.Id == pageContentId && !f.IsDeleted && !f.Content.IsDeleted)
                .Fetch(f => f.Content).ThenFetchMany(f => f.ContentOptions)
                .FetchMany(f => f.Options)
                .ToList()
                .FirstOne();

            return optionService
                .GetMergedOptionValuesForEdit(pageContent.Content.ContentOptions, pageContent.Options)
                .Select(o => new OptionValueModel
                    {
                        Key = o.OptionKey,
                        Value = o.OptionValue,
                        DefaultValue = o.OptionDefaultValue,
                        Type = ((Root.OptionType)(int)o.Type),
                        UseDefaultValue = o.UseDefaultValue,
                        CustomTypeIdentifier = o.CustomOption != null ? o.CustomOption.Identifier : null
                    }).AsQueryable();
        }
        /// <summary>
        /// Gets the titles for values.
        /// </summary>
        /// <param name="values">The values.</param>
        /// <param name="repository">The repository.</param>
        /// <returns>
        /// The dictionary with value - title pairs
        /// </returns>
        public Dictionary<string, string> GetTitlesForValues(string[] values, IRepository repository)
        {
            if (values == null || values.Length == 0)
            {
                return null;
            }

            var guids = new List<Guid>(values.Length);

            foreach (var value in values)
            {
                var guid = ConvertValueToCorrectType(value);
                if (guid != null)
                {
                    guids.Add((Guid)guid);
                }
            }

            Dictionary<string, string> result;
            if (guids.Count > 0)
            {
                result = repository
                    .AsQueryable<MediaFolder>()
                    .Where(a => guids.Contains(a.Id))
                    .Select(a => new { a.Id, a.Title })
                    .ToDictionary(a => a.Id.ToString(), a => a.Title);
            }
            else
            {
                result = new Dictionary<string, string>();
            }

            if (values.Any(string.IsNullOrEmpty))
            {
                result.Add(string.Empty, MediaGlobalization.RootFolder_Title);
            }

            return result;
        }
        private static IQueryable<OptionValueModel> GetPageContentOptionsQuery(IRepository repository, Guid pageContentId, IOptionService optionService)
        {
            var pageContent = repository
                .AsQueryable<PageContent>()
                .Where(f => f.Id == pageContentId && !f.IsDeleted && !f.Content.IsDeleted)
                .Fetch(f => f.Page).ThenFetch(f => f.Language)
                .Fetch(f => f.Content).ThenFetchMany(f => f.ContentOptions)
                .FetchMany(f => f.Options)
                .ToList()
                .FirstOne();

            var langId = pageContent.Page.Language != null ? pageContent.Page.Language.Id.ToString() : "";
            var mergedOptionValues = optionService.GetMergedOptionValuesForEdit(pageContent.Content.ContentOptions, pageContent.Options);

            foreach (var optionValue in mergedOptionValues)
            {
                if (optionValue.Translations != null)
                {
                    var translation = optionValue.Translations.FirstOrDefault(x => x.LanguageId == langId);
                    if (translation != null)
                    {
                        optionValue.OptionValue = optionValue.UseDefaultValue ? translation.OptionValue : optionValue.OptionValue;
                        optionValue.OptionDefaultValue = translation.OptionValue;
                    }
                }
            }

            return mergedOptionValues
                    .Select(o => new OptionValueModel
                        {
                            Key = o.OptionKey,
                            Value = o.OptionValue,
                            DefaultValue = o.OptionDefaultValue,
                            Type = ((Root.OptionType)(int)o.Type),
                            UseDefaultValue = o.UseDefaultValue,
                            CustomTypeIdentifier = o.CustomOption != null ? o.CustomOption.Identifier : null

                        }).AsQueryable();
        }
 public IFutureValue<int> CheckIsUsed(IRepository repository, CategoryTree categoryTree)
 {
     var query = repository.AsQueryable<PageCategory>().Where(p => p.Page is BlogPost && p.Category.CategoryTree == categoryTree);
     return query.ToRowCountFutureValue();
 }
Example #18
0
 public IEnumerable<IEntityCategory> QueryEntityCategories(IRepository repository, ICategory category)
 {
     return repository.AsQueryable<PageCategory>().Where(p => p.Page is BlogPost && p.Category.Id == category.Id).ToFuture();
 }
 public IEnumerable<IEntityCategory> QueryEntityCategories(IRepository repository, ICategory category)
 {
     return repository.AsQueryable<WidgetCategory>().Where(wc => wc.Category.Id == category.Id).ToFuture();
 }
 public IFutureValue<int> CheckIsUsed(IRepository repository, CategoryTree categoryTree)
 {
     return repository.AsQueryable<MediaCategory>().Where(m => m.Media is MediaFile && m.Category.CategoryTree == categoryTree && m.Media.Original == null).ToRowCountFutureValue();
 }
 public IFutureValue<int> CheckIsUsed(IRepository repository, CategoryTree categoryTree)
 {
     var query = repository.AsQueryable<MediaCategory>().Where(mc => mc.Media is MediaImage && mc.Category.CategoryTree == categoryTree && mc.Media.Original == null);
     return query.ToRowCountFutureValue();
 }
Example #22
0
 private static string[] GetUsersInRole(IRepository repository, string roleName)
 {
     return repository
         .AsQueryable<Models.UserRole>(userRole => userRole.Role.Name == roleName)
         .Select(userRole => userRole.User.UserName)
         .Distinct()
         .ToArray();
 }
Example #23
0
 private static string[] FindUsersInRole(IRepository repository, string roleName, string userNameToMatch)
 {
     return repository
         .AsQueryable<Models.UserRole>(userRole => userRole.Role.Name == roleName
             && userRole.User.UserName.Contains(userNameToMatch))
         .Select(userRole => userRole.User.UserName)
         .Distinct()
         .ToArray();
 }
Example #24
0
        private static void RemoveUsersFromRoles(IRepository repository, IUnitOfWork unitOfWork, string[] userNames, string[] roleNames)
        {
            unitOfWork.BeginTransaction();

            var distinctRoleNames = roleNames.Distinct().ToList();
            var futureQueries = new List<IEnumerable<Models.Role>>();

            foreach (var userName in userNames.Distinct())
            {
                var futureQuery = repository
                    .AsQueryable<Models.UserRole>(userRole => userRole.User.UserName == userName
                        && distinctRoleNames.Contains(userRole.Role.Name))
                    .Select(userRole => new Models.Role
                        {
                            Id = userRole.Id,
                            Version = userRole.Version
                        })
                    .ToFuture();
                
                futureQueries.Add(futureQuery);
            }

            futureQueries.ForEach(futureQuery => 
                futureQuery.ToList().ForEach(role => 
                    repository.Delete<Models.UserRole>(role.Id, role.Version)));

            unitOfWork.Commit();
        }
Example #25
0
        private static void AddUsersToRoles(IRepository repository, IUnitOfWork unitOfWork, string[] userNames, string[] roleNames)
        {
            unitOfWork.BeginTransaction();

            // Get roles future query
            var distinctRoleNames = roleNames.Distinct().ToArray();
            var roleIdsQuery = repository
                .AsQueryable<Models.Role>(role => distinctRoleNames.Contains(role.Name))
                .Select(role => new
                                    {
                                        Id = role.Id,
                                        Name = role.Name
                                    })
                .ToFuture();

            // Get users future query
            var distinctUserNames = userNames.Distinct().ToArray();
            var userIdsQuery = repository
                .AsQueryable<Models.User>(user => distinctUserNames.Contains(user.UserName))
                .Select(user => new
                                    {
                                        Id = user.Id,
                                        Name = user.UserName
                                    })
                .ToFuture();

            // Get already assigned roles
            var alreadyAssigned = repository
                .AsQueryable<Models.UserRole>(userRole => distinctUserNames.Contains(userRole.User.UserName))
                .Select(userRole => new
                                        {
                                            UserId = userRole.User.Id,
                                            RoleId = userRole.Role.Id
                                        })
                .ToFuture()
                .ToList();

            // Validate roles
            var roles = roleIdsQuery.ToList();
            roleNames
                .Where(roleName => roles.All(role => roleName != role.Name))
                .ForEach(roleName =>
                    { throw new ProviderException(string.Format("Role {0} does not exist.", roleName)); });

            // Validate users
            var users = userIdsQuery.ToList();
            userNames
                .Where(userName => users.All(user => userName != user.Name))
                .ForEach(userName =>
                    { throw new ProviderException(string.Format("User {0} does not exist.", userName)); });

            // Add users to roles
            roles
                .ForEach(role => users
                    .ForEach(user =>
                        {
                            if (!alreadyAssigned.Any(a => a.UserId == user.Id && a.RoleId == role.Id))
                            {
                                var userRole = new Models.UserRole
                                                   {
                                                       User = repository.AsProxy<Models.User>(user.Id),
                                                       Role = repository.AsProxy<Models.Role>(role.Id), 
                                                   };
                                repository.Save(userRole);
                            }
                        }));

            unitOfWork.Commit();
        }
Example #26
0
 private static bool RoleExists(IRepository repository, string roleName)
 {
     return repository
         .AsQueryable<Models.Role>(role => role.Name == roleName)
         .Select(u => u.Name)
         .FirstOrDefault() != null;
 }
Example #27
0
 private static bool IsUserInRole(IRepository repository, string username, string roleName)
 {
     return repository
         .AsQueryable<Models.User>(u => u.UserName == username
             && u.UserRoles.Any(ur => ur.Role.Name == roleName))
         .Select(u => u.UserName)
         .FirstOrDefault() != null;
 }
Example #28
0
 private static string[] GetRolesForUser(IRepository repository, string username)
 {
     return repository
         .AsQueryable<Models.UserRole>(userRole => userRole.User.UserName == username)
         .Select(userRole => userRole.Role.Name)
         .Distinct()
         .ToArray();
 }
 public IEnumerable<IEntityCategory> QueryEntityCategories(IRepository repository, ICategory category)
 {
     return repository.AsQueryable<MediaCategory>().Where(m =>  m.Media is MediaFile && m.Category.Id == category.Id).ToFuture();
 }
Example #30
0
 private static string[] GetAllRoles(IRepository repository)
 {
     return repository.AsQueryable<Models.Role>().Select(r => r.Name).ToArray();
 }