Example #1
0
        public override void Generate()
        {
            {
                var template = new SSDLTemplate(_model);
                var fullFileName = RELATIVE_OUTPUT_LOCATION + template.FileName;
                var eventArgs = new ProjectItemGeneratedEventArgs(fullFileName, template.FileContent, ProjectName, this, true);
                eventArgs.Properties.Add("BuildAction", 3);
                OnProjectItemGenerated(this, eventArgs);
            }

            if (_model.Database.Tables.Any(x => x.IsTenant && x.Generated))
            {
                var template = new SSDLAdminTemplate(_model);
                var fullFileName = RELATIVE_OUTPUT_LOCATION + template.FileName;
                var eventArgs = new ProjectItemGeneratedEventArgs(fullFileName, template.FileContent, ProjectName, this, true);
                eventArgs.Properties.Add("BuildAction", 3);
                OnProjectItemGenerated(this, eventArgs);
            }
            else
            {
                //If this is not a tenant model then remove the admin SSDL file
                var template = new SSDLAdminTemplate(_model);
                var fullFileName = RELATIVE_OUTPUT_LOCATION + template.FileName;
                var eventArgs = new ProjectItemDeletedEventArgs(fullFileName, ProjectName, this);
                OnProjectItemDeleted(this, eventArgs);
            }

            var gcEventArgs = new ProjectItemGenerationCompleteEventArgs(this);
            OnGenerationComplete(this, gcEventArgs);
        }
		public override void Generate()
		{
			foreach (var table in GetList())
			{
				var template = new AuditEntityExtenderTemplate(_model, table);
				var fullFileName = RELATIVE_OUTPUT_LOCATION + template.FileName;
				var eventArgs = new ProjectItemGeneratedEventArgs(fullFileName, template.FileContent, ProjectName, this, false);
				OnProjectItemGenerated(this, eventArgs);
			}

			//Process deleted items
			foreach (var name in _model.RemovedTables)
			{
				var fullFileName = RELATIVE_OUTPUT_LOCATION + string.Format("I{0}Audit.cs", name);
				var eventArgs = new ProjectItemDeletedEventArgs(fullFileName, ProjectName, this);
				OnProjectItemDeleted(this, eventArgs);
			}

			//Process tables that are not longer audited
			foreach (var name in _model.Database.Tables.Where(x => !x.AllowAuditTracking))
			{
				var fullFileName = RELATIVE_OUTPUT_LOCATION + string.Format("I{0}Audit.cs", name);
				var eventArgs = new ProjectItemDeletedEventArgs(fullFileName, ProjectName, this);
				OnProjectItemDeleted(this, eventArgs);
			}

			var gcEventArgs = new ProjectItemGenerationCompleteEventArgs(this);
			OnGenerationComplete(this, gcEventArgs);
		}
Example #3
0
 protected virtual void OnProjectItemGeneratedError(object sender, ProjectItemGeneratedEventArgs pigArgs)
 {
     if (ProjectItemGeneratedError != null)
     {
         this.ProjectItemGeneratedError(sender, pigArgs);
     }
 }
 public override void Generate()
 {
     var template = new HelperExtenderTemplate(_model);
     var fullFileName = RELATIVE_OUTPUT_LOCATION + template.FileName;
     var eventArgs = new ProjectItemGeneratedEventArgs(fullFileName, template.FileContent, ProjectName, this, false);
     OnProjectItemGenerated(this, eventArgs);
     var gcEventArgs = new ProjectItemGenerationCompleteEventArgs(this);
     OnGenerationComplete(this, gcEventArgs);
 }
		public override void Generate()
		{
			var template = new ContextExtensionsGeneratedTemplate(_model);
			var fullParentName = RELATIVE_OUTPUT_LOCATION + template.ParentItemName;
			var eventArgs = new ProjectItemGeneratedEventArgs(template.FileName, template.FileContent, ProjectName, fullParentName, this, true);
			OnProjectItemGenerated(this, eventArgs);
			var gcEventArgs = new ProjectItemGenerationCompleteEventArgs(this);
			OnGenerationComplete(this, gcEventArgs);
		}
 public override void Generate()
 {
     var template = new UpgradeVersionedTemplate(_model);
     var fullFileName = template.FileName;
     var eventArgs = new ProjectItemGeneratedEventArgs(fullFileName, template.FileContent, ProjectName, PARENT_ITEM_NAME, ProjectItemType.Folder, this, false);
     eventArgs.Properties.Add("BuildAction", 3);
     OnProjectItemGenerated(this, eventArgs);
     var gcEventArgs = new ProjectItemGenerationCompleteEventArgs(this);
     OnGenerationComplete(this, gcEventArgs);
 }
 public override void Generate()
 {
     foreach (var customView in _model.Database.CustomViews.Where(x => x.Generated).OrderBy(x => x.Name))
     {
         var template = new ViewEntityGeneratedTemplate(_model, customView);
         var fullParentName = RELATIVE_OUTPUT_LOCATION + template.ParentItemName;
         var eventArgs = new ProjectItemGeneratedEventArgs(template.FileName, template.FileContent, ProjectName, fullParentName, this, true);
         OnProjectItemGenerated(this, eventArgs);
     }
     var gcEventArgs = new ProjectItemGenerationCompleteEventArgs(this);
     OnGenerationComplete(this, gcEventArgs);
 }
 public override void Generate()
 {
     foreach (var table in _model.Database.Tables.Where(x => x.Generated && !x.AssociativeTable && (x.TypedTable != TypedTableConstants.EnumOnly) && x.AllowAuditTracking).OrderBy(x => x.Name))
     {
         var template = new AuditEntityGeneratedTemplate(_model, table);
         var fullParentName = RELATIVE_OUTPUT_LOCATION + template.ParentItemName;
         var eventArgs = new ProjectItemGeneratedEventArgs(template.FileName, template.FileContent, ProjectName, fullParentName, this, true);
         OnProjectItemGenerated(this, eventArgs);
     }
     var gcEventArgs = new ProjectItemGenerationCompleteEventArgs(this);
     OnGenerationComplete(this, gcEventArgs);
 }
