Ejemplo n.º 1
0
        public async Task GetAllTables()
        {
            //create two tables
            string        tableName1 = Recording.GenerateAssetName("testtable1");
            string        tableName2 = Recording.GenerateAssetName("testtable2");
            TableResource table1     = (await _tableCollection.CreateOrUpdateAsync(WaitUntil.Completed, tableName1)).Value;
            TableResource table2     = (await _tableCollection.CreateOrUpdateAsync(WaitUntil.Completed, tableName2)).Value;

            //validate two tables
            TableResource table3 = null;
            TableResource table4 = null;
            int           count  = 0;

            await foreach (TableResource table in _tableCollection.GetAllAsync())
            {
                count++;
                if (table.Id.Name == tableName1)
                {
                    table3 = table;
                }
                if (table.Id.Name == tableName2)
                {
                    table4 = table;
                }
            }
            Assert.AreEqual(count, 2);
            Assert.IsNotNull(table3);
            Assert.IsNotNull(table4);
        }
Ejemplo n.º 2
0
        public ResourceEntry ReadTableEntry(ResourceEntry entry, XmlWriter resourceXML, string name, string tableDIR)
        {
            TableResource resource = new TableResource();

            resource.Deserialize(entry.Version, new MemoryStream(entry.Data), Endian);
            if (!Directory.Exists(tableDIR + "/tables"))
            {
                Directory.CreateDirectory(tableDIR + "/tables");
            }

            resourceXML.WriteElementString("NumTables", resource.Tables.Count.ToString());

            foreach (TableData data in resource.Tables)
            {
                //maybe we can get away with saving to version 1, and then converting to version 2 when packing?
                using (MemoryStream stream = new MemoryStream())
                {
                    data.Serialize(1, stream, Endian.Little);
                    File.WriteAllBytes(tableDIR + data.Name, stream.ToArray());
                }

                resourceXML.WriteElementString("Table", data.Name);
            }

            return(entry);
        }
Ejemplo n.º 3
0
        public async Task CreateDeleteTable()
        {
            //create table
            string        tableName = Recording.GenerateAssetName("testtable");
            TableResource table1    = (await _tableCollection.CreateOrUpdateAsync(WaitUntil.Completed, tableName)).Value;

            Assert.IsNotNull(table1);
            Assert.AreEqual(table1.Id.Name, tableName);

            //validate if created successfully
            TableResource table2 = await _tableCollection.GetAsync(tableName);

            AssertTableEqual(table1, table2);
            Assert.IsTrue(await _tableCollection.ExistsAsync(tableName));
            Assert.IsFalse(await _tableCollection.ExistsAsync(tableName + "1"));

            //delete table
            await table1.DeleteAsync(WaitUntil.Completed);

            //validate if deleted successfully
            Assert.IsFalse(await _tableCollection.ExistsAsync(tableName));
            var exception = Assert.ThrowsAsync <RequestFailedException>(async() => { await _tableCollection.GetAsync(tableName); });

            Assert.AreEqual(404, exception.Status);
        }
Ejemplo n.º 4
0
        private void CreateTableResource(List <string> tables)
        {
            var           typeResource = typeList["Tables"];
            TableResource resource     = new TableResource();

            resource.Tables = tables.ToArray();
            resource.SetEntryVersion(typeResource.GetSerializationVersion());
            AddResource("Tables", BuildResourceTreeNode("", resource));
        }
Ejemplo n.º 5
0
        public ResourceEntry WriteTableEntry(ResourceEntry entry, XPathNodeIterator nodes, string sdsFolder, XmlNode descNode)
        {
            TableResource resource = new TableResource();

            //number of tables
            nodes.Current.MoveToNext();
            int count = nodes.Current.ValueAsInt;

            //read tables and add to resource.
            for (int i = 0; i != count; i++)
            {
                //goto next and read file name.
                nodes.Current.MoveToNext();
                string file = nodes.Current.Value;

                //create file data.
                TableData data = new TableData();

                //now read..
                using (BinaryReader reader = new BinaryReader(File.Open(sdsFolder + file, FileMode.Open)))
                {
                    data.Deserialize(1, reader.BaseStream, Endian);
                    data.Name     = file;
                    data.NameHash = FNV64.Hash(data.Name);
                }

                resource.Tables.Add(data);
            }

            //get version, always 1 Mafia II (2010) is 1, Mafia: DE (2020) is 2.
            nodes.Current.MoveToNext();
            entry.Version = Convert.ToUInt16(nodes.Current.Value);

            //create a temporary memory stream, merge all data and then fill entry data.
            using (MemoryStream stream = new MemoryStream())
            {
                resource.Serialize(entry.Version, stream, Endian.Little);
                entry.Data            = stream.ToArray();
                entry.SlotRamRequired = (uint)entry.Data.Length + 128;
            }

            //fin.
            return(entry);
        }
Ejemplo n.º 6
0
        public IActionResult GetTables(string dbName)
        {
            SMO.Database smoDb = _context.SmoServer.Databases[dbName];
            if (smoDb == null)
            {
                Log.Warning("Database {0} not found. No Tables to display.", dbName);
                return(NotFound());
            }

            // Project a list of TableResource objects
            smoDb.Tables.Refresh();
            List <TableResource> resources = new List <TableResource>();

            foreach (SMO.Table smoTable in smoDb.Tables)
            {
                TableResource resource = new TableResource(this._context, dbName, smoTable.Name, @Url);
                resources.Add(resource);
            }
            return(Ok(resources));
        }
Ejemplo n.º 7
0
        public ResourceEntry ReadTableEntry(ResourceEntry entry, XmlWriter resourceXML, string name, string tableDIR)
        {
            TableResource resource = new TableResource();

            resource.Deserialize(entry.Version, new MemoryStream(entry.Data), Endian.Little);
            if (!Directory.Exists(tableDIR + "/tables"))
            {
                Directory.CreateDirectory(tableDIR + "/tables");
            }

            resourceXML.WriteElementString("NumTables", resource.Tables.Count.ToString());

            foreach (TableData data in resource.Tables)
            {
                data.Serialize(entry.Version, File.Open(tableDIR + data.Name, FileMode.Create), Endian.Little);
                resourceXML.WriteElementString("Table", data.Name);
            }

            return(entry);
        }
Ejemplo n.º 8
0
        private void LoadSDSContent(FileInfo info)
        {
            if (!info.Name.Contains("SDSContent") && info.Extension != "xml")
            {
                return;
            }

            XmlDocument document = new XmlDocument();

            document.Load(info.FullName);

            XPathNavigator nav   = document.CreateNavigator();
            var            nodes = nav.Select("/SDSResource/ResourceEntry");

            while (nodes.MoveNext() == true)
            {
                nodes.Current.MoveToFirstChild();
                string       resourceType = nodes.Current.Value;
                BaseResource resource     = null;

                if (!resources.ContainsKey(resourceType))
                {
                    resources.Add(resourceType, new List <TreeNode>());
                }

                switch (resourceType)
                {
                case "FrameResource":
                case "Effects":
                case "PREFAB":
                case "ItemDesc":
                case "FrameNameTable":
                case "Actors":
                case "NAV_AIWORLD_DATA":
                case "NAV_OBJ_DATA":
                case "NAV_HPD_DATA":
                case "Cutscene":
                case "FxActor":
                case "FxAnimSet":
                case "Translokator":
                case "Speech":
                case "SoundTable":
                case "AnimalTrafficPaths":
                case "AudioSectors":
                case "Animated Texture":
                case "Collisions":
                case "IndexBufferPool":
                case "VertexBufferPool":
                case "EntityDataStorage":
                case "Animation2":
                case "Mipmap":
                case "Sound":
                case "MemFile":
                    resource = new BaseResource();
                    resource.ReadResourceEntry(nodes);
                    break;

                case "Texture":
                    resource = new TextureResource();
                    resource.ReadResourceEntry(nodes);
                    break;

                case "XML":
                    resource = new XMLResource();
                    resource.ReadResourceEntry(nodes);
                    break;

                case "Script":
                    resource = new ScriptResource();
                    resource.ReadResourceEntry(nodes);
                    break;

                case "Table":
                    resource = new TableResource();
                    resource.ReadResourceEntry(nodes);
                    break;

                default:
                    MessageBox.Show("Did not pack type: " + resourceType, "Toolkit", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    break;
                }

                TreeNode node = BuildTreeNode(resource.GetFileName(), resource);
                resources[resourceType].Add(node);
            }
        }
 public static void AssertTableEqual(TableResource table1, TableResource table2)
 {
     Assert.AreEqual(table1.Id.Name, table2.Id.Name);
     Assert.AreEqual(table1.Id.Location, table2.Id.Location);
 }