Пример #1
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);
                    }
                }
            }
        }
        private int MainAddTransform(bool act = true)
        {
            //var utv = new TransformView();
            var utv = new TransformView();
            var dc  = utv.DataContex;
            var id  = dc.Id = GiveIdModel.Get;

            switch (_flameColorMode)
            {
            case FlameColorMode.Color:
                dc.GradientModel = null;
                break;

            case FlameColorMode.Gradient:
                dc.GradientModel = _gradientModel;
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }

            dc.FlameColorMode = _flameColorMode;
            Transforms.Add(utv);
            if (act)
            {
                Act("AddTransformation", id);
            }
            return(id);
        }
Пример #3
0
 public void NoTransformViewChanges()
 {
     var package = Path.Combine(base.TestContext.DeploymentDirectory, "Example.msi");
     using (var db = new InstallPackage(package, DatabaseOpenMode.ReadOnly))
     {
         var view = new TransformView(db);
         Assert.AreEqual<int>(0, view.Tables.Count);
     }
 }
Пример #4
0
        public void TransfomViewChanges()
        {
            var package = Path.Combine(base.TestContext.DeploymentDirectory, "Example.msi");
            var patch = Path.Combine(base.TestContext.DeploymentDirectory, "Example.msp");
            using (var db = new InstallPackage(package, DatabaseOpenMode.ReadOnly))
            {
                var applicator = new PatchApplicator(db);
                applicator.Add(patch);

                applicator.Apply(true);

                var view = new TransformView(db);

                // Despite Orca showing 5 tables, the _TransformView table does not show the created, empty "Patch" table.
                Assert.AreEqual<int>(4, view.Tables.Count);

                Assert.AreEqual<TableOperation>(TableOperation.Modify, view.GetTableOperation("Media"));
                Assert.AreEqual<RowOperation>(RowOperation.None, view.GetRowOperation("Media", "1"));
                Assert.AreEqual<RowOperation>(RowOperation.Insert, view.GetRowOperation("Media", "100"));

                Assert.AreEqual<TableOperation>(TableOperation.Create, view.GetTableOperation("PatchPackage"));
                Assert.AreEqual<RowOperation>(RowOperation.Insert, view.GetRowOperation("PatchPackage", "{FF63D787-26E2-49CA-8FAA-28B5106ABD3A}"));

                Assert.AreEqual<TableOperation>(TableOperation.Modify, view.GetTableOperation("Property"));
                Assert.AreEqual<RowOperation>(RowOperation.None, view.GetRowOperation("Property", "ProductCode"));
                Assert.AreEqual<RowOperation>(RowOperation.Modify, view.GetRowOperation("Property", "ProductVersion"));
                Assert.AreEqual<RowOperation>(RowOperation.Insert, view.GetRowOperation("Property", "Example.PatchCode"));
                Assert.AreEqual<RowOperation>(RowOperation.Insert, view.GetRowOperation("Property", "Example.AllowRemoval"));

                Assert.AreEqual<TableOperation>(TableOperation.Modify, view.GetTableOperation("Registry"));
                Assert.AreEqual<RowOperation>(RowOperation.Modify, view.GetRowOperation("Registry", "reg302A797C45AD3AD1EC816DDC58DF65F3"));

                // Negative assertions.
                Assert.AreEqual<TableOperation>(TableOperation.None, view.GetTableOperation("File"));
                Assert.AreEqual<RowOperation>(RowOperation.None, view.GetRowOperation(null, null));
                Assert.AreEqual<RowOperation>(RowOperation.None, view.GetRowOperation("File", null));
                Assert.AreEqual<RowOperation>(RowOperation.None, view.GetRowOperation("File", "product.wxs"));
            }
        }
