/// <summary>
 /// Given an assembly containing one ore more DictionarySteps, applies specified dictionary steps into database model and physical database.
 /// </summary>
 /// <param name="assembly">Assembly containing dictionary steps</param>
 /// <param name="connectionString">Connection string to SuperOffice database where steps are to be applied.</param>
 /// <param name="tablePrefix">SuperOffice table prefix</param>
 /// <param name="dbMajor">Major version of SuperOffice database.</param>
 /// <param name="dbMinor">Minor version of SuperOffice database.</param>
 /// <param name="stepsToInclude">Name of the DictionaryStep to apply. Useful when an assembly contains more then one.</param>
 /// <param name="uninstall">Indicates whether this call should only apply DictionarySteps with a StepNumber equals to int.MaxValue</param>
 /// <param name="progress">Optional progress implementation for reporting progress.</param>
 /// <returns>Array of StepInfo indicating which dictionary steps were applied.</returns>
 public StepInfo[] ApplySteps(
     string assembly,
     string connectionString,
     string tablePrefix,
     string dbMajor,
     string dbMinor,
     IProgressNotification progress,
     StepInfo[] stepsToInclude,
     bool uninstall = false)
 {
     return(_remoteClass.ApplySteps(assembly, connectionString, tablePrefix, dbMajor, dbMinor, stepsToInclude, uninstall, progress));
 }
        /// <summary>
        /// Given an assembly containing one ore more DictionarySteps, applies specified dictionary steps into database model and physical database.
        /// </summary>
        /// <param name="assembly">Assembly containing dictionary steps</param>
        /// <param name="connectionString">Connection string to SuperOffice database where steps are to be applied.</param>
        /// <param name="tablePrefix">SuperOffice table prefix</param>
        /// <param name="dbMajor">Major version of SuperOffice database.</param>
        /// <param name="dbMinor">Minor version of SuperOffice database.</param>
        /// <param name="stepsToInclude">Name of the DictionaryStep to apply. Useful when an assembly contains more then one.</param>
        /// <param name="uninstall">Indicates whether this call should only apply DictionarySteps with a StepNumber equals to int.MaxValue</param>
        /// <param name="progress">Optional progress implementation for reporting progress.</param>
        /// <returns>Array of StepInfo indicating which dictionary steps were applied.</returns>
        internal StepInfo[] ApplySteps(
            string assembly,
            string connectionString,
            string tablePrefix,
            string dbMajor,
            string dbMinor,
            StepInfo[] stepsToInclude,
            bool uninstall,
            IProgressNotification progress)
        {
            DictionaryStepInfo[] result = null;

            try
            {
                // load the assembly into this AppDomain

                var stepAssembly = LoadAssembly(assembly);

                var fileLogger = new SuperOffice.CD.DSL.Logging.FileLogger(Environment.CurrentDirectory + "\\appliedstep.log");

                using (var connection = DbConnectionProvider.GetConnection(connectionString, dbMajor, dbMinor))
                {
                    using (var dbm = DatabaseManagement.CreateInstance(tablePrefix, connection, fileLogger, progress))
                    {
                        var model   = dbm.ReadDatabaseModel();
                        var dbState = dbm.InspectDatabase();

                        // ensure we are talking to a SuperOffice database version >= 8.1

                        if (dbState == DatabaseManagement.DatabaseContent.SuperOfficeCdd)
                        {
                            // get all DictionarySteps in this AppDomain - filter out any .net & SuperOffice assemblies

                            var steps = GetDictionarySteps(stepsToInclude, uninstall);


                            //make sure we only apply steps that were passed in stepsToInclude argument

                            var desiredSteps = new List <DictionaryStep>();

                            foreach (var item in stepsToInclude.OrderBy(st => st.Name).ThenBy(st => st.StepNumber))
                            {
                                var dicStep = steps.Find(s => s.GetAttribute().DictionaryName.Equals(item.Name, StringComparison.InvariantCultureIgnoreCase) &&
                                                         s.GetAttribute().StepNumber == item.StepNumber);

                                if (dicStep != null)
                                {
                                    desiredSteps.Add(dicStep);
                                }
                            }

                            // apply DictionarySteps in the Database
                            if (desiredSteps.Count > 0)
                            {
                                result = dbm.ApplyDictionarySteps(new LinkedList <DictionaryStep>(desiredSteps), model);
                            }
                        }

                        if (result == null)
                        {
                            return(null);
                        }

                        return(result.Select(s => new StepInfo {
                            Name = s.Name, StepNumber = s.StepNumber, State = s.State.ToString()
                        }).ToArray());
                    }
                }
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }