예제 #1
0
파일: Record.cs 프로젝트: heaths/psmsi
        /// <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;
            }
        }