public string DehydrateValue(object obj, IGraph uow) { Condition.Requires(obj).IsNotNull(); T tObj = (T)obj; IGraph actualUow = null; //if we don't have a uow we use the default one if (uow == null) { actualUow = Graph.NewDefault(); } List <string> lines = new List <string>(); foreach (var each in Maps) { MemberMapping <T> eachMap = (MemberMapping <T>)each; var val = eachMap.Getter(tObj); //note we inject a null check decoration below var mgr = actualUow.ChainOfResponsibility.GetValueManagerById(each.ValueManagerId).DecorateWithNullCheck(); var stringVal = mgr.DehydrateValue(val, actualUow); lines.Add(stringVal); } return(LengthEncoder.LengthEncodeList(lines.ToArray())); }
public void HydrateValue(object obj, string text, IGraph uow) { IGraph actualUow = null; //if we don't have a uow we use the default one if (uow == null) { actualUow = Graph.NewDefault(); } var arr = LengthEncoder.LengthDecodeList(text); Condition.Requires(arr.Count).IsEqualTo(this.Maps.Count); //iterate thru the Mappings and lines in parallel. for (int i = 0; i < arr.Count; i++) { var map = this.Maps[i]; MemberMapping <T> eachMap = (MemberMapping <T>)map; var line = arr[i]; //note we inject a null check decoration below var mgr = actualUow.ChainOfResponsibility.GetValueManagerById(map.ValueManagerId).DecorateWithNullCheck(); if (mgr == null) { continue; } var val = mgr.HydrateValue(line, actualUow); eachMap.Set((T)obj, val); } }
/// <summary> /// deserializes into a list of nodes /// </summary> /// <param name="storeText"></param> /// <returns></returns> public static List <GraphNode> HydrateNodeList(string storeText) { if (string.IsNullOrEmpty(storeText)) { return(null); } var lines = LengthEncoder.LengthDecodeList(storeText); var list = new List <GraphNode>(); for (int i = 0; i < lines.Count; i = i + 1) { if (string.IsNullOrEmpty(lines[i])) { continue; } string line = lines[i]; GraphNode node = line; list.Add(node); } return(list); }
public object HydrateValue(string nodeText, IGraph uow) { var dat = LengthEncoder.LengthDecode(nodeText); T obj = this.HydrateStrategy(dat); return(obj); }
public string DehydrateValue(object obj, IGraph uow) { Condition.Requires(obj).IsNotNull(); var data = ((DateTime)obj).ToString(); return(LengthEncoder.LengthEncode(data)); }
public object HydrateValue(string nodeText, IGraph uow) { var data = LengthEncoder.LengthDecode(nodeText); var dt = DateTime.Parse(data); return(dt); }
string IStringable.GetValue() { //split into: serializerid,instancetype name,serialized data var rv = LengthEncoder.LengthEncodeList(this.Id, this.InstanceType.AssemblyQualifiedName, this.SerializedData); return(rv); }
public object HydrateValue(string nodeText, IGraph uow) { if (string.IsNullOrEmpty(nodeText)) { return(null); } var list = LengthEncoder.LengthDecodeList(nodeText); Condition.Requires(list).HasLength(2); var mgr = uow.ChainOfResponsibility.GetValueManagerById(list.ElementAt(0)); if (mgr == null) { return(null); } //if the chain of responsibility produces This as manager, we're in an infinite loop situation and should back out if (mgr != null && mgr is UndeclaredValueManager) { return(null); } var obj = mgr.HydrateValue(list.ElementAt(1), uow); return(obj); }
public string DehydrateValue(object obj, IGraph uow) { Condition.Requires(obj).IsNotNull(); var data = this.DehydrateStrategy((T)obj); return(LengthEncoder.LengthEncode(data)); }
public string DehydrateValue(object obj, IGraph uow) { Condition.Requires(obj).IsNotNull(); var name = obj.GetType().AssemblyQualifiedName; var data = BinarySerializationUtil.Serialize(obj); return(LengthEncoder.LengthEncodeList(name, data)); }
public string DehydrateValue(object obj, IGraph uow) { Condition.Requires(obj).IsNotNull(); var name = obj.GetType().Name; var val = obj.ToString(); return(LengthEncoder.LengthEncodeList(name, val)); }
public string GetValue() { var storeText = this.NodeStore.DehydrateNodeStore(); var managerText = this.ChainOfResponsibility.GetValue(); string rv = LengthEncoder.LengthEncodeList(managerText, storeText); return(rv); }
public string GetValue() { var rv = this.GraphSerializeWithDefaults(); var data = LengthEncoder.MakeReadable(rv, "\t"); File.AppendAllText("stringabledump.txt", data + Environment.NewLine); return(rv); }
public string DehydrateValue(object obj, IGraph uow) { Condition.Requires(obj).IsNotNull(); var name = obj.GetType().AssemblyQualifiedName; IStringable s = obj as IStringable; var data = s.GetValue(); return(LengthEncoder.LengthEncodeList(name, data)); }
void IStringable.Parse(string text) { var list = LengthEncoder.LengthDecodeList(text); Condition.Requires(list).HasLength(3); this.Id = list[0]; this.InstanceType = TheTypeLocator.Instance.Locator.FindAssemblyQualifiedType(list[1]); this.SerializedData = list[2]; }
public string DehydrateValue(object obj, IGraph uow) { var typeName = obj.GetType().AssemblyQualifiedName; IHasHydrationMap hasMap = obj as IHasHydrationMap; var map = hasMap.GetHydrationMap(); Condition.Requires(map).IsNotNull(); var data = map.DehydrateValue(obj, uow); return(LengthEncoder.LengthEncodeList(typeName, data)); }
public object HydrateValue(string nodeText, IGraph uow) { var realData = LengthEncoder.LengthDecode(nodeText); Type cType = TheTypeLocator.Instance.Locator.FindAssemblyQualifiedType(realData); Condition.Requires(cType).IsNotNull(); var obj = ReflectionUtil.CreateUninitializedObject(cType); return(obj); }
public object HydrateValue(string nodeText, IGraph uow) { var list = LengthEncoder.LengthDecodeList(nodeText); Condition.Requires(list).HasLength(2); var typeName = list.ElementAt(0); var serData = list.ElementAt(1); Type type = TheTypeLocator.Instance.Locator.FindAssemblyQualifiedType(typeName); var obj = BinarySerializationUtil.Deserialize(type, serData); return(obj); }
public override string ToString() { List <string> data = new List <string>() { this.Id.ToString(), this.DateCreated.ToString(), this.GUID.ToString(), this.MachineName, this.IPAddress.ToString() }; return(LengthEncoder.LengthEncodeList(data.ToArray())); }
public void Parse(string text) { Condition.Requires(text).IsNotNullOrEmpty(); var arr = LengthEncoder.LengthDecodeList(text); Condition.Requires(arr).IsNotEmpty(); Condition.Requires(arr).HasLength(4); this.TraversalIndex = int.Parse(arr[0]); this.ValueManagerId = arr[1]; this.Id = arr[2]; this.Context = arr[3]; this.ValidateIsHydrated(); }
public void Parse(string text) { Condition.Requires(text).IsNotNullOrEmpty(); var list = LengthEncoder.LengthDecodeList(text); List <INodeValueManager> plugins = null; //strategy to load the managers (via assembly interrogation/plugin loading) Action initPlugins = () => { TypeContainer <INodeValueManager> types = TypeContainer <INodeValueManager> .NewDefault(); plugins = new List <INodeValueManager>(); foreach (var each in types.ContainedTypes) { try { INodeValueManager mgr = Activator.CreateInstance(each) as INodeValueManager; if (list.Contains(mgr.Id)) { plugins.Add(mgr); } } catch { } } }; //hydrate the managers list in the specified order var newList = new List <INodeValueManager>(); foreach (var each in list) { //get the mgr by id from the current managers (we want to use managers that we've explicitly added, first) // if it can't be found, get it from the plugins var mgr = this.ValueManagers.Find(x => x.Id == each); if (mgr == null) { //we can't find the manager so load the plugins if (plugins == null) { initPlugins(); } mgr = plugins.Find(x => x.Id == each); } Condition.Requires(mgr).IsNotNull(); newList.Add(mgr); } this.ValueManagers = newList; }
public object HydrateValue(string nodeText, IGraph uow) { //get the node that is already hydrated, with the same provided path var matches = uow.NodeStore.SearchOf <GraphNode>(LogicOfTo <GraphNode, bool> .New((x) => { if (x.NodeValue == null) { return(false); } return(x.Id.Equals(nodeText)); })); return(LengthEncoder.LengthDecode(matches[0].Id)); }
public string DehydrateValue(object obj, IGraph uow) { //we can handle this if it's a duplicate reference of something already in the node store var matches = uow.NodeStore.SearchOf <GraphNode>(LogicOfTo <GraphNode, bool> .New((x) => { if (x.NodeValue == null) { return(false); } return(object.ReferenceEquals(x.NodeValue, obj)); })); return(LengthEncoder.LengthEncode(matches[0].Id)); }
public object HydrateValue(string nodeText, IGraph uow) { var list = LengthEncoder.LengthDecodeList(nodeText); Condition.Requires(list).HasLength(2); //this is where we examine our context to see if we have the value manager required , if not we return null var mgr = uow.ChainOfResponsibility.GetValueManagerById(list[0]); if (mgr != null) { var rv = mgr.HydrateValue(list[1], uow); return(rv); } return(null); }
public object HydrateValue(string nodeText, IGraph uow) { var list = LengthEncoder.LengthDecodeList(nodeText); Condition.Requires(list).HasLength(2); Type cType = TheTypeLocator.Instance.Locator.FindAssemblyQualifiedType(list[0]); Condition.Requires(cType).IsNotNull(); var obj = ReflectionUtil.CreateUninitializedObject(cType); IHasHydrationMap hasMap = obj as IHasHydrationMap; var map = hasMap.GetHydrationMap(); map.HydrateValue(obj, list[1], uow); return(obj); }
public void Parse(string text) { Condition.Requires(text).IsNotNullOrEmpty(); var arr = LengthEncoder.LengthDecodeList(text); Condition.Requires(arr).HasLength(2); var storeText = arr[1]; var managerText = arr[0]; var set = ValueManagerChainOfResponsibility.New(); set.Parse(managerText); this.ChainOfResponsibility = set; var store = NodeStoreUtil.HydrateNodeStore(storeText); this.ReconstituteFromNodeStore(store); }
/// <summary> /// serializes the list of nodes by dehydrating each node and adding to a delimited string /// </summary> /// <param name="nodes"></param> /// <returns></returns> public static string DehydrateNodeList(List <GraphNode> nodes) { if (nodes == null) { return(null); } List <string> lines = new List <string>(); nodes.WithEach(node => { lines.Add(node.GetValue()); }); var rv = LengthEncoder.LengthEncodeList(lines.ToArray()); return(rv); }
public GraphingTest() : base(LogicOf <Nothing> .New((x) => { //build an object up var id = "id".BuildAsId(); var guid = Guid.NewGuid(); var hasGuid = id.HasGUID(guid); var now = DateTime.Now; var hasDateCreated = hasGuid.HasDateCreated(now); var lastTouchedDate = DateTime.Now; var hasLastTouched = hasDateCreated.HasDateLastTouched(lastTouchedDate); var localMachineName = NetUtil.GetLocalMachineName(); var hasLM = hasLastTouched.HasLocalMachineName(); var ip = NetUtil.GetLocalIPAddresses().First(); var hasIP = hasLM.HasIP(ip); var hasRS = hasIP.HasRandomString("blah"); var hasV = hasRS.HasVersion("v"); //graph it var objState1 = hasV.GraphSerializeWithDefaults(); var readable = LengthEncoder.MakeReadable(objState1, "\t"); readable.WithEach(i => { Debug.WriteLine(i); }); var graph = Graph.Parse(objState1, ValueManagerChainOfResponsibility.NewDefault()); var readable2 = GraphingUtil.ConvertToXML(graph).ToString(); var obj2 = objState1.GraphDeserializeWithDefaults() as HasVersionDecoration; Condition.Requires(obj2.Version).IsEqualTo("v"); Condition.Requires(obj2.As <HasRandomStringDecoration>(true).RandomString).IsEqualTo("blah"); Condition.Requires(obj2.As <HasIPDecoration>(true).IPAddress.ToString()).IsEqualTo(ip.ToString()); Condition.Requires(obj2.As <HasMachineNameDecoration>(true).MachineName).IsEqualTo(localMachineName); Condition.Requires(obj2.As <HasDateLastTouchedDecoration>(true).DateLastTouched.ToString()).IsEqualTo(lastTouchedDate.ToUniversalTime().ToString()); Condition.Requires(obj2.As <HasDateCreatedDecoration>(true).DateCreated.ToString()).IsEqualTo(now.ToUniversalTime().ToString()); Condition.Requires(obj2.As <HasGUIDDecoration>(true).GUID).IsEqualTo(guid); Condition.Requires(obj2.Id.ToString()).IsEqualTo("id"); hasV.Version = "v2"; var objState2 = hasV.GraphSerializeWithDefaults(); var obj3 = objState2.GraphDeserializeWithDefaults() as HasVersionDecoration; Condition.Requires(obj3.Version).IsEqualTo("v2"); })) { }
public static IStore DeserializeStore(string data, ValueManagerChainOfResponsibility managerSet) { if (string.IsNullOrEmpty(data)) { return(null); } var list = LengthEncoder.LengthDecodeList(data); var store = NaturalInMemoryStore.New(); list.WithEach(each => { var item = DeserializeItem(each, managerSet); IHasId obj = item as IHasId; store.SaveItem(obj); }); return(store); }
public static XDocument ConvertToXML(Graph graph) { XDocument doc = new XDocument(); XElement root = new XElement("root"); doc.Add(root); var nodes = graph.NodeStore.GetAll(); nodes = nodes.OrderBy((x) => { return(x.TraversalIndex); }).ToList(); XElement parent = null; nodes.WithEach(node => { var name = ScrubBackingFieldName(node.Path.CurrentSegment.Path); var nameArr = name.Split(new string[] { " " }, StringSplitOptions.None); var nodeName = nameArr[0]; var depth = nameArr.Length == 2 ? nameArr[1] : "0"; var mgr = graph.ChainOfResponsibility.GetValueManagerById(node.ValueManagerId); var context = string.Join(",", LengthEncoder.MakeReadable(node.Context, "").ToArray()); XElement layer = new XElement(nodeName, new XAttribute("i", node.TraversalIndex), new XAttribute("depth", depth), new XAttribute("mgr", node.ValueManagerId), context); //if (parent == null) //{ root.Add(layer); //} //else //{ // parent.Add(layer); //} //parent = layer; }); return(doc); }