private User makeUser(GDID id) { var chance = ExternalRandomGenerator.Instance.NextScaledRandomInteger(0, 100); NFX.Collections.StringMap sm = null; if (chance > 40) { sm = new NFX.Collections.StringMap(); for (var i = 0; i < (chance & 0x7); i++) { sm.Add(i.ToString(), chance.ToString()); } } return(new User(id) { Name = "Person #" + id.ToString(), Address = ((id.Counter & 1) == 0) ? id.ToString() + " Hard Drive Ave, Los Angeles, CA 91606" : null, DOB = new DateTime(1980, 1, 1), SocialMsg = sm, BuyerScore = 34, SellerScore = 473, GVendor = id.Counter % 3 == 0 ? null : (GDID?)id, IsVendor = true, ReturnApproved = false }); }
public void GDID_10() { var gdid = new GDID(1293, 3, 57); var s = gdid.ToString(); Console.WriteLine(s); Assert.AreEqual("GDID[1293:3458764513820540985(3,57)]", s); }
public override FakeRow Populate(GDID parentGdid) { int age = getFakeAge(parentGdid); ID = parentGdid; Name = NaturalTextGenerator.GenerateFullName(true); Age = age; DOB = DateTime.Now.AddYears(-age); Sex = parentGdid.ID % 2 == 0 ? Sex.Male : Sex.Female; Income = parentGdid.ID % 79 * 1000; Debt = parentGdid.ID % 11 * 1000; Rating = parentGdid.ID % 2 == 0 ? (double?)null : 3.25; Notes = parentGdid.ToString(); Voter = parentGdid.ID % 2 == 0 ? (bool?)null : true; MilitarySvc = parentGdid.ID % 2 == 0 ? (bool?)null : false; Address1 = NaturalTextGenerator.GenerateAddressLine(); Address2 = parentGdid.ID % 7 == 0 ? NaturalTextGenerator.GenerateAddressLine() : null; City = NaturalTextGenerator.GenerateCityName(); State = "OH"; Zip = "44000" + parentGdid.ID % 999; Phone1 = "(555) 222-3222"; Phone2 = parentGdid.ID % 3 == 0 ? "(555) 737-9789" : null; Email1 = NaturalTextGenerator.GenerateEMail(); Email2 = parentGdid.ID % 5 == 0 ? NaturalTextGenerator.GenerateEMail() : null; URL = parentGdid.ID % 2 == 0 ? "https://ibm.com/products/" + parentGdid.ID : null; Tags = getFakeTags(); return(this); }
public void GDID_10() { var gdid = new GDID(1293, 3, 57); var s = gdid.ToString(); Console.WriteLine(s); Assert.AreEqual("1293:3:57", s); }
private static string getAllGDIDFormats(GDID gdid) { var sb = new StringBuilder(); // native sb.AppendLine(gdid.ToString()); // hex sb.AppendLine("0x" + gdid.ToHexString()); // BASE64 sb.AppendLine(Convert.ToBase64String(gdid.Bytes)); // Elink var link = new ELink(gdid); for (var cnt = 0; cnt <= ELink.VARIATIONS; cnt++) { sb.AppendLine(link.Encode((byte)cnt)); } // byte array sb.AppendLine("[" + string.Join(", ", gdid.Bytes) + "]"); return(sb.ToString()); }
public void GDID_10() { var gdid = new GDID(1293, 3, 57); var s = gdid.ToString(); s.See(); Aver.AreEqual("1293:3:57", s); }
public override void SerializeToBSON(BSONSerializer serializer, BSONDocument doc, IBSONSerializable parent, ref object context) { base.SerializeToBSON(serializer, doc, parent, ref context); doc.Add(BSON_FLD_ENTITY, m_Entity); doc.Add(BSON_FLD_G_SHARD, m_G_Shard.ToString()); doc.Add(BSON_FLD_G_ENTITY, m_G_Entity.ToString()); doc.Add(BSON_FLD_DIMS, m_Dimensions); }
/// <summary> /// Remove node by GDID from Databases /// </summary> public GraphChangeStatus RemoveNode(GDID gNode) { try { return(DoRemoveNode(gNode)); } catch (Exception ex) { Log(MessageType.Error, "RemoveNode", ex.ToMessageWithType(), ex); throw new GraphException(StringConsts.GS_DELETE_NODE_ERROR.Args(gNode.ToString()), ex); } }
/// <summary> /// Fetches the GraphNode by its unique GDID or null if not found /// </summary> public GraphNode GetNode(GDID gNode) { try { return(DoGetNode(gNode)); } catch (Exception ex) { Log(MessageType.Error, "GetNode", ex.ToMessageWithType(), ex); throw new GraphException(StringConsts.GS_GET_NODE_ERROR.Args(gNode.ToString()), ex); } }
/// <summary> /// Deletes friend connections. The operation drops both connections from node and friend /// </summary> GraphChangeStatus IGraphFriendSystem.DeleteFriend(GDID gNode, GDID gFriendNode) { try { return(DoDeleteFriend(gNode, gFriendNode)); } catch (Exception ex) { Log(MessageType.Error, "DeleteFriend", ex.ToMessageWithType(), ex); throw new GraphException(StringConsts.GS_DELETE_FRIEND_ERROR.Args(gNode.ToString(), gFriendNode.ToString()), ex); } }
/// <summary> /// Removes the subscription. Unlike friends the subscription connection is uni-directional /// </summary> void IGraphEventSystem.Unsubscribe(GDID gRecipientNode, GDID gEmitterNode) { try { DoUnsubscribe(gRecipientNode, gEmitterNode); } catch (Exception ex) { Log(MessageType.Error, "DoUnsubscribe", ex.ToMessageWithType(), ex); throw new GraphException(StringConsts.GS_UNSUBSCRIBE_ERROR.Args(gRecipientNode.ToString(), gEmitterNode.ToString()), ex); } }
/// <summary> /// Adds a bidirectional friend connection between gNode and gFriendNode /// If friend connection already exists updates the approve/ban stamp by the receiving party (otherwise approve is ignored) /// If approve==null then no stamps are set, if true connection is approved given that gNode is not the one who initiated the connection, /// false then connection is banned given that gNode is not the one who initiated the connection /// </summary> GraphChangeStatus IGraphFriendSystem.AddFriend(GDID gNode, GDID gFriendNode, bool?approve) { try { return(DoAddFriend(gNode, gFriendNode, approve)); } catch (Exception ex) { Log(MessageType.Error, "AddFriend", ex.ToMessageWithType(), ex); throw new GraphException(StringConsts.GS_ADD_FRIEND_ERROR.Args(gNode.ToString(), gFriendNode.ToString()), ex); } }
/// <summary> /// Adds a new friend list id for the particular node. The list id may not contain commas /// </summary> GraphChangeStatus IGraphFriendSystem.AddFriendList(GDID gNode, string list, string description) { try { return(DoAddFriendList(gNode, list, description)); } catch (Exception ex) { Log(MessageType.Error, "AddFriendList", ex.ToMessageWithType(), ex); throw new GraphException(StringConsts.GS_ADD_FRIEND_LIST_ERROR.Args(gNode.ToString()), ex); } }
/// <summary> /// Returns an enumeration of friend list ids for the particular node /// </summary> IEnumerable <string> IGraphFriendSystem.GetFriendLists(GDID gNode) { try { return(DoGetFriendLists(gNode)); } catch (Exception ex) { Log(MessageType.Error, "GetFriendLists", ex.ToMessageWithType(), ex); throw new GraphException(StringConsts.GS_GET_FRIEND_LISTS_ERROR.Args(gNode.ToString()), ex); } }
/// <summary> /// Returns Subscribers for Emitter from start position /// </summary> IEnumerable <GraphNode> IGraphEventSystem.GetSubscribers(GDID gEmitterNode, long start, int count) { try { return(DoGetSubscribers(gEmitterNode, start, count)); } catch (Exception ex) { Log(MessageType.Error, "GetSubscribers", ex.ToMessageWithType(), ex); throw new GraphException(StringConsts.GS_GET_SUBSCRIBER_ERROR.Args(gEmitterNode.ToString()), ex); } }
public void Test_Values(uint era, ulong id) { var g = new GDID(era, id); var str = g.ToString(); var hex = g.ToHexString(); var g2 = GDID.Parse(str); var g3 = GDID.Parse(hex); Aver.AreEqual(g, g2); Aver.AreEqual(g, g3); Aver.AreEqual(g2, g3); Aver.AreObjectsEqual(g, g2); Aver.AreObjectsEqual(g, g3); Aver.AreObjectsEqual(g2, g3); Aver.IsTrue(g == g2); Aver.IsTrue(g == g3); Aver.IsTrue(g2 == g3); Aver.IsFalse(g != g3); Aver.IsFalse(g != g2); Aver.IsFalse(g2 != g3); Aver.AreEqual(g.GetHashCode(), g2.GetHashCode()); Aver.AreEqual(g.GetHashCode(), g3.GetHashCode()); Aver.AreEqual(g.GetDistributedStableHash(), g2.GetDistributedStableHash()); Aver.AreEqual(g.GetDistributedStableHash(), g3.GetDistributedStableHash()); var json = new { g }.ToJson(); "String: {0} \n Hex: {1} \n Json: {2} \n".SeeArgs(str, hex, json); var got = json.JsonToDataObject() as JsonDataMap; Aver.AreEqual(g, got["g"].AsGDID()); var buf = g.Bytes; var g4 = new GDID(buf); Aver.AreEqual(g, g4); var buf2 = new byte[128]; g.WriteIntoBuffer(buf2, 18); var g5 = new GDID(buf2, 18); Aver.AreEqual(g, g5); }
public static PersonRow MakeFake(GDID parentGdid) { var age = (int)(parentGdid.ID % 99); var tags = Ambient.Random.NextRandomInteger > 0 ? new string[Ambient.Random.NextScaledRandomInteger(1, 20)] : null; if (tags != null) { for (int i = 0; i < tags.Length; i++) { tags[i] = ((char)('a' + i)) + "tag"; } } var pers = new PersonRow() { ID = parentGdid, Name = Text.NaturalTextGenerator.GenerateFullName(true), Age = age, DOB = DateTime.Now.AddYears(-age), Sex = (parentGdid.ID % 2) == 0 ? Sex.Male : Sex.Female, Income = (parentGdid.ID % 79) * 1000, Debt = (parentGdid.ID % 11) * 1000, Rating = (parentGdid.ID % 2) == 0 ? (double?)null : 3.25, Notes = parentGdid.ToString(), Voter = (parentGdid.ID % 2) == 0 ? (bool?)null : true, MilitarySvc = (parentGdid.ID % 2) == 0 ? (bool?)null : false, Address1 = Text.NaturalTextGenerator.GenerateAddressLine(), Address2 = (parentGdid.ID % 7) == 0 ? Text.NaturalTextGenerator.GenerateAddressLine() : null, City = Text.NaturalTextGenerator.GenerateCityName(), State = "OH", Zip = "44000" + (parentGdid.ID % 999), Phone1 = "(555) 222-3222", Phone2 = (parentGdid.ID % 3) == 0 ? "(555) 737-9789" : null, Email1 = Text.NaturalTextGenerator.GenerateEMail(), Email2 = (parentGdid.ID % 5) == 0 ? Text.NaturalTextGenerator.GenerateEMail() : null, URL = (parentGdid.ID % 2) == 0 ? "https://ibm.com/products/" + parentGdid.ID : null, Tags = tags }; return(pers); }
public static PersonRow MakeFake(GDID parentGdid) { var age = (int)(parentGdid.ID % 99); var tags = NFX.ExternalRandomGenerator.Instance.NextRandomInteger > 0 ? new string[NFX.ExternalRandomGenerator.Instance.NextScaledRandomInteger(1, 20)] : null; if (tags != null) { for (int i = 0; i < tags.Length; i++) { tags[i] = ((char)('a' + i)) + "tag"; } } var pers = new PersonRow() { ID = parentGdid, Name = NFX.Parsing.NaturalTextGenerator.Generate(30), Age = age, DOB = DateTime.Now.AddYears(-age), Sex = (parentGdid.ID % 2) == 0 ? Sex.Male : Sex.Female, Income = (parentGdid.ID % 79) * 1000, Debt = (parentGdid.ID % 11) * 1000, Rating = (parentGdid.ID % 2) == 0 ? (double?)null : 3.25, Notes = parentGdid.ToString(), Voter = (parentGdid.ID % 2) == 0 ? (bool?)null : true, MilitarySvc = (parentGdid.ID % 2) == 0 ? (bool?)null : false, Address1 = NFX.Parsing.NaturalTextGenerator.Generate(50), Address2 = (parentGdid.ID % 7) == 0 ? NFX.Parsing.NaturalTextGenerator.Generate(50) : null, City = (parentGdid.ID % 2) == 0 ? "Magdaburg" : "Odessa On Don", State = "OH", Zip = "44000" + (parentGdid.ID % 999), Phone1 = "(555) 222-3222", Phone2 = (parentGdid.ID % 3) == 0 ? "(555) 737-9789" : null, Email1 = "*****@*****.**", Email2 = (parentGdid.ID % 5) == 0 ? "*****@*****.**" : null, URL = (parentGdid.ID % 2) == 0 ? "https://ibm.com/products/" + parentGdid.ID : null, Tags = tags }; return(pers); }
private Employee makeEmployee(GDID gdid) { var counter = gdid.Counter; var dob = new DateTime(Ambient.Random.NextScaledRandomInteger(1970, 1990), Ambient.Random.NextScaledRandomInteger(1, 12), Ambient.Random.NextScaledRandomInteger(1, 28)); var salary = Ambient.Random.NextScaledRandomDouble(100, 300).AsDecimal(); return(new Employee { GDID = gdid, Name = Text.NaturalTextGenerator.GenerateFullName(), Code = Guid.NewGuid(), DOB = dob, Department = "DPT" + (counter % 3).ToString(), IsManager = (counter % 10) == 0, Experience = Ambient.Random.NextScaledRandomInteger(10, 20), Rate = Ambient.Random.NextScaledRandomDouble(1.0, 2.0), Salary = Math.Round(salary, 2), Note = "This is employee #" + gdid.ToString() }); }
/// <summary> /// Assigns lists to the gNode (the operation is unidirectional - it only assigns the lists on the gNode). /// Lists is a comma-separated list of friend list ids /// </summary> GraphChangeStatus IGraphFriendSystem.AssignFriendLists(GDID gNode, GDID gFriendNode, string lists) { try { return(DoAssignFriendLists(gNode, gFriendNode, lists)); } catch (Exception ex) { Log(MessageType.Error, "AssignFriendLists", ex.ToMessageWithType(), ex); throw new GraphException(StringConsts.GS_ASSIGN_FRIEND_LISTS_ERROR.Args(gNode.ToString(), gFriendNode.ToString()), ex); } }
/// <summary> /// Returns an estimated approximate number of subscribers that an emitter has /// </summary> long IGraphEventSystem.EstimateSubscriberCount(GDID gEmitterNode) { try { return(DoEstimateSubscriberCount(gEmitterNode)); } catch (Exception ex) { Log(MessageType.Error, "EstimateSubscriberCount", ex.ToMessageWithType(), ex); throw new GraphException(StringConsts.GS_ESTIMATE_SUBSCRIPTION_COUNT_ERROR.Args(gEmitterNode.ToString()), ex); } }
public override string ToString() => $"ShardKey({DataType}, `{(ObjectValue != null ? ObjectValue.ToString() : DataType == Type.Gdid ? Buffer.ToString() : "{0:X8}".Args(Buffer.ID) )}`)";
public static PersonRow MakeFake(GDID parentGdid) { var age = (int)(parentGdid.ID % 99); var tags = NFX.ExternalRandomGenerator.Instance.NextRandomInteger > 0 ? new string[NFX.ExternalRandomGenerator.Instance.NextScaledRandomInteger(1, 20)] : null; if (tags != null) for (int i = 0; i < tags.Length; i++) { tags[i] = ((char)('a' + i)) + "tag"; } var pers = new PersonRow() { ID = parentGdid, Name = NFX.Parsing.NaturalTextGenerator.Generate(30), Age = age, DOB = DateTime.Now.AddYears(-age), Sex = (parentGdid.ID % 2) == 0 ? Sex.Male : Sex.Female, Income = (parentGdid.ID % 79) * 1000, Debt = (parentGdid.ID % 11) * 1000, Rating = (parentGdid.ID % 2) == 0 ? (double?)null : 3.25, Notes = parentGdid.ToString(), Voter = (parentGdid.ID % 2) == 0 ? (bool?)null : true, MilitarySvc = (parentGdid.ID % 2) == 0 ? (bool?)null : false, Address1 = NFX.Parsing.NaturalTextGenerator.Generate(50), Address2 = (parentGdid.ID % 7) == 0 ? NFX.Parsing.NaturalTextGenerator.Generate(50) : null, City = (parentGdid.ID % 2) == 0 ? "Magdaburg" : "Odessa On Don", State = "OH", Zip = "44000" + (parentGdid.ID % 999), Phone1 = "(555) 222-3222", Phone2 = (parentGdid.ID % 3) == 0 ? "(555) 737-9789" : null, Email1 = "*****@*****.**", Email2 = (parentGdid.ID % 5) == 0 ? "*****@*****.**" : null, URL = (parentGdid.ID % 2) == 0 ? "https://ibm.com/products/" + parentGdid.ID : null, Tags = tags }; return pers; }