public void MoveMapToFolder(string mapToMoveId, string moveToFolderId) { Map mapToMove = _mapDataManager.GetMapById(new ObjectId(mapToMoveId)); MapFolder moveToFolder = _mapFolderDataManager.GetMapFolderById(new ObjectId(moveToFolderId)); MapFolder oldPrevFolder = null; string userIdAsString = User.Identity.GetUserId(); ObjectId userObjectID = new ObjectId(userIdAsString); var allFoldersOfUser = _mapFolderDataManager.GetAllMapFoldersOfUser(userObjectID); var allFolderOwnedByUsr = new List <MapFolder>(); foreach (var folder in allFoldersOfUser) { if (folder.Permissions.Owner.Key.ToString().Equals(userObjectID.ToString()) && !folder.Model["type"].Equals(SharedCodedData.SHARED_SUPIRIOR)) { if (folder.idOfMapsInFolder.Contains(mapToMove.Id)) { oldPrevFolder = folder; break; } } } if (oldPrevFolder.Id.Equals(moveToFolder.Id)) { return; } oldPrevFolder.idOfMapsInFolder.Remove(mapToMove.Id); moveToFolder.idOfMapsInFolder.Add(mapToMove.Id); _mapDataManager.UpdateMap(mapToMove); _mapFolderDataManager.UpdateMapFolder(moveToFolder); _mapFolderDataManager.UpdateMapFolder(oldPrevFolder); }
public MapFolder GetParent(MapFolder folder) { var newPath = new List <int>(folder.FolderPath); newPath.PopEnd(); return(GetFolderByPath(newPath)); }
public void deleteFolder(string currFolder) { MapFolderDB folderManeger = new MapFolderDB(new Settings()); ObjectId currFolderID = new ObjectId(currFolder); MapFolder currentFolder = folderManeger.GetMapFolderById(currFolderID); try { foreach (ObjectId idOfSubFolder in currentFolder.idOfSubFolders) { deleteFolder(idOfSubFolder.ToString()); } } catch { } ObjectId prevFolderID = currentFolder.ParentDierctory; MapFolder prevFolder = folderManeger.GetMapFolderById(prevFolderID); foreach (ObjectId objID in prevFolder.idOfSubFolders) { if (currFolderID.Equals(objID)) { currFolderID = objID; } } prevFolder.idOfSubFolders.Remove(currFolderID); folderManeger.UpdateMapFolder(prevFolder); folderManeger.RemoveMapFolderById(currFolderID); ViewBag.go2 = prevFolderID.ToString(); }
public MapFolder GetFolderByPath(IEnumerable <int> folderPath) { MapFolder folder = RootFolder; if (folder == null) { RootFolder = new MapFolder(); RootFolder.Maps = new ObservableCollection <MapStub>(); folder = RootFolder; } List <int> searchPath = new List <int>(); if (folderPath != null) { searchPath = new List <int>(folderPath); searchPath.PopFront(); } while (searchPath.Count > 0) { int next = searchPath.PopFront(); MapFolder nextFolder = folder.Folders.FirstOrDefault((x) => (x.Id == next)); if (nextFolder == null) { break; } folder = nextFolder; } return(folder); }
/** public ActionResult createFolder(MapFolder parent) * { * var id = User.Identity.GetUserId(); * ObjectId UserId = new ObjectId(id); * MapFolder toadd = new MapFolder(); * toadd.Creator = UserId; * }**/ public ActionResult MyFirstMapAndFolders() { try { var id = User.Identity.GetUserId(); ObjectId UserId = new ObjectId(id); MapFolder superiorMapFolder = _mapFolderDataManager.GetSuperiorMapFolderOfUserOwned(UserId); if (superiorMapFolder == null) { // superiorMapFolder = createSuppFolderLocaly(OWNED_SUPIRIOR); _mapFolderDataManager.AddFolder(superiorMapFolder); } var mapFolders = this._mapFolderDataManager.GetAllSubFolder(superiorMapFolder); //var mapFolders = this._mapFolderDataManager.GetFirstFoldersOfUser(UserId); var maps = this._mapFolderDataManager.GetAllMapsInFolder(superiorMapFolder); _mapDataManager = new MapDB(new Settings()); ViewBag.maps = maps; ViewBag.currFolder = superiorMapFolder; return(PartialView("_MyFoldersView", mapFolders)); } catch (Exception e) { string exp = e.ToString(); //return RedirectToAction("Index", "Home"); _mapDataManager = new MapDB(new Settings()); ViewBag.maps = _mapDataManager.GetAllMaps(); return(PartialView("_MyFoldersView", new List <MapFolder>())); } }
public GameMap CreateMap(String name, MapFolder folder) { FileInfo file = new FileInfo(name); int newId = Id++; String filename = GetMapFileName(newId, name); file.CopyTo(filename, true); if (folder.FolderPath == null && folder.Id == 0) { folder.FolderPath = new ObservableCollection <int>() { 0 }; } GameMap map = new GameMap(newId, filename, file.Name.Substring(0, file.Name.Length - file.Extension.Length), new List <int>(folder.FolderPath)); MapStub stub = new MapStub(map); CurrentFolder.Maps.Add(stub); map.CanSave = true; map.SaveMap(true); return(map); }
public void addNewFolder(string parentID, string folderName, string folderDescription) { MapFolderDB folderManeger = new MapFolderDB(new Settings()); var id = User.Identity.GetUserId(); ObjectId UserId = new ObjectId(id); if (parentID == null || parentID.Equals("")) { parentID = folderManeger.GetSuperiorMapFolderOfUser(UserId).Id.ToString(); } _mapFolderDataManager = new MapFolderDB(new Settings()); MapPermissions mapPermissions = new MapPermissions(); mapPermissions.Owner = new KeyValuePair <ObjectId, MapPermissionType>(UserId, MapPermissionType.RW); mapPermissions.Users = new Dictionary <ObjectId, MapPermissionType>(); mapPermissions.Groups = new Dictionary <ObjectId, MapPermissionType>(); mapPermissions.AllUsers = MapPermissionType.NA; mapPermissions.Users.Add(UserId, MapPermissionType.RW); MapFolder folder = new MapFolder(); folder.Name = folderName; folder.Creator = UserId; folder.CreationTime = DateTime.Now; folder.Description = folderDescription; folder.Followers = new HashSet <ObjectId>(); folder.Permissions = mapPermissions; folder.idOfMapsInFolder = new HashSet <ObjectId>(); folder.idOfSubFolders = new HashSet <ObjectId>(); folder.ParentDierctory = new ObjectId(parentID); MapFolder parentFolder = folderManeger.GetMapFolderById(folder.ParentDierctory); string path = parentFolder.Model["path"].ToString(); if (path.Equals("")) { path = parentFolder.Name; } else { path = path + "/" + parentFolder.Name; } if ((parentFolder.Model["type"]).Equals("sharedSup") || (parentFolder.Model["type"]).Equals("shared")) { folder.Model = new BsonDocument { { "type", NOT_SUPIRIOR_BUT_SHARED }, { "path", path } }; } else { folder.Model = new BsonDocument { { "type", NOT_SUPIRIOR_BUT_OWNED }, { "path", path } }; } folderManeger.AddSubFolder(parentFolder, folder); }
public void RemoveMap(MapStub stub) { DeleteMapFile(stub); MapFolder folder = GetFolder(stub); folder.Maps.Remove(stub); GameMap.Delete(stub.Id); }
public MapFolder CreateFolder(String name, MapFolder parent) { folderId++; MapFolder folder = new MapFolder(name, folderId, parent.FolderPath); parent.Folders.Add(folder); return(folder); }
//update MapFolder public void UpdateMapFolder(MapFolder folder) { var query = Query <MapFolder> .EQ(e => e.Id, folder.Id); var update = Update <MapFolder> .Replace(folder); _database.GetCollection <MapFolder>(_collectionName).Update(query, update); }
public void MoveMapToFolder(MapStub stub, MapFolder newFolder) { MapFolder oldFolder = GetFolder(stub); oldFolder.Maps.Remove(stub); stub.FolderPath = new List <int>(newFolder.FolderPath); newFolder.Maps.Add(stub); }
public ActionResult CreateMap(SaveMapViewModel newMapModel) { if (ModelState.IsValid) { var id = User.Identity.GetUserId(); ObjectId oId = new ObjectId(id); MapPermissions mapPermissions = new MapPermissions(); mapPermissions.Owner = new KeyValuePair <ObjectId, MapPermissionType>(oId, MapPermissionType.RW); mapPermissions.Users = new Dictionary <ObjectId, MapPermissionType>(); mapPermissions.Groups = new Dictionary <ObjectId, MapPermissionType>(); mapPermissions.AllUsers = MapPermissionType.NA; mapPermissions.Users.Add(oId, MapPermissionType.RW); BsonDocument bMapModel = BsonDocument.Parse(newMapModel.Model); //BsonDocument bMapModel = mapModel.ToBsonDocument(); Queue <MapVersion> versions = new Queue <MapVersion>(MapVersion.VERSIONS); versions.Enqueue(new MapVersion { CreationTime = DateTime.Now, Model = bMapModel }); Map map = new Map { Name = newMapModel.Name, Creator = oId, CreationTime = DateTime.Now, Description = newMapModel.Description, Model = bMapModel, Permissions = mapPermissions, MapsArchive = versions, Followers = new HashSet <ObjectId>() }; var mId = _mapManager.AddMap(map); ObjectId mapID = new ObjectId(mId); string currentFolderIdString = _currentFolderID; ObjectId folderID = new ObjectId(currentFolderIdString); MapFolder folder = _folderManeger.GetMapFolderById(folderID); string path = folder.Model["path"].ToString(); if (path.Equals("")) { path = folder.Name; } else { path = path + "/" + folder.Name; } bMapModel.Add("path", path); map.Model = bMapModel; _mapManager.UpdateMap(map); folder.idOfMapsInFolder.Add(mapID); _folderManeger.UpdateMapFolder(folder); return(Json(new { mapId = mId, mapName = map.Name }, JsonRequestBehavior.AllowGet)); } return(Json(new { success = false })); }
//this method return all the sub Folders of the given folder public IEnumerable <MapFolder> GetAllSubFolder(MapFolder parent) { List <MapFolder> mapFoldersList = new List <MapFolder>(); foreach (ObjectId MapFolder in parent.idOfSubFolders) { var toAdd = this.GetMapFolderById(MapFolder); mapFoldersList.Add(toAdd); } return(mapFoldersList); }
//add a folder to the parent folder public void AddSubFolder(MapFolder parent, MapFolder toAdd) { var parFolder = this.GetMapFolderById(parent.Id); this.AddFolder(toAdd); if (parFolder.idOfSubFolders == null) { parFolder.idOfSubFolders = new HashSet <ObjectId>(); } parFolder.idOfSubFolders.Add(toAdd.Id); this.UpdateMapFolder(parFolder); }
//this method remove a mapFolder from the DB if this method will receive a true //bollean value it will delete all the maps and folders that are in the given folder as well public bool RemoveMapFolder(MapFolder folderToRemove, Boolean removeAllContent) { var query = Query <MapFolder> .EQ(e => e.Id, folderToRemove.Id); var result = _database.GetCollection <Group>(_collectionName).Remove(query); if (removeAllContent) { removeAll(folderToRemove); } return(GetMapFolderById(folderToRemove.Id) == null); }
//private methode that will delete all the folders in maps in the given map; private void removeAll(MapFolder folderToRemove) { MapDB deleter = new DataBaseProviders.MapDB(new Settings()); foreach (ObjectId map in folderToRemove.idOfMapsInFolder) { deleter.RemoveMap(map); } foreach (ObjectId MapFolder in folderToRemove.idOfSubFolders) { var subToRemove = this.GetMapFolderById(MapFolder); this.RemoveMapFolder(subToRemove, true); } }
private void MapChoose_Click(object sender, EventArgs e) { MapFolder.ShowDialog(); //如有地圖存檔,將載入清單 if (MapFolder.SelectedPath != "") { MapPath.Text = MapFolder.SelectedPath; string[] MapFolderList = Directory.GetDirectories(MapFolder.SelectedPath); MapList.Items.Clear(); LoadMap(MapFolderList); } else { MapPath.Text = "N/A"; } }
private MapFolder createSuppFolderLocaly(string whichSupp) { MapFolderDB _mapFolderDataManager = new MapFolderDB(new Settings()); var id = User.Identity.GetUserId(); ObjectId UserId = new ObjectId(id); MapPermissions mapPermissions = new MapPermissions(); mapPermissions.Owner = new KeyValuePair <ObjectId, MapPermissionType>(UserId, MapPermissionType.RW); mapPermissions.Users = new Dictionary <ObjectId, MapPermissionType>(); mapPermissions.Groups = new Dictionary <ObjectId, MapPermissionType>(); mapPermissions.AllUsers = MapPermissionType.NA; mapPermissions.Users.Add(UserId, MapPermissionType.RW); MapFolder suppFolder = new MapFolder(); suppFolder.Name = "suppFolder" + whichSupp; suppFolder.Creator = UserId; suppFolder.CreationTime = DateTime.Now; suppFolder.Description = "Supirior Folder " + whichSupp; suppFolder.Followers = new HashSet <ObjectId>(); suppFolder.Permissions = mapPermissions; suppFolder.idOfMapsInFolder = new HashSet <ObjectId>(); suppFolder.idOfSubFolders = new HashSet <ObjectId>(); suppFolder.ParentDierctory = new ObjectId(); suppFolder.FirstFolderOfUser = UserId; suppFolder.Model = new BsonDocument { { "type", whichSupp }, { "path", "" } }; List <Map> maps = null; if (whichSupp.Equals(SharedCodedData.OWNED_SUPIRIOR)) { maps = new MapDB(new Settings()).GetMapsByCreatorId(UserId).ToList(); } else { maps = new MapDB(new Settings()).GetSharedMapsById(UserId).ToList(); } foreach (Map map in maps) { suppFolder.idOfMapsInFolder.Add(map.Id); } return(suppFolder); }
public MapFolder GetSuperiorMapFolderOfUserOwned(ObjectId userId) { var query = Query <MapFolder> .EQ(e => e.FirstFolderOfUser, userId); var folders = GetAllMapFoldersOfUser(userId); MapFolder supfolder = null; foreach (MapFolder mf in folders) { if ((mf.Model["type"]).Equals(SharedCodedData.OWNED_SUPIRIOR)) { supfolder = mf; break; } } return(supfolder); }
public IEnumerable <Map> GetAllMapsInFolder(MapFolder parent) { try { var mapDataManager = new MapDB(new Settings()); List <Map> mapList = new List <Map>(); foreach (ObjectId Map in parent.idOfMapsInFolder) { var toAdd = mapDataManager.GetMapById(Map); mapList.Add(toAdd); } return(mapList); } catch (Exception e) { return(new MapDB(new Settings()).GetAllMaps()); } }
public void DeleteFolder(MapFolder folder) { List <MapFolder> subfolders = new List <MapFolder>(folder.Folders); foreach (MapFolder sub in subfolders) { DeleteFolder(sub); } List <MapStub> stubs = new List <MapStub>(folder.Maps); foreach (MapStub stub in stubs) { DeleteMapFile(stub); } GetParent(folder).Folders.Remove(folder); }
public void MoveFolderToFolder(string folderToMoveId, string moveToFolderId) { if (!folderToMoveId.Equals(moveToFolderId)) { MapFolder folderToMove = _mapFolderDataManager.GetMapFolderById(new ObjectId(folderToMoveId)); MapFolder moveToFolder = _mapFolderDataManager.GetMapFolderById(new ObjectId(moveToFolderId)); MapFolder oldPrevFolder = _mapFolderDataManager.GetMapFolderById(folderToMove.ParentDierctory); if (!moveToFolder.Id.Equals(oldPrevFolder.Id)) { oldPrevFolder.idOfSubFolders.Remove(folderToMove.Id); folderToMove.ParentDierctory = moveToFolder.Id; moveToFolder.idOfSubFolders.Add(folderToMove.Id); _mapFolderDataManager.UpdateMapFolder(folderToMove); _mapFolderDataManager.UpdateMapFolder(moveToFolder); _mapFolderDataManager.UpdateMapFolder(oldPrevFolder); } } }
public void ConvertToVersion1() { if (version == 0) { currentFolderPath = new ObservableCollection <int>() { 0 }; MapFolder folder = CurrentFolder; folder.FolderPath = currentFolderPath; foreach (MapStub stub in maps) { folder.Maps.Add(stub); } maps.Clear(); version = 1; } }
public MapFolder GetSuperiorMapFolderOfUserShared(ObjectId userId) { var query = Query <MapFolder> .EQ(e => e.FirstFolderOfUser, userId); //var supfolder = _database.GetCollection<MapFolder>(_collectionName).FindOne(query); //if (supfolder != null) //{ // return new MapFolder(); //} var folders = GetAllMapFoldersOfUser(userId); MapFolder supfolder = null; foreach (MapFolder mf in folders) { if ((mf.Model["type"]).Equals(SharedCodedData.SHARED_SUPIRIOR)) { supfolder = mf; break; } } return(supfolder); }
public AbstractEnemy(MapFolder.Map m) : base() { LoadStats(); Life *= (int)(AbstractGame.gameTime.TotalTime.TotalMinutes + 1); maxSpawn *= (int)(AbstractGame.gameTime.TotalTime.TotalMinutes + 1); AnimationSteps = TextureList.Count / 4; AnimationRate = 1000 / AnimationSteps; IsAlive = true; MaxLife = Life; Verticies = m.Verticies; VertexIndex = 1; LifeBar = new Sprite(new Texture("Assets/Textures/Lebensbalken.png")); sprite.Position = Verticies[0]; LifeBar.Position = (Vec2f)sprite.Position + new Vec2f(0, LifeBar.Texture.Size.Y); EnemyHandler.Add(this); }
private MapFolder createFolderLocaly(string folderName) { MapFolderDB _mapFolderDataManager = new MapFolderDB(new Settings()); var id = User.Identity.GetUserId(); ObjectId UserId = new ObjectId(id); MapPermissions mapPermissions = new MapPermissions(); mapPermissions.Owner = new KeyValuePair <ObjectId, MapPermissionType>(UserId, MapPermissionType.RW); mapPermissions.Users = new Dictionary <ObjectId, MapPermissionType>(); mapPermissions.Groups = new Dictionary <ObjectId, MapPermissionType>(); mapPermissions.AllUsers = MapPermissionType.NA; mapPermissions.Users.Add(UserId, MapPermissionType.RW); MapFolder suppFolder = new MapFolder(); suppFolder.Name = folderName; suppFolder.Creator = UserId; suppFolder.CreationTime = DateTime.Now; suppFolder.Description = "shared folder for group" + folderName; suppFolder.Followers = new HashSet <ObjectId>(); suppFolder.Permissions = mapPermissions; suppFolder.idOfMapsInFolder = new HashSet <ObjectId>(); suppFolder.idOfSubFolders = new HashSet <ObjectId>(); // MapFolder supFolder = _mapFolderDataManager.GetSuperiorMapFolderOfUser suppFolder.ParentDierctory = new ObjectId(); suppFolder.FirstFolderOfUser = UserId; var maps = new MapDB(new Settings()).GetAllMaps(); foreach (Map map in maps) { suppFolder.idOfMapsInFolder.Add(map.Id); } return(suppFolder); }
public ActionResult Index(string id, string ownedOrShared) { //MailSender.SendMailMessage("*****@*****.**", "*****@*****.**", "", "", "(do not reply)", "lalalalalala"); bool isOwned; bool isShared; ViewBag.isShared = ownedOrShared != null && ownedOrShared.Equals("shared"); if (ownedOrShared == null) { isOwned = false; isShared = false; } else { isOwned = ownedOrShared.Equals("owned"); isShared = ownedOrShared.Equals("shared"); } ViewBag.ownedFolderID = null; MapFolderDB mapFolderManeger = new MapFolderDB(new Settings()); bool isIdOfOwned = false; if (id != null) { ObjectId oId = new ObjectId(id); MapFolder mf = mapFolderManeger.GetMapFolderById(oId); if (isOwned) { ViewBag.ownedFolderID = oId; isIdOfOwned = true; } } if (!isIdOfOwned) { ObjectId userID = new ObjectId(User.Identity.GetUserId()); var supFolder = new MapFolderDB(new Settings()).GetSuperiorMapFolderOfUserOwned(userID); if (supFolder != null) { ObjectId fId = supFolder.Id; ViewBag.ownedFolderID = fId; } else { supFolder = createSuppFolderLocaly(SharedCodedData.OWNED_SUPIRIOR); mapFolderManeger.AddFolder(supFolder); ObjectId fId = supFolder.Id; ViewBag.ownedFolderID = fId; } } ViewBag.sharedFolderID = null; bool isIdOfShared = false; if (id != null) { ObjectId oId = new ObjectId(id); MapFolder mf = mapFolderManeger.GetMapFolderById(oId); if (isShared) { ViewBag.sharedFolderID = oId; isIdOfShared = true; } } if (!isIdOfShared) { ObjectId userID = new ObjectId(User.Identity.GetUserId()); var supFolder = new MapFolderDB(new Settings()).GetSuperiorMapFolderOfUserShared(userID); if (supFolder != null) { ObjectId fId = supFolder.Id; ViewBag.sharedFolderID = fId; } else { supFolder = createSuppFolderLocaly(SharedCodedData.SHARED_SUPIRIOR); mapFolderManeger.AddFolder(supFolder); ObjectId fId = supFolder.Id; ViewBag.sharedFolderID = fId; } } return(View()); }
public Mob(MapFolder.Map m) : base(m) { }
private bool IsValidMap(MapFolder folder) { return(folder != null); }
//adding a folder to the DB public void AddFolder(MapFolder Folder) { _database.GetCollection <MapFolder>(_collectionName).Save(Folder); }
public Scissor(MapFolder.Map m) : base(m) { }
public Wolf(MapFolder.Map m) : base(m) { }
public HarvestingMachine(MapFolder.Map m) : base(m) { }
public Ninja(MapFolder.Map m) : base(m) { }