示例#1
0
        public OrganizationPresenter(View.IOrganizationView _view)
        {
            model = new Model.OrganizationModel();
            view  = _view;

            tables = model.GetTables();

            Dictionary <int, string> dictionary
                = model.GetDictionaryEmployeeStatus(tables.EmployeeStatus);

            view.CBEmployeeStatus.SetItems(dictionary);


            DataSet dataSet = model.CreateDataSet(tables.DepartmentTable
                                                  , tables.EmployeeStatus
                                                  , tables.EmployeeTable
                                                  , tables.RelationTable);


            tableForDGV = CreateTable.Create(new AfterRelationTableCreator());
            model.CreateRelationForDataSet(dataSet);
            model.GetTableAfterRelation(dataSet, tableForDGV);
            view.DGVRelation.DataSource = tableForDGV;

            view.BtnTableMode.CheckedChanged          += OnButtonTableMode_CheckedChanged;
            view.CBEmployeeStatus.SelectedItemChanged += OnComboboxStatusEmployee_SelectedIndexChanged;
            OnButtonTableMode_CheckedChanged(new object(), EventArgs.Empty);
        }
 public void VerifyHasTableWorks()
 {
     DropTable.For <Player>().TryExecute(Connection);
     Assert.That(HasTable.For <Player>().ExecuteCheck(Connection), Is.False);
     CreateTable.For <Player>().Execute(Connection);
     Assert.That(HasTable.For <Player>().ExecuteCheck(Connection), Is.True);
 }
        public void IdentityTable()
        {
            var ct = new CreateTable(new SqlServerSyntax(), new TableInfo("TableC", "dbo", typeof(TableC)));

            using (var cn = GetDb().GetConnection())
            {
                StringBuilder sb = new StringBuilder();
                foreach (string sql in ct.SqlCommands(cn))
                {
                    sb.Append(sql);
                }
                Assert.IsTrue(sb.ToString().Equals(
                                  @"CREATE TABLE [dbo].[TableC] (
	[Id] int identity(1,1),
	[SomeValue] bigint NOT NULL,
	[SomeDate] datetime NOT NULL,
	[SomeDouble] float NOT NULL,
	[AnotherValue] int NOT NULL,
	[DateCreated] datetime NOT NULL,
	[CreatedBy] nvarchar(20) NOT NULL,
	[DateModified] datetime NULL,
	[ModifiedBy] nvarchar(20) NULL,
	CONSTRAINT [PK_TableC] PRIMARY KEY CLUSTERED ([Id])
)"));
            }
        }
示例#4
0
        protected override void Generate(CreateTable op)
        {
            if (string.IsNullOrWhiteSpace(op.PKName))
            {
                this.AddRun(new GenerationExceptionRun
                {
                    Message = "暂时不支持生成没有主键的表:" + op.TableName
                });
                return;
            }

            using (var sql = this.Writer())
            {
                sql.Write("CREATE TABLE ");
                sql.WriteLine(this.Quote(op.TableName));
                sql.WriteLine("(");
                sql.Indent++;
                this.GenerateColumnDeclaration(sql, op.PKName, op.PKDataType, op.PKLength, true, true);

                sql.WriteLine();
                sql.Indent--;
                sql.Write(")");

                this.AddRun(sql);
            }

            using (var sql = this.Writer())
            {
                this.GenerateAddPKConstraint(sql, op.TableName, op.PKName);

                this.AddRun(sql);
            }

            if (op.PKIdentity)
            {
                //var seqName = this.SEQName(op);
                //var existsSql= string.Format("SELECT {0}.CURRVAL FROM DUAL", seqName);

                var sql = string.Format(@"DECLARE T_COUNT NUMBER;
BEGIN
    SELECT COUNT(*) INTO T_COUNT FROM DUAL WHERE EXISTS(SELECT * FROM ALL_SEQUENCES WHERE SEQUENCE_NAME='{0}');
    IF T_COUNT = 0 THEN
        EXECUTE IMMEDIATE '
        CREATE SEQUENCE {0}
        MINVALUE 1
        MAXVALUE 99999999999999999
        START WITH 1
        INCREMENT BY 1
        NOCACHE
        ORDER
        ';
    END IF;
END;", this.SEQName(op));

                this.AddRun(new SqlMigrationRun
                {
                    Sql = sql
                });
            }
        }
示例#5
0
        public void WhenRecordInsertedWithAutoIncrementIdentityGetsUpdated()
        {
            DropTable.For <TableWithIncrement>().TryExecute(Connection);
            CreateTable.For <TableWithIncrement>().Execute(Connection);

            var first = new TableWithIncrement
            {
                Value = "Foo"
            };

            var second = new TableWithIncrement
            {
                Value = "Bar"
            };

            var numberFirst  = InsertInto.Row(first).GetLastInsertIdentity <ulong>().ExecuteRead(Connection).Single();
            var numberSecond = InsertInto.Row(second).GetLastInsertIdentity <ulong>().ExecuteRead(Connection).Single();

            Assert.That(numberFirst, Is.EqualTo(1));
            Assert.That(numberSecond, Is.EqualTo(2));

            var firstSelected = Select.From <TableWithIncrement>().WhereEqual(x => x.Identifier, 1UL)
                                .ExecuteRead(Connection)
                                .SingleOrDefault();

            Assert.IsNotNull(firstSelected);
            Assert.That(firstSelected.Identifier, Is.EqualTo(1UL));
            Assert.That(firstSelected.Value, Is.EqualTo("Foo"));
        }
示例#6
0
        public static Query Parse(Benumerator <char> en)
        {
            var s = en.Save();

            en.MoveNext();
            if (en.Current == ' ')
            {
                en.MoveNext();
            }

            if (en.Current == 'C')
            {
                return(CreateTable.Parse(s));
            }
            else if (en.Current == 'F')
            {
                return(Get.Parse(s));
            }
            else if (en.Current == 'I')
            {
                return(Insert.Parse(s));
            }
            else
            {
                throw new Exception("Unrecognized first command");
            }
        }
示例#7
0
        public void WhenRecordsInsertedTheyCanGetUpdated()
        {
            DropTable.For <Player>().TryExecute(Connection);
            CreateTable.For <Player>().Execute(Connection);

            var player = new Player
            {
                Age        = 10,
                Birthday   = DateTime.Now,
                Identifier = Guid.NewGuid(),
                Name       = "Jim"
            };

            Assert.That(InsertInto.Row(player).TryExecute(Connection));
            var records = Select.From <Player>().ExecuteRead(Connection).ToImmutableList();

            Assert.That(records, Has.Count.EqualTo(1));
            Assert.That(records[0].Name, Is.EqualTo("Jim"));

            player.Name = "John";
            Assert.That(InsertInto.Row(player).TryExecute(Connection), Is.False);

            records = Select.From <Player>().ExecuteRead(Connection).ToImmutableList();
            Assert.That(records, Has.Count.EqualTo(1));
            Assert.That(records[0].Name, Is.EqualTo("Jim"));

            Assert.That(InsertInto.Row(player).UpdateOnDuplicateKey.TryExecute(Connection));

            records = Select.From <Player>().ExecuteRead(Connection).ToImmutableList();
            Assert.That(records, Has.Count.EqualTo(1));
            Assert.That(records[0].Name, Is.EqualTo("John"));
        }
示例#8
0
        public void DeferredInlineResults()
        {
            // setup

            new Command(_database)
            {
                CreateTable.From <Sample>("deferred_inline_table"),
                new Insert {
                    Into = "deferred_inline_table", Columns = { "ID", "Column1" }, Values = { 1, "Test" }
                },
            }.Execute();

            // test

            var context = _database.CreateDeferContext();

            var results1 = new Command(context)
            {
                new Select {
                    Columns = "ID", From = "deferred_inline_table"
                }
            }.FetchListDeferred <Sample>();

            var results2 = new Command(context)
            {
                new Select {
                    Columns = "ID", From = "deferred_inline_table"
                }
            }.FetchListDeferred <Sample>();

            Assert.NotEmpty(results1.Result);
            Assert.NotEmpty(results2.Result);
        }
示例#9
0
        /// <summary>
        /// 生成创建表的语句
        /// </summary>
        /// <param name="op">创建表的对象实例</param>
        protected override void Generate(CreateTable op)
        {
            if (string.IsNullOrWhiteSpace(op.PKName))
            {
                this.AddRun(new GenerationExceptionRun
                {
                    Message = "暂时不支持生成没有主键的表:" + op.TableName
                });
                return;
            }

            using (var sql = this.Writer())
            {
                sql.Write("CREATE TABLE IF NOT EXISTS ");
                sql.WriteLine(this.Quote(op.TableName));
                sql.WriteLine("(");
                sql.Indent++;
                var pkType = op.PKIdentity ? DbType.Int32 : op.PKDbType;//sqllite:AUTOINCREMENT is only allowed on an INTEGER PRIMARY KEY
                this.GenerateColumnDeclaration(sql, op.PKName, pkType, op.PKLength, true, true);
                sql.Write(" PRIMARY KEY");
                if (op.PKIdentity)
                {
                    sql.Write(" AUTOINCREMENT");
                }
                sql.WriteLine();
                sql.Indent--;
                sql.Write(")");

                this.AddRun(sql);
            }
        }
示例#10
0
        public App()
        {
            Device.SetFlags(new string[] { "Shapes_Experimental", "CarouselView_Experimental", "MediaElement_Experimental", "SwipeView_Experimental" });

            InitializeComponent();

            var hasKey = Preferences.ContainsKey("BdCreated");

            if (!hasKey)
            {
                var bd     = new CreateTable();
                var result = bd.CreationDeLaBaseDeDonnee();


                if (result)
                {
                    Preferences.Set("BdCreated", true);
                }
                else
                {
                    MainPage = new NavigationPage(new Lottie());
                }
            }



            //MainPage = new NavigationPage(new Lottie());
            MainPage = new NavigationPage(new HomePage());
            // MainPage = new NavigationPage(new SettingsPage());
        }
示例#11
0
        static void Main(string[] args)
        {
            Document document = new Document();

            Console.WriteLine("Datums: " + document.date());
            Console.WriteLine("Numurs: " + document.number);
            Console.WriteLine("maxSumma: " + document.maxSumm);
            CreateTable createTable = new CreateTable();

            List <List <string> > table = createTable.createTable();

            Console.WriteLine("\nKods     Summa");
            foreach (List <string> rows in table)
            {
                foreach (string el in rows)
                {
                    Console.Write(el + "        ");
                }

                Console.WriteLine();
            }

            Console.WriteLine("\nKopējais dokumenta rindu skaits: " + table.Count);
            Console.WriteLine("Kopējā dokumenta summa: " + createTable.endSum);
            Console.WriteLine("Pēdēja summa: " + createTable.lastSum);
            Console.WriteLine("Pārsniegta dokumenta Maksimālā summa par: " + Math.Abs(document.maxSumm - (createTable.endSum + createTable.lastSum)));
        }
示例#12
0
        /// <summary>
        /// 生成创建表的语句
        /// </summary>
        /// <param name="op">创建表的对象实例</param>
        protected override void Generate(CreateTable op)
        {
            if (string.IsNullOrWhiteSpace(op.PKName))
            {
                this.AddRun(new GenerationExceptionRun
                {
                    Message = "暂时不支持生成没有主键的表:" + op.TableName
                });
                return;
            }

            using (var sql = this.Writer())
            {
                sql.Write("CREATE TABLE IF NOT EXISTS ");
                sql.WriteLine(this.Quote(op.TableName));
                sql.WriteLine("(");
                sql.Indent++;
                this.GenerateColumnDeclaration(sql, op.PKName, op.PKDataType, op.PKLength, true, true);
                if (op.PKIdentity)
                {
                    sql.Write(" auto_increment");
                }
                sql.Write(" primary key");
                sql.WriteLine();
                sql.Indent--;
                sql.Write(");");

                this.AddRun(sql);
            }
        }
示例#13
0
        public ReturnValue Create(CreateTable model)
        {
            ReturnValue revalue = new ReturnValue();

            try
            {
                StringBuilder sqlstr = new StringBuilder();
                sqlstr.AppendFormat("if exists (select * from sysobjects where name='{0}') drop table {0}", model.TableName);
                sqlstr.AppendFormat(" create table {0}( Id uniqueidentifier primary key,", model.TableName);
                for (int i = 0; i < model.ColumnModels.Count; i++)
                {
                    if (i > 0)
                    {
                        sqlstr.Append(",");
                    }
                    sqlstr.Append(GetCompleteType(model.ColumnModels[i]));
                }
                sqlstr.AppendFormat(")");

                SQLHelper.ExecuteCommand(sqlstr.ToString());
                revalue.IsSuccess = true;
            }
            catch (Exception ex)
            {
                revalue.IsSuccess = false;
                revalue.Message   = ex.Message;
            }

            return(revalue);
        }
示例#14
0
        /// <summary>
        /// 生成创建表的语句
        /// </summary>
        /// <param name="op"></param>
        protected override void Generate(CreateTable op)
        {
            if (string.IsNullOrWhiteSpace(op.PKName))
            {
                this.AddRun(new GenerationExceptionRun
                {
                    Message = "暂时不支持生成没有主键的表:" + op.TableName
                });
                return;
            }

            using (var sql = this.Writer())
            {
                sql.Write("CREATE TABLE ");
                sql.WriteLine(this.Quote(op.TableName));
                sql.WriteLine("(");
                sql.Indent++;
                this.GenerateColumnDeclaration(sql, op.PKName, op.PKDataType, op.PKLength, true, true);

                sql.WriteLine();
                sql.Indent--;
                sql.Write(")");

                this.AddRun(sql);
            }

            using (var sql = this.Writer())
            {
                this.GenerateAddPKConstraint(sql, op.TableName, op.PKName);
                this.AddRun(sql);
            }
        }
        private void Button3_Click(object sender, RoutedEventArgs e)
        {
            Data.sWatch.Start();
            CreateTable Table = new CreateTable();

            this.Hide();
        }
示例#16
0
 private Tables()
 {
     DepartmentTable = CreateTable.Create(new DepartmentTableCreator());
     EmployeeTable   = CreateTable.Create(new EmployeeTableCreator());
     EmployeeStatus  = CreateTable.Create(new EmployeeStatusTableCreator());
     RelationTable   = CreateTable.Create(new RelationTableCreator());
 }
示例#17
0
        public string[] SelectableColumns(bool allColumns, bool squareBraces = false)
        {
            Type t = typeof(TRecord);

            IdentityColumnAttribute idAttr;
            string identityCol    = (t.HasAttribute(out idAttr)) ? idAttr.ColumnName : SqlDb.IdentityColumnName;
            bool   useAltIdentity = (!identityCol.Equals(SqlDb.IdentityColumnName));

            var props = t.GetProperties().Where(p =>
                                                p.CanRead &&
                                                CreateTable.IsSupportedType(p.PropertyType) &&
                                                !p.HasAttribute <NotMappedAttribute>() &&
                                                !IsSupressedIdentity(useAltIdentity, p.SqlColumnName()));

            var results = (allColumns) ?
                          props.Select(p => p.SqlColumnName()) :
                          props.Where(p => !p.HasAttribute <LargeValueColumn>()).Select(p => p.SqlColumnName());

            if (squareBraces)
            {
                results = results.Select(p => $"[{p}]");
            }

            return(results.ToArray());
        }
示例#18
0
        public async Task MixedDeferredAsyncAndSync()
        {
            // setup

            var t = CreateTable.From <Sample>("deferred_inline_table");

            new Command(_database)
            {
                CreateTable.From <Sample>("deferred_mixed_table"),
                new Insert {
                    Into = "deferred_mixed_table", Columns = { "ID", "Column1" }, Values = { 1, "Test" }
                },
            }.Execute();

            // test

            var context = _database.CreateDeferContext();

            var results1 = new Command(context)
            {
                new Select {
                    Columns = "ID", From = "deferred_mixed_table"
                }
            }.FetchListDeferred <Sample>();

            var results2 = new Command(context)
            {
                new Select {
                    Columns = "ID", From = "deferred_mixed_table"
                }
            }.FetchListDeferred <Sample>();

            Assert.NotEmpty(await results1.ResultAsync);
            Assert.NotEmpty(results2.Result);
        }
示例#19
0
        /// <summary>
        /// Provides a general-purpose way to save QueryTraces. Use this in <see cref="Query{TResult}.TraceCallback"/> or
        /// <see cref="SqlDb{TKey}.TraceCallback"/> handlers
        /// </summary>
        public static void SaveTrace(IDbConnection connection, QueryTrace trace, SqlDb <int> db)
        {
            if (!db.Syntax.TableExists(connection, typeof(QueryTrace)))
            {
                var tableInfo = db.Syntax.GetTableInfoFromType(typeof(QueryTrace));
                if (!db.Syntax.SchemaExists(connection, tableInfo.Schema))
                {
                    CreateSchema cs = new CreateSchema(db.Syntax, tableInfo.Schema);
                    foreach (var cmd in cs.SqlCommands(connection))
                    {
                        connection.Execute(cmd);
                    }
                }
                CreateTable ct = new CreateTable(db.Syntax, db.Syntax.GetTableInfoFromType(typeof(QueryTrace)));
                foreach (var cmd in ct.SqlCommands(connection))
                {
                    connection.Execute(cmd);
                }
            }

            var callback = db.TraceCallback;

            // prevent infinite loop
            db.TraceCallback = null;

            db.Save(connection, trace);

            // restore original callback
            db.TraceCallback = callback;
        }
示例#20
0
        public CreateTable GenerateCreateTableStatement(Table t)
        {
            CreateTable ct = new CreateTable();

            ct.Table = t;
            return(ct);
        }
示例#21
0
        public void ReturnsCreateTableScript_WithUppercaseSqlSyntax_AndNull()
        {
            var result = CreateTable.Generate <TestCreateTableClassWithNullableIntProperty>(new CreateTableOptions {
                SqlSyntaxIsUppercase = true
            });

            Assert.Equal("CREATE TABLE TestCreateTableClassWithNullableIntProperty\r\n(\r\n    TheNullableIntProperty INT NULL\r\n)", result);
        }
示例#22
0
        public void ReturnsCreateTableScript_TestClassWithTwoProperties_WithPrimaryKeyClusteredOption_WithFirstPropertyAsPrimaryKey_AndUppercase_AndIdentifierDelimited()
        {
            var result = CreateTable.Generate <TestClassWithTwoProperties>(new CreateTableOptions {
                IncludePrimaryKeyClusteredConstraint = true, SqlSyntaxIsUppercase = true, DelimitIdentifiers = true
            });

            Assert.Equal("CREATE TABLE TestClassWithTwoProperties\r\n(\r\n    [TheIntProperty] INT NOT NULL,\r\n    [TheBoolProperty] BIT NOT NULL,\r\n\r\n    CONSTRAINT [PK_TheIntProperty] PRIMARY KEY CLUSTERED\r\n    (\r\n        [TheIntProperty] ASC\r\n    )\r\n)", result);
        }
示例#23
0
        public void ReturnsCreateTableScript_TestClassWithTwoProperties_WithPrimaryKeyClusteredOption_WithFirstPropertyAsPrimaryKey()
        {
            var result = CreateTable.Generate <TestClassWithTwoProperties>(new CreateTableOptions {
                IncludePrimaryKeyClusteredConstraint = true
            });

            Assert.Equal("create table TestClassWithTwoProperties\r\n(\r\n    TheIntProperty int not null,\r\n    TheBoolProperty bit not null,\r\n\r\n    constraint PK_TheIntProperty primary key clustered\r\n    (\r\n        TheIntProperty asc\r\n    )\r\n)", result);
        }
示例#24
0
        public void ReturnsCreateTableScript_TestClassWithTwoProperties_WithPrimaryKeyClusteredOption_WithFirstPropertyAsPrimaryKey_AndIdentifierDelimited()
        {
            var result = CreateTable.Generate <TestClassWithTwoProperties>(new CreateTableOptions {
                IncludePrimaryKeyClusteredConstraint = true, DelimitIdentifiers = true
            });

            Assert.Equal("create table TestClassWithTwoProperties\r\n(\r\n    [TheIntProperty] int not null,\r\n    [TheBoolProperty] bit not null,\r\n\r\n    constraint [PK_TheIntProperty] primary key clustered\r\n    (\r\n        [TheIntProperty] asc\r\n    )\r\n)", result);
        }
示例#25
0
        public void ReturnsCreateTableScript_WithClassWithDecimalProperty_AndSize(int precision, int scale, string expectedSize)
        {
            var result = CreateTable.Generate <TestCreateTableClassWithDecimalProperty>(new CreateTableOptions {
                DecimalPrecision = precision, DecimalScale = scale
            });

            Assert.Equal($"create table TestCreateTableClassWithDecimalProperty\r\n(\r\n    TheDecimalProperty decimal({expectedSize}) not null\r\n)", result);
        }
示例#26
0
        public void ReturnsCreateTableScript_WithClassWithStringProperty_PassedAsType_AndOptions()
        {
            var result = CreateTable.Generate(typeof(TestCreateTableClassWithStringProperty), new CreateTableOptions {
                SqlSyntaxIsUppercase = true
            });

            Assert.Equal("CREATE TABLE TestCreateTableClassWithStringProperty\r\n(\r\n    TheStringProperty VARCHAR(255) NULL\r\n)", result);
        }
示例#27
0
        public void ReturnsCreateTableScript_WithClassWithStringProperty_AndSize_AndUppercase()
        {
            var result = CreateTable.Generate <TestCreateTableClassWithStringProperty>(new CreateTableOptions {
                VarcharSize = 8001, SqlSyntaxIsUppercase = true
            });

            Assert.Equal("CREATE TABLE TestCreateTableClassWithStringProperty\r\n(\r\n    TheStringProperty VARCHAR(MAX) NULL\r\n)", result);
        }
示例#28
0
        public void ReturnsCreateTableScript_WithClassWithStringProperty_AndSize(int size, string expectedSize)
        {
            var result = CreateTable.Generate <TestCreateTableClassWithStringProperty>(new CreateTableOptions {
                VarcharSize = size
            });

            Assert.Equal($"create table TestCreateTableClassWithStringProperty\r\n(\r\n    TheStringProperty varchar({expectedSize}) null\r\n)", result);
        }
示例#29
0
        public void ReturnsCreateTableScript_WithClassWithStringProperty_AndTypeDelimiter_AndDefaultTypeSize()
        {
            var result = CreateTable.Generate <TestCreateTableClassWithStringProperty>(new CreateTableOptions {
                DelimitTypes = true
            });

            Assert.Equal("create table TestCreateTableClassWithStringProperty\r\n(\r\n    TheStringProperty [varchar](255) null\r\n)", result);
        }
示例#30
0
        public void ReturnsCreateTableScript_WithIdentifierDelimiter_AndTypeDelimiter()
        {
            var result = CreateTable.Generate <TestCreateTableClassWithIntProperty>(new CreateTableOptions {
                DelimitIdentifiers = true, DelimitTypes = true
            });

            Assert.Equal("create table TestCreateTableClassWithIntProperty\r\n(\r\n    [TheIntProperty] [int] not null\r\n)", result);
        }
        public void ReleaseShouldCreateCorrectScriptWithOnlyTableName()
        {
            var scopeResolver = A.Fake<IScopeResolver>();
            A.CallTo(() => scopeResolver.Write()).Returns(string.Empty);

            const string someTable = "someTable";
            var ct = new CreateTable(someTable, scopeResolver);
            string releaseScript = ct.GetReleaseSql();
            Assert.That(releaseScript, Is.EquivalentTo(String.Format("CREATE TABLE [{0}]", someTable)));
        }
示例#32
0
 public void CreateTbl()
 {
     CreateTable tempTable = new CreateTable();
     tempTable = tempTable.GetAttributeTable();
     netMySQL.CreateTable(tempTable.tableName,tempTable.attributeNames,tempTable.attributeTypes,tempTable.attributeLengths);
     tempTable = tempTable.GetProcessConstraintTable();
     netMySQL.CreateTable(tempTable.tableName,tempTable.attributeNames,tempTable.attributeTypes,tempTable.attributeLengths);
     netMySQL.SetPrimaryKey(tempTable.tableName,tempTable.attributeNames[tempTable.attributeNames.Count-1]);//"description");
     tempTable = tempTable.GetRelationTable();
     netMySQL.CreateTable(tempTable.tableName,tempTable.attributeNames,tempTable.attributeTypes,tempTable.attributeLengths);
 }
示例#33
0
 public string visit(CreateTable ddl)
 {
     Table table = ddl.Table;
     StringBuilder sb = new StringBuilder();
     string pattern = "\r\nCREATE TABLE {0} (\r\n{1}\r\n)";
     foreach (var column in table.Columns.Values)
     {
         sb.Append("\t");
     }
     return pattern;
 }
        public void ReleaseShouldCreateCorrectScriptWithTableNameAndScope()
        {
            const string someTable = "someTable";
            const string someSchema = "[someSchema].";

            var scopeResolver = A.Fake<IScopeResolver>();
            A.CallTo(() => scopeResolver.Write()).Returns(someSchema);

            var ct = new CreateTable(someTable, scopeResolver);
            string releaseScript = ct.GetReleaseSql();
            Assert.That(releaseScript, Is.EquivalentTo(String.Format("CREATE TABLE {1}[{0}]", someTable, someSchema)));
            A.CallTo(() => scopeResolver.Write()).MustHaveHappened(Repeated.Exactly.Once);
        }
示例#35
0
 public CreateTable GetProcessConstraintTable()
 {
     CreateTable tempTable = new CreateTable();
     tempTable.tableName = "processconstraint";
     tempTable.attributeNames = new List<string>();
     tempTable.attributeTypes = new List<string>();
     tempTable.attributeLengths = new List<int>();
     tempTable.attributeNames.Add("value");
     tempTable.attributeTypes.Add("varchar");
     tempTable.attributeLengths.Add(500);
     tempTable.attributeNames.Add("type");
     tempTable.attributeTypes.Add("varchar");
     tempTable.attributeLengths.Add(500);
     tempTable.attributeNames.Add("description");
     tempTable.attributeTypes.Add("varchar");
     tempTable.attributeLengths.Add(500);
     return tempTable;
 }
示例#36
0
 public CreateTable GetAttributeTable()
 {
     CreateTable tempTable = new CreateTable();
     tempTable.tableName = "attribute";
     tempTable.attributeNames = new List<string>();
     tempTable.attributeTypes = new List<string>();
     tempTable.attributeLengths = new List<int>();
     tempTable.attributeNames.Add("Nama Kelas");
     tempTable.attributeTypes.Add("varchar");
     tempTable.attributeLengths.Add(500);
     tempTable.attributeNames.Add("Atribut");
     tempTable.attributeTypes.Add("varchar");
     tempTable.attributeLengths.Add(500);
     tempTable.attributeNames.Add("Key");
     tempTable.attributeTypes.Add("varchar");
     tempTable.attributeLengths.Add(500);
     return tempTable;
 }
示例#37
0
 public CreateTable GetRelationTable()
 {
     CreateTable tempTable = new CreateTable();
     tempTable.tableName = "relation";
     tempTable.attributeNames = new List<string>();
     tempTable.attributeTypes = new List<string>();
     tempTable.attributeLengths = new List<int>();
     tempTable.attributeNames.Add("Nama Kelas");
     tempTable.attributeTypes.Add("varchar");
     tempTable.attributeLengths.Add(500);
     tempTable.attributeNames.Add("Relasi");
     tempTable.attributeTypes.Add("varchar");
     tempTable.attributeLengths.Add(500);
     tempTable.attributeNames.Add("Melalui");
     tempTable.attributeTypes.Add("varchar");
     tempTable.attributeLengths.Add(500);
     tempTable.attributeNames.Add("Atribut");
     tempTable.attributeTypes.Add("varchar");
     tempTable.attributeLengths.Add(500);
     //		tempTable.attributeNames.Add("Atribut Relasi");
     //		tempTable.attributeTypes.Add("varchar");
     //		tempTable.attributeLengths.Add(500);
     return tempTable;
 }
        public void Execute(IArray paramvalues, ITrackCancel trackcancel,
                            IGPEnvironmentManager envMgr, IGPMessages messages)
        {
            // Remember the original GP environment settings and temporarily override these settings

            var gpSettings = envMgr as IGeoProcessorSettings;
            bool origAddOutputsToMapSetting = gpSettings.AddOutputsToMap;
            bool origLogHistorySetting = gpSettings.LogHistory;
            gpSettings.AddOutputsToMap = false;
            gpSettings.LogHistory = false;

            // Create the Geoprocessor

            Geoprocessor gp = new Geoprocessor();

            try
            {
                // Validate our values

                IGPMessages validateMessages = ((IGPFunction2)this).Validate(paramvalues, false, envMgr);
                if ((validateMessages as IGPMessage).IsError())
                {
                    messages.AddError(1, "Validate failed");
                    return;
                }

                // Unpack values

                IGPParameter gpParam = paramvalues.get_Element(InputAETable) as IGPParameter;
                IGPValue inputAETableValue = m_gpUtils.UnpackGPValue(gpParam);
                gpParam = paramvalues.get_Element(InputAdminAreaFeatureClasses) as IGPParameter;
                var inputAdminAreaFeatureClassesMultiValue = m_gpUtils.UnpackGPValue(gpParam) as IGPMultiValue;
                gpParam = paramvalues.get_Element(OutputFileGDB) as IGPParameter;
                IGPValue outputFileGDBValue = m_gpUtils.UnpackGPValue(gpParam);
                gpParam = paramvalues.get_Element(InputTATable) as IGPParameter;
                IGPValue inputTATableValue = m_gpUtils.UnpackGPValue(gpParam);
                gpParam = paramvalues.get_Element(InputNWFeatureClass) as IGPParameter;
                IGPValue inputNWFeatureClassValue = m_gpUtils.UnpackGPValue(gpParam);
                gpParam = paramvalues.get_Element(InputTimeZoneIDBaseFieldName) as IGPParameter;
                IGPValue inputTimeZoneIDBaseFieldNameValue = m_gpUtils.UnpackGPValue(gpParam);

                if (inputTATableValue.IsEmpty() ^ inputNWFeatureClassValue.IsEmpty())
                {
                    messages.AddError(1, "The TA table and NW feature class must be specified together.");
                    return;
                }

                bool processStreetsFC = (!(inputNWFeatureClassValue.IsEmpty()));
                string timeZoneIDBaseFieldName = "";
                if (!(inputTimeZoneIDBaseFieldNameValue.IsEmpty()))
                    timeZoneIDBaseFieldName = inputTimeZoneIDBaseFieldNameValue.GetAsText();

                // Get the path to the output file GDB

                string outputFileGdbPath = outputFileGDBValue.GetAsText();

                // Create the new file geodatabase

                AddMessage("Creating the file geodatabase...", messages, trackcancel);

                int lastBackslash = outputFileGdbPath.LastIndexOf("\\");
                CreateFileGDB createFGDBTool = new CreateFileGDB();
                createFGDBTool.out_folder_path = outputFileGdbPath.Remove(lastBackslash);
                createFGDBTool.out_name = outputFileGdbPath.Substring(lastBackslash + 1);
                gp.Execute(createFGDBTool, trackcancel);

                // Copy the admin area feature classes

                int numAdminAreaFCs = inputAdminAreaFeatureClassesMultiValue.Count;
                string mergeToolInputs = "";
                for (int i = 0; i < numAdminAreaFCs; i++)
                {
                    AddMessage("Copying the Administrative Area feature classes (" + Convert.ToString(i+1) + " of " + Convert.ToString(numAdminAreaFCs) + ")...", messages, trackcancel);

                    string origAdminFCPath = inputAdminAreaFeatureClassesMultiValue.get_Value(i).GetAsText();
                    FeatureClassToFeatureClass importFCTool = new FeatureClassToFeatureClass();
                    importFCTool.in_features = origAdminFCPath;
                    importFCTool.out_path = outputFileGdbPath;
                    importFCTool.out_name = "Admin" + Convert.ToString(i, System.Globalization.CultureInfo.InvariantCulture);
                    importFCTool.field_mapping = "ID \"ID\" true true false 8 Double 0 0 ,First,#," + origAdminFCPath + ",ID,-1,-1;" +
                                                 "FEATTYP \"FEATTYP\" true true false 2 Short 0 0 ,First,#," + origAdminFCPath + ",FEATTYP,-1,-1;" +
                                                 "ORDER00 \"ORDER00\" true true false 3 Text 0 0 ,First,#," + origAdminFCPath + ",ORDER00,-1,-1;" +
                                                 "NAME \"NAME\" true true false 100 Text 0 0 ,First,#," + origAdminFCPath + ",NAME,-1,-1;" +
                                                 "NAMELC \"NAMELC\" true true false 3 Text 0 0 ,First,#," + origAdminFCPath + ",NAMELC,-1,-1";
                    gp.Execute(importFCTool, trackcancel);

                    mergeToolInputs = mergeToolInputs + outputFileGdbPath + "\\Admin" + Convert.ToString(i, System.Globalization.CultureInfo.InvariantCulture) + ";";
                }
                mergeToolInputs = mergeToolInputs.Remove(mergeToolInputs.Length - 1);

                // Merge the admin area feature classes together into one feature class

                AddMessage("Merging the Administrative Area feature classes...", messages, trackcancel);

                string adminFCPath = outputFileGdbPath + "\\AdminFC";

                Merge mergeTool = new Merge();
                mergeTool.inputs = mergeToolInputs;
                mergeTool.output = adminFCPath;
                gp.Execute(mergeTool, trackcancel);

                Delete deleteTool = null;
                for (int i = 0; i < numAdminAreaFCs; i++)
                {
                    deleteTool = new Delete();
                    deleteTool.in_data = outputFileGdbPath + "\\Admin" + Convert.ToString(i, System.Globalization.CultureInfo.InvariantCulture);
                    gp.Execute(deleteTool, trackcancel);
                }

                // Extract the time zone information and index it

                AddMessage("Extracting the time zone information...", messages, trackcancel);

                string tzTablePath = outputFileGdbPath + "\\TZ";
                TableSelect tableSelectTool = new TableSelect();
                tableSelectTool.in_table = inputAETableValue.GetAsText();
                tableSelectTool.out_table = tzTablePath;
                tableSelectTool.where_clause = "ATTTYP = 'TZ'";
                gp.Execute(tableSelectTool, trackcancel);

                AddIndex addIndexTool = new AddIndex();
                addIndexTool.in_table = tzTablePath;
                addIndexTool.fields = "ID";
                addIndexTool.index_name = "ID";
                gp.Execute(addIndexTool, trackcancel);

                // Add the UTCOffset field and calculate it

                AddField addFieldTool = new AddField();
                addFieldTool.in_table = adminFCPath;
                addFieldTool.field_name = "UTCOffset";
                addFieldTool.field_type = "SHORT";
                gp.Execute(addFieldTool, trackcancel);

                MakeFeatureLayer makeFeatureLayerTool = new MakeFeatureLayer();
                makeFeatureLayerTool.in_features = adminFCPath;
                makeFeatureLayerTool.out_layer = "AdminFC_Layer";
                gp.Execute(makeFeatureLayerTool, trackcancel);

                AddJoin addJoinTool = new AddJoin();
                addJoinTool.in_layer_or_view = "AdminFC_Layer";
                addJoinTool.in_field = "ID";
                addJoinTool.join_table = tzTablePath;
                addJoinTool.join_field = "ID";
                addJoinTool.join_type = "KEEP_COMMON";
                gp.Execute(addJoinTool, trackcancel);

                AddMessage("Calculating the UTCOffset information on the Administrative Area feature class...", messages, trackcancel);

                CalculateField calcFieldTool = new CalculateField();
                calcFieldTool.in_table = "AdminFC_Layer";
                calcFieldTool.field = "AdminFC.UTCOffset";
                calcFieldTool.code_block = "u = Null\ns = Trim([TZ.ATTVALUE])\nIf Not IsNull(s) Then\n" +
                                           "  sign = 1\n  If Left(s, 1) = \"-\" Then sign = -1\n" +
                                           "  u = sign * ( (60 * Abs(CInt(Mid(s, 1, Len(s) - 3)))) + CInt(Right(s, 2)) )\n" +
                                           "End If";
                calcFieldTool.expression = "u";
                calcFieldTool.expression_type = "VB";
                gp.Execute(calcFieldTool, trackcancel);

                RemoveJoin removeJoinTool = new RemoveJoin();
                removeJoinTool.in_layer_or_view = "AdminFC_Layer";
                removeJoinTool.join_name = "TZ";
                gp.Execute(removeJoinTool, trackcancel);

                deleteTool = new Delete();
                deleteTool.in_data = "AdminFC_Layer";
                gp.Execute(deleteTool, trackcancel);
                deleteTool = new Delete();
                deleteTool.in_data = tzTablePath;
                gp.Execute(deleteTool, trackcancel);

                // Extract out only the admin areas that have time zone information

                AddMessage("Extracting Administrative Areas with time zone information...", messages, trackcancel);

                string adminTZFCPath = outputFileGdbPath + "\\AdminFCwTZ";
                Select selectTool = new Select();
                selectTool.in_features = adminFCPath;
                selectTool.out_feature_class = adminTZFCPath;
                selectTool.where_clause = "NOT UTCOffset IS NULL";
                gp.Execute(selectTool, trackcancel);

                // Extract the daylight saving time information and index it

                AddMessage("Extracting the daylight saving time information...", messages, trackcancel);

                string suTablePath = outputFileGdbPath + "\\SU";
                tableSelectTool = new TableSelect();
                tableSelectTool.in_table = inputAETableValue.GetAsText();
                tableSelectTool.out_table = suTablePath;
                tableSelectTool.where_clause = "ATTTYP = 'SU'";
                gp.Execute(tableSelectTool, trackcancel);

                addIndexTool = new AddIndex();
                addIndexTool.in_table = suTablePath;
                addIndexTool.fields = "ID";
                addIndexTool.index_name = "ID";
                gp.Execute(addIndexTool, trackcancel);

                // Add the daylight saving field and calculate it

                addFieldTool = new AddField();
                addFieldTool.in_table = adminTZFCPath;
                addFieldTool.field_name = "DST";
                addFieldTool.field_type = "SHORT";
                gp.Execute(addFieldTool, trackcancel);

                makeFeatureLayerTool = new MakeFeatureLayer();
                makeFeatureLayerTool.in_features = adminTZFCPath;
                makeFeatureLayerTool.out_layer = "AdminFCwTZ_Layer";
                gp.Execute(makeFeatureLayerTool, trackcancel);

                addJoinTool = new AddJoin();
                addJoinTool.in_layer_or_view = "AdminFCwTZ_Layer";
                addJoinTool.in_field = "ID";
                addJoinTool.join_table = suTablePath;
                addJoinTool.join_field = "ID";
                addJoinTool.join_type = "KEEP_ALL";
                gp.Execute(addJoinTool, trackcancel);

                AddMessage("Copying the DST information to the Administrative Area feature class...", messages, trackcancel);

                calcFieldTool = new CalculateField();
                calcFieldTool.in_table = "AdminFCwTZ_Layer";
                calcFieldTool.field = "AdminFCwTZ.DST";
                calcFieldTool.code_block = "s = 0\nIf Not IsNull( [SU.ATTVALUE] ) Then s = CInt( [SU.ATTVALUE] )";
                calcFieldTool.expression = "s";
                calcFieldTool.expression_type = "VB";
                gp.Execute(calcFieldTool, trackcancel);

                removeJoinTool = new RemoveJoin();
                removeJoinTool.in_layer_or_view = "AdminFCwTZ_Layer";
                removeJoinTool.join_name = "SU";
                gp.Execute(removeJoinTool, trackcancel);

                deleteTool = new Delete();
                deleteTool.in_data = "AdminFCwTZ_Layer";
                gp.Execute(deleteTool, trackcancel);
                deleteTool = new Delete();
                deleteTool.in_data = suTablePath;
                gp.Execute(deleteTool, trackcancel);

                // Create and calculate the sortable MSTIMEZONE field

                addFieldTool = new AddField();
                addFieldTool.in_table = adminTZFCPath;
                addFieldTool.field_name = "SortableMSTIMEZONE";
                addFieldTool.field_type = "TEXT";
                addFieldTool.field_length = 60;
                gp.Execute(addFieldTool, trackcancel);

                AddMessage("Calculating the time zones...", messages, trackcancel);

                calcFieldTool = new CalculateField();
                calcFieldTool.in_table = adminTZFCPath;
                calcFieldTool.field = "SortableMSTIMEZONE";
                calcFieldTool.code_block = TimeZoneUtilities.MakeSortableMSTIMEZONECode("ORDER00");
                calcFieldTool.expression = "z";
                calcFieldTool.expression_type = "VB";
                gp.Execute(calcFieldTool, trackcancel);

                Rename renameTool = new Rename();
                renameTool.in_data = adminTZFCPath;
                renameTool.out_data = adminTZFCPath + "wNulls";
                gp.Execute(renameTool, trackcancel);

                selectTool = new Select();
                selectTool.in_features = adminTZFCPath + "wNulls";
                selectTool.out_feature_class = adminTZFCPath;
                selectTool.where_clause = "NOT SortableMSTIMEZONE IS NULL";
                gp.Execute(selectTool, trackcancel);

                deleteTool = new Delete();
                deleteTool.in_data = adminTZFCPath + "wNulls";
                gp.Execute(deleteTool, trackcancel);

                // Dissolve the time zone polygons together

                AddMessage("Dissolving the time zones...", messages, trackcancel);

                string timeZoneFCPath = outputFileGdbPath + "\\" + TimeZoneFCName;
                Dissolve dissolveTool = new Dissolve();
                dissolveTool.in_features = adminTZFCPath;
                dissolveTool.out_feature_class = timeZoneFCPath;
                dissolveTool.dissolve_field = "SortableMSTIMEZONE";
                dissolveTool.multi_part = "MULTI_PART";
                gp.Execute(dissolveTool, trackcancel);

                // Create and calculate the MSTIMEZONE field

                addFieldTool = new AddField();
                addFieldTool.in_table = timeZoneFCPath;
                addFieldTool.field_name = "MSTIMEZONE";
                addFieldTool.field_type = "TEXT";
                addFieldTool.field_length = 50;
                gp.Execute(addFieldTool, trackcancel);

                AddMessage("Calculating the time zones...", messages, trackcancel);

                calcFieldTool = new CalculateField();
                calcFieldTool.in_table = timeZoneFCPath;
                calcFieldTool.field = "MSTIMEZONE";
                calcFieldTool.expression = "Mid([SortableMSTIMEZONE], 7)";
                calcFieldTool.expression_type = "VB";
                gp.Execute(calcFieldTool, trackcancel);

                // Delete the old sortable MSTIMEZONE field

                DeleteField deleteFieldTool = new DeleteField();
                deleteFieldTool.in_table = timeZoneFCPath;
                deleteFieldTool.drop_field = "SortableMSTIMEZONE";
                gp.Execute(deleteFieldTool, trackcancel);

                if (processStreetsFC)
                {
                    // Create the network dataset time zone table

                    AddMessage("Creating the time zones table...", messages, trackcancel);

                    TableToTable importTableTool = new TableToTable();
                    importTableTool.in_rows = timeZoneFCPath;
                    importTableTool.out_path = outputFileGdbPath;
                    importTableTool.out_name = TimeZonesTableName;
                    importTableTool.field_mapping = "MSTIMEZONE \"MSTIMEZONE\" true true false 50 Text 0 0 ,First,#," +
                                                    timeZoneFCPath + ",MSTIMEZONE,-1,-1";
                    gp.Execute(importTableTool, trackcancel);

                    // Import the NW feature class to the file geodatabase

                    AddMessage("Copying the NW feature class to the geodatabase...", messages, trackcancel);

                    FeatureClassToFeatureClass importFCTool = new FeatureClassToFeatureClass();
                    importFCTool.in_features = inputNWFeatureClassValue.GetAsText();
                    importFCTool.out_path = outputFileGdbPath;
                    importFCTool.out_name = "nw";
                    gp.Execute(importFCTool, trackcancel);

                    string pathToLocalNW = outputFileGdbPath + "\\nw";

                    // Create Join polygon feature class

                    AddMessage("Creating the join polygon feature class...", messages, trackcancel);

                    string joinPolygonFCPath = outputFileGdbPath + "\\JoinPolygonFC";

                    MultipartToSinglepart multipartToSinglepartTool = new MultipartToSinglepart();
                    multipartToSinglepartTool.in_features = timeZoneFCPath;
                    multipartToSinglepartTool.out_feature_class = joinPolygonFCPath;
                    gp.Execute(multipartToSinglepartTool, trackcancel);

                    // Add and calculate the time zone ID fields to the join polygons

                    addFieldTool = new AddField();
                    addFieldTool.in_table = joinPolygonFCPath;
                    addFieldTool.field_type = "SHORT";
                    addFieldTool.field_name = "FT_" + timeZoneIDBaseFieldName;
                    gp.Execute(addFieldTool, trackcancel);
                    addFieldTool.field_name = "TF_" + timeZoneIDBaseFieldName;
                    gp.Execute(addFieldTool, trackcancel);

                    AddMessage("Calculating the FT_" + timeZoneIDBaseFieldName + " field...", messages, trackcancel);

                    calcFieldTool = new CalculateField();
                    calcFieldTool.in_table = joinPolygonFCPath;
                    calcFieldTool.field = "FT_" + timeZoneIDBaseFieldName;
                    calcFieldTool.expression = "[ORIG_FID]";
                    calcFieldTool.expression_type = "VB";
                    gp.Execute(calcFieldTool, trackcancel);

                    AddMessage("Calculating the TF_" + timeZoneIDBaseFieldName + " field...", messages, trackcancel);

                    calcFieldTool = new CalculateField();
                    calcFieldTool.in_table = joinPolygonFCPath;
                    calcFieldTool.field = "TF_" + timeZoneIDBaseFieldName;
                    calcFieldTool.expression = "[ORIG_FID]";
                    calcFieldTool.expression_type = "VB";
                    gp.Execute(calcFieldTool, trackcancel);

                    // Delete the MSTIMEZONE and ORIG_FID fields from the join polygon FC

                    deleteFieldTool = new DeleteField();
                    deleteFieldTool.in_table = joinPolygonFCPath;
                    deleteFieldTool.drop_field = "MSTIMEZONE;ORIG_FID";
                    gp.Execute(deleteFieldTool, trackcancel);

                    // Perform a spatial join between the Streets and the join polygons

                    AddMessage("Creating Streets feature class with time zone ID fields...", messages, trackcancel);

                    string outputStreetsFCPath = outputFileGdbPath + "\\" + StreetsFCName;
                    SpatialJoin spatialJoinTool = new SpatialJoin();
                    spatialJoinTool.target_features = pathToLocalNW;
                    spatialJoinTool.join_features = joinPolygonFCPath;
                    spatialJoinTool.out_feature_class = outputStreetsFCPath;
                    spatialJoinTool.match_option = "IS_WITHIN";
                    gp.Execute(spatialJoinTool, trackcancel);

                    // Delete the extraneous fields

                    deleteFieldTool = new DeleteField();
                    deleteFieldTool.in_table = outputStreetsFCPath;
                    deleteFieldTool.drop_field = "Join_Count;TARGET_FID;Shape_Length_1";
                    gp.Execute(deleteFieldTool, trackcancel);

                    // Delete the temporary NW and Join feature classes

                    deleteTool = new Delete();
                    deleteTool.in_data = pathToLocalNW;
                    gp.Execute(deleteTool, trackcancel);
                    deleteTool = new Delete();
                    deleteTool.in_data = joinPolygonFCPath;
                    gp.Execute(deleteTool, trackcancel);

                    // Extract the drive side information and index it

                    AddMessage("Extracting the drive side information...", messages, trackcancel);

                    string driveSideTablePath = outputFileGdbPath + "\\DriveSide";
                    tableSelectTool = new TableSelect();
                    tableSelectTool.in_table = inputAETableValue.GetAsText();
                    tableSelectTool.out_table = driveSideTablePath;
                    tableSelectTool.where_clause = "ATTTYP = '3D'";
                    gp.Execute(tableSelectTool, trackcancel);

                    addIndexTool = new AddIndex();
                    addIndexTool.in_table = driveSideTablePath;
                    addIndexTool.fields = "ID";
                    addIndexTool.index_name = "ID";
                    gp.Execute(addIndexTool, trackcancel);

                    // Add the DriveSide field and calculate it

                    addFieldTool = new AddField();
                    addFieldTool.in_table = adminFCPath;
                    addFieldTool.field_name = "DriveSide";
                    addFieldTool.field_type = "SHORT";
                    gp.Execute(addFieldTool, trackcancel);

                    makeFeatureLayerTool = new MakeFeatureLayer();
                    makeFeatureLayerTool.in_features = adminFCPath;
                    makeFeatureLayerTool.out_layer = "AdminFC_Layer";
                    gp.Execute(makeFeatureLayerTool, trackcancel);

                    addJoinTool = new AddJoin();
                    addJoinTool.in_layer_or_view = "AdminFC_Layer";
                    addJoinTool.in_field = "ID";
                    addJoinTool.join_table = driveSideTablePath;
                    addJoinTool.join_field = "ID";
                    addJoinTool.join_type = "KEEP_COMMON";
                    gp.Execute(addJoinTool, trackcancel);

                    AddMessage("Copying the drive side information to the Administrative Area feature class...", messages, trackcancel);

                    calcFieldTool = new CalculateField();
                    calcFieldTool.in_table = "AdminFC_Layer";
                    calcFieldTool.field = "AdminFC.DriveSide";
                    calcFieldTool.expression = "CInt( [DriveSide.ATTVALUE] )";
                    calcFieldTool.expression_type = "VB";
                    gp.Execute(calcFieldTool, trackcancel);

                    removeJoinTool = new RemoveJoin();
                    removeJoinTool.in_layer_or_view = "AdminFC_Layer";
                    removeJoinTool.join_name = "DriveSide";
                    gp.Execute(removeJoinTool, trackcancel);

                    deleteTool = new Delete();
                    deleteTool.in_data = "AdminFC_Layer";
                    gp.Execute(deleteTool, trackcancel);
                    deleteTool = new Delete();
                    deleteTool.in_data = driveSideTablePath;
                    gp.Execute(deleteTool, trackcancel);

                    // Extract out only the admin areas that have drive side information and index the ORDER00 field

                    AddMessage("Extracting Administrative Areas with drive side information...", messages, trackcancel);

                    string adminFCwDriveSidePath = outputFileGdbPath + "\\AdminFCwDriveSide";
                    selectTool = new Select();
                    selectTool.in_features = adminFCPath;
                    selectTool.out_feature_class = adminFCwDriveSidePath;
                    selectTool.where_clause = "NOT DriveSide IS NULL";
                    gp.Execute(selectTool, trackcancel);

                    addIndexTool = new AddIndex();
                    addIndexTool.in_table = adminFCwDriveSidePath;
                    addIndexTool.fields = "ORDER00";
                    addIndexTool.index_name = "ORDER00";
                    gp.Execute(addIndexTool, trackcancel);

                    // Add the DriveSide field to the AdminFCwTZ feature class and calculate it.

                    addFieldTool = new AddField();
                    addFieldTool.in_table = adminTZFCPath;
                    addFieldTool.field_name = "DriveSide";
                    addFieldTool.field_type = "SHORT";
                    gp.Execute(addFieldTool, trackcancel);

                    makeFeatureLayerTool = new MakeFeatureLayer();
                    makeFeatureLayerTool.in_features = adminTZFCPath;
                    makeFeatureLayerTool.out_layer = "AdminFCwTZ_Layer";
                    gp.Execute(makeFeatureLayerTool, trackcancel);

                    addJoinTool = new AddJoin();
                    addJoinTool.in_layer_or_view = "AdminFCwTZ_Layer";
                    addJoinTool.in_field = "ORDER00";
                    addJoinTool.join_table = adminFCwDriveSidePath;
                    addJoinTool.join_field = "ORDER00";
                    addJoinTool.join_type = "KEEP_COMMON";
                    gp.Execute(addJoinTool, trackcancel);

                    AddMessage("Calculating the DriveSide field on the AdminFCwTZ feature class...", messages, trackcancel);

                    calcFieldTool = new CalculateField();
                    calcFieldTool.in_table = "AdminFCwTZ_Layer";
                    calcFieldTool.field = "AdminFCwTZ.DriveSide";
                    calcFieldTool.expression = "[AdminFCwDriveSide.DriveSide]";
                    calcFieldTool.expression_type = "VB";
                    gp.Execute(calcFieldTool, trackcancel);

                    removeJoinTool = new RemoveJoin();
                    removeJoinTool.in_layer_or_view = "AdminFCwTZ_Layer";
                    removeJoinTool.join_name = "AdminFCwDriveSide";
                    gp.Execute(removeJoinTool, trackcancel);

                    deleteTool = new Delete();
                    deleteTool.in_data = "AdminFCwTZ_Layer";
                    gp.Execute(deleteTool, trackcancel);

                    deleteTool = new Delete();
                    deleteTool.in_data = adminFCwDriveSidePath;
                    gp.Execute(deleteTool, trackcancel);

                    // Extract the information for boundary roads

                    AddMessage("Extracting the information for boundary roads...", messages, trackcancel);

                    string taTablePath = outputFileGdbPath + "\\TA";
                    tableSelectTool = new TableSelect();
                    tableSelectTool.in_table = inputTATableValue.GetAsText();
                    tableSelectTool.out_table = taTablePath;
                    tableSelectTool.where_clause = "ARETYP <= 1120 AND SOL > 0";
                    gp.Execute(tableSelectTool, trackcancel);

                    // Join the boundary road information with the AdminFCwTZ feature class to
                    // create the FT_BoundaryTimeZones and TF_BoundaryTimeZones join tables

                    addIndexTool = new AddIndex();
                    addIndexTool.in_table = adminTZFCPath;
                    addIndexTool.fields = "ID";
                    addIndexTool.index_name = "ID";
                    gp.Execute(addIndexTool, trackcancel);

                    MakeTableView makeTableViewTool = new MakeTableView();
                    makeTableViewTool.in_table = taTablePath;
                    makeTableViewTool.out_view = "TA_View";
                    gp.Execute(makeTableViewTool, trackcancel);

                    addJoinTool = new AddJoin();
                    addJoinTool.in_layer_or_view = "TA_View";
                    addJoinTool.in_field = "AREID";
                    addJoinTool.join_table = adminTZFCPath;
                    addJoinTool.join_field = "ID";
                    addJoinTool.join_type = "KEEP_COMMON";
                    gp.Execute(addJoinTool, trackcancel);

                    AddMessage("Extracting the boundary FT time zones...", messages, trackcancel);

                    importTableTool = new TableToTable();
                    importTableTool.in_rows = "TA_View";
                    importTableTool.out_path = outputFileGdbPath;
                    importTableTool.out_name = "FT_BoundaryTimeZones";
                    importTableTool.where_clause = "TA.SOL = AdminFCwTZ.DriveSide";
                    importTableTool.field_mapping = "ID \"ID\" true true false 8 Double 0 0 ,First,#," + taTablePath + ",TA.ID,-1,-1;" +
                                                    "SortableMSTIMEZONE \"SortableMSTIMEZONE\" true true false 60 Text 0 0 ,First,#," +
                                                    adminTZFCPath + ",AdminFCwTZ.SortableMSTIMEZONE,-1,-1";
                    gp.Execute(importTableTool, trackcancel);

                    string ftBoundaryTimeZonesPath = outputFileGdbPath + "\\FT_BoundaryTimeZones";

                    addIndexTool = new AddIndex();
                    addIndexTool.in_table = ftBoundaryTimeZonesPath;
                    addIndexTool.fields = "ID";
                    addIndexTool.index_name = "ID";
                    gp.Execute(addIndexTool, trackcancel);

                    AddMessage("Extracting the boundary TF time zones...", messages, trackcancel);

                    importTableTool = new TableToTable();
                    importTableTool.in_rows = "TA_View";
                    importTableTool.out_path = outputFileGdbPath;
                    importTableTool.out_name = "TF_BoundaryTimeZones";
                    importTableTool.where_clause = "TA.SOL <> AdminFCwTZ.DriveSide";
                    importTableTool.field_mapping = "ID \"ID\" true true false 8 Double 0 0 ,First,#," + taTablePath + ",TA.ID,-1,-1;" +
                                                    "SortableMSTIMEZONE \"SortableMSTIMEZONE\" true true false 60 Text 0 0 ,First,#," +
                                                    adminTZFCPath + ",AdminFCwTZ.SortableMSTIMEZONE,-1,-1";
                    gp.Execute(importTableTool, trackcancel);

                    string tfBoundaryTimeZonesPath = outputFileGdbPath + "\\TF_BoundaryTimeZones";

                    addIndexTool = new AddIndex();
                    addIndexTool.in_table = tfBoundaryTimeZonesPath;
                    addIndexTool.fields = "ID";
                    addIndexTool.index_name = "ID";
                    gp.Execute(addIndexTool, trackcancel);

                    removeJoinTool = new RemoveJoin();
                    removeJoinTool.in_layer_or_view = "TA_View";
                    removeJoinTool.join_name = "AdminFCwTZ";
                    gp.Execute(removeJoinTool, trackcancel);

                    deleteTool = new Delete();
                    deleteTool.in_data = "TA_View";
                    gp.Execute(deleteTool, trackcancel);
                    deleteTool.in_data = taTablePath;
                    gp.Execute(deleteTool, trackcancel);

                    // Calculate the boundary time zone ID values

                    makeFeatureLayerTool = new MakeFeatureLayer();
                    makeFeatureLayerTool.in_features = outputStreetsFCPath;
                    makeFeatureLayerTool.out_layer = "Streets_Layer";
                    gp.Execute(makeFeatureLayerTool, trackcancel);

                    addJoinTool = new AddJoin();
                    addJoinTool.in_layer_or_view = "Streets_Layer";
                    addJoinTool.in_field = "ID";
                    addJoinTool.join_table = ftBoundaryTimeZonesPath;
                    addJoinTool.join_field = "ID";
                    addJoinTool.join_type = "KEEP_COMMON";
                    gp.Execute(addJoinTool, trackcancel);

                    AddMessage("Calculating the boundary FT time zones...", messages, trackcancel);

                    calcFieldTool = new CalculateField();
                    calcFieldTool.in_table = "Streets_Layer";
                    calcFieldTool.field = StreetsFCName + ".FT_" + timeZoneIDBaseFieldName;
                    calcFieldTool.code_block = TimeZoneUtilities.MakeTimeZoneIDCode(outputFileGdbPath, TimeZonesTableName, "FT_BoundaryTimeZones.SortableMSTIMEZONE");
                    calcFieldTool.expression = "tzID";
                    calcFieldTool.expression_type = "VB";
                    gp.Execute(calcFieldTool, trackcancel);

                    removeJoinTool = new RemoveJoin();
                    removeJoinTool.in_layer_or_view = "Streets_Layer";
                    removeJoinTool.join_name = "FT_BoundaryTimeZones";
                    gp.Execute(removeJoinTool, trackcancel);

                    addJoinTool = new AddJoin();
                    addJoinTool.in_layer_or_view = "Streets_Layer";
                    addJoinTool.in_field = "ID";
                    addJoinTool.join_table = tfBoundaryTimeZonesPath;
                    addJoinTool.join_field = "ID";
                    addJoinTool.join_type = "KEEP_COMMON";
                    gp.Execute(addJoinTool, trackcancel);

                    AddMessage("Calculating the boundary TF time zones...", messages, trackcancel);

                    calcFieldTool = new CalculateField();
                    calcFieldTool.in_table = "Streets_Layer";
                    calcFieldTool.field = StreetsFCName + ".TF_" + timeZoneIDBaseFieldName;
                    calcFieldTool.code_block = TimeZoneUtilities.MakeTimeZoneIDCode(outputFileGdbPath, TimeZonesTableName, "TF_BoundaryTimeZones.SortableMSTIMEZONE");
                    calcFieldTool.expression = "tzID";
                    calcFieldTool.expression_type = "VB";
                    gp.Execute(calcFieldTool, trackcancel);

                    removeJoinTool = new RemoveJoin();
                    removeJoinTool.in_layer_or_view = "Streets_Layer";
                    removeJoinTool.join_name = "TF_BoundaryTimeZones";
                    gp.Execute(removeJoinTool, trackcancel);

                    deleteTool = new Delete();
                    deleteTool.in_data = "Streets_Layer";
                    gp.Execute(deleteTool, trackcancel);

                    deleteTool = new Delete();
                    deleteTool.in_data = ftBoundaryTimeZonesPath;
                    gp.Execute(deleteTool, trackcancel);
                    deleteTool.in_data = tfBoundaryTimeZonesPath;
                    gp.Execute(deleteTool, trackcancel);
                }
                else
                {
                    // Create a dummy TimeZones table and a dummy Streets feature class

                    CreateTable createTableTool = new CreateTable();
                    createTableTool.out_path = outputFileGdbPath;
                    createTableTool.out_name = TimeZonesTableName;
                    gp.Execute(createTableTool, trackcancel);

                    CreateFeatureclass createFCTool = new CreateFeatureclass();
                    createFCTool.out_path = outputFileGdbPath;
                    createFCTool.out_name = StreetsFCName;
                    createFCTool.geometry_type = "POLYLINE";
                    gp.Execute(createFCTool, trackcancel);
                }

                deleteTool = new Delete();
                deleteTool.in_data = adminFCPath;
                gp.Execute(deleteTool, trackcancel);

                deleteTool = new Delete();
                deleteTool.in_data = adminTZFCPath;
                gp.Execute(deleteTool, trackcancel);

                // Compact the output file geodatabase

                AddMessage("Compacting the output file geodatabase...", messages, trackcancel);

                Compact compactTool = new Compact();
                compactTool.in_workspace = outputFileGdbPath;
                gp.Execute(compactTool, trackcancel);
            }
            catch (Exception e)
            {
                if (gp.MaxSeverity == 2)
                {
                    object missing = System.Type.Missing;
                    messages.AddError(1, gp.GetMessages(ref missing));
                }
                messages.AddError(1, e.Message);
                messages.AddError(1, e.StackTrace);
            }
            finally
            {
                // Restore the original GP environment settings

                gpSettings.AddOutputsToMap = origAddOutputsToMapSetting;
                gpSettings.LogHistory = origLogHistorySetting;
            }
            GC.Collect();
            return;
        }
        public void Execute(IArray paramvalues, ITrackCancel trackcancel,
                            IGPEnvironmentManager envMgr, IGPMessages messages)
        {
            // Remember the original GP environment settings and temporarily override these settings

            var gpSettings = envMgr as IGeoProcessorSettings;
            bool origAddOutputsToMapSetting = gpSettings.AddOutputsToMap;
            bool origLogHistorySetting = gpSettings.LogHistory;
            gpSettings.AddOutputsToMap = false;
            gpSettings.LogHistory = false;

            // Create the Geoprocessor

            Geoprocessor gp = new Geoprocessor();

            try
            {
                // Validate our values

                IGPMessages validateMessages = ((IGPFunction2)this).Validate(paramvalues, false, envMgr);
                if ((validateMessages as IGPMessage).IsError())
                {
                    messages.AddError(1, "Validate failed");
                    return;
                }

                // Unpack values

                IGPParameter gpParam = paramvalues.get_Element(InputMtdDSTTable) as IGPParameter;
                IGPValue inputMtdDSTTableValue = m_gpUtils.UnpackGPValue(gpParam);
                gpParam = paramvalues.get_Element(InputMtdCntryRefTable) as IGPParameter;
                IGPValue inputMtdCntryRefTableValue = m_gpUtils.UnpackGPValue(gpParam);
                gpParam = paramvalues.get_Element(InputMtdAreaTable) as IGPParameter;
                IGPValue inputMtdAreaTableValue = m_gpUtils.UnpackGPValue(gpParam);
                gpParam = paramvalues.get_Element(InputAdminBndyFeatureClasses) as IGPParameter;
                var inputAdminBndyFeatureClassesMultiValue = m_gpUtils.UnpackGPValue(gpParam) as IGPMultiValue;
                gpParam = paramvalues.get_Element(OutputFileGDB) as IGPParameter;
                IGPValue outputFileGDBValue = m_gpUtils.UnpackGPValue(gpParam);
                gpParam = paramvalues.get_Element(InputStreetsFeatureClass) as IGPParameter;
                IGPValue inputStreetsFeatureClassValue = m_gpUtils.UnpackGPValue(gpParam);
                gpParam = paramvalues.get_Element(InputTimeZoneIDBaseFieldName) as IGPParameter;
                IGPValue inputTimeZoneIDBaseFieldNameValue = m_gpUtils.UnpackGPValue(gpParam);

                bool processStreetsFC = (!(inputStreetsFeatureClassValue.IsEmpty()));
                string timeZoneIDBaseFieldName = "";
                if (!(inputTimeZoneIDBaseFieldNameValue.IsEmpty()))
                    timeZoneIDBaseFieldName = inputTimeZoneIDBaseFieldNameValue.GetAsText();

                // Get the path to the output file GDB

                string outputFileGdbPath = outputFileGDBValue.GetAsText();

                // Create the new file geodatabase

                AddMessage("Creating the file geodatabase...", messages, trackcancel);

                int lastBackslash = outputFileGdbPath.LastIndexOf("\\");
                CreateFileGDB createFGDBTool = new CreateFileGDB();
                createFGDBTool.out_folder_path = outputFileGdbPath.Remove(lastBackslash);
                createFGDBTool.out_name = outputFileGdbPath.Substring(lastBackslash + 1);
                gp.Execute(createFGDBTool, trackcancel);

                // Copy the MtdDST table to the file geodatabase and add the ADMIN_LVL and AREACODE fields to it

                AddMessage("Copying the MtdDST table to the file geodatabase...", messages, trackcancel);

                TableToTable importTableTool = new TableToTable();
                string inputMtdDSTTablePath = inputMtdDSTTableValue.GetAsText();
                importTableTool.in_rows = inputMtdDSTTablePath;
                importTableTool.out_path = outputFileGdbPath;
                importTableTool.out_name = "MtdDST";
                importTableTool.field_mapping = "AREA_ID \"AREA_ID\" true true false 4 Long 0 0 ,First,#," + inputMtdDSTTablePath + ",AREA_ID,-1,-1;" +
                                                "TIME_ZONE \"TIME_ZONE\" true true false 4 Text 0 0 ,First,#," + inputMtdDSTTablePath + ",TIME_ZONE,-1,-1;" +
                                                "DST_EXIST \"DST_EXIST\" true true false 1 Text 0 0 ,First,#," + inputMtdDSTTablePath + ",DST_EXIST,-1,-1";
                gp.Execute(importTableTool, trackcancel);

                string mtdDSTTablePath = outputFileGdbPath + "\\MtdDST";

                AddField addFieldTool = new AddField();
                addFieldTool.in_table = mtdDSTTablePath;
                addFieldTool.field_name = "ADMIN_LVL";
                addFieldTool.field_type = "SHORT";
                gp.Execute(addFieldTool, trackcancel);

                addFieldTool = new AddField();
                addFieldTool.in_table = mtdDSTTablePath;
                addFieldTool.field_name = "AREACODE";
                addFieldTool.field_type = "TEXT";
                addFieldTool.field_length = 76;
                gp.Execute(addFieldTool, trackcancel);

                // Copy the MtdArea table to the file geodatabase and index the AREA_ID field

                AddMessage("Copying the MtdArea table to the file geodatabase...", messages, trackcancel);

                importTableTool = new TableToTable();
                importTableTool.in_rows = inputMtdAreaTableValue.GetAsText();
                importTableTool.out_path = outputFileGdbPath;
                importTableTool.out_name = "MtdArea";
                gp.Execute(importTableTool, trackcancel);

                string mtdAreaTablePath = outputFileGdbPath + "\\MtdArea";

                AddIndex addIndexTool = new AddIndex();
                addIndexTool.in_table = mtdAreaTablePath;
                addIndexTool.fields = "AREA_ID";
                addIndexTool.index_name = "AREA_ID";
                gp.Execute(addIndexTool, trackcancel);

                // Calculate the ADMIN_LVL and AREACODE fields on the MtdDST table

                MakeTableView makeTableViewTool = new MakeTableView();
                makeTableViewTool.in_table = mtdDSTTablePath;
                makeTableViewTool.out_view = "MtdDST_Layer";
                gp.Execute(makeTableViewTool, trackcancel);

                AddJoin addJoinTool = new AddJoin();
                addJoinTool.in_layer_or_view = "MtdDST_Layer";
                addJoinTool.in_field = "AREA_ID";
                addJoinTool.join_table = mtdAreaTablePath;
                addJoinTool.join_field = "AREA_ID";
                addJoinTool.join_type = "KEEP_COMMON";
                gp.Execute(addJoinTool, trackcancel);

                AddMessage("Calculating the ADMIN_LVL field...", messages, trackcancel);

                CalculateField calcFieldTool = new CalculateField();
                calcFieldTool.in_table = "MtdDST_Layer";
                calcFieldTool.field = "MtdDST.ADMIN_LVL";
                calcFieldTool.expression = "[MtdArea.ADMIN_LVL]";
                calcFieldTool.expression_type = "VB";
                gp.Execute(calcFieldTool, trackcancel);

                AddMessage("Calculating the AREACODE field...", messages, trackcancel);

                calcFieldTool = new CalculateField();
                calcFieldTool.in_table = "MtdDST_Layer";
                calcFieldTool.field = "MtdDST.AREACODE";
                calcFieldTool.code_block = "lvl = [MtdArea.ADMIN_LVL]\n" +
                                           "s = CStr([MtdArea.AREACODE_1])\n" +
                                           "If lvl >= 2 Then s = s & \".\" & CStr([MtdArea.AREACODE_2])\n" +
                                           "If lvl >= 3 Then s = s & \".\" & CStr([MtdArea.AREACODE_3])\n" +
                                           "If lvl >= 4 Then s = s & \".\" & CStr([MtdArea.AREACODE_4])\n" +
                                           "If lvl >= 5 Then s = s & \".\" & CStr([MtdArea.AREACODE_5])\n" +
                                           "If lvl >= 6 Then s = s & \".\" & CStr([MtdArea.AREACODE_6])\n" +
                                           "If lvl >= 7 Then s = s & \".\" & CStr([MtdArea.AREACODE_7])";
                calcFieldTool.expression = "s";
                calcFieldTool.expression_type = "VB";
                gp.Execute(calcFieldTool, trackcancel);

                RemoveJoin removeJoinTool = new RemoveJoin();
                removeJoinTool.in_layer_or_view = "MtdDST_Layer";
                removeJoinTool.join_name = "MtdArea";
                gp.Execute(removeJoinTool, trackcancel);

                Delete deleteTool = new Delete();
                deleteTool.in_data = "MtdDST_Layer";
                gp.Execute(deleteTool, trackcancel);

                // Create the MtdDST# tables by admin levels and index the AREACODE field

                TableSelect tableSelectTool = null;
                for (int i = 1; i <= 7; i++)
                {
                    string iAsString = Convert.ToString(i, System.Globalization.CultureInfo.InvariantCulture);

                    AddMessage("Extracting level " + iAsString + " MtdDST rows...", messages, trackcancel);

                    tableSelectTool = new TableSelect();
                    tableSelectTool.in_table = mtdDSTTablePath;
                    tableSelectTool.out_table = mtdDSTTablePath + iAsString;
                    tableSelectTool.where_clause = "ADMIN_LVL = " + iAsString;
                    gp.Execute(tableSelectTool, trackcancel);

                    addIndexTool = new AddIndex();
                    addIndexTool.in_table = mtdDSTTablePath + iAsString;
                    addIndexTool.fields = "AREACODE";
                    addIndexTool.index_name = "AREACODE";
                    gp.Execute(addIndexTool, trackcancel);
                }

                deleteTool = new Delete();
                deleteTool.in_data = mtdDSTTablePath;
                gp.Execute(deleteTool, trackcancel);

                // Copy the MtdCntryRef table to the file geodatabase (use Statistics tool to remove duplicate rows)

                AddMessage("Copying the MtdCntryRef table to the file geodatabase...", messages, trackcancel);

                string inputMtdCntryRefTablePath = inputMtdCntryRefTableValue.GetAsText();
                string mtdCntryRefTablePath = outputFileGdbPath + "\\MtdCntryRef";
                Statistics statsTool = new Statistics();
                statsTool.in_table = inputMtdCntryRefTablePath;
                statsTool.out_table = mtdCntryRefTablePath;
                statsTool.statistics_fields = "ISO_CODE COUNT";
                statsTool.case_field = "GOVT_CODE;ISO_CODE;DRIVING_SD;ADMINLEVEL";
                gp.Execute(statsTool, trackcancel);

                DeleteField deleteFieldTool = new DeleteField();
                deleteFieldTool.in_table = mtdCntryRefTablePath;
                deleteFieldTool.drop_field = "FREQUENCY;COUNT_ISO_CODE";
                gp.Execute(deleteFieldTool, trackcancel);

                // Index the GOVT_CODE field

                addIndexTool = new AddIndex();
                addIndexTool.in_table = mtdCntryRefTablePath;
                addIndexTool.fields = "GOVT_CODE";
                addIndexTool.index_name = "GOVT_CODE";
                gp.Execute(addIndexTool, trackcancel);

                // Extract the top level (country) records from the MtdArea table and index the AREACODE_1 field

                AddMessage("Extracting the top-level rows from the MtdArea table...", messages, trackcancel);

                string mtdTopAreaTablePath = outputFileGdbPath + "\\TopArea";

                tableSelectTool = new TableSelect();
                tableSelectTool.in_table = mtdAreaTablePath;
                tableSelectTool.out_table = mtdTopAreaTablePath;
                tableSelectTool.where_clause = "AREACODE_2 = 0 AND AREA_TYPE = 'B'";
                gp.Execute(tableSelectTool, trackcancel);

                addIndexTool = new AddIndex();
                addIndexTool.in_table = mtdTopAreaTablePath;
                addIndexTool.fields = "AREACODE_1";
                addIndexTool.index_name = "AREACODE_1";
                gp.Execute(addIndexTool, trackcancel);

                // Create and calculate the TOP_GOVT_CODE field on the MtdArea table

                addFieldTool = new AddField();
                addFieldTool.in_table = mtdAreaTablePath;
                addFieldTool.field_name = "TOP_GOVT_CODE";
                addFieldTool.field_type = "LONG";
                gp.Execute(addFieldTool, trackcancel);

                makeTableViewTool = new MakeTableView();
                makeTableViewTool.in_table = mtdAreaTablePath;
                makeTableViewTool.out_view = "MtdArea_Layer";
                gp.Execute(makeTableViewTool, trackcancel);

                addJoinTool = new AddJoin();
                addJoinTool.in_layer_or_view = "MtdArea_Layer";
                addJoinTool.in_field = "AREACODE_1";
                addJoinTool.join_table = mtdTopAreaTablePath;
                addJoinTool.join_field = "AREACODE_1";
                addJoinTool.join_type = "KEEP_COMMON";
                gp.Execute(addJoinTool, trackcancel);

                AddMessage("Calculating the TOP_GOVT_CODE field...", messages, trackcancel);

                calcFieldTool = new CalculateField();
                calcFieldTool.in_table = "MtdArea_Layer";
                calcFieldTool.field = "MtdArea.TOP_GOVT_CODE";
                calcFieldTool.expression = "[TopArea.GOVT_CODE]";
                calcFieldTool.expression_type = "VB";
                gp.Execute(calcFieldTool, trackcancel);

                removeJoinTool = new RemoveJoin();
                removeJoinTool.in_layer_or_view = "MtdArea_Layer";
                removeJoinTool.join_name = "TopArea";
                gp.Execute(removeJoinTool, trackcancel);

                deleteTool = new Delete();
                deleteTool.in_data = mtdTopAreaTablePath;
                gp.Execute(deleteTool, trackcancel);

                // Create and calculate the ISO_CODE and DRIVING_SD string fields

                addFieldTool = new AddField();
                addFieldTool.in_table = mtdAreaTablePath;
                addFieldTool.field_name = "ISO_CODE";
                addFieldTool.field_type = "TEXT";
                addFieldTool.field_length = 3;
                gp.Execute(addFieldTool, trackcancel);

                addFieldTool = new AddField();
                addFieldTool.in_table = mtdAreaTablePath;
                addFieldTool.field_name = "DRIVING_SD";
                addFieldTool.field_type = "TEXT";
                addFieldTool.field_length = 1;
                gp.Execute(addFieldTool, trackcancel);

                addJoinTool = new AddJoin();
                addJoinTool.in_layer_or_view = "MtdArea_Layer";
                addJoinTool.in_field = "TOP_GOVT_CODE";
                addJoinTool.join_table = mtdCntryRefTablePath;
                addJoinTool.join_field = "GOVT_CODE";
                addJoinTool.join_type = "KEEP_COMMON";
                gp.Execute(addJoinTool, trackcancel);

                AddMessage("Calculating the ISO_CODE field...", messages, trackcancel);

                calcFieldTool = new CalculateField();
                calcFieldTool.in_table = "MtdArea_Layer";
                calcFieldTool.field = "MtdArea.ISO_CODE";
                calcFieldTool.expression = "[MtdCntryRef.ISO_CODE]";
                calcFieldTool.expression_type = "VB";
                gp.Execute(calcFieldTool, trackcancel);

                AddMessage("Calculating the DRIVING_SD field...", messages, trackcancel);

                calcFieldTool = new CalculateField();
                calcFieldTool.in_table = "MtdArea_Layer";
                calcFieldTool.field = "MtdArea.DRIVING_SD";
                calcFieldTool.expression = "[MtdCntryRef.DRIVING_SD]";
                calcFieldTool.expression_type = "VB";
                gp.Execute(calcFieldTool, trackcancel);

                removeJoinTool = new RemoveJoin();
                removeJoinTool.in_layer_or_view = "MtdArea_Layer";
                removeJoinTool.join_name = "MtdCntryRef";
                gp.Execute(removeJoinTool, trackcancel);

                // Create and calculate the FullAREACODE# string fields and the UTCOffset and DST fields

                addFieldTool = new AddField();
                addFieldTool.in_table = mtdAreaTablePath;
                addFieldTool.field_type = "SHORT";
                addFieldTool.field_name = "UTCOffset";
                gp.Execute(addFieldTool, trackcancel);
                addFieldTool.field_name = "DST";
                gp.Execute(addFieldTool, trackcancel);

                string codeBlock = "lvl = [ADMIN_LVL]\ns = CStr([AREACODE_1])";
                for (int i = 1; i <= 7; i++)
                {
                    string iAsString = Convert.ToString(i, System.Globalization.CultureInfo.InvariantCulture);
                    string iPlusOne = Convert.ToString(i+1, System.Globalization.CultureInfo.InvariantCulture);
                    string fullAreaCodeFieldName = "FullAREACODE" + iAsString;
                    addFieldTool = new AddField();
                    addFieldTool.in_table = mtdAreaTablePath;
                    addFieldTool.field_name = fullAreaCodeFieldName;
                    addFieldTool.field_type = "TEXT";
                    addFieldTool.field_length = 76;
                    gp.Execute(addFieldTool, trackcancel);

                    AddMessage("Calculating the FullAREACODE" + iAsString + " field...", messages, trackcancel);

                    calcFieldTool = new CalculateField();
                    calcFieldTool.in_table = mtdAreaTablePath;
                    calcFieldTool.field = fullAreaCodeFieldName;
                    calcFieldTool.code_block = codeBlock;
                    calcFieldTool.expression = "s";
                    calcFieldTool.expression_type = "VB";
                    gp.Execute(calcFieldTool, trackcancel);
                    codeBlock = codeBlock + "\nIf lvl >= " + iPlusOne + " Then s = s & \".\" & CStr([AREACODE_" + iPlusOne + "])";

                    string dstJoinTableName = "MtdDST" + iAsString;
                    string dstJoinTablePath = outputFileGdbPath + "\\" + dstJoinTableName;

                    addJoinTool = new AddJoin();
                    addJoinTool.in_layer_or_view = "MtdArea_Layer";
                    addJoinTool.in_field = fullAreaCodeFieldName;
                    addJoinTool.join_table = dstJoinTablePath;
                    addJoinTool.join_field = "AREACODE";
                    addJoinTool.join_type = "KEEP_COMMON";
                    gp.Execute(addJoinTool, trackcancel);

                    AddMessage("Calculating the UTCOffset field (" + iAsString + " of 7)...", messages, trackcancel);

                    calcFieldTool = new CalculateField();
                    calcFieldTool.in_table = "MtdArea_Layer";
                    calcFieldTool.field = "MtdArea.UTCOffset";
                    calcFieldTool.code_block = "s = [MtdArea.UTCOffset]\n" +
                                               "joinValue = [" + dstJoinTableName + ".TIME_ZONE]\n" +
                                               "If Not IsNull(joinValue) Then\n" +
                                               "  If Trim(joinValue) <> \"\" Then s = CInt(joinValue) * 6\n" +
                                               "End If";
                    calcFieldTool.expression = "s";
                    calcFieldTool.expression_type = "VB";
                    gp.Execute(calcFieldTool, trackcancel);

                    AddMessage("Calculating the DST field (" + iAsString + " of 7)...", messages, trackcancel);

                    calcFieldTool = new CalculateField();
                    calcFieldTool.in_table = "MtdArea_Layer";
                    calcFieldTool.field = "MtdArea.DST";
                    calcFieldTool.code_block = "s = [MtdArea.DST]\n" +
                                               "joinValue = [" + dstJoinTableName + ".DST_EXIST]\n" +
                                               "If Not IsNull(joinValue) Then\n" +
                                               "  Select Case Trim(joinValue)\n" +
                                               "    Case \"Y\": s = 1\n    Case \"N\": s = 0\n" +
                                               "  End Select\n" +
                                               "End If";
                    calcFieldTool.expression = "s";
                    calcFieldTool.expression_type = "VB";
                    gp.Execute(calcFieldTool, trackcancel);

                    removeJoinTool = new RemoveJoin();
                    removeJoinTool.in_layer_or_view = "MtdArea_Layer";
                    removeJoinTool.join_name = dstJoinTableName;
                    gp.Execute(removeJoinTool, trackcancel);

                    deleteTool = new Delete();
                    deleteTool.in_data = dstJoinTablePath;
                    gp.Execute(deleteTool, trackcancel);
                }

                deleteTool = new Delete();
                deleteTool.in_data = "MtdArea_Layer";
                gp.Execute(deleteTool, trackcancel);

                // Create and calculate the sortable MSTIMEZONE field on the MtdArea table

                addFieldTool = new AddField();
                addFieldTool.in_table = mtdAreaTablePath;
                addFieldTool.field_name = "SortableMSTIMEZONE";
                addFieldTool.field_type = "TEXT";
                addFieldTool.field_length = 60;
                gp.Execute(addFieldTool, trackcancel);

                AddMessage("Calculating the time zones...", messages, trackcancel);

                calcFieldTool = new CalculateField();
                calcFieldTool.in_table = mtdAreaTablePath;
                calcFieldTool.field = "SortableMSTIMEZONE";
                calcFieldTool.code_block = TimeZoneUtilities.MakeSortableMSTIMEZONECode("ISO_CODE");
                calcFieldTool.expression = "z";
                calcFieldTool.expression_type = "VB";
                gp.Execute(calcFieldTool, trackcancel);

                // Extract the MtdArea rows to be used for generating the time zone polygons and index the AREA_ID field

                string mtdAreaForTZPolysTablePath = outputFileGdbPath + "\\MtdAreaForTZPolys";
                tableSelectTool = new TableSelect();
                tableSelectTool.in_table = mtdAreaTablePath;
                tableSelectTool.out_table = mtdAreaForTZPolysTablePath;
                tableSelectTool.where_clause = CreateWhereClauseForAdminLvlByCountry(outputFileGdbPath, "MtdCntryRef");
                gp.Execute(tableSelectTool, trackcancel);

                addIndexTool = new AddIndex();
                addIndexTool.in_table = mtdAreaForTZPolysTablePath;
                addIndexTool.fields = "AREA_ID";
                addIndexTool.index_name = "AREA_ID";
                gp.Execute(addIndexTool, trackcancel);

                // We no longer need the MtdCntryRef table anymore

                deleteTool = new Delete();
                deleteTool.in_data = mtdCntryRefTablePath;
                gp.Execute(deleteTool, trackcancel);

                // Merge the AdminBndy feature classes together into one feature class

                int numAdminBndyFCs = inputAdminBndyFeatureClassesMultiValue.Count;
                string mergeToolInputs = "";
                for (int i = 0; i < numAdminBndyFCs; i++)
                {
                    mergeToolInputs = mergeToolInputs + inputAdminBndyFeatureClassesMultiValue.get_Value(i).GetAsText() + ";";
                }
                mergeToolInputs = mergeToolInputs.Remove(mergeToolInputs.Length - 1);
                string adminBndyFCPath = outputFileGdbPath + "\\AdminBndy";

                AddMessage("Merging the Administrative Boundary feature classes...", messages, trackcancel);

                Merge mergeTool = new Merge();
                mergeTool.inputs = mergeToolInputs;
                mergeTool.output = adminBndyFCPath;
                gp.Execute(mergeTool, trackcancel);

                // Join the AdminBndy polygons to the MtdArea rows to be used for generating the time zone polygons

                MakeFeatureLayer makeFeatureLayerTool = new MakeFeatureLayer();
                makeFeatureLayerTool.in_features = adminBndyFCPath;
                makeFeatureLayerTool.out_layer = "AdminBndy_Layer";
                gp.Execute(makeFeatureLayerTool, trackcancel);

                addJoinTool = new AddJoin();
                addJoinTool.in_layer_or_view = "AdminBndy_Layer";
                addJoinTool.in_field = "AREA_ID";
                addJoinTool.join_table = mtdAreaForTZPolysTablePath;
                addJoinTool.join_field = "AREA_ID";
                addJoinTool.join_type = "KEEP_COMMON";
                gp.Execute(addJoinTool, trackcancel);

                FeatureClassToFeatureClass importFCTool = new FeatureClassToFeatureClass();
                importFCTool.in_features = "AdminBndy_Layer";
                importFCTool.out_path = outputFileGdbPath;
                importFCTool.out_name = "UndissolvedTZPolys";
                importFCTool.field_mapping = "SortableMSTIMEZONE \"SortableMSTIMEZONE\" true true false 60 Text 0 0 ,First,#," +
                                             mtdAreaForTZPolysTablePath + ",MtdAreaForTZPolys.SortableMSTIMEZONE,-1,-1";
                gp.Execute(importFCTool, trackcancel);
                string undissolvedTZPolysFCPath = outputFileGdbPath + "\\UndissolvedTZPolys";

                removeJoinTool = new RemoveJoin();
                removeJoinTool.in_layer_or_view = "AdminBndy_Layer";
                removeJoinTool.join_name = "MtdAreaForTZPolys";
                gp.Execute(removeJoinTool, trackcancel);

                deleteTool = new Delete();
                deleteTool.in_data = "AdminBndy_Layer";
                gp.Execute(deleteTool, trackcancel);

                deleteTool = new Delete();
                deleteTool.in_data = adminBndyFCPath;
                gp.Execute(deleteTool, trackcancel);
                deleteTool.in_data = mtdAreaForTZPolysTablePath;
                gp.Execute(deleteTool, trackcancel);

                // Dissolve the time zone polygons together

                AddMessage("Dissolving the time zones...", messages, trackcancel);

                string timeZoneFCPath = outputFileGdbPath + "\\" + TimeZoneFCName;
                Dissolve dissolveTool = new Dissolve();
                dissolveTool.in_features = undissolvedTZPolysFCPath;
                dissolveTool.out_feature_class = timeZoneFCPath;
                dissolveTool.dissolve_field = "SortableMSTIMEZONE";
                dissolveTool.multi_part = "MULTI_PART";
                gp.Execute(dissolveTool, trackcancel);

                deleteTool = new Delete();
                deleteTool.in_data = undissolvedTZPolysFCPath;
                gp.Execute(deleteTool, trackcancel);

                // Create and calculate the MSTIMEZONE field

                addFieldTool = new AddField();
                addFieldTool.in_table = timeZoneFCPath;
                addFieldTool.field_name = "MSTIMEZONE";
                addFieldTool.field_type = "TEXT";
                addFieldTool.field_length = 50;
                gp.Execute(addFieldTool, trackcancel);

                AddMessage("Calculating the time zones...", messages, trackcancel);

                calcFieldTool = new CalculateField();
                calcFieldTool.in_table = timeZoneFCPath;
                calcFieldTool.field = "MSTIMEZONE";
                calcFieldTool.expression = "Mid([SortableMSTIMEZONE], 7)";
                calcFieldTool.expression_type = "VB";
                gp.Execute(calcFieldTool, trackcancel);

                // Delete the old sortable MSTIMEZONE field

                deleteFieldTool = new DeleteField();
                deleteFieldTool.in_table = timeZoneFCPath;
                deleteFieldTool.drop_field = "SortableMSTIMEZONE";
                gp.Execute(deleteFieldTool, trackcancel);

                if (processStreetsFC)
                {
                    // Create the network dataset time zone table

                    AddMessage("Creating the time zones table...", messages, trackcancel);

                    importTableTool = new TableToTable();
                    importTableTool.in_rows = timeZoneFCPath;
                    importTableTool.out_path = outputFileGdbPath;
                    importTableTool.out_name = TimeZonesTableName;
                    importTableTool.field_mapping = "MSTIMEZONE \"MSTIMEZONE\" true true false 50 Text 0 0 ,First,#," +
                                                    timeZoneFCPath + ",MSTIMEZONE,-1,-1";
                    gp.Execute(importTableTool, trackcancel);

                    // Separate the MtdArea table by driving side and index the AREA_ID field on each

                    AddMessage("Extracting rows for the left-side driving areas...", messages, trackcancel);

                    string drivingLTablePath = mtdAreaTablePath + "DrivingL";
                    string drivingRTablePath = mtdAreaTablePath + "DrivingR";

                    tableSelectTool = new TableSelect();
                    tableSelectTool.in_table = mtdAreaTablePath;
                    tableSelectTool.out_table = drivingLTablePath;
                    tableSelectTool.where_clause = "DRIVING_SD = 'L'";
                    gp.Execute(tableSelectTool, trackcancel);

                    addIndexTool = new AddIndex();
                    addIndexTool.in_table = drivingLTablePath;
                    addIndexTool.fields = "AREA_ID";
                    addIndexTool.index_name = "AREA_ID";
                    gp.Execute(addIndexTool, trackcancel);

                    AddMessage("Extracting rows for the right-side driving areas...", messages, trackcancel);

                    tableSelectTool = new TableSelect();
                    tableSelectTool.in_table = mtdAreaTablePath;
                    tableSelectTool.out_table = drivingRTablePath;
                    tableSelectTool.where_clause = "DRIVING_SD = 'R'";
                    gp.Execute(tableSelectTool, trackcancel);

                    addIndexTool = new AddIndex();
                    addIndexTool.in_table = drivingRTablePath;
                    addIndexTool.fields = "AREA_ID";
                    addIndexTool.index_name = "AREA_ID";
                    gp.Execute(addIndexTool, trackcancel);

                    // Import the Streets feature class to the file geodatabase and
                    // add the FT_TimeZoneID and TF_TimeZoneID fields

                    AddMessage("Copying the Streets feature class to the geodatabase...", messages, trackcancel);

                    importFCTool = new FeatureClassToFeatureClass();
                    importFCTool.in_features = inputStreetsFeatureClassValue.GetAsText();
                    importFCTool.out_path = outputFileGdbPath;
                    importFCTool.out_name = StreetsFCName;
                    gp.Execute(importFCTool, trackcancel);

                    string pathToStreetsFC = outputFileGdbPath + "\\" + StreetsFCName;

                    addFieldTool = new AddField();
                    addFieldTool.in_table = pathToStreetsFC;
                    addFieldTool.field_name = "FT_" + timeZoneIDBaseFieldName;
                    addFieldTool.field_type = "SHORT";
                    gp.Execute(addFieldTool, trackcancel);
                    addFieldTool.field_name = "TF_" + timeZoneIDBaseFieldName;
                    addFieldTool.field_type = "SHORT";
                    gp.Execute(addFieldTool, trackcancel);

                    // Calculate the TimeZoneID fields

                    makeFeatureLayerTool = new MakeFeatureLayer();
                    makeFeatureLayerTool.in_features = pathToStreetsFC;
                    makeFeatureLayerTool.out_layer = "Streets_Layer";
                    gp.Execute(makeFeatureLayerTool, trackcancel);

                    addJoinTool = new AddJoin();
                    addJoinTool.in_layer_or_view = "Streets_Layer";
                    addJoinTool.in_field = "R_AREA_ID";
                    addJoinTool.join_table = drivingLTablePath;
                    addJoinTool.join_field = "AREA_ID";
                    addJoinTool.join_type = "KEEP_COMMON";
                    gp.Execute(addJoinTool, trackcancel);

                    AddMessage("Calculating the FT_" + timeZoneIDBaseFieldName + " field for left driving side roads...", messages, trackcancel);

                    calcFieldTool = new CalculateField();
                    calcFieldTool.in_table = "Streets_Layer";
                    calcFieldTool.field = StreetsFCName + ".FT_" + timeZoneIDBaseFieldName;
                    calcFieldTool.code_block = TimeZoneUtilities.MakeTimeZoneIDCode(outputFileGdbPath, TimeZonesTableName, "MtdAreaDrivingL.SortableMSTIMEZONE");
                    calcFieldTool.expression = "tzID";
                    calcFieldTool.expression_type = "VB";
                    gp.Execute(calcFieldTool, trackcancel);

                    removeJoinTool = new RemoveJoin();
                    removeJoinTool.in_layer_or_view = "Streets_Layer";
                    removeJoinTool.join_name = "MtdAreaDrivingL";
                    gp.Execute(removeJoinTool, trackcancel);

                    addJoinTool = new AddJoin();
                    addJoinTool.in_layer_or_view = "Streets_Layer";
                    addJoinTool.in_field = "L_AREA_ID";
                    addJoinTool.join_table = drivingRTablePath;
                    addJoinTool.join_field = "AREA_ID";
                    addJoinTool.join_type = "KEEP_COMMON";
                    gp.Execute(addJoinTool, trackcancel);

                    AddMessage("Calculating the FT_" + timeZoneIDBaseFieldName + " field for right driving side roads...", messages, trackcancel);

                    calcFieldTool = new CalculateField();
                    calcFieldTool.in_table = "Streets_Layer";
                    calcFieldTool.field = StreetsFCName + ".FT_" + timeZoneIDBaseFieldName;
                    calcFieldTool.code_block = TimeZoneUtilities.MakeTimeZoneIDCode(outputFileGdbPath, TimeZonesTableName, "MtdAreaDrivingR.SortableMSTIMEZONE");
                    calcFieldTool.expression = "tzID";
                    calcFieldTool.expression_type = "VB";
                    gp.Execute(calcFieldTool, trackcancel);

                    removeJoinTool = new RemoveJoin();
                    removeJoinTool.in_layer_or_view = "Streets_Layer";
                    removeJoinTool.join_name = "MtdAreaDrivingR";
                    gp.Execute(removeJoinTool, trackcancel);

                    addJoinTool = new AddJoin();
                    addJoinTool.in_layer_or_view = "Streets_Layer";
                    addJoinTool.in_field = "L_AREA_ID";
                    addJoinTool.join_table = drivingLTablePath;
                    addJoinTool.join_field = "AREA_ID";
                    addJoinTool.join_type = "KEEP_COMMON";
                    gp.Execute(addJoinTool, trackcancel);

                    AddMessage("Calculating the TF_" + timeZoneIDBaseFieldName + " field for left driving side roads...", messages, trackcancel);

                    calcFieldTool = new CalculateField();
                    calcFieldTool.in_table = "Streets_Layer";
                    calcFieldTool.field = StreetsFCName + ".TF_" + timeZoneIDBaseFieldName;
                    calcFieldTool.code_block = TimeZoneUtilities.MakeTimeZoneIDCode(outputFileGdbPath, TimeZonesTableName, "MtdAreaDrivingL.SortableMSTIMEZONE");
                    calcFieldTool.expression = "tzID";
                    calcFieldTool.expression_type = "VB";
                    gp.Execute(calcFieldTool, trackcancel);

                    removeJoinTool = new RemoveJoin();
                    removeJoinTool.in_layer_or_view = "Streets_Layer";
                    removeJoinTool.join_name = "MtdAreaDrivingL";
                    gp.Execute(removeJoinTool, trackcancel);

                    addJoinTool = new AddJoin();
                    addJoinTool.in_layer_or_view = "Streets_Layer";
                    addJoinTool.in_field = "R_AREA_ID";
                    addJoinTool.join_table = drivingRTablePath;
                    addJoinTool.join_field = "AREA_ID";
                    addJoinTool.join_type = "KEEP_COMMON";
                    gp.Execute(addJoinTool, trackcancel);

                    AddMessage("Calculating the TF_" + timeZoneIDBaseFieldName + " field for right driving side roads...", messages, trackcancel);

                    calcFieldTool = new CalculateField();
                    calcFieldTool.in_table = "Streets_Layer";
                    calcFieldTool.field = StreetsFCName + ".TF_" + timeZoneIDBaseFieldName;
                    calcFieldTool.code_block = TimeZoneUtilities.MakeTimeZoneIDCode(outputFileGdbPath, TimeZonesTableName, "MtdAreaDrivingR.SortableMSTIMEZONE");
                    calcFieldTool.expression = "tzID";
                    calcFieldTool.expression_type = "VB";
                    gp.Execute(calcFieldTool, trackcancel);

                    removeJoinTool = new RemoveJoin();
                    removeJoinTool.in_layer_or_view = "Streets_Layer";
                    removeJoinTool.join_name = "MtdAreaDrivingR";
                    gp.Execute(removeJoinTool, trackcancel);

                    deleteTool = new Delete();
                    deleteTool.in_data = "Streets_Layer";
                    gp.Execute(deleteTool, trackcancel);

                    deleteTool = new Delete();
                    deleteTool.in_data = drivingLTablePath;
                    gp.Execute(deleteTool, trackcancel);
                    deleteTool.in_data = drivingRTablePath;
                    gp.Execute(deleteTool, trackcancel);
                }
                else
                {
                    // Create a dummy TimeZones table and a dummy Streets feature class

                    CreateTable createTableTool = new CreateTable();
                    createTableTool.out_path = outputFileGdbPath;
                    createTableTool.out_name = TimeZonesTableName;
                    gp.Execute(createTableTool, trackcancel);

                    CreateFeatureclass createFCTool = new CreateFeatureclass();
                    createFCTool.out_path = outputFileGdbPath;
                    createFCTool.out_name = StreetsFCName;
                    createFCTool.geometry_type = "POLYLINE";
                    gp.Execute(createFCTool, trackcancel);
                }

                deleteTool = new Delete();
                deleteTool.in_data = mtdAreaTablePath;
                gp.Execute(deleteTool, trackcancel);

                // Compact the output file geodatabase

                AddMessage("Compacting the output file geodatabase...", messages, trackcancel);

                Compact compactTool = new Compact();
                compactTool.in_workspace = outputFileGdbPath;
                gp.Execute(compactTool, trackcancel);
            }
            catch (Exception e)
            {
                if (gp.MaxSeverity == 2)
                {
                    object missing = System.Type.Missing;
                    messages.AddError(1, gp.GetMessages(ref missing));
                }
                messages.AddError(1, e.Message);
                messages.AddError(1, e.StackTrace);
            }
            finally
            {
                // Restore the original GP environment settings

                gpSettings.AddOutputsToMap = origAddOutputsToMapSetting;
                gpSettings.LogHistory = origLogHistorySetting;
            }
            GC.Collect();
            return;
        }