Ejemplo n.º 1
0
        /// <summary>
        /// 获取子级数据项
        /// </summary>
        /// <returns></returns>
        public override IDataItem[] GetChildren()
        {
            if (!IsContainer)
            {
                return(null);
            }
            else
            {
                DirectoryInfo        curDirInfo = new DirectoryInfo(IdentityName.Replace('/', '\\'));
                List <LocalFileData> fList      = new List <LocalFileData>();
                LocalFileData        fDat       = null;
                #region 文件
                foreach (FileInfo file in curDirInfo.GetFiles())
                {
                    fDat             = new LocalFileData(file.FullName);
                    fDat.IsContainer = false;
                    fList.Add(fDat);
                }
                #endregion

                #region 目录
                foreach (DirectoryInfo di in curDirInfo.GetDirectories())
                {
                    fDat             = new LocalFileData(di.FullName);
                    fDat.IsContainer = true;
                    fList.Add(fDat);
                }
                #endregion
                return(fList.ToArray());
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 相关属性数据绑定
        /// </summary>
        public override void DataBind()
        {
            string tarFile = (IsContainer) ? IdentityName + "\\" + FileSystemStorage.FS_DIRDAT : IdentityName;

            tarFile = tarFile.Replace('/', '\\');
            if (!File.Exists(tarFile))
            {
                return;
            }

            byte[]        diskDat = File.ReadAllBytes(tarFile);
            LocalFileData fDat    = FileWrapHelper.UnWrapObject(diskDat) as LocalFileData;

            if (fDat != null)
            {
                this.Alias               = fDat.Alias;
                this.IsContainer         = fDat.IsContainer;
                this.CreateDateTimeUTC   = fDat.CreateDateTimeUTC;
                this.ModifiedDateTimeUTC = fDat.ModifiedDateTimeUTC;
                this.Name    = fDat.Name;
                this.RawData = fDat.RawData;
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// 上级数据项
        /// </summary>
        /// <returns></returns>
        public override IDataItem GetParent()
        {
            DirectoryInfo tarDi = null;

            if (IsContainer)
            {
                tarDi = new DirectoryInfo(IdentityName.Replace('/', '\\')).Parent;
            }
            else
            {
                tarDi = new DirectoryInfo(Path.GetDirectoryName(IdentityName.Replace('/', '\\')));
            }

            if (!tarDi.Exists)
            {
                return(null);
            }
            else
            {
                LocalFileData fDat = new LocalFileData(tarDi.FullName);
                fDat.IsContainer = true;
                return(fDat);
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// 获取满足指定标志的数据集合
        /// </summary>
        /// <param name="containerIdentityName">父级容器标识名称,若为null或空则获取顶层相关数据。</param>
        /// <param name="filter">判断匹配规则</param>
        /// <param name="isMatch">匹配方向:true则匹配,false则为不匹配。</param>
        /// <returns>如果存在则返回集合,否则为null或空数组。</returns>
        public IDataItem[] GetDataList(string containerIdentityName, Predicate <IDataItem> filter, bool isMatch)
        {
            string tarDir = BaseDirectory;

            if (string.IsNullOrEmpty(containerIdentityName))
            {
                tarDir = Path.Combine(BaseDirectory, containerIdentityName.Replace('/', '\\'));
            }
            DirectoryInfo curDirInfo = new DirectoryInfo(tarDir);

            if (!curDirInfo.Exists)
            {
                return(null);
            }
            else
            {
                List <LocalFileData> fList = new List <LocalFileData>();
                LocalFileData        fDat  = null;
                #region 文件
                foreach (FileInfo file in curDirInfo.GetFiles())
                {
                    fDat             = new LocalFileData(file.FullName);
                    fDat.IsContainer = false;
                    if (filter == null)
                    {
                        fList.Add(fDat);
                    }
                    else
                    {
                        bool doAdd = (isMatch) ? filter(fDat) : !filter(fDat);
                        if (doAdd)
                        {
                            fList.Add(fDat);
                        }
                    }
                }
                #endregion

                #region 目录
                foreach (DirectoryInfo di in curDirInfo.GetDirectories())
                {
                    fDat             = new LocalFileData(di.FullName);
                    fDat.IsContainer = true;

                    if (filter == null)
                    {
                        fList.Add(fDat);
                    }
                    else
                    {
                        bool doAdd = (isMatch) ? filter(fDat) : !filter(fDat);
                        if (doAdd)
                        {
                            fList.Add(fDat);
                        }
                    }
                }
                #endregion
                return(fList.ToArray());
            }
        }