Exemplo n.º 1
0
        private void WriteOptions()
        {
            BSONObj o = new BSONObj();

            if (_activeTransaction != null)
            {
                o.add("_transactionId", _activeTransaction);
            }
            this._network.WriteBSON(o);
        }
Exemplo n.º 2
0
        public void CreateIndex(BSONObj indexDescription)
        {
            this._network.Reset();
            this._network.WriteHeader();
            this._network.WriteInt32((int)CommandType.CREATEINDEX);
            WriteOptions();
            this._network.WriteBSON(indexDescription);
            this._network.Flush();

            ReadResultCreateIndex();
        }
Exemplo n.º 3
0
        public void Update(string db, string ns, BSONObj obj)
        {
            this._network.Reset();
            this._network.WriteHeader();
            this._network.WriteInt32((int)CommandType.UPDATE);
            WriteOptions();
            this._network.WriteString(db);
            this._network.WriteString(ns);
            this._network.WriteBSON(obj);
            this._network.Flush();

            ReadResultUpdate();
        }
Exemplo n.º 4
0
        public BSONArrayObj ReadBSONArray()
        {
            long elements = ReadLong();

            BSONArrayObj res = new BSONArrayObj();

            for (long x = 0; x < elements; x++)
            {
                BSONObj o = ReadBSON();
                res.Add(o);
            }
            return(res);
        }
Exemplo n.º 5
0
        public void Insert(string db, string ns, BSONObj obj)
        {
            this._network.Reset();
            this._network.WriteHeader();
            this._network.WriteInt32((int)CommandType.INSERT);
            WriteOptions();
            this._network.WriteString(db);
            this._network.WriteString(ns);
            this._network.WriteBSON(obj);
            this._network.Flush();

            ReadResultInsert();
        }
Exemplo n.º 6
0
        public BSONObj ReadBSON()
        {
            BSONObj o        = new BSONObj();
            long    elements = ReadLong();

            for (long x = 0; x < elements; x++)
            {
                string key  = ReadString();
                long   type = ReadLong();
                switch (type)
                {
                case 0:
                    o.add(key, ReadInt32());
                    break;

                case 1:
                    o.add(key, ReadDouble());
                    break;

                case 2:
                    o.add(key, ReadLong());
                    break;

                case 4:
                    o.add(key, ReadString());
                    break;

                case 5:
                    o.add(key, ReadBSON());
                    break;

                case 6:
                    o.add(key, ReadBSONArray());
                    break;

                case 10:
                    o.add(key, ReadBoolean());
                    break;

                default:
                    throw new ApplicationException("Type not supported");
                }
            }
            return(o);
        }
Exemplo n.º 7
0
 public BSONEnumerator(BSONObj obj)
 {
     this._object    = obj;
     this._internalE = obj._data.Keys.GetEnumerator();
 }
Exemplo n.º 8
0
        public DjondbCursor ExecuteQuery(string query)
        {
            this._network.Reset();
            this._network.WriteHeader();
            this._network.WriteInt32((int)CommandType.EXECUTEQUERY);
            WriteOptions();
            this._network.WriteString(query);
            this._network.Flush();

            int          flag   = this._network.ReadInt32();
            DjondbCursor cursor = null;

            if (flag == 1)
            {
                CommandType commandType = (CommandType)this._network.ReadInt32();
                switch (commandType)
                {
                case CommandType.INSERT:
                    ReadResultInsert();
                    break;

                case CommandType.BACKUP:
                    ReadResultBackup();
                    break;

                case CommandType.COMMIT:
                    ReadResultCommit();
                    break;

                case CommandType.CREATEINDEX:
                    ReadResultCreateIndex();
                    break;

                case CommandType.DROPNAMESPACE:
                    ReadResultDropNamespace();
                    break;

                case CommandType.FIND:
                    cursor = ReadResultFind();
                    break;

                case CommandType.REMOVE:
                    ReadResultRemove();
                    break;

                case CommandType.ROLLBACK:
                    ReadResultRollbackTransaction();
                    break;

                case CommandType.SHOWDBS:
                    string[]     dbs    = ReadResultShowDbs();
                    BSONArrayObj arrDbs = new BSONArrayObj();
                    foreach (string db in dbs)
                    {
                        BSONObj o = new BSONObj();
                        o.add("db", db);
                        arrDbs.Add(o);
                    }
                    cursor = new DjondbCursor(this, null, arrDbs);
                    break;

                case CommandType.SHOWNAMESPACES:
                    string[]     nss   = ReadResultShowNameSpaces();
                    BSONArrayObj arrNs = new BSONArrayObj();
                    foreach (string ns in nss)
                    {
                        BSONObj o = new BSONObj();
                        o.add("ns", ns);
                        arrNs.Add(o);
                    }
                    cursor = new DjondbCursor(this, null, arrNs);
                    break;

                case CommandType.UPDATE:
                    ReadResultUpdate();
                    break;
                }
            }
            if (cursor == null)
            {
                BSONArrayObj arr    = new BSONArrayObj();
                BSONObj      result = new BSONObj();
                result.add("date", DateTime.Now.ToString("yyyy/MM/dd hh:mm:ss:nn"));
                result.add("success", true);
                arr.Add(result);
                cursor = new DjondbCursor(this, null, arr);
            }
            readErrorInformation();
            return(cursor);
        }
Exemplo n.º 9
0
        internal void WriteBSON(BSONObj bSONObj)
        {
            WriteLong(bSONObj.Count);

            foreach (KeyValuePair <string, object> kv in bSONObj)
            {
                WriteString(kv.Key);
                object val = kv.Value;
                Int32? i   = val as Int32?;
                if (i != null)
                {
                    WriteLong(0);
                    WriteInt32((int)i);
                }
                else
                {
                    long?l = val as long?;
                    if (l != null)
                    {
                        WriteLong(2);
                        WriteLong((long)l);
                    }
                    else
                    {
                        float?f = val as float?;
                        if (f != null)
                        {
                            WriteLong(1);
                            WriteDouble(Convert.ToDouble(f));
                        }
                        else
                        {
                            string s = val as string;
                            if (s != null)
                            {
                                WriteLong(4);
                                WriteString(s);
                            }
                            else
                            {
                                BSONObj bObj = val as BSONObj;
                                if (bObj != null)
                                {
                                    WriteLong(5);
                                    WriteBSON(bObj);
                                }
                                else
                                {
                                    bool?b = val as bool?;
                                    if (b != null)
                                    {
                                        WriteLong(10);
                                        WriteBoolean((bool)b);
                                    }
                                    else
                                    {
                                        BSONArrayObj ar = val as BSONArrayObj;
                                        if (ar != null)
                                        {
                                            WriteLong(6);
                                            WriteBSONArray(ar);
                                        }
                                        else
                                        {
                                            double?d = val as double?;
                                            if (d != null)
                                            {
                                                WriteLong(1);
                                                WriteDouble((double)d);
                                            }
                                            else
                                            {
                                                throw new ApplicationException("Unknown data type");
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
Exemplo n.º 10
0
 public void CreateIndex(BSONObj indexDef)
 {
     _command.CreateIndex(indexDef);
 }
Exemplo n.º 11
0
 public void Update(string db, string ns, BSONObj o)
 {
     _command.Update(db, ns, o);
 }
Exemplo n.º 12
0
 public void Insert(string db, string ns, BSONObj o)
 {
     _command.Insert(db, ns, o);
 }