Exemple #1
0
        /// <summary>
        /// ȡ�ø�Ŀ¼�ļ�����һ��Ŀ¼�������ļ����ļ��С�
        /// </summary>
        /// <param name="userID">��ǰ�û���ID��</param>
        /// <param name="directoryID">���ļ��е�ID��</param>
        /// <param name="directories">������ļ���ʵ��<see cref="DiskDirectory"/>���б��</param>
        /// <param name="files">������ļ�ʵ��<see cref="DiskFile"/>�б��</param>
        /// <param name="totalSize">��ǰ��Ŀ¼���������ļ��Ĵ�С��</param>
        /// <returns>����ɹ�ȡ���򷵻�<c>true</c>,���򷵻�<c>false</c>��</returns>
        public List <IFile> GetDiskFiles(int userID, int directoryID, out DiskDirectoryCollection directories, out DiskFileCollection files, FileOrderBy orderBy, bool isDesc, ExtensionList fileTypes)
        {
            List <IFile> dirAndFiles;
            int          fileTypeKey          = fileTypes == null || fileTypes.Count == 0?0: fileTypes.ToString("").GetHashCode();
            string       cachekeyOfDirectorys = string.Format(cacheKey_directoryList, userID, directoryID);
            string       cacheKeyOfFiles      = string.Format(cacheKey_fileList, userID, directoryID, fileTypeKey);

            if (!CacheUtil.TryGetValue <DiskFileCollection>(cacheKey_fileList, out files) ||
                CacheUtil.TryGetValue <DiskDirectoryCollection>(cachekeyOfDirectorys, out directories))
            {
                DiskDao.Instance.GetDiskFiles(userID, directoryID, out directories, out files);
                CacheUtil.Set <DiskFileCollection>(cacheKeyOfFiles, files);
                CacheUtil.Set <DiskDirectoryCollection>(cachekeyOfDirectorys, directories);
            }

            /*���´������ܺܲ ԭ����3.0��BO������Ӧ�����ܣ� ��ʱ��Ӧ����������ѭ������*/

            string cacheKeyOfAllFiles = string.Format(cacheKey_directoryList, userID, directoryID, orderBy, isDesc);

            if (!CacheUtil.TryGetValue <List <IFile> >(cacheKeyOfAllFiles, out dirAndFiles))
            {
                dirAndFiles = new List <IFile>(directories.Count + files.Count);


                if (orderBy != FileOrderBy.None)
                {
                    DiskFile temp;
                    int      v;
                    for (int i = 0; i < files.Count - 1; i++)
                    {
                        for (int j = i + 1; j < files.Count; j++)
                        {
                            v = CompareFile(files[i], files[j], orderBy);
                            if (isDesc)
                            {
                                if (v > 0)
                                {
                                    temp     = files[i];
                                    files[i] = files[j];
                                    files[j] = temp;
                                }
                            }
                            else
                            {
                                if (v < 0)
                                {
                                    temp     = files[j];
                                    files[j] = files[i];
                                    files[i] = temp;
                                }
                            }
                        }
                    }

                    DiskDirectory tempDir;

                    for (int i = 0; i < directories.Count - 1; i++)
                    {
                        for (int j = i + 1; j < directories.Count; j++)
                        {
                            v = CompareFile(directories[i], directories[j], orderBy);
                            if (isDesc)
                            {
                                if (v > 0)
                                {
                                    tempDir        = directories[i];
                                    directories[i] = directories[j];
                                    directories[j] = tempDir;
                                }
                            }
                            else
                            {
                                if (v < 0)
                                {
                                    tempDir        = directories[j];
                                    directories[j] = directories[i];
                                    directories[i] = tempDir;
                                }
                            }
                        }
                    }
                }

                if (orderBy == FileOrderBy.Type && isDesc == false)
                {
                    foreach (DiskFile file in files)
                    {
                        if (fileTypes != null && fileTypes.Count > 0 && !fileTypes.Contains(file.ExtensionName))
                        {
                            continue;
                        }
                        dirAndFiles.Add(file);
                    }
                    foreach (IFile dir in directories)
                    {
                        dirAndFiles.Add(dir);
                    }
                }
                else
                {
                    foreach (IFile dir in directories)
                    {
                        dirAndFiles.Add(dir);
                    }

                    foreach (DiskFile file in files)
                    {
                        if (fileTypes != null && fileTypes.Count > 0 && !fileTypes.Contains(file.ExtensionName))
                        {
                            continue;
                        }

                        dirAndFiles.Add(file);
                    }
                }

                CacheUtil.RemoveBySearch(string.Format(cacheKey_allFileListRoot, userID, directoryID));
                CacheUtil.Set <List <IFile> >(cacheKeyOfAllFiles, dirAndFiles);
            }
            return(dirAndFiles);
        }
Exemple #2
0
        static void Main(string[] args)
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            ExtensionList videoExtensions = new ExtensionList();
            ExtensionList subExtensions = new ExtensionList();

            #region read from xml using RND.XML
            //XmlStorage myXmlStorage = new XmlStorage("Extensions", System.Convert.ToChar(" "));
            //try
            //{
            //    using (Stream fStream = new FileStream(fileName, FileMode.OpenOrCreate, FileAccess.Read, FileShare.None))
            //    {
            //        //
            //        myXmlStorage.Load(fStream);
            //    }
            //}
            //catch (Exception)
            //{
            //}
            //videoExtensions = (ExtensionList)myXmlStorage.ReadEntry("VideoExt");
            //subExtensions = (ExtensionList)myXmlStorage.ReadEntry("SubExt");
            #endregion
            #region Read xml-file with user extensions using Standard XML
            XmlSerializer xmlFormat = new XmlSerializer(typeof(List<ExtensionList>), "Extensions");
            try
            {
                using (Stream fStream = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.None))
                {
                    try
                    {
                        List<ExtensionList> myList = (List<ExtensionList>)xmlFormat.Deserialize(fStream);
                        videoExtensions = myList[0];
                        subExtensions = myList[1];
                    }
                    catch (Exception)
                    {
                        Debug.WriteLine("xmlFormat.Deserialize(fStream) fails");
                    }
                    finally { fStream.Close(); }
                }
            }
            catch (Exception)
            {
                Debug.WriteLine("Fail to open xml file");
            }
            #endregion
            if (videoExtensions ==null ||videoExtensions.ToString() == "")
            {
              videoExtensions = ExtensionList.Parse(".avi;.mkv;.ogm;.mpeg;.mpg;.vid;.xvid;.m4v;.wmv;");
            }

            if (subExtensions == null|| subExtensions.ToString() == "")
                subExtensions = ExtensionList.Parse(".srt;.ass;.ssa;.rt;.js;.sub;");

            //serialize into XML
            Application.ApplicationExit += new EventHandler(Application_ApplicationExit);

            //start App
            myForm = new ParentForm(videoExtensions, subExtensions, args);
            Application.Run(myForm);//Form1(LIST)
        }