Пример #5
0
        /// <summary>
        /// Creates a new instance of the <see cref="TableInfo"/> class.
        /// </summary>
        /// <param name="name">The name of the table.</param>
        /// <param name="path">The full path to the <see cref="Database"/> containing the table.</param>
        /// <param name="transform">The <see cref="TransformView"/> containing information about operations performed on the table.</param>
        /// <param name="patches">A list of patches applied to the <see cref="Database"/> containing the table.</param>
        /// <param name="transforms">A list of transformed applied to the <see cref="Database"/> containing the table.</param>
        /// <exception cref="ArgumentNullException"><paramref name="name"/> is null or an empty string.</exception>
        internal TableInfo(string name, string path, TransformView transform, IEnumerable<string> patches, IEnumerable<string> transforms)
        {
            if (string.IsNullOrEmpty(name))
            {
                throw new ArgumentNullException("name");
            }

            this.Table = name;
            this.Path = path;

            if (null != transform)
            {
                this.Operation = transform.GetTableOperation(name);
            }
            else
            {
                this.Operation = TableOperation.None;
            }

            if (null != patches)
            {
                this.Patch = new List<string>(patches).AsReadOnly();
            }
            else
            {
                // Parameter binding requires non-null list.
                this.Patch = TableInfo.Empty;
            }

            if (null != transforms)
            {
                this.Transform = new List<string>(transforms).AsReadOnly();
            }
            else
            {
                this.Transform = TableInfo.Empty;
            }
        }
Пример #6
0
        /// <summary>
        /// Gets property records from the item.
        /// </summary>
        /// <param name="item">The item from which properties are retrieved.</param>
        protected override void ProcessItem(PSObject item)
        {
            var path = item.GetPropertyValue<string>("PSPath");
            var providerPath = this.SessionState.Path.GetUnresolvedProviderPathFromPSPath(path);

            var db = this.OpenDatabase(providerPath);
            if (null != db)
            {
                // Keep track of which properties were selected.
                IList<string> properties = null;
                if (this.PassThru)
                {
                    properties = new List<string>();
                }

                using (db)
                {
                    TransformView transform = null;
                    if (db.Tables.Contains(TransformView.TableName))
                    {
                        transform = new TransformView(db);
                    }

                    var table = "Property";
                    if ((db is PatchPackage) && db.Tables.Contains("MsiPatchMetadata"))
                    {
                        table = "MsiPatchMetadata";
                    }

                    var query = string.Format("SELECT `Property`, `Value` FROM `{0}`", table);
                    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)
                            {
                                var name = record.GetString(1);
                                if (0 == this.propertyPatterns.Count() || name.Match(this.propertyPatterns))
                                {
                                    if (this.PassThru)
                                    {
                                        if (0 == item.Properties.Match(name).Count())
                                        {
                                            properties.Add(name);

                                            var property = new PSNoteProperty(name, record.GetString(2));
                                            item.Properties.Add(property, true);
                                        }
                                    }
                                    else
                                    {
                                        // Create a locally cached copy of the record.
                                        var copy = new Record(record, columns, transform, providerPath);
                                        var obj = PSObject.AsPSObject(copy);

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

                                        base.WriteObject(obj);
                                    }
                                }
                            }

                            record = view.Fetch();
                        }
                    }
                }

                if (this.PassThru)
                {
                    var propertySet = new PSPropertySet("MSIProperties", properties);
                    item.Members.Add(propertySet, true);

                    base.WriteObject(item);
                }
            }
        }
Пример #7
0
        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);
                    }
                }
            }
        }