Example #9
0
        public override void Generate()
        {
            //Sql Server
            var template = new CSDLTemplate(_model);
            var fullFileName = RELATIVE_OUTPUT_LOCATION + template.FileName;
            var eventArgs = new ProjectItemGeneratedEventArgs(fullFileName, template.FileContent, ProjectName, this, true);
            eventArgs.Properties.Add("BuildAction", 3);
            OnProjectItemGenerated(this, eventArgs);

            var gcEventArgs = new ProjectItemGenerationCompleteEventArgs(this);
            OnGenerationComplete(this, gcEventArgs);
        }
Example #10
0
		public override void Generate()
		{
			try
			{
				var template = new FunctionsTemplate(_model);
				var fullFileName = template.FileName;
				var eventArgs = new ProjectItemGeneratedEventArgs(fullFileName, template.FileContent, ProjectName, this.ParentItemPath, ProjectItemType.Folder, this, true);
				eventArgs.Properties.Add("BuildAction", 3);
				OnProjectItemGenerated(this, eventArgs);
				var gcEventArgs = new ProjectItemGenerationCompleteEventArgs(this);
				OnGenerationComplete(this, gcEventArgs);
			}
			catch (Exception ex)
			{
				throw;
			}
		}
Example #11
0
		public override void Generate()
		{
			var metaKey1 = _model.MetaData.FirstOrDefault(x => x.Key.ToLower() == "xsdprojectname");
			var metaKey2 = _model.MetaData.FirstOrDefault(x => x.Key.ToLower() == "xsdfilename");
			var metaKey3 = _model.MetaData.FirstOrDefault(x => x.Key.ToLower() == "xsdschemaname");
			var metaKey4 = _model.MetaData.FirstOrDefault(x => x.Key.ToLower() == "xsddroprelations");

			if (metaKey2 == null || metaKey3 == null)
			{
				OnProjectItemGeneratedError(this,
					new ProjectItemGeneratedErrorEventArgs()
					{
						Text = "The XSD generation template requires the model metadata 'XSDFileName' and 'XSDSchemaName' be set. Also an optional 'XSDProjectName' meta tag may be set.",
						ShowError = true
					}
					);
				return;
			}

			var fileName = metaKey2.Value;
			var schemaName = metaKey3.Value;
			var projectName = string.Empty;
			if (metaKey1 != null) projectName = metaKey1.Value;

			var droprelations = false;
			if (metaKey4 != null)
			{
				bool.TryParse(metaKey4.Value, out droprelations);
			}

			//Prepend Module name if necessary
			if (!string.IsNullOrEmpty(_model.ModuleName))
			{
				fileName = _model.ModuleName + "." + fileName;
			}

			var noPathFileName = fileName.Split('\\').Last();

			var template = new XSDSchemaTemplate(_model, schemaName, noPathFileName, droprelations);
			var eventArgs = new ProjectItemGeneratedEventArgs(fileName, template.FileContent, projectName, this, true) { RunCustomTool = true, CustomToolName = "MSDataSetGenerator" };
			OnProjectItemGenerated(this, eventArgs);
			var gcEventArgs = new ProjectItemGenerationCompleteEventArgs(this);
			OnGenerationComplete(this, gcEventArgs);
		}
        public override void Generate()
        {
            foreach (var table in _model.Database.Tables.Where(x => x.Generated && !x.AssociativeTable && (x.TypedTable != Models.TypedTableConstants.EnumOnly)).OrderBy(x => x.Name))
            {
                var template = new EntityGeneratedTemplate(_model, table);
                var fullParentName = RELATIVE_OUTPUT_LOCATION + template.ParentItemName;
                var eventArgs = new ProjectItemGeneratedEventArgs(template.FileName, template.FileContent, ProjectName, fullParentName, this, true);
                OnProjectItemGenerated(this, eventArgs);
            }

            //Process deleted items
            foreach (var name in _model.RemovedTables)
            {
                var fullFileName = RELATIVE_OUTPUT_LOCATION + string.Format("{0}.Generated.cs", name);
                var eventArgs = new ProjectItemDeletedEventArgs(fullFileName, ProjectName, this);
                OnProjectItemDeleted(this, eventArgs);
            }

            var gcEventArgs = new ProjectItemGenerationCompleteEventArgs(this);
            OnGenerationComplete(this, gcEventArgs);
        }
		public override void Generate()
		{
			foreach (var table in GetList())
			{
				var template = new EntityPrimaryKeyTemplate(_model, table);
				var fullParentName = RELATIVE_OUTPUT_LOCATION + template.ParentItemName;
				var eventArgs = new ProjectItemGeneratedEventArgs(template.FileName, template.FileContent, ProjectName, fullParentName, this, true);
				OnProjectItemGenerated(this, eventArgs);
			}

			//Process deleted items
			foreach (var name in _model.RemovedTables)
			{
				var fullFileName = RELATIVE_OUTPUT_LOCATION + name + "PrimaryKey.Generated.cs";
				var eventArgs = new ProjectItemDeletedEventArgs(fullFileName, ProjectName, this);
				OnProjectItemDeleted(this, eventArgs);
			}

			var gcEventArgs = new ProjectItemGenerationCompleteEventArgs(this);
			OnGenerationComplete(this, gcEventArgs);
		}
		public override void Generate()
		{
			foreach (var item in GetList())
			{
				var template = new ActionTypesGeneratedTemplate(_model, item);
				var fullParentName = RELATIVE_OUTPUT_LOCATION + template.ParentItemName;
				var eventArgs = new ProjectItemGeneratedEventArgs(template.FileName, template.FileContent, ProjectName, fullParentName, this, true);
				OnProjectItemGenerated(this, eventArgs);
			}

			//Process deleted items
			foreach (var name in _model.RemovedStoredProcedures)
			{
				var fullFileName = RELATIVE_OUTPUT_LOCATION + string.Format("{0}.Generated.cs", name);
				var eventArgs = new ProjectItemDeletedEventArgs(fullFileName, ProjectName, this);
				OnProjectItemDeleted(this, eventArgs);
			}

			var gcEventArgs = new ProjectItemGenerationCompleteEventArgs(this);
			OnGenerationComplete(this, gcEventArgs);
		}
		public override void Generate()
		{
			foreach (var table in GetList())
			{
				var template = new ViewEntityExtenderTemplate(_model, table);
				var fullFileName = RELATIVE_OUTPUT_LOCATION + template.FileName;
				var eventArgs = new ProjectItemGeneratedEventArgs(fullFileName, template.FileContent, ProjectName, this, false);
				OnProjectItemGenerated(this, eventArgs);
			}

			//Process deleted items
			foreach (var name in _model.RemovedViews)
			{
				var fullFileName = RELATIVE_OUTPUT_LOCATION + string.Format("{0}.cs", name);
				var eventArgs = new ProjectItemDeletedEventArgs(fullFileName, ProjectName, this);
				OnProjectItemDeleted(this, eventArgs);
			}

			var gcEventArgs = new ProjectItemGenerationCompleteEventArgs(this);
			OnGenerationComplete(this, gcEventArgs);
		}
		public override void Generate()
		{
			foreach (var item in GetListSP())
			{
				var template = new ComplexTypesSPExtenderTemplate(_model, item);
				var fullFileName = RELATIVE_OUTPUT_LOCATION + template.FileName;
				var eventArgs = new ProjectItemGeneratedEventArgs(fullFileName, template.FileContent, ProjectName, this, false);
				OnProjectItemGenerated(this, eventArgs);
			}

			foreach (var item in GetListFunc())
			{
				var template = new ComplexTypesFuncExtenderTemplate(_model, item);
				var fullFileName = RELATIVE_OUTPUT_LOCATION + template.FileName;
				var eventArgs = new ProjectItemGeneratedEventArgs(fullFileName, template.FileContent, ProjectName, this, false);
				OnProjectItemGenerated(this, eventArgs);
			}

			//Process deleted items
			foreach (var name in _model.RemovedStoredProcedures)
			{
				var fullFileName = RELATIVE_OUTPUT_LOCATION + name + ".cs";
				var eventArgs = new ProjectItemDeletedEventArgs(fullFileName, ProjectName, this);
				OnProjectItemDeleted(this, eventArgs);
			}

			//Process deleted items
			foreach (var name in _model.RemovedFunctions)
			{
				var fullFileName = RELATIVE_OUTPUT_LOCATION + name + ".cs";
				var eventArgs = new ProjectItemDeletedEventArgs(fullFileName, ProjectName, this);
				OnProjectItemDeleted(this, eventArgs);
			}

			var gcEventArgs = new ProjectItemGenerationCompleteEventArgs(this);
			OnGenerationComplete(this, gcEventArgs);
		}
		private void GenerateHistoryFormResx()
		{
			var fullParentName = "HistoryForm.cs";
			var fileName = "HistoryForm.resx";
			var ern = new EmbeddedResourceName();
			ern.AsmLocation = this.GetEmbeddedPath();
			ern.FileName = fileName + ".embed";
			ern.FullName = this.GetEmbeddedPath() + "." + ern.FileName;
			var fileContent = GetFileContent(ern);
			var eventArgs = new ProjectItemGeneratedEventArgs(fileName, fileContent, ProjectName, fullParentName, this, true);
			eventArgs.Properties.Add("BuildAction", 3);
			OnProjectItemGenerated(this, eventArgs);
		}
        public override void Generate()
        {
            //if (_model.Database.AllowZeroTouch) return;
            try
            {
                if (this.UseSingleFile)
                {
                    //Process all views
                    var sb = new StringBuilder();
                    sb.AppendLine("--DO NOT MODIFY THIS FILE. IT IS ALWAYS OVERWRITTEN ON GENERATION.");
                    sb.AppendLine();

                    if (_model.EmitSafetyScripts)
                    {
                        sb.AppendLine("--##SECTION BEGIN [INTERNAL STORED PROCS]");
                        sb.AppendLine();

                        foreach (var table in _model.Database.Tables.Where(x => x.Generated && (x.TypedTable != TypedTableConstants.EnumOnly)).OrderBy(x => x.Name))
                        {
                            var template = new SQLStoredProcedureTableAllTemplate(_model, table, true);
                            sb.Append(template.FileContent);
                        }

                        sb.AppendLine("--##SECTION END [INTERNAL STORED PROCS]");
                        sb.AppendLine();
                    }

                    var eventArgs = new ProjectItemGeneratedEventArgs("StoredProcedures.sql", sb.ToString(), ProjectName, this.ParentItemPath, ProjectItemType.Folder, this, true);
                    eventArgs.Properties.Add("BuildAction", 3);
                    OnProjectItemGenerated(this, eventArgs);
                }
                else
                {
                    if (_model.EmitSafetyScripts)
                    {
                        //Process all tables
                        foreach (var table in _model.Database.Tables.Where(x => x.Generated && (x.TypedTable != TypedTableConstants.EnumOnly)).OrderBy(x => x.Name))
                        {
                            var template = new SQLStoredProcedureTableAllTemplate(_model, table, false);
                            var fullFileName = template.FileName;
                            var eventArgs = new ProjectItemGeneratedEventArgs(fullFileName, template.FileContent, ProjectName, this.ParentItemPath, ProjectItemType.Folder, this, true);
                            eventArgs.Properties.Add("BuildAction", 3);
                            OnProjectItemGenerated(this, eventArgs);
                        }
                    }
                }

                var gcEventArgs = new ProjectItemGenerationCompleteEventArgs(this);
                OnGenerationComplete(this, gcEventArgs);
            }
            catch (Exception ex)
            {
                throw;
            }
        }
Example #19
0
		public override void Generate()
		{
			//var template = new DatasiteOverviewTemplate(_model);
			//var fullFileName = template.FileName;
			//var eventArgs = new ProjectItemGeneratedEventArgs(fullFileName, template.FileContent, ProjectName, PARENT_ITEM_NAME, ProjectItemType.Folder, this, true);
			//OnProjectItemGenerated(this, eventArgs);
			//var gcEventArgs = new ProjectItemGenerationCompleteEventArgs(this);
			//OnGenerationComplete(this, gcEventArgs);

			#region Images
			{ //FK
				var eventArgs = new ProjectItemGeneratedEventArgs("fk.gif", string.Empty, ProjectName, PARENT_ITEM_NAME, ProjectItemType.Folder, this, true)
				{
					ProjectItemBinaryContent = Helpers.GetFileBinContent(new EmbeddedResourceName(GetEmbeddedPath() + ".fk.gif")),
					ContentType = ProjectItemContentType.Binary,
				};
				OnProjectItemGenerated(this, eventArgs);
				var gcEventArgs = new ProjectItemGenerationCompleteEventArgs(this);
				OnGenerationComplete(this, gcEventArgs);
			}
			{ //PK
				var eventArgs = new ProjectItemGeneratedEventArgs("key.gif", string.Empty, ProjectName, PARENT_ITEM_NAME, ProjectItemType.Folder, this, true)
				{
					ProjectItemBinaryContent = Helpers.GetFileBinContent(new EmbeddedResourceName(GetEmbeddedPath() + ".key.gif")),
					ContentType = ProjectItemContentType.Binary,
				};
				OnProjectItemGenerated(this, eventArgs);
				var gcEventArgs = new ProjectItemGenerationCompleteEventArgs(this);
				OnGenerationComplete(this, gcEventArgs);
			}
			{ //YES
				var eventArgs = new ProjectItemGeneratedEventArgs("yes.gif", string.Empty, ProjectName, PARENT_ITEM_NAME, ProjectItemType.Folder, this, true)
				{
					ProjectItemBinaryContent = Helpers.GetFileBinContent(new EmbeddedResourceName(GetEmbeddedPath() + ".yes.gif")),
					ContentType = ProjectItemContentType.Binary,
				};
				OnProjectItemGenerated(this, eventArgs);
				var gcEventArgs = new ProjectItemGenerationCompleteEventArgs(this);
				OnGenerationComplete(this, gcEventArgs);
			}
			{ //NO
				var eventArgs = new ProjectItemGeneratedEventArgs("no.gif", string.Empty, ProjectName, PARENT_ITEM_NAME, ProjectItemType.Folder, this, true)
				{
					ProjectItemBinaryContent = Helpers.GetFileBinContent(new EmbeddedResourceName(GetEmbeddedPath() + ".no.gif")),
					ContentType = ProjectItemContentType.Binary,
				};
				OnProjectItemGenerated(this, eventArgs);
				var gcEventArgs = new ProjectItemGenerationCompleteEventArgs(this);
				OnGenerationComplete(this, gcEventArgs);
			}
			{ //CONSTRAINT
				var eventArgs = new ProjectItemGeneratedEventArgs("constraint.gif", string.Empty, ProjectName, PARENT_ITEM_NAME, ProjectItemType.Folder, this, true)
				{
					ProjectItemBinaryContent = Helpers.GetFileBinContent(new EmbeddedResourceName(GetEmbeddedPath() + ".constraint.gif")),
					ContentType = ProjectItemContentType.Binary,
				};
				OnProjectItemGenerated(this, eventArgs);
				var gcEventArgs = new ProjectItemGenerationCompleteEventArgs(this);
				OnGenerationComplete(this, gcEventArgs);
			}
			{ //INDEX
				var eventArgs = new ProjectItemGeneratedEventArgs("index.gif", string.Empty, ProjectName, PARENT_ITEM_NAME, ProjectItemType.Folder, this, true)
				{
					ProjectItemBinaryContent = Helpers.GetFileBinContent(new EmbeddedResourceName(GetEmbeddedPath() + ".index.gif")),
					ContentType = ProjectItemContentType.Binary,
				};
				OnProjectItemGenerated(this, eventArgs);
				var gcEventArgs = new ProjectItemGenerationCompleteEventArgs(this);
				OnGenerationComplete(this, gcEventArgs);
			}
			#endregion

			//Style sheet
			{
				var template = new StyleSheetTemplate(_model, GetEmbeddedPath());
				var eventArgs = new ProjectItemGeneratedEventArgs(template.FileName, template.FileContent, ProjectName, PARENT_ITEM_NAME, ProjectItemType.Folder, this, true);
				OnProjectItemGenerated(this, eventArgs);
				var gcEventArgs = new ProjectItemGenerationCompleteEventArgs(this);
				OnGenerationComplete(this, gcEventArgs);
			}

			//Site overview
			{
				var template = new DatasiteOverviewTemplate(_model, GetEmbeddedPath());
				var eventArgs = new ProjectItemGeneratedEventArgs(template.FileName, template.FileContent, ProjectName, PARENT_ITEM_NAME, ProjectItemType.Folder, this, true);
				OnProjectItemGenerated(this, eventArgs);
				var gcEventArgs = new ProjectItemGenerationCompleteEventArgs(this);
				OnGenerationComplete(this, gcEventArgs);
			}

			//Table overview
			{
				var template = new DatasiteTableListTemplate(_model, GetEmbeddedPath());
				var eventArgs = new ProjectItemGeneratedEventArgs(template.FileName, template.FileContent, ProjectName, PARENT_ITEM_NAME, ProjectItemType.Folder, this, true);
				OnProjectItemGenerated(this, eventArgs);
				var gcEventArgs = new ProjectItemGenerationCompleteEventArgs(this);
				OnGenerationComplete(this, gcEventArgs);
			}

			//Tables
			foreach (var item in _model.Database.Tables.Where(x => x.Generated).OrderBy(x => x.Name))
			{
				var template = new DatasiteTableItemTemplate(_model, item, GetEmbeddedPath());
				var eventArgs = new ProjectItemGeneratedEventArgs(template.FileName, template.FileContent, ProjectName, PARENT_ITEM_NAME, ProjectItemType.Folder, this, true);
				OnProjectItemGenerated(this, eventArgs);
				var gcEventArgs = new ProjectItemGenerationCompleteEventArgs(this);
				OnGenerationComplete(this, gcEventArgs);
			}

			//Views overview
			{
				var template = new DatasiteViewListTemplate(_model, GetEmbeddedPath());
				var eventArgs = new ProjectItemGeneratedEventArgs(template.FileName, template.FileContent, ProjectName, PARENT_ITEM_NAME, ProjectItemType.Folder, this, true);
				OnProjectItemGenerated(this, eventArgs);
				var gcEventArgs = new ProjectItemGenerationCompleteEventArgs(this);
				OnGenerationComplete(this, gcEventArgs);
			}

			//Views
			foreach (var item in _model.Database.CustomViews.Where(x => x.Generated).OrderBy(x => x.Name))
			{
				var template = new DatasiteViewItemTemplate(_model, item, GetEmbeddedPath());
				var eventArgs = new ProjectItemGeneratedEventArgs(template.FileName, template.FileContent, ProjectName, PARENT_ITEM_NAME, ProjectItemType.Folder, this, true);
				OnProjectItemGenerated(this, eventArgs);
				var gcEventArgs = new ProjectItemGenerationCompleteEventArgs(this);
				OnGenerationComplete(this, gcEventArgs);
			}

			//Stored Procs overview
			{
				var template = new DatasiteStoredProcListTemplate(_model, GetEmbeddedPath());
				var eventArgs = new ProjectItemGeneratedEventArgs(template.FileName, template.FileContent, ProjectName, PARENT_ITEM_NAME, ProjectItemType.Folder, this, true);
				OnProjectItemGenerated(this, eventArgs);
				var gcEventArgs = new ProjectItemGenerationCompleteEventArgs(this);
				OnGenerationComplete(this, gcEventArgs);
			}

			//Stored Procs
			foreach (var item in _model.Database.CustomStoredProcedures.Where(x => x.Generated).OrderBy(x => x.Name))
			{
				var template = new DatasiteStoredProcItemTemplate(_model, item, GetEmbeddedPath());
				var eventArgs = new ProjectItemGeneratedEventArgs(template.FileName, template.FileContent, ProjectName, PARENT_ITEM_NAME, ProjectItemType.Folder, this, true);
				OnProjectItemGenerated(this, eventArgs);
				var gcEventArgs = new ProjectItemGenerationCompleteEventArgs(this);
				OnGenerationComplete(this, gcEventArgs);
			}

			//Functions overview
			{
				var template = new DatasiteFunctionListTemplate(_model, GetEmbeddedPath());
				var eventArgs = new ProjectItemGeneratedEventArgs(template.FileName, template.FileContent, ProjectName, PARENT_ITEM_NAME, ProjectItemType.Folder, this, true);
				OnProjectItemGenerated(this, eventArgs);
				var gcEventArgs = new ProjectItemGenerationCompleteEventArgs(this);
				OnGenerationComplete(this, gcEventArgs);
			}

			//Functions
			foreach (var item in _model.Database.Functions.Where(x => x.Generated).OrderBy(x => x.Name))
			{
				var template = new DatasiteFunctionItemTemplate(_model, item, GetEmbeddedPath());
				var eventArgs = new ProjectItemGeneratedEventArgs(template.FileName, template.FileContent, ProjectName, PARENT_ITEM_NAME, ProjectItemType.Folder, this, true);
				OnProjectItemGenerated(this, eventArgs);
				var gcEventArgs = new ProjectItemGenerationCompleteEventArgs(this);
				OnGenerationComplete(this, gcEventArgs);
			}

			//Scripts
			{
				var template1 = new DatasiteJQueryTemplate(_model, GetEmbeddedPath());
				var eventArgs = new ProjectItemGeneratedEventArgs(template1.FileName, template1.FileContent, ProjectName, PARENT_ITEM_NAME, ProjectItemType.Folder, this, true);
				OnProjectItemGenerated(this, eventArgs);
				var gcEventArgs = new ProjectItemGenerationCompleteEventArgs(this);
				OnGenerationComplete(this, gcEventArgs);

				var template2 = new DatasiteJQueryCornersTemplate(_model, GetEmbeddedPath());
				eventArgs = new ProjectItemGeneratedEventArgs(template2.FileName, template2.FileContent, ProjectName, PARENT_ITEM_NAME, ProjectItemType.Folder, this, true);
				OnProjectItemGenerated(this, eventArgs);
				gcEventArgs = new ProjectItemGenerationCompleteEventArgs(this);
				OnGenerationComplete(this, gcEventArgs);

				var template3 = new DatasiteMasterScriptTemplate(_model, GetEmbeddedPath());
				eventArgs = new ProjectItemGeneratedEventArgs(template3.FileName, template3.FileContent, ProjectName, PARENT_ITEM_NAME, ProjectItemType.Folder, this, true);
				OnProjectItemGenerated(this, eventArgs);
				gcEventArgs = new ProjectItemGenerationCompleteEventArgs(this);
				OnGenerationComplete(this, gcEventArgs);
			}

		}
        private void projectItemGenerator_ProjectItemGenerated(object sender, ProjectItemGeneratedEventArgs e)
        {
            //.NET is a single-threaded application so we much release to let the UI refresh sometimes.
            if (_doEventCount % 10 == 0)
                Application.DoEvents();
            _doEventCount++;

            try
            {
                const string solutionDirReplaceText="$(solutiondir)";
                if (e.FullName != null && e.FullName.ToLower().Contains(solutionDirReplaceText))
                {
                    var ti = e.FullName.ToLower().IndexOf(solutionDirReplaceText);
                    e.FullName = e.FullName.Remove(ti, solutionDirReplaceText.Length).Insert(ti, EnvDTEHelper.Instance.SolutionDirectory.FullName);
                }
                if (e.ProjectItemName != null && e.ProjectItemName.ToLower().Contains(solutionDirReplaceText))
                {
                    var ti = e.ProjectItemName.ToLower().IndexOf(solutionDirReplaceText);
                    e.ProjectItemName = e.ProjectItemName.Remove(ti, solutionDirReplaceText.Length).Insert(ti, EnvDTEHelper.Instance.SolutionDirectory.FullName);
                }

                //Get the parent project if one exists
                Project project = null;
                ProjectItem parent = null;
                if (!string.IsNullOrEmpty(e.ProjectName))
                {
                    if (projectCache.ContainsKey(e.ProjectName))
                    {
                        var p = projectCache[e.ProjectName];
                        //Test this COM object to ensure it has not expired.
                        //If error, do nothing and the project will be requeried
                        try
                        {
                            var s = p.Name;
                            project = p;
                        }
                        catch (Exception)
                        {
                            //Do Nothing
                            projectCache.Remove(e.ProjectName);
                        }
                    }

                    var fromCache = true;
                    if (project == null)
                    {
                        fromCache = false;
                        project = EnvDTEHelper.Instance.GetProject(e.ProjectName);
                        projectCache.Add(e.ProjectName, project);
                    }

                    parent = EnvDTEHelper.Instance.GetProjectItem(e.ProjectName, e.ParentItemName, e.ParentItemType);

                    //This should not happen. If do dump the cache project and requery
                    if (parent == null && fromCache)
                    {
                        if (projectCache.ContainsKey(e.ProjectName))
                            projectCache.Remove(e.ProjectName);
                        project = EnvDTEHelper.Instance.GetProject(e.ProjectName);
                        projectCache.Add(e.ProjectName, project);
                        parent = EnvDTEHelper.Instance.GetProjectItem(e.ProjectName, e.ParentItemName, e.ParentItemType);
                    }

                }

                var fileStateInfo = new FileStateInfo();
                ProjectItem projectItem = null;
                if (e.ParentItemName != string.Empty)
                {
                    if (e.ContentType == ProjectItemContentType.String)
                        projectItem = EnvDTEHelper.Instance.AddProjectItem(project, parent, e.ProjectItemName, e.ProjectItemContent, e.Overwrite, out fileStateInfo);
                    else
                    {
                        projectItem = EnvDTEHelper.Instance.AddProjectItem(parent, e.ProjectItemContent, out fileStateInfo);
                    }

                    if (fileStateInfo.FileState == EnvDTEHelper.FileStateConstants.Success)
                        EnvDTEHelper.SetProperties(projectItem, e.Properties);
                }
                else
                {
                    if (e.ContentType == ProjectItemContentType.String || e.ContentType == ProjectItemContentType.Binary)
                    {
                        if (project == null)
                            EnvDTEHelper.Instance.AddProjectItem(e.ProjectItemContent, e.ProjectItemBinaryContent, e.ContentType, e.ProjectItemName, e.Overwrite, out fileStateInfo);
                        else
                            projectItem = EnvDTEHelper.Instance.AddProjectItem(project, e.ProjectItemContent, e.ProjectItemBinaryContent, e.ContentType, e.ProjectItemName, e.Overwrite, out fileStateInfo);
                    }
                    else
                    {
                        projectItem = EnvDTEHelper.Instance.AddFileAsProjectItem(project, e.ProjectItemContent, e.ProjectItemName, e.Overwrite, out fileStateInfo);
                    }

                    if (fileStateInfo.FileState == EnvDTEHelper.FileStateConstants.Success)
                        EnvDTEHelper.SetProperties(projectItem, e.Properties);
                }

                //TEMP
                processedFiles.Add(fileStateInfo.FileName);
                //TEMP

                //Custom Tool Functionality
                if (e.RunCustomTool && projectItem != null)
                {
                    if (!string.IsNullOrEmpty(e.CustomToolName))
                    {
                        EnvDTEHelper.SetProperty(projectItem, "Generator", e.CustomToolName);
                        EnvDTEHelper.SetProperty(projectItem, "CustomTool", e.CustomToolName);
                    }

                    //Try to run the custom tool
                    try
                    {
                        var vsProjectItem = projectItem.Object as VSLangProj.VSProjectItem;
                        if (vsProjectItem != null)
                            vsProjectItem.RunCustomTool();
                    }
                    catch
                    {
                        //Do Nothing
                    }
                }

                #region Compute CRC
                //System.IO.StreamReader sr = System.IO.File.OpenText("");
                //nHydrate.Generator.Common.Util.CRC32HashAlgorithm hash = new CRC32HashAlgorithm();
                //byte[] arr = hash.ComputeHash(sr.BaseStream);
                //sr.Close();
                //XmlHelper.AddAttribute(newfileNode, "crc", "0");
                #endregion

                if (fileStateInfo.FileName == string.Empty)
                {
                    System.Diagnostics.Debug.Write(string.Empty);
                }
                if (fileStateInfo.FileState == EnvDTEHelper.FileStateConstants.Failed)
                {
                    System.Diagnostics.Debug.Write(string.Empty);
                }

                //Write Log
                nHydrateLog.LogInfo("Project Item Generated: {0}", e.ProjectItemName);
                e.FileState = fileStateInfo.FileState;
                e.FullName = fileStateInfo.FileName;
                this.OnProjectItemGenerated(sender, e);

            }
            catch (Exception ex)
            {
                this.OnProjectItemGeneratedError(this, e);
                nHydrateLog.LogWarning(ex);
            }
        }
		private void GenerateInstallSettings()
		{
			var fileName = "InstallSettings.cs";
			var fileContent = GetFileContent(new EmbeddedResourceName(this.GetEmbeddedPath() + "." + fileName));
			var eventArgs = new ProjectItemGeneratedEventArgs(fileName, fileContent, ProjectName, this, true);
			OnProjectItemGenerated(this, eventArgs);
		}
		private void GenerateDatabaseInstallerDesignerCs()
		{
			var fullParentName = "DatabaseInstaller.cs";
			var fileName = "DatabaseInstaller.Designer.cs";
			var ern = new EmbeddedResourceName();
			ern.AsmLocation = this.GetEmbeddedPath();
			ern.FileName = "DatabaseInstaller.Designer.embed";
			ern.FullName = this.GetEmbeddedPath() + "." + ern.FileName;
			var fileContent = GetFileContent(ern);
			var eventArgs = new ProjectItemGeneratedEventArgs(fileName, fileContent, ProjectName, fullParentName, this, true);
			OnProjectItemGenerated(this, eventArgs);
		}
		private void GenerateSqlServersCs()
		{
			var fileName = "SqlServers.cs";
			var fileContent = GetFileContent(new EmbeddedResourceName(this.GetEmbeddedPath() + "." + fileName));

			////need to replace text with all entities in metadata table
			//var sb = new StringBuilder();
			//sb.AppendLine();
			//foreach (var item in _model.Database.Tables.Where(x => x.Generated))
			//{
			//  sb.Append("					command = new SqlCommand(\"insert into [__nhydratemetadata] (name,type,codefacade,immutable,isassociative,parent,summary,typedtable) values (");
			//  sb.Append("'" + item.Name + "',");
			//  sb.Append("1,");
			//  sb.Append("'" + StringHelper.ConvertTextToSingleLineCodeString(item.CodeFacade) + "',");
			//  sb.Append((item.Immutable ? "1" : "0") + ",");
			//  sb.Append((item.AssociativeTable ? "1" : "0") + ",");
			//  sb.Append(StringHelper.ConvertTextToSingleLineCodeString((item.ParentTable == null ? "null" : item.ParentTable.Name)) + ",");
			//  sb.Append("'" + StringHelper.ConvertTextToSingleLineCodeString(item.Description, true) + "',");
			//  sb.Append(item.TypedTable.ToString("d"));
			//  sb.AppendLine(")\");");
			//}
			//sb.AppendLine("					command.Transaction = transaction;");
			//sb.AppendLine("					command.ExecuteNonQuery();");
			//sb.AppendLine();

			//fileContent = fileContent.Replace("//{{METADATA}}", sb.ToString());

			var eventArgs = new ProjectItemGeneratedEventArgs(fileName, fileContent, ProjectName, this, true);
			OnProjectItemGenerated(this, eventArgs);
		}
        public override void Generate()
        {
            try
            {
                if (this.UseSingleFile)
                {
                    //Process all views
                    var sb = new StringBuilder();
                    sb.AppendLine("--DO NOT MODIFY THIS FILE. IT IS ALWAYS OVERWRITTEN ON GENERATION.");
                    sb.AppendLine();

                    var grantSB = new StringBuilder();
                    foreach (var view in _model.Database.CustomViews.Where(x => x.Generated).OrderBy(x => x.Name))
                    {
                        var template = new SQLStoredProcedureViewAllTemplate(_model, view, true, grantSB);
                        sb.Append(template.FileContent);
                    }

                    //Tenant Views
                    foreach (var table in _model.Database.Tables.Where(x => x.Generated && x.IsTenant).OrderBy(x => x.Name))
                    {
                        var template = new SQLSelectTenantViewTemplate(_model, table, grantSB);
                        sb.Append(template.FileContent);
                    }

                    //Add grants
                    sb.Append(grantSB.ToString());

                    var eventArgs = new ProjectItemGeneratedEventArgs("Views.sql", sb.ToString(), ProjectName, this.ParentItemPath, ProjectItemType.Folder, this, true);
                    eventArgs.Properties.Add("BuildAction", 3);
                    OnProjectItemGenerated(this, eventArgs);
                }
                else
                {
                    //Process all views
                    foreach (var view in _model.Database.CustomViews.Where(x => x.Generated).OrderBy(x => x.Name))
                    {
                        var grantSB = new StringBuilder();
                        var template = new SQLStoredProcedureViewAllTemplate(_model, view, false, grantSB);
                        var fullFileName = template.FileName;

                        //Add grants
                        var sb = new StringBuilder();
                        sb.Append(template.FileContent);
                        sb.Append(grantSB.ToString());

                        var eventArgs = new ProjectItemGeneratedEventArgs(fullFileName, sb.ToString(), ProjectName, this.ParentItemPath, ProjectItemType.Folder, this, true);
                        eventArgs.Properties.Add("BuildAction", 3);
                        OnProjectItemGenerated(this, eventArgs);
                    }
                }

                var gcEventArgs = new ProjectItemGenerationCompleteEventArgs(this);
                OnGenerationComplete(this, gcEventArgs);
            }
            catch (Exception ex)
            {
                throw;
            }
        }
		private void GenerateIdentifyDatabaseFormCs()
		{
			var fileName = "IdentifyDatabaseForm.cs";
			var fileContent = GetFileContent(new EmbeddedResourceName(this.GetEmbeddedPath() + "." + fileName));
			var eventArgs = new ProjectItemGeneratedEventArgs(fileName, fileContent, ProjectName, this, true);
			OnProjectItemGenerated(this, eventArgs);
		}
		private void GenerateFolder2()
		{
			var foldername = "2_Upgrade Scripts";
			var fileName = string.Empty;
			ProjectItemGeneratedEventArgs eventArgs = null;

			fileName = Path.Combine(foldername, "ReadMe.txt");
			eventArgs = new ProjectItemGeneratedEventArgs(fileName, "Scripts in this folder are generated once and can be modified by the user after generation.\r\nEverything under this folder will be run in versioned number order.\r\nThese scripts will only be run on a previous versioned database, not on a create or unversioned database.", ProjectName, this, true);
			OnProjectItemGenerated(this, eventArgs);
		}
		private void GenerateFolder5()
		{
			var foldername = "5_Programmability";
			var fileName = string.Empty;
			ProjectItemGeneratedEventArgs eventArgs = null;

			//User-defined Functions
			var folderUD = Path.Combine(Path.Combine(foldername, "Functions"), "User Defined");
			fileName = Path.Combine(folderUD, "ReadMe.txt");
			eventArgs = new ProjectItemGeneratedEventArgs(fileName, "Add user-defined scripts for database functions in this folder.", ProjectName, this, true);
			OnProjectItemGenerated(this, eventArgs);

			//User-defined Stored Procedures
			folderUD = Path.Combine(Path.Combine(foldername, "Stored Procedures"), "User Defined");
			fileName = Path.Combine(folderUD, "ReadMe.txt");
			eventArgs = new ProjectItemGeneratedEventArgs(fileName, "Add user-defined scripts for database stored procedures in this folder.", ProjectName, this, true);
			OnProjectItemGenerated(this, eventArgs);

			//User-defined Views
			folderUD = Path.Combine(Path.Combine(foldername, "Views"), "User Defined");
			fileName = Path.Combine(folderUD, "ReadMe.txt");
			eventArgs = new ProjectItemGeneratedEventArgs(fileName, "Add user-defined scripts for database views in this folder.", ProjectName, this, true);
			OnProjectItemGenerated(this, eventArgs);

		}
		private void GenerateFolder3()
		{
			var foldername = "3_GeneratedTablesAndData";
			var fileName = string.Empty;
			ProjectItemGeneratedEventArgs eventArgs = null;

			fileName = Path.Combine(foldername, "ReadMe.txt");
			eventArgs = new ProjectItemGeneratedEventArgs(fileName, "Do not modify scripts in this folder.", ProjectName, this, true);
			OnProjectItemGenerated(this, eventArgs);

		}
		private void GenerateFolder6()
		{
			var foldername = "6_UserDefinedFinalize";
			var fileName = string.Empty;
			ProjectItemGeneratedEventArgs eventArgs = null;

			//Main folder Readme.txt
			fileName = Path.Combine(foldername, "ReadMe.txt");
			eventArgs = new ProjectItemGeneratedEventArgs(fileName, GetTextFolder4ReadMe(), ProjectName, this, true);
			OnProjectItemGenerated(this, eventArgs);

			//Create Always
			var folderAlways = Path.Combine(foldername, "Always");
			fileName = Path.Combine(folderAlways, "ReadMe.txt");
			eventArgs = new ProjectItemGeneratedEventArgs(fileName, "Add scripts that will always run after all other scripts in this folder. Make them embedded resources and they will be run in alphabetical order.", ProjectName, this, true);
			OnProjectItemGenerated(this, eventArgs);

			//New Database
			var folderNewDatabase = Path.Combine(foldername, "NewDatabase");
			fileName = Path.Combine(folderNewDatabase, "ReadMe.txt");
			eventArgs = new ProjectItemGeneratedEventArgs(fileName, "Add scripts that will be run after all other scripts on a database creation in this folder. Make them embedded resources and they will be run in alphabetical order.", ProjectName, this, true);
			OnProjectItemGenerated(this, eventArgs);

			//Unversioned
			var folderUnversioned = Path.Combine(foldername, "UnVersioned");
			fileName = Path.Combine(folderUnversioned, "ReadMe.txt");
			eventArgs = new ProjectItemGeneratedEventArgs(fileName, "Add scripts that will be run after all other scripts on an existing non-versioned database in this folder. Make them embedded resources and they will be run in alphabetical order.", ProjectName, this, true);
			OnProjectItemGenerated(this, eventArgs);

			//Versioned
			var folderVersioned = Path.Combine(foldername, "Versioned");
			fileName = Path.Combine(folderVersioned, "ReadMe.txt");
			eventArgs = new ProjectItemGeneratedEventArgs(fileName, "Add scripts that will be run after all other scripts on an existing versioned database in this folder. Make them embedded resources and they will be run in alphabetical order.", ProjectName, this, true);
			OnProjectItemGenerated(this, eventArgs);

		}
		private void GenerateUpgradeInstaller()
		{
			var fileName = "UpgradeInstaller.cs";
			var fileContent = GetFileContent(new EmbeddedResourceName(this.GetEmbeddedPath() + "." + fileName));
			//TODO - Change the version for _upgradeToVersion and _previousVersion
			var eventArgs = new ProjectItemGeneratedEventArgs(fileName, fileContent, ProjectName, this, true);
			OnProjectItemGenerated(this, eventArgs);
		}