/// <summary> /// Maps the specified data object. /// </summary> /// <param name="source">The source object.</param> /// <param name="target">The target object.</param> /// <returns>A new data object instance.</returns> public T Map(T source, T target = default(T)) { Context.Source = source; Context.Target = target; if (Context.Target == null) { Context.Target = Activator.CreateInstance <T>(); _isTargetCreated = true; } if (Context.Properties == null) { Context.Properties = new List <string>(_fields ?? Enumerable.Empty <string>()); var element = _parser?.Element(); // Navigate the root element to map requested properties if (element != null) { Navigate(element); } } MapProjectedProperties(); return(Context.Target); }
/// <summary> /// Navigates the root element. /// </summary> /// <param name="returnElements">The return elements.</param> public virtual void Navigate(string returnElements) { // Check if to project fields Context.IsProjection = OptionsIn.ReturnElements.IdOnly.Equals(returnElements) || OptionsIn.ReturnElements.Requested.Equals(returnElements) || OptionsIn.ReturnElements.DataOnly.Equals(returnElements) || OptionsIn.ReturnElements.StationLocationOnly.Equals(returnElements); if (Context.Fields == null) { Context.Fields = new List <string>(); } var element = _parser.Element(); // Navigate the root element and create filter and projection fields Navigate(element); }
/// <summary> /// Executes partial delete. /// </summary> /// <param name="entity">The entity.</param> /// <param name="uri">The URI.</param> /// <param name="updates">The updates.</param> public void PartialDelete(T entity, EtpUri uri, Dictionary <string, object> updates) { Logger.Debug($"Partial deleting data object: {uri}"); _entityFilter = MongoDbUtility.GetEntityFilter <T>(uri, _idPropertyName); _entity = entity; Context.Update = Update(updates, uri.ObjectId); BuildPartialDelete(_parser.Element()); LogUpdateFilter(_entityFilter, Context.Update); _collection.UpdateOne(_entityFilter, Context.Update); // Remove recurring elements after all update because of the position being used in field path RemoveArrayElementsByDepth(); WitsmlOperationContext.Current.Warnings.AddRange(Context.Warnings); }