Click here to Skip to main content
15,885,244 members
Articles / Web Development / HTML

Signum Framework Tutorials Part 1 – Southwind Entities

Rate me:
Please Sign up or sign in to vote.
4.50/5 (12 votes)
14 Nov 2012LGPL315 min read 41.3K   2K   52  
Tutorial focused in writing the entities using Signum Framework, a Win/Web LINQ-enabled framework for writing data-centric applications.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.VisualStudio.TemplateWizard;
using EnvDTE;
using System.Windows.Forms;
using System.IO;
using System.Xml;
using Microsoft.VisualStudio.Shell.Interop;
using Microsoft.VisualStudio.Shell;
using Microsoft.VisualStudio;

namespace WizardProjectName
{
    public class Wizard : IWizard
    {

        public void BeforeOpeningFile(ProjectItem projectItem)
        {

        }

        public void ProjectFinishedGenerating(Project project)
        {
            try
            {
                var serviceProvider = new ServiceProvider(project.DTE as Microsoft.VisualStudio.OLE.Interop.IServiceProvider); 
                var solution = serviceProvider.GetService(typeof(SVsSolution)) as IVsSolution;

                IVsHierarchy hierarchy;
                 
                solution.GetProjectOfUniqueName(project.FullName, out hierarchy);

                Guid projectGuid = Guid.Empty;
                if (hierarchy != null)
                {
                    ErrorHandler.ThrowOnFailure(
                        hierarchy.GetGuidProperty(
                            VSConstants.VSITEMID_ROOT,
                            (int)__VSHPROPID.VSHPROPID_ProjectIDGuid,
                            out projectGuid));
                }

                string post = postNames.SingleOrDefault(a => project.Name.EndsWith(a));
                
                string post2 = post.Replace(".", "guid");

                projectGuids[post2] = projectGuid.ToString(); 

                //StringBuilder sb = new StringBuilder();
                //sb.AppendLine(string.Format("{0}: {1}", post2, projectGuid.ToString()));

                //MessageBox.Show(sb.ToString());
                //File.AppendAllText(@"c:\debugTemplate.txt", sb.ToString());
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }

        public void ProjectItemFinishedGenerating(ProjectItem projectItem)
        {

        }

        public void RunFinished()
        {

        }

        static Dictionary<string, string> projectGuids = new Dictionary<string,string>(); 

        static string[] postNames = new[] { ".Entities", ".Load", ".Logic", ".Web", ".Windows" };

        public void RunStarted(object automationObject, Dictionary<string, string> replacementsDictionary, WizardRunKind runKind, object[] customParams)
        {
            try
            {
                string projectName = replacementsDictionary["$safeprojectname$"];

                string post = postNames.SingleOrDefault(a => projectName.EndsWith(a));
                if (post != null)
                    projectName = projectName.Remove(projectName.Length - post.Length);

                replacementsDictionary.Add("$custommessage$", projectName);


                foreach (var kvp in projectGuids)
                    replacementsDictionary.Add("$" + kvp.Key + "$", kvp.Value);

                //StringBuilder sb = new StringBuilder();
                //foreach (var kvp in replacementsDictionary)
                //    sb.AppendFormat("{0}: {1}\r\n", kvp.Key, kvp.Value); 

                //MessageBox.Show(sb.ToString());
                //File.AppendAllText(@"c:\debugTemplate.txt", sb.ToString());

            }

            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }

        public bool ShouldAddProjectItem(string filePath)
        {
            return true;
        }
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The GNU Lesser General Public License (LGPLv3)


Written By
Software Developer (Senior) Signum Software
Spain Spain
I'm Computer Scientist, one of the founders of Signum Software, and the lead developer behind Signum Framework.

www.signumframework.com

I love programming in C#, Linq, Compilers, Algorithms, Functional Programming, Computer Graphics, Maths...

Comments and Discussions