public GraphSonUtility(GraphSonMode mode, IElementFactory factory, ElementPropertyConfig config) { if (config == null) { throw new ArgumentNullException(nameof(config)); } _vertexPropertyKeys = config.VertexPropertyKeys; _edgePropertyKeys = config.EdgePropertyKeys; _vertexPropertiesRule = config.VertexPropertiesRule; _edgePropertiesRule = config.EdgePropertiesRule; _mode = mode; _factory = factory; _hasEmbeddedTypes = mode == GraphSonMode.EXTENDED; // ReSharper disable PossibleMultipleEnumeration _includeReservedVertexId = IncludeReservedKey(mode, GraphSonTokens.Id, _vertexPropertyKeys, _vertexPropertiesRule); _includeReservedEdgeId = IncludeReservedKey(mode, GraphSonTokens.Id, _edgePropertyKeys, _edgePropertiesRule); _includeReservedVertexType = IncludeReservedKey(mode, GraphSonTokens.UnderscoreType, _vertexPropertyKeys, _vertexPropertiesRule); _includeReservedEdgeType = IncludeReservedKey(mode, GraphSonTokens.UnderscoreType, _edgePropertyKeys, _edgePropertiesRule); _includeReservedEdgeLabel = IncludeReservedKey(mode, GraphSonTokens.Label, _edgePropertyKeys, _edgePropertiesRule); _includeReservedEdgeOutV = IncludeReservedKey(mode, GraphSonTokens.OutV, _edgePropertyKeys, _edgePropertiesRule); _includeReservedEdgeInV = IncludeReservedKey(mode, GraphSonTokens.InV, _edgePropertyKeys, _edgePropertiesRule); // ReSharper restore PossibleMultipleEnumeration }
private static bool IncludeKey(string key, IEnumerable <string> propertyKeys, ElementPropertyConfig.ElementPropertiesRule rule) { if (!((propertyKeys != null || !(string.IsNullOrWhiteSpace(key))) || string.IsNullOrEmpty(key))) { throw new ArgumentException("Invalid argument combination"); } if (propertyKeys == null) { // when null always include the key and shortcut this piece return(true); } // default the key situation. if it's included then it should be explicitly defined in the // property keys list to be included or the reverse otherwise var keySituation = rule == ElementPropertyConfig.ElementPropertiesRule.Include; switch (rule) { case ElementPropertyConfig.ElementPropertiesRule.Include: keySituation = propertyKeys.Contains(key); break; case ElementPropertyConfig.ElementPropertiesRule.Exclude: keySituation = !propertyKeys.Contains(key); break; } return(keySituation); }
private static bool IncludeReservedKey(GraphSonMode mode, string key, IEnumerable <string> propertyKeys, ElementPropertyConfig.ElementPropertiesRule rule) { if (string.IsNullOrWhiteSpace(key)) { throw new ArgumentNullException(nameof(key)); } // the key is always included in modes other than COMPACT. if it is COMPACT, then validate that the // key is in the property key list return(mode != GraphSonMode.COMPACT || IncludeKey(key, propertyKeys, rule)); }
private static IDictionary CreatePropertyMap(IElement element, IEnumerable <string> propertyKeys, ElementPropertyConfig.ElementPropertiesRule rule) { if (element == null) { throw new ArgumentNullException(nameof(element)); } var map = new Dictionary <string, object>(); if (propertyKeys == null) { foreach (var key in element.GetPropertyKeys()) { map.Add(key, element.GetProperty(key)); } } else { if (rule == ElementPropertyConfig.ElementPropertiesRule.Include) { foreach (var key in propertyKeys) { var valToPutInMap = element.GetProperty(key); if (valToPutInMap != null) { map.Add(key, valToPutInMap); } } } else { foreach (var key in element.GetPropertyKeys()) { // ReSharper disable PossibleMultipleEnumeration if (!propertyKeys.Contains(key)) { // ReSharper restore PossibleMultipleEnumeration map.Add(key, element.GetProperty(key)); } } } } return(map); }