private async Task WriteValuesToIndexJob(IndexJob indexJob, VideoIndexResult videoIndexResult) { try { using (IObjectManager manager = this.Helper.GetServicesManager().CreateProxy <IObjectManager>(Relativity.API.ExecutionIdentity.System)) { var toUpdate = new RelativityObjectRef { ArtifactID = indexJob.JobArtifactID }; var fields = new FieldValue[] { new FieldValue("VideoID", videoIndexResult.VideoID), new FieldValue("Video File Name", videoIndexResult.VideoName), new FieldValue("DocumentControlNumber", videoIndexResult.ControlNumber) }; var updateRequest = new UpdateRequest { Object = toUpdate, FieldValues = fields }; await manager.UpdateAsync(indexJob.WorkspaceArtifactID, updateRequest); } } catch (Exception ex) { LogError(ex); } }
private async Task WriteValuesToDocumentObject(IndexJob indexJob, VideoIndexResult videoIndexResult) { try { using (IObjectManager manager = this.Helper.GetServicesManager().CreateProxy <IObjectManager>(Relativity.API.ExecutionIdentity.System)) { var toUpdate = new RelativityObjectRef { ArtifactID = indexJob.DocumentArtifactID }; var fieldValuePair = new FieldValue("Kramerica Video Transcript", videoIndexResult.Transcript); var updateRequest = new UpdateRequest { Object = toUpdate, FieldValues = new List <FieldRefValuePair> { fieldValuePair } }; await manager.UpdateAsync(indexJob.WorkspaceArtifactID, updateRequest); } } catch (Exception ex) { LogError(ex); } }
private async Task UpdateStatus(IndexJob indexJob, string status) { try { using (IObjectManager manager = this.Helper.GetServicesManager().CreateProxy <IObjectManager>(Relativity.API.ExecutionIdentity.System)) { var toUpdate = new RelativityObjectRef { ArtifactID = indexJob.JobArtifactID }; var fieldValuePair = new FieldValue("Status", status); var updateRequest = new UpdateRequest { Object = toUpdate, FieldValues = new List <FieldRefValuePair> { fieldValuePair } }; await manager.UpdateAsync(indexJob.WorkspaceArtifactID, updateRequest); } } catch (Exception ex) { LogError(ex); } }
private async Task SetGroupStatus(string status, bool trainingStatus) { string statusDetail = trainingStatus ? Constant.Group.COMPLETE : Constant.Group.INCOMPLETE; using (IObjectManager objectManager = Helper.GetServicesManager().CreateProxy <IObjectManager>(ExecutionIdentity.CurrentUser)) { RelativityObjectRef relativityObject = new RelativityObjectRef { ArtifactID = ActiveArtifact.ArtifactID }; FieldRefValuePair fieldValuePair = new FieldRefValuePair { Field = new FieldRef() { Guid = Constant.Guids.Field.FaceRecognitionGroup.TRAINING_STATUS }, Value = status + statusDetail }; UpdateRequest updateRequest = new UpdateRequest { Object = relativityObject, FieldValues = new List <FieldRefValuePair> { fieldValuePair } }; await objectManager.UpdateAsync(Helper.GetActiveCaseID(), updateRequest); } }
protected virtual void SerializeInlineObject(XmlNode xmlObject, object obj, IClassMap classMap, IPropertyMap propertyMap, bool creating) { IObjectManager om = this.Context.ObjectManager; object value = null; bool isNull = om.GetNullValueStatus(obj, propertyMap.Name); if (!(isNull)) { value = om.GetPropertyValue(obj, propertyMap.Name); if (value == null) { isNull = true; } } //Optimistic concurrency if (!(creating)) { //Check value in xmlDoc against property original value, make sure they match } if (isNull) { om.SetOriginalPropertyValue(obj, propertyMap.Name, System.DBNull.Value); RemoveNode(xmlObject, propertyMap.GetDocElement()); } else { om.SetOriginalPropertyValue(obj, propertyMap.Name, value); XmlNode xmlInline = GetNode(xmlObject, propertyMap.GetDocElement()); SerializeInlineObjectElement(xmlObject, obj, xmlInline, value, creating); } }
internal AdvertisementWatcher(object obj) { proxy = Connection.System.CreateProxy <IObjectManager>("org.bluez", ObjectPath.Root); deviceProperties = new Dictionary <ObjectPath, Dictionary <string, object> >(); stopActions = new Stack <Func <Task> >(); this.uuids = (Guid[])obj;; }
protected virtual void SerializeInlineReferenceList(XmlNode xmlObject, object obj, IClassMap classMap, IPropertyMap propertyMap, bool creating) { IObjectManager om = this.Context.ObjectManager; IListManager lm = this.Context.ListManager; IList list = (IList)om.GetPropertyValue(obj, propertyMap.Name); //Optimistic concurrency if (!(creating)) { //Check value in xmlDoc against property original value, make sure they match } XmlNode xmlList = GetNode(xmlObject, propertyMap.GetDocElement()); RemoveAllChildNodes(xmlList); foreach (object value in list) { XmlNode xmlElement = AddNode(xmlList, "item"); SerializeInlineReferenceElement(obj, xmlElement, value); } IList orgList = lm.CloneList(obj, propertyMap, ((IList)(om.GetPropertyValue(obj, propertyMap.Name)))); om.SetOriginalPropertyValue(obj, propertyMap.Name, orgList); }
protected virtual XmlNode FindNodeForObject(XmlNode xmlRoot, object obj, IClassMap classMap) { IObjectManager om = this.Context.ObjectManager; string element = classMap.GetDocElement(); string xpath = ""; foreach (IPropertyMap idPropertyMap in classMap.GetIdentityPropertyMaps()) { if (xpath.Length > 0) { xpath += " and "; // do not localize } if (idPropertyMap.DocElement.Length > 0) { xpath += idPropertyMap.Name + " = \"" + om.GetPropertyValue(obj, idPropertyMap.Name).ToString() + "\""; // do not localize } else { xpath += "@" + idPropertyMap.GetDocAttribute() + " = \"" + om.GetPropertyValue(obj, idPropertyMap.Name).ToString() + "\""; // do not localize } } xpath = element + "[" + xpath + "]"; XmlNode xmlNode = xmlRoot.SelectSingleNode(xpath); return(xmlNode); }
protected virtual void DeserializeInlineProperty(object obj, IClassMap classMap, IPropertyMap propertyMap, XmlNode xmlObject) { IObjectManager om = this.Context.ObjectManager; IPersistenceManager pm = this.Context.PersistenceManager; string element = propertyMap.DocElement; object xmlValue = null; bool isNull = true; if (element.Length > 0) { } else { string attribute = propertyMap.GetDocAttribute(); if (!(xmlObject.Attributes[attribute] == null)) { xmlValue = xmlObject.Attributes[attribute].Value; isNull = false; } else { xmlValue = DBNull.Value; isNull = true; } } object orgValue = FromString(obj, classMap, propertyMap, xmlValue); object value = pm.ManageLoadedValue(obj, propertyMap, orgValue); om.SetNullValueStatus(obj, propertyMap.Name, isNull); om.SetPropertyValue(obj, propertyMap.Name, value); om.SetOriginalPropertyValue(obj, propertyMap.Name, orgValue); }
public void RestoreFromClone(object obj) { IObjectManager om = this.Context.ObjectManager; IObjectClone clone = ((ICloneHelper)obj).GetObjectClone(); if (clone == null) { throw new EditException("Object has no cached clone!"); } IClassMap classMap = this.Context.DomainMap.MustGetClassMap(obj.GetType()); foreach (IPropertyMap propertyMap in classMap.GetAllPropertyMaps()) { if (propertyMap.IsCollection) { //TODO: Implement this } else { if (clone.HasOriginalValues(propertyMap.Name)) { om.SetOriginalPropertyValue(obj, propertyMap.Name, clone.GetOriginalPropertyValue(propertyMap.Name)); } om.SetPropertyValue(obj, propertyMap.Name, clone.GetPropertyValue(propertyMap.Name)); om.SetNullValueStatus(obj, propertyMap.Name, clone.GetNullValueStatus(propertyMap.Name)); om.SetUpdatedStatus(obj, propertyMap.Name, clone.GetUpdatedStatus(propertyMap.Name)); } } IIdentityHelper identityHelper = obj as IIdentityHelper; if (identityHelper != null) { identityHelper.SetIdentity(clone.GetIdentity()); if (clone.HasIdentityKeyParts()) { identityHelper.GetIdentityKeyParts().Clear(); foreach (object keyPart in clone.GetIdentityKeyParts()) { identityHelper.GetIdentityKeyParts().Add(keyPart); } } if (clone.HasKeyStruct()) { identityHelper.SetKeyStruct(clone.GetKeyStruct()); } } ObjectStatus objStatus = clone.GetObjectStatus(); om.SetObjectStatus(obj, objStatus); if (objStatus == ObjectStatus.NotRegistered) { this.Context.IdentityMap.UnRegisterCreatedObject(obj); } }
public async Task <Guid> ReadModelGuid(IServicesMgr serviceManager, int workspaceId, int modelId) { Guid returnValue = Guid.Empty; using (IObjectManager objectManager = serviceManager.CreateProxy <IObjectManager>(ExecutionIdentity.System)) { IEnumerable <FieldRef> fieldRefs = new List <FieldRef> { new FieldRef { Guid = Guids.Model.MODEL_GUID_FIELD } }; ReadRequest readRequest = new ReadRequest { Object = new RelativityObjectRef { ArtifactID = modelId }, Fields = fieldRefs }; ReadResult readReturnValue = await objectManager.ReadAsync(workspaceId, readRequest); ModelGuid = Guid.Parse(readReturnValue.Object.FieldValues.Find(x => x.Field.Guids.Contains(Guids.Model.MODEL_GUID_FIELD)).Value.ToString()); returnValue = ModelGuid; } return(returnValue); }
public bool AddObject <TEntity>( TEntity entity ) where TEntity : class { GetMockObjectSet <TEntity>().AddObject(entity); if (ShouldDeferObjectManagement) { return(true); } IObjectManager objectManager = entity as IObjectManager; if (!ReferenceEquals(objectManager, null)) { objectManager.ObjectFinishedLoading(); } IBusinessLogic businessLogic = entity as IBusinessLogic; if (!ReferenceEquals(businessLogic, null)) { businessLogic.OnAddObject(this); } return(true); }
public async static Task <int> GetFieldArtifactID(string fieldName, IEHHelper helper, IAPILog logger) { int fieldArtifactId = 0; using (IObjectManager objectManager = helper.GetServicesManager().CreateProxy <IObjectManager>(ExecutionIdentity.System)) { var queryRequest = new QueryRequest() { ObjectType = new ObjectTypeRef() { Name = "Field" }, Condition = $"'Name' == '{fieldName}' AND 'Object Type' == 'Document'" }; var queryResult = await objectManager.QuerySlimAsync(helper.GetActiveCaseID(), queryRequest, 0, 1); if (queryResult.TotalCount > 0) { fieldArtifactId = queryResult.Objects.Select(x => x.ArtifactID).FirstOrDefault(); logger.LogVerbose("Alert field artifactID: {fieldArtifactID}", fieldArtifactId); } } return(fieldArtifactId); }
public CORE.DAL.Entities.Comment GetCommentData(int commentAI) { CORE.DAL.Entities.Comment comment = new CORE.DAL.Entities.Comment(); using (IObjectManager OM = _helper.GetServicesManager().CreateProxy <IObjectManager>(ExecutionIdentity.CurrentUser)) { QueryRequest QR = new QueryRequest(); QR.ObjectType = new ObjectTypeRef() { Name = "Comment" }; QR.Condition = $"'Artifact ID' == {commentAI}"; QR.Fields = new List <FieldRef>() { new FieldRef() { Name = "Comment" }, new FieldRef() { Name = "System Created On" }, new FieldRef() { Name = "Thumbnail_Image_base64" } }; var task = OM.QueryAsync(_workspaceID, QR, 1, int.MaxValue); task.Wait(); comment.Name = task.Result.Objects.FirstOrDefault().FieldValues[0].Value.ToString(); comment.CreatedOn = task.Result.Objects.FirstOrDefault().FieldValues[1].Value.ToString(); comment.imageBase64 = task.Result.Objects.FirstOrDefault().FieldValues[2].Value.ToString(); } return(comment); }
/// <summary> /// Export documents only from a saved search /// </summary> /// <param name="objMgr"></param> /// <param name="workspaceId"></param> /// <param name="savedSearchId"></param> /// <param name="outDirectory"></param> /// <returns></returns> public static async Task ExportFromSavedSearchAsync( IObjectManager objMgr, int workspaceId, int savedSearchId, string outDirectory) { // specify a batch size const int BATCH_SIZE = 1000; // get all of the fields on the Document object List <Field> fields = await Common.GetAllFieldsForObject(objMgr, workspaceId, DOC_TYPE_ID); var query = new QueryRequest { ObjectType = new ObjectTypeRef { ArtifactTypeID = DOC_TYPE_ID }, // extracted text with size greater than this many // bytes will be streamed MaxCharactersForLongTextValues = 2000000, Condition = $"(('Artifact ID' IN SAVEDSEARCH {savedSearchId}))" }; Export(objMgr, workspaceId, BATCH_SIZE, fields, query, outDirectory); }
private async Task SetPersonStatus(int workspaceArtifactId, int personArtifactId, string status) { using (IObjectManager objectManager = Helper.GetServicesManager().CreateProxy <IObjectManager>(ExecutionIdentity.CurrentUser)) { //Set Status field for current Person RelativityObjectRef relativityObject = new RelativityObjectRef { ArtifactID = personArtifactId }; FieldRefValuePair fieldValuePair = new FieldRefValuePair { Field = new FieldRef() { Guid = Constant.Guids.Field.FaceRecognitionPerson.STATUS }, Value = status }; UpdateRequest updateRequest = new UpdateRequest { Object = relativityObject, FieldValues = new List <FieldRefValuePair> { fieldValuePair } }; UpdateResult updateResult = await objectManager.UpdateAsync(workspaceArtifactId, updateRequest); } }
protected virtual void HandleSlaveOneOnePropertySet(object obj, IPropertyMap propertyMap, object value, object oldValue) { this.Context.LogManager.Info(this, "Managing inverse one-one property relationship synchronization", "Writing to object of type: " + obj.GetType().ToString() + ", Property: " + propertyMap.Name); // do not localize IPropertyMap invPropertyMap = propertyMap.GetInversePropertyMap(); if (invPropertyMap == null) { return; } IObjectManager om = this.Context.ObjectManager; IUnitOfWork uow = this.Context.UnitOfWork; if (value != null) { om.EnsurePropertyIsLoaded(value, invPropertyMap); om.SetPropertyValue(value, invPropertyMap.Name, obj); om.SetNullValueStatus(value, invPropertyMap.Name, false); om.SetUpdatedStatus(value, invPropertyMap.Name, true); uow.RegisterDirty(value); this.Context.LogManager.Debug(this, "Wrote back-reference to inverse property", "Wrote to object of type: " + value.GetType().ToString() + ", Inverse Property: " + invPropertyMap.Name); // do not localize } if (oldValue != null) { om.EnsurePropertyIsLoaded(oldValue, invPropertyMap); om.SetPropertyValue(oldValue, invPropertyMap.Name, null); om.SetNullValueStatus(oldValue, invPropertyMap.Name, false); om.SetUpdatedStatus(oldValue, invPropertyMap.Name, true); uow.RegisterDirty(oldValue); this.Context.LogManager.Debug(this, "Wrote null to inverse property", "Wrote to object of type: " + oldValue.GetType().ToString() + ", Inverse Property: " + invPropertyMap.Name); // do not localize } }
//Follow all bi-directional references from the //object, setting the nullable, clean back references to null public virtual void RemoveInverseReferences(object obj) { this.Context.LogManager.Info(this, "Removing inverse references", obj.GetType().ToString()); // do not localize IObjectManager om = this.Context.ObjectManager; IClassMap classMap = this.Context.DomainMap.MustGetClassMap(obj.GetType()); IPropertyMap invPropertyMap; foreach (IPropertyMap propertyMap in classMap.GetAllPropertyMaps()) { if (!(propertyMap.ReferenceType == ReferenceType.None)) { if (propertyMap.Inverse.Length > 0) { invPropertyMap = propertyMap.GetInversePropertyMap(); if (invPropertyMap != null) { if (invPropertyMap.GetIsNullable()) { NullifyInverseReference(propertyMap, obj, invPropertyMap, om); } } } } } }
public ObjectPool(IObjectManager manager, bool autoCleanup = false) { this.m_id = SequenceId.NextId; this.m_manager = manager; this.m_data = new Dictionary<string, IObjectSet>(); this.m_autoCleanup = autoCleanup; }
protected virtual void PerformRemoveAction(InverseAction action) { object obj = action.Obj; string propertyName = action.PropertyName; object value = action.Value; IPropertyMap propertyMap = this.Context.DomainMap.MustGetClassMap(obj.GetType()).MustGetPropertyMap(propertyName); IObjectManager om = this.Context.ObjectManager; IList list; IInterceptableList mList; bool stackMute = false; om.EnsurePropertyIsLoaded(obj, propertyMap); list = (IList)om.GetPropertyValue(obj, propertyName); mList = list as IInterceptableList; if (mList != null) { stackMute = mList.MuteNotify; mList.MuteNotify = true; } list.Remove(value); if (mList != null) { mList.MuteNotify = stackMute; } om.SetUpdatedStatus(obj, propertyName, true); this.Context.LogManager.Debug(this, "Performed cached inverse action", "Action type: " + action.ActionType.ToString() + ", Wrote to object of type: " + obj.GetType().ToString() + ", Property: " + propertyName + ", Value object type: " + value.GetType().ToString()); // do not localize }
private async Task SetImageStatus(int workspaceArtifactId, int imageArtifactId, string status) { using (IObjectManager objectManager = CreateObjectManager()) { //Set Status field for current Image RelativityObjectRef relativityObject = new RelativityObjectRef { ArtifactID = imageArtifactId }; FieldRefValuePair fieldValuePair = new FieldRefValuePair { Field = new FieldRef() { Guid = Constant.Guids.Field.FaceRecognitionImage.STATUS }, Value = status }; UpdateRequest updateRequest = new UpdateRequest { Object = relativityObject, FieldValues = new List <FieldRefValuePair> { fieldValuePair } }; UpdateResult updateResult = await objectManager.UpdateAsync(workspaceArtifactId, updateRequest); } }
private async Task SetStatus(string status) { try { using (IObjectManager manager = this.Helper.GetServicesManager().CreateProxy <IObjectManager>(Relativity.API.ExecutionIdentity.System)) { var toUpdate = new RelativityObjectRef { ArtifactID = ActiveArtifact.ArtifactID }; var fieldValuePair = new FieldRefValuePair() { Field = new FieldRef() { Guid = ApplicationConstants.INDEX_JOB_STATUS }, Value = status }; var updateRequest = new UpdateRequest { Object = toUpdate, FieldValues = new FieldRefValuePair[] { fieldValuePair } }; await manager.UpdateAsync(this.Helper.GetActiveCaseID(), updateRequest); } } catch (Exception ex) { LogError(ex); } }
public async Task <string> GetGroupIdValue(int workspaceArtifactId, int groupArtifactId) { using (IObjectManager objectManager = CreateObjectManager()) { List <FieldRef> fieldRefs = new List <FieldRef> { new FieldRef { Guid = Constant.Guids.Field.FaceRecognitionGroup.GROUP_ID } }; ReadRequest readRequest = new ReadRequest { Object = new RelativityObjectRef { ArtifactID = groupArtifactId }, Fields = fieldRefs }; ReadResult readReturnValue = await objectManager.ReadAsync(workspaceArtifactId, readRequest); string groupId = readReturnValue.Object.FieldValues.Find(x => x.Field.Guids.Contains(Constant.Guids.Field.FaceRecognitionGroup.GROUP_ID)).Value.ToString(); return(groupId); } }
public ObjectPool(IObjectManager manager, bool autoCleanup = false) { this.m_id = SequenceId.NextId; this.m_manager = manager; this.m_data = new Dictionary <string, IObjectSet>(); this.m_autoCleanup = autoCleanup; }
public DrawTool() { this._3DControl = DF3DApplication.Application.Current3DMapControl; if (this._3DControl != null) { if (this._3DControl.Terrain.IsRegistered && this._3DControl.Terrain.VisibleMask != gviViewportMask.gviViewNone) { this._heightStyle = gviHeightStyle.gviHeightOnTerrain; } else { this._heightStyle = gviHeightStyle.gviHeightAbsolute; } this._objectManager = this._3DControl.ObjectManager; this._geoFactory = new GeometryFactory(); this._curveSymbol = new CurveSymbol(); this._curveSymbol.Width = 0; this._curveSymbol.Color = Convert.ToUInt32(SystemInfo.Instance.LineColor, 16); this._surfaceSymbol = new SurfaceSymbol(); this._surfaceSymbol.Color = Convert.ToUInt32(SystemInfo.Instance.FillColor, 16); this._surfaceSymbol.BoundarySymbol = this._curveSymbol; this._simplePointSymbol = new SimplePointSymbol(); this._simplePointSymbol.FillColor = Convert.ToUInt32(SystemInfo.Instance.LineColor, 16); this._simplePointSymbol.OutlineColor = Convert.ToUInt32(SystemInfo.Instance.LineColor, 16); this._simplePointSymbol.Size = 10; this._simplePointSymbol.Style = gviSimplePointStyle.gviSimplePointCircle; this._rootID = this._3DControl.ProjectTree.RootID; } }
public virtual void EnsurePropertyIsLoaded(object obj, IPropertyMap propertyMap) { IObjectManager om = this.Context.ObjectManager; IPersistenceEngine pe = this.Context.PersistenceEngine; ObjectStatus objStatus; PropertyStatus propStatus; objStatus = om.GetObjectStatus(obj); if (objStatus != ObjectStatus.Deleted) { if (objStatus == ObjectStatus.NotLoaded) { pe.LoadObject(ref obj); if (pe == null) { throw new ObjectNotFoundException("Object not found!"); // do not localize } } propStatus = om.GetPropertyStatus(obj, propertyMap.Name); if (propStatus == PropertyStatus.NotLoaded) { pe.LoadProperty(obj, propertyMap.Name); } } else { //We really ought to throw an exception here... } }
public async Task <string> GetGroupIdValue(int workspaceArtifactId, int groupArtifactId) { using (IObjectManager objectManager = Helper.GetServicesManager().CreateProxy <IObjectManager>(ExecutionIdentity.CurrentUser)) { IEnumerable <FieldRef> fieldRefs = new List <FieldRef> { new FieldRef { Guid = Helpers.Constant.Guids.Field.FaceRecognitionGroup.GROUP_ID } }; ReadRequest readRequest = new ReadRequest { Object = new RelativityObjectRef { ArtifactID = groupArtifactId }, Fields = fieldRefs }; ReadResult readReturnValue = await objectManager.ReadAsync(workspaceArtifactId, readRequest); string groupId = readReturnValue.Object.FieldValues.Find(x => x.Field.Guids.Contains(Constant.Guids.Field.FaceRecognitionGroup.GROUP_ID)).Value.ToString(); return(groupId); } }
public virtual void AbortInserted() { IObjectManager om = this.Context.ObjectManager; foreach (object obj in m_listInserted) { IClassMap classMap = this.Context.DomainMap.MustGetClassMap(obj.GetType()); //we must roll back autoincreasers if (classMap.HasAssignedBySource()) { foreach (IPropertyMap propertyMap in classMap.GetAllPropertyMaps()) { if (propertyMap.IsAssignedBySource) { string prevId = om.GetObjectIdentity(obj); om.SetPropertyValue(obj, propertyMap.Name, 0); this.Context.IdentityMap.UpdateIdentity(obj, prevId); } } } m_listCreated.Add(obj); om.SetObjectStatus(obj, ObjectStatus.UpForCreation); } m_listInserted.Clear(); }
private async Task SetGroupId(string groupId = null) { using (IObjectManager objectManager = Helper.GetServicesManager().CreateProxy <IObjectManager>(ExecutionIdentity.CurrentUser)) { RelativityObjectRef relativityObject = new RelativityObjectRef { ArtifactID = ActiveArtifact.ArtifactID }; FieldRefValuePair fieldValuePair = new FieldRefValuePair { Field = new FieldRef() { Guid = Constant.Guids.Field.FaceRecognitionGroup.GROUP_ID }, Value = groupId }; UpdateRequest updateRequest = new UpdateRequest { Object = relativityObject, FieldValues = new List <FieldRefValuePair> { fieldValuePair } }; await objectManager.UpdateAsync(Helper.GetActiveCaseID(), updateRequest); } }
public static async Task ToDTO_FieldIsYesNo_ReturnsCorrectValue(this IObjectManager manager, IHelper helper, int workspaceId, int docId) { //ARRANGE var fieldGuid = Guid.Parse(DocumentFieldDefinitions.YesNo); var client = helper.GetRSAPIClient(workspaceId); client.Repositories.Document.UpdateSingle(new Document(docId) { Fields = new List <FieldValue> { new FieldValue(fieldGuid, true) } }); //ACT var obj = SharedTestCases.CreateTestObject( docId, new FieldRef(fieldGuid), true); var result = await manager.ReadAsync(workspaceId, obj, null); var dto = result.ToDTODocument(); var fieldValue = dto[fieldGuid].ValueAsYesNo; //ASSERT Assert.True(fieldValue); Assert.Equal(kCura.Relativity.Client.FieldType.YesNo, dto[fieldGuid].FieldType); }
public IObjectClone CloneObject(object obj) { IObjectManager om = this.Context.ObjectManager; IObjectClone clone = new ObjectClone(); IClassMap classMap = this.Context.DomainMap.MustGetClassMap(obj.GetType()); foreach (IPropertyMap propertyMap in classMap.GetAllPropertyMaps()) { if (propertyMap.IsCollection) { } else { if (om.HasOriginalValues(obj, propertyMap.Name)) { clone.SetPropertyValue(propertyMap.Name, om.GetPropertyValue(obj, propertyMap.Name)); clone.SetOriginalPropertyValue(propertyMap.Name, om.GetOriginalPropertyValue(obj, propertyMap.Name)); clone.SetNullValueStatus(propertyMap.Name, om.GetNullValueStatus(obj, propertyMap.Name)); clone.SetUpdatedStatus(propertyMap.Name, om.GetUpdatedStatus(obj, propertyMap.Name)); } } } clone.SetObjectStatus(om.GetObjectStatus(obj)); this.clonedObjects.Add(obj); return(clone); }
protected ManagedTester(IObjectManager objectManager, params string[] databaseNames) { dbsToAdd = databaseNames; this.objectManager = objectManager; }
private void LoadProperty(object obj, IPropertyMap propertyMap, IObjectManager om, object source, IPropertyMap sourcePropertyMap, IObjectManager sourceOm) { if (!Monitor.TryEnter(sourceContext, this.Context.Timeout)) throw new NPersistTimeoutException("Could not aquire exclusive lock on root context before timeout: " + this.Context.Timeout.ToString() + " ms" ); try { bool nullValueStatus; object value; if (propertyMap.ReferenceType == ReferenceType.None) { if (!(propertyMap.IsCollection)) { value = sourceOm.GetPropertyValue(source, sourcePropertyMap.Name); nullValueStatus = sourceOm.GetNullValueStatus(source, sourcePropertyMap.Name); om.SetPropertyValue(obj, propertyMap.Name, value); if (nullValueStatus) { om.SetOriginalPropertyValue(obj, propertyMap.Name, DBNull.Value); } else { om.SetOriginalPropertyValue(obj, propertyMap.Name, value); } om.SetNullValueStatus(obj, propertyMap.Name, nullValueStatus); } else { //Using CloneList will work when it is only primitive values //(or immutable objects such as strings and dates) //that can be copied between contexts IList list = (IList) sourceOm.GetPropertyValue(source, sourcePropertyMap.Name); IList listClone = this.Context.ListManager.CloneList(obj, propertyMap, list); IList listCloneOrg = this.Context.ListManager.CloneList(obj, propertyMap, list); om.SetPropertyValue(obj, propertyMap.Name, listClone); om.SetOriginalPropertyValue(obj, propertyMap.Name, listCloneOrg); } } else { if (!(propertyMap.IsCollection)) { object refObject = sourceOm.GetPropertyValue(source, sourcePropertyMap.Name); if (refObject == null) { om.SetPropertyValue(obj, propertyMap.Name, null); om.SetOriginalPropertyValue(obj, propertyMap.Name, null); om.SetNullValueStatus(obj, propertyMap.Name, true); } else { string identity = sourceOm.GetObjectIdentity(refObject); Type refType = ToLeafType(refObject); //Impossible to solve for inheritance scenarios when mapping presentation model to domain model!!!! //We could try checking which presentation domain map which class map that maps to the //domain class map, but that could be a many-one relationship (many presentation model classes //map to the same domain model class!) // IClassMap sourceOrgClassMap = this.sourceContext.DomainMap.GetClassMap(orgObject.GetType() ); // IClassMap leafOrgClassMap = this.sourceContext.DomainMap.GetClassMap(sourceOrgClassMap.Name ); // IClassMap theClassMap = this.sourceContext.DomainMap.GetClassMap (sourceOrgClassMap.Name ); value = this.Context.GetObjectById(identity, refType, true); nullValueStatus = sourceOm.GetNullValueStatus(source, sourcePropertyMap.Name); om.SetPropertyValue(obj, propertyMap.Name, value); om.SetOriginalPropertyValue(obj, propertyMap.Name, value); om.SetNullValueStatus(obj, propertyMap.Name, nullValueStatus); } } else { //Using CloneList will not work when there are reference values (to mutable objects) //that can be copied between contexts IList orgList = (IList) sourceOm.GetPropertyValue(source, sourcePropertyMap.Name); IList list = (IList) om.GetPropertyValue(obj, sourcePropertyMap.Name); this.LoadReferenceList(list, orgList); //for the org-list we can use ListManager.CloneList and clone the list of leaf objects IList listOrg = this.Context.ListManager.CloneList(obj, propertyMap, list); om.SetPropertyValue(obj, propertyMap.Name, list); om.SetOriginalPropertyValue(obj, propertyMap.Name, listOrg); } } } finally { Monitor.Exit(sourceContext); } }
public FileManager(IObjectManager objectManager) { _ObjectManager = objectManager; }
private void RefreshProperty(IObjectManager om, object targetObject, IPropertyMap propertyMap, IPersistenceManager pm, RefreshBehaviorType refreshBehavior, object value, out bool doWrite, out bool doWriteOrg) { doWrite = false; doWriteOrg = false; PropertyStatus propStatus = om.GetPropertyStatus(targetObject, propertyMap.Name); IClassMap classMap = this.Context.DomainMap.MustGetClassMap(targetObject.GetType()); RefreshBehaviorType useRefreshBehavior = pm.GetRefreshBehavior(refreshBehavior, classMap, propertyMap); if (useRefreshBehavior == RefreshBehaviorType.OverwriteNotLoaded || useRefreshBehavior == RefreshBehaviorType.DefaultBehavior) { //Overwrite both value and original far all unloaded properties if (propStatus == PropertyStatus.NotLoaded) { doWrite = true; doWriteOrg = true; } } else if (useRefreshBehavior == RefreshBehaviorType.OverwriteLoaded) { //Overwrite original for all properties //Overwrite value for all clean or unloaded properties (but not for dirty or deleted properties) doWriteOrg = true; if (propStatus == PropertyStatus.Clean || propStatus == PropertyStatus.NotLoaded) doWrite = true; } else if (useRefreshBehavior == RefreshBehaviorType.ThrowConcurrencyException) { //Overwrite original for all properties unless the old originial value and the fresh value from the //database mismatch, in that case raise an exception //Overwrite value for all clean or unloaded properties (but not for dirty or deleted properties) if (propStatus == PropertyStatus.Clean || propStatus == PropertyStatus.NotLoaded || propStatus == PropertyStatus.Dirty) { if (!(propStatus == PropertyStatus.NotLoaded)) { object testValue = om.GetOriginalPropertyValue(targetObject,propertyMap.Name); object testValue2 = value; if (DBNull.Value.Equals(testValue)) { testValue = null; } if (DBNull.Value.Equals(testValue2)) { testValue2 = null; } if (testValue2 != testValue) { string cachedValue = "null"; string freshValue = "null"; try { if (testValue != null) cachedValue = testValue.ToString() ; } catch { ; } try { if (value != null) freshValue = value.ToString() ; } catch { ; } throw new RefreshException("A refresh concurrency exception occurred when refreshing a cached object of type " + targetObject.GetType().ToString() + " with fresh data from the data source. The data source row has been modified since the last time this version of the object was loaded, specifically the value for property " + propertyMap.Name + ". (this exception occurs because ThrowConcurrencyExceptions refresh behavior was selected). Cashed value: " + cachedValue + ", Fresh value: " + freshValue, cachedValue, freshValue, targetObject, propertyMap.Name); // do not localize } } if (!(propStatus == PropertyStatus.Dirty)) doWrite = true; } } else if (useRefreshBehavior == RefreshBehaviorType.OverwriteDirty) { //Overwrite original for all properties //Overwrite value for all clean, unloaded or dirty properties (but not for deleted properties) doWriteOrg = true; if (!(propStatus == PropertyStatus.Deleted)) doWrite = true; } else { throw new NPersistException("Unknown object refresh behavior specified!"); // do not localize } }
private void NullifyInverseReference(IPropertyMap propertyMap, object obj, IPropertyMap invPropertyMap, IObjectManager om) { bool stackMute = false; IInterceptableList mList; IList refList; IList list; object thisObj; object refObj; //Ensure that the property is loaded if (this.Context.GetPropertyStatus(obj, propertyMap.Name) == PropertyStatus.NotLoaded) { this.Context.LoadProperty(obj, propertyMap.Name); } if (propertyMap.IsCollection) { list = (IList) om.GetPropertyValue(obj, propertyMap.Name); if (list == null) { list = this.Context.ListManager.CreateList(obj, propertyMap); } if (list != null) { if (invPropertyMap.IsCollection) { foreach (object itemRefObj in list) { ObjectStatus refObjStatus = om.GetObjectStatus(itemRefObj); if (!(refObjStatus.Equals(ObjectStatus.UpForDeletion) && refObjStatus.Equals(ObjectStatus.Deleted))) { //Ensure inverse is loaded PropertyStatus invPropertyStatus = this.Context.GetPropertyStatus(itemRefObj, invPropertyMap.Name); if (invPropertyMap.IsSlave && invPropertyStatus == PropertyStatus.NotLoaded) { AddAction(InverseActionType.Remove, itemRefObj, invPropertyMap.Name, obj, obj); } else { if (invPropertyStatus == PropertyStatus.NotLoaded) this.Context.LoadProperty(itemRefObj, invPropertyMap.Name); refList = ((IList) (om.GetPropertyValue(itemRefObj, invPropertyMap.Name))); if (refList.Contains(obj)) { mList = refList as IInterceptableList; if (mList != null) { stackMute = mList.MuteNotify; mList.MuteNotify = true; } refList.Remove(obj); if (mList != null) { mList.MuteNotify = stackMute; } om.SetUpdatedStatus(itemRefObj, invPropertyMap.Name, true); } } } } } else { foreach (object itemRefObj in list) { ObjectStatus refObjStatus = om.GetObjectStatus(itemRefObj); if (!(refObjStatus.Equals(ObjectStatus.UpForDeletion) && refObjStatus.Equals(ObjectStatus.Deleted))) { PropertyStatus invPropertyStatus = this.Context.GetPropertyStatus(itemRefObj, invPropertyMap.Name); if (invPropertyMap.IsSlave && invPropertyStatus == PropertyStatus.NotLoaded) { AddAction(InverseActionType.Set, itemRefObj, invPropertyMap.Name, null, obj); } else { //Ensure inverse is loaded if (invPropertyStatus == PropertyStatus.NotLoaded) this.Context.LoadProperty(itemRefObj, invPropertyMap.Name); thisObj = om.GetPropertyValue(itemRefObj, invPropertyMap.Name); if (thisObj != null) { if (thisObj == obj) { om.SetPropertyValue(itemRefObj, invPropertyMap.Name, null); om.SetUpdatedStatus(itemRefObj, invPropertyMap.Name, true); } } } } } } } } else { refObj = om.GetPropertyValue(obj, propertyMap.Name); if (refObj != null) { ObjectStatus refObjStatus = om.GetObjectStatus(refObj); if (!(refObjStatus.Equals(ObjectStatus.UpForDeletion) && refObjStatus.Equals(ObjectStatus.Deleted))) { PropertyStatus invPropertyStatus = this.Context.GetPropertyStatus(refObj, invPropertyMap.Name); //Ensure inverse is loaded if (invPropertyMap.IsSlave && invPropertyStatus == PropertyStatus.NotLoaded) { if (invPropertyMap.IsCollection) { AddAction(InverseActionType.Remove, refObj, invPropertyMap.Name, obj, obj); } else { AddAction(InverseActionType.Set, refObj, invPropertyMap.Name, null, obj); } } else { if (invPropertyStatus == PropertyStatus.NotLoaded) this.Context.LoadProperty(refObj, invPropertyMap.Name); if (invPropertyMap.IsCollection) { refList = ((IList) (om.GetPropertyValue(refObj, invPropertyMap.Name))); if (refList.Contains(obj)) { mList = refList as IInterceptableList; if (mList != null) { stackMute = mList.MuteNotify; mList.MuteNotify = true; } refList.Remove(obj); if (mList != null) {mList.MuteNotify = stackMute;} om.SetUpdatedStatus(refObj, invPropertyMap.Name, true); } } else { thisObj = om.GetPropertyValue(refObj, invPropertyMap.Name); if (thisObj != null) { //only update back ref if it is actually pointing at me if (thisObj == obj) { om.SetPropertyValue(refObj, invPropertyMap.Name, null); om.SetUpdatedStatus(refObj, invPropertyMap.Name, true); } } } } } } } }
private void MergeSingleRefProperty(IObjectManager om, object obj, IClassMap classMap, IPropertyMap propertyMap, object existing, bool forOrgValue, PropertyStatus propStatus, PropertyStatus extPropStatus, MergeBehaviorType mergeBehavior) { string extOrgObjId; string refObjId; object extRefObj; object refObj; object extOrgObj; if (forOrgValue) { refObj = om.GetOriginalPropertyValue(obj, propertyMap.Name); extOrgObj = om.GetOriginalPropertyValue(existing, propertyMap.Name); } else { refObj = om.GetPropertyValue(obj, propertyMap.Name); extOrgObj = om.GetPropertyValue(existing, propertyMap.Name); } if (refObj != null && DBNull.Value.Equals(refObj) != true) { //hmmmm won't this fail if we have two objects of different classes but with the same id? //probably the type should be included (and preferably change to KeyStruct comparisons...) refObjId = om.GetObjectIdentity(refObj); extOrgObjId = ""; if (extOrgObj != null) extOrgObjId = om.GetObjectIdentity(extOrgObj); if (!refObjId.Equals(extOrgObjId)) { bool keepExisting = KeepExistingValue(refObj, extOrgObj, mergeBehavior, classMap, propertyMap, existing, obj, propStatus, extPropStatus, forOrgValue); if (keepExisting != true) { extRefObj = this.Context.GetObjectById(refObjId, refObj.GetType()); SetSingleRefPropetyValue(forOrgValue, om, existing, propertyMap, extRefObj, propStatus); } } } else { if (extOrgObj != null) { bool keepExisting = KeepExistingValue(refObj, extOrgObj, mergeBehavior, classMap, propertyMap, existing, obj, propStatus, extPropStatus, forOrgValue); if (keepExisting) { SetSingleRefPropetyValue(forOrgValue, om, existing, propertyMap, null, propStatus); } } } }
private void LoadReferenceList(IList list, IList orgList, IObjectManager om, object obj, IPropertyMap propertyMap) { IList objectsToRemove = new ArrayList(); IList objectsToAdd = new ArrayList(); foreach (object itemOrgObj in orgList) { string itemOrgObjId = om.GetObjectIdentity(itemOrgObj); bool found = false; foreach (object itemObj in list) { string itemObjId = om.GetObjectIdentity(itemObj); if (itemObjId == itemOrgObjId) { found = true; break; } } if (!found) objectsToRemove.Add(itemOrgObj); } foreach (object itemObj in list) { string itemObjId = om.GetObjectIdentity(itemObj); bool found = false; foreach (object itemOrgObj in orgList) { string itemOrgObjId = om.GetObjectIdentity(itemOrgObj); if (itemObjId == itemOrgObjId) { found = true; break; } } if (!found) { object itemOrgObj = this.Context.GetObjectById(itemObjId, itemObj.GetType(), true); objectsToAdd.Add(itemOrgObj); } } if (objectsToRemove.Count > 0 || objectsToAdd.Count > 0) { bool stackMute = false; IInterceptableList mList = orgList as IInterceptableList; if (mList != null) { stackMute = mList.MuteNotify; mList.MuteNotify = true; } foreach (object itemOrgObj in objectsToRemove) orgList.Remove(itemOrgObj); foreach (object itemOrgObj in objectsToAdd) orgList.Add(itemOrgObj); if (mList != null) { mList.MuteNotify = stackMute; } } bool iStackMute = false; IInterceptableList iList = orgList as IInterceptableList; if (iList != null) { iStackMute = iList.MuteNotify; iList.MuteNotify = true; } IList listClone = new ArrayList( orgList); if (iList != null) { iList.MuteNotify = iStackMute; } om.SetOriginalPropertyValue(obj, propertyMap.Name, listClone); }
private bool ExamineWaitForNode(IObjectManager om, object delObj, object waitForObj) { IClassMap waitForObjClassMap = this.Context.DomainMap.MustGetClassMap(waitForObj.GetType()); foreach (IPropertyMap propertyMap in waitForObjClassMap.GetAllPropertyMaps()) { if (!propertyMap.IsReadOnly && !propertyMap.IsSlave) { if (propertyMap.ReferenceType != ReferenceType.None) { if (propertyMap.IsCollection) { IList list = (IList) om.GetPropertyValue(waitForObj, propertyMap.Name); if (list != null) { foreach (object itemRefObj in list) { if (itemRefObj == delObj) { return false; } } } } else { object refObj = om.GetPropertyValue(waitForObj, propertyMap.Name); if (refObj != null) { if (refObj == delObj) { return false; } } } } } } return true; }
protected virtual void EvaluatePropertySpecialBehavior(object obj, IPropertyMap propertyMap, PropertySpecialBehaviorType specialBehavior, IObjectManager om) { bool wrote = false; if (specialBehavior == PropertySpecialBehaviorType.Increase) { om.SetPropertyValue(obj, propertyMap.Name, Convert.ToInt64(om.GetPropertyValue(obj, propertyMap.Name)) + 1); wrote = true; } else if (specialBehavior == PropertySpecialBehaviorType.SetDateTime) { om.SetPropertyValue(obj, propertyMap.Name, DateTime.Now); wrote = true; } if (wrote) { om.SetNullValueStatus(obj, propertyMap.Name, false); om.SetUpdatedStatus(obj, propertyMap.Name, true); } }
private void NullifyUniReference(object obj, object refering, IPropertyMap uniRefPropertyMap, IObjectManager om) { bool stackMute = false; IInterceptableList mList; IList refList; object thisObj; if (uniRefPropertyMap.IsCollection) { if (!(this.Context.GetPropertyStatus(refering, uniRefPropertyMap.Name) == PropertyStatus.NotLoaded)) { refList = ((IList) (om.GetPropertyValue(refering, uniRefPropertyMap.Name))); if (refList.Contains(obj)) { mList = refList as IInterceptableList; if (mList != null) { stackMute = mList.MuteNotify; mList.MuteNotify = true; } refList.Remove(obj); if (mList != null) { mList.MuteNotify = stackMute; } om.SetUpdatedStatus(refering, uniRefPropertyMap.Name, true); } } } else { if (!(this.Context.GetPropertyStatus(refering, uniRefPropertyMap.Name) == PropertyStatus.NotLoaded)) { thisObj = this.Context.ObjectManager.GetPropertyValue(refering, uniRefPropertyMap.Name); if (thisObj != null) { if (thisObj == obj) { this.Context.ObjectManager.SetPropertyValue(refering, uniRefPropertyMap.Name, null); om.SetUpdatedStatus(refering, uniRefPropertyMap.Name, true); } } } } }
public virtual void UpdateAutoIncIdProperty(IObjectManager om, object obj, IClassMap classMap, object newId) { IContext ctx = m_SqlEngineManager.Context; string prevId; string autoPropName; IPropertyMap autoProp; object autoID = null; prevId = om.GetObjectIdentity(obj); autoProp = classMap.GetAutoIncreasingIdentityPropertyMap(); autoPropName = autoProp.Name; PropertyInfo propInfo = obj.GetType().GetProperty(autoProp.Name); if (propInfo.PropertyType == typeof(System.Int64)) { autoID = Convert.ToInt64(newId); } else if (propInfo.PropertyType == typeof(System.Int16)) { autoID = Convert.ToInt16(newId); } else if (propInfo.PropertyType == typeof(System.Double)) { autoID = Convert.ToDouble(newId); } else if (propInfo.PropertyType == typeof(System.Decimal)) { autoID = Convert.ToDecimal(newId); } else { autoID = Convert.ToInt32(newId); } om.SetPropertyValue(obj, autoPropName, autoID); //om.SetOriginalPropertyValue(obj, autoPropName, autoID); om.SetNullValueStatus(obj, autoPropName, false); ctx.IdentityMap.UpdateIdentity(obj, prevId); }
private void MergeSingleRefProperty(IObjectManager om, object obj, IClassMap classMap, IPropertyMap propertyMap, object existing, bool forOrgValue, PropertyStatus propStatus, PropertyStatus extPropStatus, MergeBehaviorType mergeBehavior) { string extOrgObjId; string refObjId; object extRefObj; object refObj; object extOrgObj; if (forOrgValue) { refObj = om.GetOriginalPropertyValue(obj, propertyMap.Name); extOrgObj = om.GetOriginalPropertyValue(existing, propertyMap.Name); } else { refObj = om.GetPropertyValue(obj, propertyMap.Name); extOrgObj = om.GetPropertyValue(existing, propertyMap.Name); } if (refObj != null && DBNull.Value.Equals(refObj) != true) { refObjId = om.GetObjectIdentity(refObj); extOrgObjId = ""; if (extOrgObj != null) extOrgObjId = om.GetObjectIdentity(extOrgObj); if (!refObjId.Equals(extOrgObjId)) { bool keepExisting = KeepExistingValue(refObj, extOrgObj, mergeBehavior, classMap, propertyMap, existing, obj, propStatus, extPropStatus, forOrgValue); if (keepExisting != true) { extRefObj = this.Context.GetObjectById(refObjId, refObj.GetType()); SetSingleRefPropetyValue(forOrgValue, om, existing, propertyMap, extRefObj, propStatus); } } } else { if (extOrgObj != null) { bool keepExisting = KeepExistingValue(refObj, extOrgObj, mergeBehavior, classMap, propertyMap, existing, obj, propStatus, extPropStatus, forOrgValue); if (keepExisting) { SetSingleRefPropetyValue(forOrgValue, om, existing, propertyMap, null, propStatus); } } } }
private void MergePrimitiveProperty(IObjectManager om, object obj, IClassMap classMap, IPropertyMap propertyMap, object existing, bool forOrgValue, PropertyStatus propStatus, PropertyStatus extPropStatus, MergeBehaviorType mergeBehavior) { if (forOrgValue) { object value = om.GetPropertyValue(obj, propertyMap.Name); object extValue = om.GetPropertyValue(existing, propertyMap.Name); MergePrimitivePropertyValues(value, extValue, propStatus, extPropStatus, om, existing, classMap, propertyMap, obj, forOrgValue, mergeBehavior); } else { object orgValue = om.GetOriginalPropertyValue(obj, propertyMap.Name); object extOrgValue = om.GetOriginalPropertyValue(existing, propertyMap.Name); MergePrimitivePropertyValues(orgValue, extOrgValue, propStatus, extPropStatus, om, existing, classMap, propertyMap, obj, forOrgValue, mergeBehavior); } }
private void MergeListRefProperty(IObjectManager om, object obj, IClassMap classMap, IPropertyMap propertyMap, object existing, PropertyStatus propStatus, PropertyStatus extPropStatus, bool forOrgValue, MergeBehaviorType mergeBehavior) { IList list = ((IList) om.GetPropertyValue(obj, propertyMap.Name)); IList orgList = ((IList) om.GetPropertyValue(existing, propertyMap.Name)); MergeReferenceLists(list, orgList, om, obj, mergeBehavior, classMap, propertyMap, existing, propStatus, extPropStatus, forOrgValue); }
protected void CopyValuesToOriginals(IPropertyMap propertyMap, IListManager lm, object obj, IObjectManager om) { if (propertyMap.IsCollection) { IList list = lm.CloneList(obj, propertyMap, ((IList) (om.GetPropertyValue(obj, propertyMap.Name)))); om.SetOriginalPropertyValue(obj, propertyMap.Name, list); } else { if (om.GetNullValueStatus(obj, propertyMap.Name)) { om.SetOriginalPropertyValue(obj, propertyMap.Name, System.DBNull.Value); } else { om.SetOriginalPropertyValue(obj, propertyMap.Name, om.GetPropertyValue(obj, propertyMap.Name)); } } }
private void SetSingleRefPropetyValue(bool forOrgValue, IObjectManager om, object existing, IPropertyMap propertyMap, object value, PropertyStatus propStatus) { IUnitOfWork uow = this.Context.UnitOfWork; if (forOrgValue) om.SetOriginalPropertyValue(existing, propertyMap.Name, value); else { om.SetPropertyValue(existing, propertyMap.Name, value); if (value == null) om.SetNullValueStatus(existing, propertyMap.Name, true); else om.SetNullValueStatus(existing, propertyMap.Name, false); if (propStatus == PropertyStatus.Dirty) { uow.RegisterDirty(existing); om.SetUpdatedStatus(existing, propertyMap.Name, true); } } }
protected virtual Hashtable GetConcernedTableMaps(object obj, int exceptionLimit, Hashtable tableMaps, IDomainMap dm, IObjectManager om, bool update) { if (obj == null) return null; ITableMap tableMap = null; IClassMap classMap = dm.MustGetClassMap(obj.GetType()); if (classMap.Table != "") { tableMap = classMap.GetTableMap(); if (tableMap != null) tableMaps[tableMap] = tableMap; foreach (IPropertyMap propertyMap in classMap.GetAllPropertyMaps()) { if (propertyMap.Table != "") { if (!(propertyMap.IsSlave || propertyMap.IsReadOnly)) { bool ok = true; if (update) { PropertyStatus propStatus = om.GetPropertyStatus(obj, propertyMap.Name); if (propStatus != PropertyStatus.Dirty) ok = false; } if (ok) { tableMap = propertyMap.GetTableMap(); if (tableMap != null) tableMaps[tableMap] = tableMap; } } } } } return tableMaps; }
private void MergePrimitivePropertyValues(object value, object extValue, PropertyStatus propStatus, PropertyStatus extPropStatus, IObjectManager om, object existing, IClassMap classMap, IPropertyMap propertyMap, object obj, bool forOrgValue, MergeBehaviorType mergeBehavior) { if (!value.Equals(extValue)) // May be to naive - possibly should use some advanced method like ComparePropertyValues.. { bool keepExisting = KeepExistingValue(value, extValue, mergeBehavior, classMap, propertyMap, existing, obj, propStatus, extPropStatus, forOrgValue); if (!keepExisting) { if (forOrgValue) { om.SetPropertyValue(existing, propertyMap.Name, value); om.SetNullValueStatus(existing, propertyMap.Name, om.GetNullValueStatus(obj, propertyMap.Name)); if (propStatus == PropertyStatus.Dirty) { this.Context.UnitOfWork.RegisterDirty(existing); om.SetUpdatedStatus(existing, propertyMap.Name, true); } } else { om.SetOriginalPropertyValue(existing, propertyMap.Name, value); } } } }
private void ExamineDeletedObject(Hashtable hashDeleted, IObjectManager om, object delObj) { IClassMap delObjClassMap = this.Context.DomainMap.MustGetClassMap(delObj.GetType()); foreach (IPropertyMap propertyMap in delObjClassMap.GetAllPropertyMaps()) { if (!propertyMap.IsReadOnly && !propertyMap.IsSlave) { if (propertyMap.ReferenceType != ReferenceType.None) { if (propertyMap.IsCollection) { //It is the value in the database, not the current value, that is of importance //for avoiding violations of the foreign key constraint //IList list = (IList) om.GetPropertyValue(delObj, propertyMap.Name); IList list = (IList) om.GetOriginalPropertyValue(delObj, propertyMap.Name); if (list != null) { foreach (object itemRefObj in list) { object isDeleted = hashDeleted[itemRefObj]; if (isDeleted != null) { m_topologicalDelete.AddNode(itemRefObj, delObj); } } } } else { //It is the value in the database, not the current value, that is of importance //for avoiding violations of the foreign key constraint //object refObj = om.GetPropertyValue(delObj, propertyMap.Name); object refObj = om.GetOriginalPropertyValue(delObj, propertyMap.Name); if (refObj != null) { object isDeleted = hashDeleted[refObj]; if (isDeleted != null) { m_topologicalDelete.AddNode(refObj, delObj); } } } } } } }
private void MergeReferenceLists(IList list, IList orgList, IObjectManager om, object obj, MergeBehaviorType mergeBehavior, IClassMap classMap, IPropertyMap propertyMap, object existing, PropertyStatus propStatus, PropertyStatus extPropStatus, bool forOrgValue) { IList objectsToRemove = new ArrayList(); IList objectsToAdd = new ArrayList(); IUnitOfWork uow = this.Context.UnitOfWork; foreach (object itemOrgObj in orgList) { string itemOrgObjId = om.GetObjectIdentity(itemOrgObj); bool found = false; foreach (object itemObj in list) { string itemObjId = om.GetObjectIdentity(itemObj); if (itemObjId == itemOrgObjId) { found = true; break; } } if (!found) objectsToRemove.Add(itemOrgObj); } foreach (object itemObj in list) { string itemObjId = om.GetObjectIdentity(itemObj); bool found = false; foreach (object itemOrgObj in orgList) { string itemOrgObjId = om.GetObjectIdentity(itemOrgObj); if (itemObjId == itemOrgObjId) { found = true; break; } } if (!found) { object itemOrgObj = this.Context.GetObjectById(itemObjId, obj.GetType()); objectsToAdd.Add(itemOrgObj); } } if (objectsToRemove.Count > 0 || objectsToAdd.Count > 0) { bool keepExisting = KeepExistingValue(list, orgList, mergeBehavior, classMap, propertyMap, existing, obj, propStatus, extPropStatus, forOrgValue); if (!keepExisting) { bool stackMute = false; IInterceptableList mList = orgList as IInterceptableList; if (mList != null) { stackMute = mList.MuteNotify; mList.MuteNotify = true; } foreach (object itemOrgObj in objectsToRemove) orgList.Remove(itemOrgObj); foreach (object itemOrgObj in objectsToAdd) orgList.Add(itemOrgObj); if (mList != null) { mList.MuteNotify = stackMute; } if (propStatus == PropertyStatus.Dirty) { uow.RegisterDirty(existing); om.SetUpdatedStatus(existing, propertyMap.Name, true); } } } }
protected void CopyValuesToOriginals(IPropertyMap propertyMap, IListManager lm, object obj, IObjectManager om) { if (propertyMap.IsCollection) { //IList list = lm.CloneList(obj, propertyMap, ((IList) (om.GetPropertyValue(obj, propertyMap.Name)))); IInterceptableList list = om.GetPropertyValue(obj, propertyMap.Name) as IInterceptableList; IList orgList = null; if (list != null) { bool stackMute = list.MuteNotify; list.MuteNotify = true; orgList = new ArrayList( list ); list.MuteNotify = stackMute; } om.SetOriginalPropertyValue(obj, propertyMap.Name, orgList); } else { if (om.GetNullValueStatus(obj, propertyMap.Name)) { om.SetOriginalPropertyValue(obj, propertyMap.Name, System.DBNull.Value); } else { om.SetOriginalPropertyValue(obj, propertyMap.Name, om.GetPropertyValue(obj, propertyMap.Name)); } } }