private static void WriteItem <T>(T item, NodeReference node) { var entityType = item.GetType(); if (EntityTypeDescriptor.IsSimpleType(entityType)) { if (item != null) { node.Set(item.ToString()); } } else if (EntityTypeDescriptor.IsSimpleNullableType(entityType)) { node.Set(item != null ? item.ToString() : null); } else if (EntityTypeDescriptor.IsArrayType(entityType)) { WriteArray(node, item as Array); } else if (EntityTypeDescriptor.IsSupportedEnumerable(entityType)) { var items = item as IEnumerable; if (items != null) { WriteEnumerable(node, items); } } else { WriteComplexEntity(item, node); } }
private static void WriteComplexEntity <TEntity>(TEntity entity, NodeReference node) { if (entity == null) { return; } var entityType = entity.GetType(); var underlyingType = EntityTypeDescriptor.IsNullableType(entityType) ? Nullable.GetUnderlyingType(entityType) : entityType; var columns = EntityTypeDescriptor.GetTypeDescription(underlyingType).Columns; foreach (var column in columns) { node.AppendSubscript(column.ColumnAttribute.Name ?? column.ColumnInfo.Name); if (column.IsSimpleColumn) { var value = column.ColumnInfo.GetValue(entity, null); if (value != null) { if (column.IsNullableColumn) { node.Set(value != null ? value.ToString() : null); } else { node.Set(value.ToString()); } } } else if (column.IsArrayColumn) { var array = column.ColumnInfo.GetValue(entity, null) as Array; WriteArray(node, array); } else if (column.IsEnumerableColumn) { var items = column.ColumnInfo.GetValue(entity, null) as IEnumerable; if (items != null) { WriteEnumerable(node, items); } } else { WriteComplexEntity(column.ColumnInfo.GetValue(entity, null), node); } node.SetSubscriptCount(node.GetSubscriptCount() - 1); } }
// graph constructor is marked INTERNAL because we want the client to use the // static class factory method CreateGraph(), which redirects here after doing checks. // For opening existing graphs, // we provide another method called OpenGraph() which redirects here also. internal GlGraph(string graph_name) { bool creating_new = !GlobalsGraphAdmin.AllGraphs().Contains(graph_name); _GlNodeRef = GlobalsGraphAdmin.ActiveConnection().CreateNodeReference(graph_name); if (creating_new) _GlNodeRef.Set(GlobalsGraphAdmin.GL_GRAPH_FLAG); // format identifier, causes persistence else { // opening an existing graph. Start by initializing the existing nodes string loop_node_guid = _GlNodeRef.NextSubscript(GlobalsGraphAdmin.GL_NODES_SUBSCRIPT, ""); while (loop_node_guid != "") { Guid new_guid = Guid.Empty; if (Guid.TryParse(loop_node_guid, out new_guid)) AllNodesByGuid.Add(new_guid, new GlGraphNode(this, new_guid)); else _GlNodeRef.Kill(GlobalsGraphAdmin.GL_NODES_SUBSCRIPT, loop_node_guid); // clean up bad data loop_node_guid = _GlNodeRef.NextSubscript(GlobalsGraphAdmin.GL_NODES_SUBSCRIPT, loop_node_guid); } // now loop again and load the edges foreach (GlGraphNode loop_node in AllNodes) { loop_node.InitializeEdges(); } } }
// constructor is marked INTERNAL because we want the client to use the // static class factory method CreateDocSet(), which redirects here after doing checks. // For opening existing doc sets, // we provide another method called OpenDocSet() which redirects here also. internal GlDocSet(string docset_name) { bool creating_new = !GlobalsDocDB.AllDocSetNames().Contains(docset_name); _GlNodeRef = GlobalsDocDB.ActiveConnection().CreateNodeReference(docset_name); if (creating_new) { _GlNodeRef.Set(GlobalsDocDB.GL_DOCS_FLAG); // format identifier, causes persistence } else { // opening an existing doc set. Start by initializing the existing nodes string loop_node_guid = _GlNodeRef.NextSubscript(""); while (loop_node_guid != "") { Guid new_guid = Guid.Empty; if (Guid.TryParse(loop_node_guid, out new_guid)) { AllDocsByGuid.Add(new_guid, new GlDoc(this, new_guid)); } else { _GlNodeRef.Kill(loop_node_guid); // clean up bad data } loop_node_guid = _GlNodeRef.NextSubscript(loop_node_guid); } } }
// CONSTRUCTORS (internal). Note that GlDoc objects for existing documents // are created by the GlDocSet constructor. GlDoc objects for docs being // created by the user are created by GlDocSet.CreateNewDoc(). These two // GlDocSet methods call these internal constructors for GlDoc. // create a doc object for a brand-new doc (does not exist in DB yet) internal GlDoc(GlDocSet parent_docset) { _DocUID = Guid.NewGuid(); _ParentDocSet = parent_docset; _DocNodeRef = GlobalsDocDB.ActiveConnection().CreateNodeReference(_ParentDocSet.Name); _DocNodeRef.AppendSubscript(_DocUID.ToString()); _DocNodeRef.Set("GlDoc"); // dummy }
private bool EnsureDataType(string property_name, ValueType desired_type) { ValueType current_type = PropertyType(property_name); if (current_type == desired_type) { return(true); // all's well } if (current_type == ValueType.UNKNOWN) // set it { _DocNodeRef.Set(DataTypeFlag(desired_type), property_name, DATA_TYPE_SUBSCRIPT); return(true); // all set } // only other possibility is that it's currently set to some other type; fail return(false); }
private static long IncrementIdentity(NodeReference node) { var identityValue = node.GetObject(IdentityValueSubscriptName); var identitySeed = identityValue == null ? 0 : Convert.ToInt64(identityValue); node.Set(++identitySeed, IdentityValueSubscriptName); return(identitySeed); }
static void CreateSecondBranch(NodeReference node, Connection myConn) { node.SetSubscriptCount(1); node.Set("Some bank 2", "DXO987"); node.Set(65241.24, "DXO987", 26032009100100); string slip = "Smith John||1965"; byte[] bytes = System.Text.Encoding.GetEncoding(1251).GetBytes(slip); node.Set(bytes, "DXO987", 26032009100100, 6541963285249512); ValueList myList = myConn.CreateList(); myList.Append(1, 29242664509184, "Jane Doe", 500.26, "Recurring payment to Amazon"); node.Set(myList, "DXO987", 26032009100100, 6541963285249512, 1); myList.Close(); myList = myConn.CreateList(); myList.Append(0, 26548962495545, "John Doe", 1015.10, "Payment for delivery"); node.Set(myList, "DXO987", 26032009100100, 6541963285249512, 2); myList.Close(); Console.WriteLine("Info about second bank is createed"); }
static void CreateFirstBranch(NodeReference node, Connection myConn) { node.AppendSubscript("111111111111"); node.Set("Smith,John"); node.AppendSubscript("DBO546"); node.Set("Some bank 1"); node.AppendSubscript(29244825509100); node.Set(28741.35); node.AppendSubscript(2145632596588547); string slip = "Smith,John/1965"; byte[] bytes = System.Text.Encoding.GetEncoding(1251).GetBytes(slip); node.Set(bytes); node.AppendSubscript(1); ValueList myList = myConn.CreateList(); myList.Append(0, 29244225564111, "John Doe", 500.26, "Payment for goods from ToysRUs"); node.Set(myList); myList.Close(); node.SetSubscriptCount(4); node.AppendSubscript(2); myList = myConn.CreateList(); myList.Append(0, 26032009100100, "John Smith", 115.54, "Transfer to own account in different bank"); node.Set(myList); myList.Close(); Console.WriteLine("Info about first bank is createed"); }
static void CreateThirdBranch(NodeReference node, Connection myConn) { node.SetSubscript(2, "DXJ342"); node.Set("Some bank 3"); node.SetSubscript(3, 26008962495545); node.Set(126.32); node.SetSubscript(4, 4567098712347654); string slip = "John Smith 1965"; byte[] bytes = System.Text.Encoding.GetEncoding(1251).GetBytes(slip); node.Set(bytes); node.SetSubscript(5, 1); ValueList myList = myConn.CreateList(); myList.Append(0, 29244825509100, "John Smith", 115.54, "Transfer to own account in different bank"); node.Set(myList); myList.Close(); node.SetSubscript(5, 2); myList = myConn.CreateList(); myList.Append(1, 26032009100100, "John Smith", 1015.54, "Transfer to own account in different bank"); node.Set(myList); myList.Close(); Console.WriteLine("Info about third bank is createed"); }
private static void WriteEnumerable(NodeReference node, IEnumerable items) { var index = 0; node.Kill(); foreach (var item in items) { node.AppendSubscript(ToSubscriptString(index)); WriteItem(item, node); node.SetSubscriptCount(node.GetSubscriptCount() - 1); index++; } node.AppendSubscript(EnumerableLengthsSubscriptName); node.Set(ToSubscriptString(index)); node.SetSubscriptCount(node.GetSubscriptCount() - 1); }
private static void WriteArray(NodeReference node, Array array) { node.Kill(); if (array == null) { return; } node.AppendSubscript(EnumerableLengthsSubscriptName); node.Set(ToSubscriptString(GetArrayLengths(array))); node.SetSubscriptCount(node.GetSubscriptCount() - 1); var indexedElements = GetIndexedElements(array, new List <int>()); foreach (var indexedElement in indexedElements) { node.AppendSubscript(ToSubscriptString(indexedElement.Item2)); WriteItem(indexedElement.Item1, node); node.SetSubscriptCount(node.GetSubscriptCount() - 1); } }
// graph constructor is marked INTERNAL because we want the client to use the // static class factory method CreateGraph(), which redirects here after doing checks. // For opening existing graphs, // we provide another method called OpenGraph() which redirects here also. internal GlGraph(string graph_name) { bool creating_new = !GlobalsGraphAdmin.AllGraphs().Contains(graph_name); _GlNodeRef = GlobalsGraphAdmin.ActiveConnection().CreateNodeReference(graph_name); if (creating_new) { _GlNodeRef.Set(GlobalsGraphAdmin.GL_GRAPH_FLAG); // format identifier, causes persistence } else { // opening an existing graph. Start by initializing the existing nodes string loop_node_guid = _GlNodeRef.NextSubscript(GlobalsGraphAdmin.GL_NODES_SUBSCRIPT, ""); while (loop_node_guid != "") { Guid new_guid = Guid.Empty; if (Guid.TryParse(loop_node_guid, out new_guid)) { AllNodesByGuid.Add(new_guid, new GlGraphNode(this, new_guid)); } else { _GlNodeRef.Kill(GlobalsGraphAdmin.GL_NODES_SUBSCRIPT, loop_node_guid); // clean up bad data } loop_node_guid = _GlNodeRef.NextSubscript(GlobalsGraphAdmin.GL_NODES_SUBSCRIPT, loop_node_guid); } // now loop again and load the edges foreach (GlGraphNode loop_node in AllNodes) { loop_node.InitializeEdges(); } } }