/// <summary> /// 删除在compareList中已经存在的Material /// </summary> /// <param name="compareList"></param> private void RemoveExistsMaterials(MaterialList compareList) { foreach (Material cm in compareList) { this.Remove(m => string.Compare(m.ID, cm.ID, true) == 0); } }
public static void DoFilesCopy(MaterialList materials, string sourceRootPathName, string destRootPathName) { string sourceRootPath = AppPathConfigSettings.GetConfig().Paths[sourceRootPathName].Dir; string destRootPath = AppPathConfigSettings.GetConfig().Paths[destRootPathName].Dir; ExceptionHelper.CheckStringIsNullOrEmpty(sourceRootPath, "sourceRootPath"); ExceptionHelper.CheckStringIsNullOrEmpty(destRootPath, "destRootPath"); foreach (Material material in materials) { FileInfo sourceFile = new FileInfo(sourceRootPath + material.RelativeFilePath); if (sourceFile.Exists == false) { sourceFile = new FileInfo(sourceRootPath + @"Temp\" + Path.GetFileName(material.RelativeFilePath)); } if (sourceFile.Exists) { FileInfo destFile = new FileInfo(Path.Combine(destRootPath, Path.GetFileName(material.RelativeFilePath))); DoFileCopy(sourceFile, destFile); } } }
/// <summary> ///由MaterialList形成以主版本为跟节点各版本为子节点的树 /// </summary> /// <param name="materials">包含主版本和其他版本的集合</param> /// <param name="mainMaterialID">重版本ID</param> /// <returns>形成的树</returns> private MaterialTreeNode GenerateMaterialVersionTree(MaterialList materials, string mainMaterialID) { MaterialTreeNode rootNode = null; MaterialTreeNodeCollection materialTreeNodeCollection = new MaterialTreeNodeCollection(); foreach (Material m in materials) { if (string.Compare(m.ID, mainMaterialID, true) == 0) { rootNode = new MaterialTreeNode(m); } else if (m.ParentID == mainMaterialID) { MaterialTreeNode node = GenerateMaterialVersionTree(materials, m.ID); if (node != null) { materialTreeNodeCollection.Add(node); } } } if (rootNode != null) { foreach (MaterialTreeNode node in materialTreeNodeCollection) { rootNode.Children.Add(node); } } return(rootNode); }
public MaterialList LoadVersionMaterialsBySceneKey(string resourceID, string wfActivityName) { MaterialList copyVersionMaterials = new MaterialList(); WhereSqlClauseBuilder whereSqlClause = new WhereSqlClauseBuilder(); whereSqlClause.AppendItem("RESOURCE_ID", resourceID); whereSqlClause.AppendItem("VERSION_TYPE", Convert.ToInt16(MaterialVersionType.CopyVersion).ToString()); whereSqlClause.AppendItem("WF_ACTIVITY_NAME", wfActivityName); whereSqlClause.AppendTenantCode(typeof(Material)); string sql = string.Format("SELECT * FROM WF.MATERIAL WHERE {0}", whereSqlClause.ToSqlString(TSqlBuilder.Instance)); using (DbContext dbi = DbHelper.GetDBContext(GetConnectionName())) { using (IDataReader dr = DbHelper.RunSqlReturnDR(sql, GetConnectionName())) { while (dr.Read()) { Material material = new Material(); ORMapping.DataReaderToObject(dr, material); copyVersionMaterials.Add(material); } } } DecorateMaterials(copyVersionMaterials); return(copyVersionMaterials); }
/// <summary> /// 获得指定ID的Material /// </summary> /// <param name="materialID">指定ID</param> /// <returns>MaterialList</returns> public MaterialList LoadMaterialByMaterialID(string materialID) { ExceptionHelper.CheckStringIsNullOrEmpty(materialID, "materialID"); MaterialList materials = new MaterialList(); WhereSqlClauseBuilder wBuilder = new WhereSqlClauseBuilder(); wBuilder.AppendItem("ID", materialID); wBuilder.AppendTenantCode(typeof(Material)); string sql = "SELECT * FROM WF.MATERIAL WHERE " + wBuilder.ToSqlString(TSqlBuilder.Instance); using (DbContext dbi = DbHelper.GetDBContext(GetConnectionName())) { using (IDataReader dr = DbHelper.RunSqlReturnDR(sql, GetConnectionName())) { while (dr.Read()) { Material material = new Material(); ORMapping.DataReaderToObject(dr, material); materials.Add(material); } } } DecorateMaterials(materials); return(materials); }
/// <summary> /// 复制文件 /// </summary> /// <param name="materials">文件集合</param> /// <param name="sourceRootPathName">源文件的主路径的配置节点名称</param> /// <param name="destRootPathName">目标文件的主路径的配置节点名称</param> /// <param name="copyFromTempFolder">是否从临时文件夹拷贝文件</param> private static void DoFilesCopy(MaterialList materials, string sourceRootPathName, string destRootPathName, bool copyFromTempFolder) { string sourceRootPath = AppPathConfigSettings.GetConfig().Paths[sourceRootPathName].Dir; string destRootPath = AppPathConfigSettings.GetConfig().Paths[destRootPathName].Dir; ExceptionHelper.CheckStringIsNullOrEmpty(sourceRootPath, "sourceRootPath"); ExceptionHelper.CheckStringIsNullOrEmpty(destRootPath, "destRootPath"); foreach (Material material in materials) { ExceptionHelper.TrueThrow <ArgumentNullException>(material.SourceMaterial == null, "material.SourceMaterial"); FileInfo sourceFile; if (copyFromTempFolder) { sourceFile = new FileInfo(sourceRootPath + @"Temp\" + Path.GetFileName(material.SourceMaterial.RelativeFilePath)); } else { sourceFile = new FileInfo(sourceRootPath + material.SourceMaterial.RelativeFilePath); } if (sourceFile.Exists) { FileInfo destFile = new FileInfo(destRootPath + material.RelativeFilePath); DoFileCopy(sourceFile, destFile); } } }
public virtual void DecorateMaterialListAfterLoad(MaterialList materials) { materials.ForEach(i => { i.ShowFileUrl = i.ExtraDataDictionary.GetValue("showUrl", i.ShowFileUrl); }); }
/// <summary> /// 复制一个附件列表 /// </summary> /// <returns></returns> public MaterialList Clone() { MaterialList result = new MaterialList(); this.ForEach(m => result.Add(m.Clone())); return(result); }
/// <summary> /// 由资源ID查询,返回根据MaterialClass分组的MaterialGroupCollection对象 /// </summary> /// <param name="resourceIDs">资源ID</param> /// <returns>查询结果</returns> public MaterialGroupCollection LoadMaterialClassGroupByResourceID(params string[] resourceIDs) { MaterialList materials = LoadMaterialsByResourceID(resourceIDs); MaterialGroupCollection materialGroups = new MaterialGroupCollection(); materialGroups.FillGroupByMaterialClass(materials); return(materialGroups); }
/// <summary> /// 附加新的list /// </summary> /// <param name="materials">要附加的MaterialList</param> public void Append(MaterialList materials) { ExceptionHelper.TrueThrow <ArgumentNullException>(materials == null, "materials"); if (materials.Count != 0) { foreach (Material material in materials) { this.Add(material); } } }
/// <summary> /// 生成副本 /// </summary> /// <returns>生成的副本</returns> internal MaterialList GenerateCopyVersion() { ExceptionHelper.TrueThrow <ArgumentNullException>(this == null, "this"); MaterialList materialList = new MaterialList(); foreach (Material material in this) { materialList.Add(material.GenerateCopyVersion()); } return(materialList); }
/// <summary> /// 由类型分组 /// </summary> /// <returns></returns> public MaterialList GetMaterialsByClass(string className) { MaterialList materials = new MaterialList(); foreach (Material m in this) { if (m.MaterialClass == className) { materials.Add(m); } } return(materials); }
/// <summary> /// 获得指定操作的SQL语句 /// </summary> /// <param name="materials">material集合</param> /// <param name="fileOPList">文件操作集合</param> /// <param name="sqlDelegate">形成相应操作SQL语句的方法</param> /// <returns>形成的SQL语句</returns> private string GetMaterialsOperationSql(MaterialList materials, List <MaterialFileOeprationInfo> fileOPList, GetMaterialSqlOPDelegate sqlDelegate) { StringBuilder strB = new StringBuilder(256); for (int i = 0; i < materials.Count; i++) { if (strB.Length > 0) { strB.Append(TSqlBuilder.Instance.DBStatementSeperator); } strB.Append(sqlDelegate(materials[i], fileOPList)); } return(strB.ToString()); }
/// <summary> /// 产生文件版本 /// </summary> /// <param name="resourceID">新表单ID</param> /// <param name="wfProcessID">新工作流ID</param> /// <param name="wfActivityID">新工作流节点ID</param> /// <param name="wfActivityName">新工作流节点名称</param> /// <param name="department">产生的副本所在的部门</param> /// <returns>生成的副本</returns> public MaterialList GenerateOtherVersion(string resourceID, string wfProcessID, string wfActivityID, string wfActivityName, IOrganization department) { ExceptionHelper.TrueThrow <ArgumentNullException>(this == null, "this"); ExceptionHelper.CheckStringIsNullOrEmpty(resourceID, "resourceID"); ExceptionHelper.CheckStringIsNullOrEmpty(wfProcessID, "wfProcessID"); ExceptionHelper.CheckStringIsNullOrEmpty(wfActivityID, "wfActivityID"); MaterialList materialList = new MaterialList(); foreach (Material material in this) { materialList.Add(material.GenerateOtherVersion(resourceID, wfProcessID, wfActivityID, wfActivityName, department)); } return(materialList); }
/// <summary> /// 删除指定ResourceID的附件 /// </summary> /// <param name="rootPathName">根目录配置名称</param> /// <param name="resourceID">资源ID</param> private void InnerDeleteMaterialsByResourceID(string rootPathName, string resourceID) { ExceptionHelper.CheckStringIsNullOrEmpty(resourceID, "resourceID"); MaterialList materialList = this.LoadMaterialsByResourceID(resourceID); DeltaMaterialList deltaMaterialList = new DeltaMaterialList(); deltaMaterialList.RootPathName = rootPathName; foreach (Material material in materialList) { deltaMaterialList.Deleted.Add(material); } this.SaveDeltaMaterials(deltaMaterialList, string.IsNullOrEmpty(rootPathName) == false); }
/// <summary> /// 转化为附件集合 /// </summary> /// <returns>附件集合</returns> public MaterialList ConvertToMaterialList() { ExceptionHelper.TrueThrow <ArgumentNullException>(this == null, "MaterialModifyObjectCollection"); MaterialList materials = new MaterialList(); foreach (MaterialModifyObject materialModifyObject in this) { if (materialModifyObject != null) { Material m = materialModifyObject.ConvertToMaterial(); materials.Add(m); } } return(materials); }
/// <summary> /// 获得指定附件的副本 /// </summary> /// <param name="materials">附件集合</param> /// <returns>指定附件对应的副本集合</returns> internal MaterialList LoadCopyVersionMaterial(MaterialList materials) { ExceptionHelper.TrueThrow <ArgumentNullException>(materials == null, "materials"); MaterialList copyVersionMaterials = new MaterialList(); if (materials.Count != 0) { ConnectiveSqlClauseCollection orClause = new ConnectiveSqlClauseCollection(LogicOperatorDefine.Or); foreach (Material material in materials) { WhereSqlClauseBuilder whereSqlClause = new WhereSqlClauseBuilder(); whereSqlClause.AppendItem("PARENT_ID", material.ID); whereSqlClause.AppendItem("WF_ACTIVITY_ID", material.WfActivityID); whereSqlClause.AppendItem("VERSION_TYPE", (int)MaterialVersionType.CopyVersion); orClause.Add(whereSqlClause); } string sql = string.Format("SELECT * FROM WF.MATERIAL WHERE {0}", orClause.AppendTenantCodeSqlClause(typeof(Material)).ToSqlString(TSqlBuilder.Instance)); using (DbContext dbi = DbHelper.GetDBContext(GetConnectionName())) { using (IDataReader dr = DbHelper.RunSqlReturnDR(sql, GetConnectionName())) { while (dr.Read()) { Material material = new Material(); ORMapping.DataReaderToObject(dr, material); copyVersionMaterials.Add(material); } } } DecorateMaterials(copyVersionMaterials); } return(copyVersionMaterials); }
/// <summary> /// 获得指定ID的副本 和 它之前的一切副本 按照时间正排序 /// </summary> /// <param name="id">id</param> /// <returns>MaterialList</returns> public MaterialList GetPreMaterialsCopyVersion(string id) { ExceptionHelper.CheckStringIsNullOrEmpty(id, "id"); WhereSqlClauseBuilder whereSqlClause = new WhereSqlClauseBuilder(); whereSqlClause.AppendItem("PARENT_ID", string.Format("(SELECT PARENT_ID FROM WF.MATERIAL WHERE ID = {0})", TSqlBuilder.Instance.CheckQuotationMark(id, true)), "=", true); whereSqlClause.AppendItem("MODIFY_TIME", string.Format("(SELECT MODIFY_TIME FROM WF.MATERIAL WHERE ID = {0})", TSqlBuilder.Instance.CheckQuotationMark(id, true)), "<=", true); whereSqlClause.AppendTenantCode(typeof(Material)); OrderBySqlClauseBuilder orderBySqlClause = new OrderBySqlClauseBuilder(); orderBySqlClause.AppendItem("MODIFY_TIME", FieldSortDirection.Ascending); string sql = string.Format(@"SELECT * FROM WF.MATERIAL WHERE {0} AND VERSION_TYPE = {1} ORDER BY {2}" , whereSqlClause.ToSqlString(TSqlBuilder.Instance), Convert.ToInt16(MaterialVersionType.CopyVersion), orderBySqlClause.ToSqlString(TSqlBuilder.Instance)); MaterialList materials = new MaterialList(); using (DbContext dbi = DbHelper.GetDBContext(GetConnectionName())) { using (IDataReader dr = DbHelper.RunSqlReturnDR(sql, GetConnectionName())) { while (dr.Read()) { Material material = new Material(); ORMapping.DataReaderToObject(dr, material); materials.Add(material); } } } return(materials); }
/// <summary> /// 将变化的的附件合并到MaterialList中 /// </summary> /// <param name="delta"></param> public void Merge(DeltaMaterialList delta) { delta.NullCheck("delta"); MaterialList copiedMaterialed = new MaterialList(); copiedMaterialed.CopyFrom(this); copiedMaterialed.RemoveExistsMaterials(delta.Inserted); copiedMaterialed.RemoveExistsMaterials(delta.Updated); copiedMaterialed.RemoveExistsMaterials(delta.Deleted); copiedMaterialed.CopyFrom(delta.Inserted); copiedMaterialed.CopyFrom(delta.Updated); copiedMaterialed.Sort((m1, m2) => m1.SortID - m2.SortID); this.Clear(); this.CopyFrom(copiedMaterialed); }
/// <summary> /// 获得materialID对应的附件对象的所有版本和本身形成的树 /// 对应的存储过程GetMaterialVersions不存在 /// </summary> /// <param name="mainMaterialID">主版本ID</param> /// <returns>以主版本为跟节点各版本为子节点的树</returns> //[Obsolete("对应的存储过程GetMaterialVersions不存在")] public MaterialTreeNode LoadMaterialVersionsByMaterialID(string mainMaterialID) { ExceptionHelper.CheckStringIsNullOrEmpty(mainMaterialID, "mainMaterialID"); MaterialList materials = new MaterialList(); using (DbContext dbi = DbHelper.GetDBContext(GetConnectionName())) { Database db = DatabaseFactory.Create(dbi); using (SqlCommand dbc = new SqlCommand()) { SqlParameter sqlParameter = new SqlParameter(); sqlParameter.Value = mainMaterialID; sqlParameter.SqlDbType = SqlDbType.NVarChar; sqlParameter.Size = 36; sqlParameter.ParameterName = "@mainMaterialID"; sqlParameter.SourceColumn = "@mainMaterialID"; sqlParameter.Direction = ParameterDirection.InputOutput; dbc.CommandType = CommandType.StoredProcedure; dbc.CommandText = "GetMaterialVersions"; dbc.Parameters.Add(sqlParameter); using (IDataReader dr = db.ExecuteReader(dbc)) { while (dr.Read()) { Material material = new Material(); ORMapping.DataReaderToObject(dr, material); materials.Add(material); } } mainMaterialID = sqlParameter.Value.ToString(); } } return(GenerateMaterialVersionTree(materials, mainMaterialID)); }
/// <summary> /// 由资源ID查询 /// </summary> /// <param name="resourceIDs">资源ID</param> /// <returns>查询结果</returns> public MaterialList LoadMaterialsByResourceID(params string[] resourceIDs) { ExceptionHelper.TrueThrow <ArgumentNullException>(resourceIDs == null, "resourceIDs"); MaterialList result = new MaterialList(); if (resourceIDs.Length != 0) { InSqlClauseBuilder inBuilder = new InSqlClauseBuilder("RESOURCE_ID"); inBuilder.AppendItem(resourceIDs); OrderBySqlClauseBuilder orderClause = new OrderBySqlClauseBuilder(); orderClause.AppendItem("SORT_ID", FieldSortDirection.Ascending); string sql = string.Format("SELECT * FROM WF.MATERIAL WHERE {0} AND VERSION_TYPE = '{1}' ORDER BY {2}", inBuilder.AppendTenantCodeSqlClause(typeof(Material)).ToSqlString(TSqlBuilder.Instance), Convert.ToInt32(MaterialVersionType.Normal).ToString(), orderClause.ToSqlString(TSqlBuilder.Instance)); using (DbContext dbi = DbHelper.GetDBContext(GetConnectionName())) { using (IDataReader dr = DbHelper.RunSqlReturnDR(sql, GetConnectionName())) { while (dr.Read()) { Material material = new Material(); ORMapping.DataReaderToObject(dr, material); result.Add(material); } } } DecorateMaterials(result); } return(result); }
public void InsertWithContent(MaterialList materials) { materials.NullCheck("materials"); StringBuilder strB = new StringBuilder(); ORMappingItemCollection mappings = ORMapping.GetMappingInfo(typeof(Material)); foreach (Material m in materials) { if (strB.Length > 0) { strB.Append(TSqlBuilder.Instance.DBStatementSeperator); } InsertSqlClauseBuilder builder = ORMapping.GetInsertSqlClauseBuilder(m, mappings, "CreateDateTime"); builder.AppendItem("CREATE_DATETIME", m.CreateDateTime); strB.AppendFormat("INSERT INTO {0}{1}", mappings.TableName, builder.ToSqlString(TSqlBuilder.Instance)); } if (strB.Length > 0) { using (TransactionScope scope = TransactionScopeFactory.Create()) { DbHelper.RunSql(strB.ToString(), GetConnectionName()); foreach (Material m in materials) { m.Content.RelativeID = m.ResourceID; MaterialFileOeprationInfo fileOp = new MaterialFileOeprationInfo(m, FileOperation.Update); DoFileOperation(MaterialAdapter.DefaultUploadPathName, fileOp, m.Content); } scope.Complete(); } } }
/// <summary> /// 保存文件的版本 /// </summary> /// <param name="materials">已经做好的文件版本信息</param> /// <param name="rootPathName">根文件夹路径配置名称</param> public void SaveOtherVersion(MaterialList materials, string rootPathName) { StringBuilder strB = new StringBuilder(256); foreach (Material material in materials) { if (strB.Length > 0) { strB.Append(TSqlBuilder.Instance.DBStatementSeperator); } strB.Append(ORMapping.GetInsertSql <Material>(material, TSqlBuilder.Instance)); } if (strB.Length != 0) { using (TransactionScope scope = TransactionScopeFactory.Create(TransactionScopeOption.Required)) { DbHelper.RunSql(strB.ToString(), GetConnectionName()); DoFilesCopy(materials, rootPathName, rootPathName, false); scope.Complete(); } } }
private static void DecorateMaterials(MaterialList materials) { MaterialFileOperationSettings.GetConfig().Operations.ForEach(op => op.DecorateMaterialListAfterLoad(materials)); }
public void DecorateMaterialListAfterLoad(MaterialList materials) { //这里可以调整附件用于显示的Url //materials.ForEach(m => m.ShowFileUrl = "http://localhost/MCSWebApp/WebTestProject/OfficeViewer/pki.doc"); }