public void Unbox_DataReader_Columns_with_Default_Handlers()
        {
            // Arrange

            // Act
            using (FakeDataReader reader = new FakeDataReader())
            {
                while (reader.Read())
                {
                    int?refNullNull = reader.Column <int?>("null");

                    bool     boolean = reader.Column <bool>("Boolean");
                    char     ch      = reader.Column <char>("Char");
                    sbyte    int8    = reader.Column <sbyte>("SByte");
                    byte     uint8   = reader.Column <byte>("Byte");
                    short    int16   = reader.Column <short>("Int16");
                    ushort   uint16  = reader.Column <ushort>("UInt16");
                    int      int32   = reader.Column <int>("Int32");
                    uint     uint32  = reader.Column <uint>("UInt32");
                    long     int64   = reader.Column <long>("Int64");
                    ulong    uint64  = reader.Column <ulong>("UInt64");
                    float    sng     = reader.Column <float>("Single");
                    double   dbl     = reader.Column <double>("Double");
                    decimal  dec     = reader.Column <decimal>("Decimal");
                    string   str     = reader.Column <string>("String");
                    DateTime dt      = reader.Column <DateTime>("DateTime");
                    TimeSpan ts      = reader.Column <TimeSpan>("TimeSpan");
                    Guid     guid    = reader.Column <Guid>("Guid");
                    Uri      uri     = reader.Column <Uri>("Uri");
                }
            }

            // Assert
        }
Beispiel #2
0
        private IDataReader GetForeignInventory(UUID AgentID, UUID folder_id, string serverURL)
        {
            FakeDataReader        d             = new FakeDataReader();
            IConfigurationService configService = m_registry.RequestModuleInterface <IConfigurationService>();

            if (serverURL == "" && configService != null)
            {
                List <string> urls = configService.FindValueOf("InventoryServerURI");
                if (urls.Count > 0)
                {
                    serverURL = urls[0];
                }
                else
                {
                    return(null);
                }
            }
            XInventoryServicesConnector xinv = new XInventoryServicesConnector(serverURL + "xinventory");
            InventoryCollection         c    = xinv.GetFolderContent(AgentID, folder_id);

            if (c != null)
            {
                foreach (InventoryItemBase item in c.Items)
                {
                    d.items.Add(item);
                }
            }
            return(d);
        }
Beispiel #3
0
        public void MessageReceivedReadsAndProcessesMessages()
        {
            var fakeDataReader = new FakeDataReader
            {
                UnicodeEncoding        = (UnicodeEncoding)(-1),
                UnconsumedBufferLength = 42
            };

            fakeDataReader.Setup("ReadString", () => "MessageBody");

            var fakeWebSocketResponse = new FakeWebSocketResponse();

            fakeWebSocketResponse.Setup("GetDataReader", () => fakeDataReader);

            var transport = new WebSocketTransport();

            transport.Start(new FakeConnection(), string.Empty, CancellationToken.None);

            var fakeConnection = new FakeConnection();

            transport.MessageReceived(fakeWebSocketResponse, fakeConnection);

            Assert.Equal(UnicodeEncoding.Utf8, fakeDataReader.UnicodeEncoding);
            fakeDataReader.Verify("ReadString", new List <object[]> {
                new object[] { 42u }
            });

            // invoked by ProcessResponse
            Assert.Equal(1, fakeConnection.GetInvocations("MarkLastMessage").Count());
            Assert.Equal(1, fakeConnection.GetInvocations("Trace").Count());
        }
Beispiel #4
0
        public void ExceptionCaughtAndReportedIfThrownWhenReadingMessage()
        {
            var exception      = new Exception();
            var fakeDataReader = new FakeDataReader();

            fakeDataReader.Setup <string>("ReadString", () => { throw exception; });

            var fakeWebSocketResponse = new FakeWebSocketResponse();

            fakeWebSocketResponse.Setup("GetDataReader", () => fakeDataReader);

            var transport = new WebSocketTransport();

            transport.Start(
                new FakeConnection
            {
                TransportConnectTimeout = new TimeSpan(0, 0, 0, 0, 100)
            },
                string.Empty, CancellationToken.None);

            var fakeConnection = new FakeConnection();

            transport.MessageReceived(fakeWebSocketResponse, fakeConnection);

            fakeConnection.Verify("OnError", new List <object[]> {
                new object[] { exception }
            });
        }
