public IOCreateVertex Set <T>(T obj)
        {
            var document = obj is ODocument ? obj as ODocument : ODocument.ToDocument(obj);

            // TODO: go also through embedded fields
            foreach (KeyValuePair <string, object> field in document)
            {
                // set only fields which doesn't start with @ character
                if ((field.Key.Length > 0) && (field.Key[0] != '@'))
                {
                    Set(field.Key, field.Value);
                }
            }

            return(this);
        }
Esempio n. 2
0
        public OCommandResult Gremlin(string query)
        {
            CommandPayloadScript payload = new CommandPayloadScript();

            payload.Language = "gremlin";
            payload.Text     = query;

            Command operation = new Command(GetConnection().Database);

            operation.OperationMode  = OperationMode.Synchronous;
            operation.CommandPayload = payload;

            ODocument document = GetConnection().ExecuteOperation(operation);

            return(new OCommandResult(document));
        }
Esempio n. 3
0
        public List <ODocument> Query(string sql, string fetchPlan)
        {
            CommandPayloadQuery payload = new CommandPayloadQuery();

            payload.Text         = sql;
            payload.NonTextLimit = -1;
            payload.FetchPlan    = fetchPlan;

            Command operation = new Command(GetConnection().Database);

            operation.OperationMode  = OperationMode.Asynchronous;
            operation.CommandPayload = payload;

            ODocument document = GetConnection().ExecuteOperation(operation);

            return(document.GetField <List <ODocument> >("Content"));
        }
        public IOCreateVertex Vertex <T>(T obj)
        {
            if (obj is ODocument)
            {
                _document = obj as ODocument;
            }
            else
            {
                _document = ODocument.ToDocument(obj);
            }

            if (string.IsNullOrEmpty(_document.OClassName))
            {
                throw new OException(OExceptionType.Query, "Document doesn't contain OClassName value.");
            }

            return(this);
        }
Esempio n. 5
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 ODocument ToSingle()
        {
            ODocument document = null;

            switch (_document.GetField <PayloadStatus>("PayloadStatus"))
            {
            case PayloadStatus.SingleRecord:
                document = _document.GetField <ODocument>("Content");
                break;

            case PayloadStatus.RecordCollection:
                document = _document.GetField <List <ODocument> >("Content").FirstOrDefault();
                break;

            default:
                break;
            }

            return(document);
        }
Esempio n. 7
0
        public OCommandResult Command(string sql)
        {
            CommandPayload payload = new CommandPayload();

            payload.Type             = CommandPayloadType.Sql;
            payload.Text             = sql;
            payload.NonTextLimit     = -1;
            payload.FetchPlan        = "";
            payload.SerializedParams = new byte[] { 0 };

            Command operation = new Command();

            operation.OperationMode  = OperationMode.Synchronous;
            operation.ClassType      = CommandClassType.NonIdempotent;
            operation.CommandPayload = payload;

            ODocument document = _connection.ExecuteOperation(operation);

            return(new OCommandResult(document));
        }
Esempio n. 8
0
        public List <ODocument> Query(string sql, string fetchPlan)
        {
            CommandPayload payload = new CommandPayload();

            payload.Type             = CommandPayloadType.Sql;
            payload.Text             = sql;
            payload.NonTextLimit     = -1;
            payload.FetchPlan        = fetchPlan;
            payload.SerializedParams = new byte[] { 0 };

            Command operation = new Command();

            operation.OperationMode  = OperationMode.Asynchronous;
            operation.ClassType      = CommandClassType.Idempotent;
            operation.CommandPayload = payload;

            ODocument document = _connection.ExecuteOperation(operation);

            return(document.GetField <List <ODocument> >("Content"));
        }
Esempio n. 9
0
        public List <ODocument> Gremlin(string query)
        {
            CommandPayload payload = new CommandPayload();

            payload.Language         = "gremlin";
            payload.Type             = CommandPayloadType.Sql;
            payload.Text             = query;
            payload.NonTextLimit     = -1;
            payload.FetchPlan        = "";
            payload.SerializedParams = new byte[] { 0 };

            Command operation = new Command();

            operation.OperationMode  = OperationMode.Asynchronous;
            operation.ClassType      = CommandClassType.NonIdempotent;
            operation.CommandPayload = payload;

            ODocument document = _connection.ExecuteOperation(operation);

            return(document.GetField <List <ODocument> >("Content"));
        }
