예제 #1
0
        public Dictionary <string, dynamic> Dictify(dynamic objectData, IGraphSONWriter writer)
        {
            ITraversal traversal = objectData;
            var        bytecode  = traversal.Bytecode;

            return(writer.ToDict(bytecode));
        }
 protected CustomGraphSON2Writer(
     Dictionary <Type, IGraphSONSerializer> serializers,
     IReadOnlyDictionary <Type, IGraphSONSerializer> customSerializers,
     IGraphSONWriter writer)
 {
     Serializers        = serializers;
     _customSerializers = customSerializers;
     Writer             = writer;
 }
        private IEnumerable <dynamic> DictifyInstruction(Instruction instruction, IGraphSONWriter writer)
        {
            var result = new List <dynamic> {
                instruction.OperatorName
            };

            result.AddRange(instruction.Arguments.Select(arg => writer.ToDict(arg)));
            return(result);
        }
예제 #4
0
        public Dictionary <string, dynamic> Dictify(dynamic objectData, IGraphSONWriter writer)
        {
            object value = objectData;

            if (StringifyValue)
            {
                value = string.Format(CultureInfo.InvariantCulture, "{0}", value);
            }
            return(GraphSONUtil.ToTypedValue(GraphSONTypeName, value, Prefix));
        }
        public Dictionary <string, dynamic> Dictify(dynamic objectData, IGraphSONWriter writer)
        {
            var binding   = (Binding)objectData;
            var valueDict = new Dictionary <string, object>
            {
                { "value", writer.ToDict(binding.Value) },
                { "key", binding.Key }
            };

            return(GraphSONUtil.ToTypedValue(nameof(Binding), valueDict));
        }
        public Dictionary <string, dynamic> Dictify(dynamic objectData, IGraphSONWriter writer)
        {
            Gremlin.Net.Structure.Vertex vertex = objectData;
            var vertexDict = new Dictionary <string, dynamic>
            {
                { "id", writer.ToDict(vertex.Id) },
                { "label", writer.ToDict(vertex.Label) }
            };

            return(GraphSONUtil.ToTypedValue(nameof(Gremlin.Net.Structure.Vertex), vertexDict));
        }
예제 #7
0
        public Dictionary <string, dynamic> Dictify(dynamic objectData, IGraphSONWriter writer)
        {
            ILambda lambda    = objectData;
            var     valueDict = new Dictionary <string, dynamic>
            {
                { "script", lambda.LambdaExpression },
                { "language", lambda.Language },
                { "arguments", lambda.Arguments }
            };

            return(GraphSONUtil.ToTypedValue(nameof(Lambda), valueDict));
        }
예제 #8
0
        public Dictionary <string, dynamic> Dictify(dynamic objectData, IGraphSONWriter writer)
        {
            RequestMessage msg = objectData;

            return(new Dictionary <string, dynamic>
            {
                { "requestId", msg.RequestId },
                { "op", msg.Operation },
                { "processor", msg.Processor },
                { "args", writer.ToDict(msg.Arguments) }
            });
        }
        public Dictionary <string, dynamic> Dictify(dynamic objectData, IGraphSONWriter writer)
        {
            Gremlin.Net.Structure.Property property = objectData;
            var elementDict = CreateElementDict(property.Element, writer);
            var valueDict   = new Dictionary <string, dynamic>
            {
                { "key", property.Key },
                { "value", writer.ToDict(property.Value) },
                { "element", elementDict }
            };

            return(GraphSONUtil.ToTypedValue(nameof(Gremlin.Net.Structure.Property), valueDict));
        }
        public Dictionary <string, dynamic> Dictify(dynamic objectData, IGraphSONWriter writer)
        {
            VertexProperty vertexProperty = objectData;
            var            valueDict      = new Dictionary <string, dynamic>
            {
                { "id", writer.ToDict(vertexProperty.Id) },
                { "label", vertexProperty.Label },
                { "value", writer.ToDict(vertexProperty.Value) },
                { "vertex", writer.ToDict(vertexProperty.Vertex.Id) }
            };

            return(GraphSONUtil.ToTypedValue(nameof(VertexProperty), valueDict));
        }
