本文整理汇总了C#中sones.GraphDB.TypeManagement.GraphDBType.AddAttribute方法的典型用法代码示例。如果您正苦于以下问题:C# GraphDBType.AddAttribute方法的具体用法?C# GraphDBType.AddAttribute怎么用?C# GraphDBType.AddAttribute使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sones.GraphDB.TypeManagement.GraphDBType
的用法示例。
在下文中一共展示了GraphDBType.AddAttribute方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Execute
public override Exceptional Execute(DBContext dbContext, GraphDBType graphDBType)
{
var listOfTypeAttributes = new Dictionary<TypeAttribute, GraphDBType>();
var retExcept = new Exceptional();
var existingTypeAttributes = graphDBType.GetAllAttributes(dbContext);
foreach (var attr in _ListOfAttributes)
{
var createExcept = attr.CreateTypeAttribute(dbContext);
if (!createExcept.Success())
{
retExcept.PushIExceptional(createExcept);
}
if (existingTypeAttributes.Exists(item => item.Name == createExcept.Value.Name))
{
retExcept.PushIExceptional(new Exceptional(new Error_AttributeAlreadyExists(createExcept.Value.Name)));
}
var attrType = dbContext.DBTypeManager.GetTypeByName(attr.AttributeType.Name);
if (attrType == null)
{
retExcept.PushIExceptional(new Exceptional(new Error_TypeDoesNotExist(attr.AttributeType.Name)));
return retExcept;
}
if (attrType.IsUserDefined)
{
retExcept.PushIExceptional(new Exceptional(new Error_InvalidReferenceAssignmentOfUndefAttr()));
return retExcept;
}
createExcept.Value.DBTypeUUID = attrType.UUID;
createExcept.Value.RelatedGraphDBTypeUUID = graphDBType.UUID;
graphDBType.AddAttribute(createExcept.Value, dbContext.DBTypeManager, true);
var flushExcept = dbContext.DBTypeManager.FlushType(graphDBType);
if (!flushExcept.Success())
{
retExcept.PushIExceptional(flushExcept);
}
listOfTypeAttributes.Add(createExcept.Value, attrType);
}
var dbobjects = dbContext.DBObjectCache.SelectDBObjectsForLevelKey(new LevelKey(graphDBType, dbContext.DBTypeManager), dbContext);
foreach (var item in dbobjects)
{
if (!item.Success())
{
retExcept.PushIExceptional(item);
}
else
{
var undefAttrExcept = item.Value.GetUndefinedAttributePayload(dbContext.DBObjectManager);
if (!undefAttrExcept.Success())
{
retExcept.PushIExceptional(undefAttrExcept);
}
foreach (var attr in listOfTypeAttributes)
{
IObject value;
if (undefAttrExcept.Value.TryGetValue(attr.Key.Name, out value))
{
var typeOfOperator = GraphDBTypeMapper.ConvertGraph2CSharp(attr.Value.Name);
if (GraphDBTypeMapper.IsAValidAttributeType(attr.Value, typeOfOperator, dbContext, value))
{
item.Value.AddAttribute(attr.Key.UUID, value);
var removeExcept = item.Value.RemoveUndefinedAttribute(attr.Key.Name, dbContext.DBObjectManager);
if (!removeExcept.Success())
{
retExcept.PushIExceptional(removeExcept);
}
var flushExcept = dbContext.DBObjectManager.FlushDBObject(item.Value);
if (!flushExcept.Success())
{
retExcept.PushIExceptional(flushExcept);
}
}
else
{
retExcept.PushIExceptional(new Exceptional(new Error_InvalidUndefAttrType(attr.Key.Name, attr.Value.Name)));
}
}
}
}
}
//.........这里部分代码省略.........
示例2: AddAttributeToType
/// <summary>
/// Adds an attribute with given name and type to the class with the given name
/// </summary>
/// <param name="targetClass">The class, we want to add the new attribute to.</param>
/// <param name="myAttributeName">The name of the attribute.</param>
/// <param name="attributeType">The type of the attribute.</param>
/// <returns>Ture, if the attribute could be added to the target class. Else, false. (attribute contained in superclass)</returns>
public Exceptional<ResultType> AddAttributeToType(GraphDBType mytype, TypeAttribute myTypeAttribute)
{
#region check if already initialized
if (GetTypeByUUID(myTypeAttribute.DBTypeUUID) == null)
{
return new Exceptional<ResultType>(new Error_TypeDoesNotExist(myTypeAttribute.DBTypeUUID.ToString()));
}
#endregion
#region Check if any ParentType already have an attribute with this name
foreach (var aType in GetAllParentTypes(mytype, true, true))
{
if (aType.GetTypeAttributeByName(myTypeAttribute.Name) != null)
{
return new Exceptional<ResultType>(new Error_AttributeExistsInSupertype(myTypeAttribute.Name, aType.Name));
}
}
#endregion
#region adapt type
//if we reach this code, no other superclass contains an attribute with this name, so add it!
myTypeAttribute.RelatedGraphDBTypeUUID = mytype.UUID;
if (myTypeAttribute.DefaultValue != null)
{
mytype.AddMandatoryAttribute(myTypeAttribute.UUID, this);
}
mytype.AddAttribute(myTypeAttribute, this, true);
var FlushExcept = FlushType(mytype);
if (FlushExcept.Failed())
return new Exceptional<ResultType>(FlushExcept);
#endregion
#region update lookup tables ob sub-classes
foreach (var aSubType in GetAllSubtypes(mytype, false))
{
aSubType.AttributeLookupTable.Add(myTypeAttribute.UUID, myTypeAttribute);
}
#endregion
return new Exceptional<ResultType>(ResultType.Successful);
}
示例3: RemoveAttributeOfType
/// <summary>
/// Removes an attribute of the given type.
/// </summary>
/// <param name="aUserType">The target type.</param>
/// <param name="attributeUUID">The attribute uuid, referencing the deprecated attribute.</param>
/// <returns></returns>
private Exceptional<ResultType> RemoveAttributeOfType(GraphDBType aUserType, AttributeUUID attributeUUID)
{
#region INPUT EXCEPTIONS
if (aUserType == null)
{
return new Exceptional<ResultType>(new Error_ArgumentNullOrEmpty("aUserType"));
}
#endregion
#region remove attribute from type
TypeAttribute typeAttribute = aUserType.Attributes[attributeUUID];
if (typeAttribute != null)
{
aUserType.RemoveAttribute(typeAttribute.UUID);
var FlushExcept = FlushType(aUserType);
if (FlushExcept.Failed())
{
aUserType.AddAttribute(typeAttribute, this, false);
return new Exceptional<ResultType>(FlushExcept);
}
#region update lookup tables ob sub-classes
foreach (var aSubType in GetAllSubtypes(aUserType).Where(aType => aType != aUserType))
{
//delete from lookuptable
aSubType.RemoveAttributeFromLookupTable(typeAttribute.UUID);
}
#endregion
}
else
{
return new Exceptional<ResultType>(new Error_AttributeIsNotDefined(aUserType.Name, typeAttribute.Name));
}
#endregion
return new Exceptional<ResultType>(ResultType.Successful);
}
示例4: Init
/// <summary>
/// Initializes the type manager. This method may only be called once, else it throws an TypeInitializationException.
/// </summary>
/// <param name="myIGraphFSSession">The myIGraphFS, on which the database is stored.</param>
/// <param name="myDatabaseLocation">The databases root path in the myIGraphFS.</param>
public Exceptional Init(IGraphFSSession myIGraphFSSession, ObjectLocation myDatabaseLocation, Boolean myRebuildIndices)
{
#region Input validation
if (myIGraphFSSession == null)
return new Exceptional<bool>(new Error_ArgumentNullOrEmpty("The parameter myIGraphFS must not be null!"));
if (myDatabaseLocation == null)
return new Exceptional<bool>(new Error_ArgumentNullOrEmpty("The parameter myDatabaseLocation must not be null!"));
//ToDo: Find a better way to check this!
if (_BasicTypes.ContainsKey(DBBaseObject.UUID))
return new Exceptional<bool>(new Error_UnknownDBError("The TypeManager had already been initialized!"));
#endregion
var objectDirectoryShards = UInt16.Parse(_DBContext.GraphAppSettings.Get<ObjectsDirectoryShardsSetting>());
#region DBObject - The base of all database types
// DBObject is a child of DBBaseObject
var typeDBBaseObject = new GraphDBType(DBBaseObject.UUID, myDatabaseLocation, DBBaseObject.Name, null, new Dictionary<AttributeUUID, TypeAttribute>(), false, false, "The base of all database types", DBConstants.ObjectDirectoryShards);
_SystemTypes.Add(typeDBBaseObject.UUID, typeDBBaseObject);
#endregion
#region DBReference - The base of all user defined database types
// DBObject is a child of DBBaseObject
// == DBObject!
var typeDBReference = new GraphDBType(DBReference.UUID, myDatabaseLocation, DBReference.Name, DBBaseObject.UUID, new Dictionary<AttributeUUID, TypeAttribute>(), false, false, "The base of all user defined database types", DBConstants.ObjectDirectoryShards);
#region DBVertex
var typeDBVertex = new GraphDBType(DBVertex.UUID, myDatabaseLocation, DBVertex.Name, DBReference.UUID, new Dictionary<AttributeUUID, TypeAttribute>(), false, false, "The base of all user defined database vertices", DBConstants.ObjectDirectoryShards);
_SystemTypes.Add(typeDBVertex.UUID, typeDBVertex);
#endregion
#region UUID special Attribute
var specialTypeAttribute_UUID = new SpecialTypeAttribute_UUID() { DBTypeUUID = DBReference.UUID, RelatedGraphDBTypeUUID = typeDBReference.UUID, KindOfType = KindsOfType.SpecialAttribute };
typeDBReference.AddAttribute(specialTypeAttribute_UUID, this, false);
_GUIDTypeAttribute = specialTypeAttribute_UUID;
#endregion
#region CreationTime special attribute
var specialTypeAttribute_CrTime = new SpecialTypeAttribute_CREATIONTIME() { DBTypeUUID = DBUInt64.UUID, RelatedGraphDBTypeUUID = typeDBReference.UUID, KindOfType = KindsOfType.SpecialAttribute };
typeDBReference.AddAttribute(specialTypeAttribute_CrTime, this, false);
#endregion
#region DeletionTime special attribute
var specialTypeAttribute_DelTime = new SpecialTypeAttribute_DELETIONTIME() { DBTypeUUID = DBUInt64.UUID, RelatedGraphDBTypeUUID = typeDBReference.UUID, KindOfType = KindsOfType.SpecialAttribute };
typeDBReference.AddAttribute(specialTypeAttribute_DelTime, this, false);
#endregion
#region Edition special attribute
var specialTypeAttribute_Edition = new SpecialTypeAttribute_EDITION() { DBTypeUUID = DBString.UUID, RelatedGraphDBTypeUUID = typeDBReference.UUID, KindOfType = KindsOfType.SpecialAttribute };
typeDBReference.AddAttribute(specialTypeAttribute_Edition, this, false);
#endregion
#region Editions special attribute
var specialTypeAttribute_Editions = new SpecialTypeAttribute_EDITIONS() { DBTypeUUID = DBString.UUID, RelatedGraphDBTypeUUID = typeDBReference.UUID, KindOfType = KindsOfType.SpecialAttribute };
typeDBReference.AddAttribute(specialTypeAttribute_Editions, this, false);
#endregion
#region LastAccessTime special attribute
var specialTypeAttribute_AcTime = new SpecialTypeAttribute_LASTACCESSTIME() { DBTypeUUID = DBUInt64.UUID, RelatedGraphDBTypeUUID = typeDBReference.UUID, KindOfType = KindsOfType.SpecialAttribute };
typeDBReference.AddAttribute(specialTypeAttribute_AcTime, this, false);
#endregion
#region LastModificationTime special attribute
var specialTypeAttribute_LastModTime = new SpecialTypeAttribute_LASTMODIFICATIONTIME() { DBTypeUUID = DBUInt64.UUID, RelatedGraphDBTypeUUID = typeDBReference.UUID, KindOfType = KindsOfType.SpecialAttribute };
typeDBReference.AddAttribute(specialTypeAttribute_LastModTime, this, false);
#endregion
#region TypeName special Attribute
var specialTypeAttribute_TYPE = new SpecialTypeAttribute_TYPE() { DBTypeUUID = DBString.UUID, RelatedGraphDBTypeUUID = typeDBReference.UUID, KindOfType = KindsOfType.SpecialAttribute };
typeDBReference.AddAttribute(specialTypeAttribute_TYPE, this, false);
#endregion
//.........这里部分代码省略.........