public async Task <IActionResult> Post([FromBody] DirectoryViewModel model)
        {
            DirectoryInformation k = await _context.Directory
                                     .FirstOrDefaultAsync(l => l.Course == model.Course && l.NameLesson == model.NameLesson);

            if (k != null)
            {
                return(BadRequest("Папка з такою назвою, курсом і факультетом вже існує"));
            }

            DirectoryInformation directory = new DirectoryInformation()
            {
                Name       = model.NameLesson,
                Course     = model.Course,
                NameLesson = model.NameLesson,
                Faculty    = model.Faculty
            };


            var d = _context.Directory.Add(directory);
            await _context.SaveChangesAsync();

            var pathDir = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot", d.Entity.Id.ToString());

            if (!Directory.Exists(pathDir))
            {
                Directory.CreateDirectory(pathDir);
            }

            return(Ok(d.Entity));
        }
        internal static DirectoryEntryHolder GetDirectoryEntry(DirectoryInformation directoryInfo, string objectDN, bool revertImpersonation)
        {
            DirectoryEntryHolder holder = new DirectoryEntryHolder(new DirectoryEntry(directoryInfo.GetADsPath(objectDN), directoryInfo.GetUsername(), directoryInfo.GetPassword(), directoryInfo.AuthenticationTypes));

            holder.Open(null, revertImpersonation);
            return(holder);
        }
        public async Task <IActionResult> Delete([FromQuery] List <Guid> id)
        {
            if (id == null)
            {
                return(BadRequest("id == null"));
            }

            List <Guid> delId = new List <Guid>();

            foreach (Guid i in id)
            {
                DirectoryInformation f = await _context.Directory.FirstOrDefaultAsync(l => l.Id == i);

                if (f != null)
                {
                    delId.Add(f.Id);
                    _context.Directory.Remove(f);

                    var pathDir = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot", f.Id.ToString());

                    if (Directory.Exists(pathDir))
                    {
                        Directory.Delete(pathDir, true);
                    }
                }
            }

            await _context.SaveChangesAsync();

            return(Ok(delId));
        }
Ejemplo n.º 4
0
        public string CreateDirectory(string ownerName, string directoryName)
        {
            string        pathName = sharedFolder.FullName + Config.SLASH + directoryName;
            DirectoryInfo info     = new DirectoryInfo(pathName);

            if (!info.Exists)
            {
                info.Create();
                FileInfo   dirInfor = new FileInfo(pathName + Config.SLASH + INFOR_FILE);
                FileStream stream   = dirInfor.Open(FileMode.Create, FileAccess.Write);
                try
                {
                    IFormatter           formatter = new BinaryFormatter();
                    DirectoryInformation infor     = new DirectoryInformation(null, directoryName, ownerName);
                    formatter.Serialize(stream, infor);
                    stream.Close();
                }
                catch
                {
                    if (stream != null)
                    {
                        try
                        {
                            stream.Close();
                        }
                        catch
                        {
                        }
                    }
                    info.Delete(true);
                    return(null);
                }
            }
            return(directoryName);
        }