예제 #11
0
        /// <inheritdoc />
        public bool TryDictify(
            dynamic objectData,
            IGraphSONWriter serializer,
            IGenericSerializer genericSerializer,
            out dynamic result)
        {
            if (objectData == null)
            {
                result = null;
                return(false);
            }

            var type = (Type)objectData.GetType();
            var map  = genericSerializer.GetUdtMapByType(type);

            if (map == null)
            {
                result = null;
                return(false);
            }

            var dict = GetUdtTypeDefinition(map, genericSerializer);

            var value  = (object)objectData;
            var values = new List <object>();

            foreach (var field in map.Definition.Fields)
            {
                object fieldValue      = null;
                var    prop            = map.GetPropertyForUdtField(field.Name);
                var    fieldTargetType = genericSerializer.GetClrTypeForGraph(field.TypeCode, field.TypeInfo);
                if (prop != null)
                {
                    fieldValue = prop.GetValue(value, null);
                    if (!fieldTargetType.GetTypeInfo().IsAssignableFrom(prop.PropertyType.GetTypeInfo()))
                    {
                        fieldValue = UdtMap.TypeConverter.ConvertToDbFromUdtFieldValue(prop.PropertyType,
                                                                                       fieldTargetType,
                                                                                       fieldValue);
                    }
                }

                values.Add(fieldValue);
            }

            dict.Add("value", values.Select(serializer.ToDict));
            result = GraphSONUtil.ToTypedValue("UDT", dict, "dse");
            return(true);
        }
예제 #12
0
        public Dictionary <string, dynamic> Dictify(dynamic objectData, IGraphSONWriter writer)
        {
            Duration d     = objectData;
            var      value = new Dictionary <string, dynamic>
            {
                { "months", writer.ToDict(d.Months) },
                { "days", writer.ToDict(d.Days) },
                { "nanos", writer.ToDict(d.Nanoseconds) }
            };

            return(GraphSONUtil.ToTypedValue(
                       Duration3Serializer.TypeKey,
                       value,
                       Duration3Serializer.Prefix));
        }
예제 #13
0
        public Dictionary <string, dynamic> Dictify(dynamic objectData, IGraphSONWriter writer)
        {
            Gremlin.Net.Structure.Edge edge = objectData;
            var edgeDict = new Dictionary <string, dynamic>
            {
                { "id", writer.ToDict(edge.Id) },
                { "outV", writer.ToDict(edge.OutV.Id) },
                { "outVLabel", edge.OutV.Label },
                { "label", edge.Label },
                { "inV", writer.ToDict(edge.InV.Id) },
                { "inVLabel", edge.InV.Label }
            };

            return(GraphSONUtil.ToTypedValue(nameof(Gremlin.Net.Structure.Edge), edgeDict));
        }
예제 #14
0
        public Dictionary <string, dynamic> Dictify(dynamic objectData, IGraphSONWriter writer)
        {
            Vertex vertex     = objectData;
            var    vertexDict = new Dictionary <string, dynamic>
            {
                { "id", writer.ToDict(vertex.Id) },
                { "label", writer.ToDict(vertex.Label) }
            };

            if (vertex.Properties != null && vertex.Properties.Count > 0)
            {
                vertexDict["properties"] = vertex.Properties.ToDictionary(kvp => kvp.Key, kvp => writer.ToDict(kvp.Value));
            }

            return(GraphSONUtil.ToTypedValue(nameof(Vertex), vertexDict));
        }
        public Dictionary <string, dynamic> Dictify(dynamic bytecodeObj, IGraphSONWriter writer)
        {
            Bytecode bytecode = bytecodeObj;

            var valueDict = new Dictionary <string, IEnumerable <IEnumerable <dynamic> > >();

            if (bytecode.SourceInstructions.Count > 0)
            {
                valueDict["source"] = DictifyInstructions(bytecode.SourceInstructions, writer);
            }
            if (bytecode.StepInstructions.Count > 0)
            {
                valueDict["step"] = DictifyInstructions(bytecode.StepInstructions, writer);
            }

            return(GraphSONUtil.ToTypedValue(nameof(Bytecode), valueDict));
        }
