private static SelectListItem[] GetRosterSelectList( Raven.Client.IDocumentSession session, int season, string rosterId, bool bits, Func <Roster, bool> pred) { IQueryable <Roster> query = session.Query <Roster, RosterSearchTerms>() .Where(x => x.Season == season) .Where(x => x.Date < SystemTime.UtcNow) .Where(x => x.Preliminary == false); if (bits) { query = query.Where(x => x.BitsMatchId != 0); } else { query = query.Where(x => x.BitsMatchId == 0); } SelectListItem[] rosterSelectList = query.OrderBy(x => x.Date) .ToList() .Where(x => x.MatchResultId == null || string.IsNullOrEmpty(rosterId) == false) .Where(pred) .Select( x => new SelectListItem { Text = $"{x.Turn}: {x.Team} - {x.Opponent} ({x.Location} {x.Date.ToShortTimeString()})", Value = x.Id, Selected = x.Id == rosterId }) .ToArray(); return(rosterSelectList); }
public static RosterViewModel LoadRosterViewModel( this Raven.Client.IDocumentSession session, Roster roster) { HashSet <string> accepted = new(roster.AcceptedPlayers); List <RosterViewModel.PlayerItem> players = new(); foreach (Player player in roster.Players.Where(p => p != null).Select(session.Load <Player>)) { players.Add(new RosterViewModel.PlayerItem(player.Id, player.Name, accepted.Contains(player.Id))); } RosterViewModel.PlayerItem?teamLeaderTuple = null; if (roster.TeamLeader != null) { Player teamLeader = session.Load <Player>(roster.TeamLeader); teamLeaderTuple = new RosterViewModel.PlayerItem( teamLeader.Id, teamLeader.Name, accepted.Contains(teamLeader.Id)); } RosterViewModel vm = new(roster, teamLeaderTuple, players); return(vm); }
public static SelectListItem[] CreatePlayerSelectList( this Raven.Client.IDocumentSession documentSession, string player = "", Func <Player[]>?getPlayers = null, Func <Player, string>?textFormatter = null) { List <SelectListItem> playerList = new() { new SelectListItem { Text = "Välj medlem", Value = string.Empty } }; Player[] query = getPlayers != null ? getPlayers.Invoke() : documentSession.Query <Player, PlayerSearch>() .Where(x => x.PlayerStatus == Player.Status.Active) .ToArray(); SelectListItem[] players = query.OrderBy(x => x.Name) .Select(x => new SelectListItem { Text = textFormatter != null ? textFormatter.Invoke(x) : x.Name, Value = x.Id, Selected = x.Id == player }) .ToArray(); playerList.AddRange(players); return(playerList.ToArray()); }
private static void AnalyzeDirectory(DirectoryInfo directoryInfo) { foreach (var item in directoryInfo.GetFiles()) { iLoopCounter++; if (iLoopCounter == 30) { session.Dispose(); session = null; session = ravenDBStore.OpenSession(); iLoopCounter = 0; } var fileInformation = (from item1 in session.Query<FileInformation>() where item1.FileNameWithPath == item.FullName select item1).FirstOrDefault<FileInformation>(); if (fileInformation == null) { fileInformation = FileInformation.CreateFileInfo(item); Console.WriteLine("Storing {0}", fileInformation.ID); bulkInsert.Store(fileInformation); } //session.Store(fileInformation); fileCount++; } foreach (var item in directoryInfo.GetDirectories()) { folderCount++; AnalyzeDirectory(item); } }
public static SelectListItem[] CreateRosterSelectList( this Raven.Client.IDocumentSession session, int season, string rosterId = "", Func <Roster, bool>?pred = null) { return(GetRosterSelectList(session, season, rosterId, false, pred ?? (x => true))); }
public static int LatestSeasonOrDefault(this Raven.Client.IDocumentSession sess, int def) { return(sess.Query <Roster, RosterSearchTerms>() .OrderByDescending(s => s.Season) .Select(r => r.Season) .ToList() .DefaultIfEmpty(def) .First()); }
internal static void StoreToDB(ServerClientEntity entity) { using (Raven.Client.IDocumentSession session = Dem2Hub.docDB.OpenSession()) { session.Store(entity); session.SaveChanges(); } }
private static void FillInbox(Guid processId, Raven.Client.IDocumentSession session) { var newActors = Runtime.GetAllActorsForDirectCommandTransitions(processId); foreach (var newActor in newActors) { var newInboxItem = new WorkflowInbox() { IdentityId = newActor, ProcessId = processId }; session.Store(newInboxItem); } }
static void Main(string[] args) { Console.WriteLine("Starting scan.."); ravenDBConnector = new RavenDBConnector(); Console.WriteLine("Iniating db connection.."); ravenDBStore = ravenDBConnector.InitDBConnection(); Console.WriteLine("Instantiating db session"); session = ravenDBStore.OpenSession(); Console.WriteLine("Getting the Bulk Insert object"); bulkInsert = ravenDBStore.BulkInsert(); string rootStartDrive = @"C:\anddev\"; Console.WriteLine("Drive for scanning is " + rootStartDrive); DirectoryInfo directoryInfo = new DirectoryInfo(rootStartDrive); AnalyzeDirectory(directoryInfo); Console.WriteLine("Scanned {0} folders and {1} files under {2}", folderCount, fileCount,rootStartDrive); Console.ReadLine(); ravenDBConnector.DisposeConnection(); }
public static void ValidateMenu(Menu menu, string enterpriseId, Raven.Client.IDocumentSession session, Abstract.ILogger _logger) { var allProductIds = menu.Categories.SelectMany(c => c.Products); var productIds = allProductIds as string[] ?? allProductIds.ToArray(); var allProducts = session.Load <Product>(productIds); //Check if all products belongs to this enterprise foreach (var product in allProducts.Where(product => product != null && product.Enterprise != enterpriseId).ToList()) { foreach (var category in from category in menu.Categories from c in category.Products.Where(c => c == product.Id).ToList() select category) { category.Products.Remove(product.Id); } _logger.Warn("Product '{0}' belongs to enterprise: '{1}' was about to be added to '{2}' Code:[hTrsvv563]", product.Id, product.Enterprise, enterpriseId); } //Remove category if it does not have any products foreach (var category in menu.Categories.Where(category => category.Products.Count == 0).ToList()) { menu.Categories.Remove(category); } try { var productDuplicates = productIds.GroupBy(p => p.ToUpper()).SelectMany(grp => grp.Skip(1)); foreach (var productDuplicate in productDuplicates) { _logger.Warn("Duplicate in products found: {0}, Enterprise: {1}", productDuplicate, enterpriseId); } var categoryDuplicates = menu.Categories.GroupBy(c => c.Id.ToUpper()).SelectMany(grp => grp.Skip(1)); foreach (var categoryDuplicate in categoryDuplicates) { _logger.Info("Duplicate in categories found: Name: {0}, Id: {1}, Enterprise: {2}", categoryDuplicate.Name, categoryDuplicate.Id, enterpriseId); categoryDuplicate.Id = GeneralHelper.GetGuid(); } } catch (Exception ex) { _logger.Fatal("ValidateMenu, duplicate check!", ex); } }
public static bool ValidEditableEnterprise(Enterprise enterprise, Raven.Client.IDocumentSession session) { if (enterprise != null) { if (enterprise.OwnedByAccount) { //If enterprise is owned by an account, check if current account is the correct one var account = session.Load <Account>(HttpContext.Current.User.Identity.Name); return((account.Enterprises.Contains(enterprise.Id) || account.IsAdmin) && account.Enabled); } //Add product to a new enterprise if (enterprise.IsNew) { return(true); } //Add product to an enterprise in edit-mode if (!enterprise.LockedFromEdit) { return(true); } } return(false); }
public RavenDBServer(string Url, string Database) { docStore = new Raven.Client.Document.DocumentStore() { Url = Url, DefaultDatabase = "Keys" }; docStore.Initialize(); session = docStore.OpenSession(); }
public static User FindUserByEmail(this Raven.Client.IDocumentSession sess, string email) { return(sess.Query <User, User_ByEmail>() .FirstOrDefault(u => u.Email == email)); }
public static TResult LoadEx <TResult>(this Raven.Client.IDocumentSession session, string key) { return(session.Load <TResult>(key) ?? throw new Exception($"No entity with key '{key}' found")); }
public static User FindUserByActivationKey(this Raven.Client.IDocumentSession sess, string key) { return(sess.Query <User>() .FirstOrDefault(u => u.ActivationKey == key)); }