Ejemplo n.º 5
0
    public void getFileList(DirectoryInfo di)
    {
        //set current directory
        currentDirectory = di;
        //get parent
        if (backTexture)
        {
            parentDir = (di.Parent == null)?new DirectoryInformation(di, backTexture):new DirectoryInformation(di.Parent, backTexture);
        }
        else
        {
            parentDir = (di.Parent == null)?new DirectoryInformation(di):new DirectoryInformation(di.Parent);
        }
        showDrives = di.Parent == null;

        //get drives
        string[] drvs = Directory.GetLogicalDrives();
        drives = new DirectoryInformation[drvs.Length];
        for (int v = 0; v < drvs.Length; v++)
        {
            drives[v] = (driveTexture == null)?new DirectoryInformation(new DirectoryInfo(drvs[v])):new DirectoryInformation(new DirectoryInfo(drvs[v]), driveTexture);
        }

        //get directories
        DirectoryInfo[] dia = di.GetDirectories();
        directories = new DirectoryInformation[dia.Length];
        for (int d = 0; d < dia.Length; d++)
        {
            if (directoryTexture)
            {
                directories[d] = new DirectoryInformation(dia[d], directoryTexture);
            }
            else
            {
                directories[d] = new DirectoryInformation(dia[d]);
            }
        }

        //get files
        FileInfo[] fia = new string[] { "*.map", "*.jpg", "*.png" }
        .SelectMany(i => di.GetFiles(i, SearchOption.AllDirectories))
        .ToArray();
        //FileInfo[] fia = di.GetFiles(searchPattern);
        //FileInfo[] fia = searchDirectory(di,searchPattern);
        files = new FileInformation[fia.Length];
        for (int f = 0; f < fia.Length; f++)
        {
            if (fileTexture)
            {
                files[f] = new FileInformation(fia[f], fileTexture);
            }
            else
            {
                files[f] = new FileInformation(fia[f]);
            }
        }
    }
        public async Task <IActionResult> GetById(Guid?id)
        {
            if (id == null)
            {
                return(BadRequest("id == null"));
            }

            DirectoryInformation d = await _context.Directory.Include(l => l.Files)
                                     .Include(l => l.SubDirectories)
                                     .Include(l => l.Links)
                                     .FirstOrDefaultAsync(l => l.Id == id);

            if (d == null)
            {
                return(NotFound());
            }

            return(Ok(d));
        }
        internal static DirectoryEntryHolder GetDirectoryEntry(DirectoryInformation directoryInfo, string objectDN, bool revertImpersonation)
        {
            Debug.Assert((objectDN != null) && (objectDN.Length != 0));

            //
            // Get the adspath and create a directory entry holder
            //
            DirectoryEntryHolder holder = new DirectoryEntryHolder(new DirectoryEntry(
                                                                       directoryInfo.GetADsPath(objectDN),
                                                                       directoryInfo.GetUsername(),
                                                                       directoryInfo.GetPassword(),
                                                                       directoryInfo.AuthenticationTypes));

            //
            // If  revertImpersonation is true, we need to revert
            //
            holder.Open(null, revertImpersonation);
            return(holder);
        }
        public async Task <IActionResult> GetByCourseAndName(byte?course, string name, Faculty?faculty)
        {
            if (course == null)
            {
                return(BadRequest("course == null"));
            }
            if (name == null || name == String.Empty)
            {
                return(BadRequest("name == null"));
            }
            if (faculty == null)
            {
                return(BadRequest("faculty == null"));
            }

            Regex           regex   = new Regex(@"\W\w\s\d*\W");
            MatchCollection matches = regex.Matches(name);

            if (matches.Count > 0)
            {
                foreach (Match match in matches)
                {
                    name = name.Replace(match.Value, "").Trim();
                }
            }

            DirectoryInformation d = await _context.Directory.Include(l => l.Files)
                                     .Include(l => l.Links)
                                     .Include(l => l.SubDirectories).ThenInclude(l => l.Files)
                                     .FirstOrDefaultAsync(l => l.Course == course && l.NameLesson.Contains(name) && l.Faculty == faculty);

            if (d == null)
            {
                return(NotFound());
            }

            d.Files          = d.Files.OrderBy(f => f.Name).ToList();
            d.SubDirectories = d.SubDirectories.OrderBy(f => f.Name).ToList();
            d.Links          = d.Links.OrderBy(f => f.Name).ToList();

            return(Ok(d));
        }
