Example #1
0
        // Initialize data provider
        private void init(Stream inStream)
        {
            HashSet <String> algorithms = new HashSet <String>();
            HashSet <String> versions   = new HashSet <String>();


            using (ZipArchive archive = new ZipArchive(inStream, ZipArchiveMode.Read))
            {
                foreach (ZipArchiveEntry entry in archive.Entries)
                {
                    if ((entry.Name.Length == 0) || (!entry.Name.EndsWith(".json")))
                    {
                        continue;
                    }

                    if (entry.FullName.StartsWith("tables"))
                    {
                        String       s     = extractEntry(entry);
                        StagingTable table = new StagingTable();
                        table = Newtonsoft.Json.JsonConvert.DeserializeObject <StagingTable>(s);

                        if (DebugSettings.DEBUG_LOADED_TABLES)
                        {
                            Debug.WriteLine("Table: ");
                            Debug.WriteLine(table.GetDebugString("  "));
                        }

                        initTable(table);

                        algorithms.Add(table.getAlgorithm());
                        versions.Add(table.getVersion());

                        _tables[table.getId()] = table;
                    }
                    else if (entry.FullName.StartsWith("schemas"))
                    {
                        String        s      = extractEntry(entry);
                        StagingSchema schema = new StagingSchema();
                        schema = Newtonsoft.Json.JsonConvert.DeserializeObject <StagingSchema>(s);

                        if (DebugSettings.DEBUG_LOADED_SCHEMAS)
                        {
                            Debug.WriteLine("Schema: ");
                            Debug.WriteLine(schema.GetDebugString("  "));
                        }

                        initSchema(schema);

                        algorithms.Add(schema.getAlgorithm());
                        versions.Add(schema.getVersion());

                        _schemas[schema.getId()] = schema;
                    }
                }
            }

            // verify that all the algorithm names and versions are consistent
            if (algorithms.Count != 1)
            {
                throw new System.InvalidOperationException("Error initializing provider; only a single algorithm should be included in file");
            }
            if (versions.Count != 1)
            {
                throw new System.InvalidOperationException("Error initializing provider; only a single version should be included in file");
            }

            HashSet <String> .Enumerator enumAlg = algorithms.GetEnumerator();
            HashSet <String> .Enumerator enumVer = versions.GetEnumerator();
            enumAlg.MoveNext();
            enumVer.MoveNext();
            _algorithm = enumAlg.Current;
            _version   = enumVer.Current;

            GenerateSchemaIds();
            GenerateTableIds();

            // finally, initialize any caches now that everything else has been set up
            invalidateCache();
        }