예제 #16
0
        public bool TryDictify(
            dynamic objectData,
            IGraphSONWriter serializer,
            IGenericSerializer genericSerializer,
            out dynamic result)
        {
            if (objectData == null)
            {
                result = null;
                return(false);
            }

            var tupleType = (Type)objectData.GetType();

            if (!Utils.IsTuple(tupleType))
            {
                result = null;
                return(false);
            }

            var tupleTypeInfo = tupleType.GetTypeInfo();
            var subtypes      = tupleTypeInfo.GetGenericArguments();
            var data          = new List <object>();

            for (var i = 1; i <= subtypes.Length; i++)
            {
                var prop = tupleTypeInfo.GetProperty("Item" + i);
                if (prop != null)
                {
                    data.Add(prop.GetValue(objectData, null));
                }
            }

            var dict = new Dictionary <string, dynamic>
            {
                { "cqlType", "tuple" },
                {
                    "definition",
                    data.Select(elem => ComplexTypeDefinitionHelper.GetDefinitionByValue(genericSerializer, elem))
                },
                { "value", data.Select(d => serializer.ToDict(d)) }
            };

            result = GraphSONUtil.ToTypedValue("Tuple", dict, "dse");
            return(true);
        }
예제 #17
0
        public Dictionary <string, dynamic> Dictify(dynamic predicate, IGraphSONWriter writer)
        {
            P   p     = predicate;
            var value = p.Other == null
                ? writer.ToDict(p.Value)
                : new List <dynamic>
            {
                writer.ToDict(p.Value), writer.ToDict(p.Other)
            };
            var dict = new Dictionary <string, dynamic>
            {
                { "predicate", p.OperatorName },
                { "value", value }
            };

            return(GraphSONUtil.ToTypedValue("P", dict));
        }
예제 #18
0
        public Dictionary <string, dynamic> Dictify(dynamic objectData, IGraphSONWriter writer)
        {
            Edge edge     = objectData;
            var  inV      = edge.InV.To <IVertex>();
            var  outV     = edge.OutV.To <IVertex>();
            var  edgeDict = new Dictionary <string, dynamic>
            {
                { "id", writer.ToDict(edge.Id) },
                { "outV", writer.ToDict(outV.Id) },
                { "outVLabel", outV.Label },
                { "label", edge.Label },
                { "inV", writer.ToDict(inV.Id) },
                { "inVLabel", inV.Label }
            };

            return(GraphSONUtil.ToTypedValue(nameof(Edge), edgeDict));
        }
예제 #19
0
        public Dictionary <string, dynamic> Dictify(dynamic objectData, IGraphSONWriter writer)
        {
            var map = objectData as IDictionary;

            if (map == null)
            {
                throw new InvalidOperationException("Object must implement IDictionary");
            }
            var result = new object[map.Count * 2];
            var index  = 0;

            foreach (var key in map.Keys)
            {
                result[index++] = writer.ToDict(key);
                result[index++] = writer.ToDict(map[key]);
            }
            return(GraphSONUtil.ToTypedValue("Map", result));
        }
        private dynamic CreateElementDict(Gremlin.Net.Structure.Element element, IGraphSONWriter writer)
        {
            if (element == null)
            {
                return(null);
            }
            var serializedElement = writer.ToDict(element);
            Dictionary <string, dynamic> elementDict = serializedElement;

            if (elementDict.ContainsKey(GraphSONTokens.ValueKey))
            {
                var elementValueSerialized = elementDict[GraphSONTokens.ValueKey];
                Dictionary <string, dynamic> elementValueDict = elementValueSerialized;
                if (elementValueDict != null)
                {
                    elementValueDict.Remove("outVLabel");
                    elementValueDict.Remove("inVLabel");
                    elementValueDict.Remove("properties");
                    elementValueDict.Remove("value");
                }
            }
            return(serializedElement);
        }
예제 #21
0
 public Dictionary <string, dynamic> Dictify(dynamic objectData, IGraphSONWriter writer)
 {
     if (objectData is IPropertyWithElement propertyWithElement)
     {
         var elementDict = CreateElementDict(propertyWithElement.Element, writer);
         var valueDict   = new Dictionary <string, dynamic>
         {
             { "key", propertyWithElement.Name },
             { "value", writer.ToDict(propertyWithElement.Value) },
             { "element", elementDict }
         };
         return(GraphSONUtil.ToTypedValue(nameof(Property), valueDict));
     }
     else
     {
         IProperty property  = objectData;
         var       valueDict = new Dictionary <string, dynamic>
         {
             { "key", property.Name },
             { "value", writer.ToDict(property.Value) }
         };
         return(GraphSONUtil.ToTypedValue(nameof(Property), valueDict));
     }
 }
예제 #22
0
        public Dictionary <string, dynamic> Dictify(dynamic objectData, IGraphSONWriter writer)
        {
            AbstractTraversalStrategy strategy = objectData;

            return(GraphSONUtil.ToTypedValue(strategy.StrategyName, writer.ToDict(strategy.Configuration)));
        }
 private IEnumerable <IEnumerable <dynamic> > DictifyInstructions(IEnumerable <Instruction> instructions,
                                                                  IGraphSONWriter writer)
 {
     return(instructions.Select(instruction => DictifyInstruction(instruction, writer)));
 }
예제 #24
0
        public Dictionary <string, dynamic> Dictify(dynamic objectData, IGraphSONWriter writer)
        {
            TimeSpan value = objectData;

            return(GraphSONUtil.ToTypedValue("Duration", XmlConvert.ToString(value), "gx"));
        }
예제 #25
0
        public Dictionary <string, dynamic> Dictify(dynamic objectData, IGraphSONWriter writer)
        {
            EnumWrapper enumToSerialize = objectData;

            return(GraphSONUtil.ToTypedValue(enumToSerialize.EnumName, enumToSerialize.EnumValue));
        }
        public Dictionary <string, dynamic> Dictify(dynamic objectData, IGraphSONWriter writer)
        {
            BigInteger value = objectData;

            return(GraphSONUtil.ToTypedValue("BigInteger", value.ToString(), "gx"));
        }
예제 #27
0
        /// <summary>
        /// Converts a Collection to a representation of g:List or g:Set
        /// </summary>
        internal static Dictionary <string, dynamic> ToCollection(dynamic objectData, IGraphSONWriter writer,
                                                                  string typename)
        {
            var collection = objectData as IEnumerable;

            if (collection == null)
            {
                throw new InvalidOperationException("Object must implement IEnumerable");
            }
            var result = new List <object>();

            foreach (var item in collection)
            {
                result.Add(writer.ToDict(item));
            }
            return(GraphSONUtil.ToTypedValue(typename, result));
        }
예제 #28
0
 public Dictionary <string, dynamic> Dictify(dynamic objectData, IGraphSONWriter writer)
 {
     return(GraphSONUtil.ToCollection(objectData, writer, "List"));
 }
예제 #29
0
        public Dictionary <string, dynamic> Dictify(dynamic objectData, IGraphSONWriter writer)
        {
            Guid guid = objectData;

            return(GraphSONUtil.ToTypedValue("UUID", guid));
        }
예제 #30
0
        public Dictionary <string, dynamic> Dictify(dynamic objectData, IGraphSONWriter writer)
        {
            var type = (Type)objectData;

            return(writer.ToDict(Activator.CreateInstance(type)));
        }