Ejemplo n.º 9
0
        public string CreateDirectory(string ownerName, string pathName, string directoryName)
        {
            if (pathName == null || pathName == String.Empty)
            {
                throw new ArgumentException("pathname cannot be null or empty.");
            }
            string viewPathName = pathName + Config.SLASH + directoryName;

            pathName = sharedFolder.FullName + Config.SLASH + viewPathName;
            DirectoryInfo info = new DirectoryInfo(pathName);

            if (!info.Exists)
            {
                info.Create();
                FileInfo   dirInfor = new FileInfo(pathName + Config.SLASH + INFOR_FILE);
                FileStream stream   = dirInfor.Open(FileMode.Create, FileAccess.Write);
                try
                {
                    IFormatter           formatter = new BinaryFormatter();
                    DirectoryInformation infor     = new DirectoryInformation(info.Parent.FullName, directoryName, ownerName);
                    formatter.Serialize(stream, infor);
                    stream.Close();
                }
                catch
                {
                    if (stream != null)
                    {
                        try
                        {
                            stream.Close();
                        }
                        catch
                        {
                        }
                    }
                    info.Delete(true);
                    return(null);
                }
                return(viewPathName);
            }
            return(null);
        }
Ejemplo n.º 10
0
        public DirectoryInformation BuildDirectoryInfo(string path)
        {
            var result = new DirectoryInformation();

            result.FullPath = path;

            var files = Directory.GetFiles(path, "*.", SearchOption.TopDirectoryOnly);

            foreach (var file in files)
            {
                result.Files.Add(new FileInformation(file));
            }

            var folders = Directory.GetDirectories(path, "*.*", SearchOption.TopDirectoryOnly);

            foreach (var folder in folders)
            {
                result.Directories.Add(BuildDirectoryInfo(folder));
            }

            return(result);
        }
Ejemplo n.º 11
0
        public IList <Information> GetFileInformation(string pathName, string directoryName)
        {
            if (pathName == null || pathName == "")
            {
                pathName = sharedFolder.FullName + Config.SLASH + directoryName;
            }
            else
            {
                pathName = sharedFolder.FullName + Config.SLASH + pathName + Config.SLASH + directoryName;
            }
            DirectoryInfo info = new DirectoryInfo(pathName);

            if (info.Exists)
            {
                DirectoryInformation parentInfor    = GetDirectoryInfor(info);
                IList <Information>  result         = new List <Information>();
                DirectoryInfo[]      allDirectories = info.GetDirectories();
                for (int i = 0; i < allDirectories.Length; i++)
                {
                    DirectoryInfo        subDir     = allDirectories[i];
                    DirectoryInformation subDirInfo = GetDirectoryInfor(subDir);
                    if (subDirInfo != null)
                    {
                        result.Add(subDirInfo);
                    }
                }
                FileInfo[] fileInfos = info.GetFiles();
                for (int i = 0; i < fileInfos.Length; i++)
                {
                    FileInfo        subFileInfo     = fileInfos[i];
                    FileInformation fileInformation = new FileInformation(subFileInfo.Name, parentInfor.OwnerName, info.FullName);
                    fileInformation.Length = subFileInfo.Length;
                    result.Add(fileInformation);
                }
                return(result);
            }
            return(null);
        }
Ejemplo n.º 12
0
 private static DirectoryInformation GetDirectoryInfor(DirectoryInfo info)
 {
     if (info.Exists)
     {
         FileInfo   dirInfor = new FileInfo(info.FullName + Config.SLASH + INFOR_FILE);
         FileStream stream   = dirInfor.Open(FileMode.Open, FileAccess.Read);
         try
         {
             IFormatter           formatter = new BinaryFormatter();
             DirectoryInformation infor     = (DirectoryInformation)formatter.Deserialize(stream);
             return(infor);
         }
         catch
         {
             return(null);
         }
         finally
         {
             stream.Close();
         }
     }
     return(null);
 }
