private bool ScriptTask1Execute(ProcessExecutingContext context) { var resultLogger = new StringBuilder(); Action <string, MessageType> logToConsole = Get <Action <string, MessageType> >("WriteMessageAction"); Action <string, MessageType> log = (message, type) => { if (logToConsole != null) { logToConsole(message, type); } resultLogger.AppendFormat("{0}: {1}{2}", type.ToString(), message, Environment.NewLine); }; UserConnection userConnection = Get <UserConnection>("UserConnection"); string excludedSchemas = Get <string>("ExcludedSchemas"); var excludedSchemasList = string.IsNullOrWhiteSpace(excludedSchemas) ? new List <string>() : excludedSchemas.Split(new[] { "," }, StringSplitOptions.RemoveEmptyEntries).ToList().ConvertAll(s => s.Trim()); if (excludedSchemasList.Any()) { log("There are excluded schemas: " + string.Join(", ", excludedSchemasList), MessageType.Information); } var skipStructureUpdateDefaultStartDate = Get <DateTime>("NotUpdateMoneyStructureStartDate"); DateTime skipStructureUpdateStartDate = SysSettings.GetValue(userConnection, "ClientUpdate_NotUpdateMoneyStructureStartDate", skipStructureUpdateDefaultStartDate); EntitySchemaManager entitySchemaManager = userConnection.EntitySchemaManager; Func <Guid, DateTime> getSchemaLastDate = (schemaUId) => { var columnFunc = Func.IsNull(Column.SourceColumn("StructureModifiedOn"), Column.SourceColumn("ModifiedOn")); return(((Select) new Select(userConnection).Top(1) .Column(columnFunc) .From("SysSchema") .OrderByDesc(columnFunc) .Where("UId") .IsEqual(Column.Parameter(schemaUId))).ExecuteScalar <DateTime>()); }; List <EntitySchema> entitySchemasWithCurrencyColumn = entitySchemaManager.GetItems().ToList() .ConvertAll(i => entitySchemaManager.FindInstanceByUId(i.UId)) .Where(i => i != null && !i.IsVirtual && !i.IsDBView) .Where(i => i.Columns.Any(c => c.DataValueType is MoneyDataValueType)) .Where(i => !excludedSchemasList.Contains(i.Name, StringComparer.OrdinalIgnoreCase)) .ToList(); var entitySchemasToUpdateStructure = new List <EntitySchema>(); foreach (var schema in entitySchemasWithCurrencyColumn) { var actualizedDate = getSchemaLastDate(schema.UId); if (actualizedDate > skipStructureUpdateStartDate) { string logMessage = string.Format("Schema: {0} already updated on {1}. Skip...", schema.Name, actualizedDate); log(logMessage, MessageType.Information); } else { entitySchemasToUpdateStructure.Add(schema); } } List <Exception> exceptions = new List <Exception>(); if (entitySchemasToUpdateStructure.Any()) { string msg = string.Format("DB structure will be updated for: {0}", string.Join(", ", entitySchemasToUpdateStructure.Select(i => i.Name))); log(msg, MessageType.Information); var installUtilities = new PackageInstallUtilities(userConnection); installUtilities.InstallMessage += (s, arg) => { log(arg.Message, MessageType.Information); }; installUtilities.InstallError += (s, arg) => { exceptions.Add(arg.Exception); var schema = entitySchemasToUpdateStructure.Find(i => i.UId == arg.UId); var schemaName = (schema == null) ? arg.UId.ToString() : schema.Name; string errorMsg = string.Format("Error while update structure for schema: {0}, package: {1}", schemaName, arg.PackageName); log(errorMsg, MessageType.Error); }; installUtilities.SaveSchemaDBStructure(entitySchemasToUpdateStructure.Select(s => s.UId), true); } else { log("It seems that all tables structure is actualized already.", MessageType.Information); } Set("ResultString", resultLogger.ToString()); if (exceptions.Any()) { throw new AggregateException("Some errors occured while actualizing db structure", exceptions); } return(true); }