Ejemplo n.º 1
0
 public void AddProject(UserCache cache, string pname)
 {
     if(pname.ToCharArray().Contains('/'))
         return;
     if (cache.Client.ProjectsOwner.Where(p => p.Name == pname).Count() > 0)
         throw new CreateProdjectException("Проект с такими названием уже существует");
     string dir = _prodjectSubsystem.ProjectDir + "\\" + cache.Client.Login + "\\" + pname;
     try
     {
         Directory.CreateDirectory(dir);
     }
     catch (Exception)
     {
         Logger.Log.Write(LogLevels.Emerg,
             String.Format("Невозможно создать директорию проекта {0}. Проверьте путь и права доступа.", dir));
         throw new CreateProdjectFolderException("Невозможно создать директорию проекта. Обратитесь к системному администратору");
     }
     var prj = new Project();
     context.Add(prj);
     prj.Owner = cache.Client;
     prj.Sourcedir = dir;
     prj.Folders.Add(new Folder() { Name = pname, Path = _prodjectSubsystem.ProjectDir + "\\" + cache.Client.Login });
     prj.Name = pname;
     prj.Members.Add(cache.Client);
     var log = new Userlog() {Date = DateTime.Now, Message = "Создан проект " + pname};
     cache.Client.Userlogs.Add(log);
     cache.LogMessages.Add(log.AsDto());
     cache.NewProjects.Add(prj.AsDto());
     SaveContext();
 }
Ejemplo n.º 2
0
 public void AddFolder(UserCache cache, FolderDto parentFolder, FolderDto folder)
 {
     Project p = null;
     cache.CurrentProject.CopyTo(p);
     p.Folders.Add(new Folder() {Name = folder.Name, Path = folder.Path});
     Directory.CreateDirectory(folder.Path+"\\"+folder.Name);
     SaveContext();
     var log = new Userlog() { Date = DateTime.Now, Message = "Создание папки " + folder.Name };
     cache.Client.Userlogs.Add(log);
     cache.LogMessages.Add(log.AsDto());
     cache.StructureChanges.Add(new StructureChange(Action.Added, folder));
 }
Ejemplo n.º 3
0
 public void AddFile(UserCache cache, FolderDto parentFolder ,FileDto file)
 {
     Project p = null;
     cache.CurrentProject.CopyTo(p);
     var folder = p.Folders.Where(x => x.Path == parentFolder.Path && x.Name == parentFolder.Name).First();
     folder.Files.Add(new File() {Name = file.Name, Path = file.Path});
     System.IO.File.Create(file.Path + "\\" + file.Name);
     SaveContext();
     var log = new Userlog() { Date = DateTime.Now, Message = "Создание файла " + file.Name };
     cache.Client.Userlogs.Add(log);
     cache.LogMessages.Add(log.AsDto());
     cache.StructureChanges.Add(new StructureChange(Action.Added, file));
 }
Ejemplo n.º 4
0
 public int Login(string uname, string upasswd)
 {
     try
     {
         var user = _context.Users.Where(u => (u. Login == uname) && (u.Password == upasswd)).First();
         user.LastAccess = DateTime.Now;
         _loginTime = DateTime.Now;
         user.Userlogs.Add(new Userlog(){ Date = DateTime.Now, Message = "Вход в систему"});
         var cache = new UserCache(user);
         Kernel.GetKernel.Clients.Add(cache.GetHashCode(), cache);
         return cache.GetHashCode();
     }
     catch(Exception)
     {
         return 0;
     }
 }
Ejemplo n.º 5
0
 public void AddMember(UserCache cache, User member)
 {
     throw new NotImplementedException();
 }
Ejemplo n.º 6
0
 public void RemoveFolder(UserCache cache, FolderDto folder)
 {
     Project p = null;
     cache.CurrentProject.CopyTo(p);
     var f = p.Folders.Where(x => x.Path == folder.Path && x.Name == folder.Name).First();
     p.Folders.Remove(f);
     Directory.Delete(f.Path + "\\" + f.Name, true);
     SaveContext();
     var log = new Userlog() { Date = DateTime.Now, Message = "Удаление папки " + folder.Name };
     cache.Client.Userlogs.Add(log);
     cache.LogMessages.Add(log.AsDto());
     cache.StructureChanges.Add(new StructureChange(Action.Removed, folder));
 }
Ejemplo n.º 7
0
 public void RemoveFile(UserCache cache, FileDto file)
 {
     Project p = null;
     cache.CurrentProject.CopyTo(p);
     foreach(var folder in p.Folders)
     {
         var f = folder.Files.Where(x => x.Path == file.Path && x.Name == file.Name);
         if(f.Count() > 0)
         {
             folder.Files.Remove(f.First());
             System.IO.File.Delete(file.Path+"\\"+file.Name);
             SaveContext();
             return;
         }
     }
     SaveContext();
     var log = new Userlog() {Date = DateTime.Now, Message = "Удаление файла " + file.Name};
     cache.Client.Userlogs.Add(log);
     cache.LogMessages.Add(log.AsDto());
     cache.StructureChanges.Add(new StructureChange(Action.Removed,file));
 }
Ejemplo n.º 8
0
 public ProjectStructure GetStructure(UserCache u, string pname)
 {
     var project = u.Client.ProjectsOwner.Where(x => x.Name == pname).First();
     u.CurrentProject = project.AsDto();
     var structure = new ProjectStructure();
     //TODO: Реализовать учет прав доступа.
     foreach (var folder in project.Folders)
     {
         structure.Folders.Add(new FolderDto(){Name = folder.Name, Path = folder.Path});
         foreach (var file in folder.Files)
         {
             structure.Files.Add(new FileDto(){Name = file.Name, Path = file.Path});
         }
     }
     return structure;
 }