Ejemplo n.º 13
0
    public void getFileList(DirectoryInfo di)
    {
        //set current directory
        currentDirectory = di;
        //get parent
        if (backTexture)
        {
            parentDir = (di.Parent == null)?new DirectoryInformation(di, backTexture):new DirectoryInformation(di.Parent, backTexture);
        }
        else
        {
            parentDir = (di.Parent == null)?new DirectoryInformation(di):new DirectoryInformation(di.Parent);
        }
        showDrives = di.Parent == null;

        //get drives
        string[] drvs = System.IO.Directory.GetLogicalDrives();
        drives = new DirectoryInformation[drvs.Length];
        for (int v = 0; v < drvs.Length; v++)
        {
            drives[v] = (driveTexture == null)?new DirectoryInformation(new DirectoryInfo(drvs[v])):new DirectoryInformation(new DirectoryInfo(drvs[v]), driveTexture);
        }

        //get directories
        DirectoryInfo[] dia = di.GetDirectories();
        directories = new DirectoryInformation[dia.Length];
        for (int d = 0; d < dia.Length; d++)
        {
            if (directoryTexture)
            {
                directories[d] = new DirectoryInformation(dia[d], directoryTexture);
            }
            else
            {
                directories[d] = new DirectoryInformation(dia[d]);
            }
        }

        //get files
        FileInfo[] fia;
        if (GameManager.i.getType().Equals("Model"))
        {
            searchPattern = "*.obj";
            fia           = di.GetFiles(searchPattern);
        }
        else
        {
            searchPattern = "*.jpg";
            List <FileInfo> backup = new List <FileInfo>(di.GetFiles(searchPattern));
            searchPattern = "*.png";
            FileInfo[] find = di.GetFiles(searchPattern);
            for (int i = 0; i < find.Length; i++)
            {
                backup.Add(find[i]);
            }
            searchPattern = "*.gif";
            find          = di.GetFiles(searchPattern);
            for (int i = 0; i < find.Length; i++)
            {
                backup.Add(find[i]);
            }
            fia = backup.ToArray();
        }

        //FileInfo[] fia = searchDirectory(di,searchPattern);
        files = new FileInformation[fia.Length];
        for (int f = 0; f < fia.Length; f++)
        {
            if (fileTexture)
            {
                files[f] = new FileInformation(fia[f], fileTexture);
            }
            else
            {
                files[f] = new FileInformation(fia[f]);
            }
        }
    }
Ejemplo n.º 14
0
    public void GetFileList(DirectoryInfo di)
    {
        // Clear directories
        for (int i = directoryInformations.Count - 1; i >= 0; i--)
        {
            Destroy(directoryInformations[i].gameObject);
        }

        directoryInformations.Clear();

        for (int i = fileInformations.Count - 1; i >= 0; i--)
        {
            Destroy(fileInformations[i].gameObject);
        }

        fileInformations.Clear();

        // Set directories
        currentDirectory = di;
        parentDirectory  = currentDirectory.Parent;

        if (parentDirectory == null)
        {
            backButton.SetDisable();
        }
        else
        {
            backButton.SetEnable();
        }

        // Create directories
        DirectoryInfo[] dia = di.GetDirectories();
        for (int i = 0; i < dia.Length; i++)
        {
            if ((dia[i].Attributes & FileAttributes.Hidden) == FileAttributes.Hidden)
            {
                continue;
            }

            GameObject directoryInformation = Instantiate(directoryInformationPrefab, scrollViewContent) as GameObject;
            directoryInformation.transform.localPosition = Vector3.zero;

            DirectoryInformation dirInfo = directoryInformation.GetComponent <DirectoryInformation>();
            dirInfo.InitItem(this);
            dirInfo.SetName(dia[i].Name);

            directoryInformations.Add(dirInfo);
        }

        // Create files
        FileInfo[] fia = di.GetFiles("*");
        for (int i = 0; i < fia.Length; i++)
        {
            if (CheckFileExtension(fia[i].Name))
            {
                GameObject fileInformation = Instantiate(fileInformationPrefab, scrollViewContent) as GameObject;
                fileInformation.transform.localPosition = Vector3.zero;

                FileInformation fileInfo = fileInformation.GetComponent <FileInformation>();
                fileInfo.InitItem(this);
                fileInfo.SetName(fia[i].Name);

                fileInformations.Add(fileInfo);
            }
        }
    }