Beispiel #5
0
        public void Construct_With_DataTable_leaves_SchemaType_as_default_RowData()
        {
            var table = new DataTable();

            var sut = new FakeDataReader(table);

            //Assert.Equal(SchemaDataTypeSource.DataTable, sut.SchemaDataTypeSource);
        }
Beispiel #6
0
        public static T Column <T>(this FakeDataReader reader, string name)
        {
            if (reader is null)
            {
                throw new ArgumentException(nameof(reader));
            }

            return(_extractor.Extract <T>(reader.GetValue(reader.GetOrdinal(name))));
        }
        public static TResult Column <T, TResult>(this FakeDataReader reader, string name)
        {
            if (reader is null)
            {
                throw new ArgumentException(nameof(reader));
            }

            T value = _extractor.Extract <T>(reader.GetValue(reader.GetOrdinal(name)));

            return((TResult)ExtractionConverters.DualTypeConverterWithFallback.ConvertToType(value, typeof(TResult)));
        }
Beispiel #8
0
        public void Construct_With_FakeTable_sets_SchemaType_to_DataTable()
        {
            var table = new FakeTable <Person>();

            table.AddRow(new Person {
                Id = 1, Name = "Bob", DateOfBirth = new DateTime(1980, 06, 15)
            });

            var sut = new FakeDataReader(table);

            //Assert.Equal(SchemaDataTypeSource.DataTable, sut.SchemaDataTypeSource);
        }
Beispiel #9
0
        public void Construct_With_Rows_And_Columns_leaves_SchemaType_as_default_RowData()
        {
            var rows = new[]
            {
                new object[] { 1, "Dave", DateTime.UtcNow }
            };

            var table = new FakeTable(rows);

            var sut = new FakeDataReader(table);

            //Assert.Equal(SchemaDataTypeSource.RowData, sut.SchemaDataTypeSource);
        }
Beispiel #10
0
        public void SimpleExample()
        {
            // This is the result we want to return when execute reader is executed
            var fakeDataReader = new FakeDataReader(0, "UserId", "Name");

            fakeDataReader.AddRow(1, "Smith");
            fakeDataReader.AddRow(2, "John");

            var result = new List <User>();

            using (var connection = new FakeDbConnection("ConnectionString", dbCommand => fakeDataReader))
            {
                connection.Open();
                using (IDbCommand command = connection.CreateCommand())
                {
                    command.CommandText = "SELECT * FROM Users";

                    IDbDataParameter dbDataParameter = command.CreateParameter();
                    dbDataParameter.ParameterName = "ParameterName";
                    dbDataParameter.DbType        = DbType.Int32;
                    dbDataParameter.Value         = 0;

                    command.Parameters.Add(dbDataParameter);
                    using (IDataReader reader = command.ExecuteReader())
                    {
                        while (reader.Read())
                        {
                            result.Add(new User {
                                UserId = reader.GetInt32(0), Name = reader.GetString(1)
                            });
                        }
                    }
                }
            }

            Assert.That(result.Count, Is.EqualTo(2));

            Assert.That(result.ElementAt(0).UserId, Is.EqualTo(1));
            Assert.That(result.ElementAt(0).Name, Is.EqualTo("Smith"));

            Assert.That(result.ElementAt(1).UserId, Is.EqualTo(2));
            Assert.That(result.ElementAt(1).Name, Is.EqualTo("John"));
        }
Beispiel #11
0
        public void Unbox_ExplicitConvert_DataReader_Columns()
        {
            // Arrange

            // Act
            using (FakeDataReader reader = new FakeDataReader())
            {
                if (reader.Read())
                {
                    int?i = reader.Column <int?>("Int32");

                    long id  = reader.Column <decimal, long>("Decimal");
                    long?idx = reader.Column <decimal?, long?>("Decimal");

                    Uri uri = reader.Column <string, Uri>("UriString");
                }
            }

            // Assert
        }
        public void Unbox_AutoConvert_DataReader_Columns()
        {
            // Arrange

            // Act
            using (FakeDataReader reader = new FakeDataReader())
            {
                while (reader.Read())
                {
                    int?i = reader.Column <int?>("Int32");

                    long id  = reader.Column <long>("Decimal");
                    long?idx = reader.Column <long?>("Decimal");

                    Uri uri = reader.Column <Uri>("UriString");
                }
            }

            // Assert
        }
        public void SimpleExample()
        {
            // This is the result we want to return when execute reader is executed
            var fakeDataReader = new FakeDataReader(0,"UserId","Name");
            fakeDataReader.AddRow(1, "Smith");
            fakeDataReader.AddRow(2, "John");

            var result = new List<User>();
            using (var connection = new FakeDbConnection("ConnectionString", dbCommand => fakeDataReader))
            {
                connection.Open();
                using (IDbCommand command = connection.CreateCommand())
                {
                    command.CommandText = "SELECT * FROM Users";

                    IDbDataParameter dbDataParameter = command.CreateParameter();
                    dbDataParameter.ParameterName = "ParameterName";
                    dbDataParameter.DbType = DbType.Int32;
                    dbDataParameter.Value = 0;

                    command.Parameters.Add(dbDataParameter);
                    using (IDataReader reader = command.ExecuteReader())
                    {

                        while (reader.Read())
                        {
                            result.Add(new User { UserId = reader.GetInt32(0), Name = reader.GetString(1)});
                        }
                    }
                }
            }

            Assert.That(result.Count, Is.EqualTo(2));

            Assert.That(result.ElementAt(0).UserId, Is.EqualTo(1));
            Assert.That(result.ElementAt(0).Name, Is.EqualTo("Smith"));

            Assert.That(result.ElementAt(1).UserId, Is.EqualTo(2));
            Assert.That(result.ElementAt(1).Name, Is.EqualTo("John"));
        }
Beispiel #14
0
    public void TestMethod1()
    {
        var values = new Dictionary <string, object>();

        values.Add("ProductId", 17);
        values.Add("ProductName", "Something");
        values.Add("Price", 29.99M);
        var reader   = new FakeDataReader(values);
        var product1 = new Product();

        reader.SetValue(product1, p => p.Id);
        reader.SetValue(product1, p => p.Name);
        reader.SetValue(product1, p => p.Price);
        Assert.AreEqual(17, product1.Id);
        Assert.AreEqual("Something", product1.Name);
        Assert.AreEqual(29.99M, product1.Price);
        var product2 = new Product();

        reader.SetAllValues(product2);
        Assert.AreEqual(17, product2.Id);
        Assert.AreEqual("Something", product2.Name);
        Assert.AreEqual(29.99M, product2.Price);
    }
        public void MessageReceivedReadsAndProcessesMessages()
        {
            var fakeDataReader = new FakeDataReader
            {
                UnicodeEncoding = (UnicodeEncoding)(-1),
                UnconsumedBufferLength = 42
            };
            fakeDataReader.Setup("ReadString", () => "MessageBody");

            var fakeWebSocketResponse = new FakeWebSocketResponse();
            fakeWebSocketResponse.Setup("GetDataReader", () => fakeDataReader);

            var transport = new WebSocketTransport();
            transport.Start(new FakeConnection(), string.Empty, CancellationToken.None);

            var fakeConnection = new FakeConnection();
            transport.MessageReceived(fakeWebSocketResponse, fakeConnection);

            Assert.Equal(UnicodeEncoding.Utf8, fakeDataReader.UnicodeEncoding);
            fakeDataReader.Verify("ReadString", new List<object[]> {new object[] { 42u}});

            // invoked by ProcessResponse
            Assert.Equal(1, fakeConnection.GetInvocations("MarkLastMessage").Count());
            Assert.Equal(1, fakeConnection.GetInvocations("Trace").Count());
        }
        public void ExceptionCaughtAndReportedIfThrownWhenReadingMessage()
        {
            var exception = new Exception();
            var fakeDataReader = new FakeDataReader();

            fakeDataReader.Setup<string>("ReadString", () => { throw exception; });

            var fakeWebSocketResponse = new FakeWebSocketResponse();
            fakeWebSocketResponse.Setup("GetDataReader", () => fakeDataReader);

            var transport = new WebSocketTransport();
            transport.Start(
                new FakeConnection
                {
                    TransportConnectTimeout = new TimeSpan(0, 0, 0, 0, 100)
                },
                string.Empty, CancellationToken.None);

            var fakeConnection = new FakeConnection();
            transport.MessageReceived(fakeWebSocketResponse, fakeConnection);

            fakeConnection.Verify("OnError", new List<object[]> { new object[] { exception } });
        }
Beispiel #17
0
        public override byte[] FetchInventoryReply(OSDArray fetchRequest, UUID AgentID, UUID forceOwnerID, UUID libraryOwnerID)
        {
            LLSDSerializationDictionary contents = new LLSDSerializationDictionary();

            contents.WriteStartMap("llsd");      //Start llsd

            contents.WriteKey("folders");        //Start array items
            contents.WriteStartArray("folders"); //Start array folders

            foreach (OSD m in fetchRequest)
            {
                contents.WriteStartMap("internalContents"); //Start internalContents kvp
                OSDMap invFetch = (OSDMap)m;

                //UUID agent_id = invFetch["agent_id"].AsUUID();
                UUID owner_id      = invFetch["owner_id"].AsUUID();
                UUID folder_id     = invFetch["folder_id"].AsUUID();
                bool fetch_folders = invFetch["fetch_folders"].AsBoolean();
                bool fetch_items   = invFetch["fetch_items"].AsBoolean();
                int  sort_order    = invFetch["sort_order"].AsInteger();

                //Set the normal stuff
                contents["agent_id"]  = forceOwnerID == UUID.Zero ? owner_id : forceOwnerID;
                contents["owner_id"]  = forceOwnerID == UUID.Zero ? owner_id : forceOwnerID;
                contents["folder_id"] = folder_id;

                contents.WriteKey("items"); //Start array items
                contents.WriteStartArray("items");
                List <UUID> moreLinkedItems = new List <UUID>();
                int         count           = 0;
                bool        addToCount      = true;
                string      invServer       = "";
                bool        isForeign       = GetIsForeign(AgentID, "InventoryServerURI", m_registry, out invServer);
                IDataReader fretVal         = null;
                if (isForeign)
                {
                    fretVal = GetForeignInventory(AgentID, folder_id, invServer);
                }
                string query = String.Format("where {0} = '{1}'", "parentFolderID", folder_id,
                                             "avatarID", AgentID, "avatarID", libraryOwnerID);
redoQuery:
                using (IDataReader retVal = isForeign ? fretVal : GD.QueryData(query, m_itemsrealm, "*"))
                {
                    try
                    {
                        while (retVal.Read())
                        {
                            contents.WriteStartMap("item"); //Start item kvp
                            UUID assetID = UUID.Parse(retVal["assetID"].ToString());
                            contents["asset_id"] = assetID;
                            contents["name"]     = retVal["inventoryName"].ToString();
                            contents["desc"]     = retVal["inventoryDescription"].ToString();


                            contents.WriteKey("permissions"); //Start permissions kvp
                            contents.WriteStartMap("permissions");
                            contents["group_id"]       = UUID.Parse(retVal["groupID"].ToString());
                            contents["is_owner_group"] = int.Parse(retVal["groupOwned"].ToString()) == 1;
                            contents["group_mask"]     = uint.Parse(retVal["inventoryGroupPermissions"].ToString());
                            contents["owner_id"]       = forceOwnerID == UUID.Zero
                                                       ? UUID.Parse(retVal["avatarID"].ToString())
                                                       : forceOwnerID;
                            contents["last_owner_id"]   = UUID.Parse(retVal["avatarID"].ToString());
                            contents["next_owner_mask"] = uint.Parse(retVal["inventoryNextPermissions"].ToString());
                            contents["owner_mask"]      = uint.Parse(retVal["inventoryCurrentPermissions"].ToString());
                            UUID creator;
                            if (UUID.TryParse(retVal["creatorID"].ToString(), out creator))
                            {
                                contents["creator_id"] = creator;
                            }
                            else
                            {
                                contents["creator_id"] = UUID.Zero;
                            }
                            contents["base_mask"]     = uint.Parse(retVal["inventoryBasePermissions"].ToString());
                            contents["everyone_mask"] = uint.Parse(retVal["inventoryEveryOnePermissions"].ToString());
                            contents.WriteEndMap(/*Permissions*/);

                            contents.WriteKey("sale_info");      //Start permissions kvp
                            contents.WriteStartMap("sale_info"); //Start sale_info kvp
                            contents["sale_price"] = int.Parse(retVal["salePrice"].ToString());
                            switch (byte.Parse(retVal["saleType"].ToString()))
                            {
                            default:
                                contents["sale_type"] = "not";
                                break;

                            case 1:
                                contents["sale_type"] = "original";
                                break;

                            case 2:
                                contents["sale_type"] = "copy";
                                break;

                            case 3:
                                contents["sale_type"] = "contents";
                                break;
                            }
                            contents.WriteEndMap(/*sale_info*/);


                            contents["created_at"] = int.Parse(retVal["creationDate"].ToString());
                            contents["flags"]      = uint.Parse(retVal["flags"].ToString());
                            UUID inventoryID = UUID.Parse(retVal["inventoryID"].ToString());
                            contents["item_id"]   = inventoryID;
                            contents["parent_id"] = UUID.Parse(retVal["parentFolderID"].ToString());
                            UUID avatarID = forceOwnerID == UUID.Zero
                                                ? UUID.Parse(retVal["avatarID"].ToString())
                                                : forceOwnerID;
                            contents["agent_id"] = avatarID;

                            AssetType assetType = (AssetType)int.Parse(retVal["assetType"].ToString());
                            if (assetType == AssetType.Link)
                            {
                                moreLinkedItems.Add(assetID);
                            }
                            contents["type"] = Utils.AssetTypeToString(assetType);
                            InventoryType invType = (InventoryType)int.Parse(retVal["invType"].ToString());
                            contents["inv_type"] = Utils.InventoryTypeToString(invType);

                            if (addToCount)
                            {
                                count++;
                            }
                            contents.WriteEndMap(/*"item"*/);  //end array items
                        }
                    }
                    catch
                    {
                    }
                    finally
                    {
                        try
                        {
                            //Slow, and doesn't help, plus they get called by the using statement
                            //if (retVal != null)
                            //{
                            //    retVal.Close ();
                            //    retVal.Dispose ();
                            //}
                        }
                        catch
                        {
                        }
                        GD.CloseDatabase();
                    }
                }
                if (moreLinkedItems.Count > 0)
                {
                    addToCount = false;
                    query      = String.Format("where {0} = '{1}' and (", "avatarID", AgentID);
#if (!ISWIN)
                    foreach (UUID item in moreLinkedItems)
                    {
                        query = query + String.Format("{0} = '{1}' or ", "inventoryID", item);
                    }
#else
                    query = moreLinkedItems.Aggregate(query, (current, t) => current + String.Format("{0} = '{1}' or ", "inventoryID", t));
#endif
                    query  = query.Remove(query.Length - 4, 4);
                    query += ")";
                    if (isForeign)
                    {
                        fretVal = new FakeDataReader();
                        IConfigurationService configService = m_registry.RequestModuleInterface <IConfigurationService>();
                        if (invServer == "" && configService != null)
                        {
                            List <string> urls = configService.FindValueOf("InventoryServerURI");
                            if (urls.Count > 0)
                            {
                                invServer = urls[0];
                            }
                            else
                            {
                                return(null);
                            }
                        }
                        XInventoryServicesConnector xinv = new XInventoryServicesConnector(invServer + "xinventory");
                        foreach (UUID t in moreLinkedItems)
                        {
                            ((FakeDataReader)fretVal).items.Add(xinv.GetItem(new InventoryItemBase(t)));
                        }
                    }
                    moreLinkedItems.Clear();
                    goto redoQuery;
                }
                contents.WriteEndArray(/*"items"*/);    //end array items

                contents.WriteStartArray("categories"); //We don't send any folders
                int         version = 0;
                QueryFilter filter  = new QueryFilter();
                filter.andFilters["folderID"] = folder_id;
                List <string> versionRetVal = GD.Query(new string[2] {
                    "version", "type"
                }, m_foldersrealm, filter, null, null, null);
                List <InventoryFolderBase> foldersToAdd = new List <InventoryFolderBase>();
                if (versionRetVal.Count > 0)
                {
                    version = int.Parse(versionRetVal[0]);
                    if (int.Parse(versionRetVal[1]) == (int)AssetType.TrashFolder ||
                        int.Parse(versionRetVal[1]) == (int)AssetType.CurrentOutfitFolder ||
                        int.Parse(versionRetVal[1]) == (int)AssetType.LinkFolder)
                    {
                        //If it is the trash folder, we need to send its descendents, because the viewer wants it
                        query = String.Format("where {0} = '{1}' and {2} = '{3}'", "parentFolderID", folder_id,
                                              "agentID", AgentID);
                        using (IDataReader retVal = GD.QueryData(query, m_foldersrealm, "*"))
                        {
                            try
                            {
                                while (retVal.Read())
                                {
                                    contents.WriteStartMap("folder"); //Start item kvp
                                    contents["folder_id"] = UUID.Parse(retVal["folderID"].ToString());
                                    contents["parent_id"] = UUID.Parse(retVal["parentFolderID"].ToString());
                                    contents["name"]      = retVal["folderName"].ToString();
                                    int type = int.Parse(retVal["type"].ToString());
                                    contents["type"]           = type;
                                    contents["preferred_type"] = type;

                                    count++;
                                    contents.WriteEndMap(/*"folder"*/);  //end array items
                                }
                            }
                            catch
                            {
                            }
                            finally
                            {
                                try
                                {
                                    //if (retVal != null)
                                    //{
                                    //    retVal.Close ();
                                    //    retVal.Dispose ();
                                    //}
                                }
                                catch
                                {
                                }
                                GD.CloseDatabase();
                            }
                        }
                    }
                }

                contents.WriteEndArray(/*"categories"*/);
                contents["descendents"] = count;
                contents["version"]     = version;

                //Now add it to the folder array
                contents.WriteEndMap(); //end array internalContents
            }

            contents.WriteEndArray();         //end array folders
            contents.WriteEndMap(/*"llsd"*/); //end llsd

            try
            {
                return(contents.GetSerializer());
            }
            finally
            {
                contents = null;
            }
        }
        public override byte[] FetchInventoryReply (OSDArray fetchRequest, UUID AgentID, UUID forceOwnerID)
        {
            LLSDSerializationDictionary contents = new LLSDSerializationDictionary();
            contents.WriteStartMap("llsd"); //Start llsd

            contents.WriteKey("folders"); //Start array items
            contents.WriteStartArray("folders"); //Start array folders

            foreach (OSD m in fetchRequest)
            {
                contents.WriteStartMap("internalContents"); //Start internalContents kvp
                OSDMap invFetch = (OSDMap)m;

                //UUID agent_id = invFetch["agent_id"].AsUUID();
                UUID owner_id = invFetch["owner_id"].AsUUID();
                UUID folder_id = invFetch["folder_id"].AsUUID();
                bool fetch_folders = invFetch["fetch_folders"].AsBoolean();
                bool fetch_items = invFetch["fetch_items"].AsBoolean();
                int sort_order = invFetch["sort_order"].AsInteger();

                //Set the normal stuff
                contents["agent_id"] = forceOwnerID == UUID.Zero ? owner_id : forceOwnerID;
                contents["owner_id"] = forceOwnerID == UUID.Zero ? owner_id : forceOwnerID;
                contents["folder_id"] = folder_id;

                contents.WriteKey("items"); //Start array items
                contents.WriteStartArray("items");
                List<UUID> moreLinkedItems = new List<UUID> ();
                int count = 0;
                bool addToCount = true;
                string invServer = "";
                bool isForeign = GetIsForeign (AgentID, "InventoryServerURI", m_registry, out invServer);
                IDataReader fretVal = null;
                if (isForeign)
                    fretVal = GetForeignInventory (AgentID, folder_id, invServer);
                string query = String.Format("where {0} = '{1}' and {2} = '{3}'", "parentFolderID", folder_id, "avatarID", AgentID);
            redoQuery:
                using (IDataReader retVal = isForeign ? fretVal : GD.QueryData (query, m_itemsrealm, "*"))
                {
                    try
                    {
                        while (retVal.Read ())
                        {
                            contents.WriteStartMap ("item"); //Start item kvp
                            UUID assetID = UUID.Parse (retVal["assetID"].ToString ());
                            contents["asset_id"] = assetID;
                            contents["name"] = retVal["inventoryName"].ToString ();
                            contents["desc"] = retVal["inventoryDescription"].ToString ();


                            contents.WriteKey ("permissions"); //Start permissions kvp
                            contents.WriteStartMap ("permissions");
                            contents["group_id"] = UUID.Parse (retVal["groupID"].ToString ());
                            contents["is_owner_group"] = int.Parse (retVal["groupOwned"].ToString ()) == 1;
                            contents["group_mask"] = uint.Parse (retVal["inventoryGroupPermissions"].ToString ());
                            contents["owner_id"] = forceOwnerID == UUID.Zero ?  UUID.Parse (retVal["avatarID"].ToString ()) : forceOwnerID;
                            contents["last_owner_id"] = UUID.Parse (retVal["avatarID"].ToString ());
                            contents["next_owner_mask"] = uint.Parse (retVal["inventoryNextPermissions"].ToString ());
                            contents["owner_mask"] = uint.Parse (retVal["inventoryCurrentPermissions"].ToString ());
                            UUID creator;
                            if (UUID.TryParse (retVal["creatorID"].ToString (), out creator))
                                contents["creator_id"] = creator;
                            else
                                contents["creator_id"] = UUID.Zero;
                            contents["base_mask"] = uint.Parse (retVal["inventoryBasePermissions"].ToString ());
                            contents["everyone_mask"] = uint.Parse (retVal["inventoryEveryOnePermissions"].ToString ());
                            contents.WriteEndMap (/*Permissions*/);

                            contents.WriteKey ("sale_info"); //Start permissions kvp
                            contents.WriteStartMap ("sale_info"); //Start sale_info kvp
                            contents["sale_price"] = int.Parse (retVal["salePrice"].ToString ());
                            switch (byte.Parse (retVal["saleType"].ToString ()))
                            {
                                default:
                                    contents["sale_type"] = "not";
                                    break;
                                case 1:
                                    contents["sale_type"] = "original";
                                    break;
                                case 2:
                                    contents["sale_type"] = "copy";
                                    break;
                                case 3:
                                    contents["sale_type"] = "contents";
                                    break;
                            }
                            contents.WriteEndMap (/*sale_info*/);


                            contents["created_at"] = int.Parse (retVal["creationDate"].ToString ());
                            contents["flags"] = uint.Parse (retVal["flags"].ToString ());
                            UUID inventoryID = UUID.Parse (retVal["inventoryID"].ToString ());
                            contents["item_id"] = inventoryID;
                            contents["parent_id"] = UUID.Parse (retVal["parentFolderID"].ToString ());
                            UUID avatarID = forceOwnerID == UUID.Zero ? UUID.Parse (retVal["avatarID"].ToString ()) : forceOwnerID;
                            contents["agent_id"] = avatarID;

                            AssetType assetType = (AssetType)int.Parse (retVal["assetType"].ToString ());
                            if(assetType == AssetType.Link)
                                moreLinkedItems.Add(assetID);
                            contents["type"] = Utils.AssetTypeToString (assetType);
                            InventoryType invType = (InventoryType)int.Parse (retVal["invType"].ToString ());
                            contents["inv_type"] = Utils.InventoryTypeToString (invType);

                            if(addToCount)
                                count++;
                            contents.WriteEndMap (/*"item"*/); //end array items
                        }
                    }
                    catch
                    {
                    }
                    finally
                    {
                        try
                        {
                            //Slow, and doesn't help, plus they get called by the using statement 
                            //if (retVal != null)
                            //{
                            //    retVal.Close ();
                            //    retVal.Dispose ();
                            //}
                        }
                        catch { }
                        GD.CloseDatabase ();
                    }
                }
                if(moreLinkedItems.Count > 0)
                {
                    addToCount = false;
                    query = String.Format("where {0} = '{1}' and (", "avatarID", AgentID);
                    for(int i = 0; i < moreLinkedItems.Count; i++)
                        query += String.Format("{0} = '{1}' or ", "inventoryID", moreLinkedItems[i]);
                    query = query.Remove (query.Length - 4, 4);
                    query += ")";
                    if (isForeign)
                    {
                        fretVal = new FakeDataReader();
                        IConfigurationService configService = m_registry.RequestModuleInterface<IConfigurationService>();
                        if (invServer == "" && configService != null)
                        {
                            List<string> urls = configService.FindValueOf("InventoryServerURI");
                            if (urls.Count > 0)
                                invServer = urls[0];
                            else
                                return null;
                        }
                        XInventoryServicesConnector xinv = new XInventoryServicesConnector(invServer + "xinventory");
                        for (int i = 0; i < moreLinkedItems.Count; i++)
                        {
                            ((FakeDataReader)fretVal).items.Add(xinv.GetItem(new InventoryItemBase(moreLinkedItems[i])));
                        }
                    }
                    moreLinkedItems.Clear ();
                    goto redoQuery;
                }
                contents.WriteEndArray(/*"items"*/); //end array items

                contents.WriteStartArray ("categories"); //We don't send any folders
                int version = 0;
                List<string> versionRetVal = GD.Query ("folderID", folder_id, m_foldersrealm, "version, type");
                List<InventoryFolderBase> foldersToAdd = new List<InventoryFolderBase> ();
                if (versionRetVal.Count > 0)
                {
                    version = int.Parse (versionRetVal[0]);
                    if(int.Parse(versionRetVal[1]) == (int)AssetType.TrashFolder ||
                        int.Parse (versionRetVal[1]) == (int)AssetType.CurrentOutfitFolder ||
                        int.Parse (versionRetVal[1]) == (int)AssetType.LinkFolder)
                    {
                        //If it is the trash folder, we need to send its descendents, because the viewer wants it
                        query = String.Format ("where {0} = '{1}' and {2} = '{3}'", "parentFolderID", folder_id, "agentID", AgentID);
                        using (IDataReader retVal = GD.QueryData (query, m_foldersrealm, "*"))
                        {
                            try
                            {
                                while (retVal.Read ())
                                {
                                    contents.WriteStartMap ("folder"); //Start item kvp
                                    contents["folder_id"] = UUID.Parse (retVal["folderID"].ToString ());
                                    contents["parent_id"] = UUID.Parse (retVal["parentFolderID"].ToString ());
                                    contents["name"] = retVal["folderName"].ToString ();
                                    int type = int.Parse(retVal["type"].ToString ());
                                    contents["type"] = type;
                                    contents["preferred_type"] = type;
                                    
                                    count++;
                                    contents.WriteEndMap (/*"folder"*/); //end array items
                                }
                            }
                            catch
                            {
                            }
                            finally
                            {
                                try
                                {
                                    //if (retVal != null)
                                    //{
                                    //    retVal.Close ();
                                    //    retVal.Dispose ();
                                    //}
                                }
                                catch
                                {
                                }
                                GD.CloseDatabase ();
                            }
                        }
                    }
                }

                contents.WriteEndArray(/*"categories"*/);
                contents["descendents"] = count;
                contents["version"] = version;

                //Now add it to the folder array
                contents.WriteEndMap(); //end array internalContents
            }

            contents.WriteEndArray(); //end array folders
            contents.WriteEndMap(/*"llsd"*/); //end llsd

            try
            {
                return contents.GetSerializer ();
            }
            finally
            {
                contents = null;
            }
        }
 /// <summary>
 /// Creates a schema table.
 /// </summary>
 /// <param name="reader">The reader for whom the schema was requested.</param>
 /// <returns>Default is an empty table.</returns>
 public DataTable CreateSchemaTable(FakeDataReader reader)
 {
     return new DataTable();
 }
 private IDataReader GetForeignInventory (UUID AgentID, UUID folder_id, string serverURL)
 {
     FakeDataReader d = new FakeDataReader ();
     IConfigurationService configService = m_registry.RequestModuleInterface<IConfigurationService> ();
     if (serverURL == "" && configService != null)
     {
         List<string> urls = configService.FindValueOf ("InventoryServerURI");
         if (urls.Count > 0)
             serverURL = urls[0];
         else
             return null;
     }
     XInventoryServicesConnector xinv = new XInventoryServicesConnector (serverURL + "xinventory");
     InventoryCollection c = xinv.GetFolderContent (AgentID, folder_id);
     if (c != null)
     {
         foreach (InventoryItemBase item in c.Items)
         {
             d.items.Add (item);
         }
     }
     return d;
 }