public void TestRootIsValid()
        {
            FileType t = new FileType
            {
                ID = 1,
                ImageUrl = "folder.png",
                Extension = null,
                Description = "Folder"
            };

            FileItem fi = new FileItem
            {
                FileName = "Root",
                ID = 0,
                IsFolder = true,
                OwnerId = 1,
                PerantID = -1,
                Rate = 0,
                SubItems = new List<FileItem>(),
                Type = t
            };
            FileStructure fs = new FileStructure(fi);
            Assert.NotNull(fs.RootFolder);
        }
        /*
            root
                -folder0
                    -folder1
                        -folder2
                            -folder3
                                -file0
                    -folder4
                        -folder5
                        -file1
                    -folder6
                        file2
                        file3
                        file4
                -folder7
                    folder8
                        file5
                        file6
                    file7
                -folder9
                    file8
                    file9
                    file10
                -file11
                -file12
         */
        private static void CreateNewStaticStructure()
        {
            item = 1;
            FileType t = new FileType
            {
                ID = 1,
                ImageUrl = "folder.png",
                Extension = null,
                Description = "Folder"
            };

            FileItem fi = new FileItem
            {
                FileName = "Root",
                ID = 0,
                IsFolder = true,
                OwnerId = 1,
                PerantID = -1,
                Rate = 0,
                SubItems = new List<FileItem>(),
                Type = t
            };
            List<FileItem> folders = new List<FileItem>();
            for (int i = 0; i < 10; i++)
            {
                folders.Add(GetNewFolder(false, -1));
            }
            List<FileItem> files = new List<FileItem>();
            for (int i = 0; i < 13; i++)
            {
                files.Add(GetNewFile(false, -1));
            }
            //root
            AddToFolder(fi, folders[0]);
                AddToFolder(folders[0], folders[1]);
                    AddToFolder(folders[1], folders[2]);
                        AddToFolder(folders[2], folders[3]);
                            AddToFolder(folders[3], files[0]);
                AddToFolder(fi, folders[4]);
                    AddToFolder(folders[4], folders[5]);
                    AddToFolder(folders[4], files[1]);
                AddToFolder(fi, folders[6]);
                    AddToFolder(folders[6], files[2]);
                    AddToFolder(folders[6], files[3]);
                    AddToFolder(folders[6], files[4]);
                AddToFolder(fi, folders[7]);
                    AddToFolder(folders[7], folders[8]);
                        AddToFolder(folders[8], files[5]);
                        AddToFolder(folders[8], files[6]);
                    AddToFolder(folders[7], files[7]);
                AddToFolder(fi, folders[9]);
                    AddToFolder(folders[9], files[8]);
                    AddToFolder(folders[9], files[9]);
                    AddToFolder(folders[9], files[10]);
                AddToFolder(fi, files[11]);
                AddToFolder(fi, files[12]);
            fs = new FileStructure(fi);
        }
Beispiel #3
0
        public static FileStructure GetCourseFiles(string sessionId, int userId, int courseId)
        {
            try
            {
                DataTable table = new DataAccess(ConnectionString).ExecuteQuerySP("SP_GetFilesByCourseID",
                        "@SessionID", sessionId,
                        "@UserID", userId,
                        "@courseID", courseId);
                if (table == null || table.Rows.Count == 0)
                    return null;

                FileStructure struc = null;
                List<FileItem> files = new List<FileItem>();
                foreach (DataRow row in table.Rows)
                {
                    int id, ownerId, perantId, rate,typeId, size,rUsers;
                    bool isFolder;

                    ParseCellDataToInt(row["ID"], out id);
                    ParseCellDataToInt(row["UserId"], out ownerId);
                    ParseCellDataToInt(row["ParentFileID"], out perantId);
                    ParseCellDataToInt(row["Rate"], out rate);
                    ParseCellDataToInt(row["RatingUsers"], out rUsers);
                    ParseCellDataToInt(row["TypeID"], out typeId);

                    ParseCellDataToBool(row["IsFolder"], out isFolder);

                    ParseCellDataToInt(row["Size"], out size);

                    FileType type = new FileType
                    {
                        ID=typeId,
                        Description = ParseCellDataToString(row["Type"]),
                        Extension = ParseCellDataToString(row["Extension"]),
                        ImageUrl = ParseCellDataToString(row["ImageUrl"])
                    };

                    FileItem item = new FileItem
                    {
                        FileName = ParseCellDataToString(row["FileName"]),
                        Type = type,
                        SubItems=null,
                        OwnerName = ParseCellDataToString(row["UserName"]),
                        LastModify = ParseCellDataToDateTime(row["LastModify"]),
                        ID=id,
                        IsFolder=isFolder,
                        OwnerId=ownerId,
                        PerantID=perantId,
                        Rate = ((double)rate / rUsers),
                        Size=size
                    };
                    if (rate == 0 && rUsers == 0)
                        item.Rate = -1;

                    files.Add(item);
                }

                struc = new FileStructure(files.Where(x => x.PerantID == -1).First());
                files.Remove(struc.RootFolder);
                while (files.Count != 0)
                {
                    if (files.Count > 0 && struc.AddFileByPerantID(files[0]))
                        files.Remove(files[0]);
                }

                return struc;
            }
            catch (Exception)
            {
                return null;
            }
        }