Пример #8
0
        /// <summary>
        /// Gets property records from the item.
        /// </summary>
        /// <param name="item">The item from which properties are retrieved.</param>
        protected override void ProcessItem(PSObject item)
        {
            var path         = item.GetPropertyValue <string>("PSPath");
            var providerPath = this.SessionState.Path.GetUnresolvedProviderPathFromPSPath(path);

            var db = this.OpenDatabase(providerPath);

            if (null != db)
            {
                // Keep track of which properties were selected.
                IList <string> properties = null;
                if (this.PassThru)
                {
                    properties = new List <string>();
                }

                using (db)
                {
                    TransformView transform = null;
                    if (db.Tables.Contains(TransformView.TableName))
                    {
                        transform = new TransformView(db);
                    }

                    var table = "Property";
                    if ((db is PatchPackage) && db.Tables.Contains("MsiPatchMetadata"))
                    {
                        table = "MsiPatchMetadata";
                    }

                    var query = string.Format("SELECT `Property`, `Value` FROM `{0}`", table);
                    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)
                            {
                                var name = record.GetString(1);
                                if (0 == this.propertyPatterns.Count() || name.Match(this.propertyPatterns))
                                {
                                    if (this.PassThru)
                                    {
                                        if (0 == item.Properties.Match(name).Count())
                                        {
                                            properties.Add(name);

                                            var property = new PSNoteProperty(name, record.GetString(2));
                                            item.Properties.Add(property, true);
                                        }
                                    }
                                    else
                                    {
                                        // Create a locally cached copy of the record.
                                        var copy = new Record(record, columns, transform, providerPath);
                                        var obj  = PSObject.AsPSObject(copy);

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

                                        base.WriteObject(obj);
                                    }
                                }
                            }

                            record = view.Fetch();
                        }
                    }
                }

                if (this.PassThru)
                {
                    var propertySet = new PSPropertySet("MSIProperties", properties);
                    item.Members.Add(propertySet, true);

                    base.WriteObject(item);
                }
            }
        }
Пример #9
0
 public void TransformViewNullArguments()
 {
     var view = new TransformView(null);
 }
Пример #10
0
        /// <summary>
        /// Creates a new instance of the <see cref="Record"/> class copying values
        /// from the <see cref="Deployment.WindowsInstaller.Record"/> object.
        /// </summary>
        /// <param name="record">The <see cref="Deployment.WindowsInstaller.Record"/> from which to copy values.</param>
        /// <param name="columns">The <see cref="ColumnCollection"/> for a <see cref="Deployment.WindowsInstaller.View"/>.</param>
        /// <param name="transform">The <see cref="TransformView"/> containing information about operations performed on this record.</param>
        /// <param name="path">The path to the package that contains the record.</param>
        internal Record(Deployment.WindowsInstaller.Record record, ColumnCollection columns, TransformView transform = null, string path = null)
        {
            // Internal constructor will assume valid parameters.

            // Shared reference to the column collection.
            this.Columns = columns;

            this.Path = path;

            // Cache the data from the record.
            var primaryKeys = new List<string>();
            this.Data = new List<object>(columns.Count);
            for (int i = 0; i < columns.Count; ++i)
            {
                // Windows Installer uses 1-based indices.
                var offset = i + 1;

                var type = columns[i].Type;
                if (type.IsEnum)
                {
                    var value = record.GetNullableInteger(offset);
                    this.Data.Add(new AttributeColumn(type, value));

                    if (columns[i].IsPrimaryKey)
                    {
                        primaryKeys.Add(null != value ? value.Value.ToString(CultureInfo.InvariantCulture) : string.Empty);
                    }
                }
                else if (typeof(Stream) == type)
                {
                    var buffer = CopyStream(record, offset);
                    this.Data.Add(buffer);

                    // Binary column types cannot be primary keys.
                }
                else
                {
                    var data = record[offset];
                    this.Data.Add(data);

                    if (columns[i].IsPrimaryKey)
                    {
                        primaryKeys.Add(null != data ? data.ToString() : string.Empty);
                    }
                }
            }

            if (0 < primaryKeys.Count)
            {
                this.PrimaryKey = primaryKeys.Join(Record.KeySeparator);
            }

            // Can only reliably get row operations performed on rows in a single table.
            if (null != transform && 1 == columns.TableNames.Count())
            {
                var tableName = columns.TableNames[0];
                this.Operation = transform.GetRowOperation(tableName, this.PrimaryKey);
            }
            else
            {
                this.Operation = RowOperation.None;
            }
        }