Esempio n. 10
0
        public Dictionary <string, ODatabaseInfo> Databases()
        {
            Dictionary <string, ODatabaseInfo> returnValue = new Dictionary <string, ODatabaseInfo>();
            DBList    operation = new DBList(null);
            ODocument document  = _connection.ExecuteOperation(operation);
            ODocument databases = document.GetField <ODocument>("databases");

            if (OClient.Serializer == ORecordFormat.ORecordDocument2csv)
            {
                foreach (var item in databases)
                {
                    string       databaseName = item.Key;
                    string[]     pathValue    = item.Value.ToString().Split(':');
                    var          info         = new ODatabaseInfo();
                    OStorageType storageType;

                    Enum.TryParse <OStorageType>(pathValue[0], true, out storageType);
                    info.DataBaseName = databaseName.Replace("\"", "");
                    info.StorageType  = storageType;
                    info.Path         = pathValue[1].Replace("\"", "");;
                    returnValue.Add(info.DataBaseName, info);
                }
            }
            else
            {
                foreach (var item in databases)
                {
                    var          info      = new ODatabaseInfo();
                    string[]     pathValue = item.Value.ToString().Split(':');
                    OStorageType storageType;

                    Enum.TryParse <OStorageType>(pathValue[0], true, out storageType);
                    info.DataBaseName = item.Key;
                    info.StorageType  = storageType;
                    info.Path         = item.Value.ToString();
                    returnValue.Add(info.DataBaseName, info);
                }
            }
            return(returnValue);
        }
Esempio n. 11
0
        public OSqlDeleteEdge To <T>(T obj)
        {
            ODocument document;

            if (obj is ODocument)
            {
                document = obj as ODocument;
            }
            else
            {
                document = ODocument.ToDocument(obj);
            }

            if (document.ORID == null)
            {
                throw new OException(OExceptionType.Query, "Document doesn't contain ORID value.");
            }

            _sqlQuery.To(document.ORID);

            return(this);
        }
        public OSqlCreateVertex Vertex <T>(T obj)
        {
            ODocument document;

            if (obj is ODocument)
            {
                document = obj as ODocument;
            }
            else
            {
                document = ODocument.ToDocument(obj);
            }

            if (string.IsNullOrEmpty(document.OClassName))
            {
                throw new OException(OExceptionType.Query, "Document doesn't contain OClassName value.");
            }

            _sqlQuery.Vertex(document.OClassName);
            _sqlQuery.Set(document);

            return(this);
        }
Esempio n. 13
0
        public bool HasField(string fieldPath)
        {
            if (ContainsKey(fieldPath))
            {
                return(true);
            }

            bool contains = false;

            if (fieldPath.Contains("."))
            {
                var       fields           = fieldPath.Split('.');
                int       iteration        = 1;
                ODocument embeddedDocument = this;

                foreach (var field in fields)
                {
                    if (iteration == fields.Length)
                    {
                        contains = embeddedDocument.ContainsKey(field);
                        break;
                    }

                    if (embeddedDocument.ContainsKey(field))
                    {
                        embeddedDocument = (ODocument)embeddedDocument[field];
                        iteration++;
                    }
                    else
                    {
                        break;
                    }
                }
            }

            return(contains);
        }
 internal OCommandResult(ODocument document)
 {
     _document = document;
 }
Esempio n. 15
0
 public ODocument ToDocument()
 {
     return(ODocument.ToDocument(this));
 }
