public void Test_IsStored_Reference_NotStored() { using (LogGroup logGroup = LogGroup.Start("Testing the IsStored function on a reference object", NLog.LogLevel.Debug)) { TestArticle article = new TestArticle(); article.ID = Guid.NewGuid(); article.Title = "Test Article"; TestCategory category = new TestCategory(); category.ID = Guid.NewGuid(); category.Name = "Test Category"; article.Categories = new TestCategory[] { category }; //DataAccess.Data.Saver.Save(article); //DataAccess.Data.Saver.Save(category); EntityReferenceCollection collection = DataAccess.Data.Referencer.GetActiveReferences(article); //.Data.GetReferences(article.GetType(), article.ID, "Categories", category.GetType(), false); Assert.IsNotNull(collection, "Reference collection is null."); if (collection != null) { Assert.AreEqual(1, collection.Count, "Incorrect number of references found."); } foreach (EntityReference reference in collection) { bool match = DataAccess.Data.IsStored(reference); Assert.AreEqual(false, match, "Reference matched when it shouldn't have."); } } }
/// <summary> /// Creates a filter for the active data source based on the specified type. /// </summary> public override IDataFilter CreateFilter(Type filterType) { using (LogGroup logGroup = LogGroup.Start("Creating filter", NLog.LogLevel.Debug)) { LogWriter.Debug("Type: " + filterType.ToString()); if (filterType.Equals(typeof(PropertyFilter))) { LogWriter.Debug("Filter type supported."); return(new Db4oPropertyFilter()); } else if (filterType.Equals(typeof(ReferenceFilter))) { LogWriter.Debug("Filter type supported."); return(new Db4oReferenceFilter()); } else { LogWriter.Debug("Creation failed. " + filterType.ToString() + " isn't a supported filter."); throw new NotSupportedException(filterType.ToString() + " isn't yet supported."); } } }
/// <summary> /// Creates a new instance of the specified type of entity. /// </summary> /// <param name="shortTypeName">The short name of the type of entity to create an instance of.</param> public override IEntity Create() { // TODO: Check if needed. Should be unnecessary ISubEntity entity = null; using (LogGroup logGroup = LogGroup.Start("Creating a new entity of type '" + TypeName + "'.", NLog.LogLevel.Debug)) { if (!EntityState.IsType(TypeName)) { throw new InvalidOperationException("The TypeName property needs to be set to the type of an entity. Invalid type: " + TypeName); } Type type = EntityState.GetType(TypeName); LogWriter.Debug("Authorisation required: " + RequireAuthorisation.ToString()); if (RequireAuthorisation) { AuthoriseCreateStrategy.New(TypeName).EnsureAuthorised(TypeName); } entity = (ISubEntity)base.Create(); entity.ID = Guid.NewGuid(); } return(entity); }
static public Type GetEntityType(IEntity entity, PropertyInfo property) { Type type = null; using (LogGroup group = LogGroup.Start("Retrieving the type of entity being referenced by the provided property.", LogLevel.Debug)) { if (entity == null) { throw new ArgumentNullException("entity"); } if (property == null) { throw new ArgumentNullException("property"); } LogWriter.Debug("Entity type: " + entity.GetType().ToString()); LogWriter.Debug("Property name: " + property.Name); LogWriter.Debug("Property type: " + property.PropertyType.Name); type = EntitiesUtilities.GetReferenceType(entity, property); } if (type == null) { LogWriter.Debug("return type == null"); } else { LogWriter.Debug("return type == " + type.ToString()); } return(type); }
/// <summary> /// Gets the name of the data store that the provided entity is stored in. /// </summary> /// <param name="entity">The entity to get the data store name for.</param> /// <param name="throwErrorIfNotFound">A flag indicating whether an error should be thrown when no data store attribute is found.</param> /// <returns>The data store that the provided entity is stored in.</returns> static public string GetDataStoreName(IEntity entity, bool throwErrorIfNotFound) { if (entity == null) { throw new ArgumentNullException("entity"); } string dataStoreName = String.Empty; Type type = entity.GetType(); using (LogGroup logGroup = LogGroup.Start("Retrieving data store name for entity of type '" + type.ToString() + "'.", LogLevel.Debug)) { if (EntitiesUtilities.IsReference(entity)) { LogWriter.Debug("Provided entity is an EntityReference"); EntityReference reference = (EntityReference)entity; dataStoreName = GetDataStoreName(new string[] { reference.Type1Name, reference.Type2Name }); } else { LogWriter.Debug("Provided entity is NOT an EntityReference."); dataStoreName = GetDataStoreName(entity.GetType()); } LogWriter.Debug("Data store name: " + dataStoreName); } return(dataStoreName); }
/// <summary> /// Updates the provided entity back to the data store. /// </summary> /// <param name="entity"></param> /// <returns>A bool value indicating the success of the update. If it fails it's due to the entity being invalid.</returns> public virtual bool ExecuteUpdate(IEntity entity) { bool didSucceed = false; using (LogGroup logGroup = LogGroup.Start("Updating the provided entity.", NLog.LogLevel.Debug)) { if (EnsureAuthorised()) { DataSource = entity; if (entity == null) { throw new ArgumentNullException("entity"); } // Update the entity if (Updater.Update(entity)) { Result.Display(DynamicLanguage.GetEntityText(EntityUpdatedLanguageKey, Command.TypeName)); didSucceed = true; } else { // Add the validation error to the result control Validation.DisplayError(entity); didSucceed = false; } } LogWriter.Debug("Did succeed: " + didSucceed.ToString()); } return(didSucceed); }
public void Test_IsMatch() { using (LogGroup logGroup = LogGroup.Start("Testing the ReferenceFilter.IsMatch function.", NLog.LogLevel.Debug)) { TestArticle article = new TestArticle(); article.ID = Guid.NewGuid(); TestCategory category = new TestCategory(); category.ID = Guid.NewGuid(); article.Categories = new TestCategory[] { category }; DataAccess.Data.Saver.Save(category); DataAccess.Data.Saver.Save(article); ReferenceFilter filter = (ReferenceFilter)DataAccess.Data.CreateFilter(typeof(ReferenceFilter)); filter.Operator = FilterOperator.Equal; filter.PropertyName = "Categories"; filter.ReferencedEntityID = category.ID; filter.ReferenceType = typeof(TestCategory); filter.AddType(typeof(TestArticle)); bool isMatch = filter.IsMatch(article); Assert.IsTrue(isMatch, "The IsMatch function returned false when it should have been true."); } }
/// <summary> /// Displays an index of entities matching the provided filter values. /// </summary> /// <param name="filterValues"></param> public virtual void Index(Dictionary <string, object> filterValues) { using (LogGroup logGroup = LogGroup.Start("Preparing to load an index of enitities for display.")) { LogWriter.Debug("Type name: " + Command.TypeName); if (filterValues == null) { filterValues = new Dictionary <string, object>(); } CheckInitialized(); if (filterValues == null) { throw new ArgumentNullException("filterValues"); } if (filterValues.Count == 0) { throw new ArgumentNullException("No filter values specified. Use the other overload if not specifying filter values."); } IEntity[] entities = null; entities = PrepareIndex(filterValues); Index(entities); } }
public void Test_IsMatch() { using (LogGroup logGroup = LogGroup.Start("Testing the PropertyFilter.IsMatch function.", NLog.LogLevel.Debug)) { TestArticle article = new TestArticle(); article.ID = Guid.NewGuid(); article.Title = "Test Title 1"; TestArticle article2 = new TestArticle(); article2.ID = Guid.NewGuid(); article2.Title = "Test Title 2"; //DataAccess.Data.Saver.Save(article); //DataAccess.Data.Saver.Save(article2); PropertyFilter filter = (PropertyFilter)DataAccess.Data.CreateFilter(typeof(PropertyFilter)); filter.Operator = FilterOperator.Equal; filter.PropertyName = "Title"; filter.PropertyValue = article.Title; filter.AddType(typeof(TestArticle)); bool isMatch = filter.IsMatch(article); Assert.IsTrue(isMatch, "The IsMatch function returned false when it should have been true."); } }
/// <summary> /// Persists the provided references into the data store. Checks each of the provided references and saves those that are missing. /// </summary> /// <param name="references">The collection of entity references to persist.</param> public virtual void PersistReferences(EntityReferenceCollection references) { using (LogGroup logGroup = LogGroup.Start("Persisting the provided references.", LogLevel.Debug)) { if (references != null) { LogWriter.Debug("Reference count: " + references.Count.ToString()); // TODO: Check if binding is needed. Shouldn't be because // existing references are skipped and only new references get saved //BindReferences(references); foreach (EntityReference reference in references) { // If the reference is new then save it if (!Provider.IsStored(reference)) { LogWriter.Debug("Reference is new. Saving."); Provider.Saver.Save(reference); } // Otherwise just leave the existing reference as-is // Existing references shouldn't need to change } } } }
/// <summary> /// Maintains the references of the provided entity by deleting the obsolete references (those in the data store but no longer active on one of the properties) /// and persisting the new references into the data store. /// </summary> /// <param name="entity">The entity to maintain the references for.</param> public virtual void MaintainReferences(IEntity entity) { using (LogGroup logGroup = LogGroup.Start("Maintaining the references for the provided entity.", LogLevel.Debug)) { EntityReferenceCollection updateList = new EntityReferenceCollection(); EntityReferenceCollection deleteList = new EntityReferenceCollection(); // Get the current/actives references foreach (EntityReference reference in GetActiveReferences(entity)) { updateList.Add(reference); } // Get the obsolete references foreach (EntityReference reference in GetObsoleteReferences(entity, updateList.GetEntityIDs(entity.ID))) { deleteList.Add(reference); } // Delete the obsolete references LogWriter.Debug("References to delete: " + deleteList.Count); DeleteObsoleteReferences(deleteList); // Update/save the current references LogWriter.Debug("References to update: " + updateList.Count); PersistReferences(updateList); Provider.Referencer.SetCountProperties(entity, false); } }
public void Test_GetReferences_Basic() { using (LogGroup logGroup = LogGroup.Start("Testing the retrieval of references for an entity.", NLog.LogLevel.Debug)) { TestUser user = new TestUser(); Guid userID = user.ID = Guid.NewGuid(); user.FirstName = "Test"; user.LastName = "User"; TestRole role = new TestRole(); Guid roleID = role.ID = Guid.NewGuid(); role.Name = "Test Role"; user.Roles = Collection <TestRole> .Add(user.Roles, role); DataAccess.Data.Saver.Save(role); DataAccess.Data.Saver.Save(user); EntityReferenceCollection references = DataAccess.Data.Referencer.GetReferences(user.GetType(), user.ID, "Roles", typeof(TestRole), false); Assert.IsNotNull(references, "The references object returned was null."); if (references != null) { Assert.AreEqual(1, references.Count, "Wrong number of references returned."); Assert.IsTrue(references[0].Includes(userID, "Roles"), "The user ID wasn't found on the reference."); Assert.IsTrue(references[0].Includes(roleID, "Users"), "The role ID wasn't found on the reference."); } } }
public void Test_MatchReference_Opposite() { using (LogGroup logGroup = LogGroup.Start("Testing the MatchReference function to ensure matches properly.", NLog.LogLevel.Debug)) { TestArticle article = new TestArticle(); article.ID = Guid.NewGuid(); article.Title = "Test Article"; TestCategory category = new TestCategory(); category.ID = Guid.NewGuid(); category.Name = "Test Category"; article.Categories = new TestCategory[] { category }; DataAccess.Data.Saver.Save(category); DataAccess.Data.Saver.Save(article); bool match = DataAccess.Data.Referencer.MatchReference(article.GetType(), article.ID, "Categories", category.GetType(), category.ID, "Articles"); bool match2 = DataAccess.Data.Referencer.MatchReference(category.GetType(), category.ID, "Articles", article.GetType(), article.ID, "Categories"); Assert.IsTrue(match, "Didn't match on standard check."); Assert.IsTrue(match2, "Didn't match on reverse check."); DataAccess.Data.Deleter.Delete(article); DataAccess.Data.Deleter.Delete(category); } }
public void Test_GetReference_Async() { using (LogGroup logGroup = LogGroup.Start("Testing the GetReference function with an asynchronous reference to ensure it retrieves the correct reference.", NLog.LogLevel.Debug)) { EntityFive e5 = new EntityFive(); e5.ID = Guid.NewGuid(); e5.Name = "Test Entity 5"; EntitySix e6 = new EntitySix(); e6.ID = Guid.NewGuid(); e6.Name = "Test Entity 6"; e5.ReferencedEntities = new EntitySix[] { e6 }; DataAccess.Data.Saver.Save(e6); DataAccess.Data.Saver.Save(e5); EntityReference reference = DataAccess.Data.Referencer.GetReference(e5.GetType(), e5.ID, "ReferencedEntities", e6.GetType(), e6.ID, String.Empty, false); Assert.IsNotNull(reference, "The return value is null."); Assert.IsTrue(reference.Includes(e5.ID, "ReferencedEntities"), "The returned reference is invalid. (#1)"); Assert.IsTrue(reference.Includes(e6.ID, ""), "The returned reference is invalid. (#2)"); DataAccess.Data.Deleter.Delete(e5); DataAccess.Data.Deleter.Delete(e6); } }
public override void NavigateAfterUpdate() { using (LogGroup logGroup = LogGroup.Start("Navigating after a update operation.", NLog.LogLevel.Debug)) { if (DataSource == null) { throw new InvalidOperationException("The DataSource property isn't set."); } ISubEntity entity = (ISubEntity)DataSource; if (entity.Parent == null) { LogWriter.Debug("No parent found. Activating entity.Parent."); ActivateStrategy.New <ISubEntity>().Activate(entity, entity.ParentPropertyName); } if (entity.Parent == null) { throw new Exception("No parent assigned to entity."); } Navigator.Current.NavigateAfterOperation("View", entity.Parent); } }
/// <summary> /// Executes the schema change command on the provided serialized reference. /// </summary> /// <param name="document">The reference serialized to an XML document.</param> public override void ExecuteOnReference(XmlDocument document) { using (LogGroup logGroup = LogGroup.Start("Renaming the type on the provided reference.", LogLevel.Debug)) { XmlNode type1Node = document.DocumentElement.SelectSingleNode("Type1Name"); XmlNode type2Node = document.DocumentElement.SelectSingleNode("Type2Name"); if (type1Node == null) { throw new ArgumentException("The provided document doesn't have a 'Type1Name' node."); } if (type2Node == null) { throw new ArgumentException("The provided document doesn't have a 'Type2Name' node."); } if (type1Node.InnerText == TypeName) { LogWriter.Debug("Found matching node '" + type1Node.InnerText + "'...replacing with '" + newTypeName + "'."); type1Node.InnerText = newTypeName; } if (type2Node.InnerText == TypeName) { LogWriter.Debug("Found matching node '" + type2Node.InnerText + "'...replacing with '" + newTypeName + "'."); type2Node.InnerText = newTypeName; } } }
/// <summary> /// Prepares the edit form with the entity specified by the ID or unique key in the query string. /// </summary> /// <returns>The entity specified in the query string.</returns> public virtual IEntity PrepareEdit() { IEntity entity = null; using (LogGroup logGroup = LogGroup.Start("Preparing to edit an entity.", NLog.LogLevel.Debug)) { Guid id = GetID(); string uniqueKey = GetUniqueKey(); if (id != Guid.Empty) { LogWriter.Debug("ID: " + id.ToString()); entity = PrepareEdit(id); } else if (uniqueKey != String.Empty) { LogWriter.Debug("Unique key: " + uniqueKey); entity = PrepareEdit(uniqueKey); } else { throw new InvalidOperationException("Cannot edit entity. No identifier found."); } } return(entity); }
public virtual bool ExecuteSave(ISubEntity entity) { bool success = false; using (LogGroup logGroup = LogGroup.Start("Saving the new entity.", NLog.LogLevel.Debug)) { if (entity == null) { throw new ArgumentNullException("entity"); } if (entity.Parent == null) { ActivateStrategy.New <ISubEntity>().Activate(entity, entity.ParentPropertyName); } if (entity.Parent == null) { throw new Exception("No parent found for entity with ID: " + entity.ID.ToString()); } DataSource = entity; success = base.ExecuteSave(entity); } return(success); }
/// <summary> /// Disposes the provided elements. /// </summary> public void Dispose(ElementStateCollection elements) { using (LogGroup logGroup = LogGroup.Start("Disposing the provided elements.", NLog.LogLevel.Debug)) { elements.Clear(); } }
/// <summary> /// Creates a new sub entity and assigns the parent entity specified in the query strings. /// </summary> /// <returns></returns> public override IEntity Create() { IEntity entity = null; using (LogGroup logGroup = LogGroup.Start("Preparing the form to create a new sub entity.", NLog.LogLevel.Debug)) { if (EnsureAuthorised()) { Guid parentID = Guid.Empty; string parentUniqueKey = String.Empty; if (QueryStrings.Available) { parentID = QueryStrings.GetID("Parent"); parentUniqueKey = QueryStrings.GetUniqueKey("Parent"); } else { throw new InvalidOperationException("Query strings aren't available. Provide parent ID or parent unique key manually."); } LogWriter.Debug("Parent ID: " + parentID); LogWriter.Debug("Parent unique key: " + parentUniqueKey); entity = Create(parentID, parentUniqueKey); } } return(entity); }
/// <summary> /// Checks whether the provided type is a element. /// </summary> /// <param name="type"></param> /// <returns></returns> public bool IsElement(Type type) { bool isElement = false; using (LogGroup logGroup = LogGroup.Start("Checks whether the provided type is a element.", NLog.LogLevel.Debug)) { LogWriter.Debug("Type: " + type.ToString()); bool matchesInterface = false; bool isNotInterface = false; bool isNotAbstract = false; bool hasAttribute = false; matchesInterface = (type.GetInterface("IElement") != null); isNotInterface = !type.IsInterface; isNotAbstract = !type.IsAbstract; hasAttribute = type.GetCustomAttributes(typeof(ElementAttribute), true).Length > 0; LogWriter.Debug("Matches interface: " + matchesInterface); LogWriter.Debug("Is not element interface: " + isNotInterface); LogWriter.Debug("Has attribute: " + isNotAbstract); isElement = matchesInterface && isNotInterface && isNotAbstract && hasAttribute; LogWriter.Debug("Is element: " + isElement.ToString()); } return(isElement); }
/// <summary> /// Checks whether the current user is authorised to update the provided entity. /// </summary> /// <param name="entity">The entity to be updated.</param> /// <returns>A value indicating whether the current user is authorised to update the provided entity.</returns> public override bool IsAuthorised(IEntity entity) { bool isAuthorised = false; using (LogGroup logGroup = LogGroup.Start("Checking whether the current user is authorised to update the provided entity.", NLog.LogLevel.Debug)) { if (entity == null) { throw new ArgumentNullException("entity"); } if (!RequireAuthorisation) { isAuthorised = true; } else { isAuthorised = IsAuthorised(entity.ShortTypeName); AuthoriseReferencesStrategy.New(entity).Authorise(entity); } LogWriter.Debug("Is authorised: " + isAuthorised); } return(isAuthorised); }
// TODO: Check if function should be removed static public void StripReferences(IEntity entity) { using (LogGroup logGroup2 = LogGroup.Start("Clearing all the object references so that they don't cascade automatically.", LogLevel.Debug)) { if (entity is EntityReference) { ((EntityReference)entity).Deactivate(); } else { // Clear all the references from the entity once they're ready to be saved separately foreach (PropertyInfo property in entity.GetType().GetProperties()) { LogWriter.Debug("Property name: " + property.Name); LogWriter.Debug("Property type: " + property.PropertyType.ToString()); // If the property is a reference // OR the actual provided entity is a reference AND the property holds an IEntity instance if (EntitiesUtilities.IsReference(entity.GetType(), property.Name, property.PropertyType)) { LogWriter.Debug("Cleared property. (Set to null)"); Reflector.SetPropertyValue(entity, property.Name, null); } } } } }
/// <summary> /// Retrieves the entities of the specified type. /// </summary> /// <returns></returns> public virtual T[] Index <T>() where T : IEntity { T[] entities = new T[] {}; using (LogGroup logGroup = LogGroup.Start("Indexing entities that have the specified reference.", NLog.LogLevel.Debug)) { LogWriter.Debug("Type name: " + typeof(T).ToString()); LogWriter.Debug("Enable paging: " + EnablePaging.ToString()); LogWriter.Debug("Require authorisation: " + RequireAuthorisation.ToString()); if (EnablePaging) { entities = DataAccess.Data.Indexer.GetPageOfEntities <T>(Location, SortExpression); } else { entities = DataAccess.Data.Indexer.GetEntities <T>(); } if (RequireAuthorisation) { AuthoriseIndexStrategy.New <T>().EnsureAuthorised(ref entities); } LogWriter.Debug("Entity count: " + entities.Length); AssignStrategies(entities); React(entities); } return(entities); }
/// <summary> /// Deletes the provided entity. /// </summary> /// <param name="entity"></param> public virtual void ExecuteDelete(IEntity entity) { using (LogGroup logGroup = LogGroup.Start("Deleting the provided entity.", NLog.LogLevel.Debug)) { if (entity == null) { throw new ArgumentNullException("entity"); } if (EnsureAuthorised(entity)) { if (entity == null) { LogWriter.Debug("Entity: [null]"); } else { LogWriter.Debug("Entity: " + entity.GetType().FullName); } Deleter.Delete(entity); LogWriter.Debug("Done"); // Display the result Result.Display(DynamicLanguage.GetEntityText("EntityDeleted", entity.ShortTypeName)); NavigateAfterDelete(entity); } } }
/// <summary> /// Index the entity with a references that matches the provided parameters. /// </summary> /// <param name="propertyName">The name of the property containing the references.</param> /// <param name="referencedEntityType">The type of the entity being referenced.</param> /// <param name="referencedEntityID">The ID of the entity being referenced.</param> /// <returns>The entity matching the provided parameters.</returns> public virtual IEntity[] IndexWithReference(string propertyName, string referencedEntityType, Guid referencedEntityID) { IEntity[] entities = new IEntity[] {}; using (LogGroup logGroup = LogGroup.Start("Indexing entities that have the specified reference.", NLog.LogLevel.Debug)) { LogWriter.Debug("Type name: " + TypeName); LogWriter.Debug("Property name: " + propertyName); LogWriter.Debug("Reference entity type: " + referencedEntityType); LogWriter.Debug("Referenced entity ID: " + referencedEntityID.ToString()); LogWriter.Debug("Enable paging: " + EnablePaging.ToString()); LogWriter.Debug("Require authorisation: " + RequireAuthorisation.ToString()); entities = (IEntity[])Reflector.InvokeGenericMethod(this, "IndexWithReference", new Type[] { EntityState.Entities[TypeName].GetEntityType() }, new object[] { propertyName, referencedEntityType, referencedEntityID }); if (RequireAuthorisation) { AuthoriseIndexStrategy.New(TypeName).EnsureAuthorised(ref entities); } React(entities); LogWriter.Debug("Entity count: " + entities.Length); } return(entities); }
public virtual int SetNumber(ISubEntity entity) { using (LogGroup logGroup = LogGroup.Start("Setting the number of the new sub entity.", NLog.LogLevel.Debug)) { if (entity == null) { throw new ArgumentNullException("entity"); } if (entity.Parent == null) { throw new Exception("No parent is assigned to this item."); } IEntity parent = entity.Parent; ActivateStrategy.New(parent).Activate(parent, entity.ItemsPropertyName); ISubEntity[] items = Collection <ISubEntity> .ConvertAll(EntitiesUtilities.GetPropertyValue(parent, entity.ItemsPropertyName)); LogWriter.Debug("Existing items: " + items.Length.ToString()); entity.Number = items.Length + 1; LogWriter.Debug("Entity number: " + entity.Number.ToString()); } return(entity.Number); }
/// <summary> /// Checks whether the command applies to the reference provided as a serialized XML document. /// </summary> /// <param name="document">The serialized reference as an XML document.</param> /// <returns>A boolean flag indicating whether the command applies to the provided XML document.</returns> public bool AppliesToReference(XmlDocument document) { bool doesApply = false; using (LogGroup logGroup = LogGroup.Start("Checking whether the command applies to the provided XML document.", LogLevel.Debug)) { XmlNode type1Node = document.DocumentElement.SelectSingleNode("Type1Name"); XmlNode type2Node = document.DocumentElement.SelectSingleNode("Type2Name"); if (type1Node == null) { throw new ArgumentException("The provided document doesn't have a 'Type1Name' node."); } if (type2Node == null) { throw new ArgumentException("The provided document doesn't have a 'Type2Name' node."); } LogWriter.Debug("Type 1 name: " + type1Node.InnerText); LogWriter.Debug("Type 2 name: " + type2Node.InnerText); LogWriter.Debug("Expected type name: " + TypeName); // The command applies if either of the type nodes match the type on the command doesApply = type1Node.InnerText == TypeName || type2Node.InnerText == TypeName; } return(doesApply); }
public IEntity GetParent(string parentTypeName, Guid parentID, string parentUniqueKey) { IEntity parent = null; using (LogGroup logGroup = LogGroup.Start("Retrieving the parent for entity being created.", NLog.LogLevel.Debug)) { LogWriter.Debug("Parent ID: " + parentID.ToString()); LogWriter.Debug("Parent unique key: " + parentUniqueKey); LogWriter.Debug("Parent type: " + parentTypeName); IRetrieveStrategy retrieveStrategy = RetrieveStrategy.New(parentTypeName, RequireAuthorisation); if (parentUniqueKey != String.Empty) { parent = retrieveStrategy.Retrieve("UniqueKey", parentUniqueKey); } else if (parentID != Guid.Empty) { parent = retrieveStrategy.Retrieve("ID", parentID); } else { throw new Exception("No unique key or ID found for the parent."); } } return(parent); }
public virtual void Delete(IEntity entity) { using (LogGroup logGroup = LogGroup.Start("Deleting the entity provided.", NLog.LogLevel.Debug)) { Controller.Delete(entity); } }