protected void BeforeInnerUpdate(Material data) { data.FillExtraData(data.ExtraDataDictionary); }
/// <summary> /// 序列化DeltaMaterial /// </summary> /// <param name="obj">DeltaMaterial对象</param> /// <param name="serializer">序列化器</param> /// <returns>属性集合</returns> public override IDictionary<string, object> Serialize(object obj, JavaScriptSerializer serializer) { Dictionary<string, object> dictionary = new Dictionary<string, object>(); DeltaMaterialList deltaMaterialList = (DeltaMaterialList)obj; Material[] insertedMaterials = new Material[deltaMaterialList.Inserted.Count]; for (int i = 0; i < insertedMaterials.Length; i++) insertedMaterials[i] = deltaMaterialList.Inserted[i]; dictionary.Add("insertedMaterials", insertedMaterials); Material[] updatedMaterials = new Material[deltaMaterialList.Updated.Count]; for (int i = 0; i < updatedMaterials.Length; i++) updatedMaterials[i] = deltaMaterialList.Updated[i]; dictionary.Add("updatedMaterials", updatedMaterials); Material[] deletedMaterials = new Material[deltaMaterialList.Deleted.Count]; for (int i = 0; i < deletedMaterials.Length; i++) deletedMaterials[i] = deltaMaterialList.Deleted[i]; dictionary.Add("deletedMaterials", deletedMaterials); dictionary.Add("rootPathName", deltaMaterialList.RootPathName); return dictionary; }
/// <summary> /// 获得删除操作的SQL语句 /// </summary> /// <param name="material">要处理的material</param> /// <param name="fileOPList">文件操作</param> /// <returns>形成的SQL语句</returns> private string GetDeleteMaterialSql(Material material, List<MaterialFileOeprationInfo> fileOPList) { fileOPList.Add(new MaterialFileOeprationInfo(material, FileOperation.Delete)); return string.Format("DELETE WF.MATERIAL WHERE {0}", ORMapping.GetWhereSqlClauseBuilderByPrimaryKey<Material>(material).ToSqlString(TSqlBuilder.Instance)); }
/// <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> /// 获得插入操作的SQL语句 /// </summary> /// <param name="material">要处理的material</param> /// <param name="fileOPList">文件操作</param> /// <returns>形成的SQL语句</returns> private string GetInsertMaterialSql(Material material, List<MaterialFileOeprationInfo> fileOPList) { BeforeInnerUpdate(material); fileOPList.Add(new MaterialFileOeprationInfo(material, FileOperation.Add)); return ORMapping.GetInsertSql<Material>(material, TSqlBuilder.Instance); }
/// <summary> /// 获得修改操作的SQL语句 /// </summary> /// <param name="material">要处理的material</param> /// <param name="fileOPList">文件操作</param> /// <returns>形成的SQL语句</returns> private string GetUpdateMaterialSql(Material material, List<MaterialFileOeprationInfo> fileOPList) { BeforeInnerUpdate(material); fileOPList.Add(new MaterialFileOeprationInfo(material, FileOperation.Update)); if (material.Department == null || material.Creator == null) { return ORMapping.GetUpdateSql<Material>(material, TSqlBuilder.Instance, new string[] { "Creator", "Department" }); } else { return ORMapping.GetUpdateSql<Material>(material, TSqlBuilder.Instance); } }
/// <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; }
public Material Clone() { Material newMaterial = new Material(); newMaterial.id = this.id; newMaterial.Department = this.department; newMaterial.resourceID = this.resourceID; newMaterial.sortID = this.sortID; newMaterial.materialClass = this.materialClass; newMaterial.title = this.title; newMaterial.pageQuantity = this.pageQuantity; newMaterial.relativeFilePath = this.relativeFilePath.Replace(this.id, newMaterial.ID); newMaterial.originalName = this.originalName; newMaterial.creator = this.creator; newMaterial.lastUploadTag = this.lastUploadTag; newMaterial.createDateTime = this.createDateTime; newMaterial.modifyTime = this.modifyTime; newMaterial.wfProcessID = wfProcessID; newMaterial.wfActivityID = wfActivityID; newMaterial.wfActivityName = wfActivityName; newMaterial._SourceMaterialID = this.id; newMaterial.versionType = MaterialVersionType.Normal; newMaterial.extraData = this.extraData; newMaterial.showFileUrl = this.showFileUrl; if (this._Content != null) newMaterial._Content = this._Content.Clone(); return newMaterial; }
/// <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; }
/// <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); }
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; }
public MaterialFileOeprationInfo(Material m, FileOperation op) { material = m; operation = op; }
/// <summary> /// 生成副本 /// </summary> /// <returns>生成的副本</returns> public Material GenerateCopyVersion() { ExceptionHelper.TrueThrow<ArgumentNullException>(this == null, "this"); Material material = new Material(); material.id = Guid.NewGuid().ToString(); material.Department = this.department; material.resourceID = this.resourceID; material.sortID = this.sortID; material.materialClass = this.materialClass; material.title = this.title; material.pageQuantity = this.pageQuantity; material.relativeFilePath = this.relativeFilePath.Replace(this.id, material.ID); material.originalName = this.originalName; if (DeluxePrincipal.IsAuthenticated) material.Creator = (IUser)OguUser.CreateWrapperObject(DeluxeIdentity.CurrentRealUser); material.lastUploadTag = this.lastUploadTag; material.createDateTime = DateTime.Now; material.modifyTime = this.modifyTime; material.wfProcessID = this.wfProcessID; material.wfActivityID = this.wfActivityID; material.wfActivityName = this.wfActivityName; material.parentID = this.id; material.sourceMaterial = this; material.versionType = MaterialVersionType.CopyVersion; material.extraData = this.extraData; material.showFileUrl = this.showFileUrl; return material; }
/// <summary> /// 序列化MultiMaterial /// </summary> /// <param name="obj">MultiMaterial对象</param> /// <param name="serializer">序列化器</param> /// <returns>属性集合</returns> public override IDictionary<string, object> Serialize(object obj, JavaScriptSerializer serializer) { Dictionary<string, object> dictionary = new Dictionary<string, object>(); MultiMaterialList multiMaterialList = (MultiMaterialList)obj; Material[] materials = new Material[multiMaterialList.Materials.Count]; for (int i = 0; i < materials.Length; i++) materials[i] = multiMaterialList.Materials[i]; dictionary.Add("materials", materials); dictionary.Add("deltaMaterials", multiMaterialList.DeltaMaterials); return dictionary; }
/// <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> ///反序列化material /// </summary> /// <param name="dictionary">对象类型</param> /// <param name="type">对象类型</param> /// <param name="serializer">JS序列化器</param> /// <returns>反序列化出的对象</returns> public override object Deserialize(IDictionary<string, object> dictionary, Type type, JavaScriptSerializer serializer) { Material material = new Material(); object id = string.Empty; if (dictionary.TryGetValue("id", out id)) material.ID = id.ToString(); //object oguOrganization; //if (dictionary.TryGetValue("department", out oguOrganization)) // material.Department = JSONSerializerExecute.Deserialize<OguOrganization>(oguOrganization); object resourceID = string.Empty; if (dictionary.TryGetValue("resourceID", out resourceID)) material.ResourceID = (resourceID == null ? string.Empty : resourceID.ToString()); object sortID = 0; if (dictionary.TryGetValue("sortID", out sortID)) material.SortID = int.Parse(sortID.ToString()); object materialClass = string.Empty; if (dictionary.TryGetValue("materialClass", out materialClass)) material.MaterialClass = (materialClass == null ? string.Empty : materialClass.ToString()); object title = string.Empty; if (dictionary.TryGetValue("title", out title)) material.Title = title.ToString(); object pageQuantity = string.Empty; if (dictionary.TryGetValue("pageQuantity", out pageQuantity)) material.PageQuantity = int.Parse(pageQuantity.ToString()); object relativeFilePath = string.Empty; if (dictionary.TryGetValue("relativeFilePath", out relativeFilePath)) material.RelativeFilePath = relativeFilePath.ToString(); object originalName = string.Empty; if (dictionary.TryGetValue("originalName", out originalName)) material.OriginalName = originalName.ToString(); //object oguUser; //if (dictionary.TryGetValue("creator", out oguUser)) // material.Creator = JSONSerializerExecute.Deserialize<OguUser>(oguUser); object lastUploadTag = string.Empty; if (dictionary.TryGetValue("lastUploadTag", out lastUploadTag)) material.LastUploadTag = lastUploadTag != null ? lastUploadTag.ToString() : string.Empty; object createDateTime; if (dictionary.TryGetValue("createDateTime", out createDateTime)) material.CreateDateTime = createDateTime == null ? DateTime.Now : DateTime.Parse(createDateTime.ToString()); object modifyTime; if (dictionary.TryGetValue("modifyTime", out modifyTime)) material.ModifyTime = (DateTime)modifyTime; //material.ModifyTime = modifyTime == null ? DateTime.Now.ToLocalTime() : DateTime.Parse(modifyTime.ToString()).ToLocalTime(); object wfProcessID = string.Empty; if (dictionary.TryGetValue("wfProcessID", out wfProcessID)) material.WfProcessID = (wfProcessID == null ? string.Empty : wfProcessID.ToString()); object wfActivityID = string.Empty; if (dictionary.TryGetValue("wfActivityID", out wfActivityID)) material.WfActivityID = (wfActivityID == null ? string.Empty : wfActivityID.ToString()); object wfActivityName = string.Empty; if (dictionary.TryGetValue("wfActivityName", out wfActivityName)) material.WfActivityName = (wfActivityName == null ? string.Empty : wfActivityName.ToString()); object parentID = string.Empty; if (dictionary.TryGetValue("parentID", out parentID)) material.ParentID = (parentID == null ? string.Empty : parentID.ToString()); object versionType = string.Empty; if (dictionary.TryGetValue("versionType", out versionType)) material.VersionType = (MaterialVersionType)Convert.ToInt32(versionType.ToString()); object extraData = null; if (dictionary.TryGetValue("extraData", out extraData)) { if (extraData is Dictionary<string, Object>) { material.ExtraDataDictionary.Clear(); foreach (var item in (Dictionary<string, Object>)extraData) { material.ExtraDataDictionary.Add(item.Key, item.Value.ToString()); } } } object showFileUrl = string.Empty; if (dictionary.TryGetValue("showFileUrl", out showFileUrl)) material.ShowFileUrl = showFileUrl.ToString(); return material; }
/// <summary> /// 产生文件版本 /// </summary> /// <param name="rootPath">文件夹所在根目录路径</param> /// <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 Material 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"); Material material = new Material(); material.id = Guid.NewGuid().ToString(); material.Department = department; material.resourceID = resourceID; material.sortID = this.sortID; material.materialClass = this.materialClass; material.title = this.title; material.pageQuantity = this.pageQuantity; material.relativeFilePath = this.relativeFilePath.Replace(this.id, material.ID); material.originalName = this.originalName; material.creator = this.creator; material.lastUploadTag = this.lastUploadTag; material.createDateTime = this.createDateTime; material.modifyTime = this.modifyTime; material.wfProcessID = wfProcessID; material.wfActivityID = wfActivityID; material.wfActivityName = wfActivityName; material.parentID = this.id; material.sourceMaterial = this; material.versionType = MaterialVersionType.Normal; material.extraData = this.extraData; material.showFileUrl = this.showFileUrl; return material; }