本文整理汇总了C#中Graph.NewVertexProperty方法的典型用法代码示例。如果您正苦于以下问题:C# Graph.NewVertexProperty方法的具体用法?C# Graph.NewVertexProperty怎么用?C# Graph.NewVertexProperty使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Graph
的用法示例。
在下文中一共展示了Graph.NewVertexProperty方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CreateGraph
static readonly string s_licenseDbFile = "c:/4.odb"; // (download from https://www.velocitydb.com/Secure/Download.aspx)
static void CreateGraph()
{
using (SessionNoServer session = new SessionNoServer(systemDir))
{
if (Directory.Exists(session.SystemDirectory))
Directory.Delete(session.SystemDirectory, true); // remove systemDir from prior runs and all its databases.
// Start an update transaction
session.BeginUpdate();
// Copy VelocityDB license database to this database directory
File.Copy(s_licenseDbFile, Path.Combine(session.SystemDirectory, "4.odb"));
Graph g = new Graph(session);
session.Persist(g);
// Add a node type for the movies, with a unique identifier and two indexed Propertys
VertexType movieType = g.NewVertexType("Movie");
PropertyType movieTitleType = g.NewVertexProperty(movieType, "title", DataType.String, PropertyKind.Indexed);
PropertyType movieYearType = g.NewVertexProperty(movieType, "year", DataType.Integer, PropertyKind.Indexed);
// Add a node type for the actor
VertexType actorType = g.NewVertexType("Actor");
PropertyType actorNameType = g.NewVertexProperty(actorType, "name", DataType.String, PropertyKind.Indexed);
// Add a directed edge type with a Property for the cast of a movie
EdgeType castType = g.NewEdgeType("ACTS_IN", false);
PropertyType castCharacterType = g.NewEdgeProperty(castType, "role", DataType.String, PropertyKind.Indexed);
// Add some Movies
Vertex matrix1 = movieType.NewVertex();
matrix1.SetProperty(movieTitleType, "The Matrix");
matrix1.SetProperty(movieYearType, (int)1999);
Vertex matrix2 = movieType.NewVertex();
matrix2.SetProperty(movieTitleType, "The Matrix Reloaded");
matrix2.SetProperty(movieYearType, (int)2003);
Vertex matrix3 = movieType.NewVertex();
matrix3.SetProperty(movieTitleType, "The Matrix Revolutions");
matrix3.SetProperty(movieYearType, (int)2003);
// Add some Actors
Vertex keanu = actorType.NewVertex();
keanu.SetProperty(actorNameType, "Keanu Reeves");
Vertex laurence = actorType.NewVertex();
laurence.SetProperty(actorNameType, "Laurence Fishburne");
Vertex carrieanne = actorType.NewVertex();
carrieanne.SetProperty(actorNameType, "Carrie-Anne Moss");
// Add some edges
Edge keanuAsNeo = castType.NewEdge(keanu, matrix1);
keanuAsNeo.SetProperty(castCharacterType, "Neo");
keanuAsNeo = castType.NewEdge(keanu, matrix2);
keanuAsNeo.SetProperty(castCharacterType, "Neo");
keanuAsNeo = castType.NewEdge(keanu, matrix3);
keanuAsNeo.SetProperty(castCharacterType, "Neo");
Edge laurenceAsMorpheus = castType.NewEdge(laurence, matrix1);
laurenceAsMorpheus.SetProperty(castCharacterType, "Morpheus");
laurenceAsMorpheus = castType.NewEdge(laurence, matrix2);
laurenceAsMorpheus.SetProperty(castCharacterType, "Morpheus");
laurenceAsMorpheus = castType.NewEdge(laurence, matrix3);
laurenceAsMorpheus.SetProperty(castCharacterType, "Morpheus");
Edge carrieanneAsTrinity = castType.NewEdge(carrieanne, matrix1);
carrieanneAsTrinity.SetProperty(castCharacterType, "Trinity");
carrieanneAsTrinity = castType.NewEdge(carrieanne, matrix2);
carrieanneAsTrinity.SetProperty(castCharacterType, "Trinity");
carrieanneAsTrinity = castType.NewEdge(carrieanne, matrix3);
carrieanneAsTrinity.SetProperty(castCharacterType, "Trinity");
// Commit the transaction
session.Commit();
}
}
示例2: SandeepGraph
public void SandeepGraph(bool useServerSession)
{
bool dirExist = Directory.Exists(systemDir);
try
{
if (Directory.Exists(systemDir))
Directory.Delete(systemDir, true); // remove systemDir from prior runs and all its databases.
Directory.CreateDirectory(systemDir);
File.Copy(licenseDbFile, Path.Combine(systemDir, "4.odb"));
}
catch
{
File.Copy(licenseDbFile, Path.Combine(systemDir, "4.odb"));
}
using (SessionBase session = useServerSession ? (SessionBase)new ServerClientSession(systemDir) : (SessionBase)new SessionNoServer(systemDir))
{
session.BeginUpdate();
session.DefaultDatabaseLocation().CompressPages = PageInfo.compressionKind.None;
Graph g = new Graph(session);
session.Persist(g);
// SCHEMA
VertexType userType = g.NewVertexType("User");
// Add a node type for the movies, with a unique identifier and two indexed Propertys
VertexType movieType = g.NewVertexType("MOVIE");
PropertyType movieTitleType = g.NewVertexProperty(movieType, "TITLE", DataType.String, PropertyKind.Indexed);
PropertyType movieYearType = g.NewVertexProperty(movieType, "YEAR", DataType.Integer, PropertyKind.Indexed);
PropertyType objectPropertyType = g.NewVertexProperty(movieType, "object", DataType.Object, PropertyKind.NotIndexed);
PropertyType objectPropertyTypeIndexed = g.NewVertexProperty(movieType, "director", DataType.IOptimizedPersistable, PropertyKind.Indexed);
Vertex mVickyCB = movieType.NewVertex();
mVickyCB.SetProperty(movieTitleType, "Vicky Cristina Barcelona");
mVickyCB.SetProperty(movieYearType, (int)(2008));
Person pObj = new Person();
session.Persist(pObj);
mVickyCB.SetProperty(objectPropertyType, pObj);
pObj = new Person();
Person pSave = null;
Vertex vSave = null;
mVickyCB.SetProperty(objectPropertyTypeIndexed, pObj);
for (int i = 0; i < 100; i++)
{
Vertex vertex = movieType.NewVertex();
pObj = new Person();
vertex.SetProperty(objectPropertyTypeIndexed, pObj);
if (i == 44)
{
pSave = pObj;
vSave = vertex;
}
}
Vertex lookup = objectPropertyTypeIndexed.GetPropertyVertex(pSave);
Assert.AreEqual(lookup, vSave);
Vertex mMatsCB = movieType.NewVertex();
mMatsCB.SetProperty(movieTitleType, "Mats Cristina Barcelona");
mMatsCB.SetProperty(movieYearType, (int)(2008));
pObj = new Person();
session.Persist(pObj);
mMatsCB.SetProperty(objectPropertyType, pObj);
session.Commit();
session.BeginUpdate();
try
{
mMatsCB.SetProperty(objectPropertyTypeIndexed, null);
throw new UnexpectedException();
}
catch (NullObjectException)
{
}
mMatsCB.Remove();
session.Commit();
//session.Persist(g);
//session.Commit();
}
using (SessionBase session = useServerSession ? (SessionBase)new ServerClientSession(systemDir) : (SessionBase)new SessionNoServer(systemDir))
{
session.BeginUpdate();
Graph g = Graph.Open(session);
VertexType movieType = g.FindVertexType("MOVIE");
Assert.NotNull(movieType);
}
Task taskB = new Task(() => WatchUser());
taskB.Start();
Task taskA = new Task(() => CreateUser());
taskA.Start();
taskB.Wait();
taskA.Wait();
}
示例3: TraverseTest
public void TraverseTest()
{
using (SessionNoServer session = new SessionNoServer(systemDir))
{
session.BeginUpdate();
Graph g = new Graph(session);
session.Persist(g);
VertexType Airport_Type = g.NewVertexType("Airport");
PropertyType Airport_Name_Type = g.NewVertexProperty(Airport_Type, "Airport", DataType.String, PropertyKind.Indexed);
VertexType Flight_Type = g.NewVertexType("Flight");
PropertyType Flight_Name_Type = g.NewVertexProperty(Flight_Type, "Flight", DataType.String, PropertyKind.Indexed);
PropertyType Flight_Origin_Type = g.NewVertexProperty(Flight_Type, "Origin", DataType.String, PropertyKind.Indexed);
PropertyType Flight_Dest_Type = g.NewVertexProperty(Flight_Type, "Destination", DataType.String, PropertyKind.Indexed);
EdgeType origin_for = g.NewEdgeType("origin for", true, Airport_Type, Flight_Type);
EdgeType arrives_at = g.NewEdgeType("arrives at", true, Flight_Type, Airport_Type);
Vertex sydney = Airport_Type.NewVertex();
sydney.SetProperty(Airport_Name_Type, "SYD");
Vertex london = Airport_Type.NewVertex();
london.SetProperty(Airport_Name_Type, "LHR");
Vertex madrid = Airport_Type.NewVertex();
madrid.SetProperty(Airport_Name_Type, "MAD");
Vertex dubai = Airport_Type.NewVertex();
dubai.SetProperty(Airport_Name_Type, "DBX");
// sydney to london
Vertex qf1 = Flight_Type.NewVertex();
qf1.SetProperty(Flight_Name_Type, "QF1");
qf1.SetProperty(Flight_Origin_Type, "SYD");
qf1.SetProperty(Flight_Dest_Type, "LHR");
//london to sydney
Vertex qf2 = Flight_Type.NewVertex();
qf2.SetProperty(Flight_Name_Type, "QF2");
qf2.SetProperty(Flight_Origin_Type, "LHR");
qf2.SetProperty(Flight_Dest_Type, "SYD");
//london to madrid
Vertex ba512 = Flight_Type.NewVertex();
ba512.SetProperty(Flight_Name_Type, "BA512");
ba512.SetProperty(Flight_Origin_Type, "LHR");
ba512.SetProperty(Flight_Dest_Type, "MAD");
//madrid to london
Vertex ba461 = Flight_Type.NewVertex();
ba461.SetProperty(Flight_Name_Type, "BA461");
ba461.SetProperty(Flight_Origin_Type, "MAD");
ba461.SetProperty(Flight_Dest_Type, "LHR");
//sydney to dubai
Vertex qf414 = Flight_Type.NewVertex();
qf414.SetProperty(Flight_Name_Type, "QF414");
qf414.SetProperty(Flight_Origin_Type, "SYD");
qf414.SetProperty(Flight_Dest_Type, "DBX");
//dubai to sydney
Vertex qf413 = Flight_Type.NewVertex();
qf413.SetProperty(Flight_Name_Type, "QF413");
qf413.SetProperty(Flight_Origin_Type, "DBX");
qf413.SetProperty(Flight_Dest_Type, "SYD");
//sydney to london
Vertex ba999 = Flight_Type.NewVertex();
ba999.SetProperty(Flight_Name_Type, "BA999");
ba999.SetProperty(Flight_Origin_Type, "SYD");
ba999.SetProperty(Flight_Dest_Type, "LHR");
Vertex ba888 = Flight_Type.NewVertex();
ba888.SetProperty(Flight_Name_Type, "BA888");
ba888.SetProperty(Flight_Origin_Type, "LHR");
ba888.SetProperty(Flight_Dest_Type, "SYD");
Edge anEdge;
anEdge = g.NewEdge(origin_for, sydney, qf1);
anEdge = g.NewEdge(arrives_at, qf1, london);
anEdge = g.NewEdge(origin_for, london, qf2);
anEdge = g.NewEdge(arrives_at, qf2, sydney);
anEdge = g.NewEdge(origin_for, london, ba512);
anEdge = g.NewEdge(arrives_at, ba512, madrid);
anEdge = g.NewEdge(origin_for, madrid, ba461);
anEdge = g.NewEdge(arrives_at, ba461, london);
anEdge = g.NewEdge(origin_for, sydney, qf414);
anEdge = g.NewEdge(arrives_at, qf414, dubai);
anEdge = g.NewEdge(origin_for, dubai, qf413);
anEdge = g.NewEdge(arrives_at, qf413, sydney);
anEdge = g.NewEdge(origin_for, sydney, ba999);
anEdge = g.NewEdge(arrives_at, ba999, london);
//.........这里部分代码省略.........
示例4: Create1Vertices
public void Create1Vertices(bool vertexIdSetPerVertexType)
{
DataCache.MaximumMemoryUse = 10000000000; // 10 GB
bool dirExist = Directory.Exists(systemDir);
try
{
if (Directory.Exists(systemDir))
Directory.Delete(systemDir, true); // remove systemDir from prior runs and all its databases.
Directory.CreateDirectory(systemDir);
File.Copy(licenseDbFile, Path.Combine(systemDir, "4.odb"));
}
catch
{
File.Copy(licenseDbFile, Path.Combine(systemDir, "4.odb"));
}
using (SessionNoServer session = new SessionNoServer(systemDir, 5000, false, true))
{
session.BeginUpdate();
Graph g = new Graph(session, vertexIdSetPerVertexType);
session.Persist(g);
VertexType userType = g.NewVertexType("User");
VertexType otherType = g.NewVertexType("Other");
PropertyType userNamePropertyType = g.NewVertexProperty(userType, "NAME", DataType.String, PropertyKind.Indexed);
VertexType powerUserType = g.NewVertexType("PowerUser", userType);
EdgeType userFriendEdgeType = g.NewEdgeType("Friend", true, userType, userType);
EdgeType userBestFriendEdgeType = g.NewEdgeType("Best Friend", true, userType, userType, userFriendEdgeType);
EdgeType otherEdgeType = g.NewEdgeType("Other", true, userType, userType);
PropertyType bestFriendPropertyType = g.NewEdgeProperty(userFriendEdgeType, "START", DataType.DateTime, PropertyKind.Indexed);
Vertex kinga = userType.NewVertex();
Vertex robin = userType.NewVertex();
Vertex mats = powerUserType.NewVertex();
Vertex chiran = powerUserType.NewVertex();
Vertex other = otherType.NewVertex();
Edge bestFriend = kinga.AddEdge(userBestFriendEdgeType, robin);
Edge otherEdge = kinga.AddEdge(otherEdgeType, robin);
DateTime now = DateTime.UtcNow;
mats.SetProperty("Address", 1);
bestFriend.SetProperty(bestFriendPropertyType, now);
kinga.SetProperty(userNamePropertyType, "Kinga");
if (g.VertexIdSetPerType == false)
mats.SetProperty(userNamePropertyType, "Mats");
else
{
try
{
mats.SetProperty(userNamePropertyType, "Mats");
Assert.Fail("Invalid property for VertexType not handled");
}
catch (Exception)
{
}
}
try
{
other.SetProperty(userNamePropertyType, "Mats");
Assert.Fail("Invalid property for VertexType not handled");
}
catch (Exception)
{
}
try
{
otherEdge.SetProperty(bestFriendPropertyType, now);
Assert.Fail("Invalid property for VertexType not handled");
}
catch (Exception)
{
}
Vertex findMats = userNamePropertyType.GetPropertyVertex("Mats", true);
var list = userNamePropertyType.GetPropertyVertices("Mats", true).ToList();
//Edge findWhen = bestFriendPropertyType.GetPropertyEdge(now);
//var list2 = bestFriendPropertyType.GetPropertyEdges(now);
Console.WriteLine(findMats);
// session.Commit();
// session.BeginRead();
PropertyType adressProperty = g.FindVertexProperty(powerUserType, "Address");
Vertex find1 = adressProperty.GetPropertyVertex(1, true);
session.Abort();
/*session.BeginUpdate();
g.Unpersist(session);
session.Commit();
dirExist = Directory.Exists(systemDir);
try
{
if (Directory.Exists(systemDir))
Directory.Delete(systemDir, true); // remove systemDir from prior runs and all its databases.
Directory.CreateDirectory(systemDir);
File.Copy(licenseDbFile, Path.Combine(systemDir, "4.odb"));
}
catch
{
File.Copy(licenseDbFile, Path.Combine(systemDir, "4.odb"));
}*/
}
using (SessionNoServer session = new SessionNoServer(systemDir, 5000, false, true))
{
session.BeginUpdate();
//.........这里部分代码省略.........
示例5: Main
static readonly string systemDir = "VelocityGraphSample"; // appended to SessionBase.BaseDatabasePath
static void Main(string[] args)
{
using (SessionNoServer session = new SessionNoServer(systemDir))
{
if (Directory.Exists(session.SystemDirectory))
Directory.Delete(session.SystemDirectory, true); // remove systemDir from prior runs and all its databases.
Console.WriteLine("Running with databases in directory: " + session.SystemDirectory);
session.BeginUpdate();
Graph g = new Graph(session);
session.Persist(g);
// SCHEMA
// Add a node type for the movies, with a unique identifier and two indexed Propertys
VertexType movieType = g.NewVertexType("MOVIE");
PropertyType movieTitleType = g.NewVertexProperty(movieType, "TITLE", DataType.String, PropertyKind.Indexed);
PropertyType movieYearType = g.NewVertexProperty(movieType, "YEAR", DataType.Integer, PropertyKind.Indexed);
// Add a node type for the people, with a unique identifier and an indexed Property
VertexType peopleType = g.NewVertexType("PEOPLE");
PropertyType peopleNameType = g.NewVertexProperty(peopleType, "NAME", DataType.String, PropertyKind.Indexed);
// Add an undirected edge type with a Property for the cast of a movie
EdgeType castType = g.NewEdgeType("CAST", false);
PropertyType castCharacterType = g.NewEdgeProperty(castType, "CHARACTER", DataType.String, PropertyKind.Indexed);
// Add a directed edge type restricted to go from people to movie for the director of a movie
EdgeType directsType = g.NewEdgeType("DIRECTS", true, peopleType, movieType);
// DATA
// Add some MOVIE nodes
Vertex mLostInTranslation = movieType.NewVertex();
mLostInTranslation.SetProperty(movieTitleType, "Lost in Translation");
mLostInTranslation.SetProperty(movieYearType, (int)2003);
Vertex mVickyCB = movieType.NewVertex();
mVickyCB.SetProperty(movieTitleType, "Vicky Cristina Barcelona");
mVickyCB.SetProperty(movieYearType, (int)2008);
Vertex mManhattan = movieType.NewVertex();
mManhattan.SetProperty(movieTitleType, "Manhattan");
mManhattan.SetProperty(movieYearType, (int)1979);
// Add some PEOPLE nodes
Vertex pScarlett = peopleType.NewVertex();
pScarlett.SetProperty(peopleNameType, "Scarlett Johansson");
Vertex pBill = peopleType.NewVertex();
pBill.SetProperty(peopleNameType, "Bill Murray");
Vertex pSofia = peopleType.NewVertex();
pSofia.SetProperty(peopleNameType, "Sofia Coppola");
Vertex pWoody = peopleType.NewVertex();
pWoody.SetProperty(peopleNameType, "Woody Allen");
Vertex pPenelope = peopleType.NewVertex();
pPenelope.SetProperty(peopleNameType, "Penélope Cruz");
Vertex pDiane = peopleType.NewVertex();
pDiane.SetProperty(peopleNameType, "Diane Keaton");
// Add some CAST edges
Edge anEdge;
anEdge = g.NewEdge(castType, mLostInTranslation, pScarlett);
anEdge.SetProperty(castCharacterType, "Charlotte");
anEdge = g.NewEdge(castType, mLostInTranslation, pBill);
anEdge.SetProperty(castCharacterType, "Bob Harris");
anEdge = g.NewEdge(castType, mVickyCB, pScarlett);
anEdge.SetProperty(castCharacterType, "Cristina");
anEdge = g.NewEdge(castType, mVickyCB, pPenelope);
anEdge.SetProperty(castCharacterType, "Maria Elena");
anEdge = g.NewEdge(castType, mManhattan, pDiane);
anEdge.SetProperty(castCharacterType, "Mary");
anEdge = g.NewEdge(castType, mManhattan, pWoody);
anEdge.SetProperty(castCharacterType, "Isaac");
// Add some DIRECTS edges
anEdge = g.NewEdge(directsType, pSofia, mLostInTranslation);
anEdge = g.NewEdge(directsType, pWoody, mVickyCB);
anEdge = g.NewEdge(directsType, pWoody, mManhattan);
// QUERIES
// Get the movies directed by Woody Allen
Dictionary<Vertex, HashSet<Edge>> directedByWoody = pWoody.Traverse(directsType, Direction.Out);
// Get the cast of the movies directed by Woody Allen
Dictionary<Vertex, HashSet<Edge>> castDirectedByWoody = g.Traverse(directedByWoody.Keys.ToArray(), castType, Direction.Both);
// Get the movies directed by Sofia Coppola
Dictionary<Vertex, HashSet<Edge>> directedBySofia = pSofia.Traverse(directsType, Direction.Out);
// Get the cast of the movies directed by Sofia Coppola
//.........这里部分代码省略.........