Ejemplo n.º 15
0
	public void getFileList(DirectoryInfo di){
		//set current directory
		currentDirectory = di;
		//get parent
		if(backTexture)
			parentDir = (di.Parent==null)?new DirectoryInformation(di,backTexture):new DirectoryInformation(di.Parent,backTexture);
		else
			parentDir = (di.Parent==null)?new DirectoryInformation(di):new DirectoryInformation(di.Parent);
		showDrives = di.Parent==null;
		
		//get drives
		string[] drvs = System.IO.Directory.GetLogicalDrives();
		drives = new DirectoryInformation[drvs.Length];
		for(int v=0;v<drvs.Length;v++){
			drives[v]= (driveTexture==null)?new DirectoryInformation(new DirectoryInfo(drvs[v])):new DirectoryInformation(new DirectoryInfo(drvs[v]),driveTexture);
		}
		
		//get directories
		DirectoryInfo[] dia = di.GetDirectories();
		directories = new DirectoryInformation[dia.Length];
		for(int d=0;d<dia.Length;d++){
			if(directoryTexture)
				directories[d] = new DirectoryInformation(dia[d],directoryTexture);
			else
				directories[d] = new DirectoryInformation(dia[d]);
		}
		
		//get files
		FileInfo[] fia = di.GetFiles(searchPattern);
		//FileInfo[] fia = searchDirectory(di,searchPattern);

		files = new FileInformation[fia.Length];
		for(int f=0;f<fia.Length;f++){
			if(fileTexture)
				files[f] = new FileInformation(fia[f],fileTexture);
			else
				files[f] = new FileInformation(fia[f]);

		}

	}
Ejemplo n.º 16
0
 private void GetFileList(DirectoryInfo directory)
 {
     SelectFile(-1);
     currentDirectory = directory;
     parentDirectory = new DirectoryInformation(directory.Parent ?? directory, backTexture);
     showDrives = directory.Parent == null;
     var driveNames = Directory.GetLogicalDrives();
     drives = new DirectoryInformation[driveNames.Length];
     for (var i = 0; i < drives.Length; i++)
         drives[i] = new DirectoryInformation(new DirectoryInfo(driveNames[i]), driveTexture);
     var directoryInfos = directory.GetDirectories();
     directories = new DirectoryInformation[directoryInfos.Length];
     for (var i = 0; i < directories.Length; i++)
         directories[i] = new DirectoryInformation(directoryInfos[i], directoryTexture);
     var fileInfos = directory.GetFiles();
     files = new FileInformation[fileInfos.Length];
     for (var i = 0; i < files.Length; i++)
         files[i] = new FileInformation(fileInfos[i], fileTexture);
 }
Ejemplo n.º 17
0
        public static int GetDirectoryId(SQLiteConnection db, DriveInformation drive, DirectoryInfo directory)
        {
            var directoryPath = directory.ToDirectoryPath();
            directoryPath = (directoryPath ?? string.Empty).Trim();

            var cmd = db.CreateCommand("Select * from " + typeof(DirectoryInformation).Name + " Where DriveId = ? AND Path = ?", drive.DriveId, directoryPath);
            var retVal = cmd.ExecuteQuery<DirectoryInformation>().FirstOrDefault();

            if (retVal != null) {
                return retVal.DirectoryId;
            }

            int? parentDirectoryInfo = null;

            if (directory.Parent != null) {
                var parentName = directory.Parent.FullName.Substring(3);
                parentDirectoryInfo = GetDirectoryId(db, drive, directory.Parent);
            }

            var directoryName = directory.Name;

            if (directoryName.IndexOf(":") > -1) {
                directoryName = directoryName.Substring(3);
            }

            //create a new record
            var newDirectory = new DirectoryInformation() {
                DriveId = drive.DriveId,
                Name = directoryName,
                ParentDirectoryId = parentDirectoryInfo.HasValue ? parentDirectoryInfo : null,
                Path = directoryPath
            };

            db.Insert(newDirectory);

            return newDirectory.DirectoryId;
        }