private void PerformGeneration(
            nHydrateModel model,
            List<nHydrateGeneratorProject> genList,
            Microsoft.VisualStudio.Modeling.Store store,
            Microsoft.VisualStudio.Modeling.Shell.ModelingDocData docData,
            List<Type> excludeList,
            nHydrate.Generator.Common.GeneratorFramework.GeneratorHelper genHelper,
            List<string> generateModuleList)
        {
            _totalFileCount = 0;
            _processedFileCount = 0;
            var pkey = string.Empty;
            try
            {
                var startTime = DateTime.Now;
                var isLicenseError = false;
                var generationProcessing = false;
                var fullModuleGenList = genList.Select(x => new ModuleVersionInfo() { ModuleName = (x.Model as nHydrate.Generator.Models.ModelRoot).ModuleName }).ToList();

                try
                {
                    //Get the last version we generated on this machine
                    //We will use this to determine if any other generations have been performed on other machines
                    var cacheFile = new nHydrate.Generator.Common.ModelCacheFile(genList.First());
                    var cachedGeneratedVersion = cacheFile.GeneratedVersion;

                    var generatedVersion = cachedGeneratedVersion + 1;

                    pkey = ProgressHelper.ProgressingStarted("Generating...", false, 240000); //Put a 4 minute timer on it
                    foreach (var item in genList)
                    {
                        (item.Model as nHydrate.Generator.Models.ModelRoot).GeneratedVersion = generatedVersion;
                        //(item.Model as nHydrate.Generator.Models.ModelRoot).SyncServerToken = model.SyncServerToken;
                        //(item.Model as nHydrate.Generator.Models.ModelRoot).SyncServerURL = model.SyncServerURL;
                        _totalFileCount += genHelper.GetFileCount(item, excludeList);
                    }
                    System.Diagnostics.Debug.WriteLine("File count: " + _totalFileCount);

                    //Save document
                    var isDirty = 0;
                    docData.IsDirty(out isDirty);
                    if (model.IsDirty || (isDirty != 0))
                        (docData as nHydrateDocData).Save(docData.FileName, 1, 0);

                    _startTime = DateTime.Now;
                    foreach (var item in genList)
                    {
                        if (model.UseModules)
                        {
                            if (generateModuleList.Contains((item.Model as nHydrate.Generator.Models.ModelRoot).ModuleName))
                                genHelper.GenerateAll(item, excludeList);
                        }
                        else
                        {
                            genHelper.GenerateAll(item, excludeList);
                        }
                    }

                    if (model.Refactorizations.Count > 0)
                    {
                        using (var transaction = store.TransactionManager.BeginTransaction(Guid.NewGuid().ToString()))
                        {
                            model.Refactorizations.Clear();
                            model.UseUTCTime = !model.UseUTCTime; //Trigger a model change
                            model.UseUTCTime = !model.UseUTCTime; //Keep this line too
                            transaction.Commit();

                            //Save document
                            (docData as nHydrateDocData).Save(docData.FileName, 1, 0);

                        }
                    }

                    //Save local copy of last generated version
                    cacheFile.GeneratedVersion = generatedVersion;
                    cacheFile.ModelerVersion = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version;
                    cacheFile.Save();

                    this.ErrorList = genHelper.GetErrorList().ToList();

                }
                catch (nHydrate.Generator.Common.Exceptions.LicenseException ex)
                {
                    ProgressHelper.ProgressingComplete(pkey);
                    MessageBox.Show("This product is not properly licensed", "License Error", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    isLicenseError = true;
                }
                catch (Exception ex)
                {
                    throw;
                }
                finally
                {
                    ProgressHelper.ProgressingComplete(pkey);

                }

                var endTime = DateTime.Now;
                var duration = endTime.Subtract(startTime);
                #region Show Generation Complete Dialog
                if (!isLicenseError)
                {
                    using (var F = new StatisticsForm())
                    {
                        var text = "The generation was successful.\r\n\r\n";
                        text += "Files generated: " + this.FilesSuccess + "\r\n";
                        text += "Files skipped: " + this.FilesSkipped + "\r\n";
                        text += "Files failed: " + this.FilesFailed + "\r\n";
                        text += "\r\n\r\n";
                        text += "Generation time: " + duration.Hours.ToString("00") + ":" +
                                duration.Minutes.ToString("00") + ":" +
                                duration.Seconds.ToString("00");
                        F.DisplayText = text;
                        F.GeneratedFileList = this.GeneratedFileList;
                        F.ShowDialog();
                    }
                }
                #endregion

            }
            catch (Exception ex)
            {
                ProgressHelper.ProgressingComplete(pkey);
                GlobalHelper.ShowError(ex);
            }
        }
        private bool ChooseGenerators(
            nHydrateModel model,
            List<nHydrateGeneratorProject> genList,
            List<Type> generatorTypeList,
            List<Type> excludeList,
            nHydrate.Generator.Common.GeneratorFramework.GeneratorHelper genHelper,
            List<string> generateModuleList)
        {

            var cacheFile = new nHydrate.Generator.Common.ModelCacheFile(genList.First());
            if (cacheFile.ModelerVersion > System.Reflection.Assembly.GetExecutingAssembly().GetName().Version)
            {
                if (MessageBox.Show("This model schema was last generated with a newer modeler version (" + cacheFile.ModelerVersion + "). Your current version is " + System.Reflection.Assembly.GetExecutingAssembly().GetName().Version + ". Generating with an older modeler may cause many files to change unexpectedly. Do you wish to proceed with the generation?", "Warning", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.No)
                    return false;
            }

            //Show generator list
            var allModules = model.Modules.Select(x => x.Name).ToList();
            if (!model.UseModules) allModules.Clear();
            using (var F = new GenerateSettings(genList.First(), generatorTypeList, null, allModules))
            {
                if (F.ShowDialog() != DialogResult.OK) return false;
                excludeList.AddRange(F.ExcludeList);
                generateModuleList.AddRange(F.SelectedModules);
            }

            //If we are using modules then filter on the selected ones
            if (model.UseModules)
            {
                genList = genList.Where(x => generateModuleList.Contains((x.Model as nHydrate.Generator.Models.ModelRoot).ModuleName)).ToList();
            }

            return true;

        }