Пример #1
0
        public static ODocument ToDocument <T>(T genericObject)
        {
            ODocument document          = new ODocument();
            Type      genericObjectType = genericObject.GetType();

            // TODO: recursive mapping of nested/embedded objects
            foreach (PropertyInfo propertyInfo in genericObjectType.GetProperties(BindingFlags.Public | BindingFlags.Instance))
            {
                string propertyName = propertyInfo.Name;

                // serialize following properties into dedicated fields in ODocument
                if (propertyName.Equals("ORID"))
                {
                    document.ORID = (ORID)propertyInfo.GetValue(genericObject, null);
                    continue;
                }
                else if (propertyName.Equals("OVersion"))
                {
                    document.OVersion = (int)propertyInfo.GetValue(genericObject, null);
                    continue;
                }
                else if (propertyName.Equals("OClassId"))
                {
                    document.OClassId = (short)propertyInfo.GetValue(genericObject, null);
                    continue;
                }
                else if (propertyName.Equals("OClassName"))
                {
                    document.OClassName = (string)propertyInfo.GetValue(genericObject, null);
                    continue;
                }

                bool     isSerializable = true;
                object[] oProperties    = propertyInfo.GetCustomAttributes(typeof(OProperty), true);

                if (oProperties.Any())
                {
                    OProperty oProperty = oProperties.First() as OProperty;
                    if (oProperty != null)
                    {
                        propertyName   = oProperty.Alias;
                        isSerializable = oProperty.Serializable;
                    }
                }

                if (isSerializable)
                {
                    document.SetField(propertyName, propertyInfo.GetValue(genericObject, null));
                }
            }

            return(document);
        }
Пример #2
0
 private Task <ODocument> retrieveDataBaseProperties()
 {
     return(Task.Factory.StartNew(() =>
     {
         var document = Load.ORID(new ORID(0, 0)).Run();
         var str = Encoding.UTF8.GetString(document.GetField <byte[]>("RawBytes"));
         var values = str.Split(new[] { '|' }, StringSplitOptions.RemoveEmptyEntries);
         var doc = new ODocument();
         doc.SetField("Version", values[0]);
         doc.SetField("LocaleLanguage", values[5]);
         doc.SetField("LocaleCountry", values[6]);
         doc.SetField("DateFormat", values[7]);
         doc.SetField("DateTimeFormat", values[8]);
         doc.SetField("Timezone", values[9]);
         doc.SetField("Charset", values[10]);
         return doc;
     }));
 }
        public IOCreateVertex Set <T>(string fieldName, T fieldValue)
        {
            _document.SetField(fieldName, fieldValue);

            return(this);
        }