public static bool IsReferenceLoaded <TEntity, TProperty>( this HookingDbContext ctx, TEntity entity, Expression <Func <TEntity, TProperty> > navigationProperty, out ReferenceEntry <TEntity, TProperty> referenceEntry) where TEntity : BaseEntity where TProperty : BaseEntity { Guard.NotNull(entity, nameof(entity)); Guard.NotNull(navigationProperty, nameof(navigationProperty)); referenceEntry = null; if (entity.Id == 0) { return(false); } var entry = ctx.Entry(entity); referenceEntry = entry.Reference(navigationProperty); // Avoid System.InvalidOperationException: Member 'IsLoaded' cannot be called for property... if (entry.State == EfState.Detached || entry.State == EfState.Added) { return(referenceEntry.CurrentValue != null); } return(referenceEntry.IsLoaded); }
private List <AuditPropertyDto> GetValueObjectAuditProperties(string entityName, ReferenceEntry reference, string?prefix = null) { if (reference.TargetEntry == null) { throw new Exception("TargetEntry is null."); } var state = reference.TargetEntry.State; var fromValues = reference.TargetEntry.OriginalValues; var toValues = reference.TargetEntry.CurrentValues; if (state == EntityState.Added || state == EntityState.Deleted) { toValues = null; } var auditProperties = GetAuditProperties(entityName, state, prefix + "." + reference.Metadata.Name, fromValues, toValues); foreach (var childReference in reference.TargetEntry.References) { if (childReference.TargetEntry?.Entity is DbValueObject) { var childProps = GetValueObjectAuditProperties(entityName, childReference, prefix: reference.Metadata.Name); auditProperties.AddRange(childProps); } } return(auditProperties); }
public virtual bool hasNext() { checkMod(); while (nextNull()) { ReferenceEntry e = entry; int i = index; while ((e == null) && (i > 0)) { i--; e = (ReferenceEntry)parent.data[i]; } entry = e; index = i; if (e == null) { currentKey = null; currentValue = null; return(false); } nextKey = e.getKey(); nextValue = e.getValue(); if (nextNull()) { entry = entry.next(); } } return(true); }
public void AddReference([NotNull] string tagName, PermittedGender gender, int minage, int maxAge, double referenceValue) { var re = new ReferenceEntry(tagName, gender, minage, maxAge, referenceValue); _referenceEntries.Add(re); }
static Reference CreateReference(ReferenceEntry entry) { ITextBuffer fileContent = GetFileContent(entry.fileName); string expression = fileContent.GetText(entry.minChar, entry.length); return(new Reference(entry.fileName, entry.minChar, entry.length, expression, null)); }
private void ProcessEntry(ReferenceEntry referenceEntry) { if (!referenceEntry.IsLoaded) { referenceEntry.Load(); } var dependentEntry = referenceEntry.CurrentValue; if (dependentEntry == null) { return; } switch (referenceEntry.Metadata.ForeignKey.DeleteBehavior) { // We only have to process changes in database, // about changes on the client side the ef core will take care. case DeleteBehavior.Cascade: Remove(dependentEntry); break; case DeleteBehavior.SetNull: SetNull(Entry(dependentEntry), referenceEntry.Metadata.ForeignKey); break; // Do nothing for other cases } }
/// <summary> /// Adds the specified unmanaged object reference. /// </summary> /// <param name="t">The t.</param> /// <param name="ptr">The r.</param> /// <param name="location">The location.</param> public void Add(UnmanagedType t, IntPtr ptr, string location) { #if DEBUG lock (SyncLock) Instances[ptr] = new ReferenceEntry() { Instance = ptr, Type = t, Location = location }; #endif }
public void AddReference(string id, byte[] digest) { if (this.count == this.references.Length) { ReferenceEntry[] destinationArray = new ReferenceEntry[this.references.Length * 2]; Array.Copy(this.references, 0, destinationArray, 0, this.count); this.references = destinationArray; } this.references[this.count++].Set(id, digest); }
public void AddReference(string id, byte[] digest, bool useStrTransform) { if (this.count == this.references.Length) { ReferenceEntry[] newReferences = new ReferenceEntry[this.references.Length * 2]; Array.Copy(this.references, 0, newReferences, 0, this.count); this.references = newReferences; } this.references[this.count++].Set(id, digest, useStrTransform); }
/// <summary> /// Adds the specified unmanaged object reference. /// </summary> /// <param name="unmanagedType">Type of the unmanaged.</param> /// <param name="pointer">The pointer.</param> /// <param name="memberName">Name of the member.</param> /// <param name="filePath">The file path.</param> /// <param name="lineNumber">The line number.</param> private void AddInternal(UnmanagedType unmanagedType, IntPtr pointer, string memberName, string filePath, int lineNumber) { if (MediaEngine.Platform.IsInDebugMode == false) { return; } lock (SyncLock) Instances[pointer] = new ReferenceEntry(unmanagedType, pointer, memberName, filePath, lineNumber); }
static SearchResultMatch CreateSearchResultMatch(ReferenceEntry entry) { ITextSource textSource = SD.FileService.GetFileContent(entry.fileName); var document = new ReadOnlyDocument(textSource, entry.fileName); TextLocation start = document.GetLocation(entry.minChar); TextLocation end = document.GetLocation(entry.minChar + entry.length); IHighlighter highlighter = SD.EditorControlService.CreateHighlighter(document); return(SearchResultMatch.Create(document, start, end, highlighter)); }
/// <summary> /// Adds the specified unmanaged object reference. /// </summary> /// <param name="unmanagedType">Type of the unmanaged.</param> /// <param name="pointer">The pointer.</param> /// <param name="memberName">Name of the member.</param> /// <param name="filePath">The file path.</param> /// <param name="lineNumber">The line number.</param> private void Addpublic(UnmanagedType unmanagedType, IntPtr pointer, string memberName, string filePath, int lineNumber) { if (!Debugger.IsAttached) { return; } lock (SyncLock) Instances[pointer] = new ReferenceEntry(unmanagedType, pointer, memberName, filePath, lineNumber); }
private void UpdateChildren(ReferenceEntry refi) { if (refi.TargetEntry != null) { refi.TargetEntry.State = EntityState.Modified; foreach (var refii in refi.TargetEntry.References) { UpdateChildren(refii); } } }
private void AtualizarReferencias(ReferenceEntry refi) { if (refi.TargetEntry != null) { refi.TargetEntry.State = EntityState.Modified; foreach (var refii in refi.TargetEntry.References) { AtualizarReferencias(refii); } } }
public virtual void LoadReference <TProperty>(TEntity entity, Expression <Func <TEntity, TProperty> > member) where TProperty : class { Attach(entity); ReferenceEntry <TEntity, TProperty> reference = _dbContext.Entry(entity).Reference(member); if (reference.IsLoaded == false) { reference.Load(); } }
public virtual async Task LoadReferenceAsync <TProperty>(TEntity entity, Expression <Func <TEntity, TProperty> > member, CancellationToken cancellationToken) where TProperty : class { Attach(entity); ReferenceEntry <TEntity, TProperty> reference = _dbContext.Entry(entity).Reference(member); if (reference.IsLoaded == false) { await reference.LoadAsync(cancellationToken).ConfigureAwait(false); } }
public virtual void remove() { checkMod(); if (previous == null) { throw new java.lang.IllegalStateException(); } parent.remove(currentKey); previous = null; currentKey = null; currentValue = null; expectedModCount = parent.modCount; }
/// <summary> /// Adds the specified unmanaged object reference. /// </summary> /// <param name="t">The t.</param> /// <param name="ptr">The r.</param> /// <param name="location">The location.</param> public void Add(UnmanagedType t, IntPtr ptr, string location) { if (MediaEngine.Platform.IsInDebugMode == false) { return; } lock (SyncLock) Instances[ptr] = new ReferenceEntry() { Instance = ptr, Type = t, Location = location }; }
bool IsCorlibReference(ReferenceEntry re) { TargetRuntime tr; TargetFramework fx; string file; if (ProjectDomService.ParseAssemblyUri(re.Uri, out tr, out fx, out file)) { return(Path.GetFileNameWithoutExtension(file) == "mscorlib"); } else { return(false); } }
protected virtual ReferenceEntry nextEntry() { checkMod(); if (nextNull() && !hasNext()) { throw new java.util.NoSuchElementException(); } previous = entry; entry = entry.next(); currentKey = nextKey; currentValue = nextValue; nextKey = null; nextValue = null; return(previous); }
public virtual void LoadReference <TProperty>(TDto dto, Expression <Func <TDto, TProperty> > member) where TProperty : class { try { Attach(dto); ReferenceEntry <TDto, TProperty> reference = _dbContext.Entry(dto).Reference(member); if (reference.IsLoaded == false) { reference.Load(); } } finally { Detach(dto); } }
public virtual async Task LoadReferenceAsync <TProperty>(TDto dto, Expression <Func <TDto, TProperty> > member, CancellationToken cancellationToken) where TProperty : class { try { Attach(dto); ReferenceEntry <TDto, TProperty> reference = _dbContext.Entry(dto).Reference(member); if (reference.IsLoaded == false) { await reference.LoadAsync(cancellationToken).ConfigureAwait(false); } } finally { Detach(dto); } }
public void AddReference(string id, byte[] digest, bool useStrTransform) { if (!LocalAppContextSwitches.AllowUnlimitedXmlReferences) { long maximumNumberOfReferences = SecurityUtils.GetMaxXmlReferencesPerSignedInfo(); if (ReferenceCount > maximumNumberOfReferences) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new CryptographicException()); } } if (this.count == this.references.Length) { ReferenceEntry[] newReferences = new ReferenceEntry[this.references.Length * 2]; Array.Copy(this.references, 0, newReferences, 0, this.count); this.references = newReferences; } this.references[this.count++].Set(id, digest, useStrTransform); }
public static void Work_with_a_single_navigation_1() { Console.WriteLine($">>>> Sample: {nameof(Work_with_a_single_navigation_1)}"); Console.WriteLine(); Helpers.RecreateCleanDatabase(); Helpers.PopulateDatabase(); using var context = new BlogsContext(); var post = context.Posts.Include(e => e.Blog).Single(e => e.Id == 1); #region Work_with_a_single_navigation_1 ReferenceEntry <Post, Blog> referenceEntry1 = context.Entry(post).Reference(e => e.Blog); ReferenceEntry <Post, Blog> referenceEntry2 = context.Entry(post).Reference <Blog>("Blog"); ReferenceEntry referenceEntry3 = context.Entry(post).Reference("Blog"); #endregion Console.WriteLine(); }
public override bool OnInitialize() { //ResourceNode n; //if ((n = Root.FindNode(DataOffset)) != null) // _name = n.Name; //else _name = "Lookup" + Index; int val; if ((val = *(bint *)Header) == -1) { ReferenceEntry ext = _root.TryGetExternal(_offset); if (ext != null) { _name = ext.Name; } return(false); } return(false); }
private TreeNode newTreeNode(object obj) { TreeNode n = new TreeNode(); if (obj is ModelClass) { ModelClass c = (ModelClass)obj; n.Tag = c; n.Text = c.Name; n.ImageIndex = 3; n.SelectedImageIndex = 3; c.Updated += new ModelClassEventHandler(classUpdated); } else if (obj is ModelEnum) { ModelEnum e = (ModelEnum)obj; n.Tag = e; n.Text = e.Name; n.ImageIndex = 5; n.SelectedImageIndex = 5; } else if (obj is ReferenceEntry) { ReferenceEntry r = (ReferenceEntry)obj; n.Tag = r; n.Text = r.Name; n.ImageIndex = 4; n.SelectedImageIndex = 4; } else if (obj is ReferenceType) { ReferenceType type = (ReferenceType)obj; n.Tag = type; n.Text = type.Name; n.ImageIndex = 3; n.SelectedImageIndex = 3; } return(n); }
public static bool IsReferenceLoaded <TEntity, TProperty>( this HookingDbContext ctx, TEntity entity, Expression <Func <TEntity, TProperty> > navigationProperty, out ReferenceEntry <TEntity, TProperty> referenceEntry) where TEntity : BaseEntity where TProperty : BaseEntity { Guard.NotNull(entity, nameof(entity)); Guard.NotNull(navigationProperty, nameof(navigationProperty)); referenceEntry = null; if (entity.Id == 0) { return(false); } var entry = ctx.Entry(entity); referenceEntry = entry.Reference(navigationProperty); var isLoaded = referenceEntry.CurrentValue != null || referenceEntry.IsLoaded; // Avoid System.InvalidOperationException: Member 'IsLoaded' cannot be called for property... if (!isLoaded && (entry.State == EfState.Detached)) { // Attaching an entity while another instance with same primary key is attached will throw. // First we gonna try to locate an already attached entity. var other = ctx.FindTracked <TEntity>(entity.Id); if (other != null) { referenceEntry = ctx.Entry(entity).Reference(navigationProperty); } else { ctx.Attach(entity); } } return(isLoaded); }
public void AddReference(byte[] refernceData, uint offset, uint length) { ReferenceEntry entry = new ReferenceEntry(offset, length); m_entries.Add(entry); }
public void WriteSignedInfoCanonicalForm( Stream stream, string signatureMethod, string digestMethod, ReferenceEntry[] references, int referenceCount, byte[] workBuffer, char[] base64WorkBuffer) { DiagnosticUtility.DebugAssert(XmlSignatureStrings.Prefix.Length == 0, "Update SignedInfoCanonicalFormWriter to match new XmlDSig prefix"); stream.Write(this.fragment1, 0, this.fragment1.Length); byte[] signatureMethodBytes = EncodeSignatureAlgorithm(signatureMethod); stream.Write(signatureMethodBytes, 0, signatureMethodBytes.Length); stream.Write(this.fragment2, 0, this.fragment2.Length); byte[] digestMethodBytes = EncodeDigestAlgorithm(digestMethod); for (int i = 0; i < referenceCount; i++) { stream.Write(this.fragment3, 0, this.fragment3.Length); EncodeAndWrite(stream, workBuffer, references[i].id); if (references[i].useStrTransform) { stream.Write(this.fragment4StrTransform, 0, this.fragment4StrTransform.Length); } else { stream.Write(this.fragment4, 0, this.fragment4.Length); } stream.Write(digestMethodBytes, 0, digestMethodBytes.Length); stream.Write(this.fragment5, 0, this.fragment5.Length); Base64EncodeAndWrite(stream, workBuffer, base64WorkBuffer, references[i].digest); stream.Write(this.fragment6, 0, this.fragment6.Length); } stream.Write(this.fragment7, 0, this.fragment7.Length); }
/// <summary> /// Initializes a new instance of the <see cref="SaveChangesHelper" /> class. /// </summary> /// <param name="dbContext"> <see cref="DbContext" /> against which the requested query will be executed. </param> /// <param name="request"> The <see cref="SaveChangesRequest" /> object from the client containing the updated entities. </param> public SaveChangesHelper(DbContext dbContext, SaveChangesRequest request) { this.dbContext = dbContext; var typeMap = this.dbContext.Model.GetEntityTypes().ToDictionary(x => x.DisplayName()); var stateManager = this.dbContext.GetService <IStateManager>(); var entityMaterializerSource = this.dbContext.GetService <IEntityMaterializerSource>(); // Materialize entities and add entries to dbContext EntityEntry MaterializeAndTrackEntity(UpdateEntryDto dto) { IEntityType entityType = typeMap[dto.EntityTypeName]; object MaterializeEntity() { var valueBuffer = new ValueBuffer(dto.GetCurrentValues(entityType, request.Mapper)); var materializationContext = new MaterializationContext(valueBuffer, this.dbContext); return(entityMaterializerSource.GetMaterializer(entityType).Invoke(materializationContext)); } EntityEntry entry; if (entityType.HasDefiningNavigation()) { IKey key = entityType.DefiningEntityType.FindPrimaryKey(); object[] keyValues = dto.GetDelegatedIdentityKeys(request.Mapper, key); // Here we assume that the owner entry is already present in the context EntityEntry ownerEntry = stateManager.TryGetEntry(key, keyValues).ToEntityEntry(); ReferenceEntry referenceEntry = ownerEntry.Reference(entityType.DefiningNavigationName); if (referenceEntry.CurrentValue == null) { referenceEntry.CurrentValue = MaterializeEntity(); } entry = referenceEntry.TargetEntry; } else { entry = stateManager.GetOrCreateEntry(MaterializeEntity()).ToEntityEntry(); } // Correlate properties of DTO and entry var props = dto.JoinScalarProperties(entry, request.Mapper); // Set Key properties foreach (var p in props.Where(x => x.EfProperty.Metadata.IsKey())) { p.EfProperty.CurrentValue = p.CurrentValue; if (p.EfProperty.Metadata.GetOriginalValueIndex() >= 0) { p.EfProperty.OriginalValue = p.OriginalValue; } } // Set EntityState after PK values (temp or perm) are set. // This will add entities to identity map. entry.State = dto.EntityState; // Set non key properties foreach (var p in props.Where(x => !x.EfProperty.Metadata.IsKey())) { bool canSetCurrentValue = p.EfProperty.Metadata.IsShadowProperty || p.EfProperty.Metadata.TryGetMemberInfo(forConstruction: false, forSet: true, out _, out _); if (canSetCurrentValue) { p.EfProperty.CurrentValue = p.CurrentValue; } if (p.EfProperty.Metadata.GetOriginalValueIndex() >= 0 && p.EfProperty.OriginalValue != p.OriginalValue) { p.EfProperty.OriginalValue = p.OriginalValue; } if (canSetCurrentValue) { p.EfProperty.IsModified = p.DtoProperty.IsModified; } } // Mark temporary property values foreach (var p in props.Where(x => x.DtoProperty.IsTemporary)) { p.EfProperty.IsTemporary = true; } return(entry); } request.SharedIdentityDataTransferObjects.ForEach(dto => MaterializeAndTrackEntity(dto)); var entries = request.DataTransferObjects.Select(MaterializeAndTrackEntity).ToList(); // Replace temporary PKs coming from client with generated values (e.g. HiLoSequence) var valueGeneratorSelector = this.dbContext.GetService <IValueGeneratorSelector>(); foreach (EntityEntry entry in entries) { foreach (PropertyEntry tempPk in entry.Properties.Where(p => p.IsTemporary && p.Metadata.IsKey() && p.Metadata.RequiresValueGenerator()).ToList()) { ValueGenerator valueGenerator = valueGeneratorSelector.Select(tempPk.Metadata, entry.Metadata); if (!valueGenerator.GeneratesTemporaryValues) { tempPk.CurrentValue = valueGenerator.Next(entry); tempPk.IsTemporary = false; } } } this.Entries = entries.Select(e => e.GetInfrastructure()).ToList(); }
bool IsCorlibReference (ReferenceEntry re) { TargetRuntime tr; TargetFramework fx; string file; if (ProjectDomService.ParseAssemblyUri (re.Uri, out tr, out fx, out file)) return Path.GetFileNameWithoutExtension (file) == "mscorlib"; else return false; }
private void treePackageInfo_SelectedItemChanged(object sender, RoutedPropertyChangedEventArgs <object> e) { if (e.NewValue == null) { return; } TreeViewItem item = e.NewValue as TreeViewItem; if (item.Tag is ReferenceEntry) { ReferenceEntry entry = (ReferenceEntry)item.Tag; this.txtPath.Text = StaticData.Hashes.GetPath(entry.Path); this.txtType.Text = StaticData.Hashes.GetExtension(entry.Extension); this.txtPath.IsEnabled = true; this.txtLang.IsEnabled = false; this.txtType.IsEnabled = true; this.txtAddress.IsEnabled = false; this.txtID.IsEnabled = false; this.txtLangID.IsEnabled = false; this.txtLength.IsEnabled = false; } else if (item.Tag is BundleEntry) { this.txtPath.IsEnabled = true; this.txtLang.IsEnabled = true; this.txtType.IsEnabled = true; this.txtAddress.IsEnabled = true; this.txtID.IsEnabled = true; this.txtLangID.IsEnabled = true; this.txtLength.IsEnabled = true; BundleEntry entry = (BundleEntry)item.Tag; DatabaseEntry dbEntry = StaticData.BundleDB.EntryFromID(entry.Id); this.txtPath.Text = StaticData.Hashes.GetPath(dbEntry.Path); this.txtLang.Text = dbEntry.Language == 0 ? "" : StaticData.Hashes.GetAny(StaticData.BundleDB.LanguageFromID(dbEntry.Language).Hash); this.txtType.Text = StaticData.Hashes.GetExtension(dbEntry.Extension); this.txtAddress.Text = entry.Address.ToString(); this.txtID.Text = entry.Id.ToString(); this.txtLangID.Text = dbEntry.Language.ToString(); this.txtLength.Text = entry.Length.ToString(); } else { this.txtPath.Text = ""; this.txtPath.IsEnabled = false; this.txtLang.Text = ""; this.txtLang.IsEnabled = false; this.txtLangID.Text = ""; this.txtLangID.IsEnabled = false; this.txtType.Text = ""; this.txtType.IsEnabled = false; this.txtAddress.Text = ""; this.txtAddress.IsEnabled = false; this.txtID.Text = ""; this.txtID.IsEnabled = false; this.txtLength.Text = ""; this.txtLength.IsEnabled = false; } }