Esempio n. 1
1
 public MSIDataReader(Database msiDatabase, TableInfo tableInfo)
 {
     _database = msiDatabase;
     _tableInfo = tableInfo;
     _tableView = _database.OpenView(tableInfo.SqlSelectString);
     _tableView.Execute();
     _enumerator = _tableView.GetEnumerator();
     _columnCount = tableInfo.Columns.Count;
 }
Esempio n. 2
1
        private void WriteRecords(Database db, string path)
        {
            TransformView transform = null;
            if (db.Tables.Contains(TransformView.TableName))
            {
                transform = new TransformView(db);
            }

            string query = null;
            try
            {
                query = this.GetQuery(db, path);
            }
            catch (PSArgumentException ex)
            {
                base.WriteError(ex.ErrorRecord);
                return;
            }

            if (!string.IsNullOrEmpty(query))
            {
                using (var view = db.OpenView(query))
                {
                    view.Execute();

                    // Get column information from the view before being disposed.
                    var columns = ViewManager.GetColumns(view);

                    var record = view.Fetch();
                    while (null != record)
                    {
                        using (record)
                        {
                            // Create a locally cached copy of the record.
                            var copy = new Record(record, columns, transform, path);
                            var obj = PSObject.AsPSObject(copy);

                            // Show only column properties by default.
                            var memberSet = ViewManager.GetMemberSet(view);
                            obj.Members.Add(memberSet, true);

                            this.WriteObject(obj);
                        }

                        record = view.Fetch();
                    }
                }
            }
            else
            {
                foreach (var table in db.Tables)
                {
                    if (db.IsTablePersistent(table.Name))
                    {
                        var info = new TableInfo(table.Name, path, transform, this.Patch, this.Transform);
                        var obj = PSObject.AsPSObject(info);

                        this.WriteObject(obj);
                    }
                }
            }
        }
Esempio n. 3
0
        private void Initialize(Database db, Microsoft.Deployment.WindowsInstaller.TableInfo info)
        {
            using (var view = db.OpenView(info.SqlSelectString))
            {
                view.Execute();

                var record = view.Fetch();
                while (null != record)
                {
                    using (record)
                    {
                        var table  = record.GetString(1);
                        var column = record.GetString(2);
                        var key    = record.GetString(3);

                        Table tbl;
                        if (!this.tables.ContainsKey(table))
                        {
                            tbl = new Table();
                            this.tables.Add(table, tbl);
                        }
                        else
                        {
                            tbl = this.tables[table];
                        }

                        Row row = null;
                        if (!string.IsNullOrEmpty(key))
                        {
                            var primaryKey = key
                                             .Replace(TransformView.Tab, Record.KeySeparator)
                                             .Replace(TransformView.Space, string.Empty);

                            if (!tbl.Rows.Contains(primaryKey))
                            {
                                row = new Row(primaryKey);
                                tbl.Rows.Add(row);
                            }
                            else
                            {
                                row = tbl.Rows[primaryKey];
                            }
                        }

                        switch (TransformView.TableOperations.IndexOf(column))
                        {
                        case 0:
                            tbl.SetPrincipalOperation(TableOperation.Create);
                            break;

                        case 1:
                            tbl.SetPrincipalOperation(TableOperation.Modify);
                            row.SetPrincipalOperation(RowOperation.Insert);
                            break;

                        case 2:
                            tbl.SetPrincipalOperation(TableOperation.Modify);
                            row.SetPrincipalOperation(RowOperation.Delete);
                            break;

                        case 3:
                            tbl.SetPrincipalOperation(TableOperation.Drop);
                            break;

                        default:
                            tbl.SetPrincipalOperation(TableOperation.Modify);

                            if (null != row)
                            {
                                row.SetPrincipalOperation(RowOperation.Modify);
                            }

                            break;
                        }
                    }

                    record = view.Fetch();
                }
            }
        }
Esempio n. 4
0
            /// <summary>
            ///   Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
            /// </summary>
            /// <filterpriority>2</filterpriority>
            public void Dispose()
            {
                if (_currentRecord != null) {
                    _currentRecord.Dispose();
                }

                if (_enumerator != null) {
                    _enumerator.Dispose();
                }

                if (_tableView != null) {
                    _tableView.Dispose();
                }

                _currentRecord = null;
                _enumerator = null;
                _tableView = null;
                _database = null;
                _tableInfo = null;
            }