/// <summary> /// 保存特定数据 /// </summary> /// <param name="item">数据实例</param> public void Store(IDataItem item) { string tarPath = Path.Combine(BaseDirectory, item.IdentityName.Replace('/', '\\').Trim('\\')); if (item.IsContainer) { Directory.CreateDirectory(tarPath); tarPath += "\\" + FS_DIRDAT; } File.WriteAllBytes(tarPath, FileWrapHelper.WrapObject(item)); }
/// <summary> /// 获取指定标志的数据 /// </summary> /// <param name="identityName">数据标志号</param> /// <returns>如果存在该数据则返回,否则为null。</returns> public IDataItem GetData(string identityName) { string tarPath = Path.Combine(BaseDirectory, identityName.Replace('/', '\\').Trim('\\')); if (!File.Exists(tarPath)) { tarPath += "\\" + FS_DIRDAT; if (!File.Exists(tarPath)) { throw new NullReferenceException("指定标识数据[" + identityName + "]在存储系统中不存在!"); } } return(FileWrapHelper.UnWrapObject(File.ReadAllBytes(tarPath)) as IDataItem); }
/// <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; } }