Esempio n. 16
0
        public T GetField <T>(string fieldPath)
        {
            var type = typeof(T);

            object fieldValue;

            if (TryGetValue(fieldPath, out fieldValue))
            {
                if (fieldValue == null || fieldValue.GetType() == typeof(T))
                {
                    return((T)fieldValue);
                }

                if (fieldValue is ICollection && (fieldValue as ICollection).Count == 1)
                {
                    var enumerable = (fieldValue as IEnumerable).GetEnumerator();
                    enumerable.MoveNext();
                    if (enumerable.Current != null && enumerable.Current is T)
                    {
                        return((T)enumerable.Current);
                    }
                }

                // if value is list or set type, get element type and enumerate over its elements
                if (!type.GetTypeInfo().IsPrimitive&& ImplementsIList(type) && !type.IsArray)
                {
                    var         value       = (T)Activator.CreateInstance(type);
                    Type        elementType = type.GetGenericArguments()[0];
                    IEnumerator enumerator  = EnumerableFromField <T>(fieldValue).GetEnumerator();

                    while (enumerator.MoveNext())
                    {
                        // if current element is ODocument type which is Dictionary<string, object>
                        // map its dictionary data to element instance
                        if (enumerator.Current is ODocument)
                        {
                            var instance = Activator.CreateInstance(elementType);
                            ((ODocument)enumerator.Current).Map(ref instance);

                            ((IList)value).Add(instance);
                        }
                        else
                        {
                            try
                            {
                                ((IList)value).Add(enumerator.Current);
                            }
                            catch
                            {
                                ((IList)value).Add(Convert.ChangeType(enumerator.Current, elementType));
                            }
                        }
                    }

                    return(value);
                }

                if (type.Name == "HashSet`1")
                {
                    var value = (T)Activator.CreateInstance(type);

                    Type        elementType = ((IEnumerable)value).GetType().GetGenericArguments()[0];
                    IEnumerator enumerator  = ((IEnumerable)fieldValue).GetEnumerator();

                    var addMethod = type.GetMethod("Add");

                    while (enumerator.MoveNext())
                    {
                        // if current element is ODocument type which is Dictionary<string, object>
                        // map its dictionary data to element instance
                        if (enumerator.Current is ODocument)
                        {
                            var instance = Activator.CreateInstance(elementType);
                            ((ODocument)enumerator.Current).Map(ref instance);

                            addMethod.Invoke(value, new object[] { instance });
                        }
                        else
                        {
                            addMethod.Invoke(value, new object[] { enumerator.Current });
                        }
                    }
                    return(value);
                }
                else if (type == typeof(DateTime))
                {
                    DateTime parsedValue;
                    if (DateTime.TryParse((string)fieldValue, out parsedValue))
                    {
                        return((T)(object)parsedValue);
                    }
                }
                else if (type == typeof(TimeSpan) || type == typeof(Nullable <TimeSpan>))
                {
                    if (fieldValue != null && (fieldValue.GetType() == typeof(TimeSpan) || fieldValue.GetType() == typeof(Nullable <TimeSpan>)))
                    {
                        return((T)fieldValue);
                    }
                    TimeSpan parsedValue;
                    if (TimeSpan.TryParse((string)fieldValue, out parsedValue))
                    {
                        return((T)(object)parsedValue);
                    }
                }
                else if (type == typeof(Guid))
                {
                    Guid parsedValue;
                    if (Guid.TryParse((string)fieldValue, out parsedValue))
                    {
                        return((T)(object)parsedValue);
                    }
                }
                else if (type == typeof(Decimal))
                {
                    if (fieldValue != null)
                    {
                        return((T)(object)Convert.ChangeType(fieldValue, typeof(T)));
                    }
                    else
                    {
                        return((T)(object)null);
                    }
                }

                return((T)fieldValue);
            }
            if (fieldPath.Contains("."))
            {
                ODocument target = this;
                var       fields = fieldPath.Split('.');
                for (int i = 0; i < fields.Length - 1; i++)
                {
                    target = target.GetField <ODocument>(fields[i]);
                }
                return(target.GetField <T>(fields.Last()));
            }

            var result = type.GetTypeInfo().IsPrimitive || type == typeof(string) || type.IsArray ? default(T) : (T)Activator.CreateInstance(type);

            SetField(fieldPath, result);
            return(result);
        }
Esempio n. 17
0
        public T GetField <T>(string fieldPath)
        {
            Type type = typeof(T);
            T    value;

            if (type.IsPrimitive || type.IsArray || (type.Name == "String"))
            {
                value = default(T);
            }
            else
            {
                value = (T)Activator.CreateInstance(type);
            }

            if (fieldPath.Contains("."))
            {
                var       fields           = fieldPath.Split('.');
                int       iteration        = 1;
                ODocument embeddedDocument = this;

                foreach (var field in fields)
                {
                    if (iteration == fields.Length)
                    {
                        // if value is collection type, get element type and enumerate over its elements
                        if (value is IList)
                        {
                            Type        elementType = ((IEnumerable)value).GetType().GetGenericArguments()[0];
                            IEnumerator enumerator  = ((IEnumerable)embeddedDocument[field]).GetEnumerator();

                            while (enumerator.MoveNext())
                            {
                                // if current element is ODocument type which is dictionary<string, object>
                                // map its dictionary data to element instance
                                if (enumerator.Current is ODocument)
                                {
                                    var instance = Activator.CreateInstance(elementType);
                                    ((ODocument)enumerator.Current).Map(ref instance);

                                    ((IList)value).Add(instance);
                                }
                                else
                                {
                                    ((IList)value).Add(enumerator.Current);
                                }
                            }
                        }
                        else if (type.Name == "HashSet`1")
                        {
                            Type        elementType = ((IEnumerable)value).GetType().GetGenericArguments()[0];
                            IEnumerator enumerator  = ((IEnumerable)this[fieldPath]).GetEnumerator();

                            var addMethod = type.GetMethod("Add");

                            while (enumerator.MoveNext())
                            {
                                // if current element is ODocument type which is Dictionary<string, object>
                                // map its dictionary data to element instance
                                if (enumerator.Current is ODocument)
                                {
                                    var instance = Activator.CreateInstance(elementType);
                                    ((ODocument)enumerator.Current).Map(ref instance);

                                    addMethod.Invoke(value, new object[] { instance });
                                }
                                else
                                {
                                    addMethod.Invoke(value, new object[] { enumerator.Current });
                                }
                            }
                        }
                        else
                        {
                            value = (T)embeddedDocument[field];
                        }
                        break;
                    }

                    if (embeddedDocument.ContainsKey(field))
                    {
                        embeddedDocument = (ODocument)embeddedDocument[field];
                        iteration++;
                    }
                    else
                    {
                        break;
                    }
                }
            }
            else
            {
                if (this.ContainsKey(fieldPath))
                {
                    // if value is list or set type, get element type and enumerate over its elements
                    if (value is IList)
                    {
                        Type        elementType = ((IEnumerable)value).GetType().GetGenericArguments()[0];
                        IEnumerator enumerator  = ((IEnumerable)this[fieldPath]).GetEnumerator();

                        while (enumerator.MoveNext())
                        {
                            // if current element is ODocument type which is Dictionary<string, object>
                            // map its dictionary data to element instance
                            if (enumerator.Current is ODocument)
                            {
                                var instance = Activator.CreateInstance(elementType);
                                ((ODocument)enumerator.Current).Map(ref instance);

                                ((IList)value).Add(instance);
                            }
                            else
                            {
                                ((IList)value).Add(enumerator.Current);
                            }
                        }
                    }
                    else if (type.Name == "HashSet`1")
                    {
                        Type        elementType = ((IEnumerable)value).GetType().GetGenericArguments()[0];
                        IEnumerator enumerator  = ((IEnumerable)this[fieldPath]).GetEnumerator();

                        var addMethod = type.GetMethod("Add");

                        while (enumerator.MoveNext())
                        {
                            // if current element is ODocument type which is Dictionary<string, object>
                            // map its dictionary data to element instance
                            if (enumerator.Current is ODocument)
                            {
                                var instance = Activator.CreateInstance(elementType);
                                ((ODocument)enumerator.Current).Map(ref instance);

                                addMethod.Invoke(value, new object[] { instance });
                            }
                            else
                            {
                                addMethod.Invoke(value, new object[] { enumerator.Current });
                            }
                        }
                    }
                    else
                    {
                        value = (T)this[fieldPath];
                    }
                }
            }

            return(value);
        }
Esempio n. 18
0
 public OSqlUpdate Record(ODocument document)
 {
     return(Record(document.ORID));
 }
Esempio n. 19
0
 public OSqlDeleteDocument Record(ODocument document)
 {
     return(Record(document.ORID));
 }
Esempio n. 20
0
        public T GetField <T>(string fieldPath)
        {
            var type = typeof(T);

            object fieldValue;

            if (TryGetValue(fieldPath, out fieldValue))
            {
                if (fieldValue == null || fieldValue.GetType() == typeof(T))
                {
                    return((T)fieldValue);
                }

                // if value is list or set type, get element type and enumerate over its elements
                if (!type.IsPrimitive && ImplementsIList(type) && !type.IsArray)
                {
                    var         value       = (T)Activator.CreateInstance(type);
                    Type        elementType = type.GetGenericArguments()[0];
                    IEnumerator enumerator  = EnumerableFromField <T>(fieldValue).GetEnumerator();

                    while (enumerator.MoveNext())
                    {
                        // if current element is ODocument type which is Dictionary<string, object>
                        // map its dictionary data to element instance
                        if (enumerator.Current is ODocument)
                        {
                            var instance = Activator.CreateInstance(elementType);
                            ((ODocument)enumerator.Current).Map(ref instance);

                            ((IList)value).Add(instance);
                        }
                        else
                        {
                            ((IList)value).Add(enumerator.Current);
                        }
                    }

                    return(value);
                }

                if (type.Name == "HashSet`1")
                {
                    var value = (T)Activator.CreateInstance(type);

                    Type        elementType = ((IEnumerable)value).GetType().GetGenericArguments()[0];
                    IEnumerator enumerator  = ((IEnumerable)fieldValue).GetEnumerator();

                    var addMethod = type.GetMethod("Add");

                    while (enumerator.MoveNext())
                    {
                        // if current element is ODocument type which is Dictionary<string, object>
                        // map its dictionary data to element instance
                        if (enumerator.Current is ODocument)
                        {
                            var instance = Activator.CreateInstance(elementType);
                            ((ODocument)enumerator.Current).Map(ref instance);

                            addMethod.Invoke(value, new object[] { instance });
                        }
                        else
                        {
                            addMethod.Invoke(value, new object[] { enumerator.Current });
                        }
                    }
                    return(value);
                }

                return((T)fieldValue);
            }
            if (fieldPath.Contains("."))
            {
                ODocument target = this;
                var       fields = fieldPath.Split('.');
                for (int i = 0; i < fields.Length - 1; i++)
                {
                    target = target.GetField <ODocument>(fields[i]);
                }
                return(target.GetField <T>(fields.Last()));
            }

            var result = type.IsPrimitive || type == typeof(string) || type.IsArray ? default(T) : (T)Activator.CreateInstance(type);

            SetField(fieldPath, result);